怪物技能

This commit is contained in:
chenxi 2023-04-16 22:59:00 +08:00
parent fc44d4dc8f
commit b311395f10
6 changed files with 145 additions and 11 deletions

View File

@ -56,7 +56,7 @@ BattleConst.UNIT_STATE = {
INIT = 0, -- 初始化
IDLE = 1, -- 待机
NORMAL_ATTACK = 2, -- 普通攻击
SKILL = 3, -- 技能
SKILL_ATTACK = 3, -- 技能攻击
HURT = 4, -- 受伤
DEAD = 5, -- 死亡
ENTER_BATTLEFIELD = 6, -- 进入战场

View File

@ -44,6 +44,9 @@ function BattleUnitComp:_initBase()
self.buffList = {}
self.sameBuffCount = {}
self.shieldBuffList = {}
self.activeSkillIndex = 1
self.currActiveSkill = nil
self.targetX = nil
self.currState = UNIT_STATE.INIT
end
@ -86,6 +89,21 @@ function BattleUnitComp:getAnimationDuration(aniName)
return duration or 0
end
function BattleUnitComp:useAllSkills(callback)
self.actionOverCallback = callback
self.activeSkillIndex = 1
self.currActiveSkill = self.unitEntity:getActiveSkill(self.activeSkillIndex)
if self.currActiveSkill == nil then
self.actionOverCallback = nil
callback()
return
end
if not self:changeState(UNIT_STATE.SKILL_ATTACK) then
self.actionOverCallback = nil
callback()
end
end
function BattleUnitComp:useNormalSkill(count, callback)
self.baseObject:getTransform():SetAsLastSibling()
self.actionOverCallback = callback
@ -117,8 +135,8 @@ function BattleUnitComp:changeState(state)
self:exitIdleState()
elseif self.currState == UNIT_STATE.NORMAL_ATTACK then
self:exitNormalAttackState()
elseif self.currState == UNIT_STATE.SKILL then
self:exitSkillState()
elseif self.currState == UNIT_STATE.SKILL_ATTACK then
self:exitSkillAttackState()
elseif self.currState == UNIT_STATE.DEAD then
self:exitDeadState()
elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then
@ -130,8 +148,8 @@ function BattleUnitComp:changeState(state)
self:enterIdleState()
elseif state == UNIT_STATE.NORMAL_ATTACK then
self:enterNormalAttackState()
elseif state == UNIT_STATE.SKILL then
self:enterSkillState()
elseif state == UNIT_STATE.SKILL_ATTACK then
self:enterSkillAttackState()
elseif state == UNIT_STATE.DEAD then
self:enterDeadState()
elseif self.currState == UNIT_STATE.BORN then
@ -145,7 +163,7 @@ end
function BattleUnitComp:repeatCurrState()
if self.currState == UNIT_STATE.NORMAL_ATTACK then
return true
elseif self.currState == UNIT_STATE.SKILL then
elseif self.currState == UNIT_STATE.SKILL_ATTACK then
return true
end
return false
@ -240,6 +258,112 @@ function BattleUnitComp:updateHurt(dt)
end
end
function BattleUnitComp:enterSkillAttackState()
self.attackOver = false
self.attackTime = 0
self.currAttackKeyTime = 0.3
self.targetX = nil
if self.currActiveSkill:getMoveType() == BattleConst.SKILL_MOVE_TYPE.MOVE then
self.isMove = true
self:playAnimation(BattleConst.SPINE_ANIMATION_NAME.MOVE, true, false)
self.positionX = self.baseObject:fastGetLocalPosition()
if self.side == BattleConst.SIDE_ATK then
self.targetX = BattleConst.UNIT_FRONT_POS_X
self.moveDirection = 1
else
self.targetX = -BattleConst.UNIT_FRONT_POS_X
self.moveDirection = -1
end
else
self.isMove = false
self.attackTime = 0
local attackName = self.currActiveSkill:getSkillAttackName()
self.currAttackDuration = self:getAnimationDuration(attackName)
self:playAnimation(attackName, false, false)
end
end
function BattleUnitComp:exitSkillAttackState()
end
function BattleUnitComp:updateSkillAttack(dt)
if self.isMove then
local addX = dt*BattleConst.MOVE_SPEED*self.moveDirection
self.positionX = self.positionX + addX
if (self.moveDirection > 0 and self.positionX >= self.targetX) or (self.moveDirection < 0 and self.positionX <= self.targetX) then
self.isMove = false
self.positionX = self.targetX
if self.attackOver then -- 归位后该进行下一次攻击了
self.activeSkillIndex = self.activeSkillIndex + 1
self.currActiveSkill = self.unitEntity:getActiveSkill(self.activeSkillIndex)
if self.currActiveSkill == nil then
self:changeState(UNIT_STATE.IDLE)
local callback = self.actionOverCallback
self.actionOverCallback = nil
if callback then
callback()
end
return
else
if not self:changeState(UNIT_STATE.SKILL_ATTACK) then
local callback = self.actionOverCallback
self.actionOverCallback = nil
callback()
return
end
end
else -- 到位置该攻击了
self.attackTime = 0
local attackName = self.currActiveSkill:getSkillAttackName()
self.currAttackDuration = self:getAnimationDuration(attackName)
self:playAnimation(attackName, false, false)
end
end
self.baseObject:setLocalPosition(self.positionX, 0, 0)
return
end
self.attackTime = self.attackTime + dt
if self.attackTime >= self.currAttackDuration then
self.attackOver = true
self.activeSkillIndex = self.activeSkillIndex + 1
local currActiveSkill = self.unitEntity:getActiveSkill(self.activeSkillIndex)
if currActiveSkill == nil then
if self.targetX then -- 移动过,准备归位
self.isMove = true
self:playAnimation(BattleConst.SPINE_ANIMATION_NAME.MOVE, true, false)
self.positionX = self.baseObject:fastGetLocalPosition()
if self.side == BattleConst.SIDE_ATK then
self.targetX = -BattleConst.INIT_POS_X
self.moveDirection = -1
else
self.targetX = BattleConst.INIT_POS_X
self.moveDirection = 1
end
else
self:changeState(UNIT_STATE.IDLE)
local callback = self.actionOverCallback
self.actionOverCallback = nil
if callback then
callback()
end
end
return
else -- 继续攻击
self.currActiveSkill = currActiveSkill
self.attackTime = 0
self.currAttackKeyTime = 0.3
local attackName = self.currActiveSkill:getSkillAttackName()
self.currAttackDuration = self:getAnimationDuration(attackName)
self:playAnimation(attackName, false, false)
end
else
if self.currAttackKeyTime > 0 and self.attackTime >= self.currAttackKeyTime then -- 到达关键后使用
self.currAttackKeyTime = 0
self:onSkillTakeEffect(self.currActiveSkill)
end
end
end
function BattleUnitComp:enterNormalAttackState()
self.attackOver = false
self.attackTime = 0
@ -463,8 +587,8 @@ function BattleUnitComp:tick(dt)
end
if self.currState == UNIT_STATE.NORMAL_ATTACK then
self:updateNormalAttack(dt)
elseif self.currState == UNIT_STATE.SKILL then
self:updateSkill(dt)
elseif self.currState == UNIT_STATE.SKILL_ATTACK then
self:updateSkillAttack(dt)
elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then
self:updateEnterBattlefieldState(dt)
end

View File

@ -305,8 +305,9 @@ end
function BattleController:enterDefStep()
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_DEF_STEP
-- defTodo
self.defMainUnit:useAllSkills(function()
self:enterDefStepOver()
end)
end
function BattleController:enterDefStepOver()

View File

@ -375,7 +375,7 @@ function BattleData:initHeroData()
modelId = heroEntity:getModelId(),
matchType = matchType,
normalSkill = heroEntity:getHurtSkill(),
activeSkill = {activeSkill},
activeSkills = {activeSkill},
attr = {
hp = hp,
max_hp = hp,

View File

@ -44,6 +44,11 @@ function BattleSkillEntity:getRandomNormalAttackName()
return self.normalSkillNameList[self.normalSkillNameIndex]
end
function BattleSkillEntity:getSkillAttackName()
-- return self.skillInfo.name_act
return "atk1"
end
function BattleSkillEntity:getEffectList()
return self.effectList
end

View File

@ -53,6 +53,10 @@ function BattleUnitEntity:getNormalSkill()
return self.normalSkill
end
function BattleUnitEntity:getActiveSkill(index)
return self.activeSkills[index]
end
function BattleUnitEntity:takeDamageOrCure(num)
return self.team:takeDamageOrCure(num)
end