JjcGodWarDB.lua 38 KB

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