KingWorldLogic.lua 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. --------------------------------
  2. -- 成神之路-君临天下
  3. -- db.kingworld[id] = state
  4. --------------------------------
  5. local Lang = require("common.Lang")
  6. local Util = require("common.Util")
  7. local OpenActLogic = require("present.OpenAct")
  8. local OpenServerExcel = require("excel.openAct")
  9. local MailExcel = require("excel.mail")
  10. local Msg = require("core.Msg")
  11. local ObjHuman = require("core.ObjHuman")
  12. local MailManager = require("mail.MailManager")
  13. local Grid = require("bag.Grid")
  14. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  15. local BattleLogic = require("battle.BattleLogic")
  16. local SceneHandler = require("scene.Handler")
  17. local HeroGrid = require("hero.HeroGrid")
  18. local MonthCardLogic = require("present.MonthCard")
  19. local BagLogic = require("bag.BagLogic")
  20. local YunYingLogic = require("yunying.YunYingLogic")
  21. local PanelDefine = require("broadcast.PanelDefine")
  22. local OpenServerGiftLogic = require("present.OpenServerGiftLogic")
  23. local ChengjiuExcel = require("excel.chengjiu").chengjiu
  24. KING_TYPE_1 = 1 -- 关卡必须75
  25. KING_TYPE_2 = 2 -- 次日登录
  26. KING_TYPE_3 = 3 -- 激活至尊月卡
  27. KING_TYPE_4 = 4 -- 总览
  28. STATE_NONE = 0
  29. STATE_FINISH = 1 -- 可领取
  30. STATE_GET = 2 -- 已领取
  31. -- 第二版需求出了 之后 有的服已经上线了 所以 维持原有的 DB 格式去修改
  32. --
  33. local function initDB(human)
  34. if not human.db.kingworld then
  35. human.db.kingworld = { }
  36. for i = 1, KING_TYPE_4 do
  37. human.db.kingworld[i] = human.db.kingworld[i] or { }
  38. human.db.kingworld[i].status = human.db.kingworld[i].status or STATE_NONE
  39. end
  40. end
  41. end
  42. -- 是否开放
  43. function isOpen(human)
  44. if not SceneHandler.canCharge(human) then
  45. return
  46. end
  47. local isOpen, leftTime = OpenActLogic.getOpenActTime(OpenActLogic.OPEN_ACT_KING_WORLD)
  48. return isOpen, leftTime
  49. end
  50. -- 返回时间
  51. function getLeftTime(human)
  52. local isOpen, leftTime = OpenActLogic.getOpenActTime(OpenActLogic.OPEN_ACT_KING_WORLD)
  53. return leftTime
  54. end
  55. -- 发送奖励
  56. local function mailReward(human, id, mailId)
  57. local config = OpenServerExcel.kingWorld[id]
  58. if not config then return end
  59. local items = { }
  60. for z, v in ipairs(config.reward) do
  61. items[#items + 1] = { v[1], v[2] }
  62. end
  63. local title = MailExcel.mail[mailId].title
  64. local content = MailExcel.mail[mailId].content
  65. local senderName = MailExcel.mail[mailId].senderName
  66. MailManager.add(MailManager.SYSTEM, human.db._id, title, content, items, senderName)
  67. end
  68. function fontChengJiuNet(human, net, id)
  69. local config = ChengjiuExcel[id]
  70. net.maxCnt = config.param
  71. net.nowCnt = 0
  72. net.state = 0
  73. if human.db.chengjiu.type and human.db.chengjiu.type[config.type] then
  74. net.nowCnt = human.db.chengjiu.type[config.type]
  75. end
  76. if human.db.chengjiu.task and human.db.chengjiu.task[id] == STATE_GET then
  77. net.state = human.db.chengjiu.task[id]
  78. end
  79. end
  80. function query(human)
  81. local open, leftTime = isOpen(human)
  82. if not open then return end
  83. local msgRet = Msg.gc.GC_PRESENT_KING_WORLD_QUERY
  84. msgRet.leftTime = leftTime
  85. msgRet.list[0] = KING_TYPE_3
  86. for i = KING_TYPE_1, KING_TYPE_3 do
  87. local net = msgRet.list[i]
  88. local cf = OpenServerExcel.kingWorld[i]
  89. net.id = i
  90. net.sort = cf.sort
  91. net.desc = cf.desc
  92. net.panelID = cf.panelID
  93. net.tubiao = cf.tubiaoID
  94. net.item[0] = #cf.reward
  95. for j = 1, net.item[0] do
  96. local itemID = cf.reward[j][1]
  97. local itemCnt = cf.reward[j][2]
  98. Grid.makeItem(net.item[j], itemID, itemCnt)
  99. end
  100. fontChengJiuNet(human, net, cf.chengJiuID)
  101. end
  102. local fconfig = OpenServerExcel.kingWorld[KING_TYPE_4]
  103. msgRet.finalId = KING_TYPE_4
  104. msgRet.finalReward[0] = #fconfig.reward
  105. for j = 1, msgRet.finalReward[0] do
  106. local itemID = fconfig.reward[j][1]
  107. local itemCnt = fconfig.reward[j][2]
  108. Grid.makeItem(msgRet.finalReward[j], itemID, itemCnt)
  109. end
  110. HeroGrid.makeHeroSimpleByID(msgRet.hero, fconfig.reward[1][1])
  111. msgRet.finalState = getState(human, KING_TYPE_4)
  112. Msg.send(msgRet, human.fd)
  113. end
  114. -- 领奖
  115. function getReward(human, id, mail)
  116. if not isOpen(human) then return end
  117. local cf = OpenServerExcel.kingWorld[id]
  118. if not cf then return end
  119. -- 不在这个界面领取
  120. if id ~= KING_TYPE_4 then
  121. return
  122. end
  123. local status = getState(human, id)
  124. if status ~= STATE_FINISH then return end
  125. human.db.kingworld = human.db.kingworld or {}
  126. -- 标识状态
  127. human.db.kingworld[id] = human.db.kingworld[id] or {}
  128. human.db.kingworld[id].status = STATE_GET
  129. if not mail then
  130. BagLogic.addItemList(human, cf.reward, "kingworld")
  131. else
  132. mailReward(human, id, 1012)
  133. end
  134. for k, v in pairs(funcID) do
  135. YunYingLogic.updateIcon(YYInfo[k], human)
  136. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3603)
  137. break
  138. end
  139. query(human)
  140. end
  141. -- 获取当前进度
  142. function canFinish(human, id)
  143. if id ~= KING_TYPE_4 then
  144. local cf = OpenServerExcel.kingWorld[id]
  145. local config = ChengjiuExcel[cf.chengJiuID]
  146. if human.db.chengjiu.type and human.db.chengjiu.type[config.type] then
  147. if human.db.chengjiu.task and human.db.chengjiu.task[cf.chengJiuID] and human.db.chengjiu.task[cf.chengJiuID] == STATE_GET then
  148. return true
  149. end
  150. end
  151. return false
  152. else
  153. return isFinishAll(human)
  154. end
  155. end
  156. -- 是否领取
  157. function getState(human, id)
  158. local cf = OpenServerExcel.kingWorld[id]
  159. if not cf then return end
  160. if id == KING_TYPE_4 then
  161. local state = isFinishAll(human)
  162. if not state then
  163. return STATE_NONE
  164. end
  165. if not human.db.kingworld then return STATE_FINISH end
  166. if human.db.kingworld[id] and human.db.kingworld[id].status == STATE_GET then
  167. return STATE_GET
  168. else
  169. return STATE_FINISH
  170. end
  171. end
  172. --[[
  173. if human.db.kingworld[id].status == STATE_NONE then
  174. if canFinish(human, id) then
  175. return STATE_FINISH
  176. end
  177. return STATE_NONE
  178. end
  179. return human.db.kingworld[id].status
  180. ]]
  181. end
  182. function setState(human,id)
  183. if not isOpen(human) then return end
  184. initDB(human)
  185. human.db.kingworld[id].status = STATE_GET
  186. for k, v in pairs(funcID) do
  187. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3603)
  188. break
  189. end
  190. end
  191. -- 1-3都完成
  192. function isFinishAll(human)
  193. for i = 1, KING_TYPE_3 do
  194. if not canFinish(human, i) then
  195. return
  196. end
  197. end
  198. return true
  199. end
  200. function updateDaily(human)
  201. if not isOpen(human) then
  202. -- 活动结束推送没有领取的奖励
  203. if human.db.kingworld then
  204. for i = KING_TYPE_1, KING_TYPE_4 do
  205. getReward(human, i, true)
  206. end
  207. human.db.kingworld = nil
  208. end
  209. return
  210. end
  211. initDB(human)
  212. end
  213. function isRed(human)
  214. if not isOpen(human) then return end
  215. for i = KING_TYPE_1, KING_TYPE_4 do
  216. if getState(human, i) == STATE_FINISH then
  217. return true
  218. end
  219. end
  220. end