怪物技能
This commit is contained in:
parent
fc44d4dc8f
commit
b311395f10
@ -56,7 +56,7 @@ BattleConst.UNIT_STATE = {
|
|||||||
INIT = 0, -- 初始化
|
INIT = 0, -- 初始化
|
||||||
IDLE = 1, -- 待机
|
IDLE = 1, -- 待机
|
||||||
NORMAL_ATTACK = 2, -- 普通攻击
|
NORMAL_ATTACK = 2, -- 普通攻击
|
||||||
SKILL = 3, -- 技能
|
SKILL_ATTACK = 3, -- 技能攻击
|
||||||
HURT = 4, -- 受伤
|
HURT = 4, -- 受伤
|
||||||
DEAD = 5, -- 死亡
|
DEAD = 5, -- 死亡
|
||||||
ENTER_BATTLEFIELD = 6, -- 进入战场
|
ENTER_BATTLEFIELD = 6, -- 进入战场
|
||||||
|
|||||||
@ -44,6 +44,9 @@ function BattleUnitComp:_initBase()
|
|||||||
self.buffList = {}
|
self.buffList = {}
|
||||||
self.sameBuffCount = {}
|
self.sameBuffCount = {}
|
||||||
self.shieldBuffList = {}
|
self.shieldBuffList = {}
|
||||||
|
self.activeSkillIndex = 1
|
||||||
|
self.currActiveSkill = nil
|
||||||
|
self.targetX = nil
|
||||||
self.currState = UNIT_STATE.INIT
|
self.currState = UNIT_STATE.INIT
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -86,6 +89,21 @@ function BattleUnitComp:getAnimationDuration(aniName)
|
|||||||
return duration or 0
|
return duration or 0
|
||||||
end
|
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)
|
function BattleUnitComp:useNormalSkill(count, callback)
|
||||||
self.baseObject:getTransform():SetAsLastSibling()
|
self.baseObject:getTransform():SetAsLastSibling()
|
||||||
self.actionOverCallback = callback
|
self.actionOverCallback = callback
|
||||||
@ -117,8 +135,8 @@ function BattleUnitComp:changeState(state)
|
|||||||
self:exitIdleState()
|
self:exitIdleState()
|
||||||
elseif self.currState == UNIT_STATE.NORMAL_ATTACK then
|
elseif self.currState == UNIT_STATE.NORMAL_ATTACK then
|
||||||
self:exitNormalAttackState()
|
self:exitNormalAttackState()
|
||||||
elseif self.currState == UNIT_STATE.SKILL then
|
elseif self.currState == UNIT_STATE.SKILL_ATTACK then
|
||||||
self:exitSkillState()
|
self:exitSkillAttackState()
|
||||||
elseif self.currState == UNIT_STATE.DEAD then
|
elseif self.currState == UNIT_STATE.DEAD then
|
||||||
self:exitDeadState()
|
self:exitDeadState()
|
||||||
elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then
|
elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then
|
||||||
@ -130,8 +148,8 @@ function BattleUnitComp:changeState(state)
|
|||||||
self:enterIdleState()
|
self:enterIdleState()
|
||||||
elseif state == UNIT_STATE.NORMAL_ATTACK then
|
elseif state == UNIT_STATE.NORMAL_ATTACK then
|
||||||
self:enterNormalAttackState()
|
self:enterNormalAttackState()
|
||||||
elseif state == UNIT_STATE.SKILL then
|
elseif state == UNIT_STATE.SKILL_ATTACK then
|
||||||
self:enterSkillState()
|
self:enterSkillAttackState()
|
||||||
elseif state == UNIT_STATE.DEAD then
|
elseif state == UNIT_STATE.DEAD then
|
||||||
self:enterDeadState()
|
self:enterDeadState()
|
||||||
elseif self.currState == UNIT_STATE.BORN then
|
elseif self.currState == UNIT_STATE.BORN then
|
||||||
@ -145,7 +163,7 @@ end
|
|||||||
function BattleUnitComp:repeatCurrState()
|
function BattleUnitComp:repeatCurrState()
|
||||||
if self.currState == UNIT_STATE.NORMAL_ATTACK then
|
if self.currState == UNIT_STATE.NORMAL_ATTACK then
|
||||||
return true
|
return true
|
||||||
elseif self.currState == UNIT_STATE.SKILL then
|
elseif self.currState == UNIT_STATE.SKILL_ATTACK then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
@ -240,6 +258,112 @@ function BattleUnitComp:updateHurt(dt)
|
|||||||
end
|
end
|
||||||
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()
|
function BattleUnitComp:enterNormalAttackState()
|
||||||
self.attackOver = false
|
self.attackOver = false
|
||||||
self.attackTime = 0
|
self.attackTime = 0
|
||||||
@ -463,8 +587,8 @@ function BattleUnitComp:tick(dt)
|
|||||||
end
|
end
|
||||||
if self.currState == UNIT_STATE.NORMAL_ATTACK then
|
if self.currState == UNIT_STATE.NORMAL_ATTACK then
|
||||||
self:updateNormalAttack(dt)
|
self:updateNormalAttack(dt)
|
||||||
elseif self.currState == UNIT_STATE.SKILL then
|
elseif self.currState == UNIT_STATE.SKILL_ATTACK then
|
||||||
self:updateSkill(dt)
|
self:updateSkillAttack(dt)
|
||||||
elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then
|
elseif self.currState == UNIT_STATE.ENTER_BATTLEFIELD then
|
||||||
self:updateEnterBattlefieldState(dt)
|
self:updateEnterBattlefieldState(dt)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -305,8 +305,9 @@ end
|
|||||||
function BattleController:enterDefStep()
|
function BattleController:enterDefStep()
|
||||||
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_DEF_STEP
|
self.roundStep = BattleConst.BATTLE_ROUND_STEP.ON_DEF_STEP
|
||||||
|
|
||||||
-- defTodo
|
self.defMainUnit:useAllSkills(function()
|
||||||
self:enterDefStepOver()
|
self:enterDefStepOver()
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function BattleController:enterDefStepOver()
|
function BattleController:enterDefStepOver()
|
||||||
|
|||||||
@ -375,7 +375,7 @@ function BattleData:initHeroData()
|
|||||||
modelId = heroEntity:getModelId(),
|
modelId = heroEntity:getModelId(),
|
||||||
matchType = matchType,
|
matchType = matchType,
|
||||||
normalSkill = heroEntity:getHurtSkill(),
|
normalSkill = heroEntity:getHurtSkill(),
|
||||||
activeSkill = {activeSkill},
|
activeSkills = {activeSkill},
|
||||||
attr = {
|
attr = {
|
||||||
hp = hp,
|
hp = hp,
|
||||||
max_hp = hp,
|
max_hp = hp,
|
||||||
|
|||||||
@ -44,6 +44,11 @@ function BattleSkillEntity:getRandomNormalAttackName()
|
|||||||
return self.normalSkillNameList[self.normalSkillNameIndex]
|
return self.normalSkillNameList[self.normalSkillNameIndex]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function BattleSkillEntity:getSkillAttackName()
|
||||||
|
-- return self.skillInfo.name_act
|
||||||
|
return "atk1"
|
||||||
|
end
|
||||||
|
|
||||||
function BattleSkillEntity:getEffectList()
|
function BattleSkillEntity:getEffectList()
|
||||||
return self.effectList
|
return self.effectList
|
||||||
end
|
end
|
||||||
|
|||||||
@ -53,6 +53,10 @@ function BattleUnitEntity:getNormalSkill()
|
|||||||
return self.normalSkill
|
return self.normalSkill
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function BattleUnitEntity:getActiveSkill(index)
|
||||||
|
return self.activeSkills[index]
|
||||||
|
end
|
||||||
|
|
||||||
function BattleUnitEntity:takeDamageOrCure(num)
|
function BattleUnitEntity:takeDamageOrCure(num)
|
||||||
return self.team:takeDamageOrCure(num)
|
return self.team:takeDamageOrCure(num)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user