JjcLadderLogic.lua 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350
  1. -----------------------------------------------------------------
  2. -- 天梯争霸
  3. -- 提示说明在notice配置79
  4. -- 活动开始前x秒,本服发送单人竞技场前100名数据到跨服
  5. -- 人物db
  6. -- db.jjcLadder.useCnt 已使用体力
  7. -- db.jjcLadder.buyCnt 已购买体力
  8. -- db.jjcLadder.mobais 已膜拜列表 [rank]=是否膜拜
  9. -- db.jjcLadder.beMobaiCnt 历史被膜拜次数
  10. -- common db
  11. -- db.state 当前阶段
  12. -- db.endTime 阶段结束时间戳
  13. -- db.uuid2sign [本服]报名列表 [uuid] = time
  14. -- db.sendDataList [本服]同步列表
  15. -- db.lastTopList [跨服]上一届前三 可膜拜对象 [rank] = rolebase
  16. -- db.rank2uuid [跨服]本次排名 [rank] = uuid
  17. -- db.uuid2rank [跨服]本次排名 [uuid] = rank
  18. -- db.logReds [跨服]日志红点 [uuid] = 是否有新记录
  19. -- db.uuid2logs [跨服]日志记录 [uuid] = {[index]=videoUuid}
  20. -- 活动配置jjcLadder.xlsx
  21. -- 活动时间周六0点-周日23点
  22. -- 活动开始前60秒(周五23点55分-周六0点)为准备阶段,本服同步jjc活动前100名的角色信息到跨服作为活动参赛者
  23. -----------------------------------------------------------------
  24. local Config = require("Config")
  25. local JjcLadderExcel = require("excel.jjcLadder")
  26. local JjcLadderDefine = JjcLadderExcel.define[1]
  27. local MailExcel = require("excel.mail")
  28. local Util = require("common.Util")
  29. local Lang = require("common.Lang")
  30. local CommonDB = require("common.CommonDB")
  31. local Msg = require("core.Msg")
  32. local Timer = require("core.Timer")
  33. local InnerMsg = require("core.InnerMsg")
  34. local ObjHuman = require("core.ObjHuman")
  35. local Broadcast = require("broadcast.Broadcast")
  36. local Grid = require("bag.Grid")
  37. local BagLogic = require("bag.BagLogic")
  38. local CombatLogic = require("combat.CombatLogic")
  39. local CombatDefine = require("combat.CombatDefine")
  40. local CombatPosLogic = require("combat.CombatPosLogic")
  41. local MiddleConnect = require("middle.MiddleConnect")
  42. local MiddleManager = require("middle.MiddleManager")
  43. local MailManager = require("mail.MailManager")
  44. local MailDefine = require("mail.MailIdDefine")
  45. local JjcDB = require("jjc.JjcDB")
  46. local JjcActLogic = require("jjc.JjcActLogic")
  47. local JjcLadderMiddle = require("jjcLadder.JjcLadderMiddle")
  48. local RoleDBLogic = require("role.RoleDBLogic")
  49. local RoleDefine = require("role.RoleDefine")
  50. local RoleLogic = require("role.RoleLogic")
  51. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  52. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  53. local UnionDBLogic = require("union.UnionDBLogic")
  54. local LiLianLogic = require("dailyTask.LiLianLogic")
  55. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  56. local WarReportLogic = require("warReport.WarReportLogic")
  57. local MonsterOutExcel = require("excel.monster").monsterOut
  58. local MonsterExcel = require("excel.monster").monster
  59. local HeroGrid = require("hero.HeroGrid")
  60. local HeroExcel = require("excel.hero")
  61. local ItemDefine = require("bag.ItemDefine")
  62. local RoleSystemExcel = require("excel.roleSystem")
  63. local RoleHeadLogic = require("role.RoleHeadLogic")
  64. STATE_ACT_NO_OPEN = 0 -- 未开放 可能没开跨服
  65. STATE_ACT_START = 1 -- 活动进行中
  66. STATE_ACT_READY = 2 -- 活动准备中-活动未开始
  67. STATE_ACT_SENDDATA = 3 -- 活动准备中-数据同步
  68. READY_TIME = 60 -- 准备阶段时间 秒
  69. REFRESH_TIME = 5 -- 刷新间隔 秒
  70. SENDDATA_PLAYER_CNT = 100 -- 每个服同步x人
  71. SENDDATA_PER_TIME = 10 -- 每次同步x个玩家数据
  72. MOBAI_PLAYER_CNT = 3 -- 可膜拜人数
  73. JJCLADDER_MOBAICNT = JJCLADDER_MOBAICNT or 0 -- 可膜拜人数
  74. UUID_2_COMBATINFO = UUID_2_COMBATINFO or {}
  75. local TEMP_REWARD_LIST = {{}}
  76. -- 获得活动最新状态 state, startTime, endTime
  77. local function getNewState()
  78. local nowTime = os.time()
  79. local weekStartTime = Util.getWeekStartTime(nowTime)
  80. local scf = JjcLadderDefine.startTime
  81. local startTime = weekStartTime + (scf.week - 1) * 86400 + scf.hour * 3600 + scf.min * 60
  82. local ecf = JjcLadderDefine.endTime
  83. local endTime = weekStartTime + (ecf.week - 1) * 86400 + ecf.hour * 3600 + ecf.min * 60
  84. if startTime <= nowTime and nowTime < endTime then
  85. return STATE_ACT_START, endTime
  86. end
  87. if nowTime < startTime then
  88. if startTime - nowTime <= READY_TIME then
  89. return STATE_ACT_SENDDATA, startTime
  90. else
  91. return STATE_ACT_READY, startTime - READY_TIME
  92. end
  93. end
  94. return STATE_ACT_READY, startTime + 7 * 86400 - READY_TIME
  95. end
  96. function getActTime()
  97. local weekStartTime = Util.getWeekStartTime(os.time())
  98. local scf = JjcLadderDefine.startTime
  99. local startTime = weekStartTime + (scf.week - 1) * 86400 + scf.hour * 3600 + scf.min * 60
  100. local ecf = JjcLadderDefine.endTime
  101. local endTime = weekStartTime + (ecf.week - 1) * 86400 + ecf.hour * 3600 + ecf.min * 60
  102. return startTime, endTime
  103. end
  104. -- 获取活动当前状态(显示用)
  105. function getState()
  106. if not _G.is_middle and not MiddleConnect.IS_MIDDLE_CONNECT then
  107. return STATE_ACT_NO_OPEN, 0
  108. end
  109. local commonDB = getCommonDB()
  110. if not commonDB.state then
  111. onTimer()
  112. commonDB = getCommonDB()
  113. end
  114. if commonDB.state == STATE_ACT_START then
  115. return STATE_ACT_START, commonDB.endTime - os.time()
  116. end
  117. if commonDB.state == STATE_ACT_READY then
  118. return STATE_ACT_READY, commonDB.endTime + READY_TIME - os.time()
  119. end
  120. return STATE_ACT_READY, commonDB.endTime - os.time()
  121. end
  122. -- 是否开放
  123. function isOpen(human)
  124. local state = getState()
  125. if state == STATE_ACT_NO_OPEN then -- 跨服未启动
  126. Broadcast.sendErr(human, Lang.MIDDLE_SVR_ERR_CONNECT)
  127. return
  128. end
  129. -- 判断开放等级
  130. local config = RoleSystemExcel.roleSystem[RoleSystemDefine.ROLE_SYS_ID_1401]
  131. local openDay = CommonDB.getServerOpenDay()
  132. if config and openDay and config.openSvrDay <= openDay then
  133. else
  134. return
  135. end
  136. -- if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1401, true) then
  137. -- print(" reutrn 111 ", state)
  138. -- return
  139. -- end
  140. return state
  141. end
  142. -- 检查是否有 配开启 天梯
  143. function isSysOpen()
  144. local config = RoleSystemExcel.roleSystem[RoleSystemDefine.ROLE_SYS_ID_1401]
  145. local openDay = CommonDB.getServerOpenDay()
  146. if config and openDay and config.openSvrDay < openDay then
  147. return true
  148. end
  149. return false
  150. end
  151. -- 红点
  152. function isDot(human)
  153. -- 可膜拜
  154. for rank = 1, JJCLADDER_MOBAICNT do
  155. if not isMobai(human, rank) then
  156. return true
  157. end
  158. end
  159. -- 有挑战次数
  160. local state = getState()
  161. if state == STATE_ACT_START then
  162. if getLeftCnt(human) > 0 and isSignAct(human.db._id) then
  163. return true
  164. end
  165. end
  166. end
  167. -- 随机奖励
  168. function randomReward(confs)
  169. local weightSum = 0
  170. for _, conf in pairs(confs) do
  171. weightSum = weightSum + conf.weight
  172. end
  173. if weightSum < 0 then
  174. return
  175. end
  176. local r = math.random(1, weightSum)
  177. local tconf = nil
  178. for _, conf in pairs(confs) do
  179. if r <= conf.weight then
  180. tconf = conf
  181. break
  182. end
  183. r = r - conf.weight
  184. end
  185. if not tconf then return end
  186. local itemCnt = math.random(tconf.itemCnt1, tconf.itemCnt2)
  187. return tconf.itemID, itemCnt
  188. end
  189. -- 根据名次获取排名奖励
  190. function getRewardByRank(rank)
  191. for _, conf in ipairs(JjcLadderExcel.reward) do
  192. if conf.rankMin > rank then
  193. break
  194. end
  195. if rank <= conf.rankMax then
  196. return conf
  197. end
  198. end
  199. end
  200. -- 获取玩家公会旗帜
  201. function getUnionName(unionUuid)
  202. if unionUuid and unionUuid ~= "" then
  203. local union = UnionDBLogic.getUnion(unionUuid)
  204. if union then
  205. return union.name
  206. end
  207. end
  208. return ""
  209. end
  210. -- 创建人物信息
  211. local function createHumanData(uuid)
  212. local fakeHuman = CombatLogic.createCombatFakeHuman(uuid)
  213. if not fakeHuman then return end
  214. -- 空了就取征战队伍
  215. local combatHero = CombatPosLogic.getCombatHeros(fakeHuman, CombatDefine.COMBAT_TYPE16 ) -- CombatDefine.COMBAT_TYPE16
  216. if CombatLogic.isCombatHeroEmpty(combatHero) then
  217. CombatPosLogic.copyCombatHeros(fakeHuman, CombatDefine.COMBAT_TYPE1, CombatDefine.COMBAT_TYPE16)
  218. RoleDBLogic.saveRoleSset(fakeHuman.db)
  219. end
  220. local objList, helpList, rolebase, formation, jiban = CombatLogic.getHumanObjList(fakeHuman, CombatDefine.COMBAT_TYPE16) --COMBAT_TYPE16
  221. if not objList then return end
  222. rolebase.svrName = Config.SVR_NAME
  223. rolebase.svrIndex = Config.SVR_INDEX
  224. rolebase.beMobaiCnt = getBeMobaiCnt(fakeHuman) -- 历史被点赞数
  225. rolebase.unionName = getUnionName(rolebase.unionUuid)
  226. local playerData = {}
  227. playerData._id = uuid
  228. playerData.rolebase = rolebase
  229. playerData.objList = objList
  230. playerData.helpList = helpList
  231. playerData.formation = formation
  232. playerData.jiban = jiban
  233. return playerData
  234. end
  235. -- 创建NPC信息
  236. local function createNPCData(jjcData)
  237. local objList, helpList, rolebase, formation, jiban = CombatLogic.getMonsterObjList(jjcData.monsterOutID)
  238. if not objList then return end
  239. rolebase.name = jjcData.name
  240. rolebase.lv = jjcData.lv
  241. rolebase.head = jjcData.head
  242. rolebase.headFrame = RoleDefine.DEFAULT_HEAD_FRAME
  243. rolebase.zhandouli = jjcData.zhandouli
  244. rolebase.uuid = jjcData._id
  245. rolebase.svrName = Config.SVR_NAME
  246. rolebase.svrIndex = Config.SVR_INDEX
  247. rolebase.beMobaiCnt = nil -- 历史被点赞数
  248. rolebase.unionName = ""
  249. local _, mcf = CombatLogic.getMonsterIDByOutID(jjcData.monsterOutID)
  250. rolebase.body = mcf and mcf.body or 0
  251. local playerData = {}
  252. playerData._id = jjcData._id
  253. playerData.rolebase = rolebase
  254. playerData.objList = objList
  255. playerData.helpList = helpList
  256. playerData.formation = formation
  257. playerData.jiban = jiban
  258. return playerData
  259. end
  260. -- 根据竞技场数据创建传送到跨服的玩家数据
  261. function createPlayerData(jjcData)
  262. if jjcData.monsterOutID then
  263. return createNPCData(jjcData)
  264. else
  265. return createHumanData(jjcData._id)
  266. end
  267. end
  268. ----------------------------------------------- db --------------------------------------------------
  269. -- 每日刷新
  270. function updateDaily(human)
  271. if not human.db.jjcLadder then
  272. return
  273. end
  274. human.db.jjcLadder.useCnt = nil
  275. human.db.jjcLadder.buyCnt = nil
  276. human.db.jjcLadder.mobais = nil
  277. end
  278. -- 阵容/基础信息变化
  279. function onUpdatePos(human)
  280. if not isSignAct(human.db._id) then
  281. return
  282. end
  283. local playerData = createHumanData(human.db._id)
  284. if not playerData then return end
  285. sendLWPlayerData(playerData)
  286. end
  287. -- 英雄变化
  288. function onUpdateHeroZDL(human, index)
  289. if not isSignAct(human.db._id) then
  290. return
  291. end
  292. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE16) --CombatDefine.COMBAT_TYPE16
  293. if not combatHero then return end
  294. local isFind = nil
  295. for _, heroIndex in pairs(combatHero) do
  296. if heroIndex == index then
  297. isFind = true
  298. break
  299. end
  300. end
  301. if not isFind then return end
  302. local playerData = createHumanData(human.db._id)
  303. if not playerData then return end
  304. sendLWPlayerData(playerData)
  305. end
  306. -- 已使用体力
  307. function getUseCnt(human)
  308. if not human.db.jjcLadder then
  309. return 0
  310. end
  311. return human.db.jjcLadder.useCnt or 0
  312. end
  313. --
  314. function addUseCnt(human, value)
  315. if not human.db.jjcLadder then
  316. human.db.jjcLadder = {}
  317. end
  318. local oldValue = human.db.jjcLadder.useCnt or 0
  319. human.db.jjcLadder.useCnt = oldValue + (value or 1)
  320. end
  321. -- 已购买体力次数
  322. function getBuyCnt(human)
  323. if not human.db.jjcLadder then
  324. return 0
  325. end
  326. return human.db.jjcLadder.buyCnt or 0
  327. end
  328. --
  329. function addBuyCnt(human, value)
  330. if not human.db.jjcLadder then
  331. human.db.jjcLadder = {}
  332. end
  333. local oldValue = human.db.jjcLadder.buyCnt or 0
  334. human.db.jjcLadder.buyCnt = oldValue + (value or 1)
  335. end
  336. -- 剩余可挑战次数
  337. function getLeftCnt(human)
  338. local maxCnt = JjcLadderDefine.initCnt + getBuyCnt(human)
  339. local useCnt = getUseCnt(human)
  340. return math.max(maxCnt - useCnt, 0)
  341. end
  342. -- 剩余购买次数
  343. function getLeftBuyCnt(human)
  344. local maxCnt = #JjcLadderDefine.buyCosts
  345. local buyCnt = getBuyCnt(human)
  346. return math.max(maxCnt - buyCnt, 0)
  347. end
  348. -- 购买体力价格
  349. function getBuyPrice(human)
  350. local buyCnt = getBuyCnt(human)
  351. local price = JjcLadderDefine.buyCosts[buyCnt + 1]
  352. if not price then
  353. price = JjcLadderDefine.buyCosts[#JjcLadderDefine.buyCosts]
  354. end
  355. return price
  356. end
  357. -- 是否已膜拜
  358. function isMobai(human, rank)
  359. if not human.db.jjcLadder then
  360. return
  361. end
  362. local mobais = human.db.jjcLadder.mobais
  363. if not mobais then return end
  364. return Util.getBit(mobais, rank) > 0
  365. end
  366. -- 设置膜拜
  367. function setMobai(human, rank)
  368. if not human.db.jjcLadder then
  369. human.db.jjcLadder = {}
  370. end
  371. local mobais = human.db.jjcLadder.mobais or 0
  372. human.db.jjcLadder.mobais = Util.setBit(mobais, rank)
  373. end
  374. -- 是否存在可膜拜
  375. function isMobaiRed(human, mobaiCnt)
  376. for i = 1, mobaiCnt do
  377. if not isMobai(human, i) then
  378. return true
  379. end
  380. end
  381. end
  382. -- 刷新剩余时间
  383. function getRefreshLeftTime(human)
  384. if not human.jjcLadderRefreshTime then
  385. return 0
  386. end
  387. local time = os.time() - human.jjcLadderRefreshTime
  388. return math.max(0, REFRESH_TIME - time)
  389. end
  390. -- 历史被膜拜次数
  391. function getBeMobaiCnt(human)
  392. if not human.db.jjcLadder then
  393. return 0
  394. end
  395. return human.db.jjcLadder.beMobaiCnt or 0
  396. end
  397. function setBeMobaiCnt(human, cnt)
  398. if not human.db.jjcLadder then
  399. human.db.jjcLadder = {}
  400. end
  401. human.db.jjcLadder.beMobaiCnt = cnt
  402. end
  403. function saveCommonDB(data)
  404. data = data or {}
  405. CommonDB.updateValue(CommonDB.KEY_JJC_LADDER, data)
  406. end
  407. local TEMP_COMMONDB = {}
  408. function getCommonDB()
  409. return CommonDB.getValueByKey(CommonDB.KEY_JJC_LADDER) or TEMP_COMMONDB
  410. end
  411. -- 是否有参赛资格
  412. function isSignAct(uuid)
  413. local commonDB = getCommonDB()
  414. if commonDB.uuid2sign and commonDB.uuid2sign[uuid] then
  415. return true
  416. end
  417. end
  418. ------------------------------------------------ msg --------------------------------------------------
  419. -- 查询主界面
  420. function query(human)
  421. if not isOpen(human) then
  422. return
  423. end
  424. local msgInner = InnerMsg.lw.LW_JJC_LADDER_QUERY
  425. msgInner.uuid = human.db._id
  426. InnerMsg.sendMsg(0, msgInner)
  427. end
  428. -- 真打 参数 targetRank|targetUuid
  429. function fight(human, args, combatType)
  430. local cacheCombatInfo = UUID_2_COMBATINFO[human.db._id]
  431. if cacheCombatInfo and cacheCombatInfo.time == os.time() then
  432. return -- 防止连按的情况
  433. end
  434. local state = isOpen(human)
  435. if not state then return end
  436. if state ~= STATE_ACT_START then
  437. return Broadcast.sendErr(human, Lang.JJC_LADDER_ERR_TIME)
  438. end
  439. if not isSignAct(human.db._id) then
  440. return Broadcast.sendErr(human, Lang.JJC_LADDER_ERR_JOIN)
  441. end
  442. if getLeftCnt(human) < 1 then
  443. if getLeftBuyCnt(human) > 0 then
  444. if not buyCnt(human) then
  445. return
  446. end
  447. else
  448. return Broadcast.sendErr(human, Lang.JJC_LADDER_FIGHT_ERR_CNT)
  449. end
  450. end
  451. local targetRank = tonumber(args[1])
  452. local targetUuid = args[2]
  453. if not targetRank or not targetUuid then
  454. return
  455. end
  456. if targetUuid == human.db._id then
  457. return -- 不能挑战自己哦
  458. end
  459. local msgInner = InnerMsg.lw.LW_JJC_LADDER_COMBAT_ASK
  460. msgInner.uuid = human.db._id
  461. msgInner.targetUuid = targetUuid
  462. msgInner.targetRank = targetRank
  463. InnerMsg.sendMsg(0, msgInner)
  464. --print("fight", targetUuid, targetRank)
  465. end
  466. -- 战斗结束回调
  467. function onFightEnd(human, result, combatType, cbParam, combatInfo, param, isSaodang)
  468. print(" onFightEnd onFightEnd onFightEnd onFightEnd")
  469. --print("fight end", result, combatInfo, result)
  470. if not cbParam or not cbParam.uuid then
  471. return
  472. end
  473. if not param or not param.uuid then
  474. print(" not param ")
  475. end
  476. UUID_2_COMBATINFO[cbParam.uuid] = combatInfo
  477. local rolebase = cbParam.playerData.rolebase
  478. combatInfo.attacker.name = combatInfo.attacker.name
  479. combatInfo.defender.name = rolebase.name
  480. if combatInfo.isWin and cbParam.rank > cbParam.targetRank then
  481. combatInfo.endParam = cbParam.targetRank .. "|" .. cbParam.rank .. "|" .. cbParam.rank .. "|" .. cbParam.targetRank
  482. else
  483. combatInfo.endParam = cbParam.rank .. "|" .. cbParam.targetRank .. "|" .. cbParam.rank .. "|" .. cbParam.targetRank
  484. end
  485. local msgRet = Msg.gc.GC_JJC_LADDER_AFTER_FIGHT
  486. local len = 0
  487. if getLeftCnt(human) > 0 then
  488. -- 扣次数 给奖励
  489. addUseCnt(human)
  490. local config = combatInfo.isWin and JjcLadderExcel.winReward or JjcLadderExcel.failReward
  491. local itemID, itemCnt = randomReward(config)
  492. if itemID then
  493. BagLogic.addItem(human, itemID, itemCnt, "jjc_ladder")
  494. combatInfo.rewardItem = {}
  495. combatInfo.rewardItem[1] = {itemID, itemCnt}
  496. len = len + 1
  497. Grid.makeItem(msgRet.items[len], itemID, itemCnt)
  498. end
  499. end
  500. local state = getState()
  501. local newRank, newTargetRank = cbParam.rank , cbParam.targetRank
  502. if state == STATE_ACT_START then
  503. if combatInfo.isWin and (cbParam.rank > cbParam.targetRank) then
  504. newRank, newTargetRank = cbParam.targetRank, cbParam.rank
  505. end
  506. else
  507. combatInfo.isActEnd = true
  508. end
  509. msgRet.result = result
  510. msgRet.rank = cbParam.rank
  511. msgRet.newRank = newRank
  512. msgRet.targetRank = cbParam.targetRank
  513. msgRet.targetNewRank = newTargetRank
  514. RoleLogic.makeRoleBase(combatInfo.attacker, msgRet.atkRole)
  515. RoleLogic.makeRoleBase(combatInfo.defender, msgRet.defRole)
  516. msgRet.items[0] = len
  517. Msg.send(msgRet, human.fd)
  518. local msgInner = InnerMsg.lw.LW_JJC_LADDER_COMBAT_RESULT
  519. msgInner.uuid = cbParam.uuid
  520. msgInner.rank = cbParam.rank
  521. msgInner.targetUuid = cbParam.targetUuid
  522. msgInner.targetRank = cbParam.targetRank
  523. msgInner.combatInfo = combatInfo
  524. InnerMsg.sendMsg(0, msgInner)
  525. if result == CombatDefine.RESULT_WIN then
  526. LiLianLogic.onCallback(human,LiLianLogic.LILIAN_OUTID4,1)
  527. end
  528. -- 战报
  529. WarReportLogic.add(WarReportLogic.WAR_REPORT_3, combatInfo, cbParam.rank, cbParam.targetRank)
  530. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1401)
  531. end
  532. -- 一键挑战
  533. function combatOneKey(human)
  534. local state = isOpen(human)
  535. if not state then return end
  536. if state ~= STATE_ACT_START then
  537. return Broadcast.sendErr(human, Lang.JJC_LADDER_ERR_TIME)
  538. end
  539. ObjHuman.updateDaily(human)
  540. if getLeftCnt(human) < 1 then
  541. if getLeftBuyCnt(human) > 0 then
  542. if not buyCnt(human) then
  543. return
  544. end
  545. else
  546. return Broadcast.sendErr(human, Lang.JJC_LADDER_FIGHT_ERR_CNT)
  547. end
  548. end
  549. if not isSignAct(human.db._id) then
  550. return Broadcast.sendErr(human, Lang.JJC_LADDER_ERR_JOIN)
  551. end
  552. -- 扣次数 给奖励 名次不变
  553. addUseCnt(human)
  554. local itemID, itemCnt = randomReward(JjcLadderExcel.winReward)
  555. if itemID then
  556. BagLogic.addItem(human, itemID, itemCnt, "jjc_ladder")
  557. TEMP_REWARD_LIST[1][1] = itemID
  558. TEMP_REWARD_LIST[1][2] = itemCnt
  559. BagLogic.sendItemGetList(human, TEMP_REWARD_LIST)
  560. end
  561. sendBuyCnt(human)
  562. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1401)
  563. LiLianLogic.onCallback(human,LiLianLogic.LILIAN_OUTID4,1)
  564. end
  565. -- 购买挑战次数
  566. function buyCnt(human)
  567. local state = isOpen(human)
  568. if not state then return end
  569. if state ~= STATE_ACT_START then
  570. return Broadcast.sendErr(human, Lang.JJC_LADDER_ERR_TIME)
  571. end
  572. ObjHuman.updateDaily(human)
  573. if getLeftBuyCnt(human) < 1 then
  574. return Broadcast.sendErr(human, Lang.JJC_LADDER_BUY_ERR_CNT)
  575. end
  576. local needPrice = getBuyPrice(human)
  577. if not ObjHuman.checkRMB(human, needPrice) then
  578. return Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI)
  579. end
  580. if not isSignAct(human.db._id) then
  581. return Broadcast.sendErr(human, Lang.JJC_LADDER_ERR_JOIN)
  582. end
  583. print(" decZuanshi ", -needPrice)
  584. -- 扣钻石,给次数
  585. ObjHuman.decZuanshi(human, -needPrice, "jjc_ladder")
  586. addBuyCnt(human)
  587. sendBuyCnt(human)
  588. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1401)
  589. return true
  590. end
  591. function sendBuyCnt(human)
  592. local msgRet = Msg.gc.GC_JJC_LADDER_BUYCNT
  593. msgRet.leftCnt = getLeftCnt(human)
  594. msgRet.leftBuyCnt = getLeftBuyCnt(human)
  595. msgRet.buyCost = getBuyPrice(human)
  596. Msg.send(msgRet, human.fd)
  597. end
  598. -- 刷新挑战对象
  599. function refresh(human)
  600. local state = isOpen(human)
  601. if not state then return end
  602. if state ~= STATE_ACT_START then
  603. return Broadcast.sendErr(human, Lang.JJC_LADDER_ERR_TIME)
  604. end
  605. if not isSignAct(human.db._id) then
  606. return Broadcast.sendErr(human, Lang.JJC_LADDER_ERR_JOIN)
  607. end
  608. -- 判断刷新间隔
  609. local leftTime = getRefreshLeftTime(human)
  610. if leftTime > 0 then
  611. return Broadcast.sendErr(human, Util.format(Lang.JJC_LADDER_REFRESH_TOO_QUICK, leftTime))
  612. end
  613. human.jjcLadderRefreshTime = os.time()
  614. query(human)
  615. end
  616. -- 查询膜拜列表
  617. function mobaiQuery(human)
  618. if not isOpen(human) then
  619. return
  620. end
  621. local msgInner = InnerMsg.lw.LW_JJC_LADDER_MOBAI_QUERY
  622. msgInner.uuid = human.db._id
  623. InnerMsg.sendMsg(0, msgInner)
  624. end
  625. -- 膜拜
  626. function mobai(human, rank, isOk)
  627. if not isOpen(human) then
  628. return
  629. end
  630. if rank < 1 or rank > MOBAI_PLAYER_CNT then
  631. return
  632. end
  633. if isMobai(human, rank) then
  634. return Broadcast.sendErr(human, Lang.JJC_LADDER_MOBAI_ERR_HAD)
  635. end
  636. if isOk then
  637. setMobai(human, rank)
  638. for _, item in ipairs(JjcLadderDefine.mobaiItems) do
  639. local itemID = item[1]
  640. local itemCnt = item[2]
  641. BagLogic.addItem(human, itemID, itemCnt, "jjc_ladder_mobai")
  642. end
  643. local itemID = JjcLadderDefine.mobaiItems[1][1]
  644. local itemCnt = JjcLadderDefine.mobaiItems[1][2]
  645. Broadcast.sendErr(human, Util.format(Lang.JJC_LADDER_MOBAI_SUCCEED, ItemDefine.getValue(itemID, "name"), itemCnt) )
  646. else
  647. local msgInner = InnerMsg.lw.LW_JJC_LADDER_MOBAI
  648. msgInner.uuid = human.db._id
  649. msgInner.rank = rank
  650. InnerMsg.sendMsg(0, msgInner)
  651. end
  652. end
  653. -- 查看当前排行/上一期排行榜
  654. function boardQuery(human)
  655. local state = isOpen(human)
  656. if not state then return end
  657. local msgInner = InnerMsg.lw.LW_JJC_LADDER_BOARD
  658. msgInner.uuid = human.db._id
  659. InnerMsg.sendMsg(0, msgInner)
  660. end
  661. -- 排名奖励
  662. function queryReward(human, rank)
  663. local state = isOpen(human)
  664. if not state then return end
  665. if rank then
  666. local msgRet = Msg.gc.GC_JJC_LADDER_REWARD_QUERY
  667. msgRet.list[0] = #JjcLadderExcel.reward
  668. for i = 1, msgRet.list[0] do
  669. local net = msgRet.list[i]
  670. local conf = JjcLadderExcel.reward[i]
  671. net.rankMin = conf.rankMin
  672. net.rankMax = conf.rankMax
  673. net.items[0] = #conf.reward
  674. for j = 1, net.items[0] do
  675. local itemID = conf.reward[j][1]
  676. local itemCnt = conf.reward[j][2]
  677. Grid.makeItem(net.items[j], itemID, itemCnt)
  678. end
  679. end
  680. local myConf = getRewardByRank(rank)
  681. msgRet.rank = nil
  682. msgRet.myRank = rank
  683. msgRet.myReward[0] = myConf and #myConf.reward or 0
  684. for i = 1, msgRet.myReward[0] do
  685. local itemID = myConf.reward[i][1]
  686. local itemCnt = myConf.reward[i][2]
  687. Grid.makeItem(msgRet.myReward[i], itemID, itemCnt)
  688. end
  689. --Msg.trace(msgRet)
  690. Msg.send(msgRet, human.fd)
  691. else
  692. local msgInner = InnerMsg.lw.LW_JJC_LADDER_RANK
  693. msgInner.uuid = human.db._id
  694. InnerMsg.sendMsg(0, msgInner)
  695. end
  696. end
  697. -- 日志查看
  698. function logQuery(human)
  699. print(" logQuery !!!!!! " )
  700. local state = isOpen(human)
  701. if not state then return end
  702. if state ~= STATE_ACT_START then
  703. return Broadcast.sendErr(human, Lang.JJC_LADDER_ERR_TIME)
  704. end
  705. local msgInner = InnerMsg.lw.LW_JJC_LADDER_LOG
  706. msgInner.uuid = human.db._id
  707. InnerMsg.sendMsg(0, msgInner)
  708. end
  709. -- 查看录像
  710. function repeatVideo(human, videoUuid)
  711. local state = isOpen(human)
  712. if not state then return end
  713. if state ~= STATE_ACT_START then
  714. return Broadcast.sendErr(human, Lang.JJC_LADDER_ERR_TIME)
  715. end
  716. local msgInner = InnerMsg.lw.LW_JJC_LADDER_REPEAT_VIDEO
  717. msgInner.uuid = human.db._id
  718. msgInner.videoUuid = videoUuid
  719. InnerMsg.sendMsg(0, msgInner)
  720. end
  721. -------------------------------------- middle -------------------------------------------
  722. local function cmpRank(a, b)
  723. return a.roleBase.rank < b.roleBase.rank
  724. end
  725. -- 封装 英雄
  726. local function fontHeroList(net,data)
  727. local len = 0
  728. local monsterOutID = data.monsterOutID
  729. if monsterOutID then
  730. for k,v in ipairs(MonsterOutExcel[monsterOutID].member) do
  731. if v[1] > 0 then
  732. len = len + 1
  733. HeroGrid.makeHeroSimpleByMonsterID(net[len],v[1],{lv = v[2]})
  734. end
  735. end
  736. else
  737. for i = 1,CombatDefine.COMBAT_HERO_CNT do
  738. local obj = data.objList[i]
  739. if obj then
  740. len = len + 1
  741. if HeroExcel.hero[obj.id] then
  742. HeroGrid.makeHeroSimpleByID(net[len],obj.id, obj.bagIndex,{lv = obj.lv,star = obj.star})
  743. else
  744. HeroGrid.makeHeroSimpleByMonsterID(net[len],obj.id,{lv = obj.lv,star = obj.star})
  745. end
  746. end
  747. end
  748. end
  749. net[0] = len
  750. end
  751. -- 返回主界面信息
  752. function WL_JJC_LADDER_QUERY(uuid, targetList, mobaiCnt, logRed, myRank)
  753. local human = ObjHuman.onlineUuid[uuid]
  754. if not human then return end
  755. ObjHuman.updateDaily(human)
  756. local state, leftTime = getState()
  757. local msgRet = Msg.gc.GC_JJC_LADDER_QUERY
  758. local dataNet = msgRet.data
  759. dataNet.state = state
  760. print(" state getState() dataNet.state ", state , dataNet.state)
  761. dataNet.leftTime = leftTime
  762. dataNet.mobaiRed = isMobaiRed(human, mobaiCnt) and 1 or 0
  763. dataNet.logRed = logRed
  764. local startTime,endTime = getActTime()
  765. local cleanTime = Util.getDayStartTime(endTime + 60 * 60 * 24)
  766. if state == STATE_ACT_START then
  767. dataNet.list[0] = #targetList
  768. if dataNet.list[0] > 1 then
  769. table.sort(targetList, cmpRank)
  770. end
  771. for i = 1, dataNet.list[0] do
  772. local rankNet = dataNet.list[i]
  773. local rankData = targetList[i].roleBase
  774. rankNet.rank = rankData.rank
  775. rankNet.uuid = rankData.uuid
  776. rankNet.name = rankData.name
  777. rankNet.svrName = rankData.svrName
  778. rankNet.body = rankData.body or 0
  779. rankNet.head = rankData.head
  780. rankNet.headFrame = rankData.headFrame or RoleDefine.DEFAULT_HEAD_FRAME
  781. rankNet.zhandouli = rankData.zhandouli
  782. rankNet.unionName = rankData.unionName
  783. rankNet.svrIndex = rankData.svrIndex or 0
  784. fontHeroList(rankNet.heroList, targetList[i])
  785. end
  786. else
  787. dataNet.list[0] = 0
  788. if (state == STATE_ACT_READY and os.time() >= startTime and os.time() < cleanTime) then
  789. dataNet.state = 3
  790. if #targetList > 0 then
  791. dataNet.list[0] = #targetList
  792. if dataNet.list[0] > 1 then
  793. table.sort(targetList, cmpRank)
  794. end
  795. for i = 1, dataNet.list[0] do
  796. local rankNet = dataNet.list[i]
  797. local rankData = targetList[i].roleBase
  798. rankNet.rank = rankData.rank
  799. rankNet.uuid = rankData.uuid
  800. rankNet.name = rankData.name
  801. rankNet.svrName = rankData.svrName
  802. rankNet.body = rankData.body or 0
  803. rankNet.head = rankData.head
  804. rankNet.headFrame = rankData.headFrame or RoleDefine.DEFAULT_HEAD_FRAME
  805. rankNet.zhandouli = rankData.zhandouli
  806. rankNet.unionName = rankData.unionName
  807. rankNet.svrIndex = rankData.svrIndex or 0
  808. fontHeroList(rankNet.heroList, targetList[i])
  809. end
  810. end
  811. end
  812. end
  813. dataNet.myRank = myRank
  814. dataNet.leftCnt = getLeftCnt(human)
  815. dataNet.leftBuyCnt = getLeftBuyCnt(human)
  816. dataNet.buyCost = getBuyPrice(human)
  817. --Msg.trace(msgRet)
  818. Msg.send(msgRet, human.fd)
  819. human.jjcLadderTargetList = targetList
  820. JJCLADDER_MOBAICNT = mobaiCnt
  821. end
  822. -- 行为检测
  823. function WL_JJC_LADDER_RANK(uuid, rank)
  824. local human = ObjHuman.onlineUuid[uuid]
  825. if not human then return end
  826. queryReward(human, rank)
  827. end
  828. -- 膜拜查询
  829. function WL_JJC_LADDER_MOBAI_QUERY(uuid, list)
  830. local human = ObjHuman.onlineUuid[uuid]
  831. if not human then return end
  832. local msgRet = Msg.gc.GC_JJC_LADDER_MOBAI_QUERY
  833. msgRet.list[0] = list and #list or 0
  834. for i = 1, msgRet.list[0] do
  835. local net = msgRet.list[i]
  836. local rankData = list[i]
  837. net.rank = i
  838. net.uuid = rankData.uuid
  839. net.name = rankData.name
  840. net.svrName = rankData.svrName
  841. net.head = rankData.head
  842. net.headFrame = rankData.headFrame or RoleDefine.DEFAULT_HEAD_FRAME
  843. net.body = rankData.body or 0
  844. net.cnt = rankData.beMobaiCnt or 0
  845. net.isMobai = isMobai(human, i) and 1 or 0
  846. net.svrIndex = rankData.svrIndex or 0
  847. end
  848. --Msg.trace(msgRet)
  849. Msg.send(msgRet, human.fd)
  850. end
  851. -- 膜拜点赞
  852. function WL_JJC_LADDER_MOBAI(uuid, rank)
  853. local human = ObjHuman.onlineUuid[uuid]
  854. if not human then return end
  855. mobai(human, rank, true)
  856. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1401)
  857. end
  858. -- 封装排行榜结构体
  859. local function fontBoardNet(net, data, db)
  860. if data.rank and data.uuid then
  861. net.rank = data.rank
  862. net.uuid = data.uuid
  863. net.head = data.head
  864. net.headFrame = data.headFrame or RoleDefine.DEFAULT_HEAD_FRAME
  865. net.name = data.name
  866. net.svrName = data.svrName
  867. net.unionName = data.unionName or ""
  868. net.zhandouli = data.zhandouli
  869. else
  870. local union = UnionDBLogic.getUnion(db.unionUuid)
  871. net.rank = 0
  872. net.uuid = db._id
  873. net.head = db.head
  874. net.headFrame = db.headFrame or RoleDefine.DEFAULT_HEAD_FRAME
  875. net.name = db.name
  876. net.svrName = Config.SVR_NAME
  877. net.unionName = union and union.name or ""
  878. net.zhandouli = db.zhandouli
  879. end
  880. end
  881. -- 排行榜查询
  882. function WL_JJC_LADDER_BOARD(uuid, list, myData)
  883. local human = ObjHuman.onlineUuid[uuid]
  884. if not human then return end
  885. local msgRet = Msg.gc.GC_JJC_LADDER_BOARD
  886. msgRet.list[0] = list and #list or 0
  887. for i = 1, msgRet.list[0] do
  888. local rankData = list[i]
  889. RoleLogic.makeRoleBase(rankData, msgRet.list[i].rolebase)
  890. msgRet.list[i].rolebase.serverName = rankData.serverName and rankData.serverName or msgRet.list[i].rolebase.serverName -- and msgRet.list[i].rolebase.svrName or rankData.serverName
  891. msgRet.list[i].unionName = rankData.unionName or ""
  892. end
  893. if myData.uuid then
  894. RoleLogic.makeRoleBase(myData, msgRet.myData.rolebase)
  895. msgRet.myData.unionName = myData.unionName or ""
  896. else
  897. RoleLogic.makeRoleBase(human.db, msgRet.myData.rolebase)
  898. msgRet.myData.unionName = getUnionName(human.db.unionUuid)
  899. end
  900. msgRet.myRank = myData.rank or 0
  901. --Msg.trace(msgRet)
  902. Msg.send(msgRet, human.fd)
  903. end
  904. -- 战斗请求返回
  905. function WL_JJC_LADDER_COMBAT_ASK(uuid, rank, targetUuid, targetRank, playerData)
  906. local human = ObjHuman.onlineUuid[uuid]
  907. if not human then return end
  908. -- 开打
  909. local cbParam = {}
  910. cbParam.uuid = uuid
  911. cbParam.rank = rank
  912. cbParam.targetUuid = targetUuid
  913. cbParam.targetRank = targetRank
  914. cbParam.playerData = playerData
  915. local param = {}
  916. param.defender = playerData.objList
  917. param.defHelp = playerData.helpList
  918. param.defRBase = playerData.rolebase
  919. param.defFormation = playerData.formation
  920. param.defJiban = playerData.jiban
  921. print(" WL_JJC_LADDER_COMBAT_ASK !!!!!! ", cbParam.uuid)
  922. CombatLogic.combatBegin(human, 1001, param, CombatDefine.COMBAT_TYPE15, cbParam)
  923. end
  924. -- 战斗结果播放
  925. function WL_JJC_LADDER_COMBAT_RESULT(uuid, rank, targetUuid, targetRank)
  926. local human = ObjHuman.onlineUuid[uuid]
  927. if not human then return end
  928. local cacheCombatInfo = UUID_2_COMBATINFO[uuid]
  929. UUID_2_COMBATINFO[uuid] = nil
  930. if cacheCombatInfo then
  931. -- CombatLogic.addCombatCache(human.db._id, cacheCombatInfo, nil, true)
  932. -- CombatLogic.sendCombatData(human, cacheCombatInfo)
  933. end
  934. end
  935. function fontJJCLog(net, log)
  936. net.time = log.time
  937. RoleLogic.makeRoleBase(log.attacker, net.attacker )
  938. RoleLogic.makeRoleBase(log.defender, net.defender)
  939. net.isWin = log.isWin and 1 or 0
  940. net.videoUuid = log.videoUuid or ""
  941. net.atkRank = log.atkRank
  942. net.defRank = log.defRank
  943. net.atkSvr = log.attacker.serverName
  944. net.defSvr = log.defender.serverName
  945. end
  946. -- 战斗日志
  947. function WL_JJC_LADDER_LOG(uuid, logs, godLogs)
  948. local human = ObjHuman.onlineUuid[uuid]
  949. if not human then return end
  950. local msgRet = Msg.gc.GC_JJC_LADDER_LOG
  951. msgRet.list[0] = logs and #logs or 0
  952. for i = 1, msgRet.list[0] do
  953. local net = msgRet.list[i]
  954. fontJJCLog(net, logs[i])
  955. end
  956. msgRet.godList[0] = godLogs and #godLogs or 0
  957. msgRet.godList[0] = msgRet.godList[0] < 10 and msgRet.godList[0] or 10
  958. for i = 1, msgRet.godList[0] do
  959. local net = msgRet.godList[i]
  960. fontJJCLog(net, godLogs[i])
  961. end
  962. -- Msg.trace(msgRet)
  963. Msg.send(msgRet, human.fd)
  964. end
  965. -- 战斗回放
  966. function WL_JJC_LADDER_REPEAT_VIDEO(uuid, combatInfo)
  967. local human = ObjHuman.onlineUuid[uuid]
  968. if not human then return end
  969. if not next(combatInfo) then
  970. Broadcast.sendErr(human, Lang.COMBAT_ERR_NOT_VIDEO)
  971. else
  972. CombatLogic.repeatCombat(human, combatInfo)
  973. end
  974. end
  975. -- 比赛结果 发奖励
  976. local FieldJjcFinal = {lv = 1}
  977. function WL_JJC_LADDER_FINAL_RESULT(list)
  978. local mailConfig = MailExcel.mail[MailDefine.MAIL_ID_JJC_LADDER]
  979. local title = mailConfig.title
  980. local senderName = mailConfig.senderName
  981. local needLv = 0 -- RoleSystemLogic.getOpenLv(RoleSystemDefine.ROLE_SYS_ID_10012)
  982. for _, conf in ipairs(JjcLadderExcel.reward) do
  983. for rank = conf.rankMin, conf.rankMax do
  984. local uuid = list[rank]
  985. local db = uuid and RoleDBLogic.getDb(uuid, FieldJjcFinal)
  986. if db and (db.lv >= needLv) then
  987. -- 发邮件
  988. local content = Util.format(mailConfig.content, rank)
  989. MailManager.add(MailManager.SYSTEM, uuid, title, content, conf.reward, senderName)
  990. -- 回调
  991. LiLianLogic.onCallbackByUuid(uuid,LiLianLogic.LILIAN_OUTID3,1,rank,nil,true)
  992. end
  993. end
  994. end
  995. end
  996. --
  997. function WL_JJC_LADDER_MOBAI_CNT(mobaiCnt)
  998. JJCLADDER_MOBAICNT = mobaiCnt
  999. --print("JJCLADDER_MOBAICNT",JJCLADDER_MOBAICNT)
  1000. end
  1001. -- 点赞数同步
  1002. local FieldJjcBemobai = {jjcLadder = 1}
  1003. function WL_JJC_LADDER_BEMOBAICNT(uuid, beMobaiCnt)
  1004. local db = RoleDBLogic.getDb(uuid, FieldJjcBemobai)
  1005. if db then
  1006. db.jjcLadder = db.jjcLadder or {}
  1007. db.jjcLadder.beMobaiCnt = beMobaiCnt
  1008. RoleDBLogic.saveRoleSset(db)
  1009. end
  1010. end
  1011. -- 刷新红点
  1012. function updateReds()
  1013. for _, human in pairs(ObjHuman.onlineUuid) do
  1014. if human.fd then
  1015. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1401)
  1016. end
  1017. end
  1018. end
  1019. local function getChengHaoIDByRank(rank)
  1020. if rank > 3 then
  1021. return 0
  1022. end
  1023. local config = JjcLadderExcel.godWarBoard[rank]
  1024. if config then
  1025. local chenghao = config.reward[#config.reward]
  1026. return chenghao
  1027. end
  1028. return 0
  1029. end
  1030. function WL_JJC_LADDER_CHENGHAO_DEL(msg)
  1031. for uuid, db in pairs(msg.list) do
  1032. if db.svrIndex == Config.SVR_INDEX then
  1033. local chenghao = getChengHaoIDByRank(db.rank)
  1034. if chenghao and chenghao > 0 then
  1035. RoleHeadLogic.unActive(uuid, RoleHeadLogic.HEAD_TYPE_4, chenghao)
  1036. end
  1037. end
  1038. end
  1039. end
  1040. ------------------------------------- 活动状态变化 ------------------------------------------
  1041. -- 活动开始
  1042. function onActStart()
  1043. if _G.is_middle then
  1044. return JjcLadderMiddle.onActStart()
  1045. end
  1046. Timer.addLater(1, updateReds)
  1047. end
  1048. -- 活动结束
  1049. function onActEnd()
  1050. if _G.is_middle then
  1051. return JjcLadderMiddle.onActEnd()
  1052. end
  1053. local commonDB = getCommonDB()
  1054. commonDB.uuid2sign = nil
  1055. commonDB.sendDataList = nil
  1056. saveCommonDB(commonDB)
  1057. Timer.addLater(1, updateReds)
  1058. end
  1059. -- 活动准备开始
  1060. function onActReady()
  1061. if _G.is_middle then
  1062. return JjcLadderMiddle.onActReady()
  1063. end
  1064. print(" onActReady !!! go ")
  1065. local openDay = CommonDB.getServerOpenDay()
  1066. if not openDay then
  1067. return
  1068. end
  1069. if openDay < 3 then
  1070. return
  1071. end
  1072. local commonDB = getCommonDB()
  1073. commonDB.sendDataList = {}
  1074. commonDB.uuid2sign = {}
  1075. for i = SENDDATA_PLAYER_CNT, 1, -1 do
  1076. local jjcData = JjcDB.RANK_2_JJCDATA[i]
  1077. if jjcData then
  1078. local listLen = #commonDB.sendDataList
  1079. commonDB.sendDataList[listLen + 1] = jjcData
  1080. end
  1081. end
  1082. saveCommonDB(commonDB)
  1083. end
  1084. -- l->w
  1085. function sendLWPlayerData(playerData)
  1086. local msgInner = InnerMsg.lw.LW_JJC_LADDER_SENDDATA
  1087. msgInner.player = playerData
  1088. InnerMsg.sendMsg(0, msgInner)
  1089. end
  1090. -- 同步玩家数据到跨服 l->w
  1091. function sendData2Middle()
  1092. local commonDB = getCommonDB()
  1093. if not commonDB.sendDataList then
  1094. return
  1095. end
  1096. local nowTime = os.time()
  1097. for i = 1, SENDDATA_PER_TIME do
  1098. local listLen = #commonDB.sendDataList
  1099. local jjcData = commonDB.sendDataList[listLen]
  1100. if not jjcData then break end
  1101. commonDB.sendDataList[listLen] = nil
  1102. local playerData = createPlayerData(jjcData)
  1103. if playerData then
  1104. sendLWPlayerData(playerData)
  1105. commonDB.uuid2sign[playerData._id] = nowTime
  1106. end
  1107. end
  1108. -- 全部发完,清空
  1109. if #commonDB.sendDataList < 1 then
  1110. commonDB.sendDataList = nil
  1111. end
  1112. saveCommonDB(commonDB)
  1113. end
  1114. function getCleanUpTime()
  1115. local _,endTime = getActTime()
  1116. return Util.getDayStartTime(endTime + 60 * 60 * 24)
  1117. end
  1118. -- 定时器
  1119. TEMP_TIMER_STAMPTIME = TEMP_TIMER_STAMPTIME or nil
  1120. function onTimer()
  1121. if not TEMP_TIMER_STAMPTIME then
  1122. _, TEMP_TIMER_STAMPTIME = getNewState()
  1123. end
  1124. local nowTime = os.time()
  1125. local commonDB = getCommonDB()
  1126. if (not commonDB.endTime) or
  1127. (commonDB.endTime <= nowTime) or
  1128. (commonDB.endTime ~= TEMP_TIMER_STAMPTIME) then
  1129. local oldState = commonDB.state
  1130. local state, endTime = getNewState()
  1131. print(" onTimer ", state, endTime)
  1132. commonDB.state = state
  1133. commonDB.endTime = endTime
  1134. TEMP_TIMER_STAMPTIME = endTime
  1135. saveCommonDB(commonDB)
  1136. --print("jjcLadder state",state,oldState,endTime)
  1137. if state == STATE_ACT_START then
  1138. onActStart()
  1139. elseif state == STATE_ACT_READY then
  1140. onActEnd()
  1141. elseif state == STATE_ACT_SENDDATA then
  1142. onActReady()
  1143. end
  1144. end
  1145. if _G.is_middle then
  1146. -- 跨服
  1147. if not commonDB.cleanTime then
  1148. commonDB.cleanTime = getCleanUpTime()
  1149. saveCommonDB(commonDB)
  1150. end
  1151. -- print(" endTime, cleanTime ",nowTime , commonDB.cleanTime- nowTime, nowTime > commonDB.cleanTime , Util.getWeekDay(commonDB.endTime), Util.getWeekDay(cleanTime) ,os.time(), os.time() >= commonDB.endTime )
  1152. if nowTime > commonDB.cleanTime then
  1153. print(" read clean up")
  1154. JjcLadderMiddle.resetDbActEnd()
  1155. end
  1156. else
  1157. -- 本服
  1158. sendData2Middle()
  1159. end
  1160. end
  1161. -- 返回活动列表的状态
  1162. function getActState()
  1163. if not MiddleConnect.IS_MIDDLE_CONNECT then
  1164. return JjcActLogic.STATE_NOOPEN, 0
  1165. end
  1166. local state, leftTime = getState()
  1167. if state == STATE_ACT_START then
  1168. -- 如果是 是当天开服 则没有走 0点逻辑 没有对手 没有天梯比赛
  1169. local openDay = CommonDB.getServerOpenDay()
  1170. if not openDay then
  1171. return JjcActLogic.STATE_NOOPEN, 0
  1172. end
  1173. if openDay and openDay <= 4 then
  1174. return JjcActLogic.STATE_NOOPEN, 0
  1175. end
  1176. return JjcActLogic.STATE_START, leftTime
  1177. end
  1178. return JjcActLogic.STATE_READY, leftTime
  1179. end
  1180. -- 描述
  1181. function getActDesc(desc)
  1182. if not MiddleConnect.IS_MIDDLE_CONNECT then
  1183. return Lang.MIDDLE_SVR_ERR_CONNECT
  1184. end
  1185. return desc
  1186. end