FightUnitLogic.lua 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. FightUnitLogic = {}
  2. FightUnitLogic.__index = FightUnitLogic
  3. local Random = Random
  4. local floor = math.floor
  5. local max = math.max
  6. local min = math.min
  7. local skillPool = BattleObjectPool.New(function ()
  8. return Skill:New()
  9. end)
  10. function FightUnitLogic.New()
  11. local instance = {type = 0, unitData = 0, data = RoleData.New(), camp = 0, name = 0,
  12. Event = BattleEvent:New()}
  13. setmetatable(instance, FightUnitLogic)
  14. return instance
  15. end
  16. function FightUnitLogic:Init(data)
  17. self.type = data.type
  18. self.unitData = data
  19. if data.property == nil or next(data.property) == nil or #data.property == 0 then --< 无属性的服务端没传战斗属性 用下值
  20. self.data:Init(self, {0,0,0,0,0, 0,0,0,0,10000, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0})
  21. else
  22. self.data:Init(self, data.property)
  23. end
  24. self.camp = data.camp --阵营 0:我方 1:敌方
  25. self.name = data.name
  26. self.position = 99999 --< 应对log nil问题
  27. self.Event:ClearEvent()
  28. self.skill = data.skill
  29. self.lockTarget = nil --嘲讽
  30. self.ctrl_dizzy = false --眩晕 不能释放所有技能
  31. self.ctrl_slient = false --沉默 只能1技能
  32. self.ctrl_palsy = false --麻痹 只能2技能
  33. self.ctrl_noheal = false --禁疗
  34. self.ctrl_blind = false --致盲
  35. self.ctrltimes = 0 --< 控制次数
  36. self.deadFilter = true -- 控制死亡,置为false则角色暂时无法死亡
  37. self.effect218times = 0 --< effect 218 触发次数
  38. self.skilling = false --< 技能间
  39. end
  40. function FightUnitLogic:Dispose()
  41. end
  42. -- 判断角色是否可以释放技能
  43. function FightUnitLogic:IsAvailable()
  44. return true
  45. end
  46. -- 释放技能
  47. function FightUnitLogic:SkillCast(skill, func)
  48. local _CastDone = function()
  49. if func then
  50. func()
  51. end
  52. end
  53. -- 角色不可用直接结束技能释放
  54. if not skill or not self:IsAvailable() then
  55. _CastDone()
  56. return
  57. end
  58. skill:CastUnit(_CastDone)
  59. end
  60. -- 加入一个技能
  61. -- type 加入的技能类型 --< 修改为physical magic
  62. -- targets 指定目标
  63. -- isAdd 是否是追加技能
  64. -- effectData 战斗技能数据
  65. function FightUnitLogic:AddSkill(type, isAdd, targets, effectData)
  66. WYLog("FightUnitLogic:AddSkill")
  67. SkillManager.AddSkill(self, effectData, type, targets, isAdd)
  68. -- BattleLogManager.Log(
  69. -- "Add Skill",
  70. -- "camp", self.camp,
  71. -- "pos", self.position,
  72. -- "type", type,
  73. -- -- "isRage", tostring(isRage),
  74. -- "isAdd", tostring(isAdd),
  75. -- "targets", targets and #targets or "0"
  76. -- )
  77. end
  78. -- 正常触发技能
  79. function FightUnitLogic:CastSkill(func)
  80. -- 设置轮转方法
  81. SkillManager.SetTurnRoundFunc(func)
  82. local haveSkill = false
  83. local isHave, skilldata = self:CheckSkill(SkillBaseType.Magic)
  84. -- 释放大技能
  85. LogBlue(Language[10234])
  86. if isHave then
  87. self:AddSkill(SkillBaseType.Magic, true, nil, skilldata)
  88. haveSkill = true
  89. else
  90. local isHave_p, skilldata_p = self:CheckSkill(SkillBaseType.Physical)
  91. if isHave_p then
  92. self:AddSkill(SkillBaseType.Physical, true, nil, skilldata_p)
  93. haveSkill = true
  94. else
  95. LogError("FightUnitLogic CastSkill not have physical skill_1 !!!")
  96. end
  97. end
  98. LogBlue(Language[10236])
  99. return haveSkill
  100. end
  101. --> 检测技能list中 可释放的技能
  102. function FightUnitLogic:CheckSkill(skilltype)
  103. local CurRound, MaxRound = BattleLogic.GetCurRound()
  104. -- WYLog("技能列表")
  105. -- for k, skill in ipairs(self.skillArray) do
  106. -- while true
  107. -- do
  108. -- if skilltype == SkillBaseType.Physical and skill[8].slot ~= SkillSlotPos.Slot_0 then --< 物理技能 排除magic skill
  109. -- break
  110. -- end
  111. -- if skilltype == SkillBaseType.Magic and skill[8].slot == SkillSlotPos.Slot_0 then
  112. -- break
  113. -- end
  114. -- local skillid = skill[1]
  115. -- local cd = skill[8].cd
  116. -- local release = skill[8].release
  117. -- if CurRound == release then --< 起始回合
  118. -- WYLog("ret skillid")
  119. -- WYLog(skillid)
  120. -- return true, skill
  121. -- elseif CurRound > release and (CurRound - release) % cd == 0 then --< cd回合
  122. -- return true, skill
  123. -- end
  124. -- break
  125. -- end
  126. -- end
  127. --> 暂时直接返回
  128. return true, self.skill
  129. -- return false, nil
  130. end
  131. function FightUnitLogic:GetRoleData(property)
  132. local tarPro = self.data:GetData(property)
  133. -- local item
  134. -- for i=1, self.proTranList.size do
  135. -- item = self.proTranList.buffer[i]
  136. -- if item.proName == property then
  137. -- local value
  138. -- if item.changeType == 1 then --加算
  139. -- value = item.tranFactor
  140. -- elseif item.changeType == 2 then --乘加算(百分比属性加算)
  141. -- value = BattleUtil.ErrorCorrection(self.data:GetData(item.tranProName) * item.tranFactor)
  142. -- elseif item.changeType == 3 then --减算
  143. -- value = -item.tranFactor
  144. -- elseif item.changeType == 4 then --乘减算(百分比属性减算)
  145. -- value = -BattleUtil.ErrorCorrection(self.data:GetData(item.tranProName) * item.tranFactor)
  146. -- end
  147. -- tarPro = tarPro + value
  148. -- end
  149. -- end
  150. return tarPro
  151. end
  152. --> 应对被动
  153. function FightUnitLogic:AddBuff(...)
  154. end
  155. function FightUnitLogic:Update()
  156. end