CombatLogicCS.lua 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. -- 战斗逻辑(跨服)
  2. local CombatExcel = require("excel.combat")
  3. local Config = require("Config")
  4. local Util = require("common.Util")
  5. local CombatImpl = require("combat.CombatImpl")
  6. local CombatDefine = require("combat.CombatDefine")
  7. local CombatPosLogic = require("combat.CombatPosLogic")
  8. local CombatPetCalc = require("combat.CombatPetCalc")
  9. local JibanLogic = require("combat.JibanLogic")
  10. local BeSkill = require("combat.BeSkill")
  11. local CombatObj = require("combat.CombatObj")
  12. local RoleDefine = require("role.RoleDefine")
  13. -- 初始combatInfo
  14. local function initCombatInfo(human, combatType, mapID)
  15. local combatInfo = {}
  16. combatInfo.time = os.time() -- 战斗时间
  17. combatInfo.passTime = 0 -- 客户端经过的时间
  18. combatInfo.type = combatType -- 战斗类型
  19. combatInfo.mapID = mapID -- 地图
  20. combatInfo.posAttr = {} -- 阵法属性
  21. combatInfo.jiban = {} -- 阵法属性
  22. combatInfo.attacker = nil -- 攻方基础角色信息 roleBase
  23. combatInfo.defender = nil -- 守方基础角色信息 roleBase
  24. combatInfo.atkJiban = nil -- 攻方羁绊英雄
  25. combatInfo.defJiban = nil -- 守方羁绊英雄
  26. combatInfo.isWin = nil -- 战斗结果
  27. combatInfo.result = nil -- 战斗帧
  28. combatInfo.skillUseList = nil -- 战斗技能
  29. combatInfo.cmdUseList = nil -- 战斗技能命令
  30. combatInfo.bufferUseList = nil -- 战斗buff
  31. combatInfo.objList = nil -- 战斗英雄列表
  32. combatInfo.helpList = nil -- 战斗魔兽列表
  33. combatInfo.rewardItem = {} -- 奖励
  34. combatInfo.endParam = nil -- 额外参数
  35. combatInfo.isVideo = nil -- 是否录像
  36. combatInfo.videoUuid = nil -- 录像uuid
  37. combatInfo.panelID = nil -- 返回界面(特殊)
  38. combatInfo.maxRound = nil -- 最大会合数
  39. combatInfo.fightMode = nil -- 战斗模式
  40. human.combat = combatInfo
  41. return combatInfo
  42. end
  43. local function getMapID(combatType)
  44. local mapID = nil
  45. local config = CombatExcel.combat[combatType]
  46. mapID = config.mapID == 0 and 1001 or config.mapID
  47. return mapID
  48. end
  49. --获取战斗最大回合数
  50. local function getMaxRound(combatType)
  51. local config = CombatExcel.combat[combatType]
  52. if config and config.maxRound and config.maxRound > 0 then
  53. return config.maxRound
  54. end
  55. return CombatDefine.COMBAT_ROUND_MAX
  56. end
  57. --获取战斗模式
  58. local function getFightMode(combatType)
  59. local config = CombatExcel.combat[combatType]
  60. if config.fightMode[1] == CombatDefine.FIGHT_MODE1 or config.fightMode[1] == CombatDefine.FIGHT_MODE3 then
  61. return config.fightMode
  62. end
  63. end
  64. local function setCombatInfo(formation,objList, side)
  65. for index = 1, CombatDefine.COMBAT_HERO_CNT do
  66. local obj = objList[index]
  67. if obj then
  68. -- 出战英雄站位
  69. if CombatPosLogic.checkPos(formation,index, side) then
  70. local pos = CombatDefine.SIDE2POS[side][index]
  71. obj.formationPos = index
  72. CombatImpl.setData(pos, obj)
  73. end
  74. end
  75. end
  76. end
  77. -- 设置辅助对象出战
  78. local function setHelp(helpList, side)
  79. if not helpList then return end
  80. for k,v in pairs(helpList) do
  81. if k == CombatDefine.HELP_TYPE1 then
  82. CombatPetCalc.calcGrowArgs(v)
  83. CombatPetCalc.clacBuffArgs(v)
  84. end
  85. CombatImpl.setHelp(side,k,v)
  86. end
  87. end
  88. -- 为了战斗回放,某些数据需要保存
  89. local function copyToCombatInfo(combatInfo)
  90. combatInfo.isWin = CombatImpl.result.isWin
  91. combatInfo.result = Util.copyTable(CombatImpl.result)
  92. combatInfo.result.round = CombatImpl.round
  93. combatInfo.skillUseList = Util.copyTable(CombatImpl.skillUseList)
  94. combatInfo.cmdUseList = Util.copyTable(CombatImpl.cmdUseList)
  95. combatInfo.bufferUseList = Util.copyTable(CombatImpl.bufferUseList)
  96. combatInfo.objList = Util.copyTable(CombatImpl.objList)
  97. combatInfo.helpList = Util.copyTable(CombatImpl.helpList)
  98. combatInfo.totalAtkCnt = CombatImpl.totalAtkCnt
  99. end
  100. -- 根据阵营和下标获取对战位置
  101. local function getPos(side, index)
  102. if side == CombatDefine.ATTACK_SIDE then
  103. return index
  104. elseif side == CombatDefine.DEFEND_SIDE then
  105. return index + CombatDefine.COMBAT_HERO_CNT
  106. else
  107. assert()
  108. end
  109. end
  110. -- 在各种战前加成后,重新设置血量
  111. local function recalcHpFightBegin(human, combatType, cbParam)
  112. for i = 1,CombatDefine.COMBAT_HERO_CNT do
  113. local atkPos = getPos(CombatDefine.ATTACK_SIDE, i)
  114. local atkObj = CombatImpl.objList[atkPos]
  115. if atkObj then
  116. if atkObj.isSysAttrChange then
  117. CombatObj.calcAttr(atkObj)
  118. -- -- 重新计算血量
  119. -- if combatType == CombatDefine.COMBAT_TYPE9 then
  120. -- DrillLogic.calcAttrAtk(human, i, atkObj, cbParam)
  121. -- elseif combatType == CombatDefine.COMBAT_TYPE17 then
  122. -- ValleyLogic.calcAttr(CombatDefine.ATTACK_SIDE, i, atkObj, cbParam)
  123. -- elseif combatType == CombatDefine.COMBAT_TYPE8 then
  124. -- LianyuLogic.recalcHpFightBegin(human, i, atkObj)
  125. -- end
  126. end
  127. atkObj.hpMax = CombatObj.getHpMax(atkObj)
  128. atkObj.hp = atkObj.hp or CombatObj.getHpMax(atkObj)
  129. atkObj.mp = atkObj.mp or atkObj.attr[RoleDefine.INIT_MP]
  130. atkObj.initHp = atkObj.hp
  131. atkObj.initMp = atkObj.mp
  132. end
  133. local defPos = getPos(CombatDefine.DEFEND_SIDE, i)
  134. local defObj = CombatImpl.objList[defPos]
  135. if defObj then
  136. if defObj.isSysAttrChange then
  137. CombatObj.calcAttr(defObj)
  138. -- if combatType == CombatDefine.COMBAT_TYPE9 then
  139. -- DrillLogic.calcAttrDef(human, i, defObj, cbParam)
  140. -- elseif combatType == CombatDefine.COMBAT_TYPE17 then
  141. -- ValleyLogic.calcAttr(CombatDefine.DEFEND_SIDE, i, defObj, cbParam)
  142. -- end
  143. end
  144. defObj.hpMax = CombatObj.getHpMax(defObj)
  145. defObj.hp = defObj.hp or CombatObj.getHpMax(defObj)
  146. defObj.mp = defObj.mp or defObj.attr[RoleDefine.INIT_MP]
  147. defObj.initHp = defObj.hp
  148. defObj.initMp = defObj.mp
  149. end
  150. end
  151. end
  152. local function onFightBegin(human, combatType, cbParam, param)
  153. -- local moduleFn = getModule(combatType)
  154. -- if moduleFn and moduleFn.onFightBegin then
  155. -- moduleFn.onFightBegin(human, cbParam, combatType, param)
  156. -- end
  157. BeSkill.onFightBegin()
  158. -- SkinLogic.onFightBegin(human) -- 处理皮肤属性, 这里原来逻辑也有问题,先不处理
  159. CombatPosLogic.onFightBegin(human)
  160. recalcHpFightBegin(human, combatType, cbParam)
  161. end
  162. function combatBegin(attackerInfo, defenderInfo, combatType, onFightEndFunc, extraArgs)
  163. CombatImpl.init(combatType)
  164. local mapID = getMapID(combatType)
  165. if not attackerInfo or not next(attackerInfo) then
  166. return
  167. end
  168. if not defenderInfo or not next(defenderInfo) then
  169. return
  170. end
  171. local defender, defHelp = defenderInfo.objList, defenderInfo.helpList
  172. local defRBase, defFormation, defJiban = defenderInfo.roleBase, defenderInfo.formation, defenderInfo.jiBan
  173. local attacker, atkHelp = attackerInfo.objList, attackerInfo.helpList
  174. local atkRBase, atkFormation, atkJiban = attackerInfo.roleBase, attackerInfo.formation, attackerInfo.jiBan
  175. if not (attacker and next(attacker)) then
  176. return
  177. end
  178. if not defender or not next(defender) then
  179. return
  180. end
  181. local human = {}
  182. local combatInfo = initCombatInfo(human, combatType, mapID)
  183. combatInfo.attacker = atkRBase or {}
  184. combatInfo.atkHelp = atkHelp or {}
  185. combatInfo.atkFormation = atkFormation
  186. combatInfo.atkJiban = atkJiban
  187. combatInfo.defender = defRBase or {}
  188. combatInfo.defHelp = defHelp or {}
  189. combatInfo.defFormation = defFormation
  190. combatInfo.defJiban = defJiban
  191. combatInfo.posAttr[CombatDefine.ATTACK_SIDE] = CombatPosLogic.getPosAttr(attacker)
  192. combatInfo.posAttr[CombatDefine.DEFEND_SIDE] = CombatPosLogic.getPosAttr(defender)
  193. combatInfo.jiban[CombatDefine.ATTACK_SIDE] = JibanLogic.getJiban(attacker,atkJiban)
  194. combatInfo.jiban[CombatDefine.DEFEND_SIDE] = JibanLogic.getJiban(defender,defJiban)
  195. combatInfo.maxRound = getMaxRound(combatType)
  196. combatInfo.fightMode = getFightMode(combatType)
  197. JibanLogic.setBeSkill(attacker,combatInfo.jiban[CombatDefine.ATTACK_SIDE])
  198. JibanLogic.setBeSkill(defender,combatInfo.jiban[CombatDefine.DEFEND_SIDE])
  199. local changePos = nil
  200. -- if combatType == CombatDefine.COMBAT_TYPE10 then
  201. -- for k,v in pairs(attacker) do
  202. -- changePos = k
  203. -- attacker[k] = nil
  204. -- attacker[5] = v
  205. -- break
  206. -- end
  207. -- end
  208. setCombatInfo(atkFormation, attacker, CombatDefine.ATTACK_SIDE)
  209. setCombatInfo(defFormation, defender, CombatDefine.DEFEND_SIDE)
  210. setHelp(atkHelp, CombatDefine.ATTACK_SIDE)
  211. setHelp(defHelp, CombatDefine.DEFEND_SIDE)
  212. CombatImpl.setMaxRound(combatInfo.maxRound)
  213. CombatImpl.setFightMode(combatInfo.fightMode)
  214. onFightBegin(human, combatType, nil, {}, {})
  215. while CombatImpl.calcFrame() do end
  216. copyToCombatInfo(combatInfo)
  217. combatInfo.changePos = changePos
  218. local result = combatInfo.isWin and CombatDefine.RESULT_WIN or CombatDefine.RESULT_FAIL
  219. if onFightEndFunc then
  220. onFightEndFunc(result, combatType, combatInfo, extraArgs)
  221. end
  222. end