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;
setDISLid(uint32) ram db airecv;
toggleSleep() ownrecv;
magicWordTeleport(uint32) ownrecv;
};
dclass DistributedCCharBase : DistributedObject {

View file

@ -657,14 +657,12 @@ class GlobalTeleport(MagicWord):
class Teleport(MagicWord):
aliases = ["tp", "goto"]
desc = "Teleport to a specified zone."
execLocation = MagicWordConfig.EXEC_LOC_CLIENT
execLocation = MagicWordConfig.EXEC_LOC_SERVER
arguments = [("zoneName", str, False, '')]
def handleWord(self, invoker, avId, toon, *args):
from toontown.hood import ZoneUtil
from toontown.toonbase import ToontownGlobals
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.
# so if you wanted to add a silly street key, theroetically you could do something like this: 'sillystreet': ToontownGlobals.SillyStreet +1,
@ -689,21 +687,9 @@ class Teleport(MagicWord):
except KeyError:
return "Unknown zone name!"
hood = ZoneUtil.getHoodId(zone)
toon.d_magicWordTeleport(zone)
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.
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):
aliases = ["sleep", "nosleep", "neversleep", "togglesleeping", "insomnia"]

View file

@ -2595,3 +2595,17 @@ class DistributedToon(DistributedPlayer.DistributedPlayer, Toon.Toon, Distribute
base.localAvatar.noSleep = 0
else:
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):
self.sendUpdate('toggleSleep', [])
def d_magicWordTeleport(self, zone):
self.sendUpdate('magicWordTeleport', [zone])
@staticmethod
def staticGetLogicalZoneChangeAllEvent():
return 'DOLogicalChangeZone-all'