UnionWarLogic.lua 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660
  1. local Msg = require("core.Msg")
  2. local InnerMsg = require("core.InnerMsg")
  3. local ObjHuman = require("core.ObjHuman")
  4. local Util = require("common.Util")
  5. local Config = require("Config")
  6. local Lang = require("common.Lang")
  7. local LuaMongo = _G.lua_mongo
  8. local DB = require("common.DB")
  9. local RoleDBLogic = require("role.RoleDBLogic")
  10. local CombatLogic = require("combat.CombatLogic")
  11. local CombatPosLogic = require("combat.CombatPosLogic")
  12. local CombatDefine = require("combat.CombatDefine")
  13. local UnionWarDBLogic = require("union.UnionWarDBLogic")
  14. local UnionWarMiddleLogic = require("union.UnionWarMiddleLogic")
  15. local HeroGrid = require("hero.HeroGrid")
  16. local Grid = require("bag.Grid")
  17. local BagLogic = require("bag.BagLogic")
  18. local Broadcast = require("broadcast.Broadcast")
  19. local RoleDefine = require("role.RoleDefine")
  20. local UnionDBLogic = require("union.UnionDBLogic")
  21. local RoleLogic = require("role.RoleLogic")
  22. local MailManager = require("mail.MailManager")
  23. local BattleLogic = require("battle.BattleLogic")
  24. local MailDefine = require("mail.MailIdDefine")
  25. local MailExcel = require("excel.mail").mail
  26. local MonsterOutExcel = require("excel.monster").monsterOut
  27. local UnionWarExcel = require("excel.unionWar")
  28. local RobotExcel = UnionWarExcel.robot
  29. local DefineConf = UnionWarExcel.define[1]
  30. local LvExcel = UnionWarExcel.lv
  31. local RankExcel = UnionWarExcel.rank
  32. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  33. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  34. local BillboardDB = require("billboard.BillboardDB")
  35. local BillboardDefine = require("billboard.BillboardDefine")
  36. local Broadcast = require("broadcast.Broadcast")
  37. local Timer = require("core.Timer")
  38. local MiddleConnect = require("middle.MiddleConnect")
  39. local Config = require("Config")
  40. --活动阶段
  41. WDAY = {[1] = 1,[3] = 1,[5] = 1}
  42. --获取公会战阶段
  43. HOUR1 = {5,8} --确认
  44. HOUR2 = {8,12} --匹配
  45. HOUR3 = {12,20} --战斗
  46. HOUR4 = {20,24} --结算
  47. STATE0 = 0 --非活动阶段
  48. STATE1 = 1 --确认
  49. STATE2 = 2 --匹配
  50. STATE3 = 3 --战斗
  51. STATE4 = 4 --结算
  52. UNION_STATE1 = 1 --匹配成功
  53. UNION_STATE2 = 2 --确认不成功
  54. UNION_STATE3 = 3 --匹配不成功
  55. UNION_LV = 2 -- 公会等级条件
  56. UNION_HUOYUE = 5 --功会活跃人数条件
  57. HUOYUE_TIME = 86400
  58. UNION_FEIXU_CNT = 5 -- 废墟可挑战次数
  59. local function getLocalUnionWarData(localData,unionUuid)
  60. localData[unionUuid] = localData[unionUuid] or {member = {},memberCnt = 0,star = 0,cnt = 0,exp = 0,lv = 0,rank = {}}
  61. return localData[unionUuid]
  62. end
  63. local function getLocalMemberData(unionWarData,uuid)
  64. unionWarData.member[uuid] = unionWarData.member[uuid] or {name = "",cnt = 0,shop = {{},{}},chengjiu = {{},{}}}
  65. return unionWarData.member[uuid]
  66. end
  67. local function getUnionWarRankRewardID(rank)
  68. for k, v in ipairs(RankExcel) do
  69. if v.minRank <= rank and rank <= v.maxRank then
  70. return k
  71. end
  72. end
  73. return 0
  74. end
  75. local function getUnionWarData(human,memberData)
  76. if not human.db.unionWarData then
  77. human.db.unionWarData = {}
  78. human.db.unionWarData.shop = Util.copyTable(memberData.shop)
  79. human.db.unionWarData.upShopTime = memberData.upShopTime
  80. human.db.unionWarData.chengjiu = Util.copyTable(memberData.chengjiu)
  81. human.db.unionWarData.cnt = memberData.cnt
  82. end
  83. local now = os.time()
  84. if not human.db.unionWarData.upShopTime or human.db.unionWarData.upShopTime < now then
  85. human.db.unionWarData.upShopTime = Util.getWeekStartTime(now) + 86400 * 7
  86. human.db.unionWarData.shop[1] = {}
  87. end
  88. return human.db.unionWarData
  89. end
  90. function fontFakeObj(objList)
  91. local fakeList = {}
  92. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  93. local obj = objList[i]
  94. if obj then
  95. fakeList[i] = {}
  96. fakeList[i] = Util.copyTable(obj)
  97. local fake = fakeList[i]
  98. fake.beSkillList = nil
  99. fake.skillList = nil
  100. fake.beSkillListTemp = nil
  101. fake.attrs = nil
  102. fake.attrs2 = {}
  103. fake.attrs2[RoleDefine.HP] = obj.attrs[RoleDefine.HP]
  104. fake.attrs2[RoleDefine.DEF] = obj.attrs[RoleDefine.DEF]
  105. fake.attrs2[RoleDefine.ATK] = obj.attrs[RoleDefine.ATK]
  106. fake.attrs2[RoleDefine.SPEED] = obj.attrs[RoleDefine.SPEED]
  107. fake.attrs2[RoleDefine.ATK_RATE] = obj.attrs[RoleDefine.SPEED_RATE]
  108. fake.attrs2[RoleDefine.DEF_RATE] = obj.attrs[RoleDefine.SPEED_RATE]
  109. fake.attrs2[RoleDefine.HP_RATE] = obj.attrs[RoleDefine.SPEED_RATE]
  110. fake.attrs2[RoleDefine.SPEED_RATE] = obj.attrs[RoleDefine.SPEED_RATE]
  111. -- fake.attrsting = ""
  112. -- for k,v in pairs(obj.attrs) do
  113. -- fake.attrsting = fake.attrsting .. "|" .. k.. "," .. v
  114. -- end
  115. end
  116. end
  117. return fakeList
  118. end
  119. local function getData(data)
  120. if data.lv < UNION_LV then return end
  121. local unionData = {member = {}}
  122. local len = 0
  123. local huoyueCnt = 0
  124. local sortList = {}
  125. local localData = UnionWarDBLogic.getLocalData()
  126. local unionUuid = data._id
  127. local now = os.time()
  128. local d = os.date("*t",now)
  129. d.hour = HOUR4[1]
  130. d.min = 0
  131. d.sec = 0
  132. local boxEndTime = os.time(d) + 24 * 3600
  133. local donateTime = Util.getDayStartTime(os.time())
  134. donateTime = donateTime - HUOYUE_TIME
  135. localData[unionUuid] = localData[unionUuid] or {member = {},memberCnt = 0,star = 0,cnt = 0,exp = 0,lv = 0,rank = {}}
  136. localData[unionUuid].rank = {}
  137. if localData[unionUuid].box and localData[unionUuid].box.endTime and localData[unionUuid].box.endTime < now then
  138. localData[unionUuid].isWin = nil
  139. localData[unionUuid].isMatch = nil
  140. end
  141. for k,v in pairs(data.member) do
  142. local db = RoleDBLogic.getDb(k)
  143. if db then
  144. if db.lastLoginTime and db.lastLoginTime >= donateTime then
  145. huoyueCnt = huoyueCnt + 1
  146. end
  147. local objList, helpList, rolebase,formation, jiban = CombatLogic.getHumanObjList({db = db},CombatDefine.COMBAT_TYPE3)
  148. if rolebase.zhandouli > 0 then
  149. len = len + 1
  150. local battleMonsterOutID = BattleLogic.getCombatMonsterOutID({db = db}, CombatDefine.DEFEND_SIDE)
  151. if not battleMonsterOutID then
  152. battleMonsterOutID = 10001
  153. end
  154. unionData.member[k] = {objList = objList,helpList = helpList,formation = formation, jiban = jiban , rolebase = rolebase,name = db.name ,attackStar = 0,defendStar = 3,defendCnt = 0,attackCnt = 0, jifen = 0,log = {},battleMonsterOutID = battleMonsterOutID} --
  155. sortList[len] = {k,rolebase.zhandouli}
  156. localData[unionUuid].member[k] = localData[unionUuid].member[k] or {name = db.name,cnt = 0,shop = {{},{}},chengjiu = {{},{}}}
  157. localData[unionUuid].member[k].join = 1
  158. localData[unionUuid].member[k].post = v.post
  159. localData[unionUuid].member[k].rolebase = rolebase
  160. localData[unionUuid].member[k].boxTime = boxEndTime
  161. end
  162. end
  163. end
  164. if len == 0 or huoyueCnt < UNION_HUOYUE then
  165. return
  166. end
  167. for k, v in pairs(localData[unionUuid].member) do
  168. if not data.member[k] then
  169. localData[unionUuid].member[k] = nil
  170. end
  171. end
  172. table.sort(sortList,function(a,b)
  173. return a[2] > b[2]
  174. end)
  175. for k,v in ipairs(sortList) do
  176. unionData.member[v[1]].index = k
  177. localData[unionUuid].rank[k] = {v[1],0,0}
  178. end
  179. unionData.memberCnt = len
  180. unionData.unionUuid = data._id
  181. unionData.name = data.name
  182. unionData.bannerID = data.bannerID
  183. unionData.lv = data.lv
  184. unionData.zhandouli = data.zhandouli
  185. unionData.svrName = Config.SVR_NAME
  186. unionData.svrIndex = Config.SVR_INDEX
  187. unionData.rank = BillboardDB.getRank(BillboardDefine.TYPE_UNION,data._id) or 0
  188. localData[unionUuid].memberCnt = len
  189. localData[unionUuid].star = 0
  190. return unionData
  191. end
  192. --重置公会战数据(资格确认)
  193. fileds = {unionUuid = 1,name = 1,bannerID = 1,lv = 1,zhandouli = 1,member = 1}
  194. local ToMidUnionList = nil
  195. function refreshData()
  196. print(" refreshData refreshData refreshData")
  197. ToMidUnionList = {}
  198. LuaMongo.find(DB.db_union,nil,fileds)
  199. local msgRet = InnerMsg.lw.LW_UNION_WAR_ADD
  200. msgRet.list = {}
  201. local len = 0
  202. local unionList = {}
  203. local unionUuid
  204. while true do
  205. local data = {}
  206. if not LuaMongo.next(data) then
  207. break
  208. end
  209. unionList[#unionList + 1] = data
  210. end
  211. for k,data in ipairs(unionList) do
  212. local unionData = getData(data)
  213. if unionData then
  214. unionUuid = unionData.unionUuid
  215. local toLen = #ToMidUnionList + 1
  216. ToMidUnionList[toLen] = {}
  217. ToMidUnionList[toLen].member = {}
  218. ToMidUnionList[toLen].unionUuid = unionUuid
  219. ToMidUnionList[toLen].member = Util.copyTable(unionData.member)
  220. unionData.member = {}
  221. len = len + 1
  222. msgRet.list[len] = unionData
  223. end
  224. if len >= 5 then
  225. InnerMsg.sendMsg(0, msgRet)
  226. Util.cleanTable(msgRet.list)
  227. len = 0
  228. end
  229. end
  230. if len >= 1 then
  231. InnerMsg.sendMsg(0, msgRet)
  232. end
  233. UnionWarDBLogic.updateDB()
  234. print(" Timer.addLater(1, sendUnionToMid) Timer.addLater(1, sendUnionToMid)")
  235. Timer.addLater(1, sendUnionToMid)
  236. end
  237. local function getSurCnt(member)
  238. local len = 0
  239. if not member then return len end
  240. for _ in pairs(member) do
  241. len = len + 1
  242. end
  243. return len
  244. end
  245. function sendUnionToMid()
  246. print(" sendUnionToMid , sendUnionToMid , sendUnionToMid")
  247. if ToMidUnionList and #ToMidUnionList > 0 then
  248. print(" sendUnionToMid sendUnionToMid sendUnionToMid", #ToMidUnionList)
  249. local data = ToMidUnionList[#ToMidUnionList]
  250. if data and data.unionUuid then
  251. local msgRet = InnerMsg.lw.LW_UNION_WAR_MEMBER
  252. msgRet.unionUuid = data.unionUuid
  253. msgRet.list = {}
  254. Util.cleanTable(msgRet.list)
  255. local len = 0
  256. local sendUuid = {}
  257. if #ToMidUnionList == 1 and getSurCnt(data.member) <= 10 then
  258. data.isEnd = 1
  259. end
  260. local isSend = false
  261. msgRet.isEnd = data.isEnd or 0
  262. for k,v in pairs(data.member) do
  263. len = len + 1
  264. msgRet.list[len] = {k,v}
  265. sendUuid[k] = 1
  266. if len >= 10 then
  267. -- Util.printTable(msgRet)
  268. InnerMsg.sendMsg(0, msgRet)
  269. Util.cleanTable(msgRet.list)
  270. isSend = true
  271. break
  272. end
  273. end
  274. if not isSend then
  275. -- Util.printTable(msgRet)
  276. InnerMsg.sendMsg(0, msgRet)
  277. Util.cleanTable(msgRet.list)
  278. end
  279. local surLen = 0
  280. for uuid in pairs(data.member) do
  281. if sendUuid[uuid] then
  282. data.member[uuid] = nil
  283. else
  284. surLen = surLen + 1
  285. end
  286. end
  287. print(" surLen surLen ", surLen)
  288. if surLen == 0 then
  289. ToMidUnionList[#ToMidUnionList] = nil
  290. print(" del ToMidUnionList !", #ToMidUnionList)
  291. end
  292. if #ToMidUnionList > 0 then
  293. Timer.addLater(1, sendUnionToMid)
  294. else
  295. ToMidUnionList = nil
  296. end
  297. end
  298. end
  299. end
  300. -- 匹配完成 各个单服 将匹配上的 公会标记 用于红点
  301. function middleUnionMatchFinish(msg)
  302. local localData = UnionWarDBLogic.getLocalData()
  303. for unionUuid in pairs(msg.list) do
  304. if localData[unionUuid] then
  305. localData[unionUuid].isMatch = true
  306. localData[unionUuid].matchTime = os.time()
  307. end
  308. end
  309. end
  310. function getState()
  311. local now = os.time()
  312. local d = os.date("*t",now)
  313. local wday = d.wday
  314. local h = d.hour
  315. -- 周一 周三 周五 公会战
  316. if WDAY[wday - 1] then
  317. if h >= HOUR1[1] and h < HOUR1[2] then
  318. return STATE1
  319. elseif h >= HOUR2[1] and h < HOUR2[2] then
  320. return STATE2
  321. elseif h >= HOUR3[1] and h < HOUR3[2] then
  322. return STATE3
  323. elseif h >= HOUR4[1] and h < HOUR4[2] then
  324. return STATE4
  325. end
  326. end
  327. return STATE0
  328. end
  329. function getEndTime(actState)
  330. local now = os.time()
  331. local d = os.date("*t",now)
  332. if actState == STATE0 then
  333. local wday = d.wday
  334. if wday < 6 then
  335. d.hour = HOUR2[2]
  336. local checkTime = os.time(d)
  337. return checkTime + 24 * 60 * 60 - now
  338. elseif wday == 6 then
  339. if actState < STATE3 then
  340. d.hour = HOUR2[2]
  341. else
  342. d.hour = HOUR3[2]
  343. end
  344. d.min = 0
  345. d.sec = 0
  346. local checkTime = os.time(d)
  347. return checkTime - now
  348. else
  349. local Monday = Util.getWeekStartTime()
  350. return Monday + 24 * 60 * 60 * 7 + HOUR2[2] * 3600 - now
  351. end
  352. else
  353. if actState < STATE3 then
  354. d.hour = HOUR2[2]
  355. else
  356. d.hour = HOUR3[2]
  357. end
  358. d.min = 0
  359. d.sec = 0
  360. local checkTime = os.time(d)
  361. return checkTime - now
  362. end
  363. end
  364. function getWarTime(human)
  365. local msgRet = Msg.gc.GC_UNION_WAR_TIME
  366. if MiddleConnect.IS_MIDDLE_CONNECT then
  367. local actState = getState()
  368. msgRet.actState = actState
  369. msgRet.time = getEndTime(actState)
  370. Msg.send(msgRet,human.fd)
  371. else
  372. msgRet.actState = 0
  373. msgRet.time = 0
  374. Msg.send(msgRet,human.fd)
  375. end
  376. end
  377. local function getChengjiuExcel(type)
  378. if type == 1 then
  379. return UnionWarExcel.chengjiu1
  380. else
  381. return UnionWarExcel.chengjiu2
  382. end
  383. end
  384. local function isDotChengjiu(human,localData,unionWarData,memberData,type)
  385. local ChengjiuExcel = getChengjiuExcel(type)
  386. if not memberData then
  387. --未参与公会战
  388. return
  389. end
  390. local getList,cnt
  391. local humanData = getUnionWarData(human,memberData)
  392. if type == 1 then
  393. cnt = humanData.cnt
  394. getList = humanData.chengjiu[1]
  395. else
  396. cnt = unionWarData.cnt
  397. getList = humanData.chengjiu[2]
  398. end
  399. for k, v in ipairs(ChengjiuExcel) do
  400. if not getList[k] and v.cnt <= cnt then
  401. return true
  402. end
  403. end
  404. end
  405. local function sendState(human,actState,unionState)
  406. local msgRet = Msg.gc.GC_UNION_WAR_STATE
  407. msgRet.actState = actState
  408. msgRet.unionState = unionState
  409. msgRet.winState = 0
  410. msgRet.cjDot = 0
  411. msgRet.zgDot = 0
  412. msgRet.shopDot = 0
  413. msgRet.fightDot = 0
  414. msgRet.pipeiDot = 0
  415. local localData = UnionWarDBLogic.getLocalData()
  416. local unionWarData = getLocalUnionWarData(localData,human.db.unionUuid)
  417. local memberData = getLocalMemberData(unionWarData,human.db._id)
  418. if unionWarData and memberData and isDotChengjiu(human,localData,unionWarData,memberData,1) or isDotChengjiu(human,localData,unionWarData,memberData,2) then
  419. msgRet.cjDot = 1
  420. end
  421. if unionWarData and isDotByBox(human, unionWarData) then
  422. msgRet.zgDot = 1
  423. end
  424. if unionWarData and isDotByShop(human, unionWarData) then
  425. msgRet.shopDot = 1
  426. end
  427. if unionWarData and isDotByCnt(human, unionWarData) then
  428. msgRet.fightDot = 1
  429. end
  430. if unionWarData and isDotByPiPei(human, unionWarData) then
  431. msgRet.pipeiDot = 1
  432. end
  433. if actState == STATE4 and unionState == UNION_STATE1 then
  434. msgRet.winState = unionWarData.isWin and unionWarData.isWin or 0
  435. end
  436. Msg.send(msgRet,human.fd)
  437. end
  438. --请求:查询状态
  439. --返回:状态,攻守双方成员
  440. local function fontUnionWarTeam(net,data)
  441. local localData = UnionWarDBLogic.getLocalData()
  442. local unionWarData = getLocalUnionWarData(localData,data.unionUuid)
  443. local rankData = unionWarData.rank
  444. local temp = {}
  445. for i = 1,3 do
  446. if rankData[i] then
  447. temp[rankData[i][1]] = i
  448. else
  449. break
  450. end
  451. end
  452. net.unionUuid = data.unionUuid
  453. net.name = data.name
  454. net.svrName = data.svrName or ""
  455. net.bannerID = data.bannerID
  456. net.star = data.star
  457. local len = 0
  458. for k,v in pairs(data.member) do
  459. len = len + 1
  460. net.list[len].index = v.index
  461. net.list[len].uuid = v.uuid
  462. net.list[len].name = v.name
  463. net.list[len].star = v.star
  464. net.list[len].zhandouli = v.zhandouli
  465. net.list[len].rank = temp[v.uuid] or 0
  466. local pos = RobotExcel[v.index].pos
  467. net.list[len].x = pos[1]
  468. net.list[len].y = pos[2]
  469. end
  470. net.list[0] = len
  471. end
  472. local function fontSimpleRank(net,unionUuid)
  473. local localData = UnionWarDBLogic.getLocalData()
  474. local unionWarData = getLocalUnionWarData(localData,unionUuid)
  475. local memberList = unionWarData.member
  476. local len = 0
  477. local fields = {name = 1}
  478. local db
  479. for k,v in ipairs(unionWarData.rank) do
  480. len = len + 1
  481. net[len].rank = k
  482. db = RoleDBLogic.getDb(v[1], fields)
  483. net[len].name = db and db.name or memberList[v[1]].name
  484. if len >= 3 then
  485. break
  486. end
  487. end
  488. net[0] = len
  489. end
  490. function onLogin(human)
  491. end
  492. function query(human,msg, actState)
  493. local msgRet = Msg.gc.GC_UNION_WAR_QUERY
  494. local localData = UnionWarDBLogic.getLocalData()
  495. local unionWarData = getLocalUnionWarData(localData,human.db.unionUuid)
  496. fontUnionWarTeam(msgRet.attacker,msg.attacker)
  497. fontUnionWarTeam(msgRet.defender,msg.defender)
  498. fontSimpleRank(msgRet.threeRank,msg.attacker.unionUuid)
  499. local now = os.time()
  500. local d = os.date("*t",now)
  501. d.hour = HOUR3[2]
  502. --[[
  503. if actState == STATE2 then
  504. d.hour = HOUR2[2]
  505. else
  506. d.hour = HOUR3[2]
  507. end
  508. ]]
  509. d.min = 0
  510. d.sec = 0
  511. local checkTime = os.time(d)
  512. msgRet.leftTime = checkTime - now
  513. msgRet.cnt = msg.cnt
  514. msgRet.maxCnt = DefineConf.cnt
  515. -- Msg.trace(msgRet)
  516. Msg.send(msgRet,human.fd)
  517. end
  518. function CGQuery(human)
  519. end
  520. function WLQuery(human,msg)
  521. local actState = getState()
  522. sendState(human,actState,msg.state)
  523. if msg.state == UNION_STATE1 then
  524. query(human,msg, actState)
  525. end
  526. end
  527. -- 客户端 最多请求三次
  528. -- 用于给 客户端 给予 停留在公会战界面 倒计时结束 公会战结果 查询更新
  529. function CGEndQuery(human)
  530. local msgRet = Msg.gc.GC_UNION_WAR_END_STATE_QUERY
  531. local localData = UnionWarDBLogic.getLocalData()
  532. local unionWarData = getLocalUnionWarData(localData,human.db.unionUuid)
  533. msgRet.winState = unionWarData.isWin and unionWarData.isWin or 0
  534. Msg.send(msgRet,human.fd)
  535. end
  536. local function fontBufferNet(msgRet, lv)
  537. msgRet.maxBuff = #UnionWarExcel.buff
  538. local config = UnionWarExcel.buff[lv]
  539. msgRet.nowAttr[0] = 0
  540. msgRet.nextAttr[0] = 0
  541. if config then
  542. for k, v in ipairs(config.attr) do
  543. local net = msgRet.nowAttr[k]
  544. net.key = v[1]
  545. net.value = v[2]
  546. end
  547. msgRet.nowAttr[0] = #config.attr
  548. end
  549. if lv + 1 <= msgRet.maxBuff then
  550. local nextConfig = UnionWarExcel.buff[lv + 1]
  551. for k, v in ipairs(nextConfig.attr) do
  552. local net = msgRet.nextAttr[k]
  553. net.key = v[1]
  554. net.value = v[2]
  555. end
  556. msgRet.nextAttr[0] = #nextConfig.attr
  557. end
  558. end
  559. -- BUF 请求
  560. function CGBuffQuery(human)
  561. local msgRet = Msg.gc.GC_UNION_WAR_BUFF
  562. msgRet.buffLv = 0
  563. fontBufferNet(msgRet, 0)
  564. if human then
  565. Msg.send(msgRet,human.fd)
  566. end
  567. local actState = getState()
  568. if actState > STATE1 then
  569. local msgRet = InnerMsg.lw.LW_UNION_WAR_BUFF_QUERY
  570. msgRet.uuid = human.db._id
  571. msgRet.unionUuid = human.db.unionUuid
  572. InnerMsg.sendMsg(0, msgRet)
  573. end
  574. end
  575. function WLBuffQuery(human, msg)
  576. local msgRet = Msg.gc.GC_UNION_WAR_BUFF
  577. msgRet.buffLv = msg.buffLv
  578. fontBufferNet(msgRet, msg.buffLv)
  579. if human and human.fd then
  580. Msg.send(msgRet,human.fd)
  581. else
  582. local localData = UnionWarDBLogic.getLocalData()
  583. local unionWarData = getLocalUnionWarData(localData, msg.unionUuid)
  584. if not unionWarData or not unionWarData.member then return end
  585. for uuid,_ in pairs(unionWarData.member) do
  586. local human = ObjHuman.onlineUuid[uuid]
  587. if human and human.fd then
  588. Msg.send(msgRet,human.fd)
  589. end
  590. end
  591. end
  592. end
  593. --请求:公会成员信息
  594. --返回:公会成员信息
  595. function CGInfo(human,unionUuid,targetUuid)
  596. local msgRet = InnerMsg.lw.LW_UNION_WAR_INFO
  597. msgRet.uuid = human.db._id
  598. msgRet.attackUnionUuid = human.db.unionUuid
  599. msgRet.unionUuid = unionUuid
  600. msgRet.targetUuid = targetUuid
  601. InnerMsg.sendMsg(0, msgRet)
  602. end
  603. -- 封装 英雄
  604. local function fontHeroList(net,data)
  605. local len = 0
  606. local monsterOutID = data.monsterOutID
  607. if monsterOutID then
  608. for k,v in ipairs(MonsterOutExcel[monsterOutID].member) do
  609. if v[1] > 0 then
  610. len = len + 1
  611. HeroGrid.makeHeroSimpleByMonsterID(net[len],v[1],{lv = v[2]})
  612. end
  613. end
  614. else
  615. for i = 1,CombatDefine.COMBAT_HERO_CNT do
  616. local obj = data.objList[i]
  617. if obj then
  618. len = len + 1
  619. HeroGrid.makeHeroSimpleByID(net[len],obj.id, obj.bagIndex,{lv = obj.lv,star = obj.star})
  620. end
  621. end
  622. end
  623. net[0] = len
  624. end
  625. function getDiff(robotConf,diff,monsterOutID, isFeixu)
  626. if isFeixu then
  627. diff = 3
  628. return robotConf.rate[diff],0,robotConf.jifen2
  629. else
  630. return robotConf.rate[diff],robotConf.star[diff],robotConf.jifen1[diff]
  631. end
  632. end
  633. -- 玩家信息
  634. function WLInfo(human,msg)
  635. local msgRet = Msg.gc.GC_UNION_WAR_INFO
  636. local target = msg.target
  637. msgRet.cnt = msg.cnt
  638. msgRet.maxCnt = DefineConf.cnt
  639. msgRet.unionUuid = msg.unionUuid
  640. msgRet.uuid = target.uuid
  641. msgRet.index = msg.index
  642. msgRet.star = target.defendStar
  643. msgRet.zhandouli = target.zhandouli
  644. msgRet.defendCnt = target.defendCnt
  645. msgRet.canFight = msg.canFight
  646. msgRet.feixuCnt = target.loseBuff
  647. local len = 0
  648. local monsterOutID = target.monsterOutID
  649. if monsterOutID then
  650. msgRet.isRobot = 1
  651. else
  652. msgRet.isRobot = 0
  653. end
  654. local robotConf = RobotExcel[target.index]
  655. local diffList = robotConf.diff
  656. local isFeixu = target.defendStar <= 0
  657. if isFeixu then
  658. diffList = {3}
  659. end
  660. for k,v in ipairs(diffList) do
  661. len = len + 1
  662. local net = msgRet.diffList[len]
  663. net.diff = v
  664. net.rate,net.star,net.jifen = getDiff(robotConf,k,monsterOutID)
  665. local len1 = 0
  666. for k1,v1 in ipairs(robotConf.item[v]) do
  667. len1 = len1 + 1
  668. Grid.makeItem(net.item[len1], v1[1], v1[2])
  669. end
  670. net.item[0] = len1
  671. end
  672. msgRet.diffList[0] = len
  673. -- Util.printTable(target)
  674. fontHeroList(msgRet.list,target)
  675. Msg.send(msgRet,human.fd)
  676. end
  677. --请求:匹配列表
  678. --返回:匹配列表
  679. function CGMatch(human)
  680. local msgRet = InnerMsg.lw.LW_UNION_WAR_MATCH
  681. msgRet.uuid = human.db._id
  682. msgRet.unionUuid = human.db.unionUuid
  683. InnerMsg.sendMsg(0, msgRet)
  684. end
  685. function WLMatch(human,msg)
  686. local msgRet = Msg.gc.GC_UNION_WAR_MATCH
  687. local len = 0
  688. for k,v in ipairs(msg.list) do
  689. len = len + 1
  690. local net = msgRet.list[len]
  691. net.nameLeft = v[1][1]
  692. net.rankLeft = v[1][3] or 0
  693. net.nameRight = v[2][1]
  694. net.rankRight = v[2][3] or 0
  695. net.svrNameLeft = v[3][3]
  696. net.svrNameRight = v[3][4]
  697. if len >= 60 then
  698. break
  699. end
  700. end
  701. msgRet.list[0] = len
  702. Msg.send(msgRet,human.fd)
  703. if human.db.unionUuid then
  704. local localData = UnionWarDBLogic.getLocalData()
  705. local unionWarData = getLocalUnionWarData(localData,human.db.unionUuid)
  706. if unionWarData then
  707. local memberData = getLocalMemberData(unionWarData,human.db._id)
  708. local humanData = getUnionWarData(human,memberData)
  709. local actState = getState()
  710. if actState >= STATE2 and not Util.isSameDay(humanData.pipeiLook) then
  711. humanData.pipeiLook = os.time()
  712. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1006)
  713. end
  714. end
  715. end
  716. end
  717. --请求:日志
  718. --返回:日志
  719. function CGAtkLog(human, type)
  720. local msgRet = InnerMsg.lw.LW_UNION_WAR_ATKLOG
  721. msgRet.uuid = human.db._id
  722. msgRet.type = type
  723. msgRet.unionUuid = human.db.unionUuid
  724. InnerMsg.sendMsg(0, msgRet)
  725. end
  726. function WLAtkLog(human, msg)
  727. local msgRet = Msg.gc.GC_UNION_WAR_ATKLOG
  728. msgRet.type = msg.type
  729. local len = 0
  730. for k,v in ipairs(msg.list) do
  731. len = len + 1
  732. local net = msgRet.list[len]
  733. net.upTime = v[1]
  734. net.ret = v[2] and 1 or 0
  735. net.name = v[3]
  736. net.defName = v[4]
  737. net.star = v[5]
  738. net.jifen = v[6]
  739. net.unionUuid = v[7]
  740. net.atkUnionStar = v[8] or 0
  741. net.buffLv = v[9] and v[9] or 0
  742. end
  743. msgRet.list[0] = len
  744. -- Msg.trace(msgRet)
  745. Msg.send(msgRet,human.fd)
  746. end
  747. --请求 防守日志
  748. --返回 防守日志
  749. function CGDefLog(human,uuid, unionUuid)
  750. local msgRet = InnerMsg.lw.LW_UNION_WAR_DEFLOG
  751. msgRet.uuid = human.db._id
  752. msgRet.unionUuid = human.db.unionUuid
  753. msgRet.defendUuid = uuid
  754. msgRet.defendUnion = unionUuid
  755. InnerMsg.sendMsg(0, msgRet)
  756. end
  757. function WLDefLog(human,msg)
  758. local msgRet = Msg.gc.GC_UNION_WAR_DEFLOG
  759. msgRet.zhandouli = msg.defender.zhandouli
  760. fontHeroList(msgRet.heroList,msg.defender)
  761. local len = 0
  762. for k,v in ipairs(msg.list) do
  763. len = len + 1
  764. local net = msgRet.logList[len]
  765. net.id = 0
  766. net.name = v.name
  767. net.zhandouli = v.zhandouli
  768. net.diff = v.diff
  769. net.result = v.result
  770. net.time = v.upTime
  771. local formationConfig = CombatPosLogic.getFormationConfig(v.formation)
  772. net.formation = formationConfig.name
  773. net.videoIndex = v.videoIndex
  774. fontHeroList(net.list,v.target)
  775. end
  776. msgRet.logList[0] = len
  777. --Msg.trace(msgRet)
  778. Msg.send(msgRet,human.fd)
  779. end
  780. function CGVideo(human, videoIndex)
  781. local msgRet = InnerMsg.lw.LW_UNION_WAR_VIDEO
  782. msgRet.uuid = human.db._id
  783. msgRet.unionUuid = human.db.unionUuid
  784. msgRet.index = videoIndex
  785. InnerMsg.sendMsg(0, msgRet)
  786. end
  787. function WLVideo(human,msg)
  788. CombatLogic.repeatCombat(human, msg.combatInfo)
  789. end
  790. --请求:挑战
  791. --返回:挑战失败原因或者战斗帧
  792. function fight(human,args)
  793. local actState = getState()
  794. if actState ~= STATE3 then
  795. return Broadcast.sendErr(human, Lang.UNION_WAR_FIGHT_ERR_END)
  796. end
  797. local msgRet = InnerMsg.lw.LW_UNION_WAR_FIGHT
  798. msgRet.unionUuid = human.db.unionUuid
  799. msgRet.attackUuid = human.db._id
  800. msgRet.defendUuid = args[1]
  801. msgRet.diff = args[2]
  802. InnerMsg.sendMsg(0, msgRet)
  803. print("================fight", msgRet.diff)
  804. end
  805. function sendfightErr(human, msg)
  806. if msg.state == UnionWarMiddleLogic.FIGHT2 then
  807. Broadcast.sendErr(human, Lang.UNION_WAR_FIGHT_ERR_TILI)
  808. elseif msg.state == UnionWarMiddleLogic.FIGHT3 then
  809. Broadcast.sendErr(human, Lang.UNION_WAR_FIGHT_ERR_ING)
  810. elseif msg.state == UnionWarMiddleLogic.FIGHT4 then
  811. Broadcast.sendErr(human, Lang.UNION_WAR_FIGHT_ERR_BEING)
  812. elseif msg.state == UnionWarMiddleLogic.FIGHT5 then
  813. Broadcast.sendErr(human, Lang.UNION_WAR_FIGHT_ERR_STAR)
  814. elseif msg.state == UnionWarMiddleLogic.FIGHT6 then
  815. Broadcast.sendErr(human, Lang.UNION_WAR_FIGHT_ERR_ZIGE)
  816. end
  817. end
  818. function WLFight(human,msg)
  819. print("================wlfight",msg.state,UnionWarMiddleLogic.FIGHT1)
  820. if msg.state ~= UnionWarMiddleLogic.FIGHT1 then
  821. sendfightErr(human, msg)
  822. return
  823. end
  824. human.unionWar = {}
  825. human.unionWar.target = Util.copyTable(msg.defender)
  826. human.unionWar.diff = msg.diff
  827. human.unionWar.name = msg.name
  828. CombatLogic.combatBegin(human,1001, {}, CombatDefine.COMBAT_TYPE12)
  829. end
  830. function getCombatObjList(human, side)
  831. if side == CombatDefine.ATTACK_SIDE then
  832. return CombatLogic.getHumanObjList(human,CombatDefine.COMBAT_TYPE1)
  833. else
  834. local target = human.unionWar.target
  835. local diff = human.unionWar.diff
  836. local rate = RobotExcel[target.index].rate[diff]
  837. for k,v in pairs(target.objList) do
  838. v.attrs[RoleDefine.ATK] = v.attrs[RoleDefine.ATK] * rate/10000
  839. v.attrs[RoleDefine.DEF] = v.attrs[RoleDefine.DEF] * rate/10000
  840. v.attrs[RoleDefine.HP] = v.attrs[RoleDefine.HP] * rate/10000
  841. end
  842. return target.objList, target.helpList, target.rolebase,target.formation, target.jiban
  843. end
  844. end
  845. --挑战结束回调
  846. function onFightEnd(human,ret, combatType, cbParam, combatInfo)
  847. local msgRet = InnerMsg.lw.LW_UNION_WAR_FIGHT_END
  848. msgRet.upTime = os.time()
  849. msgRet.uuid = human.db._id
  850. msgRet.unionUuid = human.db.unionUuid
  851. msgRet.combatInfo = combatInfo
  852. InnerMsg.sendMsg(0, msgRet)
  853. combatInfo.endStatus = CombatLogic.COMBAT_END_STATUS1
  854. human.unionWar = human.unionWar or {}
  855. human.unionWar.combatInfo = combatInfo
  856. end
  857. function WLFightEnd(human,msg)
  858. local msgRet = Msg.gc.GC_UNION_WAR_FIGHT_END
  859. msgRet.diff = msg.diff
  860. msgRet.unionStar = msg.unionStar
  861. msgRet.defendStar = msg.defender.defendStar
  862. msgRet.defendUuid = msg.defender.uuid or ""
  863. msgRet.defIndex = msg.defender.index
  864. msgRet.cnt = msg.cnt
  865. local combatInfo = msg.combatInfo
  866. local target = msg.defender
  867. local diff = msg.diff
  868. local isFeixu = msg.isFeixu == 1 and true or false
  869. local robotConf = RobotExcel[target.index]
  870. local rate,star,jifen = getDiff(robotConf, diff,target.monsterOutID, isFeixu)
  871. combatInfo.endParam = rate.."|"..star.."|"..msg.defUnionName
  872. combatInfo.rewardItem = robotConf.item[diff]
  873. local localData = UnionWarDBLogic.getLocalData()
  874. local unionWarData = localData[human.db.unionUuid]
  875. local rankData = unionWarData.rank
  876. local addStar = msg.addStar
  877. local memberData = unionWarData.member[human.db._id]
  878. if combatInfo.isWin then
  879. if memberData then
  880. memberData.cnt = memberData.cnt + 1
  881. local chengjiuData = getUnionWarData(human,memberData)
  882. chengjiuData.cnt = chengjiuData.cnt + 1
  883. end
  884. else
  885. combatInfo.rewardItem = robotConf.item2[diff]
  886. jifen = 1
  887. addStar = 0
  888. end
  889. if memberData then
  890. local humanData = getUnionWarData(human,memberData)
  891. humanData.fightCnt = humanData.fightCnt or 0
  892. humanData.fightCnt = msg.cnt
  893. humanData.fightTime = os.time()
  894. end
  895. -- 玩家增加 公会战积分 星级
  896. for k,v in ipairs(rankData) do
  897. if v[1] == human.db._id then
  898. v[2] = v[2] + jifen
  899. v[3] = v[3] + addStar
  900. break
  901. end
  902. end
  903. table.sort(rankData,function(a,b)
  904. return a[2] > b[2]
  905. end)
  906. UnionWarDBLogic.updateDB()
  907. fontSimpleRank(msgRet.threeRank, human.db.unionUuid)
  908. Msg.send(msgRet,human.fd)
  909. for k,v in ipairs(combatInfo.rewardItem) do
  910. BagLogic.addItem(human, v[1], v[2], "unionWar")
  911. end
  912. CombatLogic.sendCombatFinish(human,combatInfo)
  913. human.unionWar = nil
  914. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1006)
  915. end
  916. -- 通知参与公会战的在线玩家场景更新 星级 同步
  917. function WLFightTongzhi(msg)
  918. local msgRet = Msg.gc.GC_UNION_WAR_SCENE_INFO
  919. msgRet.unionUuid = msg.atkUnion
  920. msgRet.unionStar = msg.atkUnionStar
  921. msgRet.defendUuid = msg.defUuid
  922. msgRet.defendStar = msg.defStar
  923. msgRet.defIndex = msg.defIndex
  924. msgRet.targetUnion = msg.defUnion
  925. local ToUuid = msg.unionUuid
  926. fontSimpleRank(msgRet.threeRank, ToUuid)
  927. local localData = UnionWarDBLogic.getLocalData()
  928. local unionWarData = getLocalUnionWarData(localData, ToUuid)
  929. for uuid,_ in pairs(unionWarData.member) do
  930. if uuid ~= msg.atkUuid then
  931. local human = ObjHuman.onlineUuid[uuid]
  932. if human then
  933. Msg.send(msgRet,human.fd)
  934. end
  935. end
  936. end
  937. end
  938. --请求:开箱子
  939. --返回:开箱子
  940. function CGBox(human)
  941. local localData = UnionWarDBLogic.getLocalData()
  942. local unionWarData = getLocalUnionWarData(localData,human.db.unionUuid)
  943. local boxData = unionWarData.box
  944. local msgRet = Msg.gc.GC_UNION_WAR_BOX
  945. msgRet.leftTime = 0
  946. msgRet.isWin = 1
  947. local len = 0
  948. local now = os.time()
  949. if boxData and now < boxData.endTime then
  950. msgRet.leftTime = boxData.endTime - now
  951. msgRet.isWin = unionWarData.isWin
  952. for k,v in ipairs(boxData.list) do
  953. len = len + 1
  954. local net = msgRet.list[len]
  955. if v[3] then
  956. net.isOpen = 1
  957. net.name = unionWarData.member[v[3]].name
  958. Grid.makeItem(net.item[1],v[1],v[2])
  959. net.item[0] = 1
  960. if net.name == "" then
  961. local fake = {}
  962. RoleLogic.getRoleBaseByUuid(v[3], fake)
  963. net.name = fake and fake.name or ""
  964. end
  965. else
  966. net.isOpen = 2
  967. net.name = ""
  968. net.item[0] = 0
  969. end
  970. end
  971. end
  972. msgRet.list[0] = len
  973. -- Msg.trace(msgRet)
  974. Msg.send(msgRet,human.fd)
  975. end
  976. -- 战果宝箱领取
  977. function CGBoxGet(human,ind)
  978. local localData = UnionWarDBLogic.getLocalData()
  979. local unionWarData = getLocalUnionWarData(localData,human.db.unionUuid)
  980. local boxData = unionWarData.box
  981. if not boxData then
  982. return
  983. end
  984. if not unionWarData.member[human.db._id] then
  985. return
  986. end
  987. local now = os.time()
  988. if now > boxData.endTime then
  989. Broadcast.sendErr(human, Lang.UNION_WAR_BOX_TIME_ERR)
  990. return
  991. end
  992. if not unionWarData.member[human.db._id].boxTime then
  993. Broadcast.sendErr(human, Lang.UNION_WAR_BOX_TIME_ERR_2)
  994. return
  995. end
  996. if unionWarData.member[human.db._id].boxTime < boxData.endTime then
  997. Broadcast.sendErr(human, Lang.UNION_WAR_BOX_TIME_ERR_2)
  998. return
  999. end
  1000. if not boxData.list[ind] then
  1001. return
  1002. end
  1003. if boxData.list[ind][3] then
  1004. Broadcast.sendErr(human, Lang.UNION_WAR_BOX_NOT_ERR)
  1005. return
  1006. end
  1007. for k,v in ipairs(boxData.list) do
  1008. if v[3] == human.db._id then
  1009. Broadcast.sendErr(human, Lang.UNION_WAR_BOX_GET_ERR)
  1010. return
  1011. end
  1012. end
  1013. boxData.list[ind][3] = human.db._id
  1014. local itemID = boxData.list[ind][1]
  1015. local itemCnt = boxData.list[ind][2]
  1016. BagLogic.cleanMomentItemList()
  1017. BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, itemID, itemCnt)
  1018. BagLogic.addMomentItemList(human, "unionWar")
  1019. local msgRet = Msg.gc.GC_UNION_WAR_BOX_GET
  1020. msgRet.ind = ind
  1021. local net = msgRet.box
  1022. net.isOpen = 1
  1023. net.name = unionWarData.member[human.db._id].name
  1024. Grid.makeItem(net.item[1],itemID, itemCnt)
  1025. net.item[0] = 1
  1026. Msg.send(msgRet,human.fd)
  1027. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1006)
  1028. updateRed(human)
  1029. end
  1030. -- 公会战结束
  1031. function actFinish(msg)
  1032. local localData = UnionWarDBLogic.getLocalData()
  1033. local now = os.time()
  1034. local d = os.date("*t",now)
  1035. d.hour = HOUR4[1]
  1036. d.min = 0
  1037. d.sec = 0
  1038. local endTime = os.time(d) + 24 * 3600
  1039. local boxItem
  1040. local perExp = DefineConf.perExp
  1041. local randMax
  1042. for k,v in ipairs(msg.list) do
  1043. if v[4] == Config.SVR_INDEX then
  1044. local unionWarData = localData[v[1]]
  1045. if unionWarData then
  1046. if v[3] == 1 then
  1047. boxItem = DefineConf.boxItem
  1048. else
  1049. boxItem = DefineConf.boxItem2
  1050. end
  1051. randMax = #boxItem
  1052. unionWarData.isWin = v[3]
  1053. unionWarData.star = v[2]
  1054. Util.initTable(unionWarData.box)
  1055. unionWarData.box = {endTime = endTime,list = {}}
  1056. for i = 1,unionWarData.memberCnt do
  1057. local r = math.random(1,randMax)
  1058. unionWarData.box.list[i] = {boxItem[r][1],boxItem[r][2]}
  1059. end
  1060. if v[3] == 1 then
  1061. unionWarData.exp = unionWarData.exp + unionWarData.memberCnt * perExp
  1062. unionWarData.cnt = unionWarData.cnt + 1
  1063. unionWarData.lv = LvExcel[#LvExcel].lv
  1064. for k,v in ipairs(LvExcel) do
  1065. if unionWarData.exp < v.exp then
  1066. unionWarData.lv = v.lv - 1
  1067. break
  1068. end
  1069. end
  1070. end
  1071. end
  1072. end
  1073. end
  1074. UnionWarDBLogic.updateDB()
  1075. local localData = UnionWarDBLogic.getLocalData()
  1076. local title = MailExcel[MailDefine.MAIL_ID_UNION_WAR].title
  1077. local content = MailExcel[MailDefine.MAIL_ID_UNION_WAR].content
  1078. local senderName = MailExcel[MailDefine.MAIL_ID_UNION_WAR].senderName
  1079. for unionUuid,unionWarData in pairs(localData) do
  1080. for k,v in ipairs(unionWarData.rank) do
  1081. if v[2] == 0 then
  1082. break
  1083. end
  1084. local rankID = getUnionWarRankRewardID(k)
  1085. local conf = RankExcel[rankID]
  1086. if not conf then
  1087. break
  1088. end
  1089. MailManager.add(MailManager.SYSTEM, v[1], title, Util.format(content, k, v[2]) , conf.item, senderName)
  1090. end
  1091. end
  1092. end
  1093. --0 不可领取 1 可以领取 2 已经领取
  1094. CHENGJIU_STATE0 = 0
  1095. CHENGJIU_STATE1 = 1
  1096. CHENGJIU_STATE2 = 2
  1097. function CGChengjiu(human,type)
  1098. local ChengjiuExcel = getChengjiuExcel(type)
  1099. local localData = UnionWarDBLogic.getLocalData()
  1100. local unionWarData = getLocalUnionWarData(localData,human.db.unionUuid)
  1101. local memberData = getLocalMemberData(unionWarData,human.db._id)
  1102. local humanData = getUnionWarData(human,memberData)
  1103. local getList,cnt
  1104. if type == 1 then
  1105. cnt = humanData.cnt
  1106. getList = humanData.chengjiu[1]
  1107. else
  1108. cnt = unionWarData.cnt
  1109. getList = humanData.chengjiu[2]
  1110. end
  1111. local msgRet = Msg.gc.GC_UNION_WAR_CHENGJIU
  1112. msgRet.type = type
  1113. local len = 0
  1114. for k, v in ipairs(ChengjiuExcel) do
  1115. len = len + 1
  1116. local net = msgRet.list[len]
  1117. net.id = k
  1118. net.title = v.title or ""
  1119. net.maxCnt = v.cnt
  1120. net.cnt = cnt
  1121. if getList[k] then
  1122. net.state = CHENGJIU_STATE2
  1123. elseif v.cnt <= cnt then
  1124. net.state = CHENGJIU_STATE1
  1125. else
  1126. net.state = CHENGJIU_STATE0
  1127. end
  1128. local len1 = 0
  1129. for k1,v1 in ipairs(v.item) do
  1130. len1 = len1 + 1
  1131. Grid.makeItem(net.item[len1],v1[1],v1[2])
  1132. end
  1133. net.item[0] = len1
  1134. end
  1135. msgRet.list[0] = len
  1136. Msg.send(msgRet,human.fd)
  1137. end
  1138. function chegnjiuFinishGm(human, type)
  1139. local ChengjiuExcel = getChengjiuExcel(type)
  1140. local localData = UnionWarDBLogic.getLocalData()
  1141. local unionWarData = localData[human.db.unionUuid]
  1142. local memberData = getLocalMemberData(unionWarData,human.db._id)
  1143. if not memberData then
  1144. --未参与公会战
  1145. return
  1146. end
  1147. local humanData = getUnionWarData(human,memberData)
  1148. if type == 1 then
  1149. humanData.cnt = humanData.cnt or 0
  1150. humanData.cnt = humanData.cnt + 10
  1151. else
  1152. unionWarData.cnt = unionWarData.cnt + 10
  1153. end
  1154. UnionWarDBLogic.updateDB()
  1155. end
  1156. function CGChengjiuGet(human,type,id)
  1157. local ChengjiuExcel = getChengjiuExcel(type)
  1158. local localData = UnionWarDBLogic.getLocalData()
  1159. local unionWarData = getLocalUnionWarData(localData,human.db.unionUuid)
  1160. local memberData = getLocalMemberData(unionWarData,human.db._id)
  1161. if not memberData then
  1162. --未参与公会战
  1163. return
  1164. end
  1165. local humanData = getUnionWarData(human,memberData)
  1166. local getList,cnt
  1167. if type == 1 then
  1168. cnt = humanData.cnt
  1169. getList = humanData.chengjiu[1]
  1170. else
  1171. cnt = unionWarData.cnt
  1172. getList = humanData.chengjiu[2]
  1173. end
  1174. if getList[id] then
  1175. --已经领取
  1176. return
  1177. end
  1178. local conf = ChengjiuExcel[id]
  1179. if cnt < conf.cnt then
  1180. --未达成成就
  1181. return
  1182. end
  1183. getList[id] = 1
  1184. -- Util.printTable(conf.item)
  1185. BagLogic.addItemList(human, conf.item, "unionWar")
  1186. local msgRet = Msg.gc.GC_UNION_WAR_CHENGJIU_GET
  1187. msgRet.type = type
  1188. msgRet.id = id
  1189. Msg.send(msgRet,human.fd)
  1190. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1006)
  1191. updateRed(human)
  1192. end
  1193. local function getShopExcel(type)
  1194. if type == 1 then
  1195. return UnionWarExcel.shop1
  1196. else
  1197. return UnionWarExcel.shop2
  1198. end
  1199. end
  1200. function upWarShopLv(human, lv)
  1201. local localData = UnionWarDBLogic.getLocalData()
  1202. local unionWarData = getLocalUnionWarData(localData,human.db.unionUuid)
  1203. if not unionWarData then return end
  1204. unionWarData.lv = lv
  1205. end
  1206. function CGShop(human,type)
  1207. local ShopExcel = getShopExcel(type)
  1208. local localData = UnionWarDBLogic.getLocalData()
  1209. local unionWarData = getLocalUnionWarData(localData,human.db.unionUuid)
  1210. local memberData = getLocalMemberData(unionWarData,human.db._id)
  1211. local humanData = getUnionWarData(human,memberData)
  1212. local buyList
  1213. if type == 1 then
  1214. buyList = humanData.shop[1]
  1215. else
  1216. buyList = humanData.shop[2]
  1217. end
  1218. local msgRet = Msg.gc.GC_UNION_WAR_SHOP_QUERY
  1219. msgRet.type = type
  1220. local lv = unionWarData.lv
  1221. msgRet.shopLv = lv
  1222. msgRet.exp = unionWarData.exp
  1223. local nextShopConf = LvExcel[unionWarData.lv + 1]
  1224. msgRet.maxExp = nextShopConf and nextShopConf.exp or 0
  1225. local len = 0
  1226. for k,v in pairs(ShopExcel) do
  1227. if v.lv <= lv + 1 then
  1228. len = len + 1
  1229. local net = msgRet.list[len]
  1230. net.id = k
  1231. net.cnt = buyList[k] or 0
  1232. net.maxCnt = v.limit
  1233. net.needLv = v.lv
  1234. Grid.makeItem(net.item,v.item[1],v.item[2])
  1235. net.cost = v.cost
  1236. net.discount = v.discount
  1237. end
  1238. end
  1239. msgRet.list[0] = len
  1240. Msg.send(msgRet,human.fd)
  1241. end
  1242. function CGBuy(human,type,id,buyCnt)
  1243. local ShopExcel = getShopExcel(type)
  1244. local localData = UnionWarDBLogic.getLocalData()
  1245. local unionWarData = getLocalUnionWarData(localData,human.db.unionUuid)
  1246. local memberData = getLocalMemberData(unionWarData,human.db._id)
  1247. local humanData = getUnionWarData(human,memberData)
  1248. local buyList
  1249. if type == 1 then
  1250. buyList = humanData.shop[1]
  1251. else
  1252. buyList = humanData.shop[2]
  1253. end
  1254. local conf = ShopExcel[id]
  1255. if conf.lv > unionWarData.lv then
  1256. --等级不够
  1257. return
  1258. end
  1259. buyCnt = buyCnt or 1
  1260. local cnt = buyList[id] or 0
  1261. if conf.limit > 0 and cnt + buyCnt > conf.limit then
  1262. --达到限购次数
  1263. return
  1264. end
  1265. if not ObjHuman.checkRMB(human, conf.cost * buyCnt) then
  1266. return
  1267. end
  1268. cnt = cnt + buyCnt
  1269. buyList[id] = cnt
  1270. ObjHuman.decZuanshi(human, -conf.cost * buyCnt, "unionWar")
  1271. BagLogic.cleanMomentItemList()
  1272. BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, conf.item[1],conf.item[2] * buyCnt)
  1273. BagLogic.addMomentItemList(human, "unionWar")
  1274. local msgRet = Msg.gc.GC_UNION_WAR_SHOP_BUY
  1275. msgRet.type = type
  1276. msgRet.id = id
  1277. msgRet.cnt = cnt
  1278. Msg.send(msgRet,human.fd)
  1279. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1006)
  1280. updateRed(human)
  1281. end
  1282. function CGRank(human)
  1283. local localData = UnionWarDBLogic.getLocalData()
  1284. local unionWarData = getLocalUnionWarData(localData,human.db.unionUuid)
  1285. local memberList = unionWarData.member
  1286. local msgRet = Msg.gc.GC_UNION_WAR_RANK
  1287. local len = 0
  1288. for k,v in ipairs(unionWarData.rank) do
  1289. len = len + 1
  1290. local net = msgRet.list[len]
  1291. net.uuid = v[1]
  1292. net.rank = k
  1293. local member = memberList[v[1]]
  1294. RoleLogic.makeRoleBase(member.rolebase,net.roleBase)
  1295. net.job = member.post
  1296. local rankID = getUnionWarRankRewardID(k)
  1297. local len1 = 0
  1298. for k1,v1 in ipairs(RankExcel[rankID].item) do
  1299. len1 = len1 + 1
  1300. Grid.makeItem(net.items[len1],v1[1],v1[2])
  1301. end
  1302. net.items[0] = len1
  1303. net.jifen = v[2]
  1304. net.star = v[3]
  1305. end
  1306. msgRet.list[0] = len
  1307. Msg.send(msgRet,human.fd)
  1308. end
  1309. function auto(str)
  1310. print(" auto 1111")
  1311. local Gm = require("chat.Gm")
  1312. local CreateRole = require("role.CreateRole")
  1313. local memberCnt = 30
  1314. local now = os.time()
  1315. local union = UnionDBLogic.getUnionByName(str)
  1316. local teamUuidStr = ""
  1317. local teamHide = {[0] = memberCnt}
  1318. for i = 1, memberCnt do
  1319. local account = str .. string.format("%02d", i)
  1320. local db = RoleDBLogic.getDbByAccount(account, Config.NEW_SVR_INDEX)
  1321. if not db then
  1322. db = CreateRole.creatFakeDb(account, Config.NEW_SVR_INDEX)
  1323. db.lastLoginTime = os.time()
  1324. db.lastLogoutTime = os.time()
  1325. end
  1326. local human = {}
  1327. human.db = db
  1328. -- ObjHuman.exPand(human)
  1329. Gm.d3.god(human)
  1330. if not union then
  1331. union = UnionDBLogic.addUnion(human, str, 1, "")
  1332. end
  1333. if not union then return end
  1334. if not db.unionUuid then
  1335. db.unionUuid = union._id
  1336. UnionDBLogic.addUnionMember(union, human.db._id)
  1337. end
  1338. CombatPosLogic.setCombatByUnionWarGm(human, CombatDefine.COMBAT_TYPE3)
  1339. union.member[human.db._id].lastDonateTime = now
  1340. ObjHuman.save(human)
  1341. end
  1342. union.lv = UNION_LV
  1343. UnionDBLogic.updateUnionData(union)
  1344. end
  1345. local UNION_RANKREWARD_STATE = nil
  1346. function CGRankReward(human)
  1347. local msgRet = Msg.gc.GC_UNION_WAR_RANK_REWARD
  1348. if not UNION_RANKREWARD_STATE then
  1349. for k, v in ipairs(RankExcel) do
  1350. local net = msgRet.list[k]
  1351. net.id = k
  1352. net.minRank = v.minRank
  1353. net.maxRank = v.maxRank
  1354. for j, h in ipairs(v.item) do
  1355. Grid.makeItem(net.items[j], h[1], h[2])
  1356. end
  1357. net.items[0] = #v.item
  1358. end
  1359. msgRet.list[0] = #RankExcel
  1360. end
  1361. Msg.send(msgRet, human.fd)
  1362. end
  1363. function isDotByBox(human, unionWarData)
  1364. local now = os.time()
  1365. if not unionWarData then
  1366. local localData = UnionWarDBLogic.getLocalData()
  1367. unionWarData = getLocalUnionWarData(localData,human.db.unionUuid)
  1368. end
  1369. if not unionWarData then return end
  1370. local boxData = unionWarData.box
  1371. if not unionWarData.member[human.db._id] then
  1372. return
  1373. end
  1374. if not boxData or not boxData.endTime then return end
  1375. if now > boxData.endTime then
  1376. return
  1377. end
  1378. -- 检测 有没有领过
  1379. for k,v in ipairs(boxData.list) do
  1380. if v[3] == human.db._id then
  1381. return
  1382. end
  1383. end
  1384. return true
  1385. end
  1386. function isDotByShop(human, unionWarData)
  1387. local memberData = getLocalMemberData(unionWarData,human.db._id)
  1388. local humanData = getUnionWarData(human,memberData)
  1389. local buyList
  1390. for type = 1 , 2 do
  1391. if type == 1 then
  1392. buyList = humanData.shop[1]
  1393. else
  1394. buyList = humanData.shop[2]
  1395. end
  1396. local lv = unionWarData.lv
  1397. local len = 0
  1398. local ShopExcel = getShopExcel(type)
  1399. for k,v in pairs(ShopExcel) do
  1400. if v.lv <= lv and not buyList[k] then
  1401. return true
  1402. end
  1403. end
  1404. end
  1405. end
  1406. function isDotByCnt(human, unionWarData)
  1407. local actState = getState()
  1408. if actState == STATE3 and unionWarData.isMatch and Util.isSameDay(unionWarData.matchTime) then
  1409. local memberData = getLocalMemberData(unionWarData,human.db._id)
  1410. local humanData = getUnionWarData(human,memberData)
  1411. if not humanData.fightCnt then
  1412. return true
  1413. end
  1414. if Util.isSameDay(humanData.fightTime) then
  1415. if humanData.fightCnt and humanData.fightCnt < UnionWarExcel.define[1].cnt then
  1416. return true
  1417. end
  1418. else
  1419. return true
  1420. end
  1421. end
  1422. end
  1423. function isDotByPiPei(human, unionWarData)
  1424. local memberData = getLocalMemberData(unionWarData,human.db._id)
  1425. local humanData = getUnionWarData(human,memberData)
  1426. local actState = getState()
  1427. if actState >= STATE2 and actState < STATE4 and unionWarData.isMatch then
  1428. if not Util.isSameDay(humanData.pipeiLook) then
  1429. return true
  1430. end
  1431. end
  1432. end
  1433. function isDot(human)
  1434. if not human.db.unionUuid then
  1435. return
  1436. end
  1437. local localData = UnionWarDBLogic.getLocalData()
  1438. local unionWarData = getLocalUnionWarData(localData,human.db.unionUuid)
  1439. if not unionWarData then return end
  1440. -- 成就
  1441. local memberData = getLocalMemberData(unionWarData,human.db._id)
  1442. if isDotChengjiu(human,localData,unionWarData,memberData,1) or isDotChengjiu(human,localData,unionWarData,memberData,2) then
  1443. return true
  1444. end
  1445. if isDotByBox(human, unionWarData) then
  1446. return true
  1447. end
  1448. if isDotByShop(human, unionWarData) then
  1449. return true
  1450. end
  1451. if isDotByCnt(human, unionWarData) then
  1452. return true
  1453. end
  1454. if isDotByPiPei(human, unionWarData) then
  1455. return true
  1456. end
  1457. end
  1458. -- 更新界面 红点
  1459. function updateRed(human)
  1460. local msgRet = Msg.gc.GC_UNION_WAR_RED
  1461. msgRet.cjDot = 0
  1462. msgRet.zgDot = 0
  1463. msgRet.shopDot = 0
  1464. msgRet.fightDot = 0
  1465. msgRet.pipeiDot = 0
  1466. local localData = UnionWarDBLogic.getLocalData()
  1467. local unionWarData = getLocalUnionWarData(localData,human.db.unionUuid)
  1468. local memberData = getLocalMemberData(unionWarData,human.db._id)
  1469. if not memberData then
  1470. Msg.send(msgRet,human.fd)
  1471. return
  1472. end
  1473. if unionWarData and memberData and isDotChengjiu(human,localData,unionWarData,memberData,1) or isDotChengjiu(human,localData,unionWarData,memberData,2) then
  1474. msgRet.cjDot = 1
  1475. end
  1476. if unionWarData and isDotByBox(human, unionWarData) then
  1477. msgRet.zgDot = 1
  1478. end
  1479. if unionWarData and isDotByShop(human, unionWarData) then
  1480. msgRet.shopDot = 1
  1481. end
  1482. if unionWarData and isDotByCnt(human, unionWarData) then
  1483. msgRet.fightDot = 1
  1484. end
  1485. if unionWarData and isDotByPiPei(human, unionWarData) then
  1486. msgRet.pipeiDot = 1
  1487. end
  1488. Msg.send(msgRet,human.fd)
  1489. end