This commit is contained in:
chenxi 2023-04-14 21:21:03 +08:00
parent 93ee4653af
commit c6ae8e7c99
6 changed files with 43 additions and 3 deletions

View File

@ -25,7 +25,7 @@ function BattleUnitComp:initPosition()
end
function BattleUnitComp:playBorn()
self:playAnimation(SPINE_ANIMATION_NAME.IDLE, true, false)
self:changeState(UNIT_STATE.IDLE)
end
function BattleUnitComp:_initBase()
@ -361,8 +361,7 @@ function BattleUnitComp:takeDamageOrCure(atker, buff, num, effectType, effectSta
end
local x, y, z = self.baseObject:fastGetLocalPosition()
self:showEffectNumber(num, x, y)
local hpPercent = self.unitEntity:getHpPercent()
-- self.controlUnitComp:RefreshHpBar(hpPercent)
self.battleController:refreshHp(self.side, self.unitEntity:getHp(), self.unitEntity:getHpPercent())
-- local shieldHp = self.unitEntity:getShieldHp()
-- if shieldHp and shieldHp.value > 0 then

View File

@ -164,6 +164,7 @@ function BattleController:initAtkUnits(callback)
local function onloadFinished()
count = count + 1
if count == totalCount then
self.battleUI:refreshAtkHp(atkTeam:getHp(), atkTeam:getHpPercent())
callback()
end
end
@ -186,6 +187,14 @@ function BattleController:initAtkUnits(callback)
end
end
function BattleController:refreshHp(side, num, percent)
if side == BattleConst.SIDE_ATK then
self.battleUI:refreshAtkHp(num, percent)
else
self.battleUI:refreshDefHp(num, percent)
end
end
function BattleController:getOtherSideMainUnit(side)
if side == BattleConst.SIDE_ATK then
return self.defMainUnit

View File

@ -23,6 +23,7 @@ function BattleControllerStage:initDefUnits(callback)
self.defUnits[unitEntity:getMatchType()] = monsterComp
table.insert(self.allUnits, monsterComp)
self.defMainUnit = monsterComp
self.battleUI:refreshDefHp(unitEntity:getHp(), unitEntity:getHpPercent())
callback()
end)
end

View File

@ -36,6 +36,7 @@ function BattleUI:_display()
self:initSkill()
self:initBattlefield()
self:initNumberNode()
self:initHpNode()
end
function BattleUI:_addListeners()
@ -88,6 +89,24 @@ function BattleUI:getBattleNumber()
return self.battleNumber
end
function BattleUI:initHpNode()
self.hpNode = self.uiMap["battle_ui.battle_hp_node"]
self.hpProgressLeft = self.uiMap["battle_ui.battle_hp_node.progress_left"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER)
self.hpProgressRight = self.uiMap["battle_ui.battle_hp_node.progress_right"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER)
self.hpTextRight = self.uiMap["battle_ui.battle_hp_node.text_right"]
self.hpTextLeft = self.uiMap["battle_ui.battle_hp_node.text_left"]
end
function BattleUI:refreshAtkHp(num, percent)
self.hpTextLeft:setText(GFunc.num2Str(num))
self.hpProgressLeft.value = percent
end
function BattleUI:refreshDefHp(num, percent)
self.hpTextRight:setText(GFunc.num2Str(num))
self.hpProgressRight.value = percent
end
function BattleUI:refreshSkill(elementMap)
if not self.skillObjs then
return

View File

@ -113,6 +113,10 @@ function BattleTeamEntity:getMembersCount()
return self.membersCount
end
function BattleTeamEntity:getHp()
return self.attr.hp
end
function BattleTeamEntity:getHpPercent()
return self.attr.hp / self.attr.max_hp
end
@ -174,6 +178,9 @@ function BattleTeamEntity:addShield(num)
end
function BattleTeamEntity:takeDamageOrCure(num)
if self.isDead then
return 0
end
if num < 0 then -- 是伤害的话处理一下护盾
num = self:handleShield(num)
if num >= 0 then -- 这次伤害被抵消了
@ -185,6 +192,7 @@ function BattleTeamEntity:takeDamageOrCure(num)
local hurtEventNum = 0
if self.attr.hp <= 0 then -- 死了
hurtEventNum = -hpBefore
self.attr.hp = 0
self:die()
elseif self.attr.hp < self.attr.max_hp then
hurtEventNum = num

View File

@ -57,6 +57,10 @@ function BattleUnitEntity:takeDamageOrCure(num)
return self.team:takeDamageOrCure(num)
end
function BattleUnitEntity:getHp()
return self.team:getHp()
end
function BattleUnitEntity:getHpPercent()
return self.team:getHpPercent()
end