Allow encounter handlers to properly close

This commit is contained in:
Hazel Nova 2024-01-13 11:47:18 +08:00
parent d399af040d
commit 140d430235
1 changed files with 4 additions and 11 deletions

View File

@ -13,8 +13,6 @@ class EncounterHandler(DefaultScript):
def at_script_creation(self): def at_script_creation(self):
# When initiating the encounter # When initiating the encounter
self.key = f"encounter_handler_{random.randint(1, 1000)}" self.key = f"encounter_handler_{random.randint(1, 1000)}"
self.desc = "Handles an encounter"
self.persistent = True
self.db.characters = {} self.db.characters = {}
self.db.turns = [] self.db.turns = []
@ -34,15 +32,11 @@ class EncounterHandler(DefaultScript):
del character.ndb.encounter_handler del character.ndb.encounter_handler
character.revoke_encounter_cmdset() character.revoke_encounter_cmdset()
def at_start(self):
# When initializing or rebooting
for character in self.db.characters.values():
self._init_character(character)
def at_stop(self): def at_stop(self):
# When deinitializing or rebooting # When deinitializing
for character in list(self.db.characters.values()): for character in list(self.db.characters.values()):
self._cleanup_character(character) self._cleanup_character(character)
self.delete()
def add_character(self, character): def add_character(self, character):
# Adds a character to the encounter # Adds a character to the encounter
@ -58,10 +52,9 @@ class EncounterHandler(DefaultScript):
if len(self.db.characters) == 1: if len(self.db.characters) == 1:
char = list(self.db.characters.values())[0] char = list(self.db.characters.values())[0]
char.msg("You are no longer in an encounter.") char.msg("You are no longer in an encounter.")
self._cleanup_character(char) self.at_stop()
self.stop()
elif not self.db.characters: elif not self.db.characters:
self.stop() self.at_stop()
def msg_all(self, message): def msg_all(self, message):
# Sends text to all players in the encounter # Sends text to all players in the encounter