MonthCard.lua 9.6 KB

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