From cbba15794a05d7838f7df0454582583f94afbfdf Mon Sep 17 00:00:00 2001 From: xiekaidong Date: Thu, 25 May 2023 10:37:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=8B=E5=8F=97?= =?UTF-8?q?=E5=87=BB=E5=8A=A8=E7=94=BB=E5=AE=B9=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../battle/component/battle_unit_comp.lua | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lua/app/module/battle/component/battle_unit_comp.lua b/lua/app/module/battle/component/battle_unit_comp.lua index 9174348f..3a1e626a 100644 --- a/lua/app/module/battle/component/battle_unit_comp.lua +++ b/lua/app/module/battle/component/battle_unit_comp.lua @@ -16,7 +16,6 @@ local HURT_STATE_CRIT = BattleConst.HURT_STATE_CRIT local EFFECT_TYPE = BattleConst.EFFECT_TYPE local TIME_FACTOR = BattleConst.TIME_FACTOR local HURT_ANI_NAME_LIST = {SPINE_ANIMATION_NAME.HIT, SPINE_ANIMATION_NAME.HIT_2} -local HURT_ANI_NAME_LIST_COUNT = 2 function BattleUnitComp:ctor() end @@ -114,6 +113,19 @@ function BattleUnitComp:initWithEntity(modelId, entity, battleController, target self:initPosition() self:initPassiveSkills() self:playBorn() + self:initHitAniInfo() +end + +function BattleUnitComp:initHitAniInfo() + self.hurtAniNameList = {} + self.hurtAniNameCount = 0 + for _, name in ipairs(HURT_ANI_NAME_LIST) do + local duration = self:getAnimationDuration(name) + if duration > 0 then + table.insert(self.hurtAniNameList, name) + self.hurtAniNameCount = self.hurtAniNameCount + 1 + end + end end function BattleUnitComp:prepare() @@ -692,7 +704,10 @@ end function BattleUnitComp:playHurt() if self.currState == UNIT_STATE.IDLE or self.currState == UNIT_STATE.VERITGO then - local name = HURT_ANI_NAME_LIST[math.random(1, HURT_ANI_NAME_LIST_COUNT)] + if self.hurtAniNameCount <= 0 then + return + end + local name = self.hurtAniNameList[math.random(1, self.hurtAniNameCount)] self.playSubAniTime = 0 self.curHurtName = name if self.playSubAniDuration[name] == nil then