Poodletooth-iLand/toontown/parties/DistributedPartyCatchActivityAI.py

88 lines
3.6 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from direct.directnotify import DirectNotifyGlobal
from toontown.parties.DistributedPartyActivityAI import DistributedPartyActivityAI
from toontown.parties.DistributedPartyCatchActivityBase import DistributedPartyCatchActivityBase
from direct.task import Task
from direct.distributed.ClockDelta import globalClockDelta
from toontown.toonbase import TTLocalizer
import PartyGlobals
class DistributedPartyCatchActivityAI(DistributedPartyActivityAI, DistributedPartyCatchActivityBase):
notify = DirectNotifyGlobal.directNotify.newCategory("DistributedPartyCatchActivityAI")
2015-07-05 18:59:25 -05:00
2015-03-03 16:10:12 -06:00
def __init__(self, air, parent, activityTuple):
DistributedPartyActivityAI.__init__(self, air, parent, activityTuple)
self.numGenerations = 1
self.generations = []
self.player2catches = {}
self.startTimestamp = globalClockDelta.getRealNetworkTime(bits=32)
self.playing = False
2015-07-05 18:59:25 -05:00
2015-03-03 16:10:12 -06:00
def delete(self):
taskMgr.remove('newGeneration%d' % self.doId)
DistributedPartyActivityAI.delete(self)
def getStartTimestamp(self):
return self.startTimestamp
def setStartTimestamp(self, ts):
self.startTimestamp = ts
def setGenerations(self, generations):
self.generations = generations
2015-07-05 18:59:25 -05:00
2015-03-03 16:10:12 -06:00
def toonJoinRequest(self):
DistributedPartyActivityAI.toonJoinRequest(self)
avId = self.air.getAvatarIdFromSender()
self.player2catches[avId] = 0
if not self.playing:
self.__startGame()
self.sendUpdate('setState', ['Active', globalClockDelta.getRealNetworkTime()])
2015-07-05 18:59:25 -05:00
2015-03-03 16:10:12 -06:00
def toonExitDemand(self):
avId = self.air.getAvatarIdFromSender()
if not avId in self.toonsPlaying:
self.air.writeServerEvent('suspicious',avId,'Toon tried to exit a party game they\'re not using!')
return
catches = self.player2catches[avId]
del self.player2catches[avId]
av = self.air.doId2do.get(avId, None)
if not av:
self.air.writeServerEvent('suspicious',avId,'Toon tried to award beans while not in district!')
return
if catches > PartyGlobals.CatchMaxTotalReward:
catches = PartyGlobals.CatchMaxTotalReward
self.sendUpdateToAvatarId(avId, 'showJellybeanReward', [catches, av.getMoney(), TTLocalizer.PartyCatchRewardMessage % (catches, catches)])
av.addMoney(catches)
DistributedPartyActivityAI.toonExitDemand(self)
2015-07-05 18:59:25 -05:00
2015-03-03 16:10:12 -06:00
def __startGame(self):
self.playing = True
self.calcDifficultyConstants(len(self.toonsPlaying))
self.generations.append([self.numGenerations, globalClockDelta.getRealNetworkTime(bits=32), len(self.toonsPlaying)])
self.numGenerations += 1
self.sendUpdate('setGenerations', [self.generations])
taskMgr.doMethodLater(self.generationDuration, self.__newGeneration, 'newGeneration%d' % self.doId, extraArgs=[])
2015-07-05 18:59:25 -05:00
2015-03-03 16:10:12 -06:00
def __newGeneration(self):
if len(self.toonsPlaying) > 0:
self.__startGame()
else:
2015-07-05 18:59:25 -05:00
self.playing = False
2015-03-03 16:10:12 -06:00
def getGenerations(self):
return self.generations
def requestActivityStart(self):
pass
def startRequestResponse(self, todo0):
pass
def claimCatch(self, generation, objNum, objType):
avId = self.air.getAvatarIdFromSender()
if not avId in self.toonsPlaying:
self.air.writeServerEvent('suspicious',avId,'Toon tried to catch while not playing!')
return
if PartyGlobals.DOTypeId2Name[objType] != 'anvil':
self.player2catches[avId] += 1
2015-07-05 18:59:25 -05:00
self.sendUpdate('setObjectCaught', [avId, generation, objNum])