JjcGodWarDB.lua 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  1. ---------------------------------------
  2. -- godWarDB = {
  3. -- rank2Uuid = {},
  4. -- uuid2Roles = {},
  5. -- match2Fight = {},
  6. -- jingCai = {},
  7. -- isSendReward = nil, --发放奖励
  8. -- saveCombatState = nil, --已保存x轮的战斗数据镜像
  9. -- time = os.time(), --本期活动初始化时间
  10. -- lastTopThree = nil, --上一期前三名的信息
  11. -- }
  12. -- rank2Uuid = {}, -- rank2Uuid[rank] = uuid(包括真人与npc)
  13. -- uuid2Roles = {}, -- uuid2Roles[uuid] = roleData(包括真人与npc)
  14. -- match2Fight = {}, --各阶段比赛分组 match2Fight[state][fenzuID][paisIndex]{atkUuid,defUuid,winUuid,vestID}
  15. -- 选拔赛 fenzuID只有1
  16. -- 32强 16强 8强 fenzuID最大4
  17. -- 4强 决赛 fenzuID只有1
  18. -- match2Fight[选拔赛1][1][双方队伍1]
  19. -- match2Fight[32强][1][双方队伍1]
  20. -- match2Fight[32强][2][双方队伍1]
  21. -- jingCai = {}, --竞猜队伍 jingCai[state]{fenzuID,pairsIndex,yazhu{atkuuid=nil,defuuid=nil}}
  22. -- jingCai[选拔赛1]{fenzuID=分组1,pairIndex=双方队伍1,yazhu{atkuuid=1,defuuid=nil}}
  23. ---------------------------------------
  24. local LuaMongo = _G.lua_mongo
  25. local DB = require("common.DB")
  26. local Util = require("common.Util")
  27. local ObjHuman = require("core.ObjHuman")
  28. local CombatVideo = require("combat.CombatVideo")
  29. local CreateRole = require("role.CreateRole")
  30. local JjcGodWarExcel = require("excel.jjcGodWar")
  31. local RoleDBLogic = require("role.RoleDBLogic")
  32. local JjcDB = require("jjc.JjcDB")
  33. local JjcGodWarLogic = require("jjcGodWar.JjcGodWarLogic")
  34. local RoleLogic = require("role.RoleLogic")
  35. local CombatLogic = require("combat.CombatLogic")
  36. local CombatDefine = require("combat.CombatDefine")
  37. local CombatPosLogic = require("combat.CombatPosLogic")
  38. local WarReportLogic = require("warReport.WarReportLogic")
  39. GODWAR_FIGHT_MAX = 128 --竞技场积分排名前128名参加
  40. GODWAR_FENZU_32 = 32 --选拔赛,竞技场前32名不会相遇
  41. local DBUpdate = { _id = nil }
  42. local DBUpdateField = {} --更新域
  43. local QueryByVestID = {_id = nil}
  44. GODWAR_DB = GODWAR_DB or {}
  45. function initAfterStart()
  46. if _G.is_middle == true then return end
  47. LuaMongo.find(DB.db_jjcGodWar)
  48. local godWarDB = {}
  49. if not LuaMongo.next(godWarDB) then
  50. return
  51. end
  52. GODWAR_DB = godWarDB
  53. end
  54. -- 活动开始时 初始化
  55. function initGodWar()
  56. local db = {
  57. rank2Uuid = {}, -- rank2Uuid[rank] = uuid
  58. uuid2Roles = {}, -- uuid2Roles[uuid] = data
  59. match2Fight = {[0]=0}, --各阶段比赛分组 match2Fight[state][fenzuID][paisIndex] match2Fight[选拔赛1][分组1(abcd)][双方队伍1]{atkUuid,defUuid,winUuid,vestID}
  60. jingCai = {[0]=0}, --竞猜队伍 jingCai[state][fenzuID,pairsIndex,yazhu] jingCai[选拔赛1][fenzuID=分组1,pairIndex=1,yazhu{atkuuid=nil,defuuid=nil}]
  61. isSendReward = nil, --发放奖励
  62. saveCombatState = nil, --已保存x轮的战斗数据镜像
  63. time = os.time(), --本期活动初始化时间
  64. lastTopThree = nil, --上一期前三名的信息
  65. uuid2Yazhu = nil, --玩家押注信息 uuid2Yazhu[uuid]{jingCai[state],jingCaiBi}
  66. pointCheckState = nil, --已结算x轮积分
  67. jingCaiCalcState = nil, --竞猜x轮结算
  68. danMuList = {}, -- 弹幕
  69. }
  70. -- 清理多余的战斗数据记录
  71. LuaMongo.remove(DB.db_jjcGodWar_record)
  72. LuaMongo.find(DB.db_jjcGodWar)
  73. local godWarDB = {}
  74. if not LuaMongo.next(godWarDB) then
  75. LuaMongo.insert(DB.db_jjcGodWar, db)
  76. godWarDB = db
  77. end
  78. local rank2Uuid = godWarDB.rank2Uuid
  79. local uuid2Roles = godWarDB.uuid2Roles
  80. godWarDB = db
  81. if rank2Uuid and #rank2Uuid >= 1 then
  82. godWarDB.lastTopThree = {}
  83. for rank=1,3 do
  84. local uuid = rank2Uuid[rank]
  85. local roleData = uuid2Roles[uuid]
  86. if roleData then
  87. godWarDB.lastTopThree[rank] = roleData
  88. end
  89. end
  90. end
  91. local conf = JjcGodWarExcel.define[1]
  92. local jjcRank2Data = JjcDB.RANK_2_JJCDATA
  93. for rank=1,GODWAR_FIGHT_MAX do
  94. local roleData = nil
  95. local jjcData = jjcRank2Data[rank]
  96. local uuid = jjcData._id
  97. if not JjcDB.isNpc(jjcData) then
  98. local fakeDB = RoleDBLogic.getDb(uuid)
  99. local fakeHuman = {}
  100. fakeHuman.db = fakeDB
  101. local combatHero = CombatPosLogic.getCombatHeros(fakeHuman, CombatDefine.COMBAT_TYPE4)
  102. if CombatLogic.isCombatHeroEmpty(combatHero) then
  103. CombatPosLogic.copyCombatHeros(fakeHuman, CombatDefine.COMBAT_TYPE1, CombatDefine.COMBAT_TYPE4)
  104. ObjHuman.save(fakeHuman)
  105. end
  106. local objList, helpList, rolebase, formation, _, elfList = CombatLogic.getHumanObjList(fakeHuman, CombatDefine.COMBAT_TYPE4)
  107. roleData = {}
  108. roleData.objList = Util.copyTable(objList)
  109. roleData.helpList = Util.copyTable(helpList)
  110. roleData.elfList = Util.copyTable(elfList)
  111. roleData.rolebase = Util.copyTable(rolebase)
  112. roleData.formation = formation
  113. else
  114. roleData = Util.copyTable(jjcData)
  115. end
  116. if roleData then
  117. godWarDB.rank2Uuid[rank] = uuid
  118. roleData.uuid = uuid
  119. roleData.point = math.floor(jjcData.point * conf.jifenXuanBaGap)
  120. roleData.beiMoBai = 0
  121. roleData.sendFinalTip = nil --结算面板
  122. roleData.combatResultList = nil --胜利列表
  123. roleData.chenghao = nil --称号
  124. -- if not JjcDB.isNpc(jjcData) then
  125. -- require("common.Util").printTable(roleData)
  126. -- end
  127. godWarDB.uuid2Roles[uuid] = roleData
  128. end
  129. end
  130. --本期活动开始 先分组选拔赛
  131. godWarXuanBaFenZu(godWarDB)
  132. updateGodWarDB(godWarDB)
  133. --WarReportLogic.removeByType(WarReportLogic.WAR_REPORT_2)
  134. return godWarDB
  135. end
  136. -- 获取godWarDB
  137. function getGodWarDB()
  138. return GODWAR_DB
  139. end
  140. -- 获取个人信息 通过uuid
  141. function getGodWarDataByUuid(uuid)
  142. local uuid2Roles = getGodWarUuid2Roles()
  143. if not uuid2Roles then return end
  144. return uuid2Roles[uuid]
  145. end
  146. function getRankByUuid(uuid)
  147. local rank2Uuid = getGodWarRank2Uuid()
  148. if not rank2Uuid then return end
  149. for i=1,#rank2Uuid do
  150. if uuid == rank2Uuid[i] then
  151. return i
  152. end
  153. end
  154. end
  155. function getGodWarRank2Uuid()
  156. return GODWAR_DB.rank2Uuid
  157. end
  158. function getGodWarUuid2Roles()
  159. return GODWAR_DB.uuid2Roles
  160. end
  161. function getGodWarMatch2Fight()
  162. return GODWAR_DB.match2Fight
  163. end
  164. function getGodWarLastTopThree()
  165. return GODWAR_DB.lastTopThree
  166. end
  167. function getGodWarUuid2Yazhu()
  168. return GODWAR_DB.uuid2Yazhu
  169. end
  170. function getGodWarDanMuList()
  171. return GODWAR_DB.danMuList
  172. end
  173. -- 获取个人信息 通过排名
  174. function getGodWarDataByRank(rank)
  175. if not GODWAR_DB.rank2Uuid or
  176. not GODWAR_DB.uuid2Roles then return end
  177. local targetUuid = GODWAR_DB.rank2Uuid[rank]
  178. return GODWAR_DB.uuid2Roles[targetUuid]
  179. end
  180. --更新DB信息
  181. function updateGodWarDB(godWarDB)
  182. DBUpdate._id = godWarDB._id
  183. LuaMongo.update(DB.db_jjcGodWar, DBUpdate, godWarDB)
  184. GODWAR_DB = godWarDB
  185. end
  186. --更新db中排名信息
  187. function updateGodWarRank(rank2Uuid)
  188. DBUpdate._id = GODWAR_DB._id
  189. DBUpdateField = {["$set"]={["rank2Uuid"]=rank2Uuid}}
  190. LuaMongo.update(DB.db_jjcGodWar, DBUpdate, DBUpdateField)
  191. GODWAR_DB.rank2Uuid = rank2Uuid
  192. end
  193. --更新db中玩家信息通过uuid
  194. function updateGodWarRoleDataByUuid(roleData,uuid)
  195. DBUpdate._id = GODWAR_DB._id
  196. DBUpdateField = {["$set"]={["uuid2Roles."..uuid]=roleData}}
  197. LuaMongo.update(DB.db_jjcGodWar, DBUpdate, DBUpdateField)
  198. GODWAR_DB.uuid2Roles[uuid] = roleData
  199. end
  200. --更新db中玩家信息
  201. function updateGodWarRoleData(uuid2Roles)
  202. DBUpdate._id = GODWAR_DB._id
  203. DBUpdateField = {["$set"]={["uuid2Roles"]=uuid2Roles}}
  204. LuaMongo.update(DB.db_jjcGodWar, DBUpdate, DBUpdateField)
  205. GODWAR_DB.uuid2Roles = uuid2Roles
  206. end
  207. --更新db中玩家竞猜信息通过uuid
  208. function updateGodWarYaZhuByUuid(yazhuData,uuid)
  209. DBUpdate._id = GODWAR_DB._id
  210. DBUpdateField = {["$set"]={["uuid2Yazhu."..uuid]=yazhuData}}
  211. LuaMongo.update(DB.db_jjcGodWar, DBUpdate, DBUpdateField)
  212. GODWAR_DB.uuid2Yazhu[uuid] = yazhuData
  213. end
  214. --更新db中玩家竞猜信息
  215. function updateGodWarYaZhu(uuid2Yazhu)
  216. DBUpdate._id = GODWAR_DB._id
  217. DBUpdateField = {["$set"]={["uuid2Yazhu"]=uuid2Yazhu}}
  218. LuaMongo.update(DB.db_jjcGodWar, DBUpdate, DBUpdateField)
  219. GODWAR_DB.uuid2Yazhu = uuid2Yazhu
  220. end
  221. function updateJingCaiData(state,jingCaiData)
  222. DBUpdate._id = GODWAR_DB._id
  223. DBUpdateField = {["$set"]={["jingCai."..state]=jingCaiData}}
  224. LuaMongo.update(DB.db_jjcGodWar, DBUpdate, DBUpdateField)
  225. GODWAR_DB.jingCai[state] = jingCaiData
  226. end
  227. --更新db中押注信息
  228. function jingCaiYaUpdate(targetUuid)
  229. local state,round,leftTime = JjcGodWarLogic.getNowGodWarState()
  230. if state == JjcGodWarLogic.GODWAR_STATE_WAIT or state == JjcGodWarLogic.GODWAR_STATE_END then return end
  231. local jingCaiData = getGodWarJingCaiData(state)
  232. if not jingCaiData then return end
  233. jingCaiData.yaZhu = jingCaiData.yaZhu or {}
  234. if not jingCaiData.yaZhu[targetUuid] then
  235. jingCaiData.yaZhu[targetUuid] = 1
  236. end
  237. updateJingCaiData(state,jingCaiData)
  238. end
  239. --更新个人押注记录
  240. function updateYaZhuByUuid(uuid,yaUuid,yaZhuCnt)
  241. local state,round,leftTime = JjcGodWarLogic.getNowGodWarState()
  242. if state == JjcGodWarLogic.GODWAR_STATE_WAIT or state == JjcGodWarLogic.GODWAR_STATE_END then return end
  243. local uuid2Yazhu = getYaZhuDataByUuid(uuid)
  244. if not uuid2Yazhu then return end
  245. local yazhuData = {
  246. yaUuid = yaUuid,
  247. yaZhuCnt = yaZhuCnt,
  248. }
  249. uuid2Yazhu.jingCai = uuid2Yazhu.jingCai or {}
  250. uuid2Yazhu.jingCai[state] = yazhuData
  251. updateGodWarYaZhuByUuid(uuid2Yazhu,uuid)
  252. end
  253. -- 更新32强赛分组
  254. function updateMatch2Fight(match2FightData,state)
  255. --require("common.Util").printTable(match2FightData)
  256. DBUpdate._id = GODWAR_DB._id
  257. DBUpdateField = {["$set"]={["match2Fight."..state]=match2FightData}}
  258. LuaMongo.update(DB.db_jjcGodWar, DBUpdate, DBUpdateField)
  259. GODWAR_DB.match2Fight[state] = match2FightData
  260. end
  261. function updateDanMu(uuid, desc)
  262. local list = getGodWarDanMuList()
  263. if not list then
  264. GODWAR_DB.danMuList = {}
  265. list = getGodWarDanMuList()
  266. end
  267. list[#list + 1] = {}
  268. list[#list].uuid = uuid
  269. list[#list].desc = desc
  270. if #list > 150 then
  271. for i = 1, 150 do
  272. list[i] = list[i + 1]
  273. end
  274. end
  275. end
  276. local function checkAtkGroupID(checkGroup,atkGroupID)
  277. for atk,def in pairs(checkGroup) do
  278. if def == atkGroupID then
  279. return
  280. end
  281. end
  282. return true
  283. end
  284. function makeRankGroup(group,min,max)
  285. local randGroup = {}
  286. for rank=min,max do
  287. local index = #randGroup + 1
  288. randGroup[index] = rank
  289. end
  290. for i=min,max do
  291. local randIndex = math.random(1,#randGroup)
  292. local randRank = randGroup[randIndex]
  293. group[#group+1] = randRank
  294. randGroup[randIndex],randGroup[#randGroup] = randGroup[#randGroup],randGroup[randIndex]
  295. randGroup[#randGroup] = nil
  296. end
  297. end
  298. --选拔赛分组初始化
  299. --竞技场前32强选拔赛不会相遇
  300. --在6轮选拔赛中只会相遇相同对手1次
  301. function godWarXuanBaFenZu(godWarDB)
  302. local state,round,leftTime = JjcGodWarLogic.getNowGodWarState()
  303. if state == JjcGodWarLogic.GODWAR_STATE_WAIT or state == JjcGodWarLogic.GODWAR_STATE_END then return end
  304. if godWarDB.match2Fight[state] then return end
  305. local rank2Uuid = godWarDB.rank2Uuid
  306. --选拔赛
  307. if state >= JjcGodWarLogic.GODWAR_STATE_XUANBA1
  308. and state <= JjcGodWarLogic.GODWAR_STATE_XUANBA6 then
  309. --竞技场前32强选拔赛不会相遇
  310. --相遇对手只有1次
  311. --128人分成4组,两两配对
  312. --第一轮(1,2)(3,4) 第二轮 (1,2)(3,4)反转
  313. local xuanbaList = {
  314. [1] = {2, 2, 3, 3, 4, 4},
  315. [2] = {1, 1, 4, 4, 3, 3},
  316. [3] = {4, 4, 1, 1, 2, 2},
  317. [4] = {3, 3, 2, 2, 1, 1},
  318. }
  319. local randGroup = {}
  320. makeRankGroup(randGroup,1,32)
  321. makeRankGroup(randGroup,33,128)
  322. local n = 0
  323. local xuanbaGroup = {}
  324. for i=1,#xuanbaList do
  325. xuanbaGroup[i] = {}
  326. for j=1,#rank2Uuid / #xuanbaList do
  327. n = n + 1
  328. local rank = randGroup[n]
  329. xuanbaGroup[i][#xuanbaGroup[i] + 1] = rank
  330. end
  331. end
  332. for i=1,JjcGodWarLogic.GODWAR_STATE_XUANBA6 do
  333. local checkGroup = {}
  334. godWarDB.match2Fight[i] = {}
  335. godWarDB.match2Fight[i][1] = {}
  336. local pairsData = {}
  337. for j=1,#xuanbaList do
  338. atkGroupID = j
  339. defGroupID = xuanbaList[j][i]
  340. if checkAtkGroupID(checkGroup,atkGroupID) then
  341. checkGroup[atkGroupID] = defGroupID
  342. local groupAtk = xuanbaGroup[j]
  343. local groupDef = xuanbaGroup[defGroupID]
  344. if i % 2 == 1 then --第一次
  345. for k=1,#groupAtk do
  346. local atkUuid = rank2Uuid[groupAtk[k]]
  347. local defUuid = rank2Uuid[groupDef[k]]
  348. local index = #godWarDB.match2Fight[i][1] + 1
  349. godWarDB.match2Fight[i][1][index] = {}
  350. godWarDB.match2Fight[i][1][index].atkUuid = atkUuid
  351. godWarDB.match2Fight[i][1][index].defUuid = defUuid
  352. godWarDB.match2Fight[i][1][index].winUuid = nil
  353. godWarDB.match2Fight[i][1][index].vestID = nil
  354. godWarDB.match2Fight[i][1][index].atkRank = groupAtk[k] -- 测试
  355. godWarDB.match2Fight[i][1][index].defRank = groupDef[k] -- 测试
  356. end
  357. else --第二次
  358. for k=1,#groupAtk do
  359. local atkUuid = rank2Uuid[groupAtk[k]]
  360. local defUuid = rank2Uuid[groupDef[#groupAtk - k + 1]]
  361. local index = #godWarDB.match2Fight[i][1] + 1
  362. godWarDB.match2Fight[i][1][index] = {}
  363. godWarDB.match2Fight[i][1][index].atkUuid = atkUuid
  364. godWarDB.match2Fight[i][1][index].defUuid = defUuid
  365. godWarDB.match2Fight[i][1][index].winUuid = nil
  366. godWarDB.match2Fight[i][1][index].vestID = nil
  367. godWarDB.match2Fight[i][1][index].atkRank = groupAtk[k] -- 测试
  368. godWarDB.match2Fight[i][1][index].defRank = groupDef[#groupAtk - k + 1] -- 测试
  369. end
  370. end
  371. end
  372. end
  373. end
  374. end
  375. --require("common.Util").printTable(godWarDB.match2Fight)
  376. end
  377. -- 通过state获得排位分组
  378. function getMatch2Fight(state)
  379. if not GODWAR_DB.match2Fight then return end
  380. return GODWAR_DB.match2Fight[state]
  381. end
  382. --排位赛分组
  383. --32强-决斗,比较特殊 32个玩家分成4组abcd,每组8个人
  384. --32强赛每组决出4个胜利者一共16人
  385. --16强赛每组决出2个胜利者一共8人
  386. --8强赛每组决出1个胜利者一共4人
  387. --4强赛剩余四个人形成一个小组,两两配对,决出2个胜利者
  388. --决赛剩余两人,争夺冠亚军,季军由4强中落选两人积分最高或统计分战斗力最高者担任
  389. function paiweiFenzu(state)
  390. if state >= JjcGodWarLogic.GODWAR_STATE_END then return end
  391. if getMatch2Fight(state) then return end
  392. local rank2Uuid = getGodWarRank2Uuid()
  393. if not rank2Uuid then return end
  394. local match2FightData = nil
  395. if state == JjcGodWarLogic.GODWAR_STATE_PAIWEI32 then --32强
  396. local group = {}
  397. for i=1,4 do
  398. group[i] = {}
  399. group[i][1] = rank2Uuid[i]
  400. end
  401. local n = 5
  402. for i=1,4 do
  403. for j=1,7 do
  404. group[i][#group[i]+1] = rank2Uuid[n]
  405. n = n + 1
  406. end
  407. end
  408. match2FightData = {}
  409. for i=1,4 do
  410. match2FightData[i] = {}
  411. local index = 1
  412. for j=1,4 do
  413. local atkUuid = group[i][index]
  414. local defUuid = group[i][index + 1]
  415. match2FightData[i][j] = {}
  416. match2FightData[i][j].atkUuid = atkUuid
  417. match2FightData[i][j].defUuid = defUuid
  418. match2FightData[i][j].winUuid = nil
  419. match2FightData[i][j].vestID = nil
  420. index = index + 2
  421. end
  422. end
  423. elseif state == JjcGodWarLogic.GODWAR_STATE_PAIWEI16 then --16强
  424. local paiwei32Pairs = getMatch2Fight(JjcGodWarLogic.GODWAR_STATE_PAIWEI32)
  425. local group = {}
  426. for i=1,#paiwei32Pairs do
  427. group[i] = {}
  428. local fenzuData = paiwei32Pairs[i]
  429. for j=1,#fenzuData do
  430. local winUuid = fenzuData[j].winUuid
  431. if not winUuid then return end
  432. group[i][j] = winUuid
  433. end
  434. end
  435. match2FightData = {}
  436. for i=1,4 do
  437. match2FightData[i] = {}
  438. local index = 1
  439. for j=1,2 do
  440. local atkUuid = group[i][index]
  441. local defUuid= group[i][index + 1]
  442. match2FightData[i][j] = {}
  443. match2FightData[i][j].atkUuid = atkUuid
  444. match2FightData[i][j].defUuid = defUuid
  445. match2FightData[i][j].winUuid = nil
  446. match2FightData[i][j].vestID = nil
  447. index = index + 2
  448. end
  449. end
  450. elseif state == JjcGodWarLogic.GODWAR_STATE_PAIWEI8 then --8强
  451. local paiwei16Pairs = getMatch2Fight(JjcGodWarLogic.GODWAR_STATE_PAIWEI16)
  452. local group = {}
  453. for i=1,#paiwei16Pairs do
  454. group[i] = {}
  455. local fenzuData = paiwei16Pairs[i]
  456. for j=1,#fenzuData do
  457. local winUuid = fenzuData[j].winUuid
  458. if not winUuid then return end
  459. group[i][j] = winUuid
  460. end
  461. end
  462. match2FightData = {}
  463. for i=1,4 do
  464. match2FightData[i] = {}
  465. local atkUuid = group[i][1]
  466. local defUuid= group[i][2]
  467. match2FightData[i][1] = {}
  468. match2FightData[i][1].atkUuid = atkUuid
  469. match2FightData[i][1].defUuid = defUuid
  470. match2FightData[i][1].winUuid = nil
  471. match2FightData[i][1].vestID = nil
  472. end
  473. elseif state == JjcGodWarLogic.GODWAR_STATE_PAIWEI4 then --4强
  474. local paiwei8Pairs = getMatch2Fight(JjcGodWarLogic.GODWAR_STATE_PAIWEI8)
  475. local group = {}
  476. for i=1,#paiwei8Pairs do
  477. local fenzuData = paiwei8Pairs[i]
  478. local winUuid = fenzuData[1].winUuid
  479. if not winUuid then return end
  480. group[i] = winUuid
  481. end
  482. match2FightData = {}
  483. match2FightData[1] = {}
  484. local index = 1
  485. for i=1,2 do
  486. local atkUuid = group[index]
  487. local defUuid= group[index + 1]
  488. match2FightData[1][i] = {}
  489. match2FightData[1][i].atkUuid = atkUuid
  490. match2FightData[1][i].defUuid = defUuid
  491. match2FightData[1][i].winUuid = nil
  492. match2FightData[1][i].vestID = nil
  493. index = index + 2
  494. end
  495. elseif state == JjcGodWarLogic.GODWAR_STATE_PAIWEI1 then --决赛
  496. local paiwei4Pairs = getMatch2Fight(JjcGodWarLogic.GODWAR_STATE_PAIWEI4)
  497. local group = {}
  498. for i=1,#paiwei4Pairs do
  499. local data = paiwei4Pairs[i]
  500. for j=1,#data do
  501. local winUuid = data[j].winUuid
  502. if not winUuid then return end
  503. group[j] = winUuid
  504. end
  505. end
  506. local atkUuid = group[1]
  507. local defUuid= group[2]
  508. --print("atkUuid,defUuid",atkUuid,defUuid)
  509. match2FightData = {}
  510. match2FightData[1] = {}
  511. match2FightData[1][1] = {}
  512. match2FightData[1][1].atkUuid = atkUuid
  513. match2FightData[1][1].defUuid = defUuid
  514. match2FightData[1][1].winUuid = nil
  515. match2FightData[1][1].vestID = nil
  516. end
  517. if match2FightData then
  518. updateMatch2Fight(match2FightData,state)
  519. --require("common.Util").printTable(match2FightData)
  520. end
  521. end
  522. -- 检查队伍数据,若无则按排名强制生成
  523. function checkMatch(state)
  524. local rank2Uuid = getGodWarRank2Uuid()
  525. if not rank2Uuid then return end
  526. for i=JjcGodWarLogic.GODWAR_STATE_PAIWEI32,state do
  527. if not getMatch2Fight(i) then
  528. local match2FightData = nil
  529. local fenzuMax = nil
  530. local pairsMax = nil
  531. if i == JjcGodWarLogic.GODWAR_STATE_PAIWEI32 then
  532. paiweiFenzu(i)
  533. elseif state == JjcGodWarLogic.GODWAR_STATE_PAIWEI16 then --16强
  534. fenzuMax = 4
  535. pairsMax = 2
  536. elseif state == JjcGodWarLogic.GODWAR_STATE_PAIWEI8 then --8强
  537. fenzuMax = 4
  538. pairsMax = 1
  539. elseif state == JjcGodWarLogic.GODWAR_STATE_PAIWEI4 then --4强
  540. fenzuMax = 1
  541. pairsMax = 2
  542. elseif state == JjcGodWarLogic.GODWAR_STATE_PAIWEI1 then --决赛
  543. fenzuMax = 1
  544. pairsMax = 1
  545. end
  546. if fenzuMax and pairsMax then
  547. match2FightData = {}
  548. local pairsIndex = 1
  549. for fenzu=1,fenzuMax do
  550. for pairs=1,pairsMax do
  551. match2FightData[fenzu] = match2FightData[fenzu] or {}
  552. local index = #match2FightData[fenzu] + 1
  553. match2FightData[fenzu][index] = {}
  554. local atkUuid = rank2Uuid[pairsIndex]
  555. local defUuid = rank2Uuid[pairsIndex + 1]
  556. match2FightData[fenzu][index].atkUuid = atkUuid
  557. match2FightData[fenzu][index].defUuid = defUuid
  558. pairsIndex = pairsIndex + 2
  559. end
  560. end
  561. updateMatch2Fight(match2FightData,i)
  562. end
  563. end
  564. end
  565. end
  566. -- 获取战斗力
  567. function getNowZhandouli(uuid)
  568. local roleData = getGodWarDataByUuid(uuid)
  569. --print("uuid,roleData",uuid,roleData)
  570. local zhandouli = 0
  571. if not JjcDB.isNpc(roleData) then
  572. local fakeHuman = {}
  573. fakeHuman.db = RoleDBLogic.getDb(uuid, RoleLogic.getCombatField())
  574. if not fakeHuman.db then
  575. fakeHuman.db = roleData
  576. end
  577. zhandouli = CombatPosLogic.getCombatHeroZDL(fakeHuman, CombatDefine.COMBAT_TYPE4)
  578. else
  579. zhandouli = roleData.zhandouli
  580. end
  581. return zhandouli
  582. end
  583. --获取当前的x强排位赛所有配对,纯数据读取,选择性分组
  584. function getNowPaiWeiAll(state,fenzuID)
  585. local data = getMatch2Fight(state)
  586. if not data then return end
  587. --print("data,#data",data,#data)
  588. local group = {}
  589. if not fenzuID then
  590. for i=1,#data do
  591. local fenzuData = data[i]
  592. --print("#fenzuData",#fenzuData)
  593. for j=1,#fenzuData do
  594. local pairsData = fenzuData[j]
  595. --print("atkUuid",pairsData.atkUuid)
  596. group[#group + 1] = pairsData
  597. end
  598. end
  599. else
  600. for i=1,#data do
  601. if i == fenzuID then
  602. local fenzuData = data[i]
  603. --print("#fenzuData",#fenzuData)
  604. for j=1,#fenzuData do
  605. local pairsData = fenzuData[j]
  606. --print("atkUuid",pairsData.atkUuid)
  607. group[#group + 1] = pairsData
  608. end
  609. end
  610. end
  611. end
  612. return group
  613. end
  614. -- 通过state获得当前界面需要展示的所有的配对信息
  615. function getNowPaiWeiFenzu(nowState,fenzuID)
  616. if not getMatch2Fight(nowState) then return end
  617. local group = nil
  618. if nowState <= JjcGodWarLogic.GODWAR_STATE_PAIWEI8 then --32,16,8 需要合并数据
  619. for state=JjcGodWarLogic.GODWAR_STATE_PAIWEI32,nowState do
  620. local data = getNowPaiWeiAll(state,fenzuID)
  621. if data then
  622. group = group or {}
  623. group[state] = data
  624. end
  625. end
  626. else
  627. for i=JjcGodWarLogic.GODWAR_STATE_PAIWEI4,nowState do
  628. local data = getNowPaiWeiAll(i,fenzuID)
  629. if data then
  630. group = group or {}
  631. group[i] = data
  632. end
  633. end
  634. end
  635. return group
  636. end
  637. --获取最小战斗力差
  638. local function getZhandouLiMinPair(state)
  639. local match2Fight = getMatch2Fight(state)
  640. local min = nil
  641. local fenzuID = nil
  642. local index = nil
  643. for i=1,#match2Fight do
  644. local fenzuData = match2Fight[i]
  645. for j=1,#fenzuData do
  646. local atkUuid = fenzuData[j].atkUuid
  647. local defUuid = fenzuData[j].defUuid
  648. local atkZhandouli = getNowZhandouli(atkUuid)
  649. local defZhandouli = getNowZhandouli(defUuid)
  650. local cha = 0
  651. if atkZhandouli > defZhandouli then
  652. cha = atkZhandouli - defZhandouli
  653. else
  654. cha = defZhandouli - atkZhandouli
  655. end
  656. --print("i,j,atkZhandouli,defZhandouli,cha",i,j,atkZhandouli,defZhandouli,cha)
  657. if not min or cha < min then
  658. min = cha
  659. fenzuID = i
  660. index = j
  661. end
  662. end
  663. end
  664. --print("min,fenzuID,index",min,fenzuID,index)
  665. return fenzuID,index
  666. end
  667. --生成竞猜队伍
  668. function godWarJingCaiPairs()
  669. local state,round,leftTime = JjcGodWarLogic.getNowGodWarState()
  670. if state == JjcGodWarLogic.GODWAR_STATE_WAIT or state == JjcGodWarLogic.GODWAR_STATE_END then return end
  671. if getGodWarJingCaiData(state) then return end
  672. local match2Fight = getMatch2Fight(state)
  673. if not match2Fight then return end
  674. if state > JjcGodWarLogic.GODWAR_STATE_PAIWEI32 then
  675. local jingPaiWeiData = getGodWarJingCaiData(state-1)
  676. if jingPaiWeiData then
  677. local fenzuID = jingPaiWeiData.fenzuID
  678. local jingPaiWei2Fight = getGodWarJingCaiPairs(state-1)
  679. local winUuid = jingPaiWei2Fight.winUuid
  680. if winUuid then
  681. if #match2Fight == 1 then
  682. fenzuID = 1
  683. end
  684. local fenzuData = match2Fight[fenzuID]
  685. --print("fenzuID,winUuid,fenzuData,state",fenzuID,winUuid,fenzuData,state)
  686. for i=1,#fenzuData do
  687. local pairsData = fenzuData[i]
  688. if pairsData.atkUuid == winUuid or pairsData.defUuid == winUuid then
  689. local jingCaiData = {}
  690. jingCaiData.fenzuID = fenzuID
  691. jingCaiData.pairsIndex = i
  692. jingCaiData.yaZhu = nil
  693. --print("==================state,winUuid",state,winUuid)
  694. updateJingCaiData(state,jingCaiData)
  695. return
  696. end
  697. end
  698. end
  699. end
  700. end
  701. local fenzuID,index = getZhandouLiMinPair(state)
  702. --print("fenzuID,index",fenzuID,index)
  703. if not fenzuID then return end
  704. local jingCaiData = {}
  705. --print("==================state,#fenzuData,atkUuid,defUuid",state,#fenzuData,atkUuid,defUuid)
  706. jingCaiData.fenzuID = fenzuID
  707. jingCaiData.pairsIndex = index
  708. jingCaiData.yaZhu = nil
  709. updateJingCaiData(state,jingCaiData)
  710. end
  711. --获取配对信息
  712. function getGodWarPairsDataByUuid(targetUuid)
  713. local state,round,leftTime = JjcGodWarLogic.getNowGodWarState()
  714. if state == JjcGodWarLogic.GODWAR_STATE_WAIT then return end --活动开始倒计时界面,不需要显示战斗
  715. local roleData = getGodWarDataByUuid(targetUuid)
  716. local rank = getRankByUuid(targetUuid)
  717. if not roleData then return end --没资格的,不需要显示战斗
  718. local match2Fight = nil
  719. local nowCombat = true
  720. local getMatch2FightState = nil
  721. if state == JjcGodWarLogic.GODWAR_STATE_END then
  722. if rank > 32 then --取选拔赛6战斗
  723. getMatch2FightState = JjcGodWarLogic.GODWAR_STATE_XUANBA6
  724. elseif rank > 16 and rank <= 32 then --取排位赛32强战斗
  725. getMatch2FightState = JjcGodWarLogic.GODWAR_STATE_PAIWEI32
  726. elseif rank > 8 and rank <= 16 then --取排位赛16强战斗
  727. getMatch2FightState = JjcGodWarLogic.GODWAR_STATE_PAIWEI16
  728. elseif rank > 4 and rank <= 8 then --取排位赛8强战斗
  729. getMatch2FightState = JjcGodWarLogic.GODWAR_STATE_PAIWEI8
  730. elseif rank > 2 and rank <= 4 then --取排位赛4强战斗
  731. getMatch2FightState = JjcGodWarLogic.GODWAR_STATE_PAIWEI4
  732. elseif rank <= 2 then --取排位赛决赛战斗
  733. getMatch2FightState = JjcGodWarLogic.GODWAR_STATE_PAIWEI1
  734. end
  735. nowCombat = false
  736. else
  737. --取当前战斗
  738. --排位赛时,显示玩家最终止步的战斗
  739. if rank > 32 then
  740. if state >= JjcGodWarLogic.GODWAR_STATE_PAIWEI32 then
  741. getMatch2FightState = JjcGodWarLogic.GODWAR_STATE_XUANBA6
  742. nowCombat = false
  743. end
  744. elseif rank > 16 and rank <= 32 then
  745. if state >= JjcGodWarLogic.GODWAR_STATE_PAIWEI16 then
  746. getMatch2FightState = JjcGodWarLogic.GODWAR_STATE_PAIWEI32
  747. nowCombat = false
  748. end
  749. elseif rank > 8 and rank <= 16 then
  750. if state >= JjcGodWarLogic.GODWAR_STATE_PAIWEI8 then
  751. getMatch2FightState = JjcGodWarLogic.GODWAR_STATE_PAIWEI16
  752. nowCombat = false
  753. end
  754. elseif rank > 4 and rank <= 8 then
  755. if state >= JjcGodWarLogic.GODWAR_STATE_PAIWEI4 then
  756. getMatch2FightState = JjcGodWarLogic.GODWAR_STATE_PAIWEI8
  757. nowCombat = false
  758. end
  759. elseif rank > 2 and rank <= 4 then
  760. if state >= JjcGodWarLogic.GODWAR_STATE_PAIWEI1 then
  761. getMatch2FightState = JjcGodWarLogic.GODWAR_STATE_PAIWEI4
  762. nowCombat = false
  763. end
  764. end
  765. end
  766. --print("rank,nowCombat",rank,nowCombat)
  767. if nowCombat then
  768. getMatch2FightState = state
  769. end
  770. if getMatch2FightState then
  771. match2Fight = getMatch2Fight(getMatch2FightState)
  772. end
  773. --print("getMatch2FightState,match2Fight",getMatch2FightState,match2Fight)
  774. if not match2Fight then return end
  775. --print("match2Fight",match2Fight)
  776. for i=1,#match2Fight do
  777. local fenzuData = match2Fight[i]
  778. for j=1,#fenzuData do
  779. local pairsData = fenzuData[j]
  780. if pairsData.atkUuid == targetUuid
  781. or pairsData.defUuid == targetUuid then
  782. return pairsData,nowCombat,getMatch2FightState
  783. end
  784. end
  785. end
  786. end
  787. --获取当前竞猜信息
  788. function getGodWarJingCaiData(state)
  789. if not GODWAR_DB.jingCai then return end
  790. if state == JjcGodWarLogic.GODWAR_STATE_WAIT or state == JjcGodWarLogic.GODWAR_STATE_END then return end
  791. return GODWAR_DB.jingCai[state]
  792. end
  793. --获取当前竞猜队伍信息
  794. function getGodWarJingCaiPairs(state)
  795. if state == JjcGodWarLogic.GODWAR_STATE_WAIT or state == JjcGodWarLogic.GODWAR_STATE_END then return end
  796. local data = getGodWarJingCaiData(state)
  797. if not data then return end
  798. local fenzuID = data.fenzuID
  799. local pairsIndex = data.pairsIndex
  800. local match2Fight = getMatch2Fight(state)
  801. if not match2Fight then return end
  802. --print("fenzuID,pairsIndex",fenzuID,pairsIndex)
  803. return match2Fight[fenzuID][pairsIndex]
  804. end
  805. --获取当前竞猜队伍赔率 仅展示作用
  806. function getJingcaiPei(state)
  807. local conf = JjcGodWarExcel.jingCai[1]
  808. local jingCaiData = getGodWarJingCaiData(state)
  809. if not jingCaiData or not jingCaiData.yaZhu then
  810. return conf.jingcaiShowPei1,conf.jingcaiShowPei1
  811. end
  812. local jingCaiPairs = getGodWarJingCaiPairs(state)
  813. local atkUuid = jingCaiPairs.atkUuid
  814. local defUuid = jingCaiPairs.defUuid
  815. local atkYaZhu = jingCaiData.yaZhu[atkUuid]
  816. local defYaZhu = jingCaiData.yaZhu[defUuid]
  817. if atkYaZhu and defYaZhu then
  818. return conf.jingcaiShowPei2,conf.jingcaiShowPei2
  819. elseif not atkYaZhu and defYaZhu then
  820. return conf.jingcaiShowPei1,conf.jingcaiShowPei2
  821. elseif atkUuid and not defYaZhu then
  822. return conf.jingcaiShowPei2,conf.jingcaiShowPei1
  823. end
  824. end
  825. function getYaZhuDataByUuid(uuid)
  826. local uuid2Yazhu = getGodWarUuid2Yazhu()
  827. if not uuid2Yazhu then return end
  828. return uuid2Yazhu[uuid]
  829. end
  830. --获取个人所有押注记录
  831. function getJingCaiYaZhu(uuid)
  832. local uuid2Yazhu = getGodWarUuid2Yazhu()
  833. if not uuid2Yazhu or not uuid2Yazhu[uuid] then return end
  834. return uuid2Yazhu[uuid].jingCai
  835. end
  836. --通过阶段获取押注记录
  837. function getJingCaiYaZhuByState(uuid,state)
  838. local yazhuData = getJingCaiYaZhu(uuid)
  839. if not yazhuData then return end
  840. return yazhuData[state]
  841. end
  842. --获取当前需要生成战斗数据的2个队伍
  843. function getNowNeedCombat(state)
  844. local paiweiMatch = getMatch2Fight(state)
  845. if not paiweiMatch then return end
  846. local group = nil
  847. for i=1,#paiweiMatch do
  848. for j=1,#paiweiMatch[i] do
  849. local pairsData = paiweiMatch[i][j]
  850. if not pairsData.winUuid then
  851. group = group or {}
  852. local index = #group + 1
  853. group[index] = {}
  854. group[index].atkUuid = pairsData.atkUuid
  855. group[index].defUuid = pairsData.defUuid
  856. group[index].fenzuID = i
  857. group[index].pairsIndex = j
  858. if state == JjcGodWarLogic.GODWAR_STATE_PAIWEI1 then
  859. return paiweiMatch,group
  860. end
  861. if #group == 3 then
  862. return paiweiMatch,group
  863. end
  864. end
  865. end
  866. end
  867. if group and #group < 3 then
  868. return paiweiMatch,group
  869. end
  870. end
  871. local function getSaveZhandouli(uuid)
  872. local roleData = getGodWarDataByUuid(uuid)
  873. if not roleData then return 0 end
  874. --print("uuid,roleData",uuid,roleData)
  875. local zhandouli = 0
  876. if not JjcDB.isNpc(roleData) then
  877. zhandouli = roleData.rolebase.zhandouli
  878. else
  879. zhandouli = roleData.zhandouli
  880. end
  881. return zhandouli
  882. end
  883. --积分刷新排行榜
  884. local function cmpJiFenRank(auuid, buuid)
  885. local uuid2Roles = getGodWarUuid2Roles()
  886. local aRoleData = uuid2Roles[auuid]
  887. local bRoleData = uuid2Roles[buuid]
  888. if aRoleData.point ~= bRoleData.point then
  889. return aRoleData.point > bRoleData.point
  890. end
  891. local aZhandouli = getSaveZhandouli(auuid)
  892. local bZhandouli = getSaveZhandouli(buuid)
  893. if aZhandouli ~= bZhandouli then
  894. return aZhandouli > bZhandouli
  895. end
  896. end
  897. function sortJifenBoard()
  898. local rank2Uuid = getGodWarRank2Uuid()
  899. if not rank2Uuid then return end
  900. table.sort(rank2Uuid, cmpJiFenRank)
  901. updateGodWarRank(rank2Uuid)
  902. end
  903. --保存战斗记录
  904. function addCombatRecord(cbParam,combatInfo,result)
  905. local atkUuid = cbParam.atkUuid
  906. local defUuid = cbParam.defUuid
  907. local atkRoleData = getGodWarDataByUuid(atkUuid)
  908. local defRoleData = getGodWarDataByUuid(defUuid)
  909. if JjcDB.isNpc(atkRoleData) then
  910. combatInfo.attacker = atkRoleData
  911. end
  912. if JjcDB.isNpc(defRoleData) then
  913. combatInfo.defender = defRoleData
  914. end
  915. local record = {}
  916. record.combatInfo = combatInfo
  917. record.result = result
  918. record.time = os.time()
  919. LuaMongo.insert(DB.db_jjcGodWar_record, record)
  920. return record._id
  921. end
  922. --排位赛刷新排行榜
  923. function sortPaiWeiBoard(state)
  924. local paiweiMatch = getMatch2Fight(state)
  925. if not paiweiMatch then return end
  926. local winGroup = {}
  927. local loseGroup = {}
  928. for i=1,#paiweiMatch do
  929. local fenzuData = paiweiMatch[i]
  930. for j=1,#fenzuData do
  931. local pairsData = fenzuData[j]
  932. local atkUuid = pairsData.atkUuid
  933. local defUuid = pairsData.defUuid
  934. local winUuid = pairsData.winUuid
  935. winGroup[#winGroup+1] = winUuid
  936. local loseUuid = atkUuid
  937. if winUuid == atkUuid then
  938. loseUuid = defUuid
  939. end
  940. loseGroup[#loseGroup+1] = loseUuid
  941. end
  942. end
  943. --require("common.Util").printTable(winGroup)
  944. --require("common.Util").printTable(loseGroup)
  945. table.sort(winGroup, cmpJiFenRank)
  946. table.sort(loseGroup, cmpJiFenRank)
  947. -- require("common.Util").printTable(winGroup)
  948. -- require("common.Util").printTable(loseGroup)
  949. -- print("#winGroup,#loseGroup",#winGroup,#loseGroup)
  950. local rank2Uuid = getGodWarRank2Uuid()
  951. if not rank2Uuid then return end
  952. for i=1,#winGroup do
  953. rank2Uuid[i] = winGroup[i]
  954. end
  955. --print("#winGroup",#winGroup)
  956. local index = 0
  957. local finalRank = #loseGroup+#winGroup
  958. for i=#winGroup+1,finalRank do
  959. index = index + 1
  960. rank2Uuid[i] = loseGroup[index]
  961. end
  962. --require("common.Util").printTable(rank2Uuid)
  963. updateGodWarRank(rank2Uuid)
  964. end
  965. --获取参与的所有比赛,没有win就是还没开打
  966. function getAllMatchByUuid(uuid)
  967. local match2Fight = getGodWarMatch2Fight()
  968. if not match2Fight then return end
  969. if #match2Fight < 1 then return end
  970. local myComBat = nil
  971. for state=1,#match2Fight do
  972. local stateData = match2Fight[state]
  973. if stateData then
  974. for fenzuID=1,#stateData do
  975. local fenzuData = stateData[fenzuID]
  976. for pairsIndex=1,#fenzuData do
  977. local pairsData = fenzuData[pairsIndex]
  978. local atkUuid = pairsData.atkUuid
  979. local defUuid = pairsData.defUuid
  980. if atkUuid == uuid or
  981. defUuid == uuid then
  982. myComBat = myComBat or {}
  983. local index = #myComBat + 1
  984. myComBat[index] = {}
  985. myComBat[index].state = state
  986. myComBat[index].winUuid = pairsData.winUuid or ""
  987. myComBat[index].vestID = pairsData.vestID or ""
  988. myComBat[index].atkUuid = atkUuid
  989. myComBat[index].defUuid = defUuid
  990. end
  991. end
  992. end
  993. end
  994. end
  995. return myComBat
  996. end
  997. --获取战斗结果列表
  998. function getCombatResultListByUuid(uuid)
  999. local roleData = getGodWarDataByUuid(uuid)
  1000. if not roleData then return end
  1001. return roleData.combatResultList
  1002. end
  1003. -- 根据记录id获取记录详情
  1004. function getRecord(vestID)
  1005. if not vestID then return end
  1006. QueryByVestID._id = vestID
  1007. local record = {}
  1008. LuaMongo.find(DB.db_jjcGodWar_record, QueryByVestID)
  1009. if not LuaMongo.next(record) then
  1010. return
  1011. end
  1012. return record
  1013. end
  1014. -- 保存当前战斗需要数据的镜像
  1015. function saveCombatData(godWarDB,state)
  1016. if godWarDB.saveCombatState and godWarDB.saveCombatState == state then return end
  1017. local rankMax = 128
  1018. if state == JjcGodWarLogic.GODWAR_STATE_PAIWEI32 then
  1019. rankMax = 32
  1020. elseif state == JjcGodWarLogic.GODWAR_STATE_PAIWEI16 then
  1021. rankMax = 16
  1022. elseif state == JjcGodWarLogic.GODWAR_STATE_PAIWEI8 then
  1023. rankMax = 8
  1024. elseif state == JjcGodWarLogic.GODWAR_STATE_PAIWEI4 then
  1025. rankMax = 4
  1026. elseif state == JjcGodWarLogic.GODWAR_STATE_PAIWEI1 then
  1027. rankMax = 2
  1028. end
  1029. local uuid2Roles = godWarDB.uuid2Roles
  1030. local rank2Uuid = godWarDB.rank2Uuid
  1031. if not uuid2Roles or not rank2Uuid then return end
  1032. for rank=1,rankMax do
  1033. local uuid = rank2Uuid[rank]
  1034. local roleData = uuid2Roles[uuid]
  1035. if not JjcDB.isNpc(roleData) then
  1036. local fakeHuman = nil
  1037. local db = RoleDBLogic.getDb(uuid)
  1038. if db then
  1039. fakeHuman = {}
  1040. fakeHuman.db = db
  1041. local objList, helpList, rolebase,formation, _, elfList = CombatLogic.getHumanObjList(fakeHuman, CombatDefine.COMBAT_TYPE4)
  1042. roleData.objList = Util.copyTable(objList)
  1043. roleData.helpList = Util.copyTable(helpList)
  1044. roleData.elfList = Util.copyTable(elfList)
  1045. roleData.rolebase = Util.copyTable(rolebase)
  1046. roleData.formation = formation
  1047. --require("common.Util").printTable(roleData)
  1048. end
  1049. end
  1050. end
  1051. updateGodWarRoleData(uuid2Roles)
  1052. --require("common.Util").printTable(uuid2Roles)
  1053. godWarDB.saveCombatState = state
  1054. end
  1055. --竞猜币 首轮默认60,第二轮开始,上一轮有竞猜接着送60
  1056. function getJingCaiBiCnt(human,state)
  1057. if state == JjcGodWarLogic.GODWAR_STATE_WAIT or state == JjcGodWarLogic.GODWAR_STATE_END then return 0 end
  1058. local uuid2Yazhu = getGodWarUuid2Yazhu()
  1059. local yaData = nil
  1060. if not uuid2Yazhu then
  1061. local godWarDB = getGodWarDB()
  1062. godWarDB.uuid2Yazhu = {}
  1063. updateGodWarDB(godWarDB)
  1064. uuid2Yazhu = godWarDB.uuid2Yazhu
  1065. end
  1066. if not uuid2Yazhu[human.db._id] then
  1067. uuid2Yazhu[human.db._id] = {}
  1068. uuid2Yazhu[human.db._id].jingCaiBi = JjcGodWarExcel.jingCai[1].jingCaiSongBi
  1069. uuid2Yazhu[human.db._id].jingCai = nil
  1070. updateGodWarYaZhu(uuid2Yazhu)
  1071. end
  1072. -- 如果 当前回合 没有押注 并且 竞猜币为0 送60 竞猜币
  1073. if uuid2Yazhu[human.db._id].jingCaiBi <= 0 then
  1074. yaData = getJingCaiYaZhu(human.db._id)
  1075. if yaData and yaData[state] and yaData[state].yaUuid then
  1076. else
  1077. uuid2Yazhu[human.db._id].jingCaiBi = JjcGodWarExcel.jingCai[1].jingCaiSongBi
  1078. end
  1079. end
  1080. updateGodWarYaZhuByUuid(uuid2Yazhu[human.db._id],human.db._id)
  1081. return uuid2Yazhu[human.db._id].jingCaiBi
  1082. end
  1083. --保存战报
  1084. function makeZhanBao(state)
  1085. if state == JjcGodWarLogic.GODWAR_STATE_WAIT or state == JjcGodWarLogic.GODWAR_STATE_END then return end
  1086. local data = getMatch2Fight(state)
  1087. if not data then return end
  1088. for i=1,#data do
  1089. local fenzuData = data[i]
  1090. for j=1,#fenzuData do
  1091. local pairsData = fenzuData[j]
  1092. local vestID = pairsData.vestID
  1093. local atkUuid = pairsData.atkUuid
  1094. local defUuid = pairsData.defUuid
  1095. local winUuid = pairsData.winUuid
  1096. if winUuid and vestID then
  1097. local record = getRecord(vestID)
  1098. if record then
  1099. local combatInfo = record.combatInfo
  1100. if combatInfo then
  1101. local atkRank = getRankByUuid(atkUuid)
  1102. local defRank = getRankByUuid(defUuid)
  1103. WarReportLogic.add(WarReportLogic.WAR_REPORT_2, combatInfo, atkRank, defRank)
  1104. end
  1105. end
  1106. end
  1107. end
  1108. end
  1109. end