Poodletooth-iLand/toontown/minigame/DistributedTagGameAI.py

139 lines
5 KiB
Python
Raw Normal View History

2015-03-03 16:10:12 -06:00
from DistributedMinigameAI import *
from TagTreasurePlannerAI import *
from direct.fsm import ClassicFSM, State
from direct.fsm import State
from direct.task import Task
2015-05-25 04:31:46 -05:00
from toontown.safezone import TreasureGlobals
2015-03-03 16:10:12 -06:00
import random
import TagGameGlobals
class DistributedTagGameAI(DistributedMinigameAI):
DURATION = TagGameGlobals.DURATION
def __init__(self, air, minigameId):
try:
self.DistributedTagGameAI_initialized
except:
self.DistributedTagGameAI_initialized = 1
DistributedMinigameAI.__init__(self, air, minigameId)
self.gameFSM = ClassicFSM.ClassicFSM('DistributedTagGameAI', [State.State('inactive', self.enterInactive, self.exitInactive, ['play']), State.State('play', self.enterPlay, self.exitPlay, ['cleanup']), State.State('cleanup', self.enterCleanup, self.exitCleanup, ['inactive'])], 'inactive', 'inactive')
self.addChildGameFSM(self.gameFSM)
self.treasureScores = {}
self.itAvId = None
2015-05-25 04:31:46 -05:00
self.healAmount = 3
2015-03-03 16:10:12 -06:00
self.tagBack = 1
return
def delete(self):
self.notify.debug('delete')
del self.gameFSM
DistributedMinigameAI.delete(self)
def setGameReady(self):
self.notify.debug('setGameReady')
DistributedMinigameAI.setGameReady(self)
for avId in self.avIdList:
self.treasureScores[avId] = 0
def setGameStart(self, timestamp):
self.notify.debug('setGameStart')
DistributedMinigameAI.setGameStart(self, timestamp)
self.gameFSM.request('play')
def setGameAbort(self):
self.notify.debug('setGameAbort')
if self.gameFSM.getCurrentState():
self.gameFSM.request('cleanup')
DistributedMinigameAI.setGameAbort(self)
def gameOver(self):
self.notify.debug('gameOver')
self.gameFSM.request('cleanup')
DistributedMinigameAI.gameOver(self)
def enterInactive(self):
self.notify.debug('enterInactive')
def exitInactive(self):
pass
def enterPlay(self):
self.notify.debug('enterPlay')
self.b_setIt(random.choice(self.avIdList))
taskMgr.doMethodLater(self.DURATION, self.timerExpired, self.taskName('gameTimer'))
2015-07-05 18:59:25 -05:00
2015-05-25 04:31:46 -05:00
safezoneId = self.getSafezoneId()
if safezoneId in TreasureGlobals.SafeZoneTreasureSpawns:
treasureType, self.healAmount, spawnPoints, spawnRate, maxTreasures = TreasureGlobals.SafeZoneTreasureSpawns[safezoneId]
else:
treasureType, self.healAmount = TreasureGlobals.TreasureTT, 3
self.tagTreasurePlanner = TagTreasurePlannerAI(self.zoneId, self, self.treasureGrabCallback, treasureType, TagGameGlobals.getTreasurePoints(safezoneId))
2015-03-03 16:10:12 -06:00
self.tagTreasurePlanner.start()
def timerExpired(self, task):
self.notify.debug('timer expired')
self.gameOver()
return Task.done
def exitPlay(self):
taskMgr.remove(self.taskName('gameTimer'))
taskMgr.remove(self.taskName('tagBack'))
taskMgr.remove(self.taskName('clearTagBack'))
self.tagTreasurePlanner.stop()
self.tagTreasurePlanner.deleteAllTreasuresNow()
del self.tagTreasurePlanner
def enterCleanup(self):
self.notify.debug('enterCleanup')
self.gameFSM.request('inactive')
def exitCleanup(self):
pass
def treasureGrabCallback(self, avId):
if avId not in self.avIdList:
self.air.writeServerEvent('suspicious', avId, 'TagGameAI.treasureGrabCallback non-player avId')
return
2015-05-25 04:31:46 -05:00
self.treasureScores[avId] += self.healAmount
2015-03-03 16:10:12 -06:00
self.notify.debug('treasureGrabCallback: ' + str(avId) + ' grabbed a treasure, new score: ' + str(self.treasureScores[avId]))
self.scoreDict[avId] = self.treasureScores[avId]
treasureScoreParams = []
for avId in self.avIdList:
treasureScoreParams.append(self.treasureScores[avId])
self.sendUpdate('setTreasureScore', [treasureScoreParams])
def clearTagBack(self, task):
self.tagBack = 1
return Task.done
def tag(self, taggedAvId):
taggedAvatar = simbase.air.doId2do.get(taggedAvId)
if taggedAvatar == None:
self.air.writeServerEvent('suspicious', taggedAvId, 'TagGameAI.tag invalid taggedAvId')
return
itAvId = self.air.getAvatarIdFromSender()
if self.tagBack:
self.notify.debug('tag: ' + str(itAvId) + ' tagged: ' + str(taggedAvId))
if self.itAvId == itAvId:
self.b_setIt(taggedAvId)
else:
self.notify.warning('Got tag message from avatar that is not IT')
return
self.tagBack = 0
taskMgr.doMethodLater(2.0, self.clearTagBack, self.taskName('clearTagBack'))
return
def b_setIt(self, avId):
self.d_setIt(avId)
self.setIt(avId)
def d_setIt(self, avId):
self.sendUpdate('setIt', [avId])
def setIt(self, avId):
2015-07-05 18:59:25 -05:00
self.itAvId = avId