320 lines
9.3 KiB
Lua
320 lines
9.3 KiB
Lua
SkillManager = {}
|
|
local this = SkillManager
|
|
|
|
local skillPool = BattleObjectPool.New(function ()
|
|
return Skill:New()
|
|
end)
|
|
|
|
--
|
|
this.DeadSkillList = {} -- 人物死亡后技能队列,死亡技能优先级最高
|
|
this.MonsterSkillList = {}
|
|
this.SkillList = {}
|
|
this.IsSkilling = false
|
|
this.MaxSkillCount = 20 -- 单个回合内最多释放20次技能
|
|
-- 初始化
|
|
function this.Init()
|
|
this.CurSkillCount = 0
|
|
-- 清除轮转方法,防止收到上一局战斗的影响
|
|
this.TurnRoundFunc = nil
|
|
this.MonsterCheckFunc = nil
|
|
this.Clear()
|
|
end
|
|
|
|
function this.CheckMaxCount()
|
|
if not this.CurSkillCount then
|
|
this.CurSkillCount = 0
|
|
end
|
|
if this.CurSkillCount < this.MaxSkillCount then
|
|
this.CurSkillCount = this.CurSkillCount + 1
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
|
|
--
|
|
function this.AddMonsterSkill(skill)
|
|
-- 如果超出最大限制则不再追加技能
|
|
if not this.CheckMaxCount() then
|
|
return
|
|
end
|
|
if skill.type == BattleSkillType.Monster then
|
|
table.insert(this.MonsterSkillList, skill)
|
|
end
|
|
BattleLogManager.Log(
|
|
"Add Monster Skill",
|
|
"camp", skill.owner.camp,
|
|
"pos", skill.owner.position,
|
|
"type", BattleSkillType.Monster
|
|
)
|
|
--判断主角连击属性
|
|
local addPro=skill.owner:GetRoleData(RoleDataName.Speed)
|
|
if skill.owner.position==100 then
|
|
BattleUtil.RandomAction(addPro,function()
|
|
if skill.type == BattleSkillType.Monster then
|
|
local addSkill=skill
|
|
table.insert(this.MonsterSkillList, addSkill)
|
|
BattleLogManager.Log(
|
|
"Add Monster continue Skill",
|
|
"camp", skill.owner.camp,
|
|
"pos", skill.owner.position,
|
|
"type", BattleSkillType.Monster
|
|
)
|
|
end
|
|
end)
|
|
end
|
|
return skill
|
|
end
|
|
|
|
|
|
-- 向技能列表中追加技能
|
|
function this.AddSkill(caster, effectData, type, targets, isAdd, isRage,isTriggerJudge,isloop)
|
|
-- 如果超出最大限制则不再追加技能
|
|
if not this.CheckMaxCount() then
|
|
return
|
|
end
|
|
BattleLogManager.Log(
|
|
"Add Skill",
|
|
"camp", caster.camp,
|
|
"pos", caster.position,
|
|
"type", type,
|
|
"isRage", tostring(isRage),
|
|
"isAdd", tostring(isAdd),
|
|
"isTriggerJudge", tostring(isTriggerJudge),
|
|
"targets", targets and #targets or "0"
|
|
)
|
|
local skill = skillPool:Get()
|
|
skill:Init(caster, effectData, type, targets, isAdd, isRage,isTriggerJudge)
|
|
if isloop then
|
|
skill.isNotLoop=isloop
|
|
end
|
|
if type == BattleSkillType.DeadSkill then -- 死亡技能加入单独的对列
|
|
table.insert(this.DeadSkillList, skill)
|
|
else
|
|
table.insert(this.SkillList, skill)
|
|
end
|
|
return skill
|
|
end
|
|
-- 插入技能到技能列表首位
|
|
function this.InsertSkill(caster, effectData, type, targets, isAdd, isRage,isTriggerJudge,isLoop)
|
|
-- 如果超出最大限制则不再追加技能
|
|
if not this.CheckMaxCount() then
|
|
return
|
|
end
|
|
BattleLogManager.Log(
|
|
"Insert Skill",
|
|
"camp", caster.camp,
|
|
"pos", caster.position,
|
|
"type", type,
|
|
"isRage", tostring(isRage),
|
|
"isAdd", tostring(isAdd),
|
|
"isTriggerJudge", tostring(isTriggerJudge),
|
|
"isLoop", tostring(isLoop),
|
|
"targets", targets and #targets or "0"
|
|
)
|
|
|
|
local skill = skillPool:Get()
|
|
|
|
--角色被混乱后
|
|
if isTriggerJudge==nil then
|
|
isTriggerJudge=true
|
|
end
|
|
if caster.ctrl_chaos and type~=BattleSkillType.DeadSkill then
|
|
type=BattleSkillType.ChaosNormal
|
|
--混乱普攻使用普攻特效
|
|
effectData={caster.skill[1],caster.skill[2],caster.skill[3],caster.skill[4],{100001,{1,1,1}}}
|
|
isTriggerJudge=false
|
|
end
|
|
|
|
if caster.ctrl_lock and type~=BattleSkillType.DeadSkill then
|
|
type=BattleSkillType.ChaosNormal
|
|
--嘲讽普攻使用普攻特效
|
|
effectData={caster.skill[1],caster.skill[2],caster.skill[3],caster.skill[4],{200221,{1,1,1}}}
|
|
isTriggerJudge=false
|
|
end
|
|
skill:Init(caster, effectData, type, targets, isAdd, isRage,isTriggerJudge)
|
|
skill.isNotLoop=isLoop
|
|
if type == BattleSkillType.DeadSkill then -- 死亡技能加入单独的对列
|
|
table.insert(this.DeadSkillList, 1, skill)
|
|
else
|
|
table.insert(this.SkillList, 1, skill)
|
|
end
|
|
return skill
|
|
end
|
|
-- 获取是否拥有我的技能未释放
|
|
function this.HaveMySkill(role)
|
|
for _, skill in ipairs(this.DeadSkillList) do
|
|
if skill.owner == role then
|
|
return true
|
|
end
|
|
end
|
|
for _, skill in ipairs(this.SkillList) do
|
|
if skill.owner == role then
|
|
return true
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
|
|
-- 判断是否有即将释放的技能
|
|
function this.IsSkillEmpty()
|
|
if this.IsSkilling then
|
|
-- LogError("正在释放技能")
|
|
return false
|
|
end
|
|
if this.MonsterSkillList and #this.MonsterSkillList > 0 then
|
|
return false
|
|
end
|
|
if this.DeadSkillList and #this.DeadSkillList > 0 then
|
|
return false
|
|
end
|
|
if this.SkillList and #this.SkillList > 0 then
|
|
return false
|
|
end
|
|
return true
|
|
end
|
|
|
|
|
|
-- 设置用于轮转的方法
|
|
function this.SetTurnRoundFunc(func)
|
|
this.TurnRoundFunc = func
|
|
end
|
|
function this.CheckTurnRound()
|
|
-- 如果正在释放技能
|
|
-- if this.IsSkilling then
|
|
-- LogError("正在释放技能")
|
|
-- return
|
|
-- end
|
|
-- 如果技能列表部位为空
|
|
if not this.IsSkillEmpty() then
|
|
return
|
|
end
|
|
-- 没有技能释放的时候才轮转
|
|
if this.TurnRoundFunc then
|
|
BattleLogic.WaitForTrigger(0.3, function()
|
|
-- 清除数量限制
|
|
if this.TurnRoundFunc then
|
|
this.CurSkillCount = 0
|
|
this.TurnRoundFunc()
|
|
this.TurnRoundFunc = nil
|
|
end
|
|
end)
|
|
end
|
|
end
|
|
|
|
-- 检测是否需要等待灵兽技能
|
|
function this.CheckMonsterSkill(func)
|
|
this.MonsterCheckFunc = func
|
|
-- 判断是否可以向下执行
|
|
if not this.IsSkilling and (not this.MonsterSkillList or #this.MonsterSkillList == 0) then
|
|
--
|
|
if this.MonsterCheckFunc then
|
|
local func = this.MonsterCheckFunc
|
|
-- 置空方法放到回调之前,避免再会调中再次调用检测方法导致方法被删除
|
|
this.MonsterCheckFunc = nil
|
|
func()
|
|
end
|
|
end
|
|
end
|
|
|
|
--
|
|
function this.Update()
|
|
-- 如果正在引导战斗
|
|
if BattleManager and BattleManager.IsGuidePause() then
|
|
return
|
|
end
|
|
--
|
|
if this.IsSkilling then
|
|
return
|
|
end
|
|
|
|
|
|
if this.MonsterSkillList and #this.MonsterSkillList > 0 then
|
|
local skill = this.MonsterSkillList[1]
|
|
table.remove(this.MonsterSkillList, 1)
|
|
this.IsSkilling = true
|
|
if skill:canCastSkill() then
|
|
skill:Cast(function()
|
|
-- 检测一下轮转
|
|
this.IsSkilling = false
|
|
-- this.CheckTurnRound()
|
|
if this.MonsterCheckFunc then
|
|
this.CheckMonsterSkill(this.MonsterCheckFunc)
|
|
else
|
|
this.CheckMonsterSkill(this.CheckTurnRound)
|
|
end
|
|
end)
|
|
else
|
|
-- 检测一下轮转
|
|
this.IsSkilling = false
|
|
-- this.CheckTurnRound()
|
|
-- 检测一次灵兽技能
|
|
if this.MonsterCheckFunc then
|
|
this.CheckMonsterSkill(this.MonsterCheckFunc)
|
|
else
|
|
this.CheckMonsterSkill(this.CheckTurnRound)
|
|
end
|
|
end
|
|
|
|
return
|
|
end
|
|
|
|
-- 判断是否有死亡技能
|
|
-- 跟佳琦对的是角色死后只有死亡后释放的技能才能释放(DeadSkill) by:王振兴 2020/09/02 18:53
|
|
if this.DeadSkillList and #this.DeadSkillList > 0 then
|
|
local skill = this.DeadSkillList[1]
|
|
table.remove(this.DeadSkillList, 1)
|
|
this.IsSkilling = true
|
|
if skill.owner:IsDead() then
|
|
skill.owner:SkillCast(skill, function()
|
|
skill:Dispose()
|
|
skillPool:Put(skill)
|
|
this.IsSkilling = false
|
|
-- 检测一下轮转
|
|
this.CheckTurnRound()
|
|
end)
|
|
else
|
|
this.IsSkilling = false
|
|
this.CheckTurnRound()
|
|
end
|
|
|
|
return
|
|
end
|
|
|
|
|
|
-- 判断
|
|
if this.SkillList and #this.SkillList > 0 then
|
|
local skill = this.SkillList[1]
|
|
table.remove(this.SkillList, 1)
|
|
this.IsSkilling = true
|
|
-- 检测技能释放 只有角色不是死亡状态或角色身上有不灭
|
|
if (not skill.owner:IsDead() or BattleUtil.CheckIsNoDead(skill.owner)) then
|
|
skill.owner:SkillCast(skill, function()
|
|
skill:Dispose()
|
|
skillPool:Put(skill)
|
|
this.IsSkilling = false
|
|
-- 检测一下轮转
|
|
this.CheckTurnRound()
|
|
end)
|
|
else
|
|
this.IsSkilling = false
|
|
this.CheckTurnRound()
|
|
end
|
|
return
|
|
end
|
|
|
|
end
|
|
|
|
-- 清除
|
|
function this.Clear()
|
|
for _, skill in ipairs(this.SkillList) do
|
|
skill:Dispose()
|
|
skillPool:Put(skill)
|
|
end
|
|
this.MonsterSkillList = {}
|
|
this.DeadSkillList = {}
|
|
this.SkillList = {}
|
|
this.IsSkilling = false
|
|
end
|
|
|
|
|
|
return SkillManager |