effects.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. from evennia.utils import inherits_from, logger
  2. from typeclasses.characters import Character
  3. from typeclasses.scripts import Script
  4. from typeclasses.rooms import IndoorRoom
  5. from utils.utils import has_tag, toggle_effect, has_effect
  6. class EffectMagicalLight(Script):
  7. """
  8. """
  9. def at_script_creation(self):
  10. self.key = "effect_magic_light_script"
  11. self.desc = "not now"
  12. self.start_delay = True
  13. self.interval = 20
  14. self.persistent = True # will survive reload
  15. self.repeats = 1
  16. def at_start(self):
  17. if self.obj:
  18. if not has_effect(self.obj, "emit_magic_light"):
  19. toggle_effect(self.obj, "emit_magic_light")
  20. if self.obj.location:
  21. if inherits_from(self.obj.location, IndoorRoom):
  22. self.obj.location.msg_contents("{} starts emitting a soft and steady light.".format(self.obj.name))
  23. self.obj.location.check_light_state()
  24. # check if effect target is in actor contents
  25. if self.obj.location.location and inherits_from(self.obj.location.location, IndoorRoom):
  26. if inherits_from(self.obj.location, Character):
  27. self.obj.location.msg("{} starts emitting a soft and steady light.".format(self.obj.name))
  28. self.obj.location.location.check_light_state()
  29. def at_stop(self):
  30. if self.obj:
  31. if has_effect(self.obj, "emit_magic_light"):
  32. toggle_effect(self.obj, "emit_magic_light")
  33. if self.obj.location:
  34. if inherits_from(self.obj.location, IndoorRoom):
  35. self.obj.location.msg_contents("{} stops emitting light.".format(self.obj.name))
  36. self.obj.location.check_light_state()
  37. # check if effect target is in actor contents
  38. if self.obj.location.location and inherits_from(self.obj.location.location, IndoorRoom):
  39. if inherits_from(self.obj.location, Character):
  40. self.obj.location.msg("{} stops emitting light.".format(self.obj.name))
  41. self.obj.location.location.check_light_state()
  42. def at_repeat(self):
  43. self.at_stop()
  44. class EffectCharm(Script):
  45. """
  46. """
  47. def at_script_creation(self):
  48. self.key = "effect_charm_script"
  49. self.desc = "not now"
  50. self.start_delay = True
  51. self.interval = 20
  52. self.persistent = True # will survive reload
  53. self.repeats = 1
  54. def at_start(self):
  55. if self.obj:
  56. if not has_effect(self.obj, "charm"):
  57. toggle_effect(self.obj, "charm")
  58. self.obj.db.real_owner = self.obj.db.owner
  59. self.obj.db.owner = self.db.source
  60. def at_stop(self):
  61. if self.obj:
  62. if has_effect(self.obj, "charm"):
  63. toggle_effect(self.obj, "charm")
  64. self.obj.db.owner = self.obj.db.real_owner
  65. del self.obj.db.real_owner
  66. def at_repeat(self):
  67. self.at_stop()