Added decompiled files

Added decompiled file toontown/battle/DistributedBattleBldgAI.py

Added decompiled file toontown/building/DistributedElevatorExtAI.py

Added decompiled file toontown/building/DistributedElevatorAI.py

Added decompiled file toontown/building/DistributedElevatorIntAI.py

Added decompiled file toontown/building/DistributedSuitInteriorAI.py
This commit is contained in:
Maverick Mosher 2014-04-19 17:35:21 -07:00
parent 53ecd227d5
commit fba650378b
5 changed files with 1220 additions and 97 deletions

View file

@ -1,6 +1,174 @@
from otp.ai.AIBase import *
from direct.distributed.ClockDelta import *
from BattleBase import *
from BattleCalculatorAI import *
from toontown.toonbase.ToontownBattleGlobals import *
from SuitBattleGlobals import *
from direct.showbase.PythonUtil import addListsByValue
import DistributedBattleBaseAI
from direct.task import Task
from direct.directnotify import DirectNotifyGlobal
from toontown.battle.DistributedBattleBaseAI import DistributedBattleBaseAI
import random
from direct.fsm import State
from direct.fsm import ClassicFSM, State
from direct.showbase import PythonUtil
class DistributedBattleBldgAI(DistributedBattleBaseAI):
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedBattleBldgAI")
class DistributedBattleBldgAI(DistributedBattleBaseAI.DistributedBattleBaseAI):
notify = DirectNotifyGlobal.directNotify.newCategory('DistributedBattleBldgAI')
def __init__(self, air, zoneId, roundCallback = None, finishCallback = None, maxSuits = 4, bossBattle = 0):
DistributedBattleBaseAI.DistributedBattleBaseAI.__init__(self, air, zoneId, finishCallback, maxSuits, bossBattle)
self.streetBattle = 0
self.roundCallback = roundCallback
self.fsm.addState(State.State('BuildingReward', self.enterBuildingReward, self.exitBuildingReward, ['Resume']))
playMovieState = self.fsm.getStateNamed('PlayMovie')
playMovieState.addTransition('BuildingReward')
self.elevatorPos = Point3(0, -30, 0)
self.resumeNeedUpdate = 0
def setInitialMembers(self, toonIds, suits):
for suit in suits:
self.addSuit(suit)
for toonId in toonIds:
self.addToon(toonId)
self.fsm.request('FaceOff')
def delete(self):
del self.roundCallback
DistributedBattleBaseAI.DistributedBattleBaseAI.delete(self)
def faceOffDone(self):
toonId = self.air.getAvatarIdFromSender()
if self.ignoreResponses == 1:
self.notify.debug('faceOffDone() - ignoring toon: %d' % toonId)
return
elif self.fsm.getCurrentState().getName() != 'FaceOff':
self.notify.warning('faceOffDone() - in state: %s' % self.fsm.getCurrentState().getName())
return
elif self.toons.count(toonId) == 0:
self.notify.warning('faceOffDone() - toon: %d not in toon list' % toonId)
return
self.responses[toonId] += 1
self.notify.debug('toon: %d done facing off' % toonId)
if not self.ignoreFaceOffDone:
if self.allToonsResponded():
self.handleFaceOffDone()
else:
self.timer.stop()
self.timer.startCallback(TIMEOUT_PER_USER, self.__serverFaceOffDone)
def enterFaceOff(self):
self.notify.debug('enterFaceOff()')
self.joinableFsm.request('Joinable')
self.runableFsm.request('Unrunable')
self.timer.startCallback(self.calcToonMoveTime(self.pos, self.elevatorPos) + FACEOFF_TAUNT_T + SERVER_BUFFER_TIME, self.__serverFaceOffDone)
return None
def __serverFaceOffDone(self):
self.notify.debug('faceoff timed out on server')
self.ignoreFaceOffDone = 1
self.handleFaceOffDone()
def exitFaceOff(self):
self.timer.stop()
self.resetResponses()
return None
def handleFaceOffDone(self):
for suit in self.suits:
self.activeSuits.append(suit)
for toon in self.toons:
self.activeToons.append(toon)
self.sendEarnedExperience(toon)
self.d_setMembers()
self.b_setState('WaitForInput')
def localMovieDone(self, needUpdate, deadToons, deadSuits, lastActiveSuitDied):
self.timer.stop()
self.resumeNeedUpdate = needUpdate
self.resumeDeadToons = deadToons
self.resumeDeadSuits = deadSuits
self.resumeLastActiveSuitDied = lastActiveSuitDied
if len(self.toons) == 0:
self.d_setMembers()
self.b_setState('Resume')
else:
totalHp = 0
for suit in self.suits:
if suit.currHP > 0:
totalHp += suit.currHP
self.roundCallback(self.activeToons, totalHp, deadSuits)
def __goToResumeState(self, task):
self.b_setState('Resume')
def resume(self, currentFloor = 0, topFloor = 0):
if len(self.suits) == 0:
self.d_setMembers()
self.suitsKilledPerFloor.append(self.suitsKilledThisBattle)
if topFloor == 0:
self.b_setState('Reward')
else:
for floorNum, cogsThisFloor in PythonUtil.enumerate(self.suitsKilledPerFloor):
for toonId in self.activeToons:
toon = self.getToon(toonId)
if toon:
recovered, notRecovered = self.air.questManager.recoverItems(toon, cogsThisFloor, self.zoneId)
self.toonItems[toonId][0].extend(recovered)
self.toonItems[toonId][1].extend(notRecovered)
#TODO: promotionMgr
#meritArray = self.air.promotionMgr.recoverMerits(toon, cogsThisFloor, self.zoneId, getCreditMultiplier(floorNum))
#if toonId in self.helpfulToons:
# self.toonMerits[toonId] = addListsByValue(self.toonMerits[toonId], meritArray)
#else:
# self.notify.debug('toon %d not helpful, skipping merits' % toonId)
self.d_setBattleExperience()
self.b_setState('BuildingReward')
else:
if self.resumeNeedUpdate == 1:
self.d_setMembers()
if len(self.resumeDeadSuits) > 0 and self.resumeLastActiveSuitDied == 0 or len(self.resumeDeadToons) > 0:
self.needAdjust = 1
self.setState('WaitForJoin')
self.resumeNeedUpdate = 0
self.resumeDeadToons = []
self.resumeDeadSuits = []
self.resumeLastActiveSuitDied = 0
def enterReservesJoining(self, ts = 0):
return None
def exitReservesJoining(self, ts = 0):
return None
def enterReward(self):
self.timer.startCallback(FLOOR_REWARD_TIMEOUT, self.serverRewardDone)
return None
def exitReward(self):
self.timer.stop()
return None
def enterBuildingReward(self):
self.resetResponses()
self.assignRewards()
self.timer.startCallback(BUILDING_REWARD_TIMEOUT, self.serverRewardDone)
return None
def exitBuildingReward(self):
return None
def enterResume(self):
DistributedBattleBaseAI.DistributedBattleBaseAI.enterResume(self)
self.finishCallback(self.zoneId, self.activeToons)
def exitResume(self):
DistributedBattleBaseAI.DistributedBattleBaseAI.exitResume(self)
taskName = self.taskName('finish')
taskMgr.remove(taskName)

