From bd2077814362df67e9a4daf94e0046dc1312cdb4 Mon Sep 17 00:00:00 2001 From: Little Cat Date: Thu, 29 Dec 2022 22:13:42 -0400 Subject: [PATCH] spellbook: List and join ongoing boss battles. --- toontown/spellbook/MagicWordIndex.py | 65 +++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/toontown/spellbook/MagicWordIndex.py b/toontown/spellbook/MagicWordIndex.py index d88731b..94e77ef 100644 --- a/toontown/spellbook/MagicWordIndex.py +++ b/toontown/spellbook/MagicWordIndex.py @@ -13,11 +13,14 @@ import collections, types from direct.distributed.ClockDelta import * from direct.interval.IntervalGlobal import * +from direct.showbase.DirectObject import DirectObject +from direct.showbase.PythonUtil import * from panda3d.otp import NametagGroup, WhisperPopup from otp.otpbase import OTPLocalizer from otp.otpbase import OTPGlobals +from otp.otpbase.PythonUtil import * from . import MagicWordConfig import time, random, re, json @@ -25,7 +28,7 @@ import time, random, re, json magicWordIndex = collections.OrderedDict() -class MagicWord: +class MagicWord(DirectObject): notify = DirectNotifyGlobal.directNotify.newCategory('MagicWord') # Whether this Magic word should be considered "hidden" @@ -424,13 +427,12 @@ class BossBattle(MagicWord): except ValueError: start = 1 - from toontown.suit.DistributedBossCogAI import DistributedBossCogAI + from toontown.suit.DistributedBossCogAI import AllBossCogs boss = None - for do in self.air.doId2do.values(): - if isinstance(do, DistributedBossCogAI): - if do.isToonKnown(invoker.doId): - boss = do - break + for bc in AllBossCogs: + if bc.isToonKnown(invoker.doId): + boss = bc + break if command == "create": if boss: @@ -457,6 +459,8 @@ class BossBattle(MagicWord): boss.b_setState('WaitForToons') else: boss.b_setState('Frolic') + + self.acceptOnce(boss.uniqueName('BossDone'), self.__destroyBoss, extraArgs=[boss]) respText = f"Created {type.upper()} boss battle" if not start: @@ -464,6 +468,49 @@ class BossBattle(MagicWord): return respText + ", teleporting...", ["cogHQLoader", "cogHQBossBattle", "movie" if start else "teleportIn", boss.getHoodId(), boss.zoneId, 0] + elif command == "list": + # List all the ongoing boss battles. + dept2name = {'c': 'ceo', + 'l': 'cj', + 'm': 'cfo', + 's': 'vp'} + name2dept = invertDict(dept2name) + + if not AllBossCogs: + return "No ongoing boss battles." + + respText = "\nBoss Battles:" + + if type: + # Filter by boss type + dept = name2dept.get(type) + if not dept: + return f"Can't filter by unknown type \"{type.upper()}\"" + bossBattles = (boss for boss in AllBossCogs if boss.dept == dept) + else: + bossBattles = AllBossCogs + + for boss in bossBattles: + index = AllBossCogs.index(boss) + respText += f"\n - #{index}: {dept2name.get(boss.dept, '???').upper()}, {boss.zoneId}, {boss.state}, {len(boss.involvedToons)}" + return respText + + elif command == "join": + # Join an ongoing boss battle. + if boss: + return "You're already in a boss battle. Please finish this one." + try: + index = int(type) + except ValueError: + return "Boss index not an integer!" + + if index not in range(len(AllBossCogs)): + return "Index out of range!" + + boss = AllBossCogs[index] + return "Teleporting to boss battle...", ["cogHQLoader", "cogHQBossBattle", "", boss.getHoodId(), boss.zoneId, 0] + + # The following commands needs the invoker to be in a boss battle. if not boss: return "You ain't in a boss battle! Use the \"create\" command to create a boss battle." @@ -502,6 +549,10 @@ class BossBattle(MagicWord): # they can use INSIDE the battle. return respText + f"Unknown command: \"{command}\". Valid commands: \"start\", \"stop\", \"skip\", \"final\", \"kill\"." + def __destroyBoss(self, boss): + bossZone = boss.zoneId + boss.requestDelete() + self.air.deallocateZone(bossZone) # Instantiate all classes defined here to register them. # A bit hacky, but better than the old system