JjcGodWarDB.lua 37 KB

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