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=[])
def enterTrick(self, avatar, trickId): PetActionFSM.notify.debug('enterTrick') if not self.pet.isLockedDown(): self.pet.lockPet() self.pet.sendUpdate('doTrick', [trickId, globalClockDelta.getRealNetworkTime()]) def finish(avatar = avatar, trickId = trickId, self = self): if hasattr(self.pet, 'brain'): healRange = PetTricks.TrickHeals[trickId] aptitude = self.pet.getTrickAptitude(trickId) healAmt = int(lerp(healRange[0], healRange[1], aptitude)) if healAmt: for avId in self.pet.brain.getAvIdsLookingAtUs(): av = self.pet.air.doId2do.get(avId) if av: if isinstance(av, DistributedToonAI.DistributedToonAI): av.toonUp(healAmt) self.pet._handleDidTrick(trickId) if not self.pet.isLockedDown(): self.pet.unlockPet() messenger.send(self.getTrickDoneEvent()) self.trickDoneEvent = 'trickDone-%s-%s' % (self.pet.doId, self.trickSerialNum) self.trickSerialNum += 1 self.trickFinishIval = Sequence(WaitInterval(PetTricks.TrickLengths[trickId]), Func(finish), name='petTrickFinish-%s' % self.pet.doId) self.trickFinishIval.start()
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 resetMovie(self): taskMgr.doMethodLater( 1, self.d_setMovie, "resetMovie-%d" % self.getDoId(), extraArgs=[ClosetGlobals.CLOSET_MOVIE_CLEAR, 0, globalClockDelta.getRealNetworkTime()], )
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 blimp(phase): if not (0 <= phase <= 3): return 'Invalid phase.' for event in base.cr.doFindAllInstances(DistributedExperimentEvent): event.blimp.request('Phase%d' % phase, globalClockDelta.getRealNetworkTime(bits=32)) break else: return "Couldn't find a blimp."
def startFireworks(self, type, task=None): maxShow = len(FireworkShows.shows.get(type, [])) - 1 for hood in self.air.hoods: if hood.zoneId == ToontownGlobals.GolfZone: continue fireworkShow = DistributedFireworkShowAI(self.air) fireworkShow.generateWithRequired(hood.zoneId) fireworkShow.b_startShow(type, random.randint(0, maxShow), globalClockDelta.getRealNetworkTime()) return Task.again
def request(self, state): FSM.request(self, state) self.state = state self.sendUpdate('setState', [state, globalClockDelta.getRealNetworkTime()])
def d_setState(self, state): self.stateTimestamp = globalClockDelta.getRealNetworkTime() self.sendUpdate('setState', [state, self.stateTimestamp])
def setDNA(self, hatIdx, hatTexture, hatColor, glassesIdx, glassesTexture, glassesColor, backpackIdx, backpackTexture, backpackColor, shoesIdx, shoesTexture, shoesColor, finished, which): avId = self.air.getAvatarIdFromSender() if not self.verifyCustomer(avId): self.air.writeServerEvent('suspicious', avId, 'Tried to set DNA from closet while not using it!') return av = self.air.doId2do.get(avId) if not av: self.air.writeServerEvent('suspicious', avId, 'Interacted with a closet from another shard!') return if not self.__verifyAvatarInMyZone(av): self.air.writeServerEvent('suspicious', avId, 'Tried to setDNA while in another zone!') return if not finished: # They changed one of their accessories. if which == HAT: av.b_setHat(hatIdx, hatTexture, hatColor) if which == GLASSES: av.b_setGlasses(glassesIdx, glassesTexture, glassesColor) if which == BACKPACK: av.b_setBackpack(backpackIdx, backpackTexture, backpackColor) if which == SHOES: av.b_setShoes(shoesIdx, shoesTexture, shoesColor) elif finished == 1: # The user pressed the cancel button. All we need to do is free him. # Reset the removed items and our user. av.b_setHat(hatIdx, hatTexture, hatColor) av.b_setGlasses(glassesIdx, glassesTexture, glassesColor) av.b_setBackpack(backpackIdx, backpackTexture, backpackColor) av.b_setShoes(shoesIdx, shoesTexture, shoesColor) self.removedHats = [] self.removedGlasses = [] self.removedBackpacks = [] self.removedShoes = [] self.avId = None # Free the user. self.d_setMovie(ClosetGlobals.CLOSET_MOVIE_COMPLETE, avId, globalClockDelta.getRealNetworkTime()) self.resetMovie() self.setState(ClosetGlobals.CLOSED, 0, self.furnitureMgr.ownerId, self.gender, self.hatList, self.glassesList, self.backpackList, self.shoesList) elif finished == 2: # They are done using the trunk. Update their removed items. # Is the user actually the owner? if avId != self.furnitureMgr.ownerId: self.air.writeServerEvent('suspicious', avId, 'Tried to set their clothes from somebody else\'s closet!') return # Put on the accessories they want... if which & HAT: av.b_setHat(hatIdx, hatTexture, hatColor) if which & GLASSES: av.b_setGlasses(glassesIdx, glassesTexture, glassesColor) if which & BACKPACK: av.b_setBackpack(backpackIdx, backpackTexture, backpackColor) if which & SHOES: av.b_setShoes(shoesIdx, shoesTexture, shoesColor) # Delete all their items they want to be deleted... for hat in self.removedHats: id, texture, color = hat av.removeItemInAccessoriesList(HAT, id, texture, color) for glasses in self.removedGlasses: id, texture, color = glasses av.removeItemInAccessoriesList(GLASSES, id, texture, color) for backpack in self.removedBackpacks: id, texture, color = backpack av.removeItemInAccessoriesList(BACKPACK, id, texture, color) for shoe in self.removedShoes: id, texture, color = shoe av.removeItemInAccessoriesList(SHOES, id, texture, color) # Regenerate the available accessories... self.removedHats = [] self.removedGlasses = [] self.removedBackpacks = [] self.removedShoes = [] self.generate() # Release the customer self.releaseCustomer() # We are done, free the user! self.d_setMovie(ClosetGlobals.CLOSET_MOVIE_COMPLETE, avId, globalClockDelta.getRealNetworkTime()) self.resetMovie() self.setState(ClosetGlobals.CLOSED, 0, self.furnitureMgr.ownerId, self.gender, self.hatList, self.glassesList, self.backpackList, self.shoesList)
def d_setState(self, state): self.sendUpdate('setState', [state, globalClockDelta.getRealNetworkTime(bits=32)])
def setState(self, state): self.state = state self.sendUpdate('setState', [state, globalClockDelta.getRealNetworkTime()])
def enterIdle(self): self.sendUpdate('setState', ['Idle', globalClockDelta.getRealNetworkTime()])
def d_setState(self, state): self.sendUpdate( 'setState', [state, globalClockDelta.getRealNetworkTime(bits=32)])
def __networkTimeInSeconds(self): time = globalClockDelta.getRealNetworkTime( bits=32) / NetworkTimePrecision return time
def d_setGameState(self, gameState): self.sendUpdate( 'setGameState', [gameState, globalClockDelta.getRealNetworkTime(bits=16)])
def d_setWalkPath(self, path): # Send out a list of Point2s for the client to create a path for the suit to walk. timestamp = globalClockDelta.getRealNetworkTime() self.sendUpdate('setWalkPath', [path, timestamp])
def startFireworks(self, showType, showIndex): self.fireworkShow.b_startShow(showType, showIndex, globalClockDelta.getRealNetworkTime())
def getState(self): return self.state, globalClockDelta.getRealNetworkTime()
def enterIdle(self): self.sendUpdate('setState', ['Idle', globalClockDelta.getRealNetworkTime()])
def requestServerTime(self, context): self.sendUpdateToAvatarId(self.air.getAvatarIdFromSender(), 'serverTime', [context, globalClockDelta.getRealNetworkTime(bits=32), int(time.time())])
def d_setState(self, state, data=0): self.sendUpdate( 'setState', [state, globalClockDelta.getRealNetworkTime(), data])
def d_setState(self, state): self.stateTimestamp = globalClockDelta.getRealNetworkTime() self.sendUpdate('setState', [state, self.stateTimestamp])
def setState(self, state): self.state = state self.sendUpdate('setState', [state, globalClockDelta.getRealNetworkTime()])
def enterActive(self): self.sendUpdate('setState', ['Active', globalClockDelta.getRealNetworkTime()]) messenger.send('fireworksStarted%i' % self.getPartyDoId())
def announceGenerate(self): DistributedKartPadAI.announceGenerate(self) self.lastEntered = globalClockDelta.getRealNetworkTime()
def startFireworks(self, showType, showIndex): self.fireworkShow.b_startShow(showType, showIndex, globalClockDelta.getRealNetworkTime())
def getState(self): return [ self.fsm.getCurrentState().getName(), globalClockDelta.getRealNetworkTime() ]
def enterDisabled(self): self.sendUpdate('setState', ['Disabled', globalClockDelta.getRealNetworkTime()])
def setDNA(self, hatIdx, hatTexture, hatColor, glassesIdx, glassesTexture, glassesColor, backpackIdx, backpackTexture, backpackColor, shoesIdx, shoesTexture, shoesColor, finished, which): avId = self.air.getAvatarIdFromSender() if avId != self.avId: self.air.writeServerEvent( 'suspicious', avId, 'Tried to set DNA from closet while not using it!') return av = self.air.doId2do.get(avId) if not av: self.air.writeServerEvent( 'suspicious', avId, 'Interacted with a closet from another shard!') return if not self.__verifyAvatarInMyZone(av): self.air.writeServerEvent( 'suspicious', avId, 'Tried to setDNA while in another zone!') return if not finished: # They changed one of their accessories. if which == HAT: av.b_setHat(hatIdx, hatTexture, hatColor) if which == GLASSES: av.b_setGlasses(glassesIdx, glassesTexture, glassesColor) if which == BACKPACK: av.b_setBackpack(backpackIdx, backpackTexture, backpackColor) if which == SHOES: av.b_setShoes(shoesIdx, shoesTexture, shoesColor) elif finished == 1: # The user pressed the cancel button. All we need to do is free him. # Reset the removed items and our user. av.b_setHat(hatIdx, hatTexture, hatColor) av.b_setGlasses(glassesIdx, glassesTexture, glassesColor) av.b_setBackpack(backpackIdx, backpackTexture, backpackColor) av.b_setShoes(shoesIdx, shoesTexture, shoesColor) self.removedHats = [] self.removedGlasses = [] self.removedBackpacks = [] self.removedShoes = [] self.avId = None # Free the user. self.d_setMovie(ClosetGlobals.CLOSET_MOVIE_COMPLETE, avId, globalClockDelta.getRealNetworkTime()) self.resetMovie() self.setState(ClosetGlobals.CLOSED, 0, self.furnitureMgr.ownerId, self.gender, self.hatList, self.glassesList, self.backpackList, self.shoesList) elif finished == 2: # They are done using the trunk. Update their removed items. # Is the user actually the owner? if avId != self.furnitureMgr.ownerId: self.air.writeServerEvent( 'suspicious', avId, 'Tried to set their clothes from somebody else\'s closet!') return # Put on the accessories they want... if which & HAT: av.b_setHat(hatIdx, hatTexture, hatColor) if which & GLASSES: av.b_setGlasses(glassesIdx, glassesTexture, glassesColor) if which & BACKPACK: av.b_setBackpack(backpackIdx, backpackTexture, backpackColor) if which & SHOES: av.b_setShoes(shoesIdx, shoesTexture, shoesColor) # Delete all their items they want to be deleted... for hat in self.removedHats: id, texture, color = hat av.removeItemInAccessoriesList(HAT, id, texture, color) for glasses in self.removedGlasses: id, texture, color = glasses av.removeItemInAccessoriesList(GLASSES, id, texture, color) for backpack in self.removedBackpacks: id, texture, color = backpack av.removeItemInAccessoriesList(BACKPACK, id, texture, color) for shoe in self.removedShoes: id, texture, color = shoe av.removeItemInAccessoriesList(SHOES, id, texture, color) # Regenerate the available accessories... self.removedHats = [] self.removedGlasses = [] self.removedBackpacks = [] self.removedShoes = [] self.generate() self.avId = None # We are done, free the user! self.d_setMovie(ClosetGlobals.CLOSET_MOVIE_COMPLETE, avId, globalClockDelta.getRealNetworkTime()) self.resetMovie() self.setState(ClosetGlobals.CLOSED, 0, self.furnitureMgr.ownerId, self.gender, self.hatList, self.glassesList, self.backpackList, self.shoesList)
def setDNA(self, dnaString, finished, whichItem): avId = self.air.getAvatarIdFromSender() if avId != self.avId: self.air.writeServerEventMessage('suspicious', avId, 'Tried to set DNA from closet while not using it!') return av = self.air.doId2do.get(avId) if not av: self.air.writeServerEventMessage('suspicious', avId, 'Interacted with a closet from another shard!') return if not self.__verifyAvatarInMyZone(av): self.air.writeServerEventMessage('suspicious', avId, 'Tried to setDNA while in another zone!') return testDna = ToonDNA() if not testDna.isValidNetString(dnaString): self.air.writeServerEventMessage('suspicious', avId, 'Tried to set invalid DNA at a closet!') return if not finished: testDna.makeFromNetString(dnaString) if not self.__checkValidDNAChange(av, testDna): self.air.writeServerEventMessage('suspicious', avId, 'Tried to change their DNA temporarily!') return self.sendUpdate('setCustomerDNA', [avId, dnaString]) return elif finished == 1: self.d_setMovie(ClosetGlobals.CLOSET_MOVIE_COMPLETE, avId, globalClockDelta.getRealNetworkTime()) self.resetMovie() self.d_setState(ClosetGlobals.CLOSED, 0, self.furnitureMgr.ownerId, self.gender, self.topList, self.botList) av.b_setDNAString(self.customerDNA.makeNetString()) self.removedBottoms = [] self.removedTops = [] self.customerDNA = None self.avId = None elif finished == 2: if avId != self.furnitureMgr.ownerId: self.air.writeServerEventMessage('suspicious', avId, 'Tried to set their clothes from somebody else\'s closet!') return testDna.makeFromNetString(dnaString) if whichItem & ClosetGlobals.SHIRT: success = av.replaceItemInClothesTopsList(testDna.topTex, testDna.topTexColor, testDna.sleeveTex, testDna.sleeveTexColor, self.customerDNA.topTex, self.customerDNA.topTexColor, self.customerDNA.sleeveTex, self.customerDNA.sleeveTexColor) if success: self.customerDNA.topTex = testDna.topTex self.customerDNA.topTexColor = testDna.topTexColor self.customerDNA.sleeveTex = testDna.sleeveTex self.customerDNA.sleeveTexColor = testDna.sleeveTexColor else: self.air.writeServerEventMessage('suspicious', avId, 'Tried to set their shirt to a shirt they don\'t own!') if whichItem & ClosetGlobals.SHORTS: success = av.replaceItemInClothesBottomsList(testDna.botTex, testDna.botTexColor, self.customerDNA.botTex, self.customerDNA.botTexColor) if success: self.customerDNA.botTex = testDna.botTex self.customerDNA.botTexColor = testDna.botTexColor if self.customerDNA.torso != testDna.torso: if self.customerDNA.gender == 'm': self.air.writeServerEventMessage('suspicious', avId, 'Tried to change their torso size!') return elif self.customerDNA.torso[0] != testDna.torso[0]: self.air.writeServerEventMessage('suspicious', avId, 'Tried to change their torso size!') return self.customerDNA.torso = testDna.torso else: self.air.writeServerEventMessage('suspicious', avId, 'Tried to set their shorts to a pair they don\'t own!') for bottom in self.removedBottoms: botTex, botTexColor = bottom success = av.removeItemInClothesBottomsList(botTex, botTexColor) if not success: self.air.writeServerEventMessage('suspicious', avId, 'Tried to remove a bottom they didn\'t have!') for top in self.removedTops: topTex, topTexColor, sleeveTex, sleeveTexColor = top success = av.removeItemInClothesTopsList(topTex, topTexColor, sleeveTex, sleeveTexColor) if not success: self.air.writeServerEventMessage('suspicious', avId, 'Tried to remove a top they didn\'t have!') av.b_setDNAString(self.customerDNA.makeNetString()) av.b_setClothesTopsList(av.getClothesTopsList()) av.b_setClothesBottomsList(av.getClothesBottomsList()) self.topList = av.getClothesTopsList() self.botList = av.getClothesBottomsList() self.removedBottoms = [] self.removedTops = [] self.d_setMovie(ClosetGlobals.CLOSET_MOVIE_COMPLETE, avId, globalClockDelta.getRealNetworkTime()) self.resetMovie() self.d_setState(ClosetGlobals.CLOSED, 0, self.furnitureMgr.ownerId, self.gender, self.topList, self.botList) self.customerDNA = None self.avId = None
def handleRequestExit(self, avatar): self.d_setMovie(PiratesGlobals.DOOR_CLOSED, avatar.doId, globalClockDelta.getRealNetworkTime(bits=16)) return self.ACCEPT
def d_setState(self, state, data=0): self.sendUpdate('setState', [state, globalClockDelta.getRealNetworkTime(), data])
def setState(self, state, data=[0]): self.state = state self.sendUpdate("setState", [state, globalClockDelta.getRealNetworkTime(), data])
def setDNA(self, dnaString, finished, whichItem): avId = self.air.getAvatarIdFromSender() if avId != self.avId: self.air.writeServerEvent( 'suspicious', avId, 'Tried to set DNA from closet while not using it!') return av = self.air.doId2do.get(avId) if not av: self.air.writeServerEvent( 'suspicious', avId, 'Interacted with a closet from another shard!') return if not self.__verifyAvatarInMyZone(av): self.air.writeServerEvent( 'suspicious', avId, 'Tried to setDNA while in another zone!') return testDna = ToonDNA() if not testDna.isValidNetString(dnaString): self.air.writeServerEvent('suspicious', avId, 'Tried to set invalid DNA at a closet!') return if not finished: testDna.makeFromNetString(dnaString) if not self.__checkValidDNAChange(av, testDna): self.air.writeServerEvent( 'suspicious', avId, 'Tried to change their DNA temporarily!') return self.sendUpdate('setCustomerDNA', [avId, dnaString]) return if finished == 1: self.d_setMovie(ClosetGlobals.CLOSET_MOVIE_COMPLETE, avId, globalClockDelta.getRealNetworkTime()) self.resetMovie() self.d_setState(ClosetGlobals.CLOSED, 0, self.furnitureMgr.ownerId, self.gender, self.topList, self.botList) av.b_setDNAString(self.customerDNA.makeNetString()) self.removedBottoms = [] self.removedTops = [] self.customerDNA = None self.avId = None elif finished == 2: if avId != self.furnitureMgr.ownerId: self.air.writeServerEvent( 'suspicious', avId, "Tried to set their clothes from somebody else's closet!") return testDna.makeFromNetString(dnaString) if whichItem & ClosetGlobals.SHIRT: success = av.replaceItemInClothesTopsList( testDna.topTex, testDna.topTexColor, testDna.sleeveTex, testDna.sleeveTexColor, self.customerDNA.topTex, self.customerDNA.topTexColor, self.customerDNA.sleeveTex, self.customerDNA.sleeveTexColor) if success: self.customerDNA.topTex = testDna.topTex self.customerDNA.topTexColor = testDna.topTexColor self.customerDNA.sleeveTex = testDna.sleeveTex self.customerDNA.sleeveTexColor = testDna.sleeveTexColor else: self.air.writeServerEvent( 'suspicious', avId, "Tried to set their shirt to a shirt they don't own!") if whichItem & ClosetGlobals.SHORTS: success = av.replaceItemInClothesBottomsList( testDna.botTex, testDna.botTexColor, self.customerDNA.botTex, self.customerDNA.botTexColor) if success: self.customerDNA.botTex = testDna.botTex self.customerDNA.botTexColor = testDna.botTexColor if self.customerDNA.torso != testDna.torso: if self.customerDNA.gender == 'm': self.air.writeServerEvent( 'suspicious', avId, 'Tried to change their torso size!') return if self.customerDNA.torso[0] != testDna.torso[0]: self.air.writeServerEvent( 'suspicious', avId, 'Tried to change their torso size!') return self.customerDNA.torso = testDna.torso else: self.air.writeServerEvent( 'suspicious', avId, "Tried to set their shorts to a pair they don't own!") for bottom in self.removedBottoms: botTex, botTexColor = bottom success = av.removeItemInClothesBottomsList( botTex, botTexColor) if not success: self.air.writeServerEvent( 'suspicious', avId, "Tried to remove a bottom they didn't have!") for top in self.removedTops: topTex, topTexColor, sleeveTex, sleeveTexColor = top success = av.removeItemInClothesTopsList( topTex, topTexColor, sleeveTex, sleeveTexColor) if not success: self.air.writeServerEvent( 'suspicious', avId, "Tried to remove a top they didn't have!") av.b_setDNAString(self.customerDNA.makeNetString()) av.b_setClothesTopsList(av.getClothesTopsList()) av.b_setClothesBottomsList(av.getClothesBottomsList()) self.topList = av.getClothesTopsList() self.botList = av.getClothesBottomsList() self.removedBottoms = [] self.removedTops = [] self.d_setMovie(ClosetGlobals.CLOSET_MOVIE_COMPLETE, avId, globalClockDelta.getRealNetworkTime()) self.resetMovie() self.d_setState(ClosetGlobals.CLOSED, 0, self.furnitureMgr.ownerId, self.gender, self.topList, self.botList) self.customerDNA = None self.avId = None
def requestServerTime(self, context): self.sendUpdateToAvatarId(self.air.getAvatarIdFromSender(), 'serverTime', [context, globalClockDelta.getRealNetworkTime(bits=32), int(time.time())])
def d_setMovie(self, mode, avId): self.sendUpdate( 'setMovie', [mode, avId, globalClockDelta.getRealNetworkTime(bits=32)])
def __init__(self, air): DistributedKartPadAI.__init__(self, air) self.lastEntered = globalClockDelta.getRealNetworkTime()
def __networkTimeInSeconds(self): time = globalClockDelta.getRealNetworkTime(bits=32) / NetworkTimePrecision return time
def handleRequestInteraction(self, avatar, interactType, instant): self.d_setMovie(PiratesGlobals.DOOR_OPEN, avatar.doId, globalClockDelta.getRealNetworkTime(bits=16)) return self.ACCEPT