View file

@ -1,78 +1,302 @@
from otp.ai.AIBase import *
from toontown.toonbase import ToontownGlobals
from direct.distributed.ClockDelta import *
from ElevatorConstants import *
from direct.distributed import DistributedObjectAI
from direct.fsm import ClassicFSM, State
from direct.fsm import State
from direct.task import Task
from direct.directnotify import DirectNotifyGlobal
from direct.distributed.DistributedObjectAI import DistributedObjectAI
class DistributedElevatorAI(DistributedObjectAI):
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedElevatorAI")
class DistributedElevatorAI(DistributedObjectAI.DistributedObjectAI):
notify = DirectNotifyGlobal.directNotify.newCategory('DistributedElevatorAI')
def setBldgDoId(self, todo0):
def __init__(self, air, bldg, numSeats = 4, antiShuffle = 0, minLaff = 0):
DistributedObjectAI.DistributedObjectAI.__init__(self, air)
self.type = ELEVATOR_NORMAL
self.countdownTime = ElevatorData[self.type]['countdown']
self.bldg = bldg
self.bldgDoId = bldg.getDoId()
self.seats = []
self.setAntiShuffle(antiShuffle)
self.setMinLaff(minLaff)
if self.antiShuffle:
if not hasattr(simbase.air, 'elevatorTripId'):
simbase.air.elevatorTripId = 1
self.elevatorTripId = simbase.air.elevatorTripId
simbase.air.elevatorTripId += 1
else:
self.elevatorTripId = 0
for seat in range(numSeats):
self.seats.append(None)
self.accepting = 0
self.fsm = ClassicFSM.ClassicFSM('DistributedElevatorAI', [State.State('off', self.enterOff, self.exitOff, ['opening', 'closed']),
State.State('opening', self.enterOpening, self.exitOpening, ['waitEmpty', 'waitCountdown']),
State.State('waitEmpty', self.enterWaitEmpty, self.exitWaitEmpty, ['waitCountdown']),
State.State('waitCountdown', self.enterWaitCountdown, self.exitWaitCountdown, ['waitEmpty', 'allAboard']),
State.State('allAboard', self.enterAllAboard, self.exitAllAboard, ['closing', 'waitEmpty']),
State.State('closing', self.enterClosing, self.exitClosing, ['closed', 'waitEmpty']),
State.State('closed', self.enterClosed, self.exitClosed, ['opening'])], 'off', 'off')
self.fsm.enterInitialState()
self.boardingParty = None
return
def delete(self):
self.fsm.requestFinalState()
del self.fsm
del self.bldg
self.ignoreAll()
DistributedObjectAI.DistributedObjectAI.delete(self)
def setBoardingParty(self, party):
self.boardingParty = party
def generate(self):
self.start()
DistributedObjectAI.DistributedObjectAI.generate(self)
def getBldgDoId(self):
return self.bldgDoId
def findAvailableSeat(self):
for i in range(len(self.seats)):
if self.seats[i] == None:
return i
return
def findAvatar(self, avId):
for i in range(len(self.seats)):
if self.seats[i] == avId:
return i
return None
def countFullSeats(self):
avCounter = 0
for i in self.seats:
if i:
avCounter += 1
return avCounter
def countOpenSeats(self):
openSeats = 0
for i in range(len(self.seats)):
if self.seats[i] == None:
openSeats += 1
return openSeats
def rejectingBoardersHandler(self, avId, reason = 0, wantBoardingShow = 0):
self.rejectBoarder(avId, reason)
def rejectBoarder(self, avId, reason = 0):
self.sendUpdateToAvatarId(avId, 'rejectBoard', [avId, reason])
def acceptingBoardersHandler(self, avId, reason = 0, wantBoardingShow = 0):
self.notify.debug('acceptingBoardersHandler')
seatIndex = self.findAvailableSeat()
if seatIndex == None:
self.rejectBoarder(avId, REJECT_NOSEAT)
else:
self.acceptBoarder(avId, seatIndex, wantBoardingShow)
return
def acceptBoarder(self, avId, seatIndex, wantBoardingShow = 0):
self.notify.debug('acceptBoarder')
if self.findAvatar(avId) != None:
return
self.seats[seatIndex] = avId
self.timeOfBoarding = globalClock.getRealTime()
if wantBoardingShow:
self.timeOfGroupBoarding = globalClock.getRealTime()
self.sendUpdate('fillSlot' + str(seatIndex), [avId, wantBoardingShow])
return
def rejectingExitersHandler(self, avId):
self.rejectExiter(avId)
def rejectExiter(self, avId):
pass
def setState(self, todo0, todo1):
def acceptingExitersHandler(self, avId):
self.acceptExiter(avId)
def clearEmptyNow(self, seatIndex):
self.sendUpdate('emptySlot' + str(seatIndex), [0,
0,
globalClockDelta.getRealNetworkTime(),
0])
def clearFullNow(self, seatIndex):
avId = self.seats[seatIndex]
if avId == None:
self.notify.warning('Clearing an empty seat index: ' + str(seatIndex) + ' ... Strange...')
else:
self.seats[seatIndex] = None
self.sendUpdate('fillSlot' + str(seatIndex), [0, 0])
self.ignore(self.air.getAvatarExitEvent(avId))
return
def d_setState(self, state):
self.sendUpdate('setState', [state, globalClockDelta.getRealNetworkTime()])
def getState(self):
return self.fsm.getCurrentState().getName()
def avIsOKToBoard(self, av):
return av.hp > self.minLaff and self.accepting
def checkBoard(self, av):
if av.hp < self.minLaff:
return REJECT_MINLAFF
return 0
def requestBoard(self, *args):
self.notify.debug('requestBoard')
avId = self.air.getAvatarIdFromSender()
if self.findAvatar(avId) != None:
self.notify.warning('Ignoring multiple requests from %s to board.' % avId)
return
av = self.air.doId2do.get(avId)
if av:
boardResponse = self.checkBoard(av)
newArgs = (avId,) + args + (boardResponse,)
if self.boardingParty and self.boardingParty.hasActiveGroup(avId) and self.boardingParty.getGroupLeader(avId) != avId:
self.notify.warning('Rejecting %s from boarding the elevator because he is already part of a Boarding Group.' % avId)
self.rejectingBoardersHandler(*newArgs)
return
if boardResponse == 0:
self.acceptingBoardersHandler(*newArgs)
else:
self.rejectingBoardersHandler(*newArgs)
else:
self.notify.warning('avid: %s does not exist, but tried to board an elevator' % avId)
return
def partyAvatarBoard(self, avatar, wantBoardingShow = 0):
av = avatar
avId = avatar.doId
if self.findAvatar(avId) != None:
self.notify.warning('Ignoring multiple requests from %s to board.' % avId)
return
if av:
boardResponse = self.checkBoard(av)
newArgs = (avId,) + (boardResponse,) + (wantBoardingShow,)
if boardResponse == 0:
self.acceptingBoardersHandler(*newArgs)
else:
self.rejectingBoardersHandler(*newArgs)
else:
self.notify.warning('avid: %s does not exist, but tried to board an elevator' % avId)
return
def requestExit(self, *args):
self.notify.debug('requestExit')
avId = self.air.getAvatarIdFromSender()
av = self.air.doId2do.get(avId)
if av:
newArgs = (avId,) + args
if self.accepting:
self.acceptingExitersHandler(*newArgs)
else:
self.rejectingExitersHandler(*newArgs)
else:
self.notify.warning('avId: %s does not exist, but tried to exit an elevator' % avId)
def start(self):
self.open()
def enterOff(self):
self.accepting = 0
self.timeOfBoarding = None
self.timeOfGroupBoarding = None
if hasattr(self, 'doId'):
for seatIndex in range(len(self.seats)):
taskMgr.remove(self.uniqueName('clearEmpty-' + str(seatIndex)))
return
def exitOff(self):
self.accepting = 0
def open(self):
self.fsm.request('opening')
def enterOpening(self):
self.d_setState('opening')
self.accepting = 0
for seat in self.seats:
seat = None
return
def exitOpening(self):
self.accepting = 0
taskMgr.remove(self.uniqueName('opening-timer'))
def enterWaitCountdown(self):
self.d_setState('waitCountdown')
self.accepting = 1
def exitWaitCountdown(self):
print 'exit wait countdown'
self.accepting = 0
taskMgr.remove(self.uniqueName('countdown-timer'))
self.newTrip()
def enterAllAboard(self):
self.accepting = 0
def exitAllAboard(self):
self.accepting = 0
taskMgr.remove(self.uniqueName('waitForAllAboard'))
def enterClosing(self):
self.d_setState('closing')
self.accepting = 0
def exitClosing(self):
self.accepting = 0
taskMgr.remove(self.uniqueName('closing-timer'))
def enterClosed(self):
self.d_setState('closed')
def exitClosed(self):
pass
def fillSlot0(self, todo0, todo1):
pass
def enterWaitEmpty(self):
self.d_setState('waitEmpty')
self.accepting = 1
def fillSlot1(self, todo0, todo1):
pass
def exitWaitEmpty(self):
self.accepting = 0
def fillSlot2(self, todo0, todo1):
pass
def setElevatorTripId(self, id):
self.elevatorTripId = id
def fillSlot3(self, todo0, todo1):
pass
def getElevatorTripId(self):
return self.elevatorTripId
def fillSlot4(self, todo0, todo1):
pass
def newTrip(self):
if self.antiShuffle:
self.elevatorTripId = simbase.air.elevatorTripId
if simbase.air.elevatorTripId > 2100000000:
simbase.air.elevatorTripId = 1
simbase.air.elevatorTripId += 1
self.sendUpdate('setElevatorTripId', [self.elevatorTripId])
def fillSlot5(self, todo0, todo1):
pass
def setAntiShuffle(self, antiShuffle):
self.antiShuffle = antiShuffle
def fillSlot6(self, todo0, todo1):
pass
def getAntiShuffle(self):
return self.antiShuffle
def fillSlot7(self, todo0, todo1):
pass
def emptySlot0(self, todo0, todo1, todo2, todo3):
pass
def emptySlot1(self, todo0, todo1, todo2, todo3):
pass
def emptySlot2(self, todo0, todo1, todo2, todo3):
pass
def emptySlot3(self, todo0, todo1, todo2, todo3):
pass
def emptySlot4(self, todo0, todo1, todo2, todo3):
pass
def emptySlot5(self, todo0, todo1, todo2, todo3):
pass
def emptySlot6(self, todo0, todo1, todo2, todo3):
pass
def emptySlot7(self, todo0, todo1, todo2, todo3):
pass
def requestBoard(self):
pass
def rejectBoard(self, todo0, todo1):
pass
def requestExit(self):
pass
def setElevatorTripId(self, todo0):
pass
def setAntiShuffle(self, todo0):
pass
def setMinLaff(self, todo0):
pass
def setMinLaff(self, minLaff):
self.minLaff = minLaff
def getMinLaff(self):
return self.minLaff

View file

@ -1,9 +1,194 @@
from otp.ai.AIBase import *
from toontown.toonbase import ToontownGlobals
from direct.distributed.ClockDelta import *
from ElevatorConstants import *
import DistributedElevatorAI
from direct.fsm import ClassicFSM
from direct.fsm import State
from direct.task import Task
from direct.directnotify import DirectNotifyGlobal
from toontown.building.DistributedElevatorAI import DistributedElevatorAI
class DistributedElevatorExtAI(DistributedElevatorAI):
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedElevatorExtAI")
class DistributedElevatorExtAI(DistributedElevatorAI.DistributedElevatorAI):
notify = DirectNotifyGlobal.directNotify.newCategory('DistributedElevatorExtAI')
def setFloor(self, todo0):
pass
def __init__(self, air, bldg, numSeats = 4, antiShuffle = 0, minLaff = 0):
DistributedElevatorAI.DistributedElevatorAI.__init__(self, air, bldg, numSeats, antiShuffle=antiShuffle, minLaff=minLaff)
self.anyToonsBailed = 0
self.boardingParty = None
return
def delete(self):
for seatIndex in range(len(self.seats)):
avId = self.seats[seatIndex]
if avId:
self.clearFullNow(seatIndex)
self.clearEmptyNow(seatIndex)
DistributedElevatorAI.DistributedElevatorAI.delete(self)
def d_setFloor(self, floorNumber):
self.sendUpdate('setFloor', [floorNumber])
def acceptBoarder(self, avId, seatIndex, wantBoardingShow = 0):
DistributedElevatorAI.DistributedElevatorAI.acceptBoarder(self, avId, seatIndex, wantBoardingShow)
self.acceptOnce(self.air.getAvatarExitEvent(avId), self.__handleUnexpectedExit, extraArgs=[avId])
self.fsm.request('waitCountdown')
def __handleUnexpectedExit(self, avId):
self.notify.warning('Avatar: ' + str(avId) + ' has exited unexpectedly')
seatIndex = self.findAvatar(avId)
if seatIndex == None:
pass
else:
self.clearFullNow(seatIndex)
self.clearEmptyNow(seatIndex)
if self.countFullSeats() == 0:
self.fsm.request('waitEmpty')
return
def acceptExiter(self, avId):
seatIndex = self.findAvatar(avId)
if seatIndex == None:
pass
else:
self.clearFullNow(seatIndex)
bailFlag = 0
timeToSend = self.countdownTime
if self.antiShuffle:
myTask = taskMgr.getTasksNamed(self.uniqueName('countdown-timer'))[0]
timeLeft = myTask.wakeTime - globalClock.getFrameTime()
timeLeft = max(0, timeLeft)
timeToSet = timeLeft + 10.0
timeToSet = min(timeLeft + 10.0, self.countdownTime)
self.setCountdown(timeToSet)
timeToSend = timeToSet
self.sendUpdate('emptySlot' + str(seatIndex), [avId,
1,
globalClockDelta.getRealNetworkTime(),
timeToSend])
elif self.anyToonsBailed == 0:
bailFlag = 1
self.resetCountdown()
self.anyToonsBailed = 1
self.sendUpdate('emptySlot' + str(seatIndex), [avId,
bailFlag,
globalClockDelta.getRealNetworkTime(),
timeToSend])
else:
self.sendUpdate('emptySlot' + str(seatIndex), [avId,
bailFlag,
globalClockDelta.getRealNetworkTime(),
timeToSend])
if self.countFullSeats() == 0:
self.fsm.request('waitEmpty')
taskMgr.doMethodLater(TOON_EXIT_ELEVATOR_TIME, self.clearEmptyNow, self.uniqueName('clearEmpty-%s' % seatIndex), extraArgs=(seatIndex,))
return
def enterOpening(self):
DistributedElevatorAI.DistributedElevatorAI.enterOpening(self)
taskMgr.doMethodLater(ElevatorData[ELEVATOR_NORMAL]['openTime'], self.waitEmptyTask, self.uniqueName('opening-timer'))
def waitEmptyTask(self, task):
self.fsm.request('waitEmpty')
return Task.done
def enterWaitEmpty(self):
DistributedElevatorAI.DistributedElevatorAI.enterWaitEmpty(self)
self.anyToonsBailed = 0
def enterWaitCountdown(self):
DistributedElevatorAI.DistributedElevatorAI.enterWaitCountdown(self)
taskMgr.doMethodLater(self.countdownTime, self.timeToGoTask, self.uniqueName('countdown-timer'))
def timeToGoTask(self, task):
if self.countFullSeats() > 0:
self.fsm.request('allAboard')
else:
self.fsm.request('waitEmpty')
return Task.done
def resetCountdown(self):
taskMgr.remove(self.uniqueName('countdown-timer'))
taskMgr.doMethodLater(self.countdownTime, self.timeToGoTask, self.uniqueName('countdown-timer'))
def setCountdown(self, timeToSet):
taskMgr.remove(self.uniqueName('countdown-timer'))
taskMgr.doMethodLater(timeToSet, self.timeToGoTask, self.uniqueName('countdown-timer'))
def enterAllAboard(self):
DistributedElevatorAI.DistributedElevatorAI.enterAllAboard(self)
currentTime = globalClock.getRealTime()
elapsedTime = currentTime - self.timeOfBoarding
self.notify.debug('elapsed time: ' + str(elapsedTime))
waitTime = max(TOON_BOARD_ELEVATOR_TIME - elapsedTime, 0)
waitTime += self.getBoardingShowTimeLeft()
taskMgr.doMethodLater(waitTime, self.closeTask, self.uniqueName('waitForAllAboard'))
def getBoardingShowTimeLeft(self):
currentTime = globalClock.getRealTime()
timeLeft = 0.0
if hasattr(self, 'timeOfGroupBoarding') and self.timeOfGroupBoarding:
elapsedTime = currentTime - self.timeOfGroupBoarding
timeLeft = max(MAX_GROUP_BOARDING_TIME - elapsedTime, 0)
if timeLeft > MAX_GROUP_BOARDING_TIME:
timeLeft = 0.0
return timeLeft
def closeTask(self, task):
if self.countFullSeats() > 0:
self.fsm.request('closing')
else:
self.fsm.request('waitEmpty')
return Task.done
def enterClosing(self):
DistributedElevatorAI.DistributedElevatorAI.enterClosing(self)
taskMgr.doMethodLater(ElevatorData[ELEVATOR_NORMAL]['closeTime'], self.elevatorClosedTask, self.uniqueName('closing-timer'))
def elevatorClosedTask(self, task):
self.elevatorClosed()
return Task.done
def _createInterior(self):
self.bldg.createSuitInterior()
def elevatorClosed(self):
numPlayers = self.countFullSeats()
if numPlayers > 0:
self._createInterior()
for seatIndex in range(len(self.seats)):
avId = self.seats[seatIndex]
if avId:
self.clearFullNow(seatIndex)
else:
self.notify.warning('The elevator left, but was empty.')
self.fsm.request('closed')
def requestExit(self, *args):
self.notify.debug('requestExit')
avId = self.air.getAvatarIdFromSender()
av = self.air.doId2do.get(avId)
if self.boardingParty and self.boardingParty.getGroupLeader(avId) and avId:
if avId == self.boardingParty.getGroupLeader(avId):
memberIds = self.boardingParty.getGroupMemberList(avId)
for memberId in memberIds:
member = simbase.air.doId2do.get(memberId)
if member:
if self.accepting:
self.acceptingExitersHandler(memberId)
else:
self.rejectingExitersHandler(memberId)
else:
self.rejectingExitersHandler(avId)
else:
if av:
newArgs = (avId,) + args
if self.accepting:
self.acceptingExitersHandler(*newArgs)
else:
self.rejectingExitersHandler(*newArgs)
else:
self.notify.warning('avId: %s does not exist, but tried to exit an elevator' % avId)
return

View file

@ -1,12 +1,145 @@
from otp.ai.AIBase import *
from toontown.toonbase import ToontownGlobals
from direct.distributed.ClockDelta import *
from ElevatorConstants import *
import copy
import DistributedElevatorAI
from direct.fsm import ClassicFSM
from direct.fsm import State
from direct.task import Task
from direct.directnotify import DirectNotifyGlobal
from toontown.building.DistributedElevatorAI import DistributedElevatorAI
from toontown.battle import BattleBase
class DistributedElevatorIntAI(DistributedElevatorAI):
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedElevatorIntAI")
class DistributedElevatorIntAI(DistributedElevatorAI.DistributedElevatorAI):
def __init__(self, air, bldg, avIds):
DistributedElevatorAI.DistributedElevatorAI.__init__(self, air, bldg)
self.countdownTime = simbase.config.GetFloat('int-elevator-timeout', INTERIOR_ELEVATOR_COUNTDOWN_TIME)
self.avIds = copy.copy(avIds)
for avId in avIds:
self.acceptOnce(self.air.getAvatarExitEvent(avId), self.__handleAllAvsUnexpectedExit, extraArgs=[avId])
def checkBoard(self, av):
result = 0
if av.doId not in self.avIds:
result = REJECT_NOSEAT
else:
result = DistributedElevatorAI.DistributedElevatorAI.checkBoard(self, av)
return result
def acceptBoarder(self, avId, seatIndex, wantBoardingShow = 0):
DistributedElevatorAI.DistributedElevatorAI.acceptBoarder(self, avId, seatIndex, wantBoardingShow)
self.__closeIfNecessary()
def __closeIfNecessary(self):
numFullSeats = self.countFullSeats()
if not numFullSeats <= len(self.avIds):
self.notify.warning('we are about to crash. self.seats=%s self.avIds=%s' % (self.seats, self.avIds))
if numFullSeats == len(self.avIds):
self.fsm.request('allAboard')
def __handleAllAvsUnexpectedExit(self, avId):
self.notify.warning('Avatar: ' + str(avId) + ' has exited unexpectedly')
seatIndex = self.findAvatar(avId)
avIdCount = self.avIds.count(avId)
if avIdCount == 1:
self.avIds.remove(avId)
elif avIdCount == 0:
self.notify.warning("Strange... %d exited unexpectedly, but I don't have them on my list." % avId)
else:
self.notify.error('This list is screwed up! %s' % self.avIds)
if seatIndex == None:
self.notify.debug('%d is not boarded, but exited' % avId)
else:
self.clearFullNow(seatIndex)
self.clearEmptyNow(seatIndex)
self.__closeIfNecessary()
return
def acceptExiter(self, avId):
seatIndex = self.findAvatar(avId)
if seatIndex == None:
pass
else:
self.clearFullNow(seatIndex)
self.sendUpdate('emptySlot' + str(seatIndex), [avId,
0,
globalClockDelta.getRealNetworkTime(),
self.countdownTime])
taskMgr.doMethodLater(TOON_EXIT_ELEVATOR_TIME, self.clearEmptyNow, self.uniqueName('clearEmpty-%s' % seatIndex), extraArgs=(seatIndex,))
return
def d_forcedExit(self, avId):
self.sendUpdateToAvatarId(avId, 'forcedExit', [avId])
def requestBuildingExit(self):
pass
avId = self.air.getAvatarIdFromSender()
self.notify.debug('requestBuildingExit from %d' % avId)
if self.accepting:
if avId in self.avIds:
self.avIds.remove(avId)
self.__closeIfNecessary()
else:
self.notify.warning('avId: %s not known, but tried to exit the building' % avId)
def forcedExit(self, todo0):
pass
def enterOpening(self):
DistributedElevatorAI.DistributedElevatorAI.enterOpening(self)
taskMgr.doMethodLater(ElevatorData[ELEVATOR_NORMAL]['openTime'], self.waitCountdownTask, self.uniqueName('opening-timer'))
def waitCountdownTask(self, task):
self.fsm.request('waitCountdown')
return Task.done
def enterWaitCountdown(self):
DistributedElevatorAI.DistributedElevatorAI.enterWaitCountdown(self)
taskMgr.doMethodLater(self.countdownTime + BattleBase.SERVER_BUFFER_TIME, self.timeToGoTask, self.uniqueName('countdown-timer'))
def timeToGoTask(self, task):
self.allAboard()
return Task.done
def allAboard(self):
if len(self.avIds) == 0:
self.bldg.handleAllAboard([None,
None,
None,
None])
else:
self.fsm.request('allAboard')
return
def enterAllAboard(self):
for avId in self.avIds:
if self.findAvatar(avId) == None:
self.d_forcedExit(avId)
DistributedElevatorAI.DistributedElevatorAI.enterAllAboard(self)
if self.timeOfBoarding != None:
currentTime = globalClock.getRealTime()
elapsedTime = currentTime - self.timeOfBoarding
self.notify.debug('elapsed time: ' + str(elapsedTime))
waitTime = max(TOON_BOARD_ELEVATOR_TIME - elapsedTime, 0)
taskMgr.doMethodLater(waitTime, self.closeTask, self.uniqueName('waitForAllAboard'))
else:
self.fsm.request('closing')
return
def closeTask(self, task):
self.fsm.request('closing')
return Task.done
def enterClosing(self):
DistributedElevatorAI.DistributedElevatorAI.enterClosing(self)
taskMgr.doMethodLater(ElevatorData[ELEVATOR_NORMAL]['closeTime'] + BattleBase.SERVER_BUFFER_TIME, self.elevatorClosedTask, self.uniqueName('closing-timer'))
def elevatorClosedTask(self, task):
self.fsm.request('closed')
return Task.done
def __doorsClosed(self):
self.bldg.handleAllAboard(self.seats)
self.fsm.request('closed')
def enterClosed(self):
DistributedElevatorAI.DistributedElevatorAI.enterClosed(self)
self.__doorsClosed()

