From 25e353e2909227d3f199ae58e924fba461ae582a Mon Sep 17 00:00:00 2001 From: Open Toontown <57279094+opentoontown@users.noreply.github.com> Date: Fri, 28 Apr 2023 21:51:00 -0400 Subject: [PATCH] more cleanup --- toontown/battle/DistributedBattleBase.py | 315 +++++++++++++++-------- toontown/building/DistributedDoor.py | 186 ++++++++----- toontown/hood/Place.py | 179 +++++++------ toontown/safezone/Playground.py | 193 +++++++------- 4 files changed, 523 insertions(+), 350 deletions(-) diff --git a/toontown/battle/DistributedBattleBase.py b/toontown/battle/DistributedBattleBase.py index 9716ede..5e886b1 100644 --- a/toontown/battle/DistributedBattleBase.py +++ b/toontown/battle/DistributedBattleBase.py @@ -1,28 +1,55 @@ -from panda3d.core import * -from toontown.toonbase.ToonBaseGlobal import * -from direct.interval.IntervalGlobal import * -from .BattleBase import * -from direct.distributed.ClockDelta import * -from toontown.toonbase import ToontownBattleGlobals -from direct.distributed import DistributedNode -from direct.fsm import ClassicFSM, State -from direct.fsm import State -from direct.task.Task import Task -from direct.directnotify import DirectNotifyGlobal -from . import Movie -from . import MovieUtil -from toontown.suit import Suit -from direct.actor import Actor -from . import BattleProps -from direct.particles import ParticleEffect -from . import BattleParticles -from toontown.hood import ZoneUtil -from toontown.distributed import DelayDelete -from toontown.toon import TTEmote -from otp.avatar import Emote +from panda3d.core import CollisionNode, CollisionTube, LineSegs, NodePath, Point3, VBase3 +from panda3d.otp import NametagGlobals -class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): - notify = DirectNotifyGlobal.directNotify.newCategory('DistributedBattleBase') +from direct.actor.Actor import Actor +from direct.directnotify.DirectNotifyGlobal import directNotify +from direct.distributed.ClockDelta import globalClockDelta +from direct.distributed.DistributedNode import DistributedNode +from direct.fsm.ClassicFSM import ClassicFSM +from direct.fsm.State import State +from direct.interval.IntervalGlobal import Func, LerpPosInterval, Parallel, Sequence +from direct.showbase.MessengerGlobal import messenger +from direct.task.Task import Task +from direct.task.TaskManagerGlobal import taskMgr +from direct.task.Timer import Timer + +from otp.avatar.Emote import globalEmote + +from toontown.battle import BattleParticles +from toontown.battle import MovieUtil +from toontown.battle.BattleBase import ( + attackAffectsGroup, + BattleBase, + BATTLE_SMALL_VALUE, + CLIENT_INPUT_TIMEOUT, + FIRE, + HEAL, + levelAffectsGroup, + LURE, + MAX_JOIN_T, + NO_ATTACK, + NO_TRAP, + NPCSOS, + PASS, + PASS_ATTACK, + PETSOS, + SOS, + TRAP, + UN_ATTACK +) + +from toontown.battle.BattleProps import globalPropPool +from toontown.battle.Movie import Movie +from toontown.distributed.DelayDelete import DelayDelete, cleanupDelayDeletes +from toontown.hood import ZoneUtil +from toontown.suit.Suit import Suit +from toontown.toonbase import ToontownBattleGlobals +from toontown.toonbase import ToontownGlobals +from toontown.toonbase.ToonBaseGlobal import base + + +class DistributedBattleBase(DistributedNode, BattleBase): + notify = directNotify.newCategory('DistributedBattleBase') id = 0 camPos = ToontownBattleGlobals.BattleCamDefaultPos camHpr = ToontownBattleGlobals.BattleCamDefaultHpr @@ -32,9 +59,9 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): camJoinHpr = ToontownBattleGlobals.BattleCamJoinHpr def __init__(self, cr, townBattle): - DistributedNode.DistributedNode.__init__(self, cr) + DistributedNode.__init__(self, cr) NodePath.__init__(self) - self.assign(render.attachNewNode(self.uniqueBattleName('distributed-battle'))) + self.assign(base.render.attachNewNode(self.uniqueBattleName('distributed-battle'))) BattleBase.__init__(self) self.bossBattle = 0 self.townBattle = townBattle @@ -50,35 +77,34 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): self.localToonBattleEvent = self.uniqueBattleName('localtoon-battle-event') self.adjustName = self.uniqueBattleName('adjust') self.timerCountdownTaskName = self.uniqueBattleName('timer-countdown') - self.movie = Movie.Movie(self) + self.movie = Movie(self) self.timer = Timer() self.needAdjustTownBattle = 0 self.streetBattle = 1 self.levelBattle = 0 - self.localToonFsm = ClassicFSM.ClassicFSM('LocalToon', [State.State('HasLocalToon', self.enterHasLocalToon, self.exitHasLocalToon, ['NoLocalToon', 'WaitForServer']), State.State('NoLocalToon', self.enterNoLocalToon, self.exitNoLocalToon, ['HasLocalToon', 'WaitForServer']), State.State('WaitForServer', self.enterWaitForServer, self.exitWaitForServer, ['HasLocalToon', 'NoLocalToon'])], 'WaitForServer', 'WaitForServer') + self.localToonFsm = ClassicFSM('LocalToon', [State('HasLocalToon', self.enterHasLocalToon, self.exitHasLocalToon, ['NoLocalToon', 'WaitForServer']), State('NoLocalToon', self.enterNoLocalToon, self.exitNoLocalToon, ['HasLocalToon', 'WaitForServer']), State('WaitForServer', self.enterWaitForServer, self.exitWaitForServer, ['HasLocalToon', 'NoLocalToon'])], 'WaitForServer', 'WaitForServer') self.localToonFsm.enterInitialState() - self.fsm = ClassicFSM.ClassicFSM('DistributedBattle', [State.State('Off', self.enterOff, self.exitOff, ['FaceOff', + self.fsm = ClassicFSM('DistributedBattle', [State('Off', self.enterOff, self.exitOff, ['FaceOff', 'WaitForInput', 'WaitForJoin', 'MakeMovie', 'PlayMovie', 'Reward', 'Resume']), - State.State('FaceOff', self.enterFaceOff, self.exitFaceOff, ['WaitForInput']), - State.State('WaitForJoin', self.enterWaitForJoin, self.exitWaitForJoin, ['WaitForInput', 'Resume']), - State.State('WaitForInput', self.enterWaitForInput, self.exitWaitForInput, ['WaitForInput', 'PlayMovie', 'Resume']), - State.State('MakeMovie', self.enterMakeMovie, self.exitMakeMovie, ['PlayMovie', 'Resume']), - State.State('PlayMovie', self.enterPlayMovie, self.exitPlayMovie, ['WaitForInput', + State('FaceOff', self.enterFaceOff, self.exitFaceOff, ['WaitForInput']), + State('WaitForJoin', self.enterWaitForJoin, self.exitWaitForJoin, ['WaitForInput', 'Resume']), + State('WaitForInput', self.enterWaitForInput, self.exitWaitForInput, ['WaitForInput', 'PlayMovie', 'Resume']), + State('MakeMovie', self.enterMakeMovie, self.exitMakeMovie, ['PlayMovie', 'Resume']), + State('PlayMovie', self.enterPlayMovie, self.exitPlayMovie, ['WaitForInput', 'WaitForJoin', 'Reward', 'Resume']), - State.State('Reward', self.enterReward, self.exitReward, ['Resume']), - State.State('Resume', self.enterResume, self.exitResume, [])], 'Off', 'Off') + State('Reward', self.enterReward, self.exitReward, ['Resume']), + State('Resume', self.enterResume, self.exitResume, [])], 'Off', 'Off') self.fsm.enterInitialState() - self.adjustFsm = ClassicFSM.ClassicFSM('Adjust', [State.State('Adjusting', self.enterAdjusting, self.exitAdjusting, ['NotAdjusting']), State.State('NotAdjusting', self.enterNotAdjusting, self.exitNotAdjusting, ['Adjusting'])], 'NotAdjusting', 'NotAdjusting') + self.adjustFsm = ClassicFSM('Adjust', [State('Adjusting', self.enterAdjusting, self.exitAdjusting, ['NotAdjusting']), State('NotAdjusting', self.enterNotAdjusting, self.exitNotAdjusting, ['Adjusting'])], 'NotAdjusting', 'NotAdjusting') self.adjustFsm.enterInitialState() self.interactiveProp = None - return def uniqueBattleName(self, name): DistributedBattleBase.id += 1 @@ -86,9 +112,9 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): def generate(self): self.notify.debug('generate(%s)' % self.doId) - DistributedNode.DistributedNode.generate(self) + DistributedNode.generate(self) self.__battleCleanedUp = 0 - self.reparentTo(render) + self.reparentTo(base.render) self._skippingRewardMovie = False def storeInterval(self, interval, name): @@ -96,12 +122,13 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): ival = self.activeIntervals[name] if hasattr(ival, 'delayDelete') or hasattr(ival, 'delayDeletes'): self.clearInterval(name, finish=1) + self.activeIntervals[name] = interval def __cleanupIntervals(self): for interval in list(self.activeIntervals.values()): interval.finish() - DelayDelete.cleanupDelayDeletes(interval) + cleanupDelayDeletes(interval) self.activeIntervals = {} @@ -112,8 +139,9 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): ival.finish() else: ival.pause() + if name in self.activeIntervals: - DelayDelete.cleanupDelayDeletes(ival) + cleanupDelayDeletes(ival) if name in self.activeIntervals: del self.activeIntervals[name] else: @@ -127,7 +155,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): def disable(self): self.notify.debug('disable(%s)' % self.doId) self.cleanupBattle() - DistributedNode.DistributedNode.disable(self) + DistributedNode.disable(self) def battleCleanedUp(self): return self.__battleCleanedUp @@ -135,6 +163,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): def cleanupBattle(self): if self.__battleCleanedUp: return + self.notify.debug('cleanupBattle(%s)' % self.doId) self.__battleCleanedUp = 1 self.__cleanupIntervals() @@ -142,12 +171,14 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): if self.hasLocalToon(): self.removeLocalToon() base.camLens.setFov(ToontownGlobals.DefaultCameraFov) + self.localToonFsm.request('WaitForServer') self.ignoreAll() for suit in self.suits: if suit.battleTrap != NO_TRAP: self.notify.debug('250 calling self.removeTrap, suit=%d' % suit.doId) self.removeTrap(suit) + suit.battleTrap = NO_TRAP suit.battleTrapProp = None self.notify.debug('253 suit.battleTrapProp = None') @@ -166,7 +197,6 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): self.__stopTimer() self.__cleanupIntervals() self._removeMembersKeep() - return def delete(self): self.notify.debug('delete(%s)' % self.doId) @@ -180,13 +210,12 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): self.adjustFsm = None self.__stopTimer() self.timer = None - DistributedNode.DistributedNode.delete(self) - return + DistributedNode.delete(self) def loadTrap(self, suit, trapid): self.notify.debug('loadTrap() trap: %d suit: %d' % (trapid, suit.doId)) - trapName = AvProps[TRAP][trapid] - trap = BattleProps.globalPropPool.getProp(trapName) + trapName = ToontownBattleGlobals.AvProps[TRAP][trapid] + trap = globalPropPool.getProp(trapName) suit.battleTrap = trapid suit.battleTrapIsFresh = 0 suit.battleTrapProp = trap @@ -195,6 +224,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): pass else: trap.wrtReparentTo(suit) + distance = MovieUtil.SUIT_TRAP_DISTANCE if trapName == 'rake': distance = MovieUtil.SUIT_TRAP_RAKE_DISTANCE @@ -212,8 +242,9 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): sparks = BattleParticles.createParticleEffect(file='tnt') trap.sparksEffect = sparks sparks.start(tip) + trap.setPos(0, distance, 0) - if isinstance(trap, Actor.Actor): + if isinstance(trap, Actor): frame = trap.getNumFrames(trapName) - 1 trap.pose(trapName, frame) @@ -223,7 +254,8 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): self.notify.debug('suit.battleTrapProp == None, suit.battleTrap=%s setting to NO_TRAP, returning' % suit.battleTrap) suit.battleTrap = NO_TRAP return - if suit.battleTrap == UBER_GAG_LEVEL_INDEX: + + if suit.battleTrap == ToontownBattleGlobals.UBER_GAG_LEVEL_INDEX: if removeTrainTrack: self.notify.debug('doing removeProp on traintrack') MovieUtil.removeProp(suit.battleTrapProp) @@ -233,17 +265,16 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): self.notify.debug('351 otherSuit=%d otherSuit.battleTrapProp = None' % otherSuit.doId) otherSuit.battleTrap = NO_TRAP otherSuit.battleTrapIsFresh = 0 - else: self.notify.debug('deliberately not doing removeProp on traintrack') else: self.notify.debug('suit.battleTrap != UBER_GAG_LEVEL_INDEX') MovieUtil.removeProp(suit.battleTrapProp) + suit.battleTrapProp = None self.notify.debug('360 suit.battleTrapProp = None') suit.battleTrap = NO_TRAP suit.battleTrapIsFresh = 0 - return def pause(self): self.timer.stop() @@ -256,21 +287,19 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): if s.doId == id: return s - return None - def findToon(self, id): toon = self.getToon(id) if toon == None: return + for t in self.toons: if t == toon: return t - return - def isSuitLured(self, suit): if self.luredSuits.count(suit) != 0: return 1 + return 0 def unlureSuit(self, suit): @@ -278,19 +307,18 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): if self.luredSuits.count(suit) != 0: self.luredSuits.remove(suit) self.needAdjustTownBattle = 1 - return None def lureSuit(self, suit): self.notify.debug('movie luring suit %s' % suit.doId) if self.luredSuits.count(suit) == 0: self.luredSuits.append(suit) self.needAdjustTownBattle = 1 - return None def getActorPosHpr(self, actor, actorList = []): - if isinstance(actor, Suit.Suit): + if isinstance(actor, Suit): if actorList == []: actorList = self.activeSuits + if actorList.count(actor) != 0: numSuits = len(actorList) - 1 index = actorList.index(actor) @@ -301,6 +329,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): else: if actorList == []: actorList = self.activeToons + if actorList.count(actor) != 0: numToons = len(actorList) - 1 index = actorList.index(actor) @@ -339,12 +368,14 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): def setState(self, state, timestamp): if self.__battleCleanedUp: return + self.notify.debug('setState(%s)' % state) self.fsm.request(state, [globalClockDelta.localElapsedTime(timestamp)]) def setMembers(self, suits, suitsJoining, suitsPending, suitsActive, suitsLured, suitTraps, toons, toonsJoining, toonsPending, toonsActive, toonsRunning, timestamp): if self.__battleCleanedUp: return + self.notify.debug('setMembers() - suits: %s suitsJoining: %s suitsPending: %s suitsActive: %s suitsLured: %s suitTraps: %s toons: %s toonsJoining: %s toonsPending: %s toonsActive: %s toonsRunning: %s' % (suits, suitsJoining, suitsPending, @@ -373,7 +404,6 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): suit.battleTrapProp = None self.notify.debug('496 suit.battleTrapProp = None') suit.battleTrapIsFresh = 0 - else: self.notify.warning('setMembers() - no suit in repository: %d' % s) self.suits.append(None) @@ -391,6 +421,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): if not trainTrap.isEmpty(): self.notify.debug('removing old train trap when 4 suits died') trainTrap.removeNode() + for s in suitsJoining: suit = self.suits[int(s)] if suit != None and self.joiningSuits.count(suit) == 0: @@ -428,12 +459,14 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): trapid = int(s) if trapid == 9: trapid = -1 + suit = self.suits[index] index += 1 if suit != None: if (trapid == NO_TRAP or trapid != suit.battleTrap) and suit.battleTrapProp != None: self.notify.debug('569 calling self.removeTrap, suit=%d' % suit.doId) self.removeTrap(suit) + if trapid != NO_TRAP and suit.battleTrapProp == None: if self.fsm.getCurrentState().getName() != 'PlayMovie': self.loadTrap(suit, trapid) @@ -454,6 +487,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): self.suits = validSuits self.needAdjustTownBattle = 1 + oldtoons = self.toons self.toons = [] toonGone = 0 @@ -464,6 +498,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): self.toons.append(None) toonGone = 1 continue + self.toons.append(toon) if oldtoons.count(toon) == 0: self.notify.debug('setMembers() - add toon: %d' % toon.doId) @@ -506,6 +541,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): if len(activeSuits) > 0 or len(activeToons) > 0: self.__makeAvsActive(activeSuits, activeToons) + if toonGone == 1: validToons = [] for toon in self.toons: @@ -513,15 +549,19 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): validToons.append(toon) self.toons = validToons + if len(self.activeToons) > 0: self.__requestAdjustTownBattle() + currStateName = self.localToonFsm.getCurrentState().getName() if self.toons.count(base.localAvatar): if oldtoons.count(base.localAvatar) == 0: self.notify.debug('setMembers() - local toon just joined') if self.streetBattle == 1: base.cr.playGame.getPlace().enterZone(self.zoneId) + self.localToonJustJoined = 1 + if currStateName != 'HasLocalToon': self.localToonFsm.request('HasLocalToon') else: @@ -529,19 +569,23 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): self.notify.debug('setMembers() - local toon just ran') if self.levelBattle: self.unlockLevelViz() + if currStateName != 'NoLocalToon': self.localToonFsm.request('NoLocalToon') + return oldtoons def adjust(self, timestamp): if self.__battleCleanedUp: return + self.notify.debug('adjust(%f) from server' % globalClockDelta.localElapsedTime(timestamp)) self.adjustFsm.request('Adjusting', [globalClockDelta.localElapsedTime(timestamp)]) def setMovie(self, active, toons, suits, id0, tr0, le0, tg0, hp0, ac0, hpb0, kbb0, died0, revive0, id1, tr1, le1, tg1, hp1, ac1, hpb1, kbb1, died1, revive1, id2, tr2, le2, tg2, hp2, ac2, hpb2, kbb2, died2, revive2, id3, tr3, le3, tg3, hp3, ac3, hpb3, kbb3, died3, revive3, sid0, at0, stg0, dm0, sd0, sb0, st0, sid1, at1, stg1, dm1, sd1, sb1, st1, sid2, at2, stg2, dm2, sd2, sb2, st2, sid3, at3, stg3, dm3, sd3, sb3, st3): if self.__battleCleanedUp: return + self.notify.debug('setMovie()') if int(active) == 1: self.notify.debug('setMovie() - movie is active') @@ -550,6 +594,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): def setChosenToonAttacks(self, ids, tracks, levels, targets): if self.__battleCleanedUp: return + self.notify.debug('setChosenToonAttacks() - (%s), (%s), (%s), (%s)' % (ids, tracks, levels, @@ -569,8 +614,10 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): levels.append(-1) targetIndices.append(-1) continue + if toon == base.localAvatar: localToonInList = 1 + toonIndices.append(self.activeToons.index(toon)) if track == SOS: targetIndex = -1 @@ -603,6 +650,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): targetIndex = self.activeSuits.index(target) else: targetIndex = -1 + targetIndices.append(targetIndex) for i in range(4 - len(ids)): @@ -619,12 +667,13 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): if unAttack == 1 and self.fsm.getCurrentState().getName() == 'WaitForInput': if self.townBattle.fsm.getCurrentState().getName() != 'Attack': self.townBattle.setState('Attack') + self.townBattle.updateChosenAttacks(self.townBattleAttacks[0], self.townBattleAttacks[1], self.townBattleAttacks[2], self.townBattleAttacks[3]) - return def setBattleExperience(self, id0, origExp0, earnedExp0, origQuests0, items0, missedItems0, origMerits0, merits0, parts0, id1, origExp1, earnedExp1, origQuests1, items1, missedItems1, origMerits1, merits1, parts1, id2, origExp2, earnedExp2, origQuests2, items2, missedItems2, origMerits2, merits2, parts2, id3, origExp3, earnedExp3, origQuests3, items3, missedItems3, origMerits3, merits3, parts3, deathList, uberList, helpfulToonsList): if self.__battleCleanedUp: return + self.movie.genRewardDicts(id0, origExp0, earnedExp0, origQuests0, items0, missedItems0, origMerits0, merits0, parts0, id1, origExp1, earnedExp1, origQuests1, items1, missedItems1, origMerits1, merits1, parts1, id2, origExp2, earnedExp2, origQuests2, items2, missedItems2, origMerits2, merits2, parts2, id3, origExp3, earnedExp3, origQuests3, items3, missedItems3, origMerits3, merits3, parts3, deathList, uberList, helpfulToonsList) def __listenForUnexpectedExit(self, toon): @@ -644,10 +693,10 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): def delayDeleteMembers(self): membersKeep = [] for t in self.toons: - membersKeep.append(DelayDelete.DelayDelete(t, 'delayDeleteMembers')) + membersKeep.append(DelayDelete(t, 'delayDeleteMembers')) for s in self.suits: - membersKeep.append(DelayDelete.DelayDelete(s, 'delayDeleteMembers')) + membersKeep.append(DelayDelete(s, 'delayDeleteMembers')) self._removeMembersKeep() self.membersKeep = membersKeep @@ -658,45 +707,53 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): delayDelete.destroy() self.membersKeep = None - return def __removeSuit(self, suit): self.notify.debug('__removeSuit(%d)' % suit.doId) if self.suits.count(suit) != 0: self.suits.remove(suit) + if self.joiningSuits.count(suit) != 0: self.joiningSuits.remove(suit) + if self.pendingSuits.count(suit) != 0: self.pendingSuits.remove(suit) + if self.activeSuits.count(suit) != 0: self.activeSuits.remove(suit) + self.suitGone = 1 if suit.battleTrap != NO_TRAP: self.notify.debug('882 calling self.removeTrap, suit=%d' % suit.doId) self.removeTrap(suit) + suit.battleTrap = NO_TRAP suit.battleTrapProp = None self.notify.debug('883 suit.battleTrapProp = None') suit.battleTrapIsFresh = 0 - return def __removeToon(self, toon, unexpected = 0): self.notify.debug('__removeToon(%d)' % toon.doId) self.exitedToons.append(toon) if self.toons.count(toon) != 0: self.toons.remove(toon) + if self.joiningToons.count(toon) != 0: self.clearInterval(self.taskName('to-pending-toon-%d' % toon.doId)) if toon in self.joiningToons: self.joiningToons.remove(toon) + if self.pendingToons.count(toon) != 0: self.pendingToons.remove(toon) + if self.activeToons.count(toon) != 0: self.activeToons.remove(toon) + if self.runningToons.count(toon) != 0: self.clearInterval(self.taskName('running-%d' % toon.doId), finish=1) if toon in self.runningToons: self.runningToons.remove(toon) + self.ignore(toon.uniqueName('disable')) self.ignore(toon.uniqueName('died')) self.toonGone = 1 @@ -704,28 +761,33 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): self.removeLocalToon() self.__teleportToSafeZone(toon) return 1 + return 0 def removeLocalToon(self): if self._skippingRewardMovie: return + if base.cr.playGame.getPlace() != None: base.cr.playGame.getPlace().setState('walk') + base.localAvatar.earnedExperience = None self.localToonFsm.request('NoLocalToon') - return def removeInactiveLocalToon(self, toon): self.notify.debug('removeInactiveLocalToon(%d)' % toon.doId) self.exitedToons.append(toon) if self.toons.count(toon) != 0: self.toons.remove(toon) + if self.joiningToons.count(toon) != 0: self.clearInterval(self.taskName('to-pending-toon-%d' % toon.doId), finish=1) if toon in self.joiningToons: self.joiningToons.remove(toon) + if self.pendingToons.count(toon) != 0: self.pendingToons.remove(toon) + self.ignore(toon.uniqueName('disable')) self.ignore(toon.uniqueName('died')) base.cr.playGame.getPlace().setState('walk') @@ -733,7 +795,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): def __createJoinInterval(self, av, destPos, destHpr, name, ts, callback, toon = 0): joinTrack = Sequence() - joinTrack.append(Func(Emote.globalEmote.disableAll, av, 'dbattlebase, createJoinInterval')) + joinTrack.append(Func(globalEmote.disableAll, av, 'dbattlebase, createJoinInterval')) avPos = av.getPos(self) avPos = Point3(avPos[0], avPos[1], 0.0) av.setShadowHeight(0) @@ -746,6 +808,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): else: timeToDest = self.calcToonMoveTime(avPos, destPos) joinTrack.append(Func(av.loop, 'run')) + if timeToDest > BATTLE_SMALL_VALUE: joinTrack.append(LerpPosInterval(av, timeToDest, destPos, other=self)) totalTime = timeToDest @@ -761,14 +824,17 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): timeToPerimeter = self.calcToonMoveTime(plist[0], avPos) timePerSegment = 10.0 / BattleBase.toonSpeed timeToDest = self.calcToonMoveTime(BattleBase.posE, destPos) + totalTime = timeToPerimeter + (len(plist) - 1) * timePerSegment + timeToDest if totalTime > MAX_JOIN_T: self.notify.warning('__createJoinInterval() - time: %f' % totalTime) + joinTrack.append(Func(av.headsUp, self, plist[0])) if toon == 0: joinTrack.append(Func(av.loop, 'walk')) else: joinTrack.append(Func(av.loop, 'run')) + joinTrack.append(LerpPosInterval(av, timeToPerimeter, plist[0], other=self)) for p in plist[1:]: joinTrack.append(Func(av.headsUp, self, p)) @@ -776,12 +842,14 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): joinTrack.append(Func(av.headsUp, self, destPos)) joinTrack.append(LerpPosInterval(av, timeToDest, destPos, other=self)) + joinTrack.append(Func(av.loop, 'neutral')) joinTrack.append(Func(av.headsUp, self, Point3(0, 0, 0))) tval = totalTime - ts if tval < 0: tval = totalTime - joinTrack.append(Func(Emote.globalEmote.releaseAll, av, 'dbattlebase, createJoinInterval')) + + joinTrack.append(Func(globalEmote.releaseAll, av, 'dbattlebase, createJoinInterval')) joinTrack.append(Func(callback, av, tval)) if av == base.localAvatar: camTrack = Sequence() @@ -790,9 +858,9 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): base.camLens.setFov(fov) camTrack.append(Func(setCamFov, self.camFov)) - camTrack.append(Func(camera.wrtReparentTo, self)) - camTrack.append(Func(camera.setPos, self.camJoinPos)) - camTrack.append(Func(camera.setHpr, self.camJoinHpr)) + camTrack.append(Func(base.camera.wrtReparentTo, self)) + camTrack.append(Func(base.camera.setPos, self.camJoinPos)) + camTrack.append(Func(base.camera.setHpr, self.camJoinHpr)) return Parallel(joinTrack, camTrack, name=name) else: return Sequence(joinTrack, name=name) @@ -808,7 +876,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): trackName = self.taskName('to-pending-suit-%d' % suit.doId) track = self.__createJoinInterval(suit, pos, hpr, trackName, ts, self.__handleSuitJoinDone) track.start(ts) - track.delayDelete = DelayDelete.DelayDelete(suit, 'makeSuitJoin') + track.delayDelete = DelayDelete(suit, 'makeSuitJoin') self.storeInterval(track, trackName) if ToontownBattleGlobals.SkipMovie: track.finish() @@ -823,6 +891,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): self.clearInterval(self.taskName('to-pending-suit-%d' % suit.doId), finish=1) if self.joiningSuits.count(suit): self.joiningSuits.remove(suit) + self.pendingSuits.append(suit) def __teleportToSafeZone(self, toon): @@ -832,6 +901,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): target_sz = ZoneUtil.getSafeZoneId(self.zoneId) else: target_sz = ZoneUtil.getSafeZoneId(base.localAvatar.defaultZone) + base.cr.playGame.getPlace().fsm.request('teleportOut', [{'loader': ZoneUtil.getLoaderName(target_sz), 'where': ZoneUtil.getWhereName(target_sz, 1), 'how': 'teleportIn', @@ -840,7 +910,6 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): 'shardId': None, 'avId': -1, 'battle': 1}]) - return def __makeToonJoin(self, toon, pendingToons, ts): self.notify.debug('__makeToonJoin(%d)' % toon.doId) @@ -853,8 +922,9 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): track = self.__createJoinInterval(toon, pos, hpr, trackName, ts, self.__handleToonJoinDone, toon=1) if toon != base.localAvatar: toon.animFSM.request('off') + track.start(ts) - track.delayDelete = DelayDelete.DelayDelete(toon, '__makeToonJoin') + track.delayDelete = DelayDelete(toon, '__makeToonJoin') self.storeInterval(track, trackName) def __handleToonJoinDone(self, toon, ts): @@ -867,6 +937,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): self.clearInterval(self.taskName('to-pending-toon-%d' % toon.doId), finish=1) if self.joiningToons.count(toon): self.joiningToons.remove(toon) + spotIndex = len(self.pendingToons) self.pendingToons.append(toon) openSpot = self.toonPendingPoints[spotIndex] @@ -874,8 +945,6 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): hpr = VBase3(openSpot[1], 0.0, 0.0) toon.loop('neutral') toon.setPosHpr(self, pos, hpr) - if base.localAvatar == toon: - currStateName = self.fsm.getCurrentState().getName() def __makeAvsActive(self, suits, toons): self.notify.debug('__makeAvsActive()') @@ -884,8 +953,10 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): if self.joiningSuits.count(s): self.notify.warning('suit: %d was in joining list!' % s.doId) self.joiningSuits.remove(s) + if self.pendingSuits.count(s): self.pendingSuits.remove(s) + self.notify.debug('__makeAvsActive() - suit: %d' % s.doId) self.activeSuits.append(s) @@ -897,14 +968,17 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): else: spos = Point3(suitPos[0], suitPos[1] - MovieUtil.SUIT_LURE_DISTANCE, suitPos[2]) suit.setPosHpr(self, spos, suitHpr) + suit.loop('neutral') for toon in toons: if self.joiningToons.count(toon): self.notify.warning('toon: %d was in joining list!' % toon.doId) self.joiningToons.remove(toon) + if self.pendingToons.count(toon): self.pendingToons.remove(toon) + self.notify.debug('__makeAvsActive() - toon: %d' % toon.doId) if self.activeToons.count(toon) == 0: self.activeToons.append(toon) @@ -927,16 +1001,18 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): self.notify.debug('__makeToonRun(%d)' % toon.doId) if self.activeToons.count(toon): self.activeToons.remove(toon) + self.runningToons.append(toon) self.toonGone = 1 self.__stopTimer() if self.localToonRunning(): self.townBattle.setState('Off') + runMTrack = MovieUtil.getToonTeleportOutInterval(toon) runName = self.taskName('running-%d' % toon.doId) self.notify.debug('duration: %f' % runMTrack.getDuration()) runMTrack.start(ts) - runMTrack.delayDelete = DelayDelete.DelayDelete(toon, '__makeToonRun') + runMTrack.delayDelete = DelayDelete(toon, '__makeToonRun') self.storeInterval(runMTrack, runName) def getToon(self, toonId): @@ -944,8 +1020,6 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): return self.cr.doId2do[toonId] else: self.notify.warning('getToon() - toon: %d not in repository!' % toonId) - return None - return None def d_toonRequestJoin(self, toonId, pos): self.notify.debug('network:toonRequestJoin()') @@ -993,27 +1067,25 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): def enterOff(self, ts = 0): self.localToonFsm.requestFinalState() - return None def exitOff(self): - return None + pass def enterFaceOff(self, ts = 0): - return None + pass def exitFaceOff(self): - return None + pass def enterWaitForJoin(self, ts = 0): self.notify.debug('enterWaitForJoin()') - return None def exitWaitForJoin(self): - return None + pass def __enterLocalToonWaitForInput(self): self.notify.debug('enterLocalToonWaitForInput()') - camera.setPosHpr(self.camPos, self.camHpr) + base.camera.setPosHpr(self.camPos, self.camHpr) base.camLens.setFov(self.camMenuFov) NametagGlobals.setMasterArrowsOn(0) self.townBattle.setState('Attack') @@ -1025,6 +1097,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): self.notify.warning('startTimer() - ts: %f timeout: %f' % (ts, CLIENT_INPUT_TIMEOUT)) self.__timedOut() return + self.timer.startCallback(CLIENT_INPUT_TIMEOUT - ts, self.__timedOut) timeTask = Task.loop(Task(self.__countdown), Task.pause(0.2)) taskMgr.add(timeTask, self.timerCountdownTaskName) @@ -1040,19 +1113,21 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): else: self.notify.warning('__countdown has tried to update a timer that has been deleted. Stopping timer') self.__stopTimer() - return Task.done + + return task.done def enterWaitForInput(self, ts = 0): self.notify.debug('enterWaitForInput()') if self.interactiveProp: self.interactiveProp.gotoBattleCheer() + self.choseAttackAlready = 0 if self.localToonActive(): self.__enterLocalToonWaitForInput() self.startTimer(ts) + if self.needAdjustTownBattle == 1: self.__adjustTownBattle() - return None def exitWaitForInput(self): self.notify.debug('exitWaitForInput()') @@ -1061,7 +1136,6 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): base.camLens.setFov(self.camFov) self.ignore(self.localToonBattleEvent) self.__stopTimer() - return None def __handleLocalToonBattleEvent(self, response): mode = response['mode'] @@ -1089,6 +1163,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): targetId = self.activeSuits[target].doId else: target = -1 + if len(self.luredSuits) > 0: if track == TRAP or track == LURE and not levelAffectsGroup(LURE, level): if target != -1: @@ -1104,6 +1179,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): track = -1 level = -1 targetId = -1 + if track == TRAP: if target != -1: if attackAffectsGroup(track, level): @@ -1115,6 +1191,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): track = -1 level = -1 targetId = -1 + self.d_requestAttack(base.localAvatar.doId, track, level, targetId) elif mode == 'Run': self.notify.debug('got a run') @@ -1141,6 +1218,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): messenger.send(proxyGenerateMessage) else: self.d_requestPetProxy(base.localAvatar.doId, petProxyId) + noAttack = 1 elif mode == 'Pass': targetId = response['id'] @@ -1156,6 +1234,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): else: self.notify.warning('unknown battle response') return + if noAttack == 1: self.choseAttackAlready = 0 else: @@ -1164,6 +1243,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): def __timedOut(self): if self.choseAttackAlready == 1: return + self.notify.debug('WaitForInput timed out') if self.localToonActive(): self.notify.debug('battle timed out') @@ -1171,27 +1251,27 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): def enterMakeMovie(self, ts = 0): self.notify.debug('enterMakeMovie()') - return None def exitMakeMovie(self): - return None + pass def enterPlayMovie(self, ts): self.notify.debug('enterPlayMovie()') self.delayDeleteMembers() if self.hasLocalToon(): NametagGlobals.setMasterArrowsOn(0) + if ToontownBattleGlobals.SkipMovie: self.movie.play(ts, self.__handleMovieDone) self.movie.finish() else: self.movie.play(ts, self.__handleMovieDone) - return None def __handleMovieDone(self): self.notify.debug('__handleMovieDone()') if self.hasLocalToon(): self.d_movieDone(base.localAvatar.doId) + self.movie.reset() def exitPlayMovie(self): @@ -1214,7 +1294,6 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): 0, 0, 0]) - return None def hasLocalToon(self): return self.toons.count(base.localAvatar) > 0 @@ -1235,59 +1314,61 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): self.notify.debug('enterHasLocalToon()') if base.cr.playGame.getPlace() != None: base.cr.playGame.getPlace().setState('battle', self.localToonBattleEvent) - if localAvatar and hasattr(localAvatar, 'inventory') and localAvatar.inventory: - localAvatar.inventory.setInteractivePropTrackBonus(self.interactivePropTrackBonus) - camera.wrtReparentTo(self) + if base.localAvatar and hasattr(base.localAvatar, 'inventory') and base.localAvatar.inventory: + base.localAvatar.inventory.setInteractivePropTrackBonus(self.interactivePropTrackBonus) + + base.camera.wrtReparentTo(self) base.camLens.setFov(self.camFov) - return def exitHasLocalToon(self): self.ignore(self.localToonBattleEvent) self.__stopTimer() - if localAvatar and hasattr(localAvatar, 'inventory') and localAvatar.inventory: - localAvatar.inventory.setInteractivePropTrackBonus(-1) + if base.localAvatar and hasattr(base.localAvatar, 'inventory') and base.localAvatar.inventory: + base.localAvatar.inventory.setInteractivePropTrackBonus(-1) + stateName = None place = base.cr.playGame.getPlace() if place: stateName = place.fsm.getCurrentState().getName() + if stateName == 'died': self.movie.reset() - camera.reparentTo(render) - camera.setPosHpr(localAvatar, 5.2, 5.45, localAvatar.getHeight() * 0.66, 131.5, 3.6, 0) + base.camera.reparentTo(base.render) + base.camera.setPosHpr(base.localAvatar, 5.2, 5.45, base.localAvatar.getHeight() * 0.66, 131.5, 3.6, 0) else: - camera.wrtReparentTo(base.localAvatar) + base.camera.wrtReparentTo(base.localAvatar) messenger.send('localToonLeftBattle') + base.camLens.setFov(ToontownGlobals.DefaultCameraFov) - return def enterNoLocalToon(self): self.notify.debug('enterNoLocalToon()') - return None def exitNoLocalToon(self): - return None + pass def setSkippingRewardMovie(self): self._skippingRewardMovie = True def enterWaitForServer(self): self.notify.debug('enterWaitForServer()') - return None def exitWaitForServer(self): - return None + pass def createAdjustInterval(self, av, destPos, destHpr, toon = 0, run = 0): if run == 1: adjustTime = self.calcToonMoveTime(destPos, av.getPos(self)) else: adjustTime = self.calcSuitMoveTime(destPos, av.getPos(self)) + self.notify.debug('creating adjust interval for: %d' % av.doId) adjustTrack = Sequence() if run == 1: adjustTrack.append(Func(av.loop, 'run')) else: adjustTrack.append(Func(av.loop, 'walk')) + adjustTrack.append(Func(av.headsUp, self, destPos)) adjustTrack.append(LerpPosInterval(av, adjustTime, destPos, other=self)) adjustTrack.append(Func(av.setHpr, self, destHpr)) @@ -1307,9 +1388,11 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): destPos = point[0] if self.isSuitLured(suit) == 1: destPos = Point3(destPos[0], destPos[1] - MovieUtil.SUIT_LURE_DISTANCE, destPos[2]) + if pos != destPos: destHpr = VBase3(point[1], 0.0, 0.0) adjustTrack.append(self.createAdjustInterval(suit, destPos, destHpr)) + index += 1 for suit in self.pendingSuits: @@ -1330,6 +1413,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): if pos != destPos: destHpr = VBase3(point[1], 0.0, 0.0) adjustTrack.append(self.createAdjustInterval(toon, destPos, destHpr)) + index += 1 for toon in self.pendingToons: @@ -1377,6 +1461,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): for suit in self.luredSuits: if suit not in self.activeSuits: self.notify.error('lured suit not in self.activeSuits') + luredSuits.append(self.activeSuits.index(suit)) trappedSuits = [] @@ -1387,21 +1472,23 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): self.townBattle.adjustCogsAndToons(self.activeSuits, luredSuits, trappedSuits, self.activeToons) if hasattr(self, 'townBattleAttacks'): self.townBattle.updateChosenAttacks(self.townBattleAttacks[0], self.townBattleAttacks[1], self.townBattleAttacks[2], self.townBattleAttacks[3]) + self.needAdjustTownBattle = 0 def __adjustDone(self): self.notify.debug('__adjustDone()') if self.hasLocalToon(): self.d_adjustDone(base.localAvatar.doId) + self.adjustFsm.request('NotAdjusting') def enterAdjusting(self, ts): self.notify.debug('enterAdjusting()') if self.localToonActive(): self.__stopTimer() + self.delayDeleteMembers() self.__adjust(ts, self.__handleAdjustDone) - return None def exitAdjusting(self): self.notify.debug('exitAdjusting()') @@ -1410,14 +1497,12 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): currStateName = self.fsm.getCurrentState().getName() if currStateName == 'WaitForInput' and self.localToonActive(): self.startTimer() - return None def enterNotAdjusting(self): self.notify.debug('enterNotAdjusting()') - return None def exitNotAdjusting(self): - return None + pass def visualize(self): try: @@ -1440,7 +1525,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): p = BattleBase.allPoints[0] lsegs.drawTo(p[0], p[1], p[2]) self.vis = self.attachNewNode(lsegs.create()) - self.reparentTo(render) + self.reparentTo(base.render) self.isVisualized = 1 def setupCollisions(self, name): @@ -1466,14 +1551,17 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): if self.fsm.getCurrentState().getName() == 'Off': self.notify.debug('ignoring collision in Off state') return + if not base.localAvatar.wantBattles: return + if self._skippingRewardMovie: return + base.cr.playGame.getPlace().setState('WaitForBattle') toon = base.localAvatar self.d_toonRequestJoin(toon.doId, toon.getPos(self)) - base.localAvatar.preBattleHpr = base.localAvatar.getHpr(render) + base.localAvatar.preBattleHpr = base.localAvatar.getHpr(base.render) self.localToonFsm.request('WaitForServer') self.onWaitingForJoin() @@ -1485,6 +1573,7 @@ class DistributedBattleBase(DistributedNode.DistributedNode, BattleBase): place = self.cr.playGame.getPlace() if place.fsm.getCurrentState().getName() == 'WaitForBattle': place.setState('walk') + self.localToonFsm.request('NoLocalToon') def disableCollision(self): diff --git a/toontown/building/DistributedDoor.py b/toontown/building/DistributedDoor.py index 42c27e1..fa6af36 100644 --- a/toontown/building/DistributedDoor.py +++ b/toontown/building/DistributedDoor.py @@ -1,48 +1,66 @@ -from toontown.toonbase.ToonBaseGlobal import * -from panda3d.core import * -from direct.interval.IntervalGlobal import * -from direct.distributed.ClockDelta import * -from toontown.toonbase import ToontownGlobals -from direct.directnotify import DirectNotifyGlobal -from direct.fsm import ClassicFSM, State -from direct.distributed import DistributedObject -from toontown.hood import ZoneUtil -from toontown.suit import Suit -from toontown.distributed import DelayDelete -from . import FADoorCodes -from direct.task.Task import Task -from . import DoorTypes -from toontown.toontowngui import TTDialog -from toontown.toonbase import TTLocalizer -from toontown.toontowngui import TeaserPanel -from toontown.distributed.DelayDeletable import DelayDeletable -if (__debug__): - import pdb +from panda3d.core import NodePath, Point3, VBase3, Vec3 +from panda3d.otp import Nametag, NametagGroup -class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): +from direct.directnotify.DirectNotifyGlobal import directNotify +from direct.distributed.ClockDelta import globalClockDelta +from direct.distributed.DistributedObject import DistributedObject +from direct.fsm.ClassicFSM import ClassicFSM +from direct.fsm.State import State +from direct.interval.IntervalGlobal import ( + ActorInterval, + Func, + HprInterval, + LerpHprInterval, + LerpPosHprInterval, + LerpPosInterval, + Parallel, + PosHprInterval, + Sequence, + SoundInterval, + Wait +) + +from direct.showbase.MessengerGlobal import messenger +from direct.task.TaskManagerGlobal import taskMgr + +from toontown.building import DoorTypes +from toontown.building import FADoorCodes +from toontown.distributed.DelayDeletable import DelayDeletable +from toontown.distributed.DelayDelete import DelayDelete, cleanupDelayDeletes +from toontown.hood import ZoneUtil +from toontown.suit.Suit import Suit +from toontown.toonbase import ToontownGlobals +from toontown.toonbase import TTLocalizer +from toontown.toonbase.ToonBaseGlobal import base +from toontown.toontowngui import TTDialog +from toontown.toontowngui.TeaserPanel import TeaserPanel + + +class DistributedDoor(DistributedObject, DelayDeletable): + notify = directNotify.newCategory('DistributedDoor') def __init__(self, cr): - DistributedObject.DistributedObject.__init__(self, cr) + DistributedObject.__init__(self, cr) self.openSfx = base.loader.loadSfx('phase_3.5/audio/sfx/Door_Open_1.ogg') self.closeSfx = base.loader.loadSfx('phase_3.5/audio/sfx/Door_Close_1.ogg') self.nametag = None - self.fsm = ClassicFSM.ClassicFSM('DistributedDoor_right', [State.State('off', self.enterOff, self.exitOff, ['closing', + self.fsm = ClassicFSM('DistributedDoor_right', [State('off', self.enterOff, self.exitOff, ['closing', 'closed', 'opening', 'open']), - State.State('closing', self.enterClosing, self.exitClosing, ['closed', 'opening']), - State.State('closed', self.enterClosed, self.exitClosed, ['opening']), - State.State('opening', self.enterOpening, self.exitOpening, ['open']), - State.State('open', self.enterOpen, self.exitOpen, ['closing', 'open'])], 'off', 'off') + State('closing', self.enterClosing, self.exitClosing, ['closed', 'opening']), + State('closed', self.enterClosed, self.exitClosed, ['opening']), + State('opening', self.enterOpening, self.exitOpening, ['open']), + State('open', self.enterOpen, self.exitOpen, ['closing', 'open'])], 'off', 'off') self.fsm.enterInitialState() - self.exitDoorFSM = ClassicFSM.ClassicFSM('DistributedDoor_left', [State.State('off', self.exitDoorEnterOff, self.exitDoorExitOff, ['closing', + self.exitDoorFSM = ClassicFSM('DistributedDoor_left', [State('off', self.exitDoorEnterOff, self.exitDoorExitOff, ['closing', 'closed', 'opening', 'open']), - State.State('closing', self.exitDoorEnterClosing, self.exitDoorExitClosing, ['closed', 'opening']), - State.State('closed', self.exitDoorEnterClosed, self.exitDoorExitClosed, ['opening']), - State.State('opening', self.exitDoorEnterOpening, self.exitDoorExitOpening, ['open']), - State.State('open', self.exitDoorEnterOpen, self.exitDoorExitOpen, ['closing', 'open'])], 'off', 'off') + State('closing', self.exitDoorEnterClosing, self.exitDoorExitClosing, ['closed', 'opening']), + State('closed', self.exitDoorEnterClosed, self.exitDoorExitClosed, ['opening']), + State('opening', self.exitDoorEnterOpening, self.exitDoorExitOpening, ['open']), + State('open', self.exitDoorEnterOpen, self.exitDoorExitOpen, ['closing', 'open'])], 'off', 'off') self.exitDoorFSM.enterInitialState() self.specialDoorTypes = {DoorTypes.EXT_HQ: 0, DoorTypes.EXT_COGHQ: 0, @@ -50,17 +68,15 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): DoorTypes.EXT_KS: 0, DoorTypes.INT_KS: 0} self.doorX = 1.5 - return def generate(self): - DistributedObject.DistributedObject.generate(self) + DistributedObject.generate(self) self.avatarTracks = [] self.avatarExitTracks = [] self.avatarIDList = [] self.avatarExitIDList = [] self.doorTrack = None self.doorExitTrack = None - return def disable(self): self.clearNametag() @@ -72,20 +88,22 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): self.exitDoorFSM.request('off') if 'building' in self.__dict__: del self.building + self.finishAllTracks() self.avatarIDList = [] self.avatarExitIDList = [] if hasattr(self, 'tempDoorNodePath'): self.tempDoorNodePath.removeNode() del self.tempDoorNodePath - DistributedObject.DistributedObject.disable(self) + + DistributedObject.disable(self) def delete(self): del self.fsm del self.exitDoorFSM del self.openSfx del self.closeSfx - DistributedObject.DistributedObject.delete(self) + DistributedObject.delete(self) def wantsNametag(self): return not ZoneUtil.isInterior(self.zoneId) @@ -93,11 +111,13 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): def setupNametag(self): if not self.wantsNametag(): return + if self.nametag == None: self.nametag = NametagGroup() self.nametag.setFont(ToontownGlobals.getBuildingNametagFont()) if TTLocalizer.BuildingNametagShadow: self.nametag.setShadow(*TTLocalizer.BuildingNametagShadow) + self.nametag.setContents(Nametag.CName) self.nametag.setColorCode(NametagGroup.CCToonBuilding) self.nametag.setActive(0) @@ -106,14 +126,12 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): name = self.cr.playGame.dnaStore.getTitleFromBlockNumber(self.block) self.nametag.setName(name) self.nametag.manage(base.marginManager) - return def clearNametag(self): if self.nametag != None: self.nametag.unmanage(base.marginManager) self.nametag.setAvatar(NodePath()) self.nametag = None - return def getTriggerName(self): if self.doorType == DoorTypes.INT_HQ or self.doorType in self.specialDoorTypes: @@ -137,26 +155,25 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): self.hideIfHasFlat(self.findDoorNode('leftDoor')) self.findDoorNode('doorFrameHoleRight').hide() self.findDoorNode('doorFrameHoleLeft').hide() - else: - return def setTriggerName(self): if self.doorType in self.specialDoorTypes: building = self.getBuilding() doorTrigger = building.find('**/door_' + str(self.doorIndex) + '/**/door_trigger*') doorTrigger.node().setName(self.getTriggerName()) - else: - return def setTriggerName_wip(self): building = self.getBuilding() doorTrigger = building.find('**/door_%d/**/door_trigger_%d' % (self.doorIndex, self.block)) if doorTrigger.isEmpty(): doorTrigger = building.find('**/door_trigger_%d' % (self.block,)) + if doorTrigger.isEmpty(): doorTrigger = building.find('**/door_%d/**/door_trigger_*' % (self.doorIndex,)) + if doorTrigger.isEmpty(): doorTrigger = building.find('**/door_trigger_*') + doorTrigger.node().setName(self.getTriggerName()) def setZoneIdAndBlock(self, zoneId, block): @@ -185,7 +202,7 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): self.exitDoorFSM.request(state, [globalClockDelta.localElapsedTime(timestamp)]) def announceGenerate(self): - DistributedObject.DistributedObject.announceGenerate(self) + DistributedObject.announceGenerate(self) self.doPostAnnounceGenerate() def doPostAnnounceGenerate(self): @@ -193,6 +210,7 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): self.bHasFlat = True else: self.bHasFlat = not self.findDoorNode('door*flat', True).isEmpty() + self.hideDoorParts() self.setTriggerName() self.accept(self.getEnterTriggerEvent(), self.doorTrigger) @@ -202,13 +220,13 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): def getBuilding(self): if 'building' not in self.__dict__: if self.doorType == DoorTypes.INT_STANDARD: - door = render.find('**/leftDoor;+s') + door = base.render.find('**/leftDoor;+s') self.building = door.getParent() elif self.doorType == DoorTypes.INT_HQ: - door = render.find('**/door_0') + door = base.render.find('**/door_0') self.building = door.getParent() elif self.doorType == DoorTypes.INT_KS: - self.building = render.find('**/KartShop_Interior*') + self.building = base.render.find('**/KartShop_Interior*') elif self.doorType == DoorTypes.EXT_STANDARD or self.doorType == DoorTypes.EXT_HQ or self.doorType == DoorTypes.EXT_KS: self.building = self.cr.playGame.hood.loader.geom.find('**/??' + str(self.block) + ':*_landmark_*_DNARoot;+s') if self.building.isEmpty(): @@ -217,6 +235,7 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): self.building = self.cr.playGame.hood.loader.geom else: self.notify.error('No such door type as ' + str(self.doorType)) + return self.building def getBuilding_wip(self): @@ -226,6 +245,7 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): else: self.building = self.cr.playGame.hood.loader.geom print('---------------- door is interior -------') + return self.building def readyToExit(self): @@ -238,33 +258,38 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): otherNP = self.getDoorNodePath() if hasattr(avatar, 'stopSmooth'): avatar.stopSmooth() + if avatar.doId == base.localAvatar.doId: - track.append(LerpPosHprInterval(nodePath=camera, other=avatar, duration=duration, pos=Point3(0, -8, avatar.getHeight()), hpr=VBase3(0, 0, 0), blendType='easeInOut')) + track.append(LerpPosHprInterval(nodePath=base.camera, other=avatar, duration=duration, pos=Point3(0, -8, avatar.getHeight()), hpr=VBase3(0, 0, 0), blendType='easeInOut')) + finalPos = avatar.getParent().getRelativePoint(otherNP, Point3(self.doorX, 2, ToontownGlobals.FloorOffset)) moveHere = Sequence(self.getAnimStateInterval(avatar, 'walk'), LerpPosInterval(nodePath=avatar, duration=duration, pos=finalPos, blendType='easeIn')) track.append(moveHere) if avatar.doId == base.localAvatar.doId: track.append(Sequence(Wait(duration * 0.5), Func(base.transitions.irisOut, duration * 0.5), Wait(duration * 0.5), Func(avatar.b_setParent, ToontownGlobals.SPHidden))) - track.delayDelete = DelayDelete.DelayDelete(avatar, 'avatarEnterDoorTrack') + + track.delayDelete = DelayDelete(avatar, 'avatarEnterDoorTrack') return track def avatarEnqueueTrack(self, avatar, duration): if hasattr(avatar, 'stopSmooth'): avatar.stopSmooth() + back = -5.0 - 2.0 * len(self.avatarIDList) if back < -9.0: back = -9.0 + offset = Point3(self.doorX, back, ToontownGlobals.FloorOffset) otherNP = self.getDoorNodePath() walkLike = ActorInterval(avatar, 'walk', startTime=1, duration=duration, endTime=0.0001) standHere = Sequence(LerpPosHprInterval(nodePath=avatar, other=otherNP, duration=duration, pos=offset, hpr=VBase3(0, 0, 0), blendType='easeInOut'), self.getAnimStateInterval(avatar, 'neutral')) trackName = 'avatarEnqueueDoor-%d-%d' % (self.doId, avatar.doId) track = Parallel(walkLike, standHere, name=trackName) - track.delayDelete = DelayDelete.DelayDelete(avatar, 'avatarEnqueueTrack') + track.delayDelete = DelayDelete(avatar, 'avatarEnqueueTrack') return track def getAnimStateInterval(self, avatar, animName): - isSuit = isinstance(avatar, Suit.Suit) + isSuit = isinstance(avatar, Suit) if isSuit: return Func(avatar.loop, animName, 0) else: @@ -284,7 +309,8 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): place = base.cr.playGame.getPlace() if place: place.fsm.request('stopped') - self.dialog = TeaserPanel.TeaserPanel(pageName='otherHoods', doneFunc=self.handleOkTeaser) + + self.dialog = TeaserPanel(pageName='otherHoods', doneFunc=self.handleOkTeaser) def handleOkTeaser(self): self.accept(self.getEnterTriggerEvent(), self.doorTrigger) @@ -301,6 +327,7 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): allowed = base.ttAccess.canAccess(zoneId) else: allowed = base.ttAccess.canAccess() + return allowed def checkIsDoorHitTaskName(self): @@ -311,8 +338,9 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): self.ignore(self.checkIsDoorHitTaskName()) self.ignore(self.getExitTriggerEvent()) self.enterDoor() - return Task.done - return Task.cont + return task.done + + return task.cont def cancelCheckIsDoorHitTask(self, args): taskMgr.remove(self.checkIsDoorHitTaskName()) @@ -333,7 +361,6 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): else: self.accept(self.getExitTriggerEvent(), self.cancelCheckIsDoorHitTask) taskMgr.add(self.checkIsDoorHitTask, self.checkIsDoorHitTaskName()) - return def avatarEnter(self, avatarID): avatar = self.cr.doId2do.get(avatarID, None) @@ -343,7 +370,6 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): track.start() self.avatarTracks.append(track) self.avatarIDList.append(avatarID) - return def rejectEnter(self, reason): message = FADoorCodes.reasonDict[reason] @@ -360,7 +386,7 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): def __faRejectEnter(self, message): self.rejectDialog = TTDialog.TTGlobalDialog(message=message, doneEvent='doorRejectAck', style=TTDialog.Acknowledge) self.rejectDialog.show() - self.rejectDialog.delayDelete = DelayDelete.DelayDelete(self, '__faRejectEnter') + self.rejectDialog.delayDelete = DelayDelete(self, '__faRejectEnter') event = 'clientCleanup' self.acceptOnce(event, self.__handleClientCleanup) base.cr.playGame.getPlace().setState('stopped') @@ -370,6 +396,7 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): def __handleClientCleanup(self): if hasattr(self, 'rejectDialog') and self.rejectDialog: self.rejectDialog.doneStatus = 'ok' + self.__handleRejectAck() def __handleFallAsleepDoor(self): @@ -383,6 +410,7 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): doneStatus = self.rejectDialog.doneStatus if doneStatus != 'ok': self.notify.error('Unrecognized doneStatus: ' + str(doneStatus)) + self.__basicRejectEnter() self.rejectDialog.delayDelete.destroy() self.rejectDialog.cleanup() @@ -390,7 +418,7 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): def getDoorNodePath(self): if self.doorType == DoorTypes.INT_STANDARD: - otherNP = render.find('**/door_origin') + otherNP = base.render.find('**/door_origin') elif self.doorType == DoorTypes.EXT_STANDARD: if hasattr(self, 'tempDoorNodePath'): return self.tempDoorNodePath @@ -404,14 +432,16 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): building = self.getBuilding() otherNP = building.find('**/door_origin_' + str(self.doorIndex)) elif self.doorType == DoorTypes.INT_HQ: - otherNP = render.find('**/door_origin_' + str(self.doorIndex)) + otherNP = base.render.find('**/door_origin_' + str(self.doorIndex)) else: self.notify.error('No such door type as ' + str(self.doorType)) + return otherNP def avatarExitTrack(self, avatar, duration): if hasattr(avatar, 'stopSmooth'): avatar.stopSmooth() + otherNP = self.getDoorNodePath() trackName = 'avatarExitDoor-%d-%d' % (self.doId, avatar.doId) track = Sequence(name=trackName) @@ -419,18 +449,22 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): track.append(PosHprInterval(avatar, Point3(-self.doorX, 0, ToontownGlobals.FloorOffset), VBase3(179, 0, 0), other=otherNP)) track.append(Func(avatar.setParent, ToontownGlobals.SPRender)) if avatar.doId == base.localAvatar.doId: - track.append(PosHprInterval(camera, VBase3(-self.doorX, 5, avatar.getHeight()), VBase3(180, 0, 0), other=otherNP)) + track.append(PosHprInterval(base.camera, VBase3(-self.doorX, 5, avatar.getHeight()), VBase3(180, 0, 0), other=otherNP)) + if avatar.doId == base.localAvatar.doId: - finalPos = render.getRelativePoint(otherNP, Point3(-self.doorX, -6, ToontownGlobals.FloorOffset)) + finalPos = base.render.getRelativePoint(otherNP, Point3(-self.doorX, -6, ToontownGlobals.FloorOffset)) else: - finalPos = render.getRelativePoint(otherNP, Point3(-self.doorX, -3, ToontownGlobals.FloorOffset)) + finalPos = base.render.getRelativePoint(otherNP, Point3(-self.doorX, -3, ToontownGlobals.FloorOffset)) + track.append(LerpPosInterval(nodePath=avatar, duration=duration, pos=finalPos, blendType='easeInOut')) if avatar.doId == base.localAvatar.doId: track.append(Func(self.exitCompleted)) track.append(Func(base.transitions.irisIn)) + if hasattr(avatar, 'startSmooth'): track.append(Func(avatar.startSmooth)) - track.delayDelete = DelayDelete.DelayDelete(avatar, 'DistributedDoor.avatarExitTrack') + + track.delayDelete = DelayDelete(avatar, 'DistributedDoor.avatarExitTrack') return track def exitCompleted(self): @@ -438,6 +472,7 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): place = self.cr.playGame.getPlace() if place: place.setState('walk') + base.localAvatar.d_setParent(ToontownGlobals.SPRender) def avatarExit(self, avatarID): @@ -451,26 +486,26 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): def finishDoorTrack(self): if self.doorTrack: self.doorTrack.finish() + self.doorTrack = None - return def finishDoorExitTrack(self): if self.doorExitTrack: self.doorExitTrack.finish() + self.doorExitTrack = None - return def finishAllTracks(self): self.finishDoorTrack() self.finishDoorExitTrack() for t in self.avatarTracks: t.finish() - DelayDelete.cleanupDelayDeletes(t) + cleanupDelayDeletes(t) self.avatarTracks = [] for t in self.avatarExitTracks: t.finish() - DelayDelete.cleanupDelayDeletes(t) + cleanupDelayDeletes(t) self.avatarExitTracks = [] @@ -498,16 +533,19 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): if doorFrameHoleRight.isEmpty(): self.notify.warning('enterClosing(): did not find doorFrameHoleRight') return + rightDoor = self.findDoorNode('rightDoor') if rightDoor.isEmpty(): self.notify.warning('enterClosing(): did not find rightDoor') return + otherNP = self.getDoorNodePath() trackName = 'doorClose-%d' % self.doId if self.rightSwing: h = 100 else: h = -100 + self.finishDoorTrack() self.doorTrack = Sequence(LerpHprInterval(nodePath=rightDoor, duration=1.0, hpr=VBase3(0, 0, 0), startHpr=VBase3(h, 0, 0), other=otherNP, blendType='easeInOut'), Func(doorFrameHoleRight.hide), Func(self.hideIfHasFlat, rightDoor), SoundInterval(self.closeSfx, node=rightDoor), name=trackName) self.doorTrack.start(ts) @@ -529,16 +567,19 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): if doorFrameHoleRight.isEmpty(): self.notify.warning('enterOpening(): did not find doorFrameHoleRight') return + rightDoor = self.findDoorNode('rightDoor') if rightDoor.isEmpty(): self.notify.warning('enterOpening(): did not find rightDoor') return + otherNP = self.getDoorNodePath() trackName = 'doorOpen-%d' % self.doId if self.rightSwing: h = 100 else: h = -100 + self.finishDoorTrack() self.doorTrack = Parallel(SoundInterval(self.openSfx, node=rightDoor), Sequence(HprInterval(rightDoor, VBase3(0, 0, 0), other=otherNP), Wait(0.4), Func(rightDoor.show), Func(doorFrameHoleRight.show), LerpHprInterval(nodePath=rightDoor, duration=0.6, hpr=VBase3(h, 0, 0), startHpr=VBase3(0, 0, 0), other=otherNP, blendType='easeInOut')), name=trackName) self.doorTrack.start(ts) @@ -553,6 +594,7 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): track = self.avatarEnterDoorTrack(avatar, 1.0) track.start(ts) self.avatarTracks.append(track) + if avatarID == base.localAvatar.doId: self.done = 1 @@ -561,7 +603,7 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): def exitOpen(self): for track in self.avatarTracks: track.finish() - DelayDelete.cleanupDelayDeletes(track) + cleanupDelayDeletes(track) self.avatarTracks = [] @@ -576,10 +618,12 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): if doorFrameHoleLeft.isEmpty(): self.notify.warning('enterOpening(): did not find flatDoors') return + if self.leftSwing: h = -100 else: h = 100 + leftDoor = self.findDoorNode('leftDoor') if not leftDoor.isEmpty(): otherNP = self.getDoorNodePath() @@ -602,11 +646,13 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): if doorFrameHoleLeft.isEmpty(): self.notify.warning('enterOpening(): did not find flatDoors') return + leftDoor = self.findDoorNode('leftDoor') if self.leftSwing: h = -100 else: h = 100 + if not leftDoor.isEmpty(): otherNP = self.getDoorNodePath() trackName = 'doorDoorExitTrack-%d' % self.doId @@ -632,7 +678,7 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): def exitDoorExitOpen(self): for track in self.avatarExitTracks: track.finish() - DelayDelete.cleanupDelayDeletes(track) + cleanupDelayDeletes(track) self.avatarExitTracks = [] @@ -645,8 +691,10 @@ class DistributedDoor(DistributedObject.DistributedObject, DelayDeletable): foundNode = building.find('**/door_' + str(self.doorIndex) + '/**/' + string + '*;+s+i') if foundNode.isEmpty(): foundNode = building.find('**/' + string + '*;+s+i') + if allowEmpty: return foundNode + return foundNode def hideIfHasFlat(self, node): diff --git a/toontown/hood/Place.py b/toontown/hood/Place.py index 486bb56..fa346a2 100644 --- a/toontown/hood/Place.py +++ b/toontown/hood/Place.py @@ -1,30 +1,36 @@ -from panda3d.core import * -from toontown.toonbase.ToonBaseGlobal import * -from direct.directnotify import DirectNotifyGlobal -from direct.fsm import StateData -from direct.showbase.PythonUtil import PriorityCallbacks -from toontown.safezone import PublicWalk -from toontown.launcher import DownloadForceAcknowledge -from . import TrialerForceAcknowledge -from . import ZoneUtil -from toontown.friends import FriendsListManager -from toontown.toonbase import ToontownGlobals -from toontown.toon.Toon import teleportDebug -from toontown.estate import HouseGlobals -from toontown.toonbase import TTLocalizer -from otp.otpbase import OTPLocalizer -from otp.avatar import Emote -from otp.avatar.Avatar import teleportNotify -from direct.task import Task -from . import QuietZoneState -from toontown.distributed import ToontownDistrictStats +from panda3d.core import NodePath +from panda3d.otp import NametagGlobals -class Place(StateData.StateData, FriendsListManager.FriendsListManager): - notify = DirectNotifyGlobal.directNotify.newCategory('Place') +from direct.directnotify.DirectNotifyGlobal import directNotify +from direct.fsm.StateData import StateData +from direct.showbase.MessengerGlobal import messenger +from direct.showbase.PythonUtil import Functor, PriorityCallbacks, SubframeCall, uniqueName +from direct.task.TaskManagerGlobal import taskMgr + +from otp.avatar.Avatar import teleportNotify +from otp.avatar.Emote import globalEmote +from otp.otpbase import OTPLocalizer + +from toontown.distributed import ToontownDistrictStats +from toontown.estate import HouseGlobals +from toontown.friends.FriendsListManager import FriendsListManager +from toontown.hood import ZoneUtil +from toontown.hood.QuietZoneState import QuietZoneState +from toontown.hood.TrialerForceAcknowledge import TrialerForceAcknowledge +from toontown.launcher.DownloadForceAcknowledge import DownloadForceAcknowledge +from toontown.safezone.PublicWalk import PublicWalk +from toontown.toon.Toon import teleportDebug +from toontown.toonbase import ToontownGlobals +from toontown.toonbase import TTLocalizer +from toontown.toonbase.ToonBaseGlobal import base + + +class Place(StateData, FriendsListManager): + notify = directNotify.newCategory('Place') def __init__(self, loader, doneEvent): - StateData.StateData.__init__(self, doneEvent) - FriendsListManager.FriendsListManager.__init__(self) + StateData.__init__(self, doneEvent) + FriendsListManager.__init__(self) self.loader = loader self.dfaDoneEvent = 'dfaDoneEvent' self.trialerFADoneEvent = 'trialerFADoneEvent' @@ -35,26 +41,27 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): self._leftQuietZoneSubframeCall = None self._setZoneCompleteLocalCallbacks = PriorityCallbacks() self._setZoneCompleteSubframeCall = None - return def load(self): - StateData.StateData.load(self) - FriendsListManager.FriendsListManager.load(self) + StateData.load(self) + FriendsListManager.load(self) self.walkDoneEvent = 'walkDone' - self.walkStateData = PublicWalk.PublicWalk(self.fsm, self.walkDoneEvent) + self.walkStateData = PublicWalk(self.fsm, self.walkDoneEvent) self.walkStateData.load() self._tempFSM = self.fsm def unload(self): - StateData.StateData.unload(self) - FriendsListManager.FriendsListManager.unload(self) + StateData.unload(self) + FriendsListManager.unload(self) self.notify.info('Unloading Place (%s). Fsm in %s' % (self.zoneId, self._tempFSM.getCurrentState().getName())) if self._leftQuietZoneSubframeCall: self._leftQuietZoneSubframeCall.cleanup() self._leftQuietZoneSubframeCall = None + if self._setZoneCompleteSubframeCall: self._setZoneCompleteSubframeCall.cleanup() self._setZoneCompleteSubframeCall = None + self._leftQuietZoneLocalCallbacks = None self._setZoneCompleteLocalCallbacks = None del self._tempFSM @@ -66,12 +73,12 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): if self.trialerFA: self.trialerFA.exit() del self.trialerFA - return def _getQZState(self): if hasattr(base, 'cr') and hasattr(base.cr, 'playGame'): if hasattr(base.cr.playGame, 'quietZoneStateData') and base.cr.playGame.quietZoneStateData: return base.cr.playGame.quietZoneStateData + return None def addLeftQuietZoneCallback(self, callback, priority = None): @@ -82,22 +89,22 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): token = self._leftQuietZoneLocalCallbacks.add(callback, priority=priority) if not self._leftQuietZoneSubframeCall: self._leftQuietZoneSubframeCall = SubframeCall(self._doLeftQuietZoneCallbacks, taskMgr.getCurrentTask().getPriority() - 1) + return token def removeLeftQuietZoneCallback(self, token): if token is not None: if token in self._leftQuietZoneLocalCallbacks: self._leftQuietZoneLocalCallbacks.remove(token) + qzsd = self._getQZState() if qzsd: qzsd.removeLeftQuietZoneCallback(token) - return def _doLeftQuietZoneCallbacks(self): self._leftQuietZoneLocalCallbacks() self._leftQuietZoneLocalCallbacks.clear() self._leftQuietZoneSubframeCall = None - return def addSetZoneCompleteCallback(self, callback, priority = None): qzsd = self._getQZState() @@ -107,29 +114,30 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): token = self._setZoneCompleteLocalCallbacks.add(callback, priority=priority) if not self._setZoneCompleteSubframeCall: self._setZoneCompleteSubframeCall = SubframeCall(self._doSetZoneCompleteLocalCallbacks, taskMgr.getCurrentTask().getPriority() - 1) + return token def removeSetZoneCompleteCallback(self, token): if token is not None: if any(token == x[1] for x in self._setZoneCompleteLocalCallbacks._callbacks): self._setZoneCompleteLocalCallbacks.remove(token) + qzsd = self._getQZState() if qzsd: qzsd.removeSetZoneCompleteCallback(token) - return def _doSetZoneCompleteLocalCallbacks(self): self._setZoneCompleteSubframeCall = None localCallbacks = self._setZoneCompleteLocalCallbacks self._setZoneCompleteLocalCallbacks() localCallbacks.clear() - return def setState(self, state): if hasattr(self, 'fsm'): curState = self.fsm.getName() if state == 'pet' or curState == 'pet': self.preserveFriendsList() + self.fsm.request(state) def getState(self): @@ -148,10 +156,10 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): def handleTeleportQuery(self, fromAvatar, toAvatar): if base.config.GetBool('want-tptrack', False): - if toAvatar == localAvatar: + if toAvatar == base.localAvatar: toAvatar.doTeleportResponse(fromAvatar, toAvatar, toAvatar.doId, 1, toAvatar.defaultShard, base.cr.playGame.getPlaceId(), self.getZoneId(), fromAvatar.doId) else: - self.notify.warning('handleTeleportQuery toAvatar.doId != localAvatar.doId' % (toAvatar.doId, localAvatar.doId)) + self.notify.warning('handleTeleportQuery toAvatar.doId != localAvatar.doId' % (toAvatar.doId, base.localAvatar.doId)) else: fromAvatar.d_teleportResponse(toAvatar.doId, 1, toAvatar.defaultShard, base.cr.playGame.getPlaceId(), self.getZoneId()) @@ -159,6 +167,7 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): if self.isPeriodTimerEffective(): if base.cr.periodTimerExpired: taskMgr.doMethodLater(5, self.redoPeriodTimer, 'redoPeriodTimer') + self.accept('periodTimerExpired', self.periodTimerExpired) def disablePeriodTimer(self): @@ -167,7 +176,7 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): def redoPeriodTimer(self, task): messenger.send('periodTimerExpired') - return Task.done + return task.done def periodTimerExpired(self): self.fsm.request('final') @@ -209,10 +218,12 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): self.walkStateData.enter() if teleportIn == 0: self.walkStateData.fsm.request('walking') + self.acceptOnce(self.walkDoneEvent, self.handleWalkDone) if base.cr.productName in ['DisneyOnline-US', 'ES'] and not base.cr.isPaid() and base.localAvatar.tutorialAck: base.localAvatar.chatMgr.obscure(0, 0) base.localAvatar.chatMgr.normalButton.show() + self.accept('teleportQuery', self.handleTeleportQuery) base.localAvatar.setTeleportAvailable(1) base.localAvatar.questPage.acceptOnscreenHooks() @@ -225,6 +236,7 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): self.exitFLM() if base.cr.productName in ['DisneyOnline-US', 'ES'] and not base.cr.isPaid() and base.localAvatar.tutorialAck and not base.cr.whiteListChatEnabled: base.localAvatar.chatMgr.obscure(1, 0) + self.disablePeriodTimer() messenger.send('wakeup') self.walkStateData.exit() @@ -233,13 +245,13 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): self.ignore('teleportQuery') if base.cr.playGame.hood != None: base.cr.playGame.hood.hideTitleText() + base.localAvatar.questPage.hideQuestsOnscreen() base.localAvatar.questPage.ignoreOnscreenHooks() base.localAvatar.invPage.ignoreOnscreenHooks() base.localAvatar.invPage.hideInventoryOnscreen() base.localAvatar.questMap.hide() base.localAvatar.questMap.ignoreOnscreenHooks() - return def handleWalkDone(self, doneStatus): mode = doneStatus['mode'] @@ -308,10 +320,12 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): target = base.cr.doFind('DistributedTarget') if target: target.hideGui() + self.accept('teleportQuery', self.handleTeleportQuery) base.localAvatar.setTeleportAvailable(1) if page: base.localAvatar.book.setPage(page) + base.localAvatar.b_setAnimState('OpenBook', 1, self.enterStickerBookGUI) base.localAvatar.obscureMoveFurnitureButton(1) @@ -328,11 +342,12 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): def __handleFallingAsleep(self, task): base.localAvatar.book.exit() base.localAvatar.b_setAnimState('CloseBook', 1, callback=self.__handleFallingAsleepBookClose) - return Task.done + return task.done def __handleFallingAsleepBookClose(self): if hasattr(self, 'fsm'): self.fsm.request('walk') + base.localAvatar.forceGotoSleep() def exitStickerBook(self): @@ -377,10 +392,11 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): base.localAvatar.b_setAnimState('CloseBook', 1, callback=self.startPartyNow, extraArgs=[firstStart, hostId]) def handleBookCloseTeleport(self, hoodId, zoneId): - if localAvatar.hasActiveBoardingGroup(): + if base.localAvatar.hasActiveBoardingGroup(): rejectText = TTLocalizer.BoardingCannotLeaveZone - localAvatar.elevatorNotifier.showMe(rejectText) + base.localAvatar.elevatorNotifier.showMe(rejectText) return + self.requestLeave({'loader': ZoneUtil.getBranchLoaderName(zoneId), 'where': ZoneUtil.getToonWhereName(zoneId), 'how': 'teleportIn', @@ -388,7 +404,6 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): 'zoneId': zoneId, 'shardId': None, 'avId': -1}) - return def __handleBookCloseExit(self): base.localAvatar.b_setAnimState('TeleportOut', 1, self.__handleBookExitTeleport, [0]) @@ -396,14 +411,16 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): def __handleBookExitTeleport(self, requestStatus): if base.cr.timeManager: base.cr.timeManager.setDisconnectReason(ToontownGlobals.DisconnectBookExit) + base.transitions.fadeScreen(1.0) base.cr.gameFSM.request(self.exitTo) def goHomeNow(self, curZoneId): - if localAvatar.hasActiveBoardingGroup(): + if base.localAvatar.hasActiveBoardingGroup(): rejectText = TTLocalizer.BoardingCannotLeaveZone - localAvatar.elevatorNotifier.showMe(rejectText) + base.localAvatar.elevatorNotifier.showMe(rejectText) return + hoodId = ToontownGlobals.MyEstate self.requestLeave({'loader': 'safeZoneLoader', 'where': 'estate', @@ -412,13 +429,13 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): 'zoneId': -1, 'shardId': None, 'avId': -1}) - return def startPartyNow(self, firstStart, hostId): - if localAvatar.hasActiveBoardingGroup(): + if base.localAvatar.hasActiveBoardingGroup(): rejectText = TTLocalizer.BoardingCannotLeaveZone - localAvatar.elevatorNotifier.showMe(rejectText) + base.localAvatar.elevatorNotifier.showMe(rejectText) return + base.localAvatar.creatingNewPartyWithMagicWord = False base.localAvatar.aboutToPlanParty = False hoodId = ToontownGlobals.PartyHood @@ -436,6 +453,7 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): if shardId == base.localAvatar.defaultShard: shardId = None + base.cr.playGame.getPlace().requestLeave({'loader': 'safeZoneLoader', 'where': 'party', 'how': 'teleportIn', @@ -446,13 +464,13 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): else: if hostId is None: hostId = base.localAvatar.doId + base.cr.partyManager.sendAvatarToParty(hostId) - return - return def handleBookClose(self): if hasattr(self, 'fsm'): self.fsm.request('walk') + if hasattr(self, 'toonSubmerged') and self.toonSubmerged == 1: if hasattr(self, 'walkStateData'): self.walkStateData.fsm.request('swimming', [self.loader.swimSound]) @@ -469,26 +487,27 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): def enterDFA(self, requestStatus): teleportDebug(requestStatus, 'enterDFA(%s)' % (requestStatus,)) self.acceptOnce(self.dfaDoneEvent, self.enterDFACallback, [requestStatus]) - self.dfa = DownloadForceAcknowledge.DownloadForceAcknowledge(self.dfaDoneEvent) + self.dfa = DownloadForceAcknowledge(self.dfaDoneEvent) self.dfa.enter(base.cr.hoodMgr.getPhaseFromHood(requestStatus['hoodId'])) def exitDFA(self): self.ignore(self.dfaDoneEvent) def handleEnterTunnel(self, requestStatus, collEntry): - if localAvatar.hasActiveBoardingGroup(): + if base.localAvatar.hasActiveBoardingGroup(): rejectText = TTLocalizer.BoardingCannotLeaveZone - localAvatar.elevatorNotifier.showMe(rejectText) + base.localAvatar.elevatorNotifier.showMe(rejectText) dummyNP = NodePath('dummyNP') - dummyNP.reparentTo(render) + dummyNP.reparentTo(base.render) tunnelOrigin = requestStatus['tunnelOrigin'] - dummyNP.setPos(localAvatar.getPos()) + dummyNP.setPos(base.localAvatar.getPos()) dummyNP.setH(tunnelOrigin.getH()) dummyNP.setPos(dummyNP, 0, 4, 0) - localAvatar.setPos(dummyNP.getPos()) + base.localAvatar.setPos(dummyNP.getPos()) dummyNP.removeNode() del dummyNP return + self.requestLeave(requestStatus) def enterDFACallback(self, requestStatus, doneStatus): @@ -504,6 +523,7 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): out = {'teleportIn': 'teleportOut', 'tunnelIn': 'tunnelOut', 'doorIn': 'doorOut'} + teleportDebug(requestStatus, 'requesting %s, requestStatus=%s' % (out[requestStatus['how']], requestStatus)) self.fsm.request(out[requestStatus['how']], [requestStatus]) elif doneStatus['mode'] == 'incomplete': @@ -520,7 +540,7 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): def enterTrialerFA(self, requestStatus): teleportDebug(requestStatus, 'enterTrialerFA(%s)' % requestStatus) self.acceptOnce(self.trialerFADoneEvent, self.trialerFACallback, [requestStatus]) - self.trialerFA = TrialerForceAcknowledge.TrialerForceAcknowledge(self.trialerFADoneEvent) + self.trialerFA = TrialerForceAcknowledge(self.trialerFADoneEvent) self.trialerFA.enter(requestStatus['hoodId']) def exitTrialerFA(self): @@ -589,6 +609,7 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): tunnelName = requestStatus.get('tunnelName') if tunnelName == None: tunnelName = base.cr.hoodMgr.makeLinkTunnelName(self.loader.hood.id, fromZoneId) + self.doneStatus = {'loader': ZoneUtil.getLoaderName(zoneId), 'where': ZoneUtil.getToonWhereName(zoneId), 'how': how, @@ -599,7 +620,6 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): self.accept('tunnelOutMovieDone', self.__tunnelOutMovieDone) base.localAvatar.tunnelOut(tunnelOrigin) base.localAvatar.stopQuestMap() - return def __tunnelOutMovieDone(self): self.ignore('tunnelOutMovieDone') @@ -621,11 +641,11 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): def enterDied(self, requestStatus, callback = None): if callback == None: callback = self.__diedDone + base.localAvatar.laffMeter.start() - camera.wrtReparentTo(render) + base.camera.wrtReparentTo(base.render) base.localAvatar.b_setAnimState('Died', 1, callback, [requestStatus]) base.localAvatar.obscureMoveFurnitureButton(1) - return def __diedDone(self, requestStatus): self.doneStatus = requestStatus @@ -643,6 +663,7 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): base.cr.estateMgr.getLocalEstateZone(avId) else: base.cr.estateMgr.getLocalEstateZone(base.localAvatar.getDoId()) + if HouseGlobals.WANT_TELEPORT_TIMEOUT: taskMgr.doMethodLater(HouseGlobals.TELEPORT_TIMEOUT, self.goHomeFailed, 'goHomeFailed') @@ -653,6 +674,7 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): self.doneStatus['failed'] = 1 self.goHomeFailed(None) return + if ownerId == 0 and zoneId == 0: if self.doneStatus['shardId'] is None or self.doneStatus['shardId'] is base.localAvatar.defaultShard: self.doneStatus['failed'] = 1 @@ -666,14 +688,15 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): self.doneStatus['how'] = 'teleportIn' messenger.send(self.doneEvent) return + if self.doneStatus['zoneId'] == -1: self.doneStatus['zoneId'] = zoneId elif self.doneStatus['zoneId'] != zoneId: self.doneStatus['where'] = 'house' + self.doneStatus['ownerId'] = ownerId messenger.send(self.doneEvent) messenger.send('localToonLeft') - return def goHomeFailed(self, task): self.notify.debug('goHomeFailed') @@ -682,7 +705,7 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): self.doneStatus['hood'] = base.localAvatar.lastHood self.doneStatus['zone'] = base.localAvatar.lastHood self.fsm.request('teleportIn', [self.doneStatus]) - return Task.done + return task.done def notifyUserGoHomeFailed(self): self.notify.debug('notifyUserGoHomeFailed') @@ -692,12 +715,13 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): avatar = base.cr.identifyAvatar(failedToVisitAvId) if avatar: avName = avatar.getName() + if avName: message = TTLocalizer.EstateTeleportFailedNotFriends % avName else: message = TTLocalizer.EstateTeleportFailed + base.localAvatar.setSystemMessage(0, message) - return def enterTeleportIn(self, requestStatus): self._tiToken = self.addSetZoneCompleteCallback(Functor(self._placeTeleportInPostZoneComplete, requestStatus), 100) @@ -723,16 +747,16 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): teleportDebug(requestStatus, 'friend not here, giving up') base.localAvatar.setSystemMessage(avId, OTPLocalizer.WhisperTargetLeftVisit % (friend.getName(),)) friend.d_teleportGiveup(base.localAvatar.doId) + base.transitions.irisIn() self.nextState = requestStatus.get('nextState', 'walk') base.localAvatar.attachCamera() base.localAvatar.startUpdateSmartCamera() base.localAvatar.startPosHprBroadcast() - globalClock.tick() + base.clock.tick() base.localAvatar.b_setAnimState('TeleportIn', 1, callback=self.teleportInDone) base.localAvatar.d_broadcastPositionNow() base.localAvatar.b_setParent(ToontownGlobals.SPRender) - return def teleportInDone(self): if hasattr(self, 'fsm'): @@ -748,7 +772,6 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): base.localAvatar.stopUpdateSmartCamera() base.localAvatar.detachCamera() base.localAvatar.stopPosHprBroadcast() - return def requestTeleport(self, hoodId, zoneId, shardId, avId): if avId > 0: @@ -756,20 +779,25 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): zoneId, shardId, avId),)) - if localAvatar.hasActiveBoardingGroup(): + + if base.localAvatar.hasActiveBoardingGroup(): if avId > 0: teleportNotify.debug('requestTeleport: has active boarding group') + rejectText = TTLocalizer.BoardingCannotLeaveZone - localAvatar.elevatorNotifier.showMe(rejectText) + base.localAvatar.elevatorNotifier.showMe(rejectText) return + loaderId = ZoneUtil.getBranchLoaderName(zoneId) whereId = ZoneUtil.getToonWhereName(zoneId) if hoodId == ToontownGlobals.MyEstate: loaderId = 'safeZoneLoader' whereId = 'estate' + if hoodId == ToontownGlobals.PartyHood: loaderId = 'safeZoneLoader' whereId = 'party' + self.requestLeave({'loader': loaderId, 'where': whereId, 'how': 'teleportIn', @@ -828,6 +856,7 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): if hasattr(self, 'fsm'): messenger.send('bankAsleep') self.fsm.request('walk') + base.localAvatar.forceGotoSleep() def exitBanking(self): @@ -850,6 +879,7 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): def __handleFallingAsleepPhone(self, arg): if hasattr(self, 'fsm'): self.fsm.request('walk') + messenger.send('phoneAsleep') base.localAvatar.forceGotoSleep() @@ -863,12 +893,13 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): def enterStopped(self): base.localAvatar.b_setAnimState('neutral', 1) - Emote.globalEmote.disableBody(base.localAvatar, 'enterStopped') + globalEmote.disableBody(base.localAvatar, 'enterStopped') self.accept('teleportQuery', self.handleTeleportQuery) if base.localAvatar.isDisguised: base.localAvatar.setTeleportAvailable(0) else: base.localAvatar.setTeleportAvailable(1) + base.localAvatar.laffMeter.start() base.localAvatar.obscureMoveFurnitureButton(1) base.localAvatar.startSleepWatch(self.__handleFallingAsleepStopped) @@ -877,11 +908,12 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): def __handleFallingAsleepStopped(self, arg): if hasattr(self, 'fsm'): self.fsm.request('walk') + base.localAvatar.forceGotoSleep() messenger.send('stoppedAsleep') def exitStopped(self): - Emote.globalEmote.releaseBody(base.localAvatar, 'exitStopped') + globalEmote.releaseBody(base.localAvatar, 'exitStopped') base.localAvatar.setTeleportAvailable(0) self.ignore('teleportQuery') base.localAvatar.laffMeter.stop() @@ -892,7 +924,7 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): def enterPet(self): base.localAvatar.b_setAnimState('neutral', 1) - Emote.globalEmote.disableBody(base.localAvatar, 'enterPet') + globalEmote.disableBody(base.localAvatar, 'enterPet') self.accept('teleportQuery', self.handleTeleportQuery) base.localAvatar.setTeleportAvailable(1) base.localAvatar.setTeleportAllowed(0) @@ -902,7 +934,7 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): def exitPet(self): base.localAvatar.setTeleportAvailable(0) base.localAvatar.setTeleportAllowed(1) - Emote.globalEmote.releaseBody(base.localAvatar, 'exitPet') + globalEmote.releaseBody(base.localAvatar, 'exitPet') self.ignore('teleportQuery') base.localAvatar.laffMeter.stop() self.exitFLM() @@ -910,7 +942,7 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): def enterQuietZone(self, requestStatus): self.quietZoneDoneEvent = uniqueName('quietZoneDone') self.acceptOnce(self.quietZoneDoneEvent, self.handleQuietZoneDone) - self.quietZoneStateData = QuietZoneState.QuietZoneState(self.quietZoneDoneEvent) + self.quietZoneStateData = QuietZoneState(self.quietZoneDoneEvent) self.quietZoneStateData.load() self.quietZoneStateData.enter(requestStatus) @@ -920,7 +952,6 @@ class Place(StateData.StateData, FriendsListManager.FriendsListManager): self.quietZoneStateData.exit() self.quietZoneStateData.unload() self.quietZoneStateData = None - return def handleQuietZoneDone(self): how = base.cr.handlerArgs['how'] diff --git a/toontown/safezone/Playground.py b/toontown/safezone/Playground.py index 2a7a18e..5484176 100644 --- a/toontown/safezone/Playground.py +++ b/toontown/safezone/Playground.py @@ -1,41 +1,45 @@ -from direct.interval.IntervalGlobal import * -from panda3d.core import * -from toontown.toonbase.ToonBaseGlobal import * -from direct.directnotify import DirectNotifyGlobal -from toontown.hood import Place -from direct.showbase import DirectObject -from direct.fsm import StateData -from direct.fsm import ClassicFSM, State -from direct.fsm import State -from direct.task import Task -from toontown.toon import DeathForceAcknowledge -from toontown.toon import HealthForceAcknowledge -from toontown.tutorial import TutorialForceAcknowledge -from toontown.toon import NPCForceAcknowledge -from toontown.trolley import Trolley -from toontown.toontowngui import TTDialog -from toontown.toonbase import ToontownGlobals -from toontown.toon.Toon import teleportDebug -from toontown.toonbase import TTLocalizer -from direct.gui import DirectLabel -from otp.distributed.TelemetryLimiter import RotationLimitToH, TLGatherAllAvs -from toontown.quest import Quests +from panda3d.core import LineSegs, NodePath, TextNode, Vec4 +from panda3d.otp import NametagGlobals -class Playground(Place.Place): - notify = DirectNotifyGlobal.directNotify.newCategory('Playground') +from direct.directnotify.DirectNotifyGlobal import directNotify +from direct.fsm.ClassicFSM import ClassicFSM +from direct.fsm.State import State +from direct.gui.DirectLabel import DirectLabel +from direct.interval.IntervalGlobal import Func, LerpColorScaleInterval, Sequence +from direct.showbase.MessengerGlobal import messenger + +from otp.distributed.TelemetryLimiter import RotationLimitToH, TLGatherAllAvs + +from toontown.classicchars import CCharPaths +from toontown.hood.Place import Place +from toontown.quest import Quests +from toontown.toon.DeathForceAcknowledge import DeathForceAcknowledge +from toontown.toon.HealthForceAcknowledge import HealthForceAcknowledge +from toontown.toon.NPCForceAcknowledge import NPCForceAcknowledge +from toontown.toon.Toon import teleportDebug +from toontown.toonbase import ToontownGlobals +from toontown.toonbase import TTLocalizer +from toontown.toonbase.ToonBaseGlobal import base +from toontown.toontowngui import TTDialog +from toontown.trolley.Trolley import Trolley +from toontown.tutorial.TutorialForceAcknowledge import TutorialForceAcknowledge + + +class Playground(Place): + notify = directNotify.newCategory('Playground') def __init__(self, loader, parentFSM, doneEvent): - Place.Place.__init__(self, loader, doneEvent) + Place.__init__(self, loader, doneEvent) self.tfaDoneEvent = 'tfaDoneEvent' - self.fsm = ClassicFSM.ClassicFSM('Playground', [ - State.State('start', + self.fsm = ClassicFSM('Playground', [ + State('start', self.enterStart, self.exitStart, [ 'walk', 'deathAck', 'doorIn', 'tunnelIn']), - State.State('walk', + State('walk', self.enterWalk, self.exitWalk, [ 'drive', @@ -52,7 +56,7 @@ class Playground(Place.Place): 'purchase', 'stopped', 'fishing']), - State.State('stickerBook', + State('stickerBook', self.enterStickerBook, self.exitStickerBook, [ 'walk', @@ -66,124 +70,124 @@ class Playground(Place.Place): 'stopped', 'fishing', 'trialerFA']), - State.State('sit', + State('sit', self.enterSit, self.exitSit, [ 'walk', 'DFA', 'trialerFA']), - State.State('drive', + State('drive', self.enterDrive, self.exitDrive, [ 'walk', 'DFA', 'trialerFA']), - State.State('trolley', + State('trolley', self.enterTrolley, self.exitTrolley, [ 'walk']), - State.State('doorIn', + State('doorIn', self.enterDoorIn, self.exitDoorIn, [ 'walk']), - State.State('doorOut', + State('doorOut', self.enterDoorOut, self.exitDoorOut, [ 'walk']), - State.State('TFA', + State('TFA', self.enterTFA, self.exitTFA, [ 'TFAReject', 'DFA']), - State.State('TFAReject', + State('TFAReject', self.enterTFAReject, self.exitTFAReject, [ 'walk']), - State.State('trialerFA', + State('trialerFA', self.enterTrialerFA, self.exitTrialerFA, [ 'trialerFAReject', 'DFA']), - State.State('trialerFAReject', + State('trialerFAReject', self.enterTrialerFAReject, self.exitTrialerFAReject, [ 'walk']), - State.State('DFA', + State('DFA', self.enterDFA, self.exitDFA, [ 'DFAReject', 'NPCFA', 'HFA']), - State.State('DFAReject', + State('DFAReject', self.enterDFAReject, self.exitDFAReject, [ 'walk']), - State.State('NPCFA', + State('NPCFA', self.enterNPCFA, self.exitNPCFA, [ 'NPCFAReject', 'HFA']), - State.State('NPCFAReject', + State('NPCFAReject', self.enterNPCFAReject, self.exitNPCFAReject, [ 'walk']), - State.State('HFA', + State('HFA', self.enterHFA, self.exitHFA, [ 'HFAReject', 'teleportOut', 'tunnelOut']), - State.State('HFAReject', + State('HFAReject', self.enterHFAReject, self.exitHFAReject, [ 'walk']), - State.State('deathAck', + State('deathAck', self.enterDeathAck, self.exitDeathAck, [ 'teleportIn']), - State.State('teleportIn', + State('teleportIn', self.enterTeleportIn, self.exitTeleportIn, [ 'walk', 'popup']), - State.State('popup', + State('popup', self.enterPopup, self.exitPopup, [ 'walk']), - State.State('teleportOut', + State('teleportOut', self.enterTeleportOut, self.exitTeleportOut, [ 'deathAck', 'teleportIn']), - State.State('died', + State('died', self.enterDied, self.exitDied, [ 'final']), - State.State('tunnelIn', + State('tunnelIn', self.enterTunnelIn, self.exitTunnelIn, [ 'walk']), - State.State('tunnelOut', + State('tunnelOut', self.enterTunnelOut, self.exitTunnelOut, [ 'final']), - State.State('quest', + State('quest', self.enterQuest, self.exitQuest, [ 'walk']), - State.State('purchase', + State('purchase', self.enterPurchase, self.exitPurchase, [ 'walk']), - State.State('stopped', + State('stopped', self.enterStopped, self.exitStopped, [ 'walk']), - State.State('fishing', + State('fishing', self.enterFishing, self.exitFishing, [ 'walk']), - State.State('final', + State('final', self.enterFinal, self.exitFinal, [ 'start'])], @@ -195,7 +199,6 @@ class Playground(Place.Place): self.npcfaDoneEvent = 'npcfaDoneEvent' self.dialog = None self.deathAckBox = None - return def enter(self, requestStatus): self.fsm.enterInitialState() @@ -203,7 +206,7 @@ class Playground(Place.Place): self.accept('doorDoneEvent', self.handleDoorDoneEvent) self.accept('DistributedDoor_doorTrigger', self.handleDoorTrigger) base.playMusic(self.loader.music, looping=1, volume=0.8) - self.loader.geom.reparentTo(render) + self.loader.geom.reparentTo(base.render) for i in self.loader.nodeList: self.loader.enterAnimatedProps(i) @@ -231,12 +234,14 @@ class Playground(Place.Place): self.loader.hood.startSky() lightsOn = LerpColorScaleInterval(base.cr.playGame.hood.loader.geom, 0.1, Vec4(1, 1, 1, 1)) lightsOn.start() + NametagGlobals.setMasterArrowsOn(1) self.zoneId = requestStatus['zoneId'] self.tunnelOriginList = base.cr.hoodMgr.addLinkTunnelHooks(self, self.loader.nodeList, self.zoneId) how = requestStatus['how'] if how == 'teleportIn': how = 'deathAck' + self.fsm.request(how, [requestStatus]) def exit(self): @@ -248,13 +253,12 @@ class Playground(Place.Place): node.removeNode() del self.tunnelOriginList - self.loader.geom.reparentTo(hidden) + self.loader.geom.reparentTo(base.hidden) def __lightDecorationOff__(): for light in self.loader.hood.halloweenLights: - light.reparentTo(hidden) + light.reparentTo(base.hidden) - newsManager = base.cr.newsManager NametagGlobals.setMasterArrowsOn(0) for i in self.loader.nodeList: self.loader.exitAnimatedProps(i) @@ -263,7 +267,7 @@ class Playground(Place.Place): self.loader.music.stop() def load(self): - Place.Place.load(self) + Place.load(self) self.parentFSM.getStateNamed('playground').addChild(self.fsm) def unload(self): @@ -273,13 +277,14 @@ class Playground(Place.Place): if self.dialog: self.dialog.cleanup() self.dialog = None + if self.deathAckBox: self.deathAckBox.cleanup() self.deathAckBox = None + TTDialog.cleanupDialog('globalDialog') self.ignoreAll() - Place.Place.unload(self) - return + Place.unload(self) def showTreasurePoints(self, points): self.hideDebugPointText() @@ -303,7 +308,6 @@ class Playground(Place.Place): self.hideDebugPointText() lines = LineSegs() lines.setColor(1, 0, 0, 1) - from toontown.classicchars import CCharPaths for name, pointDef in list(paths.items()): self.showDebugPointText(name, pointDef[0]) for connectTo in pointDef[1]: @@ -333,6 +337,7 @@ class Playground(Place.Place): self.debugTextNode.setTextColor(1, 0, 0, 1) self.debugTextNode.setAlign(TextNode.ACenter) self.debugTextNode.setFont(ToontownGlobals.getSignFont()) + self.debugTextNode.setText(text) np = self.debugText.attachNewNode(self.debugTextNode.generate()) np.setPos(point[0], point[1], point[2]) @@ -344,7 +349,7 @@ class Playground(Place.Place): base.localAvatar.b_setAnimState('off', 1) base.localAvatar.cantLeaveGame = 1 self.accept(self.trolleyDoneEvent, self.handleTrolleyDone) - self.trolley = Trolley.Trolley(self, self.fsm, self.trolleyDoneEvent) + self.trolley = Trolley(self, self.fsm, self.trolleyDoneEvent) self.trolley.load() self.trolley.enter() @@ -376,7 +381,6 @@ class Playground(Place.Place): messenger.send(self.doneEvent) else: self.notify.error('Unknown mode: ' + mode + ' in handleTrolleyDone') - return def debugStartMinigame(self, zoneId, minigameId): self.doneStatus = {'loader': 'minigame', @@ -386,7 +390,6 @@ class Playground(Place.Place): 'shardId': None, 'minigameId': minigameId} messenger.send(self.doneEvent) - return def enterTFACallback(self, requestStatus, doneStatus): self.tfa.exit() @@ -412,7 +415,7 @@ class Playground(Place.Place): def enterHFA(self, requestStatus): self.acceptOnce(self.hfaDoneEvent, self.enterHFACallback, [requestStatus]) - self.hfa = HealthForceAcknowledge.HealthForceAcknowledge(self.hfaDoneEvent) + self.hfa = HealthForceAcknowledge(self.hfaDoneEvent) self.hfa.enter(1) def exitHFA(self): @@ -428,6 +431,7 @@ class Playground(Place.Place): outHow = {'teleportIn': 'teleportOut', 'tunnelIn': 'tunnelOut', 'doorIn': 'doorOut'} + self.fsm.request(outHow[requestStatus['how']], [requestStatus]) elif doneStatus['mode'] == 'incomplete': self.fsm.request('HFAReject') @@ -442,7 +446,7 @@ class Playground(Place.Place): def enterNPCFA(self, requestStatus): self.acceptOnce(self.npcfaDoneEvent, self.enterNPCFACallback, [requestStatus]) - self.npcfa = NPCForceAcknowledge.NPCForceAcknowledge(self.npcfaDoneEvent) + self.npcfa = NPCForceAcknowledge(self.npcfaDoneEvent) self.npcfa.enter() def exitNPCFA(self): @@ -469,20 +473,18 @@ class Playground(Place.Place): self.ignore('deathAck') self.deathAckBox.cleanup() self.deathAckBox = None - Place.Place.enterWalk(self, teleportIn) - return + + Place.enterWalk(self, teleportIn) def enterDeathAck(self, requestStatus): self.deathAckBox = None self.fsm.request('teleportIn', [requestStatus]) - return def exitDeathAck(self): if self.deathAckBox: self.ignore('deathAck') self.deathAckBox.cleanup() self.deathAckBox = None - return def enterTeleportIn(self, requestStatus): imgScale = 0.25 @@ -492,10 +494,10 @@ class Playground(Place.Place): requestStatus['nextState'] = 'popup' x, y, z, h, p, r = base.cr.hoodMgr.getPlaygroundCenterFromId(self.loader.hood.id) self.accept('deathAck', self.__handleDeathAck, extraArgs=[requestStatus]) - self.deathAckBox = DeathForceAcknowledge.DeathForceAcknowledge(doneEvent='deathAck') + self.deathAckBox = DeathForceAcknowledge(doneEvent='deathAck') elif base.localAvatar.hp > 0 and (Quests.avatarHasTrolleyQuest(base.localAvatar) or Quests.avatarHasFirstCogQuest(base.localAvatar) or Quests.avatarHasFriendQuest(base.localAvatar) or Quests.avatarHasPhoneQuest(base.localAvatar) and Quests.avatarHasCompletedPhoneQuest(base.localAvatar)) and self.loader.hood.id == ToontownGlobals.ToontownCentral: requestStatus['nextState'] = 'popup' - imageModel = loader.loadModel('phase_4/models/gui/tfa_images') + imageModel = base.loader.loadModel('phase_4/models/gui/tfa_images') if base.localAvatar.quests[0][0] == Quests.TROLLEY_QUEST_ID: if not Quests.avatarHasCompletedTrolleyQuest(base.localAvatar): x, y, z, h, p, r = base.cr.hoodMgr.getDropPoint(base.cr.hoodMgr.ToontownCentralInitialDropPoints) @@ -526,7 +528,7 @@ class Playground(Place.Place): if not Quests.avatarHasCompletedFriendQuest(base.localAvatar): x, y, z, h, p, r = base.cr.hoodMgr.getDropPoint(base.cr.hoodMgr.ToontownCentralInitialDropPoints) msg = TTLocalizer.NPCForceAcknowledgeMessage7 - gui = loader.loadModel('phase_3.5/models/gui/friendslist_gui') + gui = base.loader.loadModel('phase_3.5/models/gui/friendslist_gui') imgNodePath = gui.find('**/FriendsBox_Closed') imgPos = (0, 0, 0.04) imgScale = 1.0 @@ -544,38 +546,40 @@ class Playground(Place.Place): imgNodePath = imageModel.find('**/hq-dialog-image') imgPos = (0, 0, 0.05) imgScale = 0.5 + self.dialog = TTDialog.TTDialog(text=msg, command=self.__cleanupDialog, style=TTDialog.Acknowledge) - imgLabel = DirectLabel.DirectLabel(parent=self.dialog, relief=None, pos=imgPos, scale=TTLocalizer.PimgLabel, image=imgNodePath, image_scale=imgScale) + imgLabel = DirectLabel(parent=self.dialog, relief=None, pos=imgPos, scale=TTLocalizer.PimgLabel, image=imgNodePath, image_scale=imgScale) imageModel.removeNode() else: requestStatus['nextState'] = 'walk' x, y, z, h, p, r = base.cr.hoodMgr.getPlaygroundCenterFromId(self.loader.hood.id) + base.localAvatar.detachNode() - base.localAvatar.setPosHpr(render, x, y, z, h, p, r) - Place.Place.enterTeleportIn(self, requestStatus) - return + base.localAvatar.setPosHpr(base.render, x, y, z, h, p, r) + Place.enterTeleportIn(self, requestStatus) def __cleanupDialog(self, value): if self.dialog: self.dialog.cleanup() self.dialog = None + if hasattr(self, 'fsm'): self.fsm.request('walk', [1]) - return def __handleDeathAck(self, requestStatus): if self.deathAckBox: self.ignore('deathAck') self.deathAckBox.cleanup() self.deathAckBox = None + self.fsm.request('walk', [1]) - return def enterPopup(self, teleportIn = 0): if base.localAvatar.hp < 1: base.localAvatar.b_setAnimState('Sad', 1) else: base.localAvatar.b_setAnimState('neutral', 1.0) + self.accept('teleportQuery', self.handleTeleportQuery) base.localAvatar.setTeleportAvailable(1) base.localAvatar.startSleepWatch(self.__handleFallingAsleepPopup) @@ -589,18 +593,19 @@ class Playground(Place.Place): if hasattr(self, 'fsm'): self.fsm.request('walk') base.localAvatar.forceGotoSleep() - return Task.done + + return task.done def enterTeleportOut(self, requestStatus): - Place.Place.enterTeleportOut(self, requestStatus, self.__teleportOutDone) + Place.enterTeleportOut(self, requestStatus, self.__teleportOutDone) def __teleportOutDone(self, requestStatus): teleportDebug(requestStatus, 'Playground.__teleportOutDone(%s)' % (requestStatus,)) if hasattr(self, 'activityFsm'): self.activityFsm.requestFinalState() + hoodId = requestStatus['hoodId'] zoneId = requestStatus['zoneId'] - avId = requestStatus['avId'] shardId = requestStatus['shardId'] if hoodId == self.loader.hood.hoodId and zoneId == self.loader.hood.hoodId and shardId == None: teleportDebug(requestStatus, 'same playground') @@ -612,19 +617,19 @@ class Playground(Place.Place): teleportDebug(requestStatus, 'different hood/zone') self.doneStatus = requestStatus messenger.send(self.doneEvent) - return def exitTeleportOut(self): - Place.Place.exitTeleportOut(self) + Place.exitTeleportOut(self) def createPlayground(self, dnaFile): - loader.loadDNAFile(self.loader.dnaStore, self.safeZoneStorageDNAFile) - node = loader.loadDNAFile(self.loader.dnaStore, dnaFile) + base.loader.loadDNAFile(self.loader.dnaStore, self.safeZoneStorageDNAFile) + node = base.loader.loadDNAFile(self.loader.dnaStore, dnaFile) if node.getNumParents() == 1: self.geom = NodePath(node.getParent(0)) - self.geom.reparentTo(hidden) + self.geom.reparentTo(base.hidden) else: - self.geom = hidden.attachNewNode(node) + self.geom = base.hidden.attachNewNode(node) + self.makeDictionaries(self.loader.dnaStore) self.tunnelOriginList = base.cr.hoodMgr.addLinkTunnelHooks(self, self.nodeList, self.zoneId) self.geom.flattenMedium() @@ -636,10 +641,10 @@ class Playground(Place.Place): self.nodeList = [] for i in range(dnaStore.getNumDNAVisGroups()): groupFullName = dnaStore.getDNAVisGroupName(i) - groupName = base.cr.hoodMgr.extractGroupName(groupFullName) groupNode = self.geom.find('**/' + groupFullName) if groupNode.isEmpty(): self.notify.error('Could not find visgroup') + self.nodeList.append(groupNode) self.removeLandmarkBlockNodes() @@ -655,7 +660,7 @@ class Playground(Place.Place): def enterTFA(self, requestStatus): self.acceptOnce(self.tfaDoneEvent, self.enterTFACallback, [requestStatus]) - self.tfa = TutorialForceAcknowledge.TutorialForceAcknowledge(self.tfaDoneEvent) + self.tfa = TutorialForceAcknowledge(self.tfaDoneEvent) self.tfa.enter() def exitTFA(self):