def toonExitDemand(self): avId = self.air.getAvatarIdFromSender() if not avId in self.toonsPlaying: self.air.writeServerEvent( 'suspicious', avId=avId, issue='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=avId, issue='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)
def toonExitRequest(self, team): av = self._getCaller() if not av: return if not self.fsm.state in ('WaitForEnough', 'WaitToStart'): self.sendUpdateToAvatarId(av.doId, 'exitRequestDenied', [PartyGlobals.DenialReasons.Default]) return if not (av.doId in self.toonIds[0] or av.doId in self.toonIds[1]): self.air.writeServerEvent( 'suspicious', avId, 'tried to switch DistributedPartyActivityAI team, but not in one' ) self.sendUpdateToAvatarId(av.doId, 'exitRequestDenied', [PartyGlobals.DenialReasons.Default]) return currentTeam = (1, 0)[av.doId in self.toonIds[0]] self.toonIds[currentTeam].remove(av.doId) print(self.toonsPlaying) self.toonsPlaying.remove(av.doId) print(self.toonsPlaying) DistributedPartyActivityAI.toonExitRequest(self) self.__update()
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
def toonJoinRequest(self, team): av = self._getCaller() if not av: return if not self.fsm.state in ('WaitForEnough', 'WaitToStart'): self.sendUpdateToAvatarId(av.doId, 'joinRequestDenied', [PartyGlobals.DenialReasons.Default]) return if len(self.toonIds[team]) >= self.getPlayersPerTeam()[1]: self.sendUpdateToAvatarId(av.doId, 'joinRequestDenied', [PartyGlobals.DenialReasons.Full]) return if av.doId in self.toonsPlaying: print("Toon is already playing!") self.air.writeServerEvent( 'suspicious', av.doId, 'tried to join party team activity again!') self.sendUpdateToAvatarId(av.doId, 'joinRequestDenied', [PartyGlobals.DenialReasons.Default]) return # idgaf if they exit unexpectedly in this case self.toonIds[team].append(av.doId) DistributedPartyActivityAI.toonJoinRequest(self) self.__update()
def toonJoinRequest(self, team): av = self._getCaller() if not av: return if not self.fsm.state in ('WaitForEnough', 'WaitToStart'): self.sendUpdateToAvatarId(av.doId, 'joinRequestDenied', [PartyGlobals.DenialReasons.Default]) return if len(self.toonIds[team]) >= self.getPlayersPerTeam()[1]: self.sendUpdateToAvatarId(av.doId, 'joinRequestDenied', [PartyGlobals.DenialReasons.Full]) return if av.doId in self.toonsPlaying: self.air.writeServerEvent( 'suspicious', av.doId, 'tried to join party team activity again!') self.sendUpdateToAvatarId(av.doId, 'joinRequestDenied', [PartyGlobals.DenialReasons.Default]) return # We need to care if they exit before being appended to prevent District Resets. if av.doId in self.air.doId2do: self.toonIds[team].append(av.doId) DistributedPartyActivityAI.toonJoinRequest(self) self.__update() else: self.notify.warning( "Toon %d joined activity but left unexpectdly!" % (av.doId)) return
def __init__(self, air, parent, activityTuple): DistributedPartyActivityAI.__init__(self, air, parent, activityTuple) FSM.__init__(self, 'DistributedPartyTrampolineActivityAI') self.currentAv = 0 self.record = 0 self.jellybeans = [] self.collected = 0
def delete(self): DistributedPartyCatchActivityAI.notify.debug("delete") taskMgr.remove(self.conclusionCountdownTask) taskMgr.remove(self.conclusionFinishTask) del self.activityFSM self.ignore(self._partyEndedEvent) DistributedPartyActivityAI.delete(self)
def __init__(self, air, partyDoId, x, y, h): DistributedPartyActivityAI.__init__( self, air, partyDoId, x, y, h, PartyGlobals.ActivityIds.PartyCatch, PartyGlobals.ActivityTypes.HostInitiated) self.toonIdsToScores = {} # create state machine and set initial state self.activityFSM = CatchActivityFSM(self)
def __init__(self, air, partyDoId, x, y, h, actId, phaseToMusicData): self.notify.debug("Intializing.") DistributedPartyActivityAI.__init__( self, air, partyDoId, x, y, h, actId, PartyGlobals.ActivityTypes.Continuous) # Holds the list of songs requested by each avatar. # Format: { toonId : (phase, filename), ... } self.phaseToMusicData = phaseToMusicData self.toonIdToSongData = {} # Holds the queue of songs to be played by avatarId self.toonIdQueue = [] self.songPlaying = False self.songTimerTask = None self.timeoutTask = None # listen for fireworks show starting and stopping self.accept(PartyGlobals.FireworksStartedEvent, self.__handleFireworksStarted) self.accept(PartyGlobals.FireworksFinishedEvent, self.__handleFireworksFinished) # this ensure the first song we hear is one of the new ones self.randomSongPhase = 13
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()])
def toonExitDemand(self): DistributedPartyCatchActivityAI.notify.debug("toonJoinRequest") toonId = self.air.getAvatarIdFromSender() # make sure this toon is currently playing if toonId not in self.toonIds: return if toonId in self.toonIdsToScores: reward = self.toonIdsToScores[toonId] # if it's jelly bean day give us more jelly beans! if self.air.holidayManager.isHolidayRunning( ToontownGlobals.JELLYBEAN_DAY): reward *= PartyGlobals.JellyBeanDayMultiplier if reward > PartyGlobals.CatchMaxTotalReward: # put a cap so we don't go beyond something ridiculous reward = PartyGlobals.CatchMaxTotalReward self.toonIdsToJellybeanRewards[toonId] = reward self.sendUpdateToAvatarId(toonId, "showJellybeanReward", [ reward, self.air.doId2do[toonId].getMoney(), TTLocalizer.PartyCatchRewardMessage % (self.toonIdsToScores[toonId], reward) ]) del self.toonIdsToScores[toonId] self.toonIdsToJellybeanRewards[toonId] = reward self.issueJellybeanRewardToToonId(toonId) DistributedPartyActivityAI.toonExitDemand(self) if toonId in self._playerIds: self._playerIds.remove(toonId) # number of players changed, start a new generation of drops self._setUpNextGenScheduleTask(globalClock.getRealTime() - self.activityStartTime)
def __init__(self, air, parent, activityTuple): DistributedPartyActivityAI.__init__(self, air, parent, activityTuple) self.music = PartyGlobals.PhaseToMusicData40 self.queue = [] self.owners = [] self.currentToon = 0 self.playing = False
def __init__(self, air, partyDoId, x, y, h, activityId, dancePatternToAnims): self.notify.debug("Intializing.") DistributedPartyActivityAI.__init__( self, air, partyDoId, x, y, h, activityId, PartyGlobals.ActivityTypes.Continuous) self.toonIdsToHeadings = {} # toon's heading when it joined self.dancePatternToAnims = dancePatternToAnims
def sendToonJoinResponse(self, toonId, joined): # since toons can join mid-activity, make sure to add to scores dictionary if needed if joined: if not self.toonIdsToScores.has_key(toonId): self.toonIdsToScores[toonId] = 0 DistributedPartyActivityAI.sendToonJoinResponse(self, toonId, joined) # number of players changed, start a new generation of drops self._setUpNextGenScheduleTask(globalClock.getRealTime() - self.activityStartTime)
def _handleUnexpectedToonExit(self, toonId): """ An avatar bailed out because he lost his connection or quit unexpectedly. """ DistributedPartyTrampolineActivityAI.notify.debug( "_handleUnexpectedToonExit( toonId=%s )" % toonId) self.activityFSM.request("Idle") DistributedPartyActivityAI._handleUnexpectedToonExit(self, toonId)
def delete(self): self.ignoreAll() for cannon in self.cannons.values(): cannon.requestDelete() self.cannons.clear() self.flyingToons.clear() self.flyingToonCloudsHit.clear() self.toonIdsToJellybeanRewards.clear() DistributedPartyActivityAI.delete(self)
def _handleUnexpectedToonExit(self, toonId): """ Flying toon client exits, request cleanup. """ if self.flyingToons.has_key(toonId): self.notify.warning("Avatar %s has exited unexpectedly." % toonId) # cannon_movie_force_exit will clean up the avatar on the client # and eventually call setLanded to complete the cleanup on AI self.d_setMovie(PartyGlobals.CANNON_MOVIE_FORCE_EXIT, toonId) self.__cleanupFlyingToon(toonId) DistributedPartyActivityAI._handleUnexpectedToonExit(self, toonId)
def generate(self): DistributedPartyActivityAI.generate(self) self._partyEndedEvent = self.air.partyManager.getPartyEndedEvent( self.party.partyInfo.hostId) self.accept(self._partyEndedEvent, self._handlePartyEnded) self.conclusionCountdownTask = self.uniqueName( "PartyCatchConclusionCountdownTask") self.conclusionFinishTask = self.uniqueName( "PartyCatchConclusionFinishTask") self.activityFSM.request("Idle") # game is always running self.activityFSM.request("Active")
def __init__(self, air, parent, activityTuple): DistributedPartyActivityAI.__init__(self, air, parent, activityTuple) self.music = PartyGlobals.PhaseToMusicData40 self.queue = [] self.owners = [] self.currentToon = 0 self.playing = False self.paused = False self.accept('fireworksStarted%i' % self.getPartyDoId(), self.handleFireworksStart) self.accept('fireworksFinished%i' % self.getPartyDoId(), self.handleFireworksEnd)
def __init__(self, air, partyDoId, x, y, h, actId=PartyGlobals.ActivityIds.PartyTrampoline): DistributedPartyActivityAI.__init__( self, air, partyDoId, x, y, h, actId, PartyGlobals.ActivityTypes.GuestInitiated) self.activityFSM = TrampolineActivityFSM(self) # bestHeightInfo is a tuple of toon's name and their height self.bestHeightInfo = ("", 0) self.accept("NewBestHeightInfo", self.newBestHeightInfo)
def _handleUnexpectedToonExit(self, toonId): """ An avatar bailed out because he lost his connection or quit unexpectedly. """ DistributedPartyCatchActivityAI.notify.debug( "_handleUnexpectedToonExit( toonId=%s )" % toonId) DistributedPartyActivityAI._handleUnexpectedToonExit(self, toonId) if toonId in self._playerIds: self._playerIds.remove(toonId) if self.toonIdsToScores.has_key(toonId): del self.toonIdsToScores[toonId] # number of players changed, start a new generation of drops self._setUpNextGenScheduleTask(globalClock.getRealTime() - self.activityStartTime)
def __init__(self, air, partyDoId, x, y, h): DistributedPartyActivityAI.__init__( self, air, partyDoId, x, y, h, PartyGlobals.ActivityIds.PartyCannon, PartyGlobals.ActivityTypes.Continuous) # map of cannons by cannon doId self.cannons = {} # map of flying toon doIds to firing cannons doIds self.flyingToons = {} self.flyingToonCloudsHit = {} self.toonIdsToJellybeanRewards = {} # Map of cloudNumber to rgb info self.cloudColors = {}
def toonExitDemand(self): avId = self.air.getAvatarIdFromSender() if avId not in self.toonsPlaying: self.air.writeServerEvent('suspicious', avId=avId, issue="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=avId, issue='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)
def toonExitRequest(self, team): av = self._getCaller() if not av: return if not self.fsm.state_ in ('WaitForEnough', 'WaitToStart'): self.sendUpdateToAvatarId(av.doId, 'exitRequestDenied', [PartyGlobals.DenialReasons.Default]) return if not (av.doId in self.toonIds[0] or av.doId in self.toonIds[1]): self.air.writeServerEvent('suspicious', avId, 'tried to switch DistributedPartyActivityAI team, but not in one') self.sendUpdateToAvatarId(av.doId, 'exitRequestDenied', [PartyGlobals.DenialReasons.Default]) return currentTeam = (1, 0)[av.doId in self.toonIds[0]] self.toonIds[currentTeam].remove(av.doId) print self.toonsPlaying self.toonsPlaying.remove(av.doId) print self.toonsPlaying DistributedPartyActivityAI.toonExitRequest(self) self.__update()
def toonJoinRequest(self, team): av = self._getCaller() if not av: return if not self.fsm.state_ in ('WaitForEnough', 'WaitToStart'): self.sendUpdateToAvatarId(av.doId, 'joinRequestDenied', [PartyGlobals.DenialReasons.Default]) return if len(self.toonIds[team]) >= self.getPlayersPerTeam()[1]: self.sendUpdateToAvatarId(av.doId, 'joinRequestDenied', [PartyGlobals.DenialReasons.Full]) return if av.doId in self.toonsPlaying: print "Toon is already playing!" self.air.writeServerEvent('suspicious', av.doId, 'tried to join party team activity again!') self.sendUpdateToAvatarId(av.doId, 'joinRequestDenied', [PartyGlobals.DenialReasons.Default]) return # idgaf if they exit unexpectedly in this case self.toonIds[team].append(av.doId) DistributedPartyActivityAI.toonJoinRequest(self) self.__update()
def delete(self): taskMgr.remove('newGeneration%d' % self.doId) DistributedPartyActivityAI.delete(self)
def __init__(self, air, parent, activityTuple): self.toonIds = ([], []) self.responses = set() self.fsm = TeamActivityAIFSM(self) DistributedPartyActivityAI.__init__(self, air, parent, activityTuple)
def announceGenerate(self): self.b_setState('WaitForEnough') DistributedPartyActivityAI.announceGenerate(self)
def __init__( self, air, partyDoId, x, y, h, activityId, minPlayersPerTeam=PartyGlobals.TeamActivityDefaultMinPlayersPerTeam, maxPlayersPerTeam=PartyGlobals.TeamActivityDefaultMaxPlayersPerTeam, duration=PartyGlobals.TeamActivityDefaultDuration, conclusionDuration=PartyGlobals.TeamActivityDefaultConclusionDuration, startDelay=PartyGlobals.TeamActivityStartDelay, balanceTeams=False, calcAdvantage=False, canSwitchTeams=False, ): DistributedPartyActivityAI.__init__( self, air, partyDoId, x, y, h, activityId, PartyGlobals.ActivityTypes.GuestInitiated, ) self.notify.debug("__init__") self._minPlayersPerTeam = minPlayersPerTeam self._maxPlayersPerTeam = maxPlayersPerTeam # How long should the conclusion state last in seconds? self._conclusionDuration = conclusionDuration # How long the active state lasts self._duration = simbase.config.GetFloat( "party-team-activity-duration", duration) # How long should it wait for more players before going to the active state self._startDelay = simbase.config.GetFloat( "party-team-activity-start-delay", startDelay) # Should it calculate whether both team have roughly an equal amount of players? self._shouldBalanceTeams = balanceTeams # Should it calculate the advantage of a smaller team over a larger team? self._shouldCalcAdvantage = calcAdvantage # Can players willingly switch teams before the game starts? self._canSwitchTeams = canSwitchTeams # Do we allow a single player? (This is for testing purposes) self._allowSinglePlayer = simbase.config.GetBool( "party-team-activity-single-player", False) self.toonIds = ( [], # doIds of toons on the left team, ordered from those nearest the water to those furthest [], # doIds of toons on the right team, ordered from those nearest the water to those furthest ) self.readyToonIds = set() # Keep track of which side each avatar is on for quick look up during game self.toonIdsToTeams = {} # state transition request doLater self._srTask = None self.activityFSM = TeamActivityAIFSM(self)
def __init__(self, air, parent, activityTuple): DistributedPartyActivityAI.__init__(self, air, parent, activityTuple) self.cloudColors = {} self.cloudsHit = {}
def delete(self): self.cleanupRequestLater() DistributedPartyActivityAI.delete(self)
def __init__(self, air, parent, activityTuple): DistributedPartyActivityAI.__init__(self, air, parent, activityTuple) self.toons = [] self.headings = []
def __init__(self, air, parent, activityTuple, isTF=False): DistributedPartyActivityAI.__init__(self, air, parent, activityTuple) self.cloudColors = {} self.cloudsHit = {} self.isTF = isTF
def __init__(self, air, parent, activityTuple): DistributedPartyActivityAI.__init__(self, air, parent, activityTuple) FSM.__init__(self, 'DistributedPartyActivityAI') self.state_ = 'Idle'
def generate(self): DistributedPartyActivityAI.generate(self) self.sendUpdate( 'setState', ['Active', globalClockDelta.getRealNetworkTime()])
def delete(self): taskMgr.remove('playSong%d' % self.doId) DistributedPartyActivityAI.delete(self)
def generate(self): DistributedPartyActivityAI.generate(self) self.notify.debug("generate") self.activityFSM.request("WaitForEnough")
def __init__(self, air, parent, activityTuple): DistributedPartyActivityAI.__init__(self, air, parent, activityTuple) FSM.__init__(self, 'DistributedPartyActivityAI') self.state = 'Idle'
def announceGenerate(self): DistributedPartyActivityAI.announceGenerate(self) self.notify.debug("announceGenerate")
def generate(self): DistributedPartyActivityAI.generate(self) self.sendUpdate('setState', ['Active', globalClockDelta.getRealNetworkTime()])