SkillManager.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. SkillManager = {}
  2. local this = SkillManager
  3. local skillPool = BattleObjectPool.New(function ()
  4. return Skill:New()
  5. end)
  6. --
  7. this.SkillList = {}
  8. this.IsSkilling = false
  9. -- 初始化
  10. function this.Init()
  11. this.Clear()
  12. end
  13. -- 向技能列表中追加技能
  14. function this.AddSkill(caster, effectData, type, targets, isAdd)
  15. local skill = skillPool:Get()
  16. skill:Init(caster, effectData, type, targets, isAdd)
  17. table.insert(this.SkillList, skill)
  18. return skill
  19. end
  20. -- 插入技能到技能列表首位
  21. function this.InsertSkill(caster, effectData, type, targets, isAdd, skillSubType)
  22. local skill = skillPool:Get()
  23. skill:Init(caster, effectData, type, targets, isAdd, skillSubType)
  24. table.insert(this.SkillList, 1, skill)
  25. return skill
  26. end
  27. -- 插入技能到后一位
  28. function this.InsertSkillAfter(caster, effectData, type, targets, isAdd, skillSubType)
  29. local skill = skillPool:Get()
  30. skill:Init(caster, effectData, type, targets, isAdd, skillSubType)
  31. local index = #this.SkillList
  32. table.insert(this.SkillList, index + 1, skill)
  33. return skill
  34. end
  35. -- 获取是否拥有我的技能未释放
  36. function this.HaveMySkill(role)
  37. for _, skill in ipairs(this.SkillList) do
  38. if skill.owner == role then
  39. return true
  40. end
  41. end
  42. return false
  43. end
  44. --是否有追加技能
  45. function this.HaveAddSkill(role)
  46. local skill = this.SkillList[1]
  47. if skill.owner.Equle(role) then
  48. return true
  49. end
  50. return false
  51. end
  52. -- 设置用于轮转的方法
  53. function this.SetTurnRoundFunc(func)
  54. this.TurnRoundFunc = func
  55. end
  56. function this.CheckTurnRound()
  57. if this.IsSkilling then
  58. return
  59. end
  60. if this.SkillList and #this.SkillList > 0 then
  61. return
  62. end
  63. -- 没有技能释放的时候才轮转
  64. if this.TurnRoundFunc then
  65. BattleLogic.WaitForTrigger(0.3, function()
  66. this.TurnRoundFunc() --< 轮转时 会赋值 屏蔽置空
  67. -- this.TurnRoundFunc = nil
  68. end)
  69. end
  70. end
  71. --
  72. function this.Update()
  73. -- 如果正在引导战斗
  74. if BattleManager and BattleManager.IsGuidePause() then
  75. return
  76. end
  77. --
  78. if this.IsSkilling then
  79. return
  80. end
  81. if not this.SkillList or #this.SkillList == 0 then
  82. return
  83. end
  84. local skill = this.SkillList[1]
  85. table.remove(this.SkillList, 1)
  86. this.IsSkilling = true
  87. -- 检测技能释放
  88. skill.owner:SkillCast(skill, function()
  89. -- LogError("SkillCast"..skill.owner.roleId)
  90. skill:Dispose()
  91. skillPool:Put(skill)
  92. this.IsSkilling = false
  93. -- 检测一下轮转
  94. this.CheckTurnRound()
  95. end)
  96. end
  97. -- 清除
  98. function this.Clear()
  99. for _, skill in ipairs(this.SkillList) do
  100. skill:Dispose()
  101. skillPool:Put(skill)
  102. end
  103. this.SkillList = {}
  104. this.IsSkilling = false
  105. end
  106. return SkillManager