spellbook: Update Teleport magic word to be server-sided

This commit is contained in:
Samuel T 2023-11-08 23:56:52 +00:00
parent 48d88e1afe
commit e16f614b39
4 changed files with 22 additions and 18 deletions

View file

@ -619,6 +619,7 @@ dclass DistributedToon : DistributedPlayer {
setDISLname(string) ram; setDISLname(string) ram;
setDISLid(uint32) ram db airecv; setDISLid(uint32) ram db airecv;
toggleSleep() ownrecv; toggleSleep() ownrecv;
magicWordTeleport(uint32) ownrecv;
}; };
dclass DistributedCCharBase : DistributedObject { dclass DistributedCCharBase : DistributedObject {

View file

@ -657,14 +657,12 @@ class GlobalTeleport(MagicWord):
class Teleport(MagicWord): class Teleport(MagicWord):
aliases = ["tp", "goto"] aliases = ["tp", "goto"]
desc = "Teleport to a specified zone." desc = "Teleport to a specified zone."
execLocation = MagicWordConfig.EXEC_LOC_CLIENT execLocation = MagicWordConfig.EXEC_LOC_SERVER
arguments = [("zoneName", str, False, '')] arguments = [("zoneName", str, False, '')]
def handleWord(self, invoker, avId, toon, *args): def handleWord(self, invoker, avId, toon, *args):
from toontown.hood import ZoneUtil
from toontown.toonbase import ToontownGlobals from toontown.toonbase import ToontownGlobals
zoneName = args[0] zoneName = args[0]
place = base.cr.playGame.getPlace()
# Can add stuff like streets to this too if you wanted, but if you do you'll want it to be a valid zone on that street. eg: 2100 is invalid, but any value 2101 to 2156 is fine. # Can add stuff like streets to this too if you wanted, but if you do you'll want it to be a valid zone on that street. eg: 2100 is invalid, but any value 2101 to 2156 is fine.
# so if you wanted to add a silly street key, theroetically you could do something like this: 'sillystreet': ToontownGlobals.SillyStreet +1, # so if you wanted to add a silly street key, theroetically you could do something like this: 'sillystreet': ToontownGlobals.SillyStreet +1,
@ -688,22 +686,10 @@ class Teleport(MagicWord):
zone = zoneName2Id[zoneName] zone = zoneName2Id[zoneName]
except KeyError: except KeyError:
return "Unknown zone name!" return "Unknown zone name!"
hood = ZoneUtil.getHoodId(zone)
try: toon.d_magicWordTeleport(zone)
place.requestLeave({'loader': ZoneUtil.getBranchLoaderName(zone),
'where': ZoneUtil.getToonWhereName(zone),
'how': 'teleportIn',
'hoodId': hood,
'zoneId': zone,
'shardId': None,
'avId': -1})
except Exception: # Most likely cause is the place the person is in has no teleportOut state, for example, boss lobbies.
place.fsm.request('DFAReject') # We have to do this, or the Toon will be stuck.
return f"Unable to teleport {toon.getName()} to zone {zone}."
return f"Successfully teleporting {toon.getName()} to zone {zone}." return f"Requested to teleport {toon.getName()} to zone {zone}."
class ToggleSleep(MagicWord): class ToggleSleep(MagicWord):
aliases = ["sleep", "nosleep", "neversleep", "togglesleeping", "insomnia"] aliases = ["sleep", "nosleep", "neversleep", "togglesleeping", "insomnia"]

View file

@ -2594,4 +2594,18 @@ class DistributedToon(DistributedPlayer.DistributedPlayer, Toon.Toon, Distribute
if base.localAvatar.noSleep: if base.localAvatar.noSleep:
base.localAvatar.noSleep = 0 base.localAvatar.noSleep = 0
else: else:
base.localAvatar.noSleep = 1 base.localAvatar.noSleep = 1
def magicWordTeleport(self, zone):
hood = ZoneUtil.getHoodId(zone)
place = base.cr.playGame.getPlace()
try:
place.requestLeave({'loader': ZoneUtil.getBranchLoaderName(zone),
'where': ZoneUtil.getToonWhereName(zone),
'how': 'teleportIn',
'hoodId': hood,
'zoneId': zone,
'shardId': None,
'avId': -1})
except Exception: # Most likely cause is the place the person is in has no teleportOut state, for example, boss lobbies.
place.fsm.request('DFAReject') # We have to do this, or the Toon will be stuck.

View file

@ -4132,6 +4132,9 @@ class DistributedToonAI(DistributedPlayerAI.DistributedPlayerAI, DistributedSmoo
def d_toggleSleep(self): def d_toggleSleep(self):
self.sendUpdate('toggleSleep', []) self.sendUpdate('toggleSleep', [])
def d_magicWordTeleport(self, zone):
self.sendUpdate('magicWordTeleport', [zone])
@staticmethod @staticmethod
def staticGetLogicalZoneChangeAllEvent(): def staticGetLogicalZoneChangeAllEvent():
return 'DOLogicalChangeZone-all' return 'DOLogicalChangeZone-all'