UnionWarLogic.lua 52 KB

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