mirror of
https://github.com/evennia/evennia.git
synced 2026-03-31 21:17:17 +02:00
Add a setting to handle absolute game time (assuing standard a calendar)
The `@time` command now displays the game time epoch (can be set in settings) and current game time (as a datetime).
This commit is contained in:
parent
24adc5286b
commit
59a5315c79
3 changed files with 49 additions and 0 deletions
|
|
@ -651,11 +651,17 @@ class CmdTime(COMMAND_DEFAULT_CLASS):
|
|||
|
||||
def func(self):
|
||||
"Show server time data in a table."
|
||||
virtual_epoch = datetime.datetime.fromtimestamp(
|
||||
gametime.virtual_epoch())
|
||||
virtual_current = datetime.datetime.fromtimestamp(
|
||||
gametime.abs_gametime())
|
||||
table = prettytable.PrettyTable(["{wserver time statistic","{wtime"])
|
||||
table.align = 'l'
|
||||
table.add_row(["Current server uptime", utils.time_format(gametime.uptime(), 3)])
|
||||
table.add_row(["Total server running time", utils.time_format(gametime.runtime(), 2)])
|
||||
table.add_row(["Game time epoch", virtual_epoch])
|
||||
table.add_row(["Total in-game time (realtime x %g)" % (gametime.TIMEFACTOR), utils.time_format(gametime.gametime(), 2)])
|
||||
table.add_row(["Current game time", virtual_current])
|
||||
table.add_row(["Server time stamp", datetime.datetime.now()])
|
||||
self.caller.msg(str(table))
|
||||
|
||||
|
|
|
|||
|
|
@ -440,6 +440,12 @@ TIME_HOUR_PER_DAY = 24
|
|||
TIME_DAY_PER_WEEK = 7
|
||||
TIME_WEEK_PER_MONTH = 4
|
||||
TIME_MONTH_PER_YEAR = 12
|
||||
# The initial timestamp of your virtual time (in-game)
|
||||
# You can set this setting to set a fixed, initial timestamp. Your
|
||||
# game time will be this timestamp plus your current variable game time.
|
||||
# You can set this setting to a timestamp in 1980, or 2020, or 2500 if
|
||||
# you want to. Leave it to None to deduce the timestamp from the runtime.
|
||||
TIME_VIRTUAL_START = None
|
||||
|
||||
######################################################################
|
||||
# Inlinefunc
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ from evennia.server.models import ServerConfig
|
|||
# to real time.
|
||||
|
||||
TIMEFACTOR = settings.TIME_FACTOR
|
||||
TIME_VIRTUAL_START = settings.TIME_VIRTUAL_START
|
||||
|
||||
# Only set if gametime_reset was called at some point.
|
||||
GAME_TIME_OFFSET = ServerConfig.objects.conf("gametime_offset", default=0)
|
||||
|
|
@ -105,6 +106,42 @@ def uptime(format=False):
|
|||
return _format(utime, 31536000, 2628000, 604800, 86400, 3600, 60)
|
||||
return utime
|
||||
|
||||
def virtual_epoch():
|
||||
"""Return the number of VIRTUAL seconds since the server started.
|
||||
|
||||
This number is set in the TIME_VIRTUAL_START setting. If not
|
||||
set, it will be deduced from the current time and server runtime.
|
||||
Notice, in this case, that it will be slightly fluctuant every
|
||||
reload or restart.
|
||||
|
||||
Returns:
|
||||
The number of virtual seconds since the game first started.
|
||||
|
||||
"""
|
||||
if TIME_VIRTUAL_START is None:
|
||||
virtual_start = time.time() - runtime()
|
||||
else:
|
||||
virtual_start = TIME_VIRTUAL_START
|
||||
|
||||
return virtual_start
|
||||
|
||||
def abs_gametime():
|
||||
"""Return the absolute number of virtual seconds (in game time).
|
||||
|
||||
This function returns the number of seconds, using your configured
|
||||
virtual start (setting TIME_VIRTUAL_START), and adding the
|
||||
current relative gametime(). If you want to use a standard
|
||||
calendar, it might save you time and efforts. You could easily
|
||||
convert the value like this:
|
||||
>>> from datetime import datetime
|
||||
>>> current = datetime.fromtimestamp(abs_gametime())
|
||||
|
||||
Returns:
|
||||
The number of virtual seconds using the virtual epoch as a basis.
|
||||
|
||||
"""
|
||||
virtual_start = virtual_epoch()
|
||||
return virtual_start + gametime()
|
||||
|
||||
def gametime(format=False):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue