From d40ac6840bb2c987d70a20ebbc38f596d9834ca8 Mon Sep 17 00:00:00 2001 From: Little Cat Date: Wed, 28 Dec 2022 22:35:58 -0400 Subject: [PATCH] spellbook: Teleport directly to a minigame. --- toontown/minigame/DistributedDivingGame.py | 2 + toontown/minigame/DivingFishSpawn.py | 1 + toontown/spellbook/MagicWordIndex.py | 80 +++++++++++++++++----- 3 files changed, 65 insertions(+), 18 deletions(-) diff --git a/toontown/minigame/DistributedDivingGame.py b/toontown/minigame/DistributedDivingGame.py index 48a8064..aaa9269 100644 --- a/toontown/minigame/DistributedDivingGame.py +++ b/toontown/minigame/DistributedDivingGame.py @@ -319,6 +319,7 @@ class DistributedDivingGame(DistributedMinigame): for crab in self.crabs: crab.moveLerp.finish() crab.moveLerp = None + crab.cleanup() crab.removeNode() del crab @@ -766,6 +767,7 @@ class DistributedDivingGame(DistributedMinigame): fish.moveLerp.finish() fish.specialLerp = None fish.moveLerp = None + fish.cleanup() fish.removeNode() del fish del self.spawners[spawnerId].fishArray[spawnId] diff --git a/toontown/minigame/DivingFishSpawn.py b/toontown/minigame/DivingFishSpawn.py index 46ffd15..e8f943c 100644 --- a/toontown/minigame/DivingFishSpawn.py +++ b/toontown/minigame/DivingFishSpawn.py @@ -111,6 +111,7 @@ class DivingFishSpawn(DirectObject): fish.sound = None fish.moveLerp = None fish.specialLerp = None + fish.cleanup() fish.removeNode() del fish diff --git a/toontown/spellbook/MagicWordIndex.py b/toontown/spellbook/MagicWordIndex.py index 3f3ceff..d88731b 100644 --- a/toontown/spellbook/MagicWordIndex.py +++ b/toontown/spellbook/MagicWordIndex.py @@ -285,7 +285,7 @@ class MaxToon(MagicWord): return f"Successfully maxed {toon.getName()}!" class AbortMinigame(MagicWord): - aliases = ["exitgame", "exitminigame", "quitgame", "quitminigame"] + aliases = ["exitgame", "exitminigame", "quitgame", "quitminigame", "skipgame", "skipminigame"] desc = "Aborts an ongoing minigame." execLocation = MagicWordConfig.EXEC_LOC_CLIENT arguments = [] @@ -294,22 +294,49 @@ class AbortMinigame(MagicWord): messenger.send("minigameAbort") return "Requested minigame abort." -class RequestMinigame(MagicWord): - aliases = ["minigame"] - desc = "Requests a specified trolley minigame to be loaded." +class Minigame(MagicWord): + aliases = ["mg"] + desc = "Teleport to or request the next trolley minigame." execLocation = MagicWordConfig.EXEC_LOC_SERVER - arguments = [("minigame", str, True), ("difficulty", float, False, 0)] + arguments = [("command", str, True), ("minigame", str, False, ''), ("difficulty", float, False, 0)] def handleWord(self, invoker, avId, toon, *args): - minigame = args[0] - difficulty = args[1] - - mgId = None - mgDiff = None if args[1] == 0 else args[1] - mgKeep = None - mgSzId = None + command = args[0] + minigame = args[1] + difficulty = args[2] from toontown.toonbase import ToontownGlobals + from toontown.hood import ZoneUtil + from toontown.minigame import MinigameCreatorAI + if command in ToontownGlobals.MinigameNames: + # Shortcut + minigame = args[0] + try: + difficulty = float(args[2]) + except ValueError: + difficulty = 0 + + if toon.zoneId in MinigameCreatorAI.MinigameZoneRefs: + # Already in minigame zone, assume request + command = "request" + elif toon.zoneId == ZoneUtil.getSafeZoneId(toon.zoneId): + # Assume teleport + command = "teleport" + else: + # Request by default + command = "request" + + isTeleport = command in ('teleport', 'tp') + isRequest = command in ('request', 'next') + + mgId = None + mgDiff = None if difficulty == 0 else difficulty + mgKeep = None + mgSzId = ZoneUtil.getSafeZoneId(toon.zoneId) if isTeleport else None + + if not any ((isTeleport, isRequest)): + return f"Unknown command or minigame \"{command}\". Valid commands: \"teleport\", \"request\", or a minigame to automatically teleport or request" + try: mgId = int(minigame) if mgId not in ToontownGlobals.MinigameIDs: @@ -319,12 +346,29 @@ class RequestMinigame(MagicWord): return f"Unknown minigame name \"{minigame}\"." mgId = ToontownGlobals.MinigameNames.get(minigame) - from toontown.minigame import MinigameCreatorAI - MinigameCreatorAI.RequestMinigame[avId] = (mgId, mgKeep, mgDiff, mgSzId) - retStr = f"Successfully requested minigame \"{minigame}\"" - if mgDiff: - retStr += f" with difficulty {mgDiff}" - return retStr + "." + if any((isTeleport, isRequest)): + if isTeleport and (ZoneUtil.isDynamicZone(toon.zoneId) or not toon.zoneId == mgSzId): + return "Target needs to be in a playground to teleport to a minigame." + MinigameCreatorAI.RequestMinigame[avId] = (mgId, mgKeep, mgDiff, mgSzId) + if isTeleport: + try: + result = MinigameCreatorAI.createMinigame(self.air, [avId], mgSzId) + except: + return f"Unable to create \"{minigame}\" minigame" + + minigameZone = result['minigameZone'] + retStr = f"Teleporting {toon.getName()} to minigame \"{minigame}\"" + if mgDiff: + retStr += f" with difficulty {mgDiff}" + return retStr + "...", avId, ["minigame", "minigame", "", mgSzId, minigameZone, 0] + + # isRequest + retStr = f"Successfully requested minigame \"{minigame}\"" + if mgDiff: + retStr += f" with difficulty {mgDiff}" + return retStr + "." + + return f"Unknown command or minigame \"{command}\". Valid commands: \"teleport\", \"request\", or a minigame to automatically teleport or request" class Quests(MagicWord): aliases = ["quest", "tasks", "task", "toontasks"]