MonthCard.lua 8.9 KB

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