Kovitikus

time_cycle.py

Jan 9th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.24 KB | None | 0 0
  1. import datetime
  2.  
  3. from typeclasses.scripts import Script
  4. from typeclasses.rooms import Room
  5.  
  6. class TimeCycle(Script):
  7.     def at_script_creation(self):
  8.         self.key = 'time_cycle'
  9.         self.desc = "Tracks global timed events."
  10.         self.interval = 1
  11.         self.persistent = True
  12.  
  13.     def at_repeat(self):
  14.         now = datetime.datetime.now()
  15.         cur_hour = now.hour
  16.         cur_min = now.minute
  17.         cur_sec = now.second
  18.         if cur_sec != 0:
  19.             return
  20.         if cur_min not in [0, 20, 40]:
  21.             return
  22.  
  23.         # Daytime begins.
  24.         if cur_hour in [2, 6, 10, 14, 18, 22]:
  25.             if cur_min == 0:
  26.                 # Phase 1
  27.                 string = "The sun rises above the eastern horizon."
  28.             elif cur_min == 20:
  29.                 # Phase 2
  30.                 string = "It's now mid-morning."
  31.             elif cur_min == 40:
  32.                 # Phase 3
  33.                 string = "It's now early-noon."
  34.         elif cur_hour in [3, 7, 11, 15, 19, 23]:
  35.             if cur_min == 0:
  36.                 # Phase 4
  37.                 string = "It's now high-noon."
  38.             elif cur_min == 20:
  39.                 # Phase 5
  40.                 string = "It's now mid-afternoon."
  41.             elif cur_min == 40:
  42.                 # Phase 6
  43.                 string = "It's now dusk."
  44.         # Nighttime begins.
  45.         elif cur_hour in [0, 4, 8, 12, 16, 20]:
  46.             if cur_min == 0:
  47.                 # Phase 1
  48.                 string = "The sun has set and the moon begins to glow."
  49.             elif cur_min == 20:
  50.                 # Phase 2
  51.                 string = "It's now early-evening."
  52.             elif cur_min == 40:
  53.                 # Phase 3
  54.                 string = "It's now late-evening."
  55.         elif cur_hour in [1, 5, 9, 13, 17, 21]:
  56.             if cur_min == 0:
  57.                 # Phase 4
  58.                 string = "It's now midnight."
  59.             elif cur_min == 20:
  60.                 # Phase 5
  61.                 string = "It's now early-morning."
  62.             elif cur_min == 40:
  63.                 # Phase 6
  64.                 string = "The break of dawn approaches."
  65.         # Send out the string to all rooms.
  66.         for room in Room.objects.all():
  67.             room.msg_contents(string)
Add Comment
Please, Sign In to add comment