mirror of
https://github.com/Sneed-Group/Poodletooth-iLand
synced 2024-12-23 03:35:12 -06:00
Refactor suit health bar
This commit is contained in:
parent
7019d1ba9a
commit
1d8fe20587
6 changed files with 66 additions and 266 deletions
|
@ -200,7 +200,7 @@ def removeReviveSuit(suit, deathSuit):
|
|||
if not deathSuit.isEmpty():
|
||||
deathSuit.detachNode()
|
||||
suit.cleanupLoseActor()
|
||||
suit.healthBar.show()
|
||||
suit.healthBar.geom.show()
|
||||
suit.resetHealthBarForSkele()
|
||||
|
||||
|
||||
|
|
|
@ -1,23 +1,16 @@
|
|||
from panda3d.core import *
|
||||
from direct.actor import Actor
|
||||
from direct.directnotify import DirectNotifyGlobal
|
||||
from direct.fsm import FSM
|
||||
from direct.fsm import State
|
||||
from direct.interval.IntervalGlobal import *
|
||||
from direct.showbase.PythonUtil import Functor
|
||||
from direct.task.Task import Task
|
||||
from panda3d.core import *
|
||||
import types
|
||||
import random
|
||||
import Suit
|
||||
import SuitDNA
|
||||
from otp.avatar import Avatar
|
||||
from toontown.battle import BattleParticles
|
||||
from toontown.battle import BattleProps
|
||||
from otp.nametag.NametagGroup import NametagGroup
|
||||
from otp.nametag.NametagConstants import *
|
||||
from toontown.toonbase import TTLocalizer
|
||||
from toontown.toonbase import ToontownGlobals
|
||||
|
||||
from toontown.battle import BattleParticles, BattleProps
|
||||
from toontown.toonbase import TTLocalizer, ToontownGlobals
|
||||
import Suit, SuitDNA, SuitHealthBar
|
||||
import types, random
|
||||
|
||||
GenericModel = 'phase_9/models/char/bossCog'
|
||||
ModelDict = {'s': 'phase_9/models/char/sellbotBoss',
|
||||
|
@ -28,8 +21,6 @@ AnimList = ('Ff_speech', 'ltTurn2Wave', 'wave', 'Ff_lookRt', 'turn2Fb', 'Ff_neut
|
|||
|
||||
class BossCog(Avatar.Avatar):
|
||||
notify = DirectNotifyGlobal.directNotify.newCategory('BossCog')
|
||||
healthColors = Suit.Suit.healthColors
|
||||
healthGlowColors = Suit.Suit.healthGlowColors
|
||||
|
||||
def __init__(self):
|
||||
Avatar.Avatar.__init__(self)
|
||||
|
@ -52,15 +43,14 @@ class BossCog(Avatar.Avatar):
|
|||
self.queuedAnimIvals = []
|
||||
self.treadsLeftPos = 0
|
||||
self.treadsRightPos = 0
|
||||
self.healthBar = None
|
||||
self.healthCondition = 0
|
||||
self.healthBar = SuitHealthBar.SuitHealthBar()
|
||||
self.animDoneEvent = 'BossCogAnimDone'
|
||||
self.animIvalName = 'BossCogAnimIval'
|
||||
self.warningSfx = loader.loadSfx('phase_9/audio/sfx/CHQ_GOON_tractor_beam_alarmed.ogg')
|
||||
|
||||
def delete(self):
|
||||
Avatar.Avatar.delete(self)
|
||||
self.removeHealthBar()
|
||||
self.healthBar.delete()
|
||||
self.setDizzy(0)
|
||||
self.stopAnimate()
|
||||
if self.doorA:
|
||||
|
@ -155,92 +145,17 @@ class BossCog(Avatar.Avatar):
|
|||
self.collNode.setCollideMask(self.collNode.getIntoCollideMask() | ToontownGlobals.PieBitmask)
|
||||
|
||||
def generateHealthBar(self):
|
||||
self.removeHealthBar()
|
||||
chestNull = self.find('**/joint_lifeMeter')
|
||||
if chestNull.isEmpty():
|
||||
return
|
||||
model = loader.loadModel('phase_3.5/models/gui/matching_game_gui')
|
||||
button = model.find('**/minnieCircle')
|
||||
button.setScale(6.0)
|
||||
button.setP(-20)
|
||||
button.setColor(self.healthColors[0])
|
||||
button.reparentTo(chestNull)
|
||||
self.healthBar = button
|
||||
glow = BattleProps.globalPropPool.getProp('glow')
|
||||
glow.reparentTo(self.healthBar)
|
||||
glow.setScale(0.28)
|
||||
glow.setPos(-0.005, 0.01, 0.015)
|
||||
glow.setColor(self.healthGlowColors[0])
|
||||
button.flattenLight()
|
||||
self.healthBarGlow = glow
|
||||
self.healthCondition = 0
|
||||
self.healthBar.generate()
|
||||
self.healthBar.geom.reparentTo(self.find('**/joint_lifeMeter'))
|
||||
self.healthBar.geom.setScale(6.0)
|
||||
self.healthBar.geom.setHpr(0, -20, 0)
|
||||
self.healthBar.geom.show()
|
||||
|
||||
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 __blinkRed(self, task):
|
||||
if not self.healthBar:
|
||||
return
|
||||
self.healthBar.setColor(self.healthColors[8], 1)
|
||||
self.healthBarGlow.setColor(self.healthGlowColors[8], 1)
|
||||
if self.healthCondition == 10:
|
||||
self.healthBar.setScale(1.17)
|
||||
return Task.done
|
||||
|
||||
def __blinkGray(self, task):
|
||||
if not self.healthBar:
|
||||
return
|
||||
self.healthBar.setColor(self.healthColors[9], 1)
|
||||
self.healthBarGlow.setColor(self.healthGlowColors[9], 1)
|
||||
if self.healthCondition == 10:
|
||||
self.healthBar.setScale(1.0)
|
||||
return Task.done
|
||||
|
||||
def removeHealthBar(self):
|
||||
if self.healthBar:
|
||||
self.healthBar.removeNode()
|
||||
self.healthBar = None
|
||||
if self.healthCondition == 9 or self.healthCondition == 10:
|
||||
taskMgr.remove(self.uniqueName('blink-task'))
|
||||
self.healthCondition = 0
|
||||
return
|
||||
|
||||
self.healthBar.update(1.0 - float(self.bossDamage) / float(self.bossMaxDamage))
|
||||
|
||||
def reverseHead(self):
|
||||
self.neck.setHpr(self.neckReversedHpr)
|
||||
|
|
|
@ -784,7 +784,7 @@ class DistributedCashbotBoss(DistributedBossCog.DistributedBossCog, FSM.FSM):
|
|||
self.stopAnimate()
|
||||
self.cleanupAttacks()
|
||||
self.setDizzy(0)
|
||||
self.removeHealthBar()
|
||||
self.healthBar.delete()
|
||||
localAvatar.setCameraFov(ToontownGlobals.CogHQCameraFov)
|
||||
if self.newState != 'Victory':
|
||||
self.battleThreeMusic.stop()
|
||||
|
|
|
@ -326,12 +326,12 @@ class DistributedSuitBase(DistributedAvatar.DistributedAvatar, Suit.Suit, SuitBa
|
|||
self.loop('neutral', 0)
|
||||
self.disableBattleDetect()
|
||||
self.corpMedallion.hide()
|
||||
self.healthBar.show()
|
||||
self.healthBar.geom.show()
|
||||
if self.currHP < self.maxHP:
|
||||
self.updateHealthBar(0, 1)
|
||||
|
||||
def exitBattle(self):
|
||||
self.healthBar.hide()
|
||||
self.healthBar.geom.hide()
|
||||
self.corpMedallion.show()
|
||||
self.currHP = self.maxHP
|
||||
self.interactivePropTrackBonus = -1
|
||||
|
|
|
@ -2,11 +2,11 @@ from panda3d.core import *
|
|||
from direct.actor import Actor
|
||||
from direct.task.Task import Task
|
||||
from otp.avatar import Avatar
|
||||
from toontown.battle import BattleProps, SuitBattleGlobals
|
||||
from toontown.battle import SuitBattleGlobals
|
||||
from otp.nametag.NametagGroup import NametagGroup
|
||||
from toontown.toonbase import TTLocalizer, ToontownGlobals
|
||||
from toontown.suit import SuitGlobals
|
||||
import SuitDNA, string
|
||||
import SuitDNA, SuitHealthBar, string
|
||||
|
||||
aSize = 6.06
|
||||
bSize = 5.29
|
||||
|
@ -299,26 +299,6 @@ def attachSuitHead(node, suitName):
|
|||
|
||||
class Suit(Avatar.Avatar):
|
||||
__module__ = __name__
|
||||
healthColors = (Vec4(0, 1, 0, 1),# 0 Green
|
||||
Vec4(0.5, 1, 0, 1),#1 Green-Yellow
|
||||
Vec4(0.75, 1, 0, 1),#2 Yellow-Green
|
||||
Vec4(1, 1, 0, 1),#3 Yellow
|
||||
Vec4(1, 0.866, 0, 1),#4 Yellow-Orange
|
||||
Vec4(1, 0.6, 0, 1),#5 Orange-Yellow
|
||||
Vec4(1, 0.5, 0, 1),#6 Orange
|
||||
Vec4(1, 0.25, 0, 1.0),#7 Red-Orange
|
||||
Vec4(1, 0, 0, 1),#8 Red
|
||||
Vec4(0.3, 0.3, 0.3, 1))#9 Grey
|
||||
healthGlowColors = (Vec4(0.25, 1, 0.25, 0.5),#Green
|
||||
Vec4(0.5, 1, 0.25, .5),#1 Green-Yellow
|
||||
Vec4(0.75, 1, 0.25, .5),#2 Yellow-Green
|
||||
Vec4(1, 1, 0.25, 0.5),#Yellow
|
||||
Vec4(1, 0.866, 0.25, .5),#4 Yellow-Orange
|
||||
Vec4(1, 0.6, 0.25, .5),#5 Orange-Yellow
|
||||
Vec4(1, 0.5, 0.25, 0.5),#6 Orange
|
||||
Vec4(1, 0.25, 0.25, 0.5),#7 Red-Orange
|
||||
Vec4(1, 0.25, 0.25, 0.5),#8 Red
|
||||
Vec4(0.3, 0.3, 0.3, 0))#9 Grey
|
||||
medallionColors = {'c': Vec4(0.863, 0.776, 0.769, 1.0),
|
||||
's': Vec4(0.843, 0.745, 0.745, 1.0),
|
||||
'l': Vec4(0.749, 0.776, 0.824, 1.0),
|
||||
|
@ -341,8 +321,7 @@ class Suit(Avatar.Avatar):
|
|||
self.shadowJoint = None
|
||||
self.nametagJoint = None
|
||||
self.headParts = []
|
||||
self.healthBar = None
|
||||
self.healthCondition = 0
|
||||
self.healthBar = SuitHealthBar.SuitHealthBar()
|
||||
self.isDisguised = 0
|
||||
self.isWaiter = 0
|
||||
self.isRental = 0
|
||||
|
@ -368,7 +347,7 @@ class Suit(Avatar.Avatar):
|
|||
part.removeNode()
|
||||
|
||||
self.headParts = []
|
||||
self.removeHealthBar()
|
||||
self.healthBar.delete()
|
||||
Avatar.Avatar.delete(self)
|
||||
|
||||
def setHeight(self, height):
|
||||
|
@ -585,97 +564,18 @@ class Suit(Avatar.Avatar):
|
|||
icons.removeNode()
|
||||
|
||||
def generateHealthBar(self):
|
||||
self.removeHealthBar()
|
||||
model = loader.loadModel('phase_3.5/models/gui/matching_game_gui')
|
||||
button = model.find('**/minnieCircle')
|
||||
model.removeNode()
|
||||
|
||||
button.setScale(3.0)
|
||||
button.setH(180.0)
|
||||
button.setColor(self.healthColors[0])
|
||||
chestNull = self.find('**/joint_attachMeter')
|
||||
button.reparentTo(chestNull)
|
||||
self.healthBar = button
|
||||
glow = BattleProps.globalPropPool.getProp('glow')
|
||||
glow.reparentTo(self.healthBar)
|
||||
glow.setScale(0.28)
|
||||
glow.setPos(-0.005, 0.01, 0.015)
|
||||
glow.setColor(self.healthGlowColors[0])
|
||||
button.flattenLight()
|
||||
self.healthBarGlow = glow
|
||||
self.healthBar.hide()
|
||||
self.healthCondition = 0
|
||||
self.healthBar.generate()
|
||||
self.healthBar.geom.reparentTo(self.find('**/joint_attachMeter'))
|
||||
self.healthBar.geom.setScale(3.0)
|
||||
|
||||
def resetHealthBarForSkele(self):
|
||||
self.healthBar.setPos(0.0, 0.1, 0.0)
|
||||
self.healthBar.geom.setPos(0.0, 0.1, 0.0)
|
||||
|
||||
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.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 or forceUpdate:
|
||||
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 __blinkRed(self, task):
|
||||
if not self.healthBar:
|
||||
return Task.done
|
||||
self.healthBar.setColor(self.healthColors[8], 1)
|
||||
self.healthBarGlow.setColor(self.healthGlowColors[8], 1)
|
||||
if self.healthCondition == 7:
|
||||
self.healthBar.setScale(1.17)
|
||||
return Task.done
|
||||
|
||||
def __blinkGray(self, task):
|
||||
if not self.healthBar:
|
||||
return Task.done
|
||||
self.healthBar.setColor(self.healthColors[9], 1)
|
||||
self.healthBarGlow.setColor(self.healthGlowColors[9], 1)
|
||||
if self.healthCondition == 10:
|
||||
self.healthBar.setScale(1.0)
|
||||
return Task.done
|
||||
|
||||
def removeHealthBar(self):
|
||||
if self.healthBar:
|
||||
self.healthBar.removeNode()
|
||||
self.healthBar = None
|
||||
if self.healthCondition == 9 or self.healthCondition == 10:
|
||||
taskMgr.remove(self.uniqueName('blink-task'))
|
||||
self.healthCondition = 0
|
||||
return
|
||||
self.healthBar.update(float(self.currHP) / float(self.maxHP))
|
||||
|
||||
def getLoseActor(self):
|
||||
if self.loseActor == None:
|
||||
|
|
|
@ -1,66 +1,65 @@
|
|||
from direct.task import Task
|
||||
from direct.task.Task import Task
|
||||
from toontown.battle import BattleProps
|
||||
|
||||
HEALTH_COLORS = (
|
||||
(0, 1, 0, 1),
|
||||
(0.5, 1, 0, 1),
|
||||
(0.75, 1, 0, 1),
|
||||
(1, 1, 0, 1),
|
||||
(1, 0.86, 0, 1),
|
||||
(1, 0.6, 0, 1),
|
||||
(1, 0.5, 0, 1),
|
||||
(1, 0.25, 0, 1.0),
|
||||
(1, 0, 0, 1),
|
||||
(0.3, 0.3, 0.3, 1)
|
||||
)
|
||||
HEALTH_GLOW_COLORS = (
|
||||
(0.25, 1, 0.25, 0.5),
|
||||
(0.5, 1, 0.25, .5),
|
||||
(0.75, 1, 0.25, .5),
|
||||
(1, 1, 0.25, 0.5),
|
||||
(1, 0.866, 0.25, .5),
|
||||
(1, 0.6, 0.25, .5),
|
||||
(1, 0.5, 0.25, 0.5),
|
||||
(1, 0.25, 0.25, 0.5),
|
||||
(1, 0.25, 0.25, 0.5),
|
||||
(0.3, 0.3, 0.3, 0))
|
||||
|
||||
class SuitHealthBar:
|
||||
healthColors = ((0, 1, 0, 1),
|
||||
(0.5, 1, 0, 1),
|
||||
(0.75, 1, 0, 1),
|
||||
(1, 1, 0, 1),
|
||||
(1, 0.86, 0, 1),
|
||||
(1, 0.6, 0, 1),
|
||||
(1, 0.5, 0, 1),
|
||||
(1, 0.25, 0, 1.0),
|
||||
(1, 0, 0, 1),
|
||||
(0.3, 0.3, 0.3, 1))
|
||||
healthGlowColors = ((0.25, 1, 0.25, 0.5),
|
||||
(0.5, 1, 0.25, .5),
|
||||
(0.75, 1, 0.25, .5),
|
||||
(1, 1, 0.25, 0.5),
|
||||
(1, 0.866, 0.25, .5),
|
||||
(1, 0.6, 0.25, .5),
|
||||
(1, 0.5, 0.25, 0.5),
|
||||
(1, 0.25, 0.25, 0.5),
|
||||
(1, 0.25, 0.25, 0.5),
|
||||
(0.3, 0.3, 0.3, 0))
|
||||
|
||||
def __init__(self):
|
||||
print 'New Healthbar'
|
||||
self.geom = None
|
||||
self.geomGlow = None
|
||||
self.healthCondition = 0
|
||||
|
||||
def delete(self):
|
||||
print 'Deleting'
|
||||
if self.geom:
|
||||
self.geom.removeNode()
|
||||
self.geom = None
|
||||
self.geomGlow = None
|
||||
taskMgr.remove('blink-task-%s' % id(self))
|
||||
self.healthCondition = 0
|
||||
print 'Deleted'
|
||||
|
||||
def generate(self):
|
||||
print 'Generating'
|
||||
self.delete()
|
||||
model = loader.loadModel('phase_3.5/models/gui/matching_game_gui')
|
||||
button = model.find('**/minnieCircle')
|
||||
model.removeNode()
|
||||
|
||||
button.setH(180.0)
|
||||
button.setColor(self.healthColors[0])
|
||||
button.setColor(HEALTH_COLORS[0])
|
||||
self.geom = button
|
||||
|
||||
glow = BattleProps.globalPropPool.getProp('glow')
|
||||
glow.reparentTo(self.geom)
|
||||
glow.setScale(0.28)
|
||||
glow.setPos(-0.005, 0.01, 0.015)
|
||||
glow.setColor(self.healthGlowColors[0])
|
||||
glow.setColor(HEALTH_GLOW_COLORS[0])
|
||||
|
||||
button.flattenLight()
|
||||
self.geomGlow = glow
|
||||
self.geom.hide()
|
||||
self.healthCondition = 0
|
||||
print 'Generated'
|
||||
|
||||
def getHealthCondition(self, health):
|
||||
if health > 0.95:
|
||||
|
@ -87,9 +86,7 @@ class SuitHealthBar:
|
|||
|
||||
def update(self, hp, forceUpdate = 0):
|
||||
if not self.geom:
|
||||
print 'Not generated yet'
|
||||
return
|
||||
print 'Updating: %s %s' % (hp, forceUpdate)
|
||||
condition = self.getHealthCondition(hp)
|
||||
|
||||
if self.healthCondition != condition or forceUpdate:
|
||||
|
@ -99,32 +96,20 @@ class SuitHealthBar:
|
|||
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(self.healthColors[condition], 1)
|
||||
self.geomGlow.setColor(self.healthGlowColors[condition], 1)
|
||||
self.geom.setColor(HEALTH_COLORS[condition], 1)
|
||||
self.geomGlow.setColor(HEALTH_GLOW_COLORS[condition], 1)
|
||||
|
||||
self.healthCondition = condition
|
||||
print 'Updated'
|
||||
|
||||
def __blink(self, color):
|
||||
if not self.geom:
|
||||
return
|
||||
|
||||
self.geom.setColor(HEALTH_COLORS[color], 1)
|
||||
self.geomGlow.setColor(HEALTH_GLOW_COLORS[color], 1)
|
||||
|
||||
def __blinkRed(self, task):
|
||||
if not self.geom:
|
||||
return
|
||||
|
||||
print 'Blinking Red'
|
||||
self.geom.setColor(self.healthColors[8], 1)
|
||||
self.geomGlow.setColor(self.healthGlowColors[8], 1)
|
||||
|
||||
if self.healthCondition == 7:
|
||||
self.geom.setScale(1.17)
|
||||
print 'Blinked Red'
|
||||
|
||||
self.__blink(8)
|
||||
|
||||
def __blinkGray(self, task):
|
||||
if not self.geom:
|
||||
return
|
||||
|
||||
print 'Blinking Gray'
|
||||
self.geom.setColor(self.healthColors[9], 1)
|
||||
self.geomGlow.setColor(self.healthGlowColors[9], 1)
|
||||
|
||||
if self.healthCondition == 10:
|
||||
self.geom.setScale(1.0)
|
||||
print 'Blinked Gray'
|
||||
self.__blink(9)
|
Loading…
Reference in a new issue