本文整理汇总了Python中toontown.ai.ToonBarrier类的典型用法代码示例。如果您正苦于以下问题:Python ToonBarrier类的具体用法?Python ToonBarrier怎么用?Python ToonBarrier使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ToonBarrier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: enterWaitReadyCourse
def enterWaitReadyCourse(self):
self.notify.debug('GOLF COURSE: enterWaitReadyCourse')
def allAvatarsInCourse(self = self):
self.notify.debug('GOLF COURSE: all avatars ready course')
for avId in self.avIdList:
blankScoreList = [
0] * self.numHoles
self.scores[avId] = blankScoreList
self.aimTimes[avId] = 0
self.notify.debug('self.scores = %s' % self.scores)
self.startNextHole()
def handleTimeout(avIds, self = self):
self.notify.debug("GOLF COURSE: Course timed out waiting for clients %s to report 'ready'" % avIds)
if self.haveAllGolfersExited():
self.setCourseAbort()
else:
allAvatarsInCourse()
self.__barrier = ToonBarrier('WaitReadyCourse', self.uniqueName('WaitReadyCourse'), self.avIdList, READY_TIMEOUT, allAvatarsInCourse, handleTimeout)
for avId in self.avStateDict.keys():
if self.avStateDict[avId] == READY:
self.__barrier.clear(avId)
示例2: enterWaitReadyHole
def enterWaitReadyHole(self):
self.notify.debug("GOLF COURSE: enterWaitReadyHole")
def allAvatarsInHole(self=self):
self.notify.debug("GOLF COURSE: all avatars ready hole")
if self.safeDemand("PlayHole"):
self.d_setPlayHole()
def handleTimeout(avIds, self=self):
self.notify.debug("GOLF COURSE: Hole timed out waiting for clients %s to report 'ready'" % avIds)
if self.haveAllGolfersExited():
self.setCourseAbort()
elif self.safeDemand("PlayHole"):
self.d_setPlayHole()
stillPlaying = self.getStillPlayingAvIds()
self.__barrier = ToonBarrier(
"WaitReadyHole",
self.uniqueName("WaitReadyHole"),
stillPlaying,
READY_TIMEOUT,
allAvatarsInHole,
handleTimeout,
)
for avId in self.avStateDict.keys():
if self.avStateDict[avId] == ONHOLE:
self.__barrier.clear(avId)
示例3: enterWaitJoin
def enterWaitJoin(self):
self.notify.debug("GOLF COURSE: enterWaitJoin")
for avId in self.avIdList:
self.avStateDict[avId] = EXPECTED
self.acceptOnce(self.air.getAvatarExitEvent(avId), self.handleExitedAvatar, extraArgs=[avId])
def allAvatarsJoined(self=self):
self.notify.debug("GOLF COURSE: all avatars joined")
self.load()
def handleTimeout(avIds, self=self):
self.notify.debug("GOLF COURSE: timed out waiting for clients %s to join" % avIds)
for avId in self.avStateDict:
if not self.avStateDict[avId] == JOINED:
self.handleExitedAvatar(avId)
if self.haveAllGolfersExited():
self.setCourseAbort()
else:
self.load()
self.__barrier = ToonBarrier(
"waitClientsJoin",
self.uniqueName("waitClientsJoin"),
self.avIdList,
JOIN_TIMEOUT,
allAvatarsJoined,
handleTimeout,
)
示例4: enterFrameworkWaitClientsReady
def enterFrameworkWaitClientsReady(self):
self.notify.debug("BASE: enterFrameworkWaitClientsReady")
def allAvatarsReady(self=self):
self.notify.debug("BASE: all avatars ready")
self.frameworkFSM.request("frameworkGame")
def handleTimeout(avIds, self=self):
self.notify.debug("BASE: timed out waiting for clients %s to report 'ready'" % avIds)
self.setGameAbort()
self.__barrier = ToonBarrier(
"waitClientsReady",
self.uniqueName("waitClientsReady"),
self.avIdList,
READY_TIMEOUT,
allAvatarsReady,
handleTimeout,
)
for avId in self.stateDict.keys():
if self.stateDict[avId] == READY:
self.__barrier.clear(avId)
self.notify.debug(" safezone: %s" % self.getSafezoneId())
self.notify.debug("difficulty: %s" % self.getDifficulty())
示例5: enterWaitForResults
def enterWaitForResults(self):
self.notify.debug('enterWaitForResults')
self.results = [None] * self.numPlayers
self.fastestTime = PatternGameGlobals.InputTime * 2
self.fastestAvId = 0
self.resultsBarrier = ToonBarrier('results', self.uniqueName('results'), self.avIdList, PatternGameGlobals.InputTimeout + 1.0 * self.round, self.__gotAllPatterns, self.__resultsTimeout)
return
示例6: enterWaitClientsReady
def enterWaitClientsReady(self):
self.notify.debug("enterWaitClientsReady")
self.nextRoundBarrier = ToonBarrier(
"nextRoundReady",
self.uniqueName("nextRoundReady"),
self.avIdList,
PatternGameGlobals.ClientsReadyTimeout,
self.__allPlayersReady,
self.__clientsReadyTimeout,
)
for avId in self.readyClients:
self.nextRoundBarrier.clear(avId)
示例7: enterPlay
def enterPlay(self):
self.notify.debug('enterPlay')
def allToonsDone(self = self):
self.notify.debug('allToonsDone')
self.sendUpdate('setEveryoneDone')
if not ToonBlitzGlobals.EndlessGame:
self.gameOver()
def handleTimeout(avIds, self = self):
self.notify.debug('handleTimeout: avatars %s did not report "done"' % avIds)
self.setGameAbort()
self.doneBarrier = ToonBarrier('waitClientsDone', self.uniqueName('waitClientsDone'), self.avIdList, ToonBlitzGlobals.GameDuration[self.getSafezoneId()] + ToonBlitzGlobals.ShowScoresDuration + MinigameGlobals.latencyTolerance, allToonsDone, handleTimeout)
示例8: enterFrameworkWaitClientsExit
def enterFrameworkWaitClientsExit(self):
self.notify.debug('BASE: enterFrameworkWaitClientsExit')
self.b_setGameExit()
def allAvatarsExited(self = self):
self.notify.debug('BASE: all avatars exited')
self.frameworkFSM.request('frameworkCleanup')
def handleTimeout(avIds, self = self):
self.notify.debug('BASE: timed out waiting for clients %s to exit' % avIds)
self.frameworkFSM.request('frameworkCleanup')
self.__barrier = ToonBarrier('waitClientsExit', self.uniqueName('waitClientsExit'), self.avIdList, EXIT_TIMEOUT, allAvatarsExited, handleTimeout)
for avId in self.stateDict.keys():
if self.stateDict[avId] == EXITED:
self.__barrier.clear(avId)
示例9: enterFrameworkWaitClientsJoin
def enterFrameworkWaitClientsJoin(self):
self.notify.debug('BASE: enterFrameworkWaitClientsJoin')
for avId in self.avIdList:
self.stateDict[avId] = EXPECTED
self.scoreDict[avId] = DEFAULT_POINTS
self.acceptOnce(self.air.getAvatarExitEvent(avId), self.handleExitedAvatar, extraArgs=[avId])
def allAvatarsJoined(self = self):
self.notify.debug('BASE: all avatars joined')
self.b_setGameReady()
self.frameworkFSM.request('frameworkWaitClientsReady')
def handleTimeout(avIds, self = self):
self.notify.debug('BASE: timed out waiting for clients %s to join' % avIds)
self.setGameAbort()
self.__barrier = ToonBarrier('waitClientsJoin', self.uniqueName('waitClientsJoin'), self.avIdList, JOIN_TIMEOUT, allAvatarsJoined, handleTimeout)
示例10: enterPlay
def enterPlay(self):
self.notify.debug('enterPlay')
self.caughtList = [0] * 100
table = CatchGameGlobals.NumFruits[self.numPlayers - 1]
self.numFruits = table[self.getSafezoneId()]
self.notify.debug('numFruits: %s' % self.numFruits)
self.fruitsCaught = 0
def allToonsDone(self = self):
self.notify.debug('allToonsDone')
self.sendUpdate('setEveryoneDone')
if not CatchGameGlobals.EndlessGame:
self.gameOver()
def handleTimeout(avIds, self = self):
self.notify.debug('handleTimeout: avatars %s did not report "done"' % avIds)
self.setGameAbort()
self.doneBarrier = ToonBarrier('waitClientsDone', self.uniqueName('waitClientsDone'), self.avIdList, CatchGameGlobals.GameDuration + MinigameGlobals.latencyTolerance, allToonsDone, handleTimeout)
示例11: enterFrameworkWaitClientsReady
def enterFrameworkWaitClientsReady(self):
self.notify.debug('BASE: enterFrameworkWaitClientsReady')
def allAvatarsReady(self = self):
self.notify.debug('BASE: all avatars ready')
self.frameworkFSM.request('frameworkGame')
def handleTimeout(avIds, self = self):
self.notify.debug("BASE: timed out waiting for clients %s to report 'ready'" % avIds)
self.setGameAbort()
self._DistributedMinigameAI__barrier = ToonBarrier('waitClientsReady', self.uniqueName('waitClientsReady'), self.avIdList, READY_TIMEOUT, allAvatarsReady, handleTimeout)
for avId in self.stateDict.keys():
if self.stateDict[avId] == READY:
self._DistributedMinigameAI__barrier.clear(avId)
continue
self.notify.debug(' safezone: %s' % self.getSafezoneId())
self.notify.debug('difficulty: %s' % self.getDifficulty())
示例12: DistributedMinigameAI
#.........这里部分代码省略.........
def gameOver(self):
self.notify.debug('BASE: gameOver')
self.frameworkFSM.request('frameworkWaitClientsExit')
def enterFrameworkOff(self):
self.notify.debug('BASE: enterFrameworkOff')
def exitFrameworkOff(self):
pass
def enterFrameworkWaitClientsJoin(self):
self.notify.debug('BASE: enterFrameworkWaitClientsJoin')
for avId in self.avIdList:
self.stateDict[avId] = EXPECTED
self.scoreDict[avId] = DEFAULT_POINTS
self.acceptOnce(self.air.getAvatarExitEvent(avId), self.handleExitedAvatar, extraArgs = [
avId])
def allAvatarsJoined(self = self):
self.notify.debug('BASE: all avatars joined')
self.b_setGameReady()
self.frameworkFSM.request('frameworkWaitClientsReady')
def handleTimeout(avIds, self = self):
self.notify.debug('BASE: timed out waiting for clients %s to join' % avIds)
self.setGameAbort()
self._DistributedMinigameAI__barrier = ToonBarrier('waitClientsJoin', self.uniqueName('waitClientsJoin'), self.avIdList, JOIN_TIMEOUT, allAvatarsJoined, handleTimeout)
def setAvatarJoined(self):
if self.frameworkFSM.getCurrentState().getName() != 'frameworkWaitClientsJoin':
self.notify.debug('BASE: Ignoring setAvatarJoined message')
return None
avId = self.air.getAvatarIdFromSender()
self.notify.debug('BASE: setAvatarJoined: avatar id joined: ' + str(avId))
self.air.writeServerEvent('minigame_joined', avId, '%s|%s' % (self.minigameId, self.trolleyZone))
self.stateDict[avId] = JOINED
self.notify.debug('BASE: setAvatarJoined: new states: ' + str(self.stateDict))
self._DistributedMinigameAI__barrier.clear(avId)
def exitFrameworkWaitClientsJoin(self):
self._DistributedMinigameAI__barrier.cleanup()
del self._DistributedMinigameAI__barrier
def enterFrameworkWaitClientsReady(self):
self.notify.debug('BASE: enterFrameworkWaitClientsReady')
def allAvatarsReady(self = self):
self.notify.debug('BASE: all avatars ready')
self.frameworkFSM.request('frameworkGame')
def handleTimeout(avIds, self = self):
self.notify.debug("BASE: timed out waiting for clients %s to report 'ready'" % avIds)
self.setGameAbort()
示例13: enterWaitReward
def enterWaitReward(self):
self.updateHistoryForCourseComplete()
self.awardTrophies()
self.awardCups()
self.awardHoleBest()
self.awardCourseBest()
self.recordHoleInOne()
self.recordCourseUnderPar()
trophiesList = []
for index in xrange(len(self.avIdList)):
avId = self.avIdList[index]
if avId in self.newTrophies:
oneTrophyList = self.newTrophies[avId]
trophiesList.append(oneTrophyList)
else:
trophiesList.append([])
while len(trophiesList) < GolfGlobals.MAX_PLAYERS_PER_HOLE:
trophiesList.append([])
holeBestList = []
for index in xrange(len(self.avIdList)):
avId = self.avIdList[index]
if avId in self.newHoleBest:
oneTrophyList = self.newHoleBest[avId]
holeBestList.append(oneTrophyList)
else:
holeBestList.append([])
while len(holeBestList) < GolfGlobals.MAX_PLAYERS_PER_HOLE:
holeBestList.append([])
courseBestList = []
for index in xrange(len(self.avIdList)):
avId = self.avIdList[index]
if avId in self.newCourseBest:
oneTrophyList = self.newCourseBest[avId]
courseBestList.append(oneTrophyList)
else:
courseBestList.append([])
while len(courseBestList) < GolfGlobals.MAX_PLAYERS_PER_HOLE:
courseBestList.append([])
cupList = []
for index in xrange(len(self.avIdList)):
avId = self.avIdList[index]
if avId in self.newCups:
oneCupList = self.newCups[avId]
cupList.append(oneCupList)
self.cupListLen = self.cupListLen + 1
else:
cupList.append([])
while len(cupList) < GolfGlobals.MAX_PLAYERS_PER_HOLE:
cupList.append([])
REWARD_TIMEOUT = (self.trophyListLen + self.holeBestListLen + self.courseBestListLen + self.cupListLen) * 5 + 19
aimTimesList = [0] * 4
aimIndex = 0
stillPlaying = self.getStillPlayingAvIds()
for avId in self.avIdList:
if avId in stillPlaying:
aimTime = 0
if avId in self.aimTimes:
aimTime = self.aimTimes[avId]
aimTimesList[aimIndex] = aimTime
aimIndex += 1
self.sendUpdate('setReward', [trophiesList,
self.rankings,
holeBestList,
courseBestList,
cupList,
self.winnerByTieBreak,
aimTimesList[0],
aimTimesList[1],
aimTimesList[2],
aimTimesList[3]])
def allAvatarsRewarded(self = self):
self.notify.debug('GOLF COURSE: all avatars rewarded')
self.rewardDone()
def handleRewardTimeout(avIds, self = self):
self.notify.debug('GOLF COURSE: timed out waiting for clients %s to finish reward' % avIds)
self.rewardDone()
stillPlaying = self.getStillPlayingAvIds()
self.rewardBarrier = ToonBarrier('waitReward', self.uniqueName('waitReward'), stillPlaying, REWARD_TIMEOUT, allAvatarsRewarded, handleRewardTimeout)
示例14: DistributedPatternGameAI
class DistributedPatternGameAI(DistributedMinigameAI):
def __init__(self, air, minigameId):
try:
self.DistributedPatternGameAI_initialized
except:
self.DistributedPatternGameAI_initialized = 1
DistributedMinigameAI.__init__(self, air, minigameId)
self.gameFSM = ClassicFSM.ClassicFSM(
"DistributedPatternGameAI",
[
State.State("off", self.enterInactive, self.exitInactive, ["waitClientsReady", "cleanup"]),
State.State(
"waitClientsReady",
self.enterWaitClientsReady,
self.exitWaitClientsReady,
["generatePattern", "cleanup"],
),
State.State(
"generatePattern",
self.enterGeneratePattern,
self.exitGeneratePattern,
["waitForResults", "cleanup"],
),
State.State(
"waitForResults",
self.enterWaitForResults,
self.exitWaitForResults,
["waitClientsReady", "cleanup"],
),
State.State("cleanup", self.enterCleanup, self.exitCleanup, []),
],
"off",
"cleanup",
)
self.addChildGameFSM(self.gameFSM)
def delete(self):
self.notify.debug("delete")
del self.gameFSM
DistributedMinigameAI.delete(self)
def setGameReady(self):
self.notify.debug("setGameReady")
DistributedMinigameAI.setGameReady(self)
self.__initGameVars()
def setGameStart(self, timestamp):
self.notify.debug("setGameStart")
DistributedMinigameAI.setGameStart(self, timestamp)
self.gameFSM.request("waitClientsReady")
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 __initGameVars(self):
self.pattern = []
self.round = 0
self.perfectResults = {}
for avId in self.avIdList:
self.perfectResults[avId] = 1
self.readyClients = []
self.timeoutTaskName = self.uniqueName("PatternGameResultsTimeout")
def enterWaitClientsReady(self):
self.notify.debug("enterWaitClientsReady")
self.nextRoundBarrier = ToonBarrier(
"nextRoundReady",
self.uniqueName("nextRoundReady"),
self.avIdList,
PatternGameGlobals.ClientsReadyTimeout,
self.__allPlayersReady,
self.__clientsReadyTimeout,
)
for avId in self.readyClients:
self.nextRoundBarrier.clear(avId)
def reportPlayerReady(self):
if not self._inState("waitClientsReady"):
return
avId = self.air.getAvatarIdFromSender()
if avId not in self.avIdList:
self.notify.warning("Got reportPlayerReady from an avId: %s not in our list: %s" % (avId, self.avIdList))
else:
self.readyClients.append(avId)
self.nextRoundBarrier.clear(avId)
#.........这里部分代码省略.........
示例15: DistributedMinigameAI
#.........这里部分代码省略.........
self.sendUpdate("setGameAbort", [])
self.frameworkFSM.request("frameworkCleanup")
def handleExitedAvatar(self, avId):
self.notify.warning("BASE: handleExitedAvatar: avatar id exited: " + str(avId))
self.stateDict[avId] = EXITED
self.setGameAbort()
def gameOver(self):
self.frameworkFSM.request("frameworkWaitClientsExit")
def enterFrameworkOff(self):
self.notify.debug("BASE: enterFrameworkOff")
def exitFrameworkOff(self):
pass
def enterFrameworkWaitClientsJoin(self):
self.notify.debug("BASE: enterFrameworkWaitClientsJoin")
for avId in self.avIdList:
self.stateDict[avId] = EXPECTED
self.scoreDict[avId] = DEFAULT_POINTS
self.acceptOnce(self.air.getAvatarExitEvent(avId), self.handleExitedAvatar, extraArgs=[avId])
def allAvatarsJoined(self=self):
self.notify.debug("BASE: all avatars joined")
self.b_setGameReady()
self.frameworkFSM.request("frameworkWaitClientsReady")
def handleTimeout(avIds, self=self):
self.notify.debug("BASE: timed out waiting for clients %s to join" % avIds)
self.setGameAbort()
self.__barrier = ToonBarrier(
"waitClientsJoin",
self.uniqueName("waitClientsJoin"),
self.avIdList,
JOIN_TIMEOUT,
allAvatarsJoined,
handleTimeout,
)
def setAvatarJoined(self):
if self.frameworkFSM.getCurrentState().getName() != "frameworkWaitClientsJoin":
self.notify.debug("BASE: Ignoring setAvatarJoined message")
return
avId = self.air.getAvatarIdFromSender()
self.notify.debug("BASE: setAvatarJoined: avatar id joined: " + str(avId))
self.air.writeServerEvent("minigame_joined", avId, "%s|%s" % (self.minigameId, self.trolleyZone))
self.stateDict[avId] = JOINED
self.notify.debug("BASE: setAvatarJoined: new states: " + str(self.stateDict))
self.__barrier.clear(avId)
def exitFrameworkWaitClientsJoin(self):
self.__barrier.cleanup()
del self.__barrier
def enterFrameworkWaitClientsReady(self):
self.notify.debug("BASE: enterFrameworkWaitClientsReady")
def allAvatarsReady(self=self):
self.notify.debug("BASE: all avatars ready")
self.frameworkFSM.request("frameworkGame")
def handleTimeout(avIds, self=self):
self.notify.debug("BASE: timed out waiting for clients %s to report 'ready'" % avIds)