コード例 #1
0
ファイル: rooms.py プロジェクト: guicampos/arxcode
    def get_time_and_season(self):
        """
        Calculate the current time and season ids.
        """
        # get the current time as parts of year and parts of day
        # returns a tuple (years,months,weeks,days,hours,minutes,sec)
        MONTHS_PER_YEAR = 12
        SEASONAL_BOUNDARIES = (3 / 12.0, 6 / 12.0, 9 / 12.0)
        HOURS_PER_DAY = 24
        DAY_BOUNDARIES = (0, 6 / 24.0, 12 / 24.0, 18 / 24.0)
        time = gametime.gametime(format=True)
        month, hour = time[1], time[4]
        season = float(month) / MONTHS_PER_YEAR
        timeslot = float(hour) / HOURS_PER_DAY

        # figure out which slots these represent
        if SEASONAL_BOUNDARIES[0] <= season < SEASONAL_BOUNDARIES[1]:
            curr_season = "spring"
        elif SEASONAL_BOUNDARIES[1] <= season < SEASONAL_BOUNDARIES[2]:
            curr_season = "summer"
        elif SEASONAL_BOUNDARIES[2] <= season < 1.0 + SEASONAL_BOUNDARIES[0]:
            curr_season = "autumn"
        else:
            curr_season = "winter"

        if DAY_BOUNDARIES[0] <= timeslot < DAY_BOUNDARIES[1]:
            curr_timeslot = "night"
        elif DAY_BOUNDARIES[1] <= timeslot < DAY_BOUNDARIES[2]:
            curr_timeslot = "morning"
        elif DAY_BOUNDARIES[2] <= timeslot < DAY_BOUNDARIES[3]:
            curr_timeslot = "afternoon"
        else:
            curr_timeslot = "evening"
        return curr_season, curr_timeslot
コード例 #2
0
ファイル: arx_utils.py プロジェクト: notcutty/arxcode
def get_date(game_time=None):
    """
    Get in-game date as a string
    format is 'M/D/YEAR AR'
    """
    from typeclasses.scripts import gametime
    time = gametime.gametime(game_time=game_time, format=True)
    month, day, year = time[1] + 1, time[3] + 1, time[0] + 1001
    day += (time[2] * 7)
    date = ("%s/%s/%s AR" % (month, day, year))
    return date
コード例 #3
0
    def func(self):
        """Reads time info from current room"""
        if self.args:
            parsed = None
            to_parse = self.args.strip()
            try:
                parsed = time.strptime(to_parse, "%Y/%m/%d %H:%M")
            except ValueError:
                try:
                    parsed = time.strptime(to_parse, "%Y/%m/%d")
                except ValueError:
                    pass

            if not parsed:
                self.msg(
                    "Unable to understand that date!  It must be in the format "
                    "|wYYYY/mm/dd|n or |wYYYY/mm/dd HH:MM|n to be understood.")
                return

            parsed = time.mktime(parsed)
            game_time = gametime.realtime_to_gametime(parsed)
            if game_time is None:
                self.msg(
                    "Real date |w{}|n was before the game started!".format(
                        to_parse))
                return
            from server.utils.arx_utils import get_date

            self.msg("Real date |w{}|n was about |w{}|n in game time.".format(
                to_parse, get_date(game_time)))
            return

        location = self.caller.location
        if not location or not hasattr(location, "get_time_and_season"):
            self.msg("No location available - you are outside time.")
        else:
            season, timeslot = location.get_time_and_season()
            prep = "a"
            if season == "autumn":
                prep = "an"
            weather = weather_utils.get_last_emit()
            self.msg("It's %s %s day, in the %s.  %s" %
                     (prep, season, timeslot, weather))
            time_tuple = gametime.gametime(format=True)
            hour, minute = time_tuple[4], time_tuple[5]
            from server.utils.arx_utils import get_date

            self.msg("Today's date: %s. Current time: %s:%02d" %
                     (get_date(), hour, minute))
コード例 #4
0
ファイル: rooms.py プロジェクト: guicampos/arxcode
 def func(self):
     """Reads time info from current room"""
     location = self.caller.location
     if not location or not hasattr(location, "get_time_and_season"):
         self.caller.msg("No location available - you are outside time.")
     else:
         season, timeslot = location.get_time_and_season()
         prep = "a"
         if season == "autumn":
             prep = "an"
         self.caller.msg("It's %s %s day, in the %s." %
                         (prep, season.capitalize(), timeslot))
         time = gametime.gametime(format=True)
         hour, minute = time[4], time[5]
         from server.utils.arx_utils import get_date
         self.caller.msg("Today's date: %s. Current time: %s:%02d" %
                         (get_date(), hour, minute))