View file

@ -1,36 +1,449 @@
from toontown.toonbase.ToontownBattleGlobals import *
from otp.ai.AIBaseGlobal import *
from direct.distributed.ClockDelta import *
from ElevatorConstants import *
from direct.directnotify import DirectNotifyGlobal
from direct.distributed.DistributedObjectAI import DistributedObjectAI
from direct.fsm import ClassicFSM, State
from direct.distributed import DistributedObjectAI
from direct.fsm import State
from toontown.battle import DistributedBattleBldgAI
from toontown.battle import BattleBase
from direct.task import Timer
import DistributedElevatorIntAI
import copy
class DistributedSuitInteriorAI(DistributedObjectAI):
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedSuitInteriorAI")
class DistributedSuitInteriorAI(DistributedObjectAI.DistributedObjectAI):
def setZoneId(self, todo0):
pass
def __init__(self, air, elevator):
self.air = air
DistributedObjectAI.DistributedObjectAI.__init__(self, air)
self.extZoneId, self.zoneId = elevator.bldg.getExteriorAndInteriorZoneId()
self.numFloors = elevator.bldg.planner.numFloors
self.avatarExitEvents = []
self.toons = []
self.toonSkillPtsGained = {}
self.toonExp = {}
self.toonOrigQuests = {}
self.toonItems = {}
self.toonOrigMerits = {}
self.toonMerits = {}
self.toonParts = {}
self.helpfulToons = []
self.currentFloor = 0
self.topFloor = self.numFloors - 1
self.bldg = elevator.bldg
self.elevator = elevator
self.suits = []
self.activeSuits = []
self.reserveSuits = []
self.joinedReserves = []
self.suitsKilled = []
self.suitsKilledPerFloor = []
self.battle = None
self.timer = Timer.Timer()
self.responses = {}
self.ignoreResponses = 0
self.ignoreElevatorDone = 0
self.ignoreReserveJoinDone = 0
self.toonIds = copy.copy(elevator.seats)
for toonId in self.toonIds:
if toonId != None:
self.__addToon(toonId)
def setExtZoneId(self, todo0):
pass
self.savedByMap = {}
self.fsm = ClassicFSM.ClassicFSM('DistributedSuitInteriorAI', [State.State('WaitForAllToonsInside', self.enterWaitForAllToonsInside, self.exitWaitForAllToonsInside, ['Elevator']),
State.State('Elevator', self.enterElevator, self.exitElevator, ['Battle']),
State.State('Battle', self.enterBattle, self.exitBattle, ['ReservesJoining', 'BattleDone']),
State.State('ReservesJoining', self.enterReservesJoining, self.exitReservesJoining, ['Battle']),
State.State('BattleDone', self.enterBattleDone, self.exitBattleDone, ['Resting', 'Reward']),
State.State('Resting', self.enterResting, self.exitResting, ['Elevator']),
State.State('Reward', self.enterReward, self.exitReward, ['Off']),
State.State('Off', self.enterOff, self.exitOff, ['WaitForAllToonsInside'])], 'Off', 'Off', onUndefTransition=ClassicFSM.ClassicFSM.ALLOW)
self.fsm.enterInitialState()
return
def setDistBldgDoId(self, todo0):
pass
def delete(self):
self.ignoreAll()
self.toons = []
self.toonIds = []
self.fsm.requestFinalState()
del self.fsm
del self.bldg
del self.elevator
self.timer.stop()
del self.timer
self.__cleanupFloorBattle()
taskName = self.taskName('deleteInterior')
taskMgr.remove(taskName)
DistributedObjectAI.DistributedObjectAI.delete(self)
def setNumFloors(self, todo0):
pass
def __handleUnexpectedExit(self, toonId):
self.notify.warning('toon: %d exited unexpectedly' % toonId)
self.__removeToon(toonId)
if len(self.toons) == 0:
self.timer.stop()
if self.fsm.getCurrentState().getName() == 'Resting':
pass
elif self.battle == None:
self.bldg.deleteSuitInterior()
return
def setToons(self, todo0, todo1):
pass
def __addToon(self, toonId):
if not self.air.doId2do.has_key(toonId):
self.notify.warning('addToon() - no toon for doId: %d' % toonId)
return
event = self.air.getAvatarExitEvent(toonId)
self.avatarExitEvents.append(event)
self.accept(event, self.__handleUnexpectedExit, extraArgs=[toonId])
self.toons.append(toonId)
self.responses[toonId] = 0
def setSuits(self, todo0, todo1, todo2):
pass
def __removeToon(self, toonId):
if self.toons.count(toonId):
self.toons.remove(toonId)
if self.toonIds.count(toonId):
self.toonIds[self.toonIds.index(toonId)] = None
if self.responses.has_key(toonId):
del self.responses[toonId]
event = self.air.getAvatarExitEvent(toonId)
if self.avatarExitEvents.count(event):
self.avatarExitEvents.remove(event)
self.ignore(event)
return
def setState(self, todo0, todo1):
pass
def __resetResponses(self):
self.responses = {}
for toon in self.toons:
self.responses[toon] = 0
self.ignoreResponses = 0
def __allToonsResponded(self):
for toon in self.toons:
if self.responses[toon] == 0:
return 0
self.ignoreResponses = 1
return 1
def getZoneId(self):
return self.zoneId
def getExtZoneId(self):
return self.extZoneId
def getDistBldgDoId(self):
return self.bldg.getDoId()
def getNumFloors(self):
return self.numFloors
def d_setToons(self):
self.sendUpdate('setToons', self.getToons())
def getToons(self):
sendIds = []
for toonId in self.toonIds:
if toonId == None:
sendIds.append(0)
else:
sendIds.append(toonId)
return [sendIds, 0]
def d_setSuits(self):
self.sendUpdate('setSuits', self.getSuits())
def getSuits(self):
suitIds = []
for suit in self.activeSuits:
suitIds.append(suit.doId)
reserveIds = []
values = []
for info in self.reserveSuits:
reserveIds.append(info[0].doId)
values.append(info[1])
return [suitIds, reserveIds, values]
def b_setState(self, state):
self.d_setState(state)
self.setState(state)
def d_setState(self, state):
stime = globalClock.getRealTime() + BattleBase.SERVER_BUFFER_TIME
self.sendUpdate('setState', [state, globalClockDelta.localToNetworkTime(stime)])
def setState(self, state):
self.fsm.request(state)
def getState(self):
return [self.fsm.getCurrentState().getName(), globalClockDelta.getRealNetworkTime()]
def setAvatarJoined(self):
pass
avId = self.air.getAvatarIdFromSender()
if self.toons.count(avId) == 0:
self.air.writeServerEvent('suspicious', avId, 'DistributedSuitInteriorAI.setAvatarJoined from toon not in %s.' % self.toons)
self.notify.warning('setAvatarJoined() - av: %d not in list' % avId)
return
avatar = self.air.doId2do.get(avId)
if avatar != None:
self.savedByMap[avId] = (avatar.getName(), avatar.dna.asTuple())
self.responses[avId] += 1
if self.__allToonsResponded():
self.fsm.request('Elevator')
return
def elevatorDone(self):
pass
toonId = self.air.getAvatarIdFromSender()
if self.ignoreResponses == 1:
return
elif self.fsm.getCurrentState().getName() != 'Elevator':
self.notify.warning('elevatorDone() - in state: %s' % self.fsm.getCurrentState().getName())
return
elif self.toons.count(toonId) == 0:
self.notify.warning('elevatorDone() - toon not in toon list: %d' % toonId)
return
self.responses[toonId] += 1
if self.__allToonsResponded() and self.ignoreElevatorDone == 0:
self.b_setState('Battle')
def reserveJoinDone(self):
pass
toonId = self.air.getAvatarIdFromSender()
if self.ignoreResponses == 1:
return
elif self.fsm.getCurrentState().getName() != 'ReservesJoining':
self.notify.warning('reserveJoinDone() - in state: %s' % self.fsm.getCurrentState().getName())
return
elif self.toons.count(toonId) == 0:
self.notify.warning('reserveJoinDone() - toon not in list: %d' % toonId)
return
self.responses[toonId] += 1
if self.__allToonsResponded() and self.ignoreReserveJoinDone == 0:
self.b_setState('Battle')
def enterOff(self):
return None
def exitOff(self):
return None
def enterWaitForAllToonsInside(self):
self.__resetResponses()
return None
def exitWaitForAllToonsInside(self):
self.__resetResponses()
return None
def enterElevator(self):
suitHandles = self.bldg.planner.genFloorSuits(self.currentFloor)
self.suits = suitHandles['activeSuits']
self.activeSuits = []
for suit in self.suits:
self.activeSuits.append(suit)
self.reserveSuits = suitHandles['reserveSuits']
self.d_setToons()
self.d_setSuits()
self.__resetResponses()
self.d_setState('Elevator')
self.timer.startCallback(BattleBase.ELEVATOR_T + ElevatorData[ELEVATOR_NORMAL]['openTime'] + BattleBase.SERVER_BUFFER_TIME, self.__serverElevatorDone)
return None
def __serverElevatorDone(self):
self.ignoreElevatorDone = 1
self.b_setState('Battle')
def exitElevator(self):
self.timer.stop()
self.__resetResponses()
return None
def __createFloorBattle(self):
if self.currentFloor == self.topFloor:
bossBattle = 1
else:
bossBattle = 0
self.battle = DistributedBattleBldgAI.DistributedBattleBldgAI(self.air, self.zoneId, self.__handleRoundDone, self.__handleBattleDone, bossBattle=bossBattle)
self.battle.suitsKilled = self.suitsKilled
self.battle.suitsKilledPerFloor = self.suitsKilledPerFloor
self.battle.battleCalc.toonSkillPtsGained = self.toonSkillPtsGained
self.battle.toonExp = self.toonExp
self.battle.toonOrigQuests = self.toonOrigQuests
self.battle.toonItems = self.toonItems
self.battle.toonOrigMerits = self.toonOrigMerits
self.battle.toonMerits = self.toonMerits
self.battle.toonParts = self.toonParts
self.battle.helpfulToons = self.helpfulToons
self.battle.setInitialMembers(self.toons, self.suits)
self.battle.generateWithRequired(self.zoneId)
mult = getCreditMultiplier(self.currentFloor)
#todo: suitInvasionManager
#if self.air.suitInvasionManager.getInvading():
# mult *= getInvasionMultiplier()
self.battle.battleCalc.setSkillCreditMultiplier(mult)
def __cleanupFloorBattle(self):
for suit in self.suits:
self.notify.debug('cleaning up floor suit: %d' % suit.doId)
if suit.isDeleted():
self.notify.debug('whoops, suit %d is deleted.' % suit.doId)
else:
suit.requestDelete()
self.suits = []
self.reserveSuits = []
self.activeSuits = []
if self.battle != None:
self.battle.requestDelete()
self.battle = None
return
def __handleRoundDone(self, toonIds, totalHp, deadSuits):
totalMaxHp = 0
for suit in self.suits:
totalMaxHp += suit.maxHP
for suit in deadSuits:
self.activeSuits.remove(suit)
if len(self.reserveSuits) > 0 and len(self.activeSuits) < 4:
self.joinedReserves = []
hpPercent = 100 - totalHp / totalMaxHp * 100.0
for info in self.reserveSuits:
if info[1] <= hpPercent and len(self.activeSuits) < 4:
self.suits.append(info[0])
self.activeSuits.append(info[0])
self.joinedReserves.append(info)
for info in self.joinedReserves:
self.reserveSuits.remove(info)
if len(self.joinedReserves) > 0:
self.fsm.request('ReservesJoining')
self.d_setSuits()
return
if len(self.activeSuits) == 0:
self.fsm.request('BattleDone', [toonIds])
else:
self.battle.resume()
def __handleBattleDone(self, zoneId, toonIds):
if len(toonIds) == 0:
taskName = self.taskName('deleteInterior')
taskMgr.doMethodLater(10, self.__doDeleteInterior, taskName)
elif self.currentFloor == self.topFloor:
self.setState('Reward')
else:
self.b_setState('Resting')
def __doDeleteInterior(self, task):
self.bldg.deleteSuitInterior()
def enterBattle(self):
if self.battle == None:
self.__createFloorBattle()
self.elevator.d_setFloor(self.currentFloor)
return
def exitBattle(self):
return None
def enterReservesJoining(self):
self.__resetResponses()
self.timer.startCallback(ElevatorData[ELEVATOR_NORMAL]['openTime'] + SUIT_HOLD_ELEVATOR_TIME + BattleBase.SERVER_BUFFER_TIME, self.__serverReserveJoinDone)
return None
def __serverReserveJoinDone(self):
self.ignoreReserveJoinDone = 1
self.b_setState('Battle')
def exitReservesJoining(self):
self.timer.stop()
self.__resetResponses()
for info in self.joinedReserves:
self.battle.suitRequestJoin(info[0])
self.battle.resume()
self.joinedReserves = []
return None
def enterBattleDone(self, toonIds):
if len(toonIds) != len(self.toons):
deadToons = []
for toon in self.toons:
if toonIds.count(toon) == 0:
deadToons.append(toon)
for toon in deadToons:
self.__removeToon(toon)
self.d_setToons()
if len(self.toons) == 0:
self.bldg.deleteSuitInterior()
elif self.currentFloor == self.topFloor:
self.battle.resume(self.currentFloor, topFloor=1)
else:
self.battle.resume(self.currentFloor, topFloor=0)
return None
def exitBattleDone(self):
self.__cleanupFloorBattle()
return None
def __handleEnterElevator(self):
self.fsm.request('Elevator')
def enterResting(self):
self.intElevator = DistributedElevatorIntAI.DistributedElevatorIntAI(self.air, self, self.toons)
self.intElevator.generateWithRequired(self.zoneId)
return None
def handleAllAboard(self, seats):
if not hasattr(self, 'fsm'):
return
numOfEmptySeats = seats.count(None)
if numOfEmptySeats == 4:
self.bldg.deleteSuitInterior()
return
elif numOfEmptySeats >= 0 and numOfEmptySeats <= 3:
pass
else:
self.error('Bad number of empty seats: %s' % numOfEmptySeats)
for toon in self.toons:
if seats.count(toon) == 0:
self.__removeToon(toon)
self.toonIds = copy.copy(seats)
self.toons = []
for toonId in self.toonIds:
if toonId != None:
self.toons.append(toonId)
self.d_setToons()
self.currentFloor += 1
self.fsm.request('Elevator')
return
def exitResting(self):
self.intElevator.requestDelete()
del self.intElevator
return None
def enterReward(self):
victors = self.toonIds[:]
savedBy = []
for v in victors:
tuple = self.savedByMap.get(v)
if tuple:
savedBy.append([v, tuple[0], tuple[1]])
self.bldg.fsm.request('waitForVictors', [victors, savedBy])
self.d_setState('Reward')
return None
def exitReward(self):
return None
# VERIFICATION FAILED