def showChanceRewards(self): tasks = [] for reward in self.rewardList: self.notify.debug('showChanceRewards: reward = ' + str(reward)) index = self.rewardList.index(reward) if reward != -1: self.notify.debug('adding tasks!') hcc = Task(self.hideChanceMarker) hcc.chanceMarkers = self.chanceMarkers hcc.index = index sct = Task(self.showChanceCard) sct.chanceCard = self.chanceCard sct.cardSound = self.cardSound stt = Task(self.showChanceCardText) rewardEntry = RaceGameGlobals.ChanceRewards[reward] stt.rewardIdx = reward if rewardEntry[0][0] < 0 or rewardEntry[0][1] > 0: stt.sound = self.negBuzzer else: stt.sound = self.posBuzzer stt.picker = self.avIdList[index] rct = Task(self.resetChanceCard) task = Task.sequence(hcc, sct, Task.pause(1.0), stt, Task.pause(3.0), rct, Task.pause(0.25)) tasks.append(task) return tasks
def __startIntro(self): self.T_WATER = 1 self.T_WATER2LONGVIEW = 1 self.T_LONGVIEW = 1 self.T_LONGVIEW2TOONHEAD = 2 self.T_TOONHEAD = 2 self.T_TOONHEAD2CANNONBACK = 2 self.__introCameraInterval = None taskLookInWater = Task(self.__taskLookInWater) taskPullBackFromWater = Task(self.__taskPullBackFromWater) taskFlyUpToToon = Task(self.__flyUpToToon) taskFlyToBackOfCannon = Task(self.__flyToBackOfCannon) commonData = {} taskLookInWater.data = commonData taskPullBackFromWater.data = commonData taskFlyUpToToon.data = commonData taskFlyToBackOfCannon.data = commonData introTask = Task.sequence( taskLookInWater, Task.pause(self.T_WATER), taskPullBackFromWater, Task.pause(self.T_WATER2LONGVIEW + self.T_LONGVIEW), taskFlyUpToToon, Task.pause(self.T_LONGVIEW2TOONHEAD + self.T_TOONHEAD), taskFlyToBackOfCannon, ) taskMgr.add(introTask, self.INTRO_TASK_NAME)
def updateHealthBar(self, hp, forceUpdate = 0): if hp > self.currHP: hp = self.currHP self.currHP -= hp health = float(self.currHP) / float(self.maxHP) if health > 0.95: condition = 0 elif health > 0.7: condition = 1 elif health > 0.3: condition = 2 elif health > 0.05: condition = 3 elif health > 0.0: condition = 4 else: condition = 5 if self.healthCondition != condition or forceUpdate: if condition == 4: blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.uniqueName('blink-task')) elif condition == 5: if self.healthCondition == 4: taskMgr.remove(self.uniqueName('blink-task')) blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.25), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.uniqueName('blink-task')) else: self.healthBar.setColor(self.healthColors[condition], 1) self.healthBarGlow.setColor(self.healthGlowColors[condition], 1) self.healthCondition = condition
def updateHealthBar(self, hp): if not self.healthBar: return if hp > self.health: self.health = hp health = 0.0 try: health = float(hp) / float(self.maxHealth) except: pass if health > 0.95: condition = 0 elif health > 0.7: condition = 1 elif health > 0.3: condition = 2 elif health > 0.05: condition = 3 elif health > 0.0: condition = 4 else: condition = 5 if self.condition != condition: taskMgr.remove(self.taskName('blink-task')) if condition == 4: blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.taskName('blink-task')) elif condition == 5: blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.25), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.taskName('blink-task')) else: self.healthBar.setColor(SuitGlobals.healthColors[condition], 1) self.healthBarGlow.setColor(SuitGlobals.healthGlowColors[condition], 1) self.condition = condition
def updateHealthBar(self): if self.healthBar == None: return health = 1.0 - float(self.bossDamage) / float(self.bossMaxDamage) if health > 0.95: condition = 0 elif health > 0.7: condition = 1 elif health > 0.3: condition = 2 elif health > 0.05: condition = 3 elif health > 0.0: condition = 4 else: condition = 5 if self.healthCondition != condition: if condition == 4: blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.uniqueName('blink-task')) elif condition == 5: if self.healthCondition == 4: taskMgr.remove(self.uniqueName('blink-task')) blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.25), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.uniqueName('blink-task')) else: self.healthBar.setColor(self.healthColors[condition], 1) self.healthBarGlow.setColor(self.healthGlowColors[condition], 1) self.healthCondition = condition return
def updateHealthBar(self): if self.healthBar == None: return health = 1.0 - float(self.bossDamage) / float(self.bossMaxDamage) if health > 0.95: condition = 0 elif health > 0.7: condition = 1 elif health > 0.3: condition = 2 elif health > 0.05: condition = 3 elif health > 0.0: condition = 4 else: condition = 5 if self.healthCondition != condition: if condition == 4: blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.uniqueName('blink-task')) elif condition == 5: if self.healthCondition == 4: taskMgr.remove(self.uniqueName('blink-task')) blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.25), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.uniqueName('blink-task')) else: self.healthBar.setColor(self.healthColors[condition], 1) self.healthBarGlow.setColor(self.healthGlowColors[condition], 1) self.healthCondition = condition return
def updateHealthBar(self, hp, forceUpdate = 0): if hp > self.currHP: hp = self.currHP self.currHP -= hp health = float(self.currHP) / float(self.maxHP) if health > 0.95: condition = 0 elif health > 0.7: condition = 1 elif health > 0.3: condition = 2 elif health > 0.05: condition = 3 elif health > 0.0: condition = 4 else: condition = 5 if self.healthCondition != condition or forceUpdate: if condition == 4: blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.uniqueName('blink-task')) elif condition == 5: if self.healthCondition == 4: taskMgr.remove(self.uniqueName('blink-task')) blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.25), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.uniqueName('blink-task')) else: self.healthBar.setColor(self.healthColors[condition], 1) self.healthBarGlow.setColor(self.healthGlowColors[condition], 1) self.healthCondition = condition
def __startIntro(self): self.T_WATER = 1 self.T_WATER2LONGVIEW = 1 self.T_LONGVIEW = 1 self.T_LONGVIEW2TOONHEAD = 2 self.T_TOONHEAD = 2 self.T_TOONHEAD2CANNONBACK = 2 self.__cameraLookAtInterval = None taskLookInWater = Task(self.__taskLookInWater) taskPullBackFromWater = Task(self.__taskPullBackFromWater) taskFlyUpToToon = Task(self.__flyUpToToon) taskFlyToBackOfCannon = Task(self.__flyToBackOfCannon) commonData = {} taskLookInWater.data = commonData taskPullBackFromWater.data = commonData taskFlyUpToToon.data = commonData taskFlyToBackOfCannon.data = commonData introTask = Task.sequence( taskLookInWater, Task.pause(self.T_WATER), taskPullBackFromWater, Task.pause(self.T_WATER2LONGVIEW + self.T_LONGVIEW), taskFlyUpToToon, Task.pause(self.T_LONGVIEW2TOONHEAD + self.T_TOONHEAD), taskFlyToBackOfCannon) taskMgr.add(introTask, self.INTRO_TASK_NAME) return
def doSpawnTitleText(self, text): self.titleColor = (1.0, 0.5, 0.4, 1.0) self.titleText = OnscreenText.OnscreenText( text, fg = self.titleColor, font = ToontownGlobals.getSignFont(), pos = (0,-0.5), scale = 0.16, drawOrder = 0, mayChange = 1, wordwrap = 16 ) self.titleText.setText(text) self.titleText.show() self.titleText.setColor(Vec4(*self.titleColor)) self.titleText.clearColorScale() self.titleText.setFg(self.titleColor) seq = Task.sequence( # HACK! Let a pause go by to cover the loading pause # This tricks the taskMgr Task.pause(0.1), Task.pause(6.0), self.titleText.lerpColorScale( Vec4(1.0, 1.0, 1.0, 1.0), Vec4(1.0, 1.0, 1.0, 0.0), 0.5), Task(self.hideTitleTextTask)) taskMgr.add(seq, "titleText")
def showChanceRewards(self): tasks = [] for reward in self.rewardList: self.notify.debug('showChanceRewards: reward = ' + str(reward)) index = self.rewardList.index(reward) if reward != -1: self.notify.debug('adding tasks!') hcc = Task(self.hideChanceMarker) hcc.chanceMarkers = self.chanceMarkers hcc.index = index sct = Task(self.showChanceCard) sct.chanceCard = self.chanceCard sct.cardSound = self.cardSound stt = Task(self.showChanceCardText) rewardEntry = RaceGameGlobals.ChanceRewards[reward] stt.rewardIdx = reward if rewardEntry[0][0] < 0 or rewardEntry[0][1] > 0: stt.sound = self.negBuzzer else: stt.sound = self.posBuzzer stt.picker = self.avIdList[index] rct = Task(self.resetChanceCard) task = Task.sequence(hcc, sct, Task.pause(1.0), stt, Task.pause(3.0), rct, Task.pause(0.25)) tasks.append(task) return tasks
def doSpawnTitleText(self, text): self.titleText.setText(text) self.titleText.show() self.titleText.setColor(Vec4(*self.titleColor)) self.titleText.clearColorScale() self.titleText.setFg(self.titleColor) seq = Task.sequence(Task.pause(0.1), Task.pause(6.0), self.titleText.lerpColorScale(Vec4(1.0, 1.0, 1.0, 1.0), Vec4(1.0, 1.0, 1.0, 0.0), 0.5), Task(self.hideTitleTextTask)) taskMgr.add(seq, 'titleText')
def doSpawnTitleText(self, text): self.titleText.setText(text) self.titleText.show() self.titleText.setColor(Vec4(*self.titleColor)) self.titleText.clearColorScale() self.titleText.setFg(self.titleColor) seq = Task.sequence(Task.pause(0.10000000000000001), Task.pause(6.0), self.titleText.lerpColorScale(Vec4(1.0, 1.0, 1.0, 1.0), Vec4(1.0, 1.0, 1.0, 0.0), 0.5), Task(self.hideTitleTextTask)) taskMgr.add(seq, 'titleText')
def doSpawnTitleText(self, text): self.titleColor = (1.0, 0.5, 0.4, 1.0) self.titleText = OnscreenText.OnscreenText(text, fg=self.titleColor, font=ToontownGlobals.getSignFont(), pos=(0, -0.5), scale=0.16, drawOrder=0, mayChange=1, wordwrap=16) self.titleText.setText(text) self.titleText.show() self.titleText.setColor(Vec4(*self.titleColor)) self.titleText.clearColorScale() self.titleText.setFg(self.titleColor) seq = Task.sequence(Task.pause(0.1), Task.pause(6.0), self.titleText.lerpColorScale(Vec4(1.0, 1.0, 1.0, 1.0), Vec4(1.0, 1.0, 1.0, 0.0), 0.5), Task(self.hideTitleTextTask)) taskMgr.add(seq, 'titleText')
def updateHealthBar(self): condition = self.cog.healthCondition if condition == 4: self.blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75), Task.pause(0.1)) taskMgr.add(self.blinkTask, self.uniqueName('blink-task')) else: taskMgr.remove(self.uniqueName('blink-task')) self.button.setColor(self.healthColors[condition], 1) self.glow.setColor(self.healthGlowColors[condition], 1)
def updateHealthBar(self): if not self.suit: return self.setHp(self.suit.getHP()) health = float(self.currHP) / float(self.maxHP) if health > 0.95: condition = 0 elif health > 0.9: condition = 1 elif health > 0.8: condition = 2 elif health > 0.7: condition = 3 #Yellow elif health > 0.6: condition = 4 elif health > 0.5: condition = 5 elif health > 0.3: condition = 6 #Orange elif health > 0.15: condition = 7 elif health > 0.05: condition = 8 #Red elif health > 0.0: condition = 9 #Blinking Red else: condition = 10 if self.healthCondition != condition: if condition == 9: self.blinkTask = self.uniqueName('blink-task') blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.blinkTask) elif condition == 10: if self.healthCondition == 9: self.blinkTask = self.uniqueName('blink-task') taskMgr.remove(self.blinkTask) self.blinkTask = None blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.25), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.blinkTask) else: if self.blinkTask: taskMgr.remove(self.blinkTask) self.blinkTask = None self.healthBar.setColor(self.healthColors[condition], 1) self.healthBarGlow.setColor(self.healthGlowColors[condition], 1) self.healthCondition = condition
def doSpawnTitleText(self, text): self.titleText.setText(text) self.titleText.show() self.titleText.setColor(Vec4(*self.titleColor)) self.titleText.clearColorScale() self.titleText.setFg(self.titleColor) seq = Task.sequence( # HACK! Let a pause go by to cover the loading pause # This tricks the taskMgr Task.pause(0.1), Task.pause(6.0), self.titleText.lerpColorScale(Vec4(1.0, 1.0, 1.0, 1.0), Vec4(1.0, 1.0, 1.0, 0.0), 0.5), Task(self.hideTitleTextTask)) taskMgr.add(seq, "titleText")
def setCannonWillFire(self, avId, fireTime, zRot, angle): if not self.hasLocalToon: return if not self.__playing(): return self.notify.debug( "setCannonWillFire: " + str(avId) + ": zRot=" + str(zRot) + ", angle=" + str(angle) + ", time=" + str(fireTime) ) self.cannonPositionDict[avId][0] = zRot self.cannonPositionDict[avId][1] = angle self.__updateCannonPosition(avId) task = Task(self.__fireCannonTask) task.avId = avId task.fireTime = fireTime timeToWait = task.fireTime - self.getCurrentGameTime() if timeToWait > 0.0: fireTask = Task.sequence(Task.pause(timeToWait), task) else: fireTask = task fireTask = task taskMgr.add(fireTask, "fireCannon" + str(avId)) self.airborneToons += 1
def _DistributedCannonGame__fireCannonTask(self, task): launchTime = task.fireTime avId = task.avId self.notify.debug('FIRING CANNON FOR AVATAR ' + str(avId)) flightResults = self._DistributedCannonGame__calcFlightResults(avId, launchTime) if not isClient(): print 'EXECWARNING DistributedCannonGame: %s' % flightResults printStack() for key in flightResults: exec "%s = flightResults['%s']" % (key, key) self.notify.debug('start position: ' + str(startPos)) self.notify.debug('start velocity: ' + str(startVel)) self.notify.debug('time of launch: ' + str(launchTime)) self.notify.debug('time of impact: ' + str(timeOfImpact)) self.notify.debug('location of impact: ' + str(trajectory.getPos(timeOfImpact))) if hitWhat == self.HIT_WATER: self.notify.debug('toon will land in the water') elif hitWhat == self.HIT_TOWER: self.notify.debug('toon will hit the tower') else: self.notify.debug('toon will hit the ground') head = self.toonHeadDict[avId] head.stopBlink() head.stopLookAroundNow() head.reparentTo(hidden) av = self.toonModelDict[avId] av.reparentTo(render) av.setPos(startPos) av.setHpr(startHpr) avatar = self.getAvatar(avId) avatar.loop('swim') avatar.setPosHpr(0, 0, -(avatar.getHeight() / 2.0), 0, 0, 0) shootTask = Task(self._DistributedCannonGame__shootTask) flyTask = Task(self._DistributedCannonGame__flyTask) seqDoneTask = Task(self._DistributedCannonGame__flySequenceDoneTask) info = { } info['avId'] = avId info['trajectory'] = trajectory info['launchTime'] = launchTime info['timeOfImpact'] = timeOfImpact info['hitWhat'] = hitWhat info['toon'] = self.toonModelDict[avId] info['hRot'] = self.cannonPositionDict[avId][0] info['haveWhistled'] = 0 info['maxCamPullback'] = CAMERA_PULLBACK_MIN (info['timeEnterTowerXY'], info['timeExitTowerXY']) = trajectory.calcEnterAndLeaveCylinderXY(self.tower.getPos(render), TOWER_RADIUS) shootTask.info = info flyTask.info = info seqDoneTask.info = info seqTask = Task.sequence(shootTask, flyTask, Task.pause(LAND_TIME), seqDoneTask) taskMgr.add(seqTask, 'flyingToon' + str(avId)) if avId == self.localAvId: if info['hitWhat'] == self.HIT_WATER: self.sendUpdate('setToonWillLandInWater', [ info['timeOfImpact']]) return Task.done
def updateHealthBar(self): condition = self.cog.healthCondition if condition == 4: self.blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75), Task.pause(0.1)) taskMgr.add(self.blinkTask, self.uniqueName('blink-task')) else: taskMgr.remove(self.uniqueName('blink-task')) if not self.button.isEmpty(): self.button.setColor(self.healthColors[condition], 1) if not self.glow.isEmpty(): self.glow.setColor(self.healthGlowColors[condition], 1) self.hp = self.cog.getHP() self.maxHp = self.cog.getMaxHP() self.hpText['text'] = str(self.hp) + '/' + str(self.maxHp)
def enableInteractionButtons(self): self.notify.debug('enable buttons') proxTask = Task.loop(Task(self.__checkPetProximity), Task.pause(0.5)) taskMgr.add(proxTask, 'petpanel-proximity-check', priority=ToontownGlobals.PetPanelProximityPriority) self.__checkPetProximity()
def updateHealthBar(self): if not self.suit: return self.setHp(self.suit.getHP()) health = float(self.currHP) / float(self.maxHP) if health > 0.95: condition = 0 elif health > 0.9: condition = 1 elif health > 0.8: condition = 2 elif health > 0.7: condition = 3#Yellow elif health > 0.6: condition = 4 elif health > 0.5: condition = 5 elif health > 0.3: condition = 6#Orange elif health > 0.15: condition = 7 elif health > 0.05: condition = 8#Red elif health > 0.0: condition = 9#Blinking Red else: condition = 10 if self.healthCondition != condition: if condition == 9: self.blinkTask = self.uniqueName('blink-task') blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.blinkTask) elif condition == 10: if self.healthCondition == 9: self.blinkTask = self.uniqueName('blink-task') taskMgr.remove(self.blinkTask) self.blinkTask = None blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.25), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.blinkTask) else: if self.blinkTask: taskMgr.remove(self.blinkTask) self.blinkTask = None self.healthBar.setColor(self.healthColors[condition], 1) self.healthBarGlow.setColor(self.healthGlowColors[condition], 1) self.healthCondition = condition
def __fireCannonTask(self, task): launchTime = task.fireTime avId = task.avId self.notify.debug('FIRING CANNON FOR AVATAR ' + str(avId)) startPos, startHpr, startVel, trajectory, timeOfImpact, hitWhat = self.__calcFlightResults( avId, launchTime) self.notify.debug('start position: ' + str(startPos)) self.notify.debug('start velocity: ' + str(startVel)) self.notify.debug('time of launch: ' + str(launchTime)) self.notify.debug('time of impact: ' + str(timeOfImpact)) self.notify.debug('location of impact: ' + str(trajectory.getPos(timeOfImpact))) if hitWhat == self.HIT_WATER: self.notify.debug('toon will land in the water') elif hitWhat == self.HIT_TOWER: self.notify.debug('toon will hit the tower') else: self.notify.debug('toon will hit the ground') head = self.toonHeadDict[avId] head.stopBlink() head.stopLookAroundNow() head.reparentTo(hidden) av = self.toonModelDict[avId] av.reparentTo(render) av.setPos(startPos) av.setHpr(startHpr) avatar = self.getAvatar(avId) avatar.loop('swim') avatar.setPosHpr(0, 0, -(avatar.getHeight() / 2.0), 0, 0, 0) shootTask = Task(self.__shootTask) flyTask = Task(self.__flyTask) seqDoneTask = Task(self.__flySequenceDoneTask) info = {} info['avId'] = avId info['trajectory'] = trajectory info['launchTime'] = launchTime info['timeOfImpact'] = timeOfImpact info['hitWhat'] = hitWhat info['toon'] = self.toonModelDict[avId] info['hRot'] = self.cannonPositionDict[avId][0] info['haveWhistled'] = 0 info['maxCamPullback'] = CAMERA_PULLBACK_MIN info['timeEnterTowerXY'], info[ 'timeExitTowerXY'] = trajectory.calcEnterAndLeaveCylinderXY( self.tower.getPos(render), TOWER_RADIUS) shootTask.info = info flyTask.info = info seqDoneTask.info = info seqTask = Task.sequence(shootTask, flyTask, Task.pause(LAND_TIME), seqDoneTask) taskMgr.add(seqTask, 'flyingToon' + str(avId)) if avId == self.localAvId: if info['hitWhat'] == self.HIT_WATER: self.sendUpdate('setToonWillLandInWater', [info['timeOfImpact']]) return Task.done
def update(self, hp, forceUpdate=0): if not self.geom: return condition = self.getHealthCondition(hp) if self.healthCondition != condition or forceUpdate: taskMgr.remove('blink-task-%s' % id(self)) if condition in (9, 10): blinkTask = Task.loop( Task(self.__blinkRed), Task.pause(0.75 if condition == 9 else 0.25), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, 'blink-task-%s' % id(self)) else: self.geom.setColor(HEALTH_COLORS[condition], 1) self.geomGlow.setColor(HEALTH_GLOW_COLORS[condition], 1) self.healthCondition = condition
def updateHealthBar(self): health = float(float(self.hp) / float(self.maxHp)) if health < 1: self.corpMedallion.hide() self.healthBar.show() if health > 0.95: condition = 0 elif health > 0.7: condition = 1 elif health > 0.3: condition = 2 elif health > 0.05: condition = 3 elif health > 0: condition = 4 else: condition = 5 if (self.healthCondition != condition): if (condition == 4): blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75), Task(self.__blinkGray), Task.pause(0.1)) base.taskMgr.add(blinkTask, 'blink-task') elif (condition == 5): if (self.healthCondition == 4): base.taskMgr.remove('blink-task') if (self.isDefeated == False): blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.25), Task(self.__blinkGray), Task.pause(0.1)) base.taskMgr.add(blinkTask, 'blink-task') self.isDefeated = True if not self.cog.hasPythonTag("Support"): roundInstance = render.getPythonTag('Round') wave = roundInstance.getCurrentWave() wave.setCogsDefeated(wave.getCogsDefeated() + 1) base.taskMgr.doMethodLater(1.5, self.setDefeated, 'Set Cog Defeated') else: self.healthBar.setColor(healthColors[condition], 1) self.healthBarGlow.setColor(healthGlowColors[condition], 1) self.healthCondition = condition
def __checkUpdateColor(self, hp, maxhp): if self.bossBar: self.healthRatio = float(hp) / float(maxhp) if self.healthRatio > self.colorThresholds[0]: condition = 0 elif self.healthRatio > self.colorThresholds[1]: condition = 1 elif self.healthRatio > self.colorThresholds[2]: condition = 2 elif self.healthRatio > self.colorThresholds[3]: condition = 3 elif self.healthRatio > self.colorThresholds[4]: condition = 4 else: condition = 5 self.__applyNewColor(condition) if self.healthCondition != condition: if condition == 4: if self.healthCondition == 5: taskMgr.remove('bar-blink-task') self.isBlinking = False blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, 'bar-blink-task') self.isBlinking = True elif condition == 5: if self.healthCondition == 4: taskMgr.remove('bar-blink-task') self.isBlinking = False blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.25), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, 'bar-blink-task') self.isBlinking = True else: if self.isBlinking: taskMgr.remove('bar-blink-task') self.isBlinking = False self.healthCondition = condition
def updateHealthBar(self): if self.healthBar == None: return health = 1.0 - float(self.bossDamage) / float(self.bossMaxDamage) if health > 0.95: condition = 0 elif health > 0.9: condition = 1 elif health > 0.8: condition = 2 elif health > 0.7: condition = 3 #Yellow elif health > 0.6: condition = 4 elif health > 0.5: condition = 5 elif health > 0.3: condition = 6 #Orange elif health > 0.15: condition = 7 elif health > 0.05: condition = 8 #Red elif health > 0.0: condition = 9 #Blinking Red else: condition = 10 if self.healthCondition != condition: if condition == 9: blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.uniqueName('blink-task')) elif condition == 10: if self.healthCondition == 9: taskMgr.remove(self.uniqueName('blink-task')) blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.25), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.uniqueName('blink-task')) else: self.healthBar.setColor(self.healthColors[condition], 1) self.healthBarGlow.setColor(self.healthGlowColors[condition], 1) self.healthCondition = condition
def updateHealthBar(self, hp, forceUpdate=0): if (hp > self.currHP): hp = self.currHP self.currHP -= hp health = float(self.currHP) / float(self.maxHP) if (health > 0.95): condition = 0 elif (health > 0.7): condition = 1 elif (health > 0.3): condition = 2 elif (health > 0.05): condition = 3 elif (health > 0.0): # This should be blinking red condition = 4 else: # This should be blinking red even faster condition = 5 if (self.healthCondition != condition) or forceUpdate: if (condition == 4): blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.uniqueName('blink-task')) elif (condition == 5): if (self.healthCondition == 4): taskMgr.remove(self.uniqueName('blink-task')) blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.25), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.uniqueName('blink-task')) else: self.healthBar.setColor(self.healthColors[condition], 1) self.healthBarGlow.setColor(self.healthGlowColors[condition], 1) self.healthCondition = condition
def update(self, health, maxHealth): if self.isUpdating: taskMgr.remove('bar-smooth-update-task') self.isUpdating = False self.newHealth = health if self.newhealth < 0: self.newhealth = 0 if self.maxHealth != 0: if self.currentHealth != self.newHealth: smoothUpdateTask = Task.loop(Task(self.__smoothUpdate), Task.pause(0.01)) taskMgr.add(smoothUpdateTask, 'bar-smooth-update-task') self.isUpdating = True
def __fireCannonTask(self, task): launchTime = task.fireTime avId = task.avId self.notify.debug("FIRING CANNON FOR AVATAR " + str(avId)) startPos, startHpr, startVel, trajectory, timeOfImpact, hitWhat = self.__calcFlightResults(avId, launchTime) self.notify.debug("start position: " + str(startPos)) self.notify.debug("start velocity: " + str(startVel)) self.notify.debug("time of launch: " + str(launchTime)) self.notify.debug("time of impact: " + str(timeOfImpact)) self.notify.debug("location of impact: " + str(trajectory.getPos(timeOfImpact))) if hitWhat == self.HIT_WATER: self.notify.debug("toon will land in the water") elif hitWhat == self.HIT_TOWER: self.notify.debug("toon will hit the tower") else: self.notify.debug("toon will hit the ground") head = self.toonHeadDict[avId] head.stopBlink() head.stopLookAroundNow() head.reparentTo(hidden) av = self.toonModelDict[avId] av.reparentTo(render) av.setPos(startPos) av.setHpr(startHpr) avatar = self.getAvatar(avId) avatar.loop("swim") avatar.setPosHpr(0, 0, -(avatar.getHeight() / 2.0), 0, 0, 0) shootTask = Task(self.__shootTask) flyTask = Task(self.__flyTask) seqDoneTask = Task(self.__flySequenceDoneTask) info = {} info["avId"] = avId info["trajectory"] = trajectory info["launchTime"] = launchTime info["timeOfImpact"] = timeOfImpact info["hitWhat"] = hitWhat info["toon"] = self.toonModelDict[avId] info["hRot"] = self.cannonPositionDict[avId][0] info["haveWhistled"] = 0 info["maxCamPullback"] = CAMERA_PULLBACK_MIN info["timeEnterTowerXY"], info["timeExitTowerXY"] = trajectory.calcEnterAndLeaveCylinderXY( self.tower.getPos(render), TOWER_RADIUS ) shootTask.info = info flyTask.info = info seqDoneTask.info = info seqTask = Task.sequence(shootTask, flyTask, Task.pause(LAND_TIME), seqDoneTask) taskMgr.add(seqTask, "flyingToon" + str(avId)) if avId == self.localAvId: if info["hitWhat"] == self.HIT_WATER: self.sendUpdate("setToonWillLandInWater", [info["timeOfImpact"]]) return Task.done
def updateHealthBar(self): if self.healthBar == None: return health = 1.0 - float(self.bossDamage) / float(self.bossMaxDamage) if health > 0.95: condition = 0 elif health > 0.9: condition = 1 elif health > 0.8: condition = 2 elif health > 0.7: condition = 3#Yellow elif health > 0.6: condition = 4 elif health > 0.5: condition = 5 elif health > 0.3: condition = 6#Orange elif health > 0.15: condition = 7 elif health > 0.05: condition = 8#Red elif health > 0.0: condition = 9#Blinking Red else: condition = 10 if self.healthCondition != condition: if condition == 9: blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.uniqueName('blink-task')) elif condition == 10: if self.healthCondition == 9: taskMgr.remove(self.uniqueName('blink-task')) blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.25), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.uniqueName('blink-task')) else: self.healthBar.setColor(self.healthColors[condition], 1) self.healthBarGlow.setColor(self.healthGlowColors[condition], 1) self.healthCondition = condition
def update(self, hp, maxHp): if self.isUpdating: taskMgr.remove('bar-smooth-update-task') self.isUpdating = False self.newHp = hp if self.newHp < 0: self.newHp = 0 if self.maxHp != 0: if self.currHp != self.newHp: smoothUpdateTask = Task.loop(Task(self.__smoothUpdate), Task.pause(0.01)) taskMgr.add(smoothUpdateTask, 'bar-smooth-update-task') self.isUpdating = True
def showChanceRewards(self): # modify avatar positions for each chance card tasks = [] for reward in self.rewardList: self.notify.debug("showChanceRewards: reward = " + str(reward)) index = self.rewardList.index(reward) # if an actual reward is present in the list if (reward != -1): self.notify.debug("adding tasks!") # hide the chance marker hcc = Task(self.hideChanceMarker) hcc.chanceMarkers = self.chanceMarkers hcc.index = index # create the tasks to display the card sct = Task(self.showChanceCard) sct.chanceCard = self.chanceCard sct.cardSound = self.cardSound stt = Task(self.showChanceCardText) rewardEntry = RaceGameGlobals.ChanceRewards[reward] stt.rewardIdx = reward # decide if its a good or bad reward based on movement # might be better to flag each one individually in the defns if ((rewardEntry[0][0] < 0) or (rewardEntry[0][1] > 0)): stt.sound = self.negBuzzer else: stt.sound = self.posBuzzer stt.picker = self.avIdList[index] rct = Task(self.resetChanceCard) task = Task.sequence( hcc, sct, Task.pause(1.0), stt, Task.pause(3.0), rct, Task.pause(0.25), ) tasks.append(task) return tasks
def enterMoveAvatars(self, choiceList, positionList, rewardList): self.notify.debug('in enterMoveAvatars:') tasks = [] self.avatarPositionsCopy = self.avatarPositions.copy() for i in range(0, len(choiceList) / self.numPlayers): startIndex = i * self.numPlayers endIndex = startIndex + self.numPlayers self.choiceList = choiceList[startIndex:endIndex] self.positionList = positionList[startIndex:endIndex] self.rewardList = rewardList[startIndex:endIndex] self.notify.debug(' turn: ' + str(i + 1)) self.notify.debug(' choiceList: ' + str(self.choiceList)) self.notify.debug(' positionList: ' + str(self.positionList)) self.notify.debug(' rewardList: ' + str(self.rewardList)) longestLerpTime = self.getLongestLerpTime(i > 0) self.notify.debug('longestLerpTime: ' + str(longestLerpTime)) if i == 0: snt = Task(self.showNumbers) snt.choiceList = self.choiceList smt = Task(self.showMatches) smt.choiceList = self.choiceList tasks += [ snt, Task.pause(0.5), smt] if longestLerpTime > 0.0: self.notify.debug('someone moved...') mat = Task(self.moveAvatars) mat.choiceList = self.choiceList mat.positionList = self.positionList mat.rewardList = self.rewardList mat.name = 'moveAvatars' if i == 0: tasks += [ Task.pause(0.75), mat, Task.pause(0.75), Task(self.hideNumbers), Task.pause(longestLerpTime - 0.5)] else: mat.chance = 1 tasks += [ mat, Task.pause(longestLerpTime)] tasks += self.showChanceRewards() continue self.notify.debug('no one moved...') tasks += [ Task.pause(1.0), Task(self.hideNumbers)] self.notify.debug('task list : ' + str(tasks)) wdt = Task(self.walkDone) wdt.name = 'walk done' tasks.append(wdt) moveTask = Task.sequence(*tasks) taskMgr.add(moveTask, 'moveAvatars')
def enterMoveAvatars(self, choiceList, positionList, rewardList): self.notify.debug('in enterMoveAvatars:') tasks = [] self.avatarPositionsCopy = self.avatarPositions.copy() for i in range(0, len(choiceList) / self.numPlayers): startIndex = i * self.numPlayers endIndex = startIndex + self.numPlayers self.choiceList = choiceList[startIndex:endIndex] self.positionList = positionList[startIndex:endIndex] self.rewardList = rewardList[startIndex:endIndex] self.notify.debug(' turn: ' + str(i + 1)) self.notify.debug(' choiceList: ' + str(self.choiceList)) self.notify.debug(' positionList: ' + str(self.positionList)) self.notify.debug(' rewardList: ' + str(self.rewardList)) longestLerpTime = self.getLongestLerpTime(i > 0) self.notify.debug('longestLerpTime: ' + str(longestLerpTime)) if i == 0: snt = Task(self.showNumbers) snt.choiceList = self.choiceList smt = Task(self.showMatches) smt.choiceList = self.choiceList tasks += [ snt, Task.pause(0.5), smt] if longestLerpTime > 0.0: self.notify.debug('someone moved...') mat = Task(self.moveAvatars) mat.choiceList = self.choiceList mat.positionList = self.positionList mat.rewardList = self.rewardList mat.name = 'moveAvatars' if i == 0: tasks += [ Task.pause(0.75), mat, Task.pause(0.75), Task(self.hideNumbers), Task.pause(longestLerpTime - 0.5)] else: mat.chance = 1 tasks += [ mat, Task.pause(longestLerpTime)] tasks += self.showChanceRewards() continue self.notify.debug('no one moved...') tasks += [ Task.pause(1.0), Task(self.hideNumbers)] self.notify.debug('task list : ' + str(tasks)) wdt = Task(self.walkDone) wdt.name = 'walk done' tasks.append(wdt) moveTask = Task.sequence(*tasks) taskMgr.add(moveTask, 'moveAvatars')
def updateHealthBar(self): health = float(float(self.hp) / float(self.maxHp)) if health < 1: self.corpMedallion.hide() self.healthBar.show() if health > 0.95: condition = 0 elif health > 0.7: condition = 1 elif health > 0.3: condition = 2 elif health > 0.05: condition = 3 elif health > 0: condition = 4 else: condition = 5 if(self.healthCondition != condition): if(condition == 4): blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75), Task(self.__blinkGray), Task.pause(0.1)) base.taskMgr.add(blinkTask, 'blink-task') elif(condition == 5): if(self.healthCondition == 4): base.taskMgr.remove('blink-task') if(self.isDefeated == False): blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.25), Task(self.__blinkGray), Task.pause(0.1)) base.taskMgr.add(blinkTask, 'blink-task') self.isDefeated = True if not self.cog.hasPythonTag("Support"): roundInstance = render.getPythonTag('Round') wave = roundInstance.getCurrentWave() wave.setCogsDefeated(wave.getCogsDefeated() + 1) base.taskMgr.doMethodLater(1.5, self.setDefeated, 'Set Cog Defeated') else: self.healthBar.setColor(healthColors[condition], 1) self.healthBarGlow.setColor(healthGlowColors[condition], 1) self.healthCondition = condition
def launchPresence(self): callbacks = { 'ready': self.readyCallback, 'disconnected': self.disconnectedCallback, 'joinGame': self.joinCallback, 'spectateGame': None, 'joinRequest': self.joinCallback, 'error': self.errorCallback } self.discordRpc.initialize(discordToken, callbacks=callbacks, log=True) self.updatePresence() updateTask = Task.loop(Task(self.updateConnection), Task.pause(1.0), Task(self.runCallbacks)) taskMgr.add(updateTask, 'update-presence-task') return
def enableInteractionButtons(self): self.notify.debug("enable buttons") proxTask = Task.loop(Task(self.__checkPetProximity), Task.pause(0.5)) taskMgr.add(proxTask, "petpanel-proximity-check", priority=ToontownGlobals.PetPanelProximityPriority) """ if pet is out of range, this would flash feed/scratch for a frame after feeding or scratching self.scratchButton['state'] = DGG.NORMAL self.feedButton['state'] = self.feedButtonState() self.callButton['state'] = DGG.NORMAL """ # instead, call this to set the button states self.__checkPetProximity()
def updateHealthBar(self): if self.healthBar == None: return health = 1.0 - (float(self.bossDamage) / float(self.bossMaxDamage)) if (health > 0.95): condition = 0 elif (health > 0.7): condition = 1 elif (health > 0.3): condition = 2 elif (health > 0.05): condition = 3 elif (health > 0.0): # This should be blinking red condition = 4 else: # This should be blinking red even faster condition = 5 if (self.healthCondition != condition): if (condition == 4): blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.uniqueName('blink-task')) elif (condition == 5): if (self.healthCondition == 4): taskMgr.remove(self.uniqueName('blink-task')) blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.25), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, self.uniqueName('blink-task')) else: self.healthBar.setColor(self.healthColors[condition], 1) self.healthBarGlow.setColor(self.healthGlowColors[condition], 1) self.healthCondition = condition
def update(self, hp, forceUpdate = 0): if not self.geom: return condition = self.getHealthCondition(hp) if self.healthCondition != condition or forceUpdate: taskMgr.remove('blink-task-%s' % id(self)) if condition in (9, 10): blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75 if condition == 9 else 0.25), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(blinkTask, 'blink-task-%s' % id(self)) else: self.geom.setColor(HEALTH_COLORS[condition], 1) self.geomGlow.setColor(HEALTH_GLOW_COLORS[condition], 1) self.healthCondition = condition
def __fireCannonTask(self, task): launchTime = task.fireTime avId = task.avId self.notify.debug('FIRING CANNON FOR AVATAR ' + str(avId)) startPos, startHpr, startVel, trajectory, timeOfImpact, hitWhat = self.__calcFlightResults(avId, launchTime) self.notify.debug('start position: ' + str(startPos)) self.notify.debug('start velocity: ' + str(startVel)) self.notify.debug('time of launch: ' + str(launchTime)) self.notify.debug('time of impact: ' + str(timeOfImpact)) self.notify.debug('location of impact: ' + str(trajectory.getPos(timeOfImpact))) if hitWhat == self.HIT_WATER: self.notify.debug('toon will land in the water') elif hitWhat == self.HIT_TOWER: self.notify.debug('toon will hit the tower') else: self.notify.debug('toon will hit the ground') head = self.toonHeadDict[avId] head.stopBlink() head.stopLookAroundNow() head.reparentTo(hidden) av = self.toonModelDict[avId] av.reparentTo(render) av.setPos(startPos) av.setHpr(startHpr) avatar = self.getAvatar(avId) avatar.loop('swim') avatar.setPosHpr(0, 0, -(avatar.getHeight() / 2.0), 0, 0, 0) shootTask = Task(self.__shootTask) flyTask = Task(self.__flyTask) seqDoneTask = Task(self.__flySequenceDoneTask) info = {'avId': avId, 'trajectory': trajectory, 'launchTime': launchTime, 'timeOfImpact': timeOfImpact, 'hitWhat': hitWhat, 'toon': self.toonModelDict[avId], 'hRot': self.cannonPositionDict[avId][0], 'haveWhistled': 0, 'maxCamPullback': CAMERA_PULLBACK_MIN, 'timeEnterTowerXY': trajectory.calcEnterAndLeaveCylinderXY(self.tower.getPos(render), TOWER_RADIUS)[0], 'timeExitTowerXY': trajectory.calcEnterAndLeaveCylinderXY(self.tower.getPos(render), TOWER_RADIUS)[1]} shootTask.info = info flyTask.info = info seqDoneTask.info = info seqTask = Task.sequence(shootTask, flyTask, Task.pause(LAND_TIME), seqDoneTask) taskMgr.add(seqTask, 'flyingToon' + str(avId)) if avId == self.localAvId: if info['hitWhat'] == self.HIT_WATER: self.sendUpdate('setToonWillLandInWater', [info['timeOfImpact']]) return Task.done
def setCannonWillFire(self, avId, fireTime, zRot, angle): if not self.hasLocalToon: return if not self.__playing(): return self.notify.debug('setCannonWillFire: ' + str(avId) + ': zRot=' + str(zRot) + ', angle=' + str(angle) + ', time=' + str(fireTime)) self.cannonPositionDict[avId][0] = zRot self.cannonPositionDict[avId][1] = angle self.__updateCannonPosition(avId) task = Task(self.__fireCannonTask) task.avId = avId task.fireTime = fireTime timeToWait = task.fireTime - self.getCurrentGameTime() if timeToWait > 0.0: fireTask = Task.sequence(Task.pause(timeToWait), task) else: fireTask = task fireTask = task taskMgr.add(fireTask, 'fireCannon' + str(avId)) self.airborneToons += 1
def enterFlyDown(self): self.fd_sfx = audio3d.loadSfx("phase_5/audio/sfx/ENC_propeller_in.ogg") self.prop = Actor("phase_4/models/props/propeller-mod.bam", {"chan": "phase_4/models/props/propeller-chan.bam"}) audio3d.attachSoundToObject(self.fd_sfx, self.prop) self.fd_sfx.play() self.prop.reparentTo(self.suit.find('**/joint_head')) propTrack = Sequence(Func(self.prop.loop, 'chan', fromFrame=0, toFrame=3), Wait(1.75), Func(self.prop.play, 'chan', fromFrame=3)) propTrack.start() if not self.hasSpawned: showSuit = Task.sequence(Task(self.hideSuit), Task.pause(0.3), Task(self.showSuit)) taskMgr.add(showSuit, "showsuit") self.hasSpawned = True dur = self.suit.getDuration('land') suitTrack = Sequence(Func(self.suit.pose, 'land', 0), Wait(1.9), ActorInterval(self.suit, 'land', duration=dur)) suitTrack.start()
def enterMoveAvatars(self, choiceList, positionList, rewardList): self.notify.debug("in enterMoveAvatars:") # These arrays could contain multiple turn information, # so unroll them one turn at a time tasks = [] # Make a copy for getLongestLerpTime to stomp on self.avatarPositionsCopy = self.avatarPositions.copy() for i in range(0, len(choiceList) / self.numPlayers): startIndex = i * self.numPlayers endIndex = startIndex + self.numPlayers self.choiceList = choiceList[startIndex:endIndex] self.positionList = positionList[startIndex:endIndex] self.rewardList = rewardList[startIndex:endIndex] self.notify.debug(" turn: " + str(i + 1)) self.notify.debug(" choiceList: " + str(self.choiceList)) self.notify.debug(" positionList: " + str(self.positionList)) self.notify.debug(" rewardList: " + str(self.rewardList)) longestLerpTime = self.getLongestLerpTime(i > 0) self.notify.debug("longestLerpTime: " + str(longestLerpTime)) # only need to do this once if i == 0: snt = Task(self.showNumbers) snt.choiceList = self.choiceList smt = Task(self.showMatches) smt.choiceList = self.choiceList tasks += [ snt, Task.pause(0.5), smt, ] # there may be multiple moves per turn thanks to the # chance cards. Concatenate all tasks into a list, # then make one big sequence out of the lists if longestLerpTime > 0.0: self.notify.debug("someone moved...") # If anybody moves, add all these task mat = Task(self.moveAvatars) mat.choiceList = self.choiceList mat.positionList = self.positionList mat.rewardList = self.rewardList mat.name = "moveAvatars" if i == 0: tasks += [ Task.pause(0.75), # Start moving the avatars with the numbers up # for just a brief time mat, Task.pause(0.75), Task(self.hideNumbers), # Wait for the walk to finish Task.pause(longestLerpTime - 0.5), ] else: mat.chance = 1 tasks += [ mat, # Wait for the walk to finish Task.pause(longestLerpTime), ] # check for chance card hit in this lane tasks += self.showChanceRewards() else: self.notify.debug("no one moved...") # If nobody moves, use this sequence tasks += [Task.pause(1.0), Task(self.hideNumbers)] self.notify.debug("task list : " + str(tasks)) # now make and spawn a sequence out of our compiled task list wdt = Task(self.walkDone) wdt.name = "walk done" tasks.append(wdt) moveTask = Task.sequence(*tasks) taskMgr.add(moveTask, "moveAvatars")
def __init__(self, avatar): self.notify.debug('Init(): doId=%s' % avatar.doId) distPet = base.cr.doId2do.get(avatar.doId) if distPet and not distPet.isProxy(): self.avatar = distPet self.petIsLocal = True else: self.avatar = avatar self.petIsLocal = False from toontown.friends import FriendsListPanel AvatarPanel.AvatarPanel.__init__(self, self.avatar, FriendsListPanel=FriendsListPanel) base.localAvatar.obscureFriendsListButton(1) base.panel = self gui = loader.loadModel('phase_3.5/models/gui/PetControlPannel') guiScale = 0.116 guiPos = (-0.213, 0, -0.70) self.frame = DirectFrame(parent=base.a2dTopRight, image=gui, scale=guiScale, pos=guiPos, relief=None) disabledImageColor = Vec4(0.6, 0.6, 0.6, 1) text0Color = Vec4(1, 1, 1, 1) text1Color = Vec4(0.5, 1, 0.5, 1) text2Color = Vec4(1, 1, 0.5, 1) text3Color = Vec4(0.6, 0.6, 0.6, 1) self.closeButton = DirectButton(parent=self.frame, image=(gui.find('**/CancelButtonUp'), gui.find('**/CancelButtonDown'), gui.find('**/CancelButtonRollover')), relief=None, command=self.__handleClose) self.feedButton = DirectButton(parent=self.frame, image=(gui.find('**/ButtonFeedUp'), gui.find('**/ButtonFeedDown'), gui.find('**/ButtonFeedRollover'), gui.find('**/ButtonFeedUp')), geom=gui.find('**/PetControlFeedIcon'), geom3_color=disabledImageColor, image3_color=disabledImageColor, relief=None, text=TTLocalizer.PetPanelFeed, text_scale=TTLocalizer.PAPfeedButton, text0_fg=text0Color, text1_fg=text1Color, text2_fg=text2Color, text3_fg=text3Color, text_pos=(-0.5, 2.8), text_align=TextNode.ALeft, command=self.__handleFeed) if not self.petIsLocal: self.feedButton['state'] = DGG.DISABLED else: self.feedButton['state'] = self.feedButtonState() self.callButton = DirectButton(parent=self.frame, image=(gui.find('**/ButtonGoToUp'), gui.find('**/ButtonGoToDown'), gui.find('**/ButtonGoToRollover'), gui.find('**/ButtonGoToUp')), geom=gui.find('**/PetControlGoToIcon'), geom3_color=disabledImageColor, image3_color=disabledImageColor, relief=None, text=TTLocalizer.PetPanelCall, text0_fg=text0Color, text1_fg=text1Color, text2_fg=text2Color, text3_fg=text3Color, text_scale=TTLocalizer.PAPcallButton, text_pos=(-0.5, 1.3), text_align=TextNode.ALeft, command=self.__handleCall) if not self.petIsLocal: self.callButton['state'] = DGG.DISABLED self.scratchButton = DirectButton(parent=self.frame, image=(gui.find('**/ButtonScratchUp'), gui.find('**/ButtonScratchDown'), gui.find('**/ButtonScratchRollover'), gui.find('**/ButtonScratchUp')), geom=gui.find('**/PetControlScratchIcon'), geom3_color=disabledImageColor, image3_color=disabledImageColor, relief=None, text=TTLocalizer.PetPanelScratch, text0_fg=text0Color, text1_fg=text1Color, text2_fg=text2Color, text3_fg=text3Color, text_scale=TTLocalizer.PAPscratchButton, text_pos=(-0.5, 2.05), text_align=TextNode.ALeft, command=self.__handleScratch) if not self.petIsLocal: self.scratchButton['state'] = DGG.DISABLED self.ownerButton = DirectButton(parent=self.frame, image=(gui.find('**/PetControlToonButtonUp'), gui.find('**/PetControlToonButtonDown'), gui.find('**/PetControlToonButtonRollover')), geom=gui.find('**/PetControlToonIcon'), geom3_color=disabledImageColor, relief=None, image3_color=disabledImageColor, text=('', TTLocalizer.PetPanelOwner, TTLocalizer.PetPanelOwner, ''), text_fg=text2Color, text_shadow=(0, 0, 0, 1), text_scale=TTLocalizer.PAPownerButton, text_pos=(0.3, 1.05), text_align=TextNode.ACenter, command=self.__handleToOwner) if self.avatar.getOwnerId() == base.localAvatar.doId: self.ownerButton['state'] = DGG.DISABLED toonGui = loader.loadModel('phase_3.5/models/gui/avatar_panel_gui') self.detailButton = DirectButton(parent=self.frame, image=(toonGui.find('**/ChtBx_BackBtn_UP'), toonGui.find('**/ChtBx_BackBtn_DN'), toonGui.find('**/ChtBx_BackBtn_Rllvr'), toonGui.find('**/ChtBx_BackBtn_UP')), relief=None, pos=(-1.3, 0, 0.67), image3_color=disabledImageColor, text=('', TTLocalizer.PetPanelDetail, TTLocalizer.PetPanelDetail, ''), text_fg=text2Color, text_shadow=(0, 0, 0, 1), text_scale=0.05, text_pos=(0.05, 0.05), text_align=TextNode.ACenter, command=self.__handleDetail) self.detailButton.setScale(7.5) if not self.petIsLocal: self.detailButton['state'] = DGG.DISABLED gui.removeNode() toonGui.removeNode() self.petDetailPanel = None self.__fillPetInfo(self.avatar) self.accept('petNameChanged', self.__refreshPetInfo) self.accept('petStateUpdated', self.__refreshPetInfo) self.frame.show() if self.petIsLocal: proxTask = Task.loop(Task(self.__checkPetProximity), Task.pause(0.5)) taskMgr.add(proxTask, 'petpanel-proximity-check', priority=ToontownGlobals.PetPanelProximityPriority) if base.localAvatar.isLockedDown(): self.disableInteractionButtons() if self.petIsLocal: self.listenForInteractionDone() messenger.send('petPanelDone') if not self.petIsLocal and hasattr(self.avatar, 'updateMoodFromServer'): if self.avatar.doId != localAvatar.getPetId() or bboard.get(PetConstants.OurPetsMoodChangedKey, False): self.stateLabel['text'] = '' def refresh(self = self, av = self.avatar): bboard.remove(PetConstants.OurPetsMoodChangedKey) self.__refreshPetInfo(av) self.avatar.updateMoodFromServer(refresh) return
def enableInteractionButtons(self): self.notify.debug('enable buttons') proxTask = Task.loop(Task(self.__checkPetProximity), Task.pause(0.5)) taskMgr.add(proxTask, 'petpanel-proximity-check', priority=ToontownGlobals.PetPanelProximityPriority) self.__checkPetProximity()
def __init__(self, avatar): """__init__(self)""" self.notify.debug("Init(): doId=%s" % avatar.doId) #determine if this avatar is in the same zone as the localtoon distPet = base.cr.doId2do.get(avatar.doId) if distPet and not distPet.isProxy(): self.avatar = distPet self.petIsLocal = True else: self.avatar = avatar self.petIsLocal = False from toontown.friends import FriendsListPanel AvatarPanel.AvatarPanel.__init__(self, self.avatar, FriendsListPanel=FriendsListPanel) base.localAvatar.obscureFriendsListButton(1) base.panel = self gui = loader.loadModel("phase_3.5/models/gui/PetControlPannel") guiScale = 0.116 guiPos = (1.12, 0, 0.30) self.frame = DirectFrame( parent=aspect2dp, image=gui, scale=guiScale, pos=guiPos, relief=None, ) disabledImageColor = Vec4(.6, .6, .6, 1) text0Color = Vec4(1, 1, 1, 1) text1Color = Vec4(0.5, 1, 0.5, 1) text2Color = Vec4(1, 1, 0.5, 1) text3Color = Vec4(.6, .6, .6, 1) self.closeButton = DirectButton( parent=self.frame, image=( gui.find("**/CancelButtonUp"), gui.find("**/CancelButtonDown"), gui.find("**/CancelButtonRollover"), ), relief=None, command=self.__handleClose, ) self.feedButton = DirectButton( parent=self.frame, image=( gui.find("**/ButtonFeedUp"), gui.find("**/ButtonFeedDown"), gui.find("**/ButtonFeedRollover"), gui.find("**/ButtonFeedUp"), ), geom=gui.find("**/PetControlFeedIcon"), geom3_color=disabledImageColor, image3_color=disabledImageColor, relief=None, text=TTLocalizer.PetPanelFeed, text_scale=TTLocalizer.PAPfeedButton, text0_fg=text0Color, text1_fg=text1Color, text2_fg=text2Color, text3_fg=text3Color, text_pos=(-0.5, 2.8), text_align=TextNode.ALeft, command=self.__handleFeed, ) if not self.petIsLocal: self.feedButton['state'] = DGG.DISABLED else: self.feedButton['state'] = self.feedButtonState() self.callButton = DirectButton( parent=self.frame, image=( gui.find("**/ButtonGoToUp"), gui.find("**/ButtonGoToDown"), gui.find("**/ButtonGoToRollover"), gui.find("**/ButtonGoToUp"), ), geom=gui.find("**/PetControlGoToIcon"), geom3_color=disabledImageColor, image3_color=disabledImageColor, relief=None, text=TTLocalizer.PetPanelCall, text0_fg=text0Color, text1_fg=text1Color, text2_fg=text2Color, text3_fg=text3Color, text_scale=TTLocalizer.PAPcallButton, text_pos=(-0.5, 1.3), text_align=TextNode.ALeft, command=self.__handleCall, ) if not self.petIsLocal: self.callButton['state'] = DGG.DISABLED self.scratchButton = DirectButton( parent=self.frame, image=( gui.find("**/ButtonScratchUp"), gui.find("**/ButtonScratchDown"), gui.find("**/ButtonScratchRollover"), gui.find("**/ButtonScratchUp"), ), geom=gui.find("**/PetControlScratchIcon"), geom3_color=disabledImageColor, image3_color=disabledImageColor, relief=None, text=TTLocalizer.PetPanelScratch, text0_fg=text0Color, text1_fg=text1Color, text2_fg=text2Color, text3_fg=text3Color, text_scale=TTLocalizer.PAPscratchButton, text_pos=(-0.5, 2.05), text_align=TextNode.ALeft, command=self.__handleScratch, ) if not self.petIsLocal: self.scratchButton['state'] = DGG.DISABLED self.ownerButton = DirectButton( parent=self.frame, image=( gui.find("**/PetControlToonButtonUp"), gui.find("**/PetControlToonButtonDown"), gui.find("**/PetControlToonButtonRollover"), ), geom=gui.find("**/PetControlToonIcon"), geom3_color=disabledImageColor, relief=None, image3_color=disabledImageColor, text=("", TTLocalizer.PetPanelOwner, TTLocalizer.PetPanelOwner, ""), text_fg=text2Color, text_shadow=(0, 0, 0, 1), text_scale=TTLocalizer.PAPownerButton, text_pos=(0.3, 1.05), text_align=TextNode.ACenter, command=self.__handleToOwner, ) if self.avatar.getOwnerId() == base.localAvatar.doId: self.ownerButton['state'] = DGG.DISABLED toonGui = loader.loadModel("phase_3.5/models/gui/avatar_panel_gui") self.detailButton = DirectButton( parent=self.frame, image=( toonGui.find("**/ChtBx_BackBtn_UP"), toonGui.find("**/ChtBx_BackBtn_DN"), toonGui.find("**/ChtBx_BackBtn_Rllvr"), toonGui.find("**/ChtBx_BackBtn_UP"), ), relief=None, pos=(-1.3, 0, 0.67), image3_color=disabledImageColor, text=("", TTLocalizer.PetPanelDetail, TTLocalizer.PetPanelDetail, ""), text_fg=text2Color, text_shadow=(0, 0, 0, 1), text_scale=0.05, text_pos=(0.05, 0.05), text_align=TextNode.ACenter, command=self.__handleDetail, ) self.detailButton.setScale(7.5) if (not self.petIsLocal): self.detailButton['state'] = DGG.DISABLED gui.removeNode() toonGui.removeNode() self.petDetailPanel = None self.__fillPetInfo(self.avatar) self.accept("petNameChanged", self.__refreshPetInfo) self.accept("petStateUpdated", self.__refreshPetInfo) self.frame.show() if self.petIsLocal: #if this pet is real, set up a task to check his proximity proxTask = Task.loop(Task(self.__checkPetProximity), Task.pause(0.5)) taskMgr.add(proxTask, "petpanel-proximity-check", priority=ToontownGlobals.PetPanelProximityPriority) if base.localAvatar.isLockedDown(): self.disableInteractionButtons() if self.petIsLocal: self.listenForInteractionDone() messenger.send("petPanelDone") # refresh the pet info if ((not self.petIsLocal) and hasattr(self.avatar, 'updateMoodFromServer')): # can we use previously-cached mood info? Only do this for # localAv's pet. We can't reliably know if the mood of someone # else's pet has changed since we last queried their info... if (self.avatar.doId != localAvatar.getPetId() or bboard.get(PetConstants.OurPetsMoodChangedKey, False)): # clear out the state text, since it may be stale and we'll be # setting it to a correct string in a moment self.stateLabel['text'] = '' def refresh(self=self, av=self.avatar): # clear the 'mood dirty' flag for localAv's pet bboard.remove(PetConstants.OurPetsMoodChangedKey) self.__refreshPetInfo(av) self.avatar.updateMoodFromServer(refresh)
def __init__(self, avatar): self.notify.debug('Init(): doId=%s' % avatar.doId) distPet = base.cr.doId2do.get(avatar.doId) if distPet and not distPet.isProxy(): self.avatar = distPet self.petIsLocal = True else: self.avatar = avatar self.petIsLocal = False from toontown.friends import FriendsListPanel AvatarPanel.AvatarPanel.__init__(self, self.avatar, FriendsListPanel=FriendsListPanel) base.localAvatar.obscureFriendsListButton(1) base.panel = self gui = loader.loadModel('phase_3.5/models/gui/PetControlPannel') guiScale = 0.116 guiPos = (1.12, 0, 0.3) self.frame = DirectFrame(parent=aspect2dp, image=gui, scale=guiScale, pos=guiPos, relief=None) disabledImageColor = Vec4(0.6, 0.6, 0.6, 1) text0Color = Vec4(1, 1, 1, 1) text1Color = Vec4(0.5, 1, 0.5, 1) text2Color = Vec4(1, 1, 0.5, 1) text3Color = Vec4(0.6, 0.6, 0.6, 1) self.closeButton = DirectButton(parent=self.frame, image=(gui.find('**/CancelButtonUp'), gui.find('**/CancelButtonDown'), gui.find('**/CancelButtonRollover')), relief=None, command=self.__handleClose) self.feedButton = DirectButton(parent=self.frame, image=(gui.find('**/ButtonFeedUp'), gui.find('**/ButtonFeedDown'), gui.find('**/ButtonFeedRollover'), gui.find('**/ButtonFeedUp')), geom=gui.find('**/PetControlFeedIcon'), geom3_color=disabledImageColor, image3_color=disabledImageColor, relief=None, text=TTLocalizer.PetPanelFeed, text_scale=TTLocalizer.PAPfeedButton, text0_fg=text0Color, text1_fg=text1Color, text2_fg=text2Color, text3_fg=text3Color, text_pos=(-0.5, 2.8), text_align=TextNode.ALeft, command=self.__handleFeed) if not self.petIsLocal: self.feedButton['state'] = DGG.DISABLED else: self.feedButton['state'] = self.feedButtonState() self.callButton = DirectButton(parent=self.frame, image=(gui.find('**/ButtonGoToUp'), gui.find('**/ButtonGoToDown'), gui.find('**/ButtonGoToRollover'), gui.find('**/ButtonGoToUp')), geom=gui.find('**/PetControlGoToIcon'), geom3_color=disabledImageColor, image3_color=disabledImageColor, relief=None, text=TTLocalizer.PetPanelCall, text0_fg=text0Color, text1_fg=text1Color, text2_fg=text2Color, text3_fg=text3Color, text_scale=TTLocalizer.PAPcallButton, text_pos=(-0.5, 1.3), text_align=TextNode.ALeft, command=self.__handleCall) if not self.petIsLocal: self.callButton['state'] = DGG.DISABLED self.scratchButton = DirectButton(parent=self.frame, image=(gui.find('**/ButtonScratchUp'), gui.find('**/ButtonScratchDown'), gui.find('**/ButtonScratchRollover'), gui.find('**/ButtonScratchUp')), geom=gui.find('**/PetControlScratchIcon'), geom3_color=disabledImageColor, image3_color=disabledImageColor, relief=None, text=TTLocalizer.PetPanelScratch, text0_fg=text0Color, text1_fg=text1Color, text2_fg=text2Color, text3_fg=text3Color, text_scale=TTLocalizer.PAPscratchButton, text_pos=(-0.5, 2.05), text_align=TextNode.ALeft, command=self.__handleScratch) if not self.petIsLocal: self.scratchButton['state'] = DGG.DISABLED self.ownerButton = DirectButton(parent=self.frame, image=(gui.find('**/PetControlToonButtonUp'), gui.find('**/PetControlToonButtonDown'), gui.find('**/PetControlToonButtonRollover')), geom=gui.find('**/PetControlToonIcon'), geom3_color=disabledImageColor, relief=None, image3_color=disabledImageColor, text=('', TTLocalizer.PetPanelOwner, TTLocalizer.PetPanelOwner, ''), text_fg=text2Color, text_shadow=(0, 0, 0, 1), text_scale=TTLocalizer.PAPownerButton, text_pos=(0.3, 1.05), text_align=TextNode.ACenter, command=self.__handleToOwner) if self.avatar.getOwnerId() == base.localAvatar.doId: self.ownerButton['state'] = DGG.DISABLED toonGui = loader.loadModel('phase_3.5/models/gui/avatar_panel_gui') self.detailButton = DirectButton(parent=self.frame, image=(toonGui.find('**/ChtBx_BackBtn_UP'), toonGui.find('**/ChtBx_BackBtn_DN'), toonGui.find('**/ChtBx_BackBtn_Rllvr'), toonGui.find('**/ChtBx_BackBtn_UP')), relief=None, pos=(-1.3, 0, 0.67), image3_color=disabledImageColor, text=('', TTLocalizer.PetPanelDetail, TTLocalizer.PetPanelDetail, ''), text_fg=text2Color, text_shadow=(0, 0, 0, 1), text_scale=0.05, text_pos=(0.05, 0.05), text_align=TextNode.ACenter, command=self.__handleDetail) self.detailButton.setScale(7.5) if not self.petIsLocal: self.detailButton['state'] = DGG.DISABLED gui.removeNode() toonGui.removeNode() self.petDetailPanel = None self.__fillPetInfo(self.avatar) self.accept('petNameChanged', self.__refreshPetInfo) self.accept('petStateUpdated', self.__refreshPetInfo) self.frame.show() if self.petIsLocal: proxTask = Task.loop(Task(self.__checkPetProximity), Task.pause(0.5)) taskMgr.add(proxTask, 'petpanel-proximity-check', priority=ToontownGlobals.PetPanelProximityPriority) if base.localAvatar.isLockedDown(): self.disableInteractionButtons() if self.petIsLocal: self.listenForInteractionDone() messenger.send('petPanelDone') if not self.petIsLocal and hasattr(self.avatar, 'updateMoodFromServer'): if self.avatar.doId != localAvatar.getPetId() or bboard.get(PetConstants.OurPetsMoodChangedKey, False): self.stateLabel['text'] = '' def refresh(self = self, av = self.avatar): bboard.remove(PetConstants.OurPetsMoodChangedKey) self.__refreshPetInfo(av) self.avatar.updateMoodFromServer(refresh) return
def startBlinkTask(self): self.blinkTask = Task.loop(Task(self.__blinkRed), Task.pause(0.75), Task(self.__blinkGray), Task.pause(0.1)) taskMgr.add(self.blinkTask, 'bosshealthbar-blink-task')