RoleLogic.lua 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  1. RoleLogic = {}
  2. RoleLogic.__index = RoleLogic
  3. --local RoleLogic = RoleLogic
  4. --local RoleDataName = RoleDataName
  5. --local BattleLogic = BattleLogic
  6. local Random = Random
  7. local floor = math.floor
  8. local max = math.max
  9. local min = math.min
  10. local skillPool = BattleObjectPool.New(function ()
  11. return Skill:New()
  12. end)
  13. function RoleLogic.New()
  14. local instance = {uid = 0, roleData = 0, data = RoleData.New(), camp = 0, name = 0, aiIndex = 1, position = 0, sp = 0, spPass = 0,
  15. shield = BattleList.New(),
  16. exCalDmgList = BattleList.New(),
  17. proTranList = BattleList.New(),
  18. buffFilter = BattleList.New(),
  19. Event = BattleEvent:New(), passiveList = {}, isDead = false, IsDebug = false}
  20. setmetatable(instance, RoleLogic)
  21. return instance
  22. end
  23. --匹配相同id
  24. function RoleLogic:Equle(_role)
  25. if _role.roleId == self.roleId and _role.uid == self.uid then
  26. return true
  27. end
  28. return false
  29. end
  30. --回滚
  31. function RoleLogic:RoleBack(_role)
  32. -- LogError("xRolbX ---------------"..self.uid)
  33. -- 回滚的状态及其数据
  34. self.position = _role.position
  35. self.roleData= _role.roleData
  36. local _data =_role.data:Clone() --< 检查状态
  37. self.data:RoleBack( self, _data)
  38. self.Rage =_role.Rage
  39. self.RageGrow =_role.RageGrow -- 普通技能怒气成长
  40. self.SuperSkillRage =_role.SuperSkillRage -- 技能需要释放的怒气值,默认为4
  41. self.NoRageRate =_role.NoRageRate -- 不消耗怒气值的概率
  42. self.Rage =_role.Rage--self.Rage + self:GetRoleData(RoleDataName.InitRage)-- 当前怒气值
  43. self.aiOrder =_role.aiOrder
  44. self.aiIndex =_role.aiIndex
  45. self.aiTempCount =_role.aiTempCount
  46. self.IsDebug =_role.IsDebug
  47. self.lockTarget =_role.lockTarget --嘲讽
  48. self.ctrl_dizzy =_role.ctrl_dizzy --眩晕 不能释放所有技能
  49. self.ctrl_slient =_role.ctrl_slient --沉默 只能1技能
  50. self.ctrl_palsy =_role.ctrl_palsy --麻痹 只能2技能
  51. self.ctrl_noheal =_role.ctrl_noheal --禁疗
  52. self.ctrl_blind =_role.ctrl_blind --致盲
  53. self.ctrl_frozen =_role.ctrl_frozen --< 冰冻
  54. self.ctrl_chaos =_role.ctrl_chaos --< 混乱
  55. self.ctrl_chaos_beatBack =_role.ctrl_chaos_beatBack --< 混乱中的反击
  56. self.ctrltimes =_role.ctrltimes --< 控制次数
  57. self.stop_move =_role.stop_move --< 停止行动
  58. self.deadFilter =_role.deadFilter -- 控制死亡,置为false则角色暂时无法死亡
  59. self.reliveFilter =_role.reliveFilter -- 控制复活的标志位,置为false角色将不再享受复活效果
  60. self.reliveHPF =_role.reliveHPF
  61. self.IsCanAddSkill =_role.IsCanAddSkill -- 是否可以追加技能
  62. self.effect218times =_role.effect218times --< effect 218 触发次数
  63. self.skilling =_role.skilling --< 技能间
  64. self.randHitPos =_role.randHitPos --< 受击位置点
  65. self.miss_ctrl =_role.miss_ctrl --< 无视控制
  66. self.warWayType =_role.warWayType --< 战法类型
  67. self.isBeInfect = _role.isBeInfect
  68. self.movementRandom01=_role.movementRandom01
  69. end
  70. function RoleLogic:Clone()
  71. local _copy = RoleLogic.New()
  72. _copy.uid = self.uid
  73. _copy.position = self.position
  74. _copy.roleData = self.roleData
  75. _copy.roleId = self.roleId
  76. _copy.data = self.data:Clone(_copy)
  77. _copy.data:RoleBack(_copy,self.data)
  78. _copy.isDead = _copy:GetRoleData(RoleDataName.Hp) <= 0
  79. _copy.isRealDead = _copy.isDead
  80. _copy.camp = self.camp --阵营 0:我方 1:敌方
  81. _copy.name = self.name
  82. _copy.element = self.element
  83. _copy.professionId = self.professionId
  84. _copy.star = self.star or 1
  85. _copy.shield=self.shield:Clone() --护盾列表
  86. _copy.exCalDmgList=self.exCalDmgList:Clone() --额外计算伤害列表
  87. _copy.buffFilter=self.buffFilter:Clone() --buff屏蔽列表
  88. _copy.proTranList=self.proTranList:Clone() --属性转换列表
  89. _copy.Event=self.Event --< 此处回滚需要屏蔽!!
  90. -- self.skill = data.skill
  91. -- self.superSkill = data.superSkill
  92. _copy.skillArray = self.skillArray
  93. --首次读条时间=速度/(20*(等级+10)
  94. _copy.sp = self.sp
  95. -- local time = self:GetRoleData(RoleDataName.Speed)/(20*(self:GetRoleData(RoleDataName.Level)+10))
  96. _copy.spPass = self.spPass
  97. -- 初始化怒气值(
  98. _copy.Rage = self.Rage
  99. _copy.RageGrow = self.RageGrow -- 普通技能怒气成长
  100. _copy.SuperSkillRage = self.SuperSkillRage -- 技能需要释放的怒气值,默认为4
  101. _copy.NoRageRate = self.NoRageRate -- 不消耗怒气值的概率
  102. -- 被动技能
  103. _copy.passiveList = {}
  104. _copy.passivity = self.passivity
  105. _copy.passivityIds = self.passivityIds or {}
  106. --> 之前的一维改二维 每个passivity 包含多个
  107. if _copy.passivity and #_copy.passivity > 0 then
  108. for i = 1, #_copy.passivity do
  109. -- --> 用于效果被动反显示技能名
  110. -- self.tempPassivityId = nil
  111. -- if data.passivityIds and data.passivityIds[i] then
  112. -- self.tempPassivityId = data.passivityIds[i]
  113. -- end
  114. local v = _copy.passivity[i]
  115. local ids = v[1]
  116. for k = 1, #ids do
  117. local args = {}
  118. for j = 1, #v[k + 1] do
  119. args[j] = v[k + 1][j]
  120. end
  121. local id = ids[k]
  122. if BattleUtil.Passivity[id] then
  123. -- BattleUtil.Passivity[id](self, args) 被动加入了列表需要注意切换的时候只同步数据
  124. -- 计入日志
  125. -- local argtx=""
  126. -- for i,ar in pairs(args) do
  127. -- argtx = argtx.." "..i..": "..ar
  128. -- end
  129. -- BattleLogManager.Log(
  130. -- "insert Passivity idx:"..id.." "..argtx,
  131. -- "tcamp", self.camp,
  132. -- "tpos", self.position,
  133. -- "id", self.roleId
  134. -- )
  135. -- 加入被动列表
  136. table.insert(_copy.passiveList, {id, args})
  137. else
  138. end
  139. end
  140. end
  141. end
  142. -- 初始怒气值放在被动之后计算,使被动对初始怒气的影响生效
  143. --> deprecated
  144. _copy.Rage = self.Rage--self.Rage + self:GetRoleData(RoleDataName.InitRage)-- 当前怒气值
  145. --
  146. _copy.aiOrder =self.aiOrder
  147. _copy.aiIndex =self.aiIndex
  148. _copy.aiTempCount =self.aiTempCount
  149. _copy.IsDebug =self.IsDebug
  150. _copy.lockTarget =self.lockTarget --嘲讽
  151. _copy.ctrl_dizzy =self.ctrl_dizzy --眩晕 不能释放所有技能
  152. _copy.ctrl_slient =self.ctrl_slient --沉默 只能1技能
  153. _copy.ctrl_palsy =self.ctrl_palsy --麻痹 只能2技能
  154. _copy.ctrl_noheal =self.ctrl_noheal --禁疗
  155. _copy.ctrl_blind =self.ctrl_blind --致盲
  156. _copy.ctrl_frozen =self.ctrl_frozen --< 冰冻
  157. _copy.ctrl_chaos =self.ctrl_chaos --< 混乱
  158. _copy.ctrl_chaos_beatBack =self.ctrl_chaos_beatBack --< 混乱中的反击
  159. _copy.ctrltimes =self.ctrltimes --< 控制次数
  160. _copy.stop_move =self.stop_move --< 停止行动
  161. _copy.deadFilter =self.deadFilter -- 控制死亡,置为false则角色暂时无法死亡
  162. _copy.reliveFilter =self.reliveFilter -- 控制复活的标志位,置为false角色将不再享受复活效果
  163. _copy.reliveHPF =self.reliveHPF
  164. _copy.IsCanAddSkill =self.IsCanAddSkill -- 是否可以追加技能
  165. _copy.effect218times =self.effect218times --< effect 218 触发次数
  166. _copy.skilling =self.skilling --< 技能间
  167. _copy.randHitPos =self.randHitPos --< 受击位置点
  168. _copy.miss_ctrl =self.miss_ctrl --< 无视控制
  169. _copy.warWayType =self.warWayType --< 战法类型
  170. _copy.isBeInfect = self.isBeInfect
  171. _copy.movementRandom01 = self.movementRandom01
  172. _copy:InitRoleType() --< 初始目标类型
  173. return _copy
  174. end
  175. function RoleLogic:Init(uid, data, position)
  176. self.uid = uid
  177. self.position = position
  178. self.roleData = data
  179. self.roleId = data.roleId
  180. self.data:Init(self, data.property)
  181. self.isDead = self:GetRoleData(RoleDataName.Hp) <= 0
  182. self.isRealDead = self.isDead
  183. self.isFlagCrit = false
  184. self.camp = data.camp --阵营 0:我方 1:敌方
  185. self.name = data.name
  186. self.element = data.element
  187. self.professionId = data.professionId
  188. self.star = data.star or 1
  189. self.shield:Clear() --护盾列表
  190. self.exCalDmgList:Clear() --额外计算伤害列表
  191. self.buffFilter:Clear() --buff屏蔽列表
  192. self.proTranList:Clear() --属性转换列表
  193. self.Event:ClearEvent()
  194. -- self.skill = data.skill
  195. -- self.superSkill = data.superSkill
  196. self.skillArray = data.skillArray
  197. self.skillArrayBase = BattleUtil.cloneTable(data.skillArray)
  198. self.substitute = data.isTibu
  199. -- if self.substitute then
  200. -- LogError(self.uid .." true")
  201. -- else
  202. -- LogError(self.uid .."false")
  203. -- end
  204. --首次读条时间=速度/(20*(等级+10)
  205. self.sp = 0
  206. local time = self:GetRoleData(RoleDataName.Speed)/(20*(self:GetRoleData(RoleDataName.Level)+10))
  207. self.spPass = floor( BattleUtil.ErrorCorrection(time) * BattleLogic.GameFrameRate)
  208. -- 初始化怒气值(默认2)
  209. self.Rage = 2
  210. self.RageGrow = 2 -- 普通技能怒气成长
  211. self.SuperSkillRage = 4 -- 技能需要释放的怒气值,默认为4
  212. self.NoRageRate = 0 -- 不消耗怒气值的概率
  213. self.isFlagCrit = false -- 暴击标记
  214. self.passiveList = {}
  215. self.passivity = data.passivity
  216. self.passivityIds = data.passivityIds or {}
  217. --> 之前的一维改二维 每个passivity 包含多个
  218. if data.passivity and #data.passivity > 0 then
  219. for i = 1, #data.passivity do
  220. -- --> 用于效果被动反显示技能名
  221. -- self.tempPassivityId = nil
  222. -- if data.passivityIds and data.passivityIds[i] then
  223. -- self.tempPassivityId = data.passivityIds[i]
  224. -- end
  225. local v = data.passivity[i]
  226. local ids = v[1]
  227. for k = 1, #ids do
  228. local args = {}
  229. for j = 1, #v[k + 1] do
  230. args[j] = v[k + 1][j]
  231. end
  232. local id = ids[k]
  233. -- if BattleUtil.Passivity[id] then
  234. -- BattleUtil.Passivity[id](self, args)
  235. if BattleUtil.Passivity[id] then
  236. local delay = id/100
  237. if delay < 0.1 then
  238. delay = delay*4
  239. elseif delay > 1 then
  240. delay = delay/5 + 0.18
  241. end
  242. -- LogError("roleid:"..self.roleId.." p:"..id)
  243. BattleUtil.Passivity[id](self, args, 0)-- id/100)
  244. -- 计入日志
  245. local argtx=""
  246. for i,ar in pairs(args) do
  247. argtx = argtx.." "..i..": "..ar
  248. end
  249. -- BattleLogManager.Log(
  250. -- "insert Passivity idx:"..id.." "..argtx,
  251. -- "tcamp", self.camp,
  252. -- "tpos", self.position,
  253. -- "id", self.roleId
  254. -- )
  255. -- 加入被动列表
  256. table.insert(self.passiveList, {id, args})
  257. else
  258. -- -- 计入日志
  259. -- local argtx = ""
  260. -- for i ,ar in pairs(args) do
  261. -- argtx = argtx.." "..i..": "..ar
  262. -- end
  263. -- BattleLogManager.Log(
  264. -- "insert Passivity idx:"..id.." "..argtx,
  265. -- "tcamp", self.camp,
  266. -- "tpos", self.position,
  267. -- "id", self.roleId,
  268. -- )
  269. -- table.insert(self.passiveList, {id, args})
  270. -- else
  271. end
  272. end
  273. end
  274. end
  275. -- 初始怒气值放在被动之后计算,使被动对初始怒气的影响生效
  276. --> deprecated
  277. self.Rage = 0--self.Rage + self:GetRoleData(RoleDataName.InitRage)-- 当前怒气值
  278. --
  279. self.aiOrder = data.ai
  280. self.aiIndex = 1
  281. self.aiTempCount = 0
  282. self.IsDebug = false
  283. self.lockTarget = nil --嘲讽
  284. self.ctrl_dizzy = false --眩晕 不能释放所有技能
  285. self.ctrl_slient = false --沉默 只能1技能
  286. self.ctrl_palsy = false --麻痹 只能2技能
  287. self.ctrl_noheal = false --禁疗
  288. self.ctrl_blind = false --致盲
  289. self.ctrl_frozen = false --< 冰冻
  290. self.ctrl_chaos = false --< 混乱
  291. self.ctrl_chaos_beatBack = false --< 混乱中的反击
  292. self.ctrltimes = 0 --< 控制次数
  293. self.isBeInfect = false --<是否被传染
  294. self.isHoldBeatingBack = true --<是否触发反击状态 true 为未触发
  295. self.stop_move = false --< 停止行动
  296. self.deadFilter = true -- 控制死亡,置为false则角色暂时无法死亡
  297. self.deadRoundCounter = 0 -- 不可复活 死亡回合数标记(控制何时可以复活)
  298. self.reliveFilter = true -- 控制复活的标志位,置为false角色将不再享受复活效果
  299. self.reliveHPF = 1
  300. self.isOutGame = false -- 永久不可复活&&移除本场游戏
  301. self.IsCanAddSkill = true -- 是否可以追加技能
  302. self.movementRandom01 = 0 --< 固定回合一次跟新随机数
  303. self.effect218times = 0 --< effect 218 触发次数
  304. self.skilling = false --< 技能间
  305. self.randHitPos = {} --< 受击位置点
  306. self.miss_ctrl = false --< 无视控制
  307. self.warWayType = {} --< 战法类型
  308. self:InitRoleType() --< 初始目标类型
  309. self:InitMovementSeed() --< 初始化回合变化随机数
  310. end
  311. function RoleLogic:InitMovementSeed()
  312. local _round = -1
  313. local changeSeed = function ()
  314. local round = BattleLogic.GetCurRound()
  315. if _round == round then
  316. return
  317. else
  318. _round=round
  319. if Random.Range01() <= 0.5 then
  320. self.movementRandom01 = 0
  321. else
  322. self.movementRandom01 = 1
  323. end
  324. end
  325. end
  326. self.Event:AddEvent(BattleEventName.RoleTurnStart,changeSeed)
  327. end
  328. local function tableKin(_tb,_k)
  329. for k,v in pairs(_tb) do
  330. if k==_k then return true end
  331. end
  332. return false
  333. end
  334. function RoleLogic:GetData(name)
  335. return self:GetRoleData(name)
  336. end
  337. -- 被动接受替补buff
  338. function RoleLogic:AddPassiveByOther(passivity)
  339. if passivity and #passivity > 0 then
  340. for i = 1, #passivity do
  341. -- --> 用于效果被动反显示技能名
  342. -- self.tempPassivityId = nil
  343. -- if data.passivityIds and data.passivityIds[i] then
  344. -- self.tempPassivityId = data.passivityIds[i]
  345. -- end
  346. local v = passivity[i]
  347. local ids = v[1]
  348. for k = 1, #ids do
  349. local args = {}
  350. for j = 1, #v[k + 1] do
  351. args[j] = v[k + 1][j]
  352. end
  353. local id = ids[k]
  354. -- LogError("~~~~~~~~~~~~~~~ByOther oooooooo"..id)
  355. if BattleUtil.Passivity[id] then
  356. BattleUtil.Passivity[id](self, args, 0)-- id/100)
  357. -- 加入被动列表
  358. -- LogError("~~~~~~~~~~~~~~~ByOther"..id)
  359. table.insert(self.passiveList, {id, args})
  360. else
  361. end
  362. end
  363. end
  364. end
  365. end
  366. local function tableKin(_tb,_k)
  367. for k,v in pairs(_tb) do
  368. if k == _k then return true end
  369. end
  370. return false
  371. end
  372. function RoleLogic:GetData(name)
  373. return self:GetRoleData(name)
  374. end
  375. -- 添加一个被动技能
  376. function RoleLogic:AddPassive(id, args, isRepeat)
  377. --判断是否可以叠加
  378. if not isRepeat then
  379. -- 不可以叠加, 如果重复则不再加入
  380. for _, pst in ipairs(self.passiveList) do
  381. if pst[1] == id then
  382. return
  383. end
  384. end
  385. end
  386. -- 被动生效
  387. BattleUtil.Passivity[id](self, args, 0)-- id/100)
  388. -- 加入被动列表
  389. table.insert(self.passiveList, {id, args})
  390. end
  391. function RoleLogic:CanCastSkill()
  392. return self.sp >= self.spPass and not self.IsDebug
  393. end
  394. -- 废弃的方法
  395. -- function RoleLogic:GetSkillCD()
  396. -- return max(self.spPass - self.sp, 0)
  397. -- end
  398. -- -- 废弃的方法
  399. -- function RoleLogic:AddSkillCD(value, type)
  400. -- self.Event:DispatchEvent(BattleEventName.RoleCDChanged)
  401. -- if value == 0 then --为0直接清CD
  402. -- self.sp = self.spPass
  403. -- return
  404. -- end
  405. -- local cdTotal = self.spPass
  406. -- local delta = 0
  407. -- if type == 1 then --加算
  408. -- delta = floor(value * BattleLogic.GameFrameRate)
  409. -- elseif type == 2 then --乘加算(百分比属性加算)
  410. -- delta = floor(value * cdTotal)
  411. -- elseif type == 3 then --减算
  412. -- delta = -floor(value * BattleLogic.GameFrameRate)
  413. -- elseif type == 4 then --乘减算(百分比属性减算)
  414. -- delta = -floor(value * cdTotal)
  415. -- end
  416. -- if delta > 0 then --加cd加cd最大值
  417. -- self.spPass = self.spPass + delta
  418. -- else --减cd减cd当前值
  419. -- delta = -delta
  420. -- self.sp = min(self.sp + delta, self.spPass)
  421. -- end
  422. -- end
  423. -- 改变怒气值
  424. -- function RoleLogic:AddRage(value, type)
  425. -- local delta = 0
  426. -- if type == 1 then --加算
  427. -- delta = value
  428. -- elseif type == 2 then --乘加算(百分比属性加算)
  429. -- delta = floor(value * self.SuperSkillRage)
  430. -- elseif type == 3 then --减算
  431. -- delta = -value
  432. -- elseif type == 4 then --乘减算(百分比属性减算)
  433. -- delta = -floor(value * self.SuperSkillRage)
  434. -- end
  435. -- --
  436. -- self.Event:DispatchEvent(BattleEventName.RoleRageChange, delta)
  437. -- --怒气值不可为负值
  438. -- self.Rage = max(self.Rage + delta, 0)
  439. -- end
  440. -- 强行加血
  441. function RoleLogic:SetValue(property,date)
  442. self.data:SetValue(property,date)
  443. end
  444. function RoleLogic:GetRoleData(property)
  445. local tarPro = self.data:GetData(property)
  446. --> 战斗加成在此处理
  447. if property == RoleDataName.Attack then
  448. tarPro = BattleUtil.FP_Mul(tarPro, (1 + self.data:GetData(RoleDataName.AttackAddition)))
  449. elseif property == RoleDataName.PhysicalDefence then
  450. tarPro = BattleUtil.FP_Mul(tarPro, (1 + self.data:GetData(RoleDataName.ArmorAddition)))
  451. elseif property == RoleDataName.Hp then
  452. tarPro = BattleUtil.FP_Mul(tarPro, (1 + self.data:GetData(RoleDataName.MaxHpPercentage)))
  453. elseif property == RoleDataName.MaxHp then
  454. tarPro = BattleUtil.FP_Mul(tarPro, (1 + self.data:GetData(RoleDataName.MaxHpPercentage)))
  455. elseif property == RoleDataName.Speed then
  456. tarPro = BattleUtil.FP_Mul(tarPro, (1 + self.data:GetData(RoleDataName.SpeedAddition)))
  457. end
  458. local item
  459. for i=1, self.proTranList.size do
  460. item = self.proTranList.buffer[i]
  461. if item.proName == property then
  462. local value
  463. if item.changeType == 1 then --加算
  464. value = item.tranFactor
  465. elseif item.changeType == 2 then --乘加算(百分比属性加算)
  466. value = BattleUtil.ErrorCorrection(self.data:GetData(item.tranProName) * item.tranFactor)
  467. elseif item.changeType == 3 then --减算
  468. value = -item.tranFactor
  469. elseif item.changeType == 4 then --乘减算(百分比属性减算)
  470. value = -BattleUtil.ErrorCorrection(self.data:GetData(item.tranProName) * item.tranFactor)
  471. end
  472. tarPro = tarPro + value
  473. end
  474. end
  475. return tarPro
  476. end
  477. --proA替换的属性,factor系数,proB被替换的属性, duration持续时间
  478. --读取proB属性时,得到的值为proB + proA * factor
  479. function RoleLogic:AddPropertyTransfer(proA, factor, proB, ct, duration)
  480. local proTran = {proName = proB, tranProName = proA, tranFactor = factor, changeType = ct}
  481. self.proTranList:Add(proTran)
  482. local index = self.proTranList.size
  483. if duration then
  484. BattleLogic.WaitForTrigger(duration, function ()
  485. self:RemovePropertyTransfer(index, proTran)
  486. end)
  487. end
  488. return index, proTran
  489. end
  490. -- 删除临时属性
  491. function RoleLogic:RemovePropertyTransfer(index, tran)
  492. if index <= self.proTranList.size and tran == self.proTranList.buffer[index] then
  493. self.proTranList:Remove(index)
  494. end
  495. end
  496. -- 是否为指定id,指定星级的英雄 by:王振兴 2020/07/29
  497. function RoleLogic:IsAssignHeroAndHeroStar(id,star)
  498. if self.roleId==id and self.star==star then
  499. return true
  500. end
  501. return false
  502. end
  503. function RoleLogic:AddBuff(buff)
  504. -- BattleLogManager.Log(
  505. -- self.roleId..": AddBuff",
  506. -- "camp", self.camp,
  507. -- "pos", self.position,
  508. -- "type", buff.type,
  509. -- -- "isRage", tostring(isRage),
  510. -- "id", buff.id
  511. -- )
  512. if self:IsRealDead() then
  513. BattleLogic.BuffMgr:PutBuff(buff)
  514. return
  515. end
  516. -- buff的miss率
  517. local missF = 0
  518. -- 检测被动对miss概率的影响
  519. local cl = {}
  520. local function _CallBack(v, ct)
  521. if v then
  522. table.insert(cl, {v, ct})
  523. end
  524. end
  525. BattleLogic.Event:DispatchEvent(BattleEventName.RoleAddBuffMiss, _CallBack, self, buff)
  526. missF = BattleUtil.CountChangeList(missF, cl)
  527. local ImmuneTrigger = function(_buff)
  528. buff=_buff
  529. end
  530. -- 如果概率为0 或者没有miss
  531. if missF == 0 or not BattleUtil.RandomAction(missF, function() BattleLogic.BuffMgr:PutBuff(buff) end) then
  532. for i=1, self.buffFilter.size do
  533. if self.buffFilter.buffer[i](buff) then
  534. self.Event:DispatchEvent(BattleEventName.ImmuneTrigger,buff,ImmuneTrigger)
  535. BattleLogic.BuffMgr:PutBuff(buff)
  536. return
  537. end
  538. end
  539. BattleLogic.BuffMgr:AddBuff(self, buff)
  540. end
  541. end
  542. function RoleLogic:RemoveBuff(checkFunc)
  543. if checkFunc then
  544. BattleLogic.BuffMgr:RemoveBuff(self, checkFunc)
  545. end
  546. end
  547. function RoleLogic:Dispose()
  548. self.shield:Clear() --护盾列表
  549. self.exCalDmgList:Clear() --额外计算伤害列表
  550. self.buffFilter:Clear() --buff屏蔽列表
  551. self.proTranList:Clear() --属性转换列表
  552. self.Event:ClearEvent()
  553. self:RemoveBuff(function(buff) return true end)
  554. end
  555. -- 判断角色是否可以释放技能
  556. function RoleLogic:IsAvailable()
  557. if self:IsRealDead() then
  558. return false
  559. end
  560. if self.stop_move then--< 停止行动
  561. return false
  562. end
  563. --> ctrl
  564. if self.miss_ctrl then
  565. return true
  566. else
  567. --> 眩晕
  568. if self.ctrl_dizzy then
  569. return false
  570. end
  571. --> 冰冻
  572. if self.ctrl_frozen then
  573. return false
  574. end
  575. -- 沉默麻痹同时存在
  576. if self.ctrl_palsy and self.ctrl_slient then
  577. return false
  578. end
  579. end
  580. return true
  581. end
  582. -- 释放技能
  583. function RoleLogic:SkillCast(skill, func)
  584. local _CastDone = function()
  585. if func then
  586. func()
  587. end
  588. end
  589. -- 角色不可用直接结束技能释放
  590. if not skill or not self:IsAvailable() then
  591. _CastDone()
  592. return
  593. end
  594. -- 没有麻痹,释放普通攻击
  595. -- if skill.type == BattleSkillType.Normal and not self.ctrl_palsy then
  596. -- -- local function _CheckRage()
  597. -- -- -- 后成长怒气
  598. -- -- if skill.isRage then
  599. -- -- -- 检测被动技能对怒气成长的影响
  600. -- -- local grow = self.RageGrow
  601. -- -- local _RageGrowPassivity = function(finalGrow)
  602. -- -- grow = finalGrow
  603. -- -- end
  604. -- -- self.Event:DispatchEvent(BattleEventName.RoleRageGrow, grow, _RageGrowPassivity)
  605. -- -- --
  606. -- -- self.Rage = self.Rage + grow
  607. -- -- end
  608. -- -- -- 释放完成
  609. -- -- _CastDone()
  610. -- -- end
  611. -- -- 释放普技
  612. -- skill:Cast(_CastDone)
  613. -- -- 没有沉默,释放大技能
  614. -- elseif skill.type == BattleSkillType.Special and not self.ctrl_slient then
  615. -- -- 先消耗怒气
  616. -- if skill.isRage then
  617. -- if self.Rage < self.SuperSkillRage then
  618. -- -- 怒气值不足不能释放技能
  619. -- _CastDone()
  620. -- return
  621. -- end
  622. -- -- 检测被动技能对怒气消耗的影响
  623. -- local costRage = self.SuperSkillRage
  624. -- local noRageRate = self.NoRageRate
  625. -- local _RageCostPassivity = function(rate, cost)
  626. -- noRageRate = noRageRate + rate
  627. -- costRage = costRage + cost
  628. -- end
  629. -- self.Event:DispatchEvent(BattleEventName.RoleRageCost, costRage, noRageRate, _RageCostPassivity)
  630. -- -- 计算消耗怒气的概率,并消耗怒气
  631. -- local costRate = 1 - noRageRate
  632. -- costRate = costRate > 1 and 1 or costRate
  633. -- costRate = costRate < 0 and 0 or costRate
  634. -- BattleUtil.RandomAction(costRate, function()
  635. -- self.Rage = self.Rage - costRage
  636. -- end)
  637. -- end
  638. -- -- 释放绝技
  639. -- skill:Cast(_CastDone)
  640. -- -- 没有符合条件的技能直接进入下一个技能检测
  641. -- else
  642. -- _CastDone()
  643. -- end
  644. skill:Cast(_CastDone)
  645. end
  646. -- 加入一个技能
  647. -- type 加入的技能类型 --< 修改为physical magic
  648. -- targets 指定目标
  649. -- isAdd 是否是追加技能
  650. -- effectData 战斗技能数据
  651. function RoleLogic:AddSkill(type, isAdd, targets, effectData)
  652. if not self.IsCanAddSkill and isAdd then return end
  653. -- local effectData = type == BattleSkillType.Normal and self.skill or self.superSkill
  654. SkillManager.AddSkill(self, effectData, type, targets, isAdd)
  655. --
  656. -- BattleLogManager.Log(
  657. -- self.roleId..":Add Skill",
  658. -- "camp", self.camp,
  659. -- "pos", self.position,
  660. -- "type", type,
  661. -- -- "isRage", tostring(isRage),
  662. -- "isAdd", tostring(isAdd),
  663. -- "targets", targets and #targets or "0"
  664. -- )
  665. end
  666. -- 插入一个技能
  667. function RoleLogic:InsertSkill(type, isAdd, targets, effectData, skillSubType)
  668. if not self.IsCanAddSkill and isAdd then return end
  669. -- local effectData = type == BattleSkillType.Normal and self.skill or self.superSkill
  670. SkillManager.InsertSkill(self, effectData, type, targets, isAdd, skillSubType)
  671. --
  672. -- BattleLogManager.Log(
  673. -- "Insert Skill",
  674. -- "camp", self.camp,
  675. -- "pos", self.position,
  676. -- "type", type,
  677. -- -- "isRage", tostring(isRage),
  678. -- "isAdd", tostring(isAdd),
  679. -- "targets", targets and #targets or "0"
  680. -- )
  681. end
  682. -- 设置是否可以追加技能
  683. function RoleLogic:SetIsCanAddSkill(isCan)
  684. self.IsCanAddSkill = isCan
  685. end
  686. -- 正常触发技能
  687. function RoleLogic:CastSkill(func)
  688. -- 设置轮转方法
  689. SkillManager.SetTurnRoundFunc(func)
  690. local haveSkill = false
  691. -- 没有沉默
  692. -- if not self.ctrl_slient and self.Rage >= self.SuperSkillRage then
  693. if (not self.ctrl_slient and not self.ctrl_chaos) or self.miss_ctrl then --< 混乱只释放普攻
  694. local isHave, skilldata = self:CheckSkill(SkillBaseType.Magic)
  695. -- 释放大技能
  696. if isHave then
  697. self:AddSkill(SkillBaseType.Magic, true, nil, skilldata)
  698. haveSkill = true
  699. else
  700. local isHave_p, skilldata_p = self:CheckSkill(SkillBaseType.Physical)
  701. if isHave_p then
  702. self:AddSkill(SkillBaseType.Physical, true, nil, skilldata_p)
  703. haveSkill = true
  704. else
  705. LogError("RoleLogic CastSkill not have physical skill_1 !!!")
  706. end
  707. end
  708. return haveSkill
  709. end
  710. -- 没有麻痹 释放普通技能
  711. if not self.ctrl_palsy or self.miss_ctrl then
  712. local isHave, skilldata = self:CheckSkill(SkillBaseType.Physical)
  713. if isHave then
  714. self:AddSkill(SkillBaseType.Physical, true, nil, skilldata)
  715. haveSkill = true
  716. else
  717. LogError("CastSkill not have physical skill_2 !!!")
  718. end
  719. return haveSkill
  720. end
  721. LogError("### 无法填装技能")
  722. return haveSkill
  723. end
  724. -- 强制释放技能,测试技能时使用
  725. -- type 追加的技能类型 1=普技 2=特殊技
  726. -- targets 追加技能的目标 nil则自动选择目标
  727. -- func 追加技能释放完成回调
  728. function RoleLogic:ForceCastSkill(type, targets, func)
  729. -- 清除技能控制
  730. self.ctrl_dizzy = false --眩晕 不能释放技能
  731. self.ctrl_slient = false --沉默 只能1技能
  732. self.ctrl_palsy = false --麻痹 只能2技能
  733. -- 设置轮转方法
  734. SkillManager.SetTurnRoundFunc(func)
  735. -- 释放技能
  736. if type == 1 and self.skill then
  737. self:AddSkill(BattleSkillType.Normal, true, false, nil)
  738. elseif type == 2 and self.superSkill then
  739. if self.Rage < self.SuperSkillRage then
  740. self.Rage = self.SuperSkillRage
  741. end
  742. self:AddSkill(BattleSkillType.Special, true, false, nil)
  743. end
  744. end
  745. --设置为替补属性
  746. function RoleLogic:SetSubstitute(isTibu)
  747. self.substitute=isTibu
  748. end
  749. --判断是否为替补属性
  750. function RoleLogic:IsSubstitute()
  751. return self.substitute
  752. end
  753. -- 判断是否可以去死了
  754. function RoleLogic:IsCanDead()
  755. -- 暂时不能死
  756. if not self.deadFilter then
  757. return false
  758. end
  759. -- 还有我的技能没有释放,不能死啊
  760. --> 去掉死亡后释放问题
  761. -- if SkillManager.HaveMySkill(self) then
  762. -- return false
  763. -- end
  764. return true
  765. end
  766. -- 真的去死
  767. function RoleLogic:GoDead()
  768. if self:IsCanDead() then
  769. self.isRealDead = true
  770. -- self.Rage = 0
  771. BattleLogic.BuffMgr:ClearBuff(self)
  772. BattleLogic.BuffMgr:RemoveBuffQueneBy(function(buff)
  773. return buff.target == self
  774. end)
  775. self.Event:DispatchEvent(BattleEventName.RoleRealDead, self)
  776. BattleLogic.Event:DispatchEvent(BattleEventName.RoleRealDead, self)
  777. return true
  778. end
  779. return false
  780. end
  781. -- 设置是否可以死亡
  782. function RoleLogic:SetDeadFilter(filter)
  783. self.deadFilter = filter
  784. end
  785. -- 要死了
  786. function RoleLogic:SetDead()
  787. self.isDead = true
  788. RoleManager.AddDeadRole(self)
  789. end
  790. -- 判断是否死亡
  791. function RoleLogic:IsDead()
  792. return self.isDead
  793. end
  794. function RoleLogic:IsRealDead()
  795. return self.isRealDead
  796. end
  797. -- 是否可以复活
  798. function RoleLogic:IsCanRelive()
  799. if self.isOutGame then
  800. return false
  801. end
  802. if not self.reliveFilter then
  803. return false
  804. end
  805. if not self.isRealDead then
  806. return false
  807. end
  808. return true
  809. end
  810. -- 复活吧, 真的去世后才能复活
  811. function RoleLogic:Relive()
  812. if self:IsCanRelive() then
  813. -- 没有指定血量则满血
  814. self.isDead = false
  815. self.isRealDead = false
  816. --[[
  817. BattleLogic.WaitForTrigger(0.1, function()
  818. BattleLogic.BuffMgr:ClearBuff(self)
  819. end)
  820. ]]
  821. local maxHp = self.data:GetData(RoleDataName.MaxHp)
  822. -- RoleManager.LogCa(
  823. -- "curframe:"..BattleLogic.CurFrame(),
  824. -- "Relive:"..maxHp,
  825. -- "RoleDataName.Hp:"..floor(self.reliveHPF * maxHp)
  826. -- )
  827. --LogError("self.reliveHPF"..self.reliveHPF)
  828. --LogError("hp"..floor(self.reliveHPF * maxHp))
  829. self.data:SetValue(RoleDataName.Hp, floor(self.reliveHPF * maxHp))
  830. -- 发送复活事件
  831. self.Event:DispatchEvent(BattleEventName.RoleRelive, self)
  832. BattleLogic.Event:DispatchEvent(BattleEventName.RoleRelive, self)
  833. return true
  834. end
  835. return false
  836. end
  837. -- 永久死亡&移除本局游戏
  838. function RoleLogic:SetOutBattle()
  839. self.isOutGame = true
  840. self:SetReliveFilter(false)
  841. end
  842. -- 设置是否可以复活
  843. function RoleLogic:SetReliveFilter(filter)
  844. if self.isOutGame and filter then --移除游戏后无法复活
  845. return
  846. end
  847. -- LogError(self.roleId.." SetReliveFilter "..tostring(filter))
  848. self.reliveFilter = filter
  849. end
  850. --,hpf 复活时拥有的血量的百分比
  851. function RoleLogic:SetRelive(hpf)
  852. -- 判断是否可以复活
  853. if self:IsCanRelive() then
  854. self.reliveHPF = hpf or 1
  855. RoleManager.AddReliveRole(self)
  856. end
  857. return false
  858. end
  859. --> 检测技能list中 可释放的技能
  860. function RoleLogic:CheckSkill(skilltype)
  861. local CurRound, MaxRound = BattleLogic.GetCurRound()
  862. if CurRound == 0 then
  863. return false, nil
  864. end
  865. for k, skill in ipairs(self.skillArray) do
  866. while true
  867. do
  868. if skilltype == SkillBaseType.Physical and skill[8].slot ~= SkillSlotPos.Slot_0 then --< 物理技能 排除magic skill
  869. break
  870. end
  871. if skilltype == SkillBaseType.Magic and skill[8].slot == SkillSlotPos.Slot_0 then
  872. break
  873. end
  874. local skillid = skill[1]
  875. local cd = skill[8].cd
  876. local release = skill[8].release
  877. --> cd为间隔数
  878. if CurRound == release then --< 起始回合
  879. return true, skill
  880. elseif CurRound > release and (CurRound - release) % (cd + 1) == 0 then --< cd回合
  881. return true, skill
  882. end
  883. break
  884. end
  885. end
  886. return false, nil
  887. end
  888. function RoleLogic:Update()
  889. end
  890. --> 初始人物为什么类型目标
  891. function RoleLogic:InitRoleType()
  892. if self.skillArray then
  893. for i = 1, #self.skillArray do
  894. if self.skillArray[i][9] then
  895. for j = 2, #self.skillArray[i][9] do
  896. if self.skillArray[i][9][j] then
  897. local effectType = self.skillArray[i][9][j][1]
  898. if effectType == 245 then
  899. self.miss_ctrl = true
  900. end
  901. end
  902. end
  903. end
  904. end
  905. end
  906. -- if self.passivity and self.passivity[1] and self.passivity[1][1] then
  907. -- for i = 1, #self.passivity[1][1] do
  908. -- local pEffectType = self.passivity[1][1][i]
  909. -- if pEffectType == 314 or pEffectType == 367 then
  910. -- self.isReliveOrSoulRole = true
  911. -- end
  912. -- end
  913. -- end
  914. --> 战法 --目前所以被动组都在其中
  915. self.warWayType = {}
  916. for k, v in ipairs(self.passivityIds) do
  917. local passivityIdStr = tostring(v)
  918. local passivityGroup = tonumber(string.sub(passivityIdStr, 1, -2))
  919. self.warWayType[passivityGroup] = 0
  920. end
  921. end