FightUnitLogic.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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,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.round = data.round or -1
  30. self.lockTarget = nil --嘲讽
  31. self.ctrl_dizzy = false --眩晕 不能释放所有技能
  32. self.ctrl_slient = false --沉默 只能1技能
  33. self.ctrl_palsy = false --麻痹 只能2技能
  34. self.ctrl_noheal = false --禁疗
  35. self.ctrl_blind = false --致盲
  36. self.ctlr_seal = false --封印
  37. self.ctrltimes = 0 --< 控制次数
  38. self.deadFilter = true -- 控制死亡,置为false则角色暂时无法死亡
  39. self.effect218times = 0 --< effect 218 触发次数
  40. self.skilling = false --< 技能间
  41. end
  42. function FightUnitLogic:Dispose()
  43. end
  44. -- 判断角色是否可以释放技能
  45. function FightUnitLogic:IsAvailable()
  46. return true
  47. end
  48. -- 释放技能
  49. function FightUnitLogic:SkillCast(skill, func)
  50. local _CastDone = function()
  51. if func then
  52. func()
  53. end
  54. end
  55. -- 角色不可用直接结束技能释放
  56. if not skill or not self:IsAvailable() then
  57. _CastDone()
  58. return
  59. end
  60. skill:CastUnit(_CastDone)
  61. end
  62. -- 加入一个技能
  63. -- type 加入的技能类型 --< 修改为physical magic
  64. -- targets 指定目标
  65. -- isAdd 是否是追加技能
  66. -- effectData 战斗技能数据
  67. function FightUnitLogic:AddSkill(type, isAdd, targets, effectData)
  68. SkillManager.AddSkill(self, effectData, type, targets, isAdd)
  69. -- BattleLogManager.Log(
  70. -- "Add Skill",
  71. -- "camp", self.camp,
  72. -- "pos", self.position,
  73. -- "type", type,
  74. -- -- "isRage", tostring(isRage),
  75. -- "isAdd", tostring(isAdd),
  76. -- "targets", targets and #targets or "0"
  77. -- )
  78. end
  79. -- 正常触发技能
  80. function FightUnitLogic:CastSkill(func)
  81. -- 设置轮转方法
  82. SkillManager.SetTurnRoundFunc(func)
  83. local haveSkill = false
  84. local isHave, skilldata = self:CheckSkill()
  85. -- 释放大技能
  86. if isHave then
  87. --> 去掉skilltype判断 都应该是魔法
  88. self:AddSkill(SkillBaseType.Magic, true, nil, skilldata)
  89. haveSkill = true
  90. else
  91. end
  92. return haveSkill
  93. end
  94. --> 检测技能list中 可释放的技能
  95. function FightUnitLogic:CheckSkill()
  96. local CurRound, MaxRound = BattleLogic.GetCurRound()
  97. for k, skill in ipairs(self.skill) do
  98. local cd = skill[8].cd
  99. local release = skill[8].release
  100. if CurRound == release then --< 起始回合
  101. return true, skill
  102. elseif CurRound > release and (CurRound - release) % (cd + 1) == 0 then --< cd回合
  103. return true, skill
  104. end
  105. end
  106. return false, nil
  107. end
  108. function FightUnitLogic:GetRoleData(property)
  109. local tarPro = self.data:GetData(property)
  110. -- local item
  111. -- for i=1, self.proTranList.size do
  112. -- item = self.proTranList.buffer[i]
  113. -- if item.proName == property then
  114. -- local value
  115. -- if item.changeType == 1 then --加算
  116. -- value = item.tranFactor
  117. -- elseif item.changeType == 2 then --乘加算(百分比属性加算)
  118. -- value = BattleUtil.ErrorCorrection(self.data:GetData(item.tranProName) * item.tranFactor)
  119. -- elseif item.changeType == 3 then --减算
  120. -- value = -item.tranFactor
  121. -- elseif item.changeType == 4 then --乘减算(百分比属性减算)
  122. -- value = -BattleUtil.ErrorCorrection(self.data:GetData(item.tranProName) * item.tranFactor)
  123. -- end
  124. -- tarPro = tarPro + value
  125. -- end
  126. -- end
  127. return tarPro
  128. end
  129. --> 应对被动
  130. function FightUnitLogic:AddBuff(...)
  131. end
  132. function FightUnitLogic:Update()
  133. end