MonthCard.lua 8.5 KB

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