CombatLogicCS.lua 9.3 KB

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