Moved files over from decompilation branch
This commit is contained in:
parent
f49ee3d3d6
commit
bccaa37b37
5 changed files with 1059 additions and 192 deletions
|
@ -1,83 +1,74 @@
|
|||
from direct.directnotify import DirectNotifyGlobal
|
||||
from direct.distributed.DistributedObjectAI import DistributedObjectAI
|
||||
from otp.ai.AIBaseGlobal import *
|
||||
from direct.distributed.ClockDelta import *
|
||||
from direct.task import Task
|
||||
from direct.fsm.FSM import FSM
|
||||
from direct.directnotify import DirectNotifyGlobal
|
||||
from direct.fsm import ClassicFSM, State
|
||||
from direct.distributed import DistributedObjectAI
|
||||
from direct.fsm import State
|
||||
|
||||
class DistributedAnimatedPropAI(DistributedObjectAI, FSM):
|
||||
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedAnimatedPropAI")
|
||||
|
||||
def __init__(self, air):
|
||||
DistributedObjectAI.__init__(self, air)
|
||||
FSM.__init__(self, 'AnimProp')
|
||||
self.state = 'Attract'
|
||||
self.lastTime = globalClockDelta.getRealNetworkTime()
|
||||
self.propId = 0
|
||||
self.currentAvatar = 0
|
||||
|
||||
class DistributedAnimatedPropAI(DistributedObjectAI.DistributedObjectAI):
|
||||
|
||||
def setPropId(self, propId):
|
||||
def __init__(self, air, propId):
|
||||
DistributedObjectAI.DistributedObjectAI.__init__(self, air)
|
||||
self.fsm = ClassicFSM.ClassicFSM('DistributedAnimatedPropAI', [State.State('off', self.enterOff, self.exitOff, ['playing']), State.State('attract', self.enterAttract, self.exitAttract, ['playing']), State.State('playing', self.enterPlaying, self.exitPlaying, ['attract'])], 'off', 'off')
|
||||
self.fsm.enterInitialState()
|
||||
self.propId = propId
|
||||
|
||||
self.avatarId = 0
|
||||
|
||||
def delete(self):
|
||||
self.fsm.requestFinalState()
|
||||
del self.fsm
|
||||
DistributedObjectAI.DistributedObjectAI.delete(self)
|
||||
|
||||
def getPropId(self):
|
||||
return self.propId
|
||||
|
||||
def setAvatarInteract(self, avId):
|
||||
self.currentAvatar = avId
|
||||
|
||||
def d_setAvatarInteract(self, avId):
|
||||
self.sendUpdate('setAvatarInteract', [avId])
|
||||
|
||||
def b_setAvatarInteract(self, avId):
|
||||
self.setAvatarInteract(avId)
|
||||
self.d_setAvatarInteract(avId)
|
||||
|
||||
def getAvatarInteract(self):
|
||||
return self.currentAvatar
|
||||
|
||||
def requestInteract(self):
|
||||
avId = self.air.getAvatarIdFromSender()
|
||||
if self.currentAvatar != 0:
|
||||
self.sendUpdateToAvatarId(avId, 'rejectInteract', [])
|
||||
return
|
||||
elif self.state != 'Attract':
|
||||
self.sendUpdateToAvatarId(avId, 'rejectInteract', [])
|
||||
self.air.writeServerEvent('suspicious', avId, 'Toon tried to interact with a non-attractive prop!')
|
||||
return
|
||||
self.b_setAvatarInteract(avId)
|
||||
self.b_setState('Playing')
|
||||
return self.avatarId
|
||||
|
||||
def rejectInteract(self):
|
||||
pass
|
||||
def getInitialState(self):
|
||||
return [self.fsm.getCurrentState().getName(), globalClockDelta.getRealNetworkTime()]
|
||||
|
||||
def getOwnerDoId(self):
|
||||
return self.ownerDoId
|
||||
|
||||
def requestInteract(self):
|
||||
avatarId = self.air.getAvatarIdFromSender()
|
||||
stateName = self.fsm.getCurrentState().getName()
|
||||
if stateName != 'playing':
|
||||
self.sendUpdate('setAvatarInteract', [avatarId])
|
||||
self.avatarId = avatarId
|
||||
self.fsm.request('playing')
|
||||
else:
|
||||
self.sendUpdateToAvatarId(avatarId, 'rejectInteract', [])
|
||||
|
||||
def requestExit(self):
|
||||
avId = self.air.getAvatarIdFromSender()
|
||||
if self.currentAvatar != avId:
|
||||
self.air.writeServerEvent('suspicious', avId, 'Toon tried to exit an animated prop they\'re not interacting with!')
|
||||
return
|
||||
self.sendUpdate('avatarExit', [avId])
|
||||
self.b_setState('Attract')
|
||||
|
||||
def avatarExit(self, avId):
|
||||
avatarId = self.air.getAvatarIdFromSender()
|
||||
if avatarId == self.avatarId:
|
||||
stateName = self.fsm.getCurrentState().getName()
|
||||
if stateName == 'playing':
|
||||
self.sendUpdate('avatarExit', [avatarId])
|
||||
self.fsm.request('attract')
|
||||
|
||||
def getState(self):
|
||||
return [self.fsm.getCurrentState().getName(), globalClockDelta.getRealNetworkTime()]
|
||||
|
||||
def d_setState(self, state):
|
||||
self.sendUpdate('setState', [state, globalClockDelta.getRealNetworkTime()])
|
||||
|
||||
def enterOff(self):
|
||||
pass
|
||||
|
||||
def setState(self, state):
|
||||
self.lastTime = globalClockDelta.getRealNetworkTime()
|
||||
self.demand(state)
|
||||
|
||||
def d_setState(self, state):
|
||||
self.sendUpdate('setState', [state.lower(), self.lastTime])
|
||||
|
||||
def b_setState(self, state):
|
||||
self.setState(state)
|
||||
self.d_setState(state)
|
||||
|
||||
def getState(self):
|
||||
return [self.state, self.lastTime]
|
||||
|
||||
def enterPlaying(self):
|
||||
taskMgr.doMethodLater(8, self.b_setState, 'setState%d' % self.doId, ['Attract'])
|
||||
|
||||
def enterAttract(self):
|
||||
self.b_setAvatarInteract(0)
|
||||
def exitOff(self):
|
||||
pass
|
||||
|
||||
def enterAttract(self):
|
||||
self.d_setState('attract')
|
||||
|
||||
def exitAttract(self):
|
||||
pass
|
||||
|
||||
def enterPlaying(self):
|
||||
self.d_setState('playing')
|
||||
|
||||
def exitPlaying(self):
|
||||
pass
|
||||
|
|
|
@ -1,21 +1,566 @@
|
|||
from otp.ai.AIBaseGlobal import *
|
||||
from direct.distributed.ClockDelta import *
|
||||
import types
|
||||
from direct.task.Task import Task
|
||||
from direct.directnotify import DirectNotifyGlobal
|
||||
from direct.distributed.DistributedObjectAI import DistributedObjectAI
|
||||
from direct.distributed import DistributedObjectAI
|
||||
from direct.fsm import State
|
||||
from direct.fsm import ClassicFSM, State
|
||||
from toontown.toonbase.ToontownGlobals import ToonHall
|
||||
import DistributedToonInteriorAI
|
||||
import DistributedToonHallInteriorAI
|
||||
import DistributedSuitInteriorAI
|
||||
import DistributedDoorAI
|
||||
import DoorTypes
|
||||
import DistributedElevatorExtAI
|
||||
import DistributedKnockKnockDoorAI
|
||||
import SuitPlannerInteriorAI
|
||||
import SuitBuildingGlobals
|
||||
import FADoorCodes
|
||||
from toontown.hood import ZoneUtil
|
||||
import random
|
||||
import time
|
||||
#from toontown.cogdominium.DistributedCogdoInteriorAI import DistributedCogdoInteriorAI
|
||||
#from toontown.cogdominium.SuitPlannerCogdoInteriorAI import SuitPlannerCogdoInteriorAI
|
||||
#from toontown.cogdominium.CogdoLayout import CogdoLayout
|
||||
#from toontown.cogdominium.DistributedCogdoElevatorExtAI import DistributedCogdoElevatorExtAI
|
||||
|
||||
class DistributedBuildingAI(DistributedObjectAI):
|
||||
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedBuildingAI")
|
||||
class DistributedBuildingAI(DistributedObjectAI.DistributedObjectAI):
|
||||
|
||||
def setBlock(self, todo0, todo1):
|
||||
pass
|
||||
def __init__(self, air, blockNumber, zoneId, trophyMgr):
|
||||
DistributedObjectAI.DistributedObjectAI.__init__(self, air)
|
||||
self.block = blockNumber
|
||||
self.zoneId = zoneId
|
||||
self.canonicalZoneId = ZoneUtil.getCanonicalZoneId(zoneId)
|
||||
self.trophyMgr = trophyMgr
|
||||
self.victorResponses = None
|
||||
self.fsm = ClassicFSM.ClassicFSM('DistributedBuildingAI', [State.State('off', self.enterOff, self.exitOff, ['waitForVictors',
|
||||
'becomingToon',
|
||||
'toon',
|
||||
'clearOutToonInterior',
|
||||
'becomingSuit',
|
||||
'suit',
|
||||
'clearOutToonInteriorForCogdo',
|
||||
'becomingCogdo',
|
||||
'cogdo']),
|
||||
State.State('waitForVictors', self.enterWaitForVictors, self.exitWaitForVictors, ['becomingToon']),
|
||||
State.State('waitForVictorsFromCogdo', self.enterWaitForVictorsFromCogdo, self.exitWaitForVictorsFromCogdo, ['becomingToonFromCogdo']),
|
||||
State.State('becomingToon', self.enterBecomingToon, self.exitBecomingToon, ['toon']),
|
||||
State.State('becomingToonFromCogdo', self.enterBecomingToonFromCogdo, self.exitBecomingToonFromCogdo, ['toon']),
|
||||
State.State('toon', self.enterToon, self.exitToon, ['clearOutToonInterior', 'clearOutToonInteriorForCogdo']),
|
||||
State.State('clearOutToonInterior', self.enterClearOutToonInterior, self.exitClearOutToonInterior, ['becomingSuit']),
|
||||
State.State('becomingSuit', self.enterBecomingSuit, self.exitBecomingSuit, ['suit']),
|
||||
State.State('suit', self.enterSuit, self.exitSuit, ['waitForVictors', 'becomingToon']),
|
||||
State.State('clearOutToonInteriorForCogdo', self.enterClearOutToonInteriorForCogdo, self.exitClearOutToonInteriorForCogdo, ['becomingCogdo']),
|
||||
State.State('becomingCogdo', self.enterBecomingCogdo, self.exitBecomingCogdo, ['cogdo']),
|
||||
State.State('cogdo', self.enterCogdo, self.exitCogdo, ['waitForVictorsFromCogdo', 'becomingToonFromCogdo'])], 'off', 'off')
|
||||
self.fsm.enterInitialState()
|
||||
self.track = 'c'
|
||||
self.difficulty = 1
|
||||
self.numFloors = 0
|
||||
self.savedBy = None
|
||||
self.becameSuitTime = 0
|
||||
self.frontDoorPoint = None
|
||||
self.suitPlannerExt = None
|
||||
return
|
||||
|
||||
def setSuitData(self, todo0, todo1, todo2):
|
||||
pass
|
||||
def cleanup(self):
|
||||
if self.isDeleted():
|
||||
return
|
||||
self.fsm.requestFinalState()
|
||||
if hasattr(self, 'interior'):
|
||||
self.interior.requestDelete()
|
||||
del self.interior
|
||||
if hasattr(self, 'door'):
|
||||
self.door.requestDelete()
|
||||
del self.door
|
||||
self.insideDoor.requestDelete()
|
||||
del self.insideDoor
|
||||
self.knockKnock.requestDelete()
|
||||
del self.knockKnock
|
||||
if hasattr(self, 'elevator'):
|
||||
self.elevator.requestDelete()
|
||||
del self.elevator
|
||||
self.requestDelete()
|
||||
|
||||
def setVictorList(self, todo0):
|
||||
pass
|
||||
def delete(self):
|
||||
taskMgr.remove(self.taskName('suitbldg-time-out'))
|
||||
taskMgr.remove(self.taskName(str(self.block) + '_becomingToon-timer'))
|
||||
taskMgr.remove(self.taskName(str(self.block) + '_becomingSuit-timer'))
|
||||
DistributedObjectAI.DistributedObjectAI.delete(self)
|
||||
del self.fsm
|
||||
|
||||
def setState(self, todo0, todo1):
|
||||
pass
|
||||
def getPickleData(self):
|
||||
pickleData = {'state': str(self.fsm.getCurrentState().getName()),
|
||||
'block': str(self.block),
|
||||
'track': str(self.track),
|
||||
'difficulty': str(self.difficulty),
|
||||
'numFloors': str(self.numFloors),
|
||||
'savedBy': self.savedBy,
|
||||
'becameSuitTime': self.becameSuitTime}
|
||||
return pickleData
|
||||
|
||||
def _getMinMaxFloors(self, difficulty):
|
||||
return SuitBuildingGlobals.SuitBuildingInfo[difficulty][0]
|
||||
|
||||
def suitTakeOver(self, suitTrack, difficulty, buildingHeight):
|
||||
if not self.isToonBlock():
|
||||
return
|
||||
self.updateSavedBy(None)
|
||||
difficulty = min(difficulty, len(SuitBuildingGlobals.SuitBuildingInfo) - 1)
|
||||
minFloors, maxFloors = self._getMinMaxFloors(difficulty)
|
||||
if buildingHeight == None:
|
||||
numFloors = random.randint(minFloors, maxFloors)
|
||||
else:
|
||||
numFloors = buildingHeight + 1
|
||||
if numFloors < minFloors or numFloors > maxFloors:
|
||||
numFloors = random.randint(minFloors, maxFloors)
|
||||
self.track = suitTrack
|
||||
self.difficulty = difficulty
|
||||
self.numFloors = numFloors
|
||||
self.becameSuitTime = time.time()
|
||||
self.fsm.request('clearOutToonInterior')
|
||||
return
|
||||
|
||||
def cogdoTakeOver(self, difficulty, buildingHeight):
|
||||
if not self.isToonBlock():
|
||||
return
|
||||
self.updateSavedBy(None)
|
||||
minFloors, maxFloors = self._getMinMaxFloors(difficulty)
|
||||
if buildingHeight == None:
|
||||
numFloors = random.randint(minFloors, maxFloors)
|
||||
else:
|
||||
numFloors = buildingHeight + 1
|
||||
if numFloors < minFloors or numFloors > maxFloors:
|
||||
numFloors = random.randint(minFloors, maxFloors)
|
||||
self.track = 'c'
|
||||
self.difficulty = difficulty
|
||||
self.numFloors = numFloors
|
||||
self.becameSuitTime = time.time()
|
||||
self.fsm.request('clearOutToonInteriorForCogdo')
|
||||
return
|
||||
|
||||
def toonTakeOver(self):
|
||||
if 'cogdo' in self.fsm.getCurrentState().getName().lower():
|
||||
self.fsm.request('becomingToonFromCogdo')
|
||||
else:
|
||||
self.fsm.request('becomingToon')
|
||||
if self.suitPlannerExt:
|
||||
self.suitPlannerExt.recycleBuilding()
|
||||
if hasattr(self, 'interior'):
|
||||
self.interior.requestDelete()
|
||||
del self.interior
|
||||
|
||||
def getFrontDoorPoint(self):
|
||||
return self.frontDoorPoint
|
||||
|
||||
def setFrontDoorPoint(self, point):
|
||||
self.frontDoorPoint = point
|
||||
|
||||
def getBlock(self):
|
||||
dummy, interiorZoneId = self.getExteriorAndInteriorZoneId()
|
||||
return [self.block, interiorZoneId]
|
||||
|
||||
def getSuitData(self):
|
||||
return [ord(self.track), self.difficulty, self.numFloors]
|
||||
|
||||
def getState(self):
|
||||
return [self.fsm.getCurrentState().getName(), globalClockDelta.getRealNetworkTime()]
|
||||
|
||||
def setState(self, state, timestamp = 0):
|
||||
self.fsm.request(state)
|
||||
|
||||
def isSuitBuilding(self):
|
||||
state = self.fsm.getCurrentState().getName()
|
||||
return state == 'suit' or state == 'becomingSuit' or state == 'clearOutToonInterior'
|
||||
|
||||
def isCogdo(self):
|
||||
state = self.fsm.getCurrentState().getName()
|
||||
return state == 'cogdo' or state == 'becomingCogdo' or state == 'clearOutToonInteriorForCogdo'
|
||||
|
||||
def isSuitBlock(self):
|
||||
state = self.fsm.getCurrentState().getName()
|
||||
return self.isSuitBuilding() or self.isCogdo()
|
||||
|
||||
def isEstablishedSuitBlock(self):
|
||||
state = self.fsm.getCurrentState().getName()
|
||||
return state == 'suit'
|
||||
|
||||
def isToonBlock(self):
|
||||
state = self.fsm.getCurrentState().getName()
|
||||
return state in ('toon', 'becomingToon', 'becomingToonFromCogdo')
|
||||
|
||||
def getExteriorAndInteriorZoneId(self):
|
||||
blockNumber = self.block
|
||||
dnaStore = self.air.dnaStoreMap[self.canonicalZoneId]
|
||||
zoneId = dnaStore.getBlock(blockNumber).zone
|
||||
zoneId = ZoneUtil.getTrueZoneId(zoneId, self.zoneId)
|
||||
interiorZoneId = zoneId - zoneId % 100 + 500 + blockNumber
|
||||
return (zoneId, interiorZoneId)
|
||||
|
||||
def d_setState(self, state):
|
||||
self.sendUpdate('setState', [state, globalClockDelta.getRealNetworkTime()])
|
||||
|
||||
def b_setVictorList(self, victorList):
|
||||
self.setVictorList(victorList)
|
||||
self.d_setVictorList(victorList)
|
||||
|
||||
def d_setVictorList(self, victorList):
|
||||
self.sendUpdate('setVictorList', [victorList])
|
||||
|
||||
def setVictorList(self, victorList):
|
||||
self.victorList = victorList
|
||||
|
||||
def findVictorIndex(self, avId):
|
||||
for i in range(len(self.victorList)):
|
||||
if self.victorList[i] == avId:
|
||||
return i
|
||||
|
||||
return None
|
||||
|
||||
def recordVictorResponse(self, avId):
|
||||
index = self.findVictorIndex(avId)
|
||||
if index == None:
|
||||
self.air.writeServerEvent('suspicious', avId, 'DistributedBuildingAI.setVictorReady from toon not in %s.' % self.victorList)
|
||||
return
|
||||
self.victorResponses[index] = avId
|
||||
return
|
||||
|
||||
def allVictorsResponded(self):
|
||||
if self.victorResponses == self.victorList:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def setVictorReady(self):
|
||||
avId = self.air.getAvatarIdFromSender()
|
||||
if self.victorResponses == None:
|
||||
self.air.writeServerEvent('suspicious', avId, 'DistributedBuildingAI.setVictorReady in state %s.' % self.fsm.getCurrentState().getName())
|
||||
return
|
||||
self.recordVictorResponse(avId)
|
||||
event = self.air.getAvatarExitEvent(avId)
|
||||
self.ignore(event)
|
||||
if self.allVictorsResponded():
|
||||
self.toonTakeOver()
|
||||
return
|
||||
|
||||
def setVictorExited(self, avId):
|
||||
print 'victor %d exited unexpectedly for bldg %d' % (avId, self.doId)
|
||||
self.recordVictorResponse(avId)
|
||||
if self.allVictorsResponded():
|
||||
self.toonTakeOver()
|
||||
|
||||
def enterOff(self):
|
||||
pass
|
||||
|
||||
def exitOff(self):
|
||||
pass
|
||||
|
||||
def getToon(self, toonId):
|
||||
if self.air.doId2do.has_key(toonId):
|
||||
return self.air.doId2do[toonId]
|
||||
else:
|
||||
self.notify.warning('getToon() - toon: %d not in repository!' % toonId)
|
||||
return None
|
||||
|
||||
def updateSavedBy(self, savedBy):
|
||||
if self.savedBy:
|
||||
for avId, name, dna in self.savedBy:
|
||||
if not ZoneUtil.isWelcomeValley(self.zoneId):
|
||||
self.trophyMgr.removeTrophy(avId, self.numFloors)
|
||||
|
||||
self.savedBy = savedBy
|
||||
if self.savedBy:
|
||||
for avId, name, dna in self.savedBy:
|
||||
if not ZoneUtil.isWelcomeValley(self.zoneId):
|
||||
self.trophyMgr.addTrophy(avId, name, self.numFloors)
|
||||
|
||||
def enterWaitForVictors(self, victorList, savedBy):
|
||||
activeToons = []
|
||||
for t in victorList:
|
||||
toon = None
|
||||
if t:
|
||||
toon = self.getToon(t)
|
||||
if toon != None:
|
||||
activeToons.append(toon)
|
||||
|
||||
for t in victorList:
|
||||
toon = None
|
||||
if t:
|
||||
toon = self.getToon(t)
|
||||
self.air.writeServerEvent('buildingDefeated', t, '%s|%s|%s|%s' % (self.track,
|
||||
self.numFloors,
|
||||
self.zoneId,
|
||||
victorList))
|
||||
if toon != None:
|
||||
self.air.questManager.toonKilledBuilding(toon, self.track, self.difficulty, self.numFloors, self.zoneId, activeToons)
|
||||
|
||||
for i in range(0, 4):
|
||||
victor = victorList[i]
|
||||
if victor == None or not self.air.doId2do.has_key(victor):
|
||||
victorList[i] = 0
|
||||
else:
|
||||
event = self.air.getAvatarExitEvent(victor)
|
||||
self.accept(event, self.setVictorExited, extraArgs=[victor])
|
||||
|
||||
self.b_setVictorList(victorList)
|
||||
self.updateSavedBy(savedBy)
|
||||
self.victorResponses = [0,
|
||||
0,
|
||||
0,
|
||||
0]
|
||||
self.d_setState('waitForVictors')
|
||||
return
|
||||
|
||||
def exitWaitForVictors(self):
|
||||
self.victorResponses = None
|
||||
for victor in self.victorList:
|
||||
event = simbase.air.getAvatarExitEvent(victor)
|
||||
self.ignore(event)
|
||||
|
||||
return
|
||||
|
||||
def enterWaitForVictorsFromCogdo(self, victorList, savedBy):
|
||||
activeToons = []
|
||||
for t in victorList:
|
||||
toon = None
|
||||
if t:
|
||||
toon = self.getToon(t)
|
||||
if toon != None:
|
||||
activeToons.append(toon)
|
||||
|
||||
for t in victorList:
|
||||
toon = None
|
||||
if t:
|
||||
toon = self.getToon(t)
|
||||
self.air.writeServerEvent('buildingDefeated', t, '%s|%s|%s|%s' % (self.track,
|
||||
self.numFloors,
|
||||
self.zoneId,
|
||||
victorList))
|
||||
if toon != None:
|
||||
self.air.questManager.toonKilledCogdo(toon, self.difficulty, self.numFloors, self.zoneId, activeToons)
|
||||
|
||||
for i in range(0, 4):
|
||||
victor = victorList[i]
|
||||
if victor == None or not self.air.doId2do.has_key(victor):
|
||||
victorList[i] = 0
|
||||
else:
|
||||
event = self.air.getAvatarExitEvent(victor)
|
||||
self.accept(event, self.setVictorExited, extraArgs=[victor])
|
||||
|
||||
self.b_setVictorList(victorList)
|
||||
self.updateSavedBy(savedBy)
|
||||
self.victorResponses = [0,
|
||||
0,
|
||||
0,
|
||||
0]
|
||||
self.d_setState('waitForVictorsFromCogdo')
|
||||
return
|
||||
|
||||
def exitWaitForVictorsFromCogdo(self):
|
||||
self.victorResponses = None
|
||||
for victor in self.victorList:
|
||||
event = simbase.air.getAvatarExitEvent(victor)
|
||||
self.ignore(event)
|
||||
|
||||
return
|
||||
|
||||
def enterBecomingToon(self):
|
||||
self.d_setState('becomingToon')
|
||||
name = self.taskName(str(self.block) + '_becomingToon-timer')
|
||||
taskMgr.doMethodLater(SuitBuildingGlobals.VICTORY_SEQUENCE_TIME, self.becomingToonTask, name)
|
||||
|
||||
def exitBecomingToon(self):
|
||||
name = self.taskName(str(self.block) + '_becomingToon-timer')
|
||||
taskMgr.remove(name)
|
||||
|
||||
def enterBecomingToonFromCogdo(self):
|
||||
self.d_setState('becomingToonFromCogdo')
|
||||
name = self.taskName(str(self.block) + '_becomingToonFromCogdo-timer')
|
||||
taskMgr.doMethodLater(SuitBuildingGlobals.VICTORY_SEQUENCE_TIME, self.becomingToonTask, name)
|
||||
|
||||
def exitBecomingToonFromCogdo(self):
|
||||
name = self.taskName(str(self.block) + '_becomingToonFromCogdo-timer')
|
||||
taskMgr.remove(name)
|
||||
|
||||
def becomingToonTask(self, task):
|
||||
self.fsm.request('toon')
|
||||
self.suitPlannerExt.buildingMgr.save()
|
||||
return Task.done
|
||||
|
||||
def enterToon(self):
|
||||
self.d_setState('toon')
|
||||
exteriorZoneId, interiorZoneId = self.getExteriorAndInteriorZoneId()
|
||||
if simbase.config.GetBool('want-new-toonhall', 0) and ZoneUtil.getCanonicalZoneId(interiorZoneId) == ToonHall:
|
||||
self.interior = DistributedToonHallInteriorAI.DistributedToonHallInteriorAI(self.block, self.air, interiorZoneId, self)
|
||||
else:
|
||||
self.interior = DistributedToonInteriorAI.DistributedToonInteriorAI(self.block, self.air, interiorZoneId, self)
|
||||
self.interior.generateWithRequired(interiorZoneId)
|
||||
door = self.createExteriorDoor()
|
||||
insideDoor = DistributedDoorAI.DistributedDoorAI(self.air, self.block, DoorTypes.INT_STANDARD)
|
||||
door.setOtherDoor(insideDoor)
|
||||
insideDoor.setOtherDoor(door)
|
||||
door.zoneId = exteriorZoneId
|
||||
insideDoor.zoneId = interiorZoneId
|
||||
door.generateWithRequired(exteriorZoneId)
|
||||
insideDoor.generateWithRequired(interiorZoneId)
|
||||
self.door = door
|
||||
self.insideDoor = insideDoor
|
||||
self.becameSuitTime = 0
|
||||
self.knockKnock = DistributedKnockKnockDoorAI.DistributedKnockKnockDoorAI(self.air, self.block)
|
||||
self.knockKnock.generateWithRequired(exteriorZoneId)
|
||||
self.air.writeServerEvent('building-toon', self.doId, '%s|%s' % (self.zoneId, self.block))
|
||||
|
||||
def createExteriorDoor(self):
|
||||
result = DistributedDoorAI.DistributedDoorAI(self.air, self.block, DoorTypes.EXT_STANDARD)
|
||||
return result
|
||||
|
||||
def exitToon(self):
|
||||
self.door.setDoorLock(FADoorCodes.BUILDING_TAKEOVER)
|
||||
|
||||
def enterClearOutToonInterior(self):
|
||||
self.d_setState('clearOutToonInterior')
|
||||
if hasattr(self, 'interior'):
|
||||
self.interior.setState('beingTakenOver')
|
||||
name = self.taskName(str(self.block) + '_clearOutToonInterior-timer')
|
||||
taskMgr.doMethodLater(SuitBuildingGlobals.CLEAR_OUT_TOON_BLDG_TIME, self.clearOutToonInteriorTask, name)
|
||||
|
||||
def exitClearOutToonInterior(self):
|
||||
name = self.taskName(str(self.block) + '_clearOutToonInterior-timer')
|
||||
taskMgr.remove(name)
|
||||
|
||||
def clearOutToonInteriorTask(self, task):
|
||||
self.fsm.request('becomingSuit')
|
||||
return Task.done
|
||||
|
||||
def enterBecomingSuit(self):
|
||||
self.sendUpdate('setSuitData', [ord(self.track), self.difficulty, self.numFloors])
|
||||
self.d_setState('becomingSuit')
|
||||
name = self.taskName(str(self.block) + '_becomingSuit-timer')
|
||||
taskMgr.doMethodLater(SuitBuildingGlobals.TO_SUIT_BLDG_TIME, self.becomingSuitTask, name)
|
||||
|
||||
def exitBecomingSuit(self):
|
||||
name = self.taskName(str(self.block) + '_becomingSuit-timer')
|
||||
taskMgr.remove(name)
|
||||
if hasattr(self, 'interior'):
|
||||
self.interior.requestDelete()
|
||||
del self.interior
|
||||
self.door.requestDelete()
|
||||
del self.door
|
||||
self.insideDoor.requestDelete()
|
||||
del self.insideDoor
|
||||
self.knockKnock.requestDelete()
|
||||
del self.knockKnock
|
||||
|
||||
def becomingSuitTask(self, task):
|
||||
self.fsm.request('suit')
|
||||
self.suitPlannerExt.buildingMgr.save()
|
||||
return Task.done
|
||||
|
||||
def enterSuit(self):
|
||||
self.sendUpdate('setSuitData', [ord(self.track), self.difficulty, self.numFloors])
|
||||
zoneId, interiorZoneId = self.getExteriorAndInteriorZoneId()
|
||||
self.planner = SuitPlannerInteriorAI.SuitPlannerInteriorAI(self.numFloors, self.difficulty, self.track, interiorZoneId)
|
||||
self.d_setState('suit')
|
||||
exteriorZoneId, interiorZoneId = self.getExteriorAndInteriorZoneId()
|
||||
self.elevator = DistributedElevatorExtAI.DistributedElevatorExtAI(self.air, self)
|
||||
self.elevator.generateWithRequired(exteriorZoneId)
|
||||
self.air.writeServerEvent('building-cog', self.doId, '%s|%s|%s|%s' % (self.zoneId,
|
||||
self.block,
|
||||
self.track,
|
||||
self.numFloors))
|
||||
|
||||
def exitSuit(self):
|
||||
del self.planner
|
||||
if hasattr(self, 'elevator'):
|
||||
self.elevator.requestDelete()
|
||||
del self.elevator
|
||||
|
||||
def enterClearOutToonInteriorForCogdo(self):
|
||||
self.d_setState('clearOutToonInteriorForCogdo')
|
||||
if hasattr(self, 'interior'):
|
||||
self.interior.setState('beingTakenOver')
|
||||
name = self.taskName(str(self.block) + '_clearOutToonInteriorForCogdo-timer')
|
||||
taskMgr.doMethodLater(SuitBuildingGlobals.CLEAR_OUT_TOON_BLDG_TIME, self.clearOutToonInteriorForCogdoTask, name)
|
||||
|
||||
def exitClearOutToonInteriorForCogdo(self):
|
||||
name = self.taskName(str(self.block) + '_clearOutToonInteriorForCogdo-timer')
|
||||
taskMgr.remove(name)
|
||||
|
||||
def clearOutToonInteriorForCogdoTask(self, task):
|
||||
self.fsm.request('becomingCogdo')
|
||||
return Task.done
|
||||
|
||||
def enterBecomingCogdo(self):
|
||||
self.sendUpdate('setSuitData', [ord(self.track), self.difficulty, self.numFloors])
|
||||
self.d_setState('becomingCogdo')
|
||||
name = self.taskName(str(self.block) + '_becomingCogdo-timer')
|
||||
taskMgr.doMethodLater(SuitBuildingGlobals.TO_SUIT_BLDG_TIME, self.becomingCogdoTask, name)
|
||||
|
||||
def exitBecomingCogdo(self):
|
||||
name = self.taskName(str(self.block) + '_becomingCogdo-timer')
|
||||
taskMgr.remove(name)
|
||||
if hasattr(self, 'interior'):
|
||||
self.interior.requestDelete()
|
||||
del self.interior
|
||||
self.door.requestDelete()
|
||||
del self.door
|
||||
self.insideDoor.requestDelete()
|
||||
del self.insideDoor
|
||||
self.knockKnock.requestDelete()
|
||||
del self.knockKnock
|
||||
|
||||
def becomingCogdoTask(self, task):
|
||||
self.fsm.request('cogdo')
|
||||
self.suitPlannerExt.buildingMgr.save()
|
||||
return Task.done
|
||||
|
||||
def enterCogdo(self):
|
||||
self.sendUpdate('setSuitData', [ord(self.track), self.difficulty, self.numFloors])
|
||||
zoneId, interiorZoneId = self.getExteriorAndInteriorZoneId()
|
||||
self._cogdoLayout = CogdoLayout(self.numFloors)
|
||||
self.planner = SuitPlannerCogdoInteriorAI(self._cogdoLayout, self.difficulty, self.track, interiorZoneId)
|
||||
self.d_setState('cogdo')
|
||||
exteriorZoneId, interiorZoneId = self.getExteriorAndInteriorZoneId()
|
||||
self.elevator = DistributedCogdoElevatorExtAI(self.air, self)
|
||||
self.elevator.generateWithRequired(exteriorZoneId)
|
||||
self.air.writeServerEvent('building-cogdo', self.doId, '%s|%s|%s' % (self.zoneId, self.block, self.numFloors))
|
||||
|
||||
def exitCogdo(self):
|
||||
del self.planner
|
||||
if hasattr(self, 'elevator'):
|
||||
self.elevator.requestDelete()
|
||||
del self.elevator
|
||||
|
||||
def setSuitPlannerExt(self, planner):
|
||||
self.suitPlannerExt = planner
|
||||
|
||||
def _createSuitInterior(self):
|
||||
return DistributedSuitInteriorAI.DistributedSuitInteriorAI(self.air, self.elevator)
|
||||
|
||||
def _createCogdoInterior(self):
|
||||
return DistributedCogdoInteriorAI(self.air, self.elevator)
|
||||
|
||||
def createSuitInterior(self):
|
||||
self.interior = self._createSuitInterior()
|
||||
dummy, interiorZoneId = self.getExteriorAndInteriorZoneId()
|
||||
self.interior.fsm.request('WaitForAllToonsInside')
|
||||
self.interior.generateWithRequired(interiorZoneId)
|
||||
|
||||
def createCogdoInterior(self):
|
||||
self.interior = self._createCogdoInterior()
|
||||
dummy, interiorZoneId = self.getExteriorAndInteriorZoneId()
|
||||
self.interior.fsm.request('WaitForAllToonsInside')
|
||||
self.interior.generateWithRequired(interiorZoneId)
|
||||
|
||||
def deleteSuitInterior(self):
|
||||
if hasattr(self, 'interior'):
|
||||
self.interior.requestDelete()
|
||||
del self.interior
|
||||
if hasattr(self, 'elevator'):
|
||||
self.elevator.d_setFloor(-1)
|
||||
self.elevator.open()
|
||||
|
||||
def deleteCogdoInterior(self):
|
||||
self.deleteSuitInterior()
|
||||
# VERIFICATION FAILED
|
||||
|
|
352
toontown/building/DistributedBuildingMgrAI.py
Normal file
352
toontown/building/DistributedBuildingMgrAI.py
Normal file
|
@ -0,0 +1,352 @@
|
|||
import os
|
||||
from direct.task.Task import Task
|
||||
import cPickle
|
||||
from otp.ai.AIBaseGlobal import *
|
||||
import DistributedBuildingAI
|
||||
import HQBuildingAI
|
||||
#import GagshopBuildingAI
|
||||
#import PetshopBuildingAI
|
||||
#from toontown.building.KartShopBuildingAI import KartShopBuildingAI
|
||||
#from toontown.building import DistributedAnimBuildingAI
|
||||
from direct.directnotify import DirectNotifyGlobal
|
||||
from toontown.hood import ZoneUtil
|
||||
import time
|
||||
import random
|
||||
|
||||
class DistributedBuildingMgrAI:
|
||||
notify = DirectNotifyGlobal.directNotify.newCategory('DistributedBuildingMgrAI')
|
||||
serverDatafolder = simbase.config.GetString('server-data-folder', '')
|
||||
|
||||
def __init__(self, air, branchID, dnaStore, trophyMgr):
|
||||
self.branchID = branchID
|
||||
self.canonicalBranchID = ZoneUtil.getCanonicalZoneId(branchID)
|
||||
self.air = air
|
||||
self.__buildings = {}
|
||||
self.dnaStore = dnaStore
|
||||
self.trophyMgr = trophyMgr
|
||||
self.shard = str(air.districtId)
|
||||
self.backupExtension = '.bu'
|
||||
self.findAllLandmarkBuildings()
|
||||
self.doLaterTask = None
|
||||
return
|
||||
|
||||
def cleanup(self):
|
||||
taskMgr.remove(str(self.branchID) + '_delayed_save-timer')
|
||||
for building in self.__buildings.values():
|
||||
building.cleanup()
|
||||
|
||||
self.__buildings = {}
|
||||
|
||||
def isValidBlockNumber(self, blockNumber):
|
||||
return self.__buildings.has_key(blockNumber)
|
||||
|
||||
def delayedSaveTask(self, task):
|
||||
self.save()
|
||||
self.doLaterTask = None
|
||||
return Task.done
|
||||
|
||||
def isSuitBlock(self, blockNumber):
|
||||
return self.__buildings[blockNumber].isSuitBlock()
|
||||
|
||||
def getSuitBlocks(self):
|
||||
blocks = []
|
||||
for i in self.__buildings.values():
|
||||
if i.isSuitBlock():
|
||||
blocks.append(i.getBlock()[0])
|
||||
|
||||
return blocks
|
||||
|
||||
def getEstablishedSuitBlocks(self):
|
||||
blocks = []
|
||||
for i in self.__buildings.values():
|
||||
if i.isEstablishedSuitBlock():
|
||||
blocks.append(i.getBlock()[0])
|
||||
|
||||
return blocks
|
||||
|
||||
def getToonBlocks(self):
|
||||
blocks = []
|
||||
for i in self.__buildings.values():
|
||||
if isinstance(i, HQBuildingAI.HQBuildingAI):
|
||||
continue
|
||||
if not i.isSuitBlock():
|
||||
blocks.append(i.getBlock()[0])
|
||||
|
||||
return blocks
|
||||
|
||||
def getBuildings(self):
|
||||
return self.__buildings.values()
|
||||
|
||||
def getFrontDoorPoint(self, blockNumber):
|
||||
return self.__buildings[blockNumber].getFrontDoorPoint()
|
||||
|
||||
def getBuildingTrack(self, blockNumber):
|
||||
return self.__buildings[blockNumber].track
|
||||
|
||||
def getBuilding(self, blockNumber):
|
||||
return self.__buildings[blockNumber]
|
||||
|
||||
def setFrontDoorPoint(self, blockNumber, point):
|
||||
return self.__buildings[blockNumber].setFrontDoorPoint(point)
|
||||
|
||||
def getDNABlockLists(self):
|
||||
blocks = []
|
||||
hqBlocks = []
|
||||
gagshopBlocks = []
|
||||
petshopBlocks = []
|
||||
kartshopBlocks = []
|
||||
animBldgBlocks = []
|
||||
for blockId, block in self.dnaStore.getBlocks():
|
||||
blockNumber = blockId
|
||||
buildingType = block.buildingType
|
||||
if buildingType == 'hq':
|
||||
hqBlocks.append(blockNumber)
|
||||
elif buildingType == 'gagshop':
|
||||
gagshopBlocks.append(blockNumber)
|
||||
elif buildingType == 'petshop':
|
||||
petshopBlocks.append(blockNumber)
|
||||
elif buildingType == 'kartshop':
|
||||
kartshopBlocks.append(blockNumber)
|
||||
elif buildingType == 'animbldg':
|
||||
animBldgBlocks.append(blockNumber)
|
||||
else:
|
||||
blocks.append(blockNumber)
|
||||
|
||||
return (blocks,
|
||||
hqBlocks,
|
||||
gagshopBlocks,
|
||||
petshopBlocks,
|
||||
kartshopBlocks,
|
||||
animBldgBlocks)
|
||||
|
||||
def findAllLandmarkBuildings(self):
|
||||
buildings = self.load()
|
||||
blocks, hqBlocks, gagshopBlocks, petshopBlocks, kartshopBlocks, animBldgBlocks = self.getDNABlockLists()
|
||||
for block in blocks:
|
||||
self.newBuilding(block, buildings.get(block, None))
|
||||
|
||||
for block in animBldgBlocks:
|
||||
self.newAnimBuilding(block, buildings.get(block, None))
|
||||
|
||||
for block in hqBlocks:
|
||||
self.newHQBuilding(block)
|
||||
|
||||
for block in gagshopBlocks:
|
||||
self.newGagshopBuilding(block)
|
||||
|
||||
if simbase.wantPets:
|
||||
for block in petshopBlocks:
|
||||
self.newPetshopBuilding(block)
|
||||
|
||||
if simbase.wantKarts:
|
||||
for block in kartshopBlocks:
|
||||
self.newKartShopBuilding(block)
|
||||
|
||||
return
|
||||
|
||||
def newBuilding(self, blockNumber, blockData = None):
|
||||
building = DistributedBuildingAI.DistributedBuildingAI(self.air, blockNumber, self.branchID, self.trophyMgr)
|
||||
building.generateWithRequired(self.branchID)
|
||||
if blockData:
|
||||
building.track = blockData.get('track', 'c')
|
||||
building.difficulty = int(blockData.get('difficulty', 1))
|
||||
building.numFloors = int(blockData.get('numFloors', 1))
|
||||
building.numFloors = max(1, min(5, building.numFloors))
|
||||
if not ZoneUtil.isWelcomeValley(building.zoneId):
|
||||
building.updateSavedBy(blockData.get('savedBy'))
|
||||
else:
|
||||
self.notify.warning('we had a cog building in welcome valley %d' % building.zoneId)
|
||||
building.becameSuitTime = blockData.get('becameSuitTime', time.time())
|
||||
if blockData['state'] == 'suit':
|
||||
building.setState('suit')
|
||||
elif blockData['state'] == 'cogdo':
|
||||
if simbase.air.wantCogdominiums:
|
||||
building.setState('cogdo')
|
||||
else:
|
||||
building.setState('toon')
|
||||
else:
|
||||
building.setState('toon')
|
||||
self.__buildings[blockNumber] = building
|
||||
return building
|
||||
|
||||
def newAnimBuilding(self, blockNumber, blockData = None):
|
||||
return
|
||||
building = DistributedAnimBuildingAI.DistributedAnimBuildingAI(self.air, blockNumber, self.branchID, self.trophyMgr)
|
||||
building.generateWithRequired(self.branchID)
|
||||
if blockData:
|
||||
building.track = blockData.get('track', 'c')
|
||||
building.difficulty = int(blockData.get('difficulty', 1))
|
||||
building.numFloors = int(blockData.get('numFloors', 1))
|
||||
if not ZoneUtil.isWelcomeValley(building.zoneId):
|
||||
building.updateSavedBy(blockData.get('savedBy'))
|
||||
else:
|
||||
self.notify.warning('we had a cog building in welcome valley %d' % building.zoneId)
|
||||
building.becameSuitTime = blockData.get('becameSuitTime', time.time())
|
||||
if blockData['state'] == 'suit':
|
||||
building.setState('suit')
|
||||
else:
|
||||
building.setState('toon')
|
||||
else:
|
||||
building.setState('toon')
|
||||
self.__buildings[blockNumber] = building
|
||||
return building
|
||||
|
||||
def newHQBuilding(self, blockNumber):
|
||||
dnaStore = self.air.dnaStoreMap[self.canonicalBranchID]
|
||||
exteriorZoneId = dnaStore.getBlock(blockNumber).zone
|
||||
exteriorZoneId = ZoneUtil.getTrueZoneId(exteriorZoneId, self.branchID)
|
||||
interiorZoneId = self.branchID - self.branchID % 100 + 500 + blockNumber
|
||||
self.notify.debug("Spawning HQ ext: {0} int: {1}".format(exteriorZoneId, interiorZoneId))
|
||||
building = HQBuildingAI.HQBuildingAI(self.air, exteriorZoneId, interiorZoneId, blockNumber)
|
||||
self.__buildings[blockNumber] = building
|
||||
return building
|
||||
|
||||
def newGagshopBuilding(self, blockNumber):
|
||||
return
|
||||
dnaStore = self.air.dnaStoreMap[self.canonicalBranchID]
|
||||
exteriorZoneId = dnaStore.getBlock(blockNumber).zone
|
||||
exteriorZoneId = ZoneUtil.getTrueZoneId(exteriorZoneId, self.branchID)
|
||||
interiorZoneId = self.branchID - self.branchID % 100 + 500 + blockNumber
|
||||
building = GagshopBuildingAI.GagshopBuildingAI(self.air, exteriorZoneId, interiorZoneId, blockNumber)
|
||||
self.__buildings[blockNumber] = building
|
||||
return building
|
||||
|
||||
def newPetshopBuilding(self, blockNumber):
|
||||
return
|
||||
dnaStore = self.air.dnaStoreMap[self.canonicalBranchID]
|
||||
exteriorZoneId = dnaStore.getBlock(blockNumber).zone
|
||||
exteriorZoneId = ZoneUtil.getTrueZoneId(exteriorZoneId, self.branchID)
|
||||
interiorZoneId = self.branchID - self.branchID % 100 + 500 + blockNumber
|
||||
building = PetshopBuildingAI.PetshopBuildingAI(self.air, exteriorZoneId, interiorZoneId, blockNumber)
|
||||
self.__buildings[blockNumber] = building
|
||||
return building
|
||||
|
||||
def newKartShopBuilding(self, blockNumber):
|
||||
return
|
||||
dnaStore = self.air.dnaStoreMap[self.canonicalBranchID]
|
||||
exteriorZoneId = dnaStore.getBlock(blockNumber).zone
|
||||
exteriorZoneId = ZoneUtil.getTrueZoneId(exteriorZoneId, self.branchID)
|
||||
interiorZoneId = self.branchID - self.branchID % 100 + 500 + blockNumber
|
||||
building = KartShopBuildingAI(self.air, exteriorZoneId, interiorZoneId, blockNumber)
|
||||
self.__buildings[blockNumber] = building
|
||||
return building
|
||||
|
||||
def getFileName(self):
|
||||
f = '%s%s_%d.buildings' % (self.serverDatafolder, self.shard, self.branchID)
|
||||
return f
|
||||
|
||||
def saveTo(self, file, block = None):
|
||||
if block:
|
||||
pickleData = block.getPickleData()
|
||||
cPickle.dump(pickleData, file)
|
||||
else:
|
||||
for i in self.__buildings.values():
|
||||
if isinstance(i, HQBuildingAI.HQBuildingAI):
|
||||
continue
|
||||
pickleData = i.getPickleData()
|
||||
cPickle.dump(pickleData, file)
|
||||
|
||||
def fastSave(self, block):
|
||||
return
|
||||
try:
|
||||
fileName = self.getFileName() + '.delta'
|
||||
working = fileName + '.temp'
|
||||
if os.path.exists(working):
|
||||
os.remove(working)
|
||||
os.rename(fileName, working)
|
||||
file = open(working, 'w')
|
||||
file.seek(0, 2)
|
||||
self.saveTo(file, block)
|
||||
file.close()
|
||||
os.rename(working, fileName)
|
||||
except IOError:
|
||||
self.notify.error(str(sys.exc_info()[1]))
|
||||
|
||||
def save(self):
|
||||
try:
|
||||
fileName = self.getFileName()
|
||||
backup = fileName + self.backupExtension
|
||||
if os.path.exists(fileName):
|
||||
os.rename(fileName, backup)
|
||||
file = open(fileName, 'w')
|
||||
file.seek(0)
|
||||
self.saveTo(file)
|
||||
file.close()
|
||||
if os.path.exists(backup):
|
||||
os.remove(backup)
|
||||
except EnvironmentError:
|
||||
self.notify.warning(str(sys.exc_info()[1]))
|
||||
|
||||
def loadFrom(self, file):
|
||||
|
||||
#0 BUILD_MAP None
|
||||
#3 STORE_FAST 'blocks'
|
||||
blocks = {}
|
||||
|
||||
#6 SETUP_EXCEPT '55'
|
||||
try:
|
||||
|
||||
#9 SETUP_LOOP '51'
|
||||
while 1:
|
||||
|
||||
#12 LOAD_GLOBAL 'cPickle'
|
||||
#15 LOAD_ATTR 'load'
|
||||
#18 LOAD_FAST 'file'
|
||||
#21 CALL_FUNCTION_1 None
|
||||
#24 STORE_FAST 'pickleData'
|
||||
pickleData = cPickle.load(file)
|
||||
|
||||
|
||||
#27 LOAD_FAST 'pickleData'
|
||||
#30 LOAD_FAST 'blocks'
|
||||
#33 LOAD_GLOBAL 'int'
|
||||
#36 LOAD_FAST 'pickleData'
|
||||
#39 LOAD_CONST 'block'
|
||||
#42 BINARY_SUBSCR None
|
||||
#43 CALL_FUNCTION_1 None
|
||||
#46 STORE_SUBSCR None
|
||||
#47 JUMP_BACK '12'
|
||||
#50 POP_BLOCK None
|
||||
#51_0 COME_FROM '9'
|
||||
#51 POP_BLOCK None
|
||||
#52 JUMP_FORWARD '72'
|
||||
#55_0 COME_FROM '6'
|
||||
blocks[int(pickleData['block'])] = pickleData
|
||||
|
||||
#55 DUP_TOP None
|
||||
#56 LOAD_GLOBAL 'EOFError'
|
||||
#59 COMPARE_OP 'exception match'
|
||||
#62 JUMP_IF_FALSE '71'
|
||||
#65 POP_TOP None
|
||||
#66 POP_TOP None
|
||||
#67 POP_TOP None
|
||||
except EOFError:
|
||||
pass
|
||||
|
||||
#68 JUMP_FORWARD '72'
|
||||
#71 END_FINALLY None
|
||||
#72_0 COME_FROM '52'
|
||||
#72_1 COME_FROM '71'
|
||||
|
||||
#72 LOAD_FAST 'blocks'
|
||||
#75 RETURN_VALUE None
|
||||
#-1 RETURN_LAST None
|
||||
return blocks
|
||||
|
||||
def load(self):
|
||||
fileName = self.getFileName()
|
||||
try:
|
||||
file = open(fileName + self.backupExtension, 'r')
|
||||
if os.path.exists(fileName):
|
||||
os.remove(fileName)
|
||||
except IOError:
|
||||
try:
|
||||
file = open(fileName, 'r')
|
||||
except IOError:
|
||||
return {}
|
||||
|
||||
file.seek(0)
|
||||
blocks = self.loadFrom(file)
|
||||
file.close()
|
||||
return blocks
|
||||
# VERIFICATION PASSED
|
|
@ -1,28 +1,42 @@
|
|||
from otp.ai.AIBaseGlobal import *
|
||||
from direct.distributed.ClockDelta import *
|
||||
from direct.directnotify import DirectNotifyGlobal
|
||||
from toontown.building.DistributedAnimatedPropAI import DistributedAnimatedPropAI
|
||||
from toontown.dna.DNASpawnerAI import *
|
||||
from toontown.dna.DNAFlatDoor import DNAFlatDoor
|
||||
import re
|
||||
from direct.fsm import ClassicFSM
|
||||
import DistributedAnimatedPropAI
|
||||
from direct.task.Task import Task
|
||||
from direct.fsm import State
|
||||
|
||||
class DistributedKnockKnockDoorAI(DistributedAnimatedPropAI):
|
||||
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedKnockKnockDoorAI")
|
||||
class DistributedKnockKnockDoorAI(DistributedAnimatedPropAI.DistributedAnimatedPropAI):
|
||||
|
||||
# DNA spawn code:
|
||||
buildingPattern = re.compile('tb([0-9]+):')
|
||||
@dnaSpawn(DNAFlatDoor)
|
||||
def spawn(air, zone, element):
|
||||
# Get door's parent building:
|
||||
building = element.parent.parent
|
||||
|
||||
# Parse building name to figure out index number:
|
||||
match = buildingPattern.match(building.name)
|
||||
|
||||
if not match:
|
||||
# No match! Can't spawn a door...
|
||||
def __init__(self, air, propId):
|
||||
DistributedAnimatedPropAI.DistributedAnimatedPropAI.__init__(self, air, propId)
|
||||
self.fsm.setName('DistributedKnockKnockDoor')
|
||||
self.propId = propId
|
||||
self.doLaterTask = None
|
||||
return
|
||||
|
||||
index = int(match.group(1))
|
||||
def enterOff(self):
|
||||
DistributedAnimatedPropAI.DistributedAnimatedPropAI.enterOff(self)
|
||||
|
||||
door = DistributedKnockKnockDoorAI(air)
|
||||
door.setPropId(index)
|
||||
door.generateWithRequired(zone)
|
||||
def exitOff(self):
|
||||
DistributedAnimatedPropAI.DistributedAnimatedPropAI.exitOff(self)
|
||||
|
||||
def attractTask(self, task):
|
||||
self.fsm.request('attract')
|
||||
return Task.done
|
||||
|
||||
def enterAttract(self):
|
||||
DistributedAnimatedPropAI.DistributedAnimatedPropAI.enterAttract(self)
|
||||
|
||||
def exitAttract(self):
|
||||
DistributedAnimatedPropAI.DistributedAnimatedPropAI.exitAttract(self)
|
||||
|
||||
def enterPlaying(self):
|
||||
DistributedAnimatedPropAI.DistributedAnimatedPropAI.enterPlaying(self)
|
||||
self.doLaterTask = taskMgr.doMethodLater(9, self.attractTask, self.uniqueName('knockKnock-timer'))
|
||||
|
||||
def exitPlaying(self):
|
||||
DistributedAnimatedPropAI.DistributedAnimatedPropAI.exitPlaying(self)
|
||||
taskMgr.remove(self.doLaterTask)
|
||||
self.doLaterTask = None
|
||||
return
|
||||
|
|
|
@ -1,98 +1,63 @@
|
|||
from direct.directnotify import DirectNotifyGlobal
|
||||
from direct.distributed.DistributedObjectAI import DistributedObjectAI
|
||||
from toontown.toonbase.ToontownGlobals import *
|
||||
from otp.ai.AIBaseGlobal import *
|
||||
from direct.distributed.ClockDelta import *
|
||||
import cPickle
|
||||
from direct.directnotify import DirectNotifyGlobal
|
||||
from direct.fsm import ClassicFSM, State
|
||||
from direct.distributed import DistributedObjectAI
|
||||
from direct.fsm import State
|
||||
from toontown.toon import NPCToons
|
||||
|
||||
class DistributedToonInteriorAI(DistributedObjectAI):
|
||||
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedToonInteriorAI")
|
||||
|
||||
def __init__(self, air):
|
||||
DistributedObjectAI.__init__(self, air)
|
||||
self.air = air
|
||||
|
||||
def setZoneIdAndBlock(self, zoneId, block):
|
||||
self.zoneId = zoneId
|
||||
class DistributedToonInteriorAI(DistributedObjectAI.DistributedObjectAI):
|
||||
|
||||
def __init__(self, block, air, zoneId, building):
|
||||
DistributedObjectAI.DistributedObjectAI.__init__(self, air)
|
||||
self.block = block
|
||||
|
||||
def d_setZoneIdAndBlock(self, zoneId, block):
|
||||
self.sendUpdate('setZoneIdAndBlock', [zoneId, block])
|
||||
|
||||
def b_setZoneIdAndBlock(self, zoneId, block):
|
||||
self.setZoneIdAndBlock(zoneId, block)
|
||||
self.d_setZoneIdAndBlock(zoneId, block)
|
||||
|
||||
def getZoneIdAndBlock(self):
|
||||
return [self.zoneId, self.block]
|
||||
self.zoneId = zoneId
|
||||
self.building = building
|
||||
self.npcs = NPCToons.createNpcsInZone(air, zoneId)
|
||||
self.fsm = ClassicFSM.ClassicFSM('DistributedToonInteriorAI', [State.State('toon', self.enterToon, self.exitToon, ['beingTakenOver']), State.State('beingTakenOver', self.enterBeingTakenOver, self.exitBeingTakenOver, []), State.State('off', self.enterOff, self.exitOff, [])], 'toon', 'off')
|
||||
self.fsm.enterInitialState()
|
||||
|
||||
def delete(self):
|
||||
self.ignoreAll()
|
||||
for npc in self.npcs:
|
||||
npc.requestDelete()
|
||||
|
||||
del self.npcs
|
||||
del self.fsm
|
||||
del self.building
|
||||
DistributedObjectAI.DistributedObjectAI.delete(self)
|
||||
|
||||
def getZoneIdAndBlock(self):
|
||||
r = [self.zoneId, self.block]
|
||||
return r
|
||||
|
||||
def setToonData(self, toonData):
|
||||
pass
|
||||
|
||||
def getToonData(self):
|
||||
return cPickle.dumps(None)
|
||||
return cPickle.dumps(self.building.savedBy, 1)
|
||||
|
||||
def getState(self):
|
||||
r = [self.fsm.getCurrentState().getName(), globalClockDelta.getRealNetworkTime()]
|
||||
return r
|
||||
|
||||
def setState(self, state):
|
||||
self.timeStamp = globalClockDelta.getRealNetworkTime()
|
||||
self.state = state
|
||||
|
||||
def getState(self):
|
||||
return [self.state, self.timeStamp]
|
||||
|
||||
def nextSnowmanHeadPart(self):
|
||||
avId = self.air.getAvatarIdFromSender()
|
||||
if avId not in self.air.doId2do:
|
||||
self.notify.warning('avId %d does not exist as an object in the AIRepo.' % avId)
|
||||
return False # Avatar does not even exist, water you doin'.
|
||||
|
||||
av = self.air.doId2do.get(avId)
|
||||
if av.savedCheesyEffect == 14:
|
||||
#av.setSystemMessage(0, 'McQuack: You have already completed the snowman head quest!')
|
||||
return False # Avatar already has a snowman head.
|
||||
|
||||
snowmanHeadInteriors = [
|
||||
2740, # TTC, Loopy Lane, Used Firecrackers
|
||||
4652, # MML, Alto Avenue, Full Stop Shop
|
||||
9608, # DDL, non-HQ street, Cat Nip For Cat Naps
|
||||
5710, # DG, Maple Street, Tuft Guy Gym
|
||||
1711, # DD, Seaweed Street, Deep-Sea Diner
|
||||
3620, # TB, Walrus Way, Skiing Clinic
|
||||
]
|
||||
|
||||
snowmanNPCWhispers = {
|
||||
snowmanHeadInteriors[0] : 'Smokey Joe',
|
||||
snowmanHeadInteriors[1] : 'Patty Pause',
|
||||
snowmanHeadInteriors[2] : 'Kathy Nip',
|
||||
snowmanHeadInteriors[3] : 'Lars Bicep',
|
||||
snowmanHeadInteriors[4] : 'Dinah Down',
|
||||
snowmanHeadInteriors[5] : 'Henry the Hazard',
|
||||
}
|
||||
|
||||
if self.zoneId in snowmanHeadInteriors:
|
||||
if not hasattr(self.air, 'snowmanProgress'):
|
||||
self.air.snowmanProgress = {}
|
||||
|
||||
if str(avId) in self.air.snowmanProgress:
|
||||
avProg = self.air.snowmanProgress.get(str(avId))
|
||||
if avProg == snowmanHeadInteriors[-1]:
|
||||
#av.d_setSystemMessage(0, 'McQuack: You have already completed the snowman head quest!')
|
||||
return False # They have already completed the quest.
|
||||
|
||||
avNextProg = snowmanHeadInteriors[snowmanHeadInteriors.index(avProg) + 1]
|
||||
|
||||
if avNextProg == self.zoneId:
|
||||
self.air.snowmanProgress[str(avId)] = avNextProg
|
||||
shopsLeft = len(snowmanHeadInteriors) - (snowmanHeadInteriors.index(avNextProg) + 1)
|
||||
if shopsLeft > 1:
|
||||
av.d_setSystemMessage(0, '%s: Merry Christmas, %s! You have %s shops left.' % (snowmanNPCWhispers.get(self.zoneId), av.getName(), str(shopsLeft)))
|
||||
elif shopsLeft == 1:
|
||||
av.d_setSystemMessage(0, '%s: Merry Christmas, %s! You have %s shop left.' % (snowmanNPCWhispers.get(self.zoneId), av.getName(), str(shopsLeft)))
|
||||
else:
|
||||
av.d_setSystemMessage(0, '%s: Merry Christmas, %s!' % (snowmanNPCWhispers.get(self.zoneId), av.getName()))
|
||||
|
||||
if avNextProg == snowmanHeadInteriors[-1]:
|
||||
av.b_setCheesyEffect(14, 0, 0)
|
||||
av.d_setSystemMessage(0, 'McQuack: Congratulations on finding all the buildings. Enjoy your snowman head!')
|
||||
else:
|
||||
# start of quest
|
||||
self.air.snowmanProgress[str(avId)] = snowmanHeadInteriors[0]
|
||||
shopsLeft = len(snowmanHeadInteriors) - 1
|
||||
av.d_setSystemMessage(0, '%s: Merry Christmas, %s! You have %s shops left.' % (snowmanNPCWhispers.get(self.zoneId), av.getName(), str(shopsLeft)))
|
||||
self.sendUpdate('setState', [state, globalClockDelta.getRealNetworkTime()])
|
||||
self.fsm.request(state)
|
||||
|
||||
def enterOff(self):
|
||||
pass
|
||||
|
||||
def exitOff(self):
|
||||
pass
|
||||
|
||||
def enterToon(self):
|
||||
pass
|
||||
|
||||
def exitToon(self):
|
||||
pass
|
||||
|
||||
def enterBeingTakenOver(self):
|
||||
pass
|
||||
|
||||
def exitBeingTakenOver(self):
|
||||
pass
|
||||
|
|
Loading…
Reference in a new issue