JjcGodWarCombat.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. -- 众神之战 战斗逻辑 --
  2. local JjcGodWarLogic = require("jjcGodWar.JjcGodWarLogic")
  3. local JjcGodWarDB = require("jjcGodWar.JjcGodWarDB")
  4. local CombatVideo = require("combat.CombatVideo")
  5. local CreateRole = require("role.CreateRole")
  6. local CombatDefine = require("combat.CombatDefine")
  7. local HeroGrid = require("hero.HeroGrid")
  8. local CombatLogic = require("combat.CombatLogic")
  9. local JjcDB = require("jjc.JjcDB")
  10. local WarReportLogic = require("warReport.WarReportLogic")
  11. local Util = require("common.Util")
  12. --竞猜阶段就开始生成战斗数据
  13. function timerCombat()
  14. local state,round,leftTime = JjcGodWarLogic.getNowGodWarState()
  15. if state == JjcGodWarLogic.GODWAR_STATE_WAIT or state == JjcGodWarLogic.GODWAR_STATE_END then return end
  16. if round == JjcGodWarLogic.GODWAR_JIEDUAN_ZHUNBEI then return end
  17. local paiweiMatch,needCombat = JjcGodWarDB.getNowNeedCombat(state)
  18. if not paiweiMatch or not needCombat then return end
  19. for i=1,#needCombat do
  20. local pairsData = needCombat[i]
  21. local atkUuid = pairsData.atkUuid
  22. local defUuid = pairsData.defUuid
  23. -- local atkRoleData = JjcGodWarDB.getGodWarDataByUuid(atkUuid)
  24. -- local defRoleData = JjcGodWarDB.getGodWarDataByUuid(defUuid)
  25. -- require("common.Util").printTable(atkRoleData)
  26. -- require("common.Util").printTable(defRoleData)
  27. local fakeHuman = {}
  28. fakeHuman.db = {}
  29. fakeHuman.db.combatQuick = {}
  30. local param = {}
  31. local cbParam = {}
  32. cbParam.atkIndex = 1
  33. cbParam.defIndex = 1
  34. cbParam.atkUuid = atkUuid
  35. cbParam.defUuid = defUuid
  36. cbParam.fenzuID = pairsData.fenzuID
  37. cbParam.pairsIndex = pairsData.pairsIndex
  38. --print("pairsIndex",pairsData.pairsIndex)
  39. cbParam.combatInfos = {}
  40. param.atkUuid = atkUuid
  41. param.defUuid = defUuid
  42. -- require("common.Util").printTable(atkRoleData)
  43. -- require("common.Util").printTable(defRoleData)
  44. CombatLogic.combatBegin(fakeHuman, 1001, param, CombatDefine.COMBAT_TYPE4, cbParam, true)
  45. end
  46. end
  47. function getCombatObjList(human, side, args)
  48. --print("getCombatObjList(human, side, args)")
  49. local uuid = args.atkUuid
  50. if CombatDefine.DEFEND_SIDE == side then
  51. uuid = args.defUuid
  52. end
  53. local data = JjcGodWarDB.getGodWarDataByUuid(uuid)
  54. if JjcDB.isNpc(data) then return end
  55. --require("common.Util").printTable(data.rolebase)
  56. return data.objList, data.helpList, data.rolebase, data.formation
  57. end
  58. function getCombatMonsterOutID(human, side, args)
  59. --print("getCombatMonsterOutID(human, side, args)")
  60. local uuid = args.atkUuid
  61. if CombatDefine.DEFEND_SIDE == side then
  62. uuid = args.defUuid
  63. end
  64. local data = JjcGodWarDB.getGodWarDataByUuid(uuid)
  65. --require("common.Util").printTable(data)
  66. if not JjcDB.isNpc(data) then return end
  67. --print("data.monsterOutID",data.monsterOutID)
  68. return data.monsterOutID,data.zhandouli
  69. end
  70. local function xuanbaPointCanGet(winUuid,state)
  71. if state == JjcGodWarLogic.GODWAR_STATE_XUANBA1 then return 20 end
  72. local list = JjcGodWarDB.getCombatResultListByUuid(winUuid)
  73. if not list then return 20 end
  74. local winCnt = 0
  75. for lastState=1,state-1 do
  76. if list[lastState] then
  77. winCnt = winCnt + 1
  78. else
  79. winCnt = 0
  80. end
  81. end
  82. return 20 + winCnt * 10
  83. end
  84. function checkHurtResult(combatInfo)
  85. local atkHurt = 0
  86. local defHurt = 0
  87. for pos = 1, CombatDefine.COMBAT_HERO_ALL_CNT do
  88. local obj = combatInfo.objList and combatInfo.objList[pos]
  89. if obj then
  90. if pos <= 10 then
  91. atkHurt = atkHurt + obj.result[1]
  92. else
  93. defHurt = defHurt + obj.result[1]
  94. end
  95. end
  96. end
  97. if atkHurt < defHurt then
  98. return true
  99. end
  100. end
  101. -- 战斗结束
  102. function onFightEnd(human, result, type, cbParam, combatInfo)
  103. --print("result",result)
  104. --require("common.Util").printTable(cbParam)
  105. --require("common.Util").printTable(combatInfo)
  106. --print("atkFormation,defFormation,atkUuid,defUuid",combatInfo.atkFormation,combatInfo.defFormation,cbParam.atkUuid,cbParam.defUuid)
  107. local state,round,leftTime = JjcGodWarLogic.getNowGodWarState()
  108. if state == JjcGodWarLogic.GODWAR_STATE_WAIT or state == JjcGodWarLogic.GODWAR_STATE_END then return end
  109. if round == JjcGodWarLogic.GODWAR_JIEDUAN_ZHUNBEI then return end
  110. if combatInfo.result.round >= combatInfo.maxRound then
  111. if CombatLogic.calcWinByHurt(combatInfo) then
  112. combatInfo.isWin = true
  113. result = CombatDefine.RESULT_WIN
  114. else
  115. combatInfo.isWin = false
  116. result = CombatDefine.RESULT_FAIL
  117. end
  118. end
  119. local winUuid = nil
  120. if CombatDefine.RESULT_WIN == result then --atkuuid胜利
  121. winUuid = cbParam.atkUuid
  122. else --defUuid胜利
  123. winUuid = cbParam.defUuid
  124. end
  125. if not winUuid then return end
  126. --选拔赛需要累计积分 赢+20 连胜额外+10 输不掉分
  127. if state <= JjcGodWarLogic.GODWAR_STATE_XUANBA6 then
  128. local winRoleData = JjcGodWarDB.getGodWarDataByUuid(winUuid)
  129. if winRoleData then
  130. local point = xuanbaPointCanGet(winUuid,state)
  131. winRoleData.combatResultList = winRoleData.combatResultList or {}
  132. winRoleData.combatResultList[state] = {}
  133. winRoleData.combatResultList[state] = point --本轮战斗获得的积分记录
  134. end
  135. end
  136. --更新战斗配对信息
  137. local fenzuID = cbParam.fenzuID
  138. local pairsIndex = cbParam.pairsIndex
  139. local match = JjcGodWarDB.getMatch2Fight(state)
  140. match[fenzuID][pairsIndex].winUuid = winUuid
  141. --保存战斗记录
  142. local vestID = JjcGodWarDB.addCombatRecord(cbParam,combatInfo,result)
  143. match[fenzuID][pairsIndex].vestID = vestID
  144. end