SkillManager.lua 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. WYLog("SkillManager 1111")
  16. local skill = skillPool:Get()
  17. skill:Init(caster, effectData, type, targets, isAdd)
  18. table.insert(this.SkillList, skill)
  19. WYLog("SkillManager 2222")
  20. return skill
  21. end
  22. -- 插入技能到技能列表首位
  23. function this.InsertSkill(caster, effectData, type, targets, isAdd)
  24. local skill = skillPool:Get()
  25. skill:Init(caster, effectData, type, targets, isAdd)
  26. table.insert(this.SkillList, 1, skill)
  27. return skill
  28. end
  29. -- 获取是否拥有我的技能未释放
  30. function this.HaveMySkill(role)
  31. for _, skill in ipairs(this.SkillList) do
  32. if skill.owner == role then
  33. return true
  34. end
  35. end
  36. return false
  37. end
  38. -- 设置用于轮转的方法
  39. function this.SetTurnRoundFunc(func)
  40. -- LogYellow("### 设置CastSkill回调")
  41. -- WYLog(func)
  42. this.TurnRoundFunc = func
  43. end
  44. function this.CheckTurnRound()
  45. if this.IsSkilling then
  46. return
  47. end
  48. if this.SkillList and #this.SkillList > 0 then
  49. return
  50. end
  51. -- 没有技能释放的时候才轮转
  52. -- LogYellow("SkillManager 轮转")
  53. -- WYLog(this.TurnRoundFunc)
  54. if this.TurnRoundFunc then
  55. BattleLogic.WaitForTrigger(0.3, function()
  56. -- LogBlue(Language[10239])
  57. this.TurnRoundFunc() --< 轮转时 会赋值 屏蔽置空
  58. -- this.TurnRoundFunc = nil
  59. -- LogYellow("SkillManager 完成清理")
  60. -- WYLog(this.TurnRoundFunc)
  61. end)
  62. end
  63. end
  64. --
  65. function this.Update()
  66. --
  67. if this.IsSkilling then
  68. return
  69. end
  70. if not this.SkillList or #this.SkillList == 0 then
  71. return
  72. end
  73. local skill = this.SkillList[1]
  74. table.remove(this.SkillList, 1)
  75. this.IsSkilling = true
  76. -- 检测技能释放
  77. skill.owner:SkillCast(skill, function()
  78. skill:Dispose()
  79. skillPool:Put(skill)
  80. this.IsSkilling = false
  81. -- 检测一下轮转
  82. this.CheckTurnRound()
  83. end)
  84. end
  85. -- 清除
  86. function this.Clear()
  87. for _, skill in ipairs(this.SkillList) do
  88. skill:Dispose()
  89. skillPool:Put(skill)
  90. end
  91. this.SkillList = {}
  92. this.IsSkilling = false
  93. end
  94. return SkillManager