MonthCard.lua 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. local Util = require("common.Util")
  2. local ObjHuman = require("core.ObjHuman")
  3. local MonthCardExcel = require("excel.present").monthCard
  4. local Msg = require("core.Msg")
  5. local Grid = require("bag.Grid")
  6. local ItemDefine = require("bag.ItemDefine")
  7. local BuyLogic = require("topup.BuyLogic")
  8. local BagLogic = require("bag.BagLogic")
  9. local YunYingLogic = require("yunying.YunYingLogic")
  10. local PanelDefine = require("broadcast.PanelDefine")
  11. local YyHandler = require("yunying.Handler")
  12. local KingWorldLogic = require("present.KingWorldLogic")
  13. local HeroLogic = require("hero.HeroLogic")
  14. local TreasureChestLogic = require("treasurechest.TreasureChestLogic")
  15. local Log = require("common.Log")
  16. local CommonDefine = require("common.CommonDefine")
  17. local MONTH_CARD_STATE_0 = 0 -- 已过期
  18. local MONTH_CARD_STATE_1 = 1 -- 未过期
  19. local MONTH_CARD_STATE_2 = 2 -- 已领取
  20. local MONTH_CARD_FOREVER = 2 -- 永久卡ID
  21. local MONTHCHANEID_MUZI = 1 -- 木子渠道
  22. -- 写日志
  23. local function MonthCard_WriteLog(human, szText)
  24. if human then
  25. szText = szText.." name = "..human.db.name.." id = "..human.db._id
  26. end
  27. Log.write(Log.LOGID_OSS_COMMON, szText)
  28. end
  29. -- 获取配置
  30. local function MonthCard_GetConf(human)
  31. local nChanelID = human.db.phpChanelID
  32. if not nChanelID then
  33. nChanelID = human.phpChanelID
  34. end
  35. if not nChanelID then
  36. print("[MonthCard_GetConf] 不存在对应的渠道")
  37. return nil
  38. end
  39. print("[MonthCard_GetConf] 当前的nChanelID = "..nChanelID)
  40. local tConf = {}
  41. if CommonDefine.CHANNEL_TAG_MUZI == nChanelID or CommonDefine.CHANNEL_TAG_SANLI_QQ == nChanelID then
  42. table.insert(tConf, MonthCardExcel[11])
  43. table.insert(tConf, MonthCardExcel[12])
  44. else
  45. table.insert(tConf, MonthCardExcel[1])
  46. table.insert(tConf, MonthCardExcel[2])
  47. end
  48. return tConf
  49. end
  50. --- 功能修改 前 已经有不删档 服 开启 所以 DB 以原有的为标准 大体不去修改
  51. local function getState(monthCardDB)
  52. local now = os.time()
  53. if monthCardDB.endTime >= 0 and monthCardDB.endTime < now then
  54. return MONTH_CARD_STATE_0
  55. end
  56. if monthCardDB.getTime then
  57. if Util.isSameDay(monthCardDB.getTime) then
  58. return MONTH_CARD_STATE_2
  59. else
  60. return MONTH_CARD_STATE_1
  61. end
  62. else
  63. local day = Util.diffDay(monthCardDB.startTime) + 1
  64. if monthCardDB.endTime > 0 and day > monthCardDB.day then
  65. return MONTH_CARD_STATE_1
  66. elseif monthCardDB.endTime < 0 and not monthCardDB.getTime then
  67. return MONTH_CARD_STATE_1
  68. end
  69. end
  70. return MONTH_CARD_STATE_2
  71. end
  72. local function checkDB(human,id)
  73. local tMonthCardConf = MonthCard_GetConf(human)
  74. if not tMonthCardConf or not tMonthCardConf[id] then
  75. -- if not MonthCardExcel[id] then
  76. assert(nil,id)
  77. end
  78. human.db.monthCard = human.db.monthCard or {}
  79. human.db.monthCard[id] = human.db.monthCard[id] or {day = 0,startTime = 0,endTime = 0,money = 0, get = 0}
  80. local monthCardDB = human.db.monthCard[id]
  81. if monthCardDB.startTime > 0 and getState(monthCardDB) == 0 then
  82. human.db.monthCard[id] = {day = 0,startTime = 0,endTime = 0,money = 0, get = 0}
  83. end
  84. return human.db.monthCard[id]
  85. end
  86. -- -- 获取特权参数
  87. function getPowerArgs(human, powerType)
  88. -- 检查 是否开了 永久月卡
  89. local monthCardDB = checkDB(human, 2)
  90. if getState(monthCardDB) ~= MONTH_CARD_STATE_0 then
  91. local MonthCardConf = MonthCard_GetConf(human)
  92. if not MonthCardConf then
  93. return 0
  94. end
  95. local config = MonthCardConf[2]
  96. return config[powerType] or 0
  97. end
  98. local monthCardDB = checkDB(human, 1)
  99. if getState(monthCardDB) ~= MONTH_CARD_STATE_0 then
  100. local MonthCardConf = MonthCard_GetConf(human)
  101. if not MonthCardConf then
  102. return 0
  103. end
  104. local config = MonthCardConf[1]
  105. return config[powerType] or 0
  106. end
  107. return 0
  108. end
  109. function query(human)
  110. local len = 0
  111. local msgRet = Msg.gc.GC_MONTH_CARD_QUERY
  112. msgRet.jiacheng = 0
  113. msgRet.drawZhekou = 0
  114. msgRet.heroBagAdd = 0
  115. local tMonthCardConf = MonthCard_GetConf(human)
  116. if not tMonthCardConf then
  117. MonthCard_WriteLog(human, "[MonthCard_Query] 获取不到配置")
  118. return
  119. end
  120. for k, v in ipairs(tMonthCardConf) do
  121. local id = k
  122. len = len + 1
  123. local net = msgRet.list[len]
  124. local monthCardDB = checkDB(human,id)
  125. net.id = id
  126. net.name = v.name
  127. net.startTime = monthCardDB.startTime
  128. net.endTime = monthCardDB.endTime
  129. local day = Util.diffDay(monthCardDB.startTime) + 1
  130. net.day = v.day - day
  131. net.get = monthCardDB.get or 0
  132. net.state = getState(monthCardDB)
  133. Grid.makeItem(net.yuanbao,ItemDefine.ITEM_ZUANSHI_ID,v.yuanbao)
  134. Grid.makeItem(net.instantly,ItemDefine.ITEM_ZUANSHI_ID,v.instantly)
  135. -- Grid.makeItem(net.maxYuanbao,ItemDefine.ITEM_ZUANSHI_ID,v.yuanbao * v.day + v.instantly)
  136. BuyLogic.fontBuyItem(human, net.buyItem, v.buyID)
  137. msgRet.jiacheng = v[7]
  138. msgRet.drawZhekou = v[21]
  139. msgRet.heroBagAdd = v[12]
  140. end
  141. msgRet.list[0] = len
  142. Msg.send(msgRet,human.fd)
  143. end
  144. function get(human,id)
  145. local monthCardDB = checkDB(human,id)
  146. if getState(monthCardDB) ~= MONTH_CARD_STATE_1 then
  147. return
  148. end
  149. local tMonthCardConf = MonthCard_GetConf(human)
  150. if not tMonthCardConf then
  151. MonthCard_WriteLog(human, "[MonthCard_Get] 获取不到配置")
  152. return
  153. end
  154. local config = tMonthCardConf[id]
  155. -- local config = MonthCardExcel[id]
  156. local addYuanbao = config.yuanbao
  157. if config.day > 0 then
  158. monthCardDB.day = Util.diffDay(monthCardDB.startTime) + 1
  159. end
  160. monthCardDB.get = monthCardDB.get or 0
  161. monthCardDB.get = monthCardDB.get + 1
  162. monthCardDB.getTime = os.time()
  163. ObjHuman.addZuanshi(human,addYuanbao,"monthCard")
  164. BagLogic.sendItemGetList(human, {{ItemDefine.ITEM_ZUANSHI_ID,addYuanbao}}, "monthCard")
  165. local msgRet = Msg.gc.GC_MONTH_CARD_GET
  166. Msg.send(msgRet,human.fd)
  167. query(human)
  168. for k, v in pairs(funcID) do
  169. YunYingLogic.updateIcon(YYInfo[k], human)
  170. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3303)
  171. break
  172. end
  173. end
  174. function buyMonthCard(human,id)
  175. local monthCardDB = checkDB(human,id)
  176. if getState(monthCardDB) == MONTH_CARD_STATE_1 then
  177. return
  178. end
  179. local tMonthCardConf = MonthCard_GetConf(human)
  180. if not tMonthCardConf then
  181. MonthCard_WriteLog(human, "[MonthCard_buyMonthCard] 玩家购买月卡获取不到配置 id = "..id)
  182. return
  183. end
  184. local config = tMonthCardConf[id]
  185. -- local config = MonthCardExcel[id]
  186. local now = os.time()
  187. monthCardDB.startTime = Util.getDayStartTime(now)
  188. if config.day > 0 then
  189. monthCardDB.endTime = monthCardDB.startTime + config.day * 86400
  190. else
  191. monthCardDB.endTime = -1
  192. end
  193. ObjHuman.addZuanshi(human,config.instantly,"monthCard")
  194. BagLogic.sendItemGetList(human, {{ItemDefine.ITEM_ZUANSHI_ID,config.instantly}}, "monthCard")
  195. --YunYingLogic.updateIcon(KingWorldLogic.YYInfo, human)
  196. for k, v in pairs(KingWorldLogic.funcID) do
  197. YunYingLogic.updateIcon(KingWorldLogic.YYInfo[k], human)
  198. break
  199. end
  200. query(human)
  201. if monthCardDB.endTime == -1 then
  202. HeroLogic.sendHeroBagCap(human)
  203. end
  204. if MONTH_CARD_FOREVER == id then
  205. TreasureChestLogic.TreasureChestLogic_BuyOpenAuto(human)
  206. end
  207. end
  208. -- 是否购买
  209. function isActive(human, YYInfo, funcConfig)
  210. local monthCardDB = checkDB(human, 1)
  211. if getState(monthCardDB) == MONTH_CARD_STATE_0 then
  212. return
  213. end
  214. monthCardDB = checkDB(human, 2)
  215. if getState(monthCardDB) == MONTH_CARD_STATE_0 then
  216. return
  217. end
  218. return true
  219. end
  220. function isRed(human, YYInfo, funcConfig)
  221. local monthCardDB = checkDB(human,2)
  222. if getState(monthCardDB) ~= MONTH_CARD_STATE_0 then
  223. print("[MonthCard-isRed] 未过期 name = "..human.db.name)
  224. TreasureChestLogic.TreasureChestLogic_BuyOpenAuto(human)
  225. end
  226. if getState(monthCardDB) == MONTH_CARD_STATE_1 then
  227. return true
  228. end
  229. monthCardDB = checkDB(human,1)
  230. if getState(monthCardDB) == MONTH_CARD_STATE_1 then
  231. return true
  232. end
  233. return
  234. end