UIMonthCardInfo.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. ---@class UIMonthCardInfo
  2. ---@field IsGetMonthCard boolean
  3. ---@field IsGetDailyCard boolean
  4. UIMonthCardInfo = class()
  5. local this = UIMonthCardInfo
  6. function this:ctor()
  7. end
  8. function this:Reset()
  9. ---月卡会包含日卡权益 单买日卡不包含月卡权益 先买月卡再买日卡会直接加月卡天数
  10. self.IsGetMonthCard = false--是否开启了月卡
  11. self.IsGetDailyCard = false--是否开启了日卡
  12. self.MonthCardBuyCount = 0 --月卡购买次数
  13. self.DailyCardBuyCount = 0 --日卡购买次数
  14. self.MonthCardTime = 0 ---月卡时间
  15. self.DailyCardTime = 0 ---日卡时间
  16. self.IsFirstBuyMonthCard = true
  17. self.IsFirstBuyDailyCard = true
  18. self.MonthCardTimeTotal = 0 ---月卡总时间 先开月卡再开日卡时间会叠加(服务器处理)
  19. self.ThreeTime = 0 --三倍收益时间
  20. self.IsEarningFirst = false --三倍效益界面是否首次打开
  21. self.ToDayThreeTimeIsGet = false ---今天是否领取了三倍收益
  22. self.IsShowActivePanel = false
  23. self.MonthCardTbl = SL:GetConfigTable("cfg_monthlyPass")
  24. if self.coHide ~= nil then
  25. Coroutine.Stop(self.coHide)
  26. end
  27. end
  28. function this:Init()
  29. self:InitData()
  30. self:RegistMessages()
  31. self:Reset()
  32. end
  33. function this:InitData()
  34. end
  35. function this:RegistMessages()
  36. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_GET_MONTHCARD_INFO, self.RES_GET_MONTHCARD_INFO, self)-- 响应获取月卡信息
  37. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_MONTHCARD_CHANGE_INFO, self.RES_MONTHCARD_CHANGE_INFO, self)-- 响应月卡变化信息
  38. SL:RegisterLUAEvent(LUA_EVENT_ROLE_LOGIN, self.EnterGame, self)
  39. --SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_MONTHCARD_OVERTIME , self.RES_MONTHCARD_OVERTIME , self) --响应月卡过期提示
  40. SL:RegisterLUAEvent(MESSAGE_ACCEPT, self.DataProcessing, self)
  41. end
  42. function this:DataProcessing(_, message)
  43. if message then
  44. if message.id == 31 then
  45. if message.params[1] == SL:GetConfig("cfg_item", self:GetMonthCardTblData().id).name then
  46. if self.coHide ~= nil then
  47. Coroutine.Stop(self.coHide)
  48. end
  49. GUI:UIPanel_Open("dev/outui/MonthCard/Panel/KLMonthCardActiveEffect/KLMonthCardActiveEffectPanel", nil, nil, { cfgId = self:GetMonthCardTblData().id })
  50. self.coHide = Coroutine.Start(
  51. function()
  52. Coroutine.Wait(2)
  53. GUI:UIPanel_Close("dev/outui/MonthCard/Panel/KLMonthCardActiveEffect/KLMonthCardActiveEffectPanel")
  54. end
  55. )
  56. end
  57. if message.params[1] == SL:GetConfig("cfg_item", self:GetDailyCardTblData().id).name then
  58. if self.coHide ~= nil then
  59. Coroutine.Stop(self.coHide)
  60. end
  61. GUI:UIPanel_Open("dev/outui/MonthCard/Panel/KLMonthCardActiveEffect/KLMonthCardActiveEffectPanel", nil, nil, { cfgId = self:GetDailyCardTblData().id })
  62. self.coHide = Coroutine.Start(
  63. function()
  64. Coroutine.Wait(2)
  65. GUI:UIPanel_Close("dev/outui/MonthCard/Panel/KLMonthCardActiveEffect/KLMonthCardActiveEffectPanel")
  66. end
  67. )
  68. end
  69. end
  70. end
  71. end
  72. function this:EnterGame()
  73. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_GET_MONTHCARD_INFO)
  74. end
  75. ---@param message RES_GET_MONTHCARD_INFO
  76. function this:RES_GET_MONTHCARD_INFO(_, message)
  77. if message then
  78. self.IsGetMonthCard = false--是否开启了月卡
  79. self.IsGetDailyCard = false--是否开启了日卡
  80. self.MonthCardTimeTotal = 0
  81. self.ThreeTime = tonumber(message.threetime)
  82. self.ToDayThreeTimeIsGet = self:StringToBoolean(message.todayreceivethreetime)
  83. local MonthCardData = message[tostring(EMonthType.MonthCard)]
  84. if MonthCardData then
  85. --月卡
  86. self.MonthCardBuyCount = tonumber(MonthCardData.buycount)
  87. self.MonthCardTime = math.modf(tonumber(MonthCardData.vaildTime))
  88. self.IsGetMonthCard = self:StringToBoolean(MonthCardData.isopen)
  89. self.IsFirstBuyMonthCard = self:StringToBoolean(MonthCardData.isfirstbuy)
  90. end
  91. local DailyCardData = message[tostring(EMonthType.DailyCard)]
  92. if DailyCardData then
  93. --日卡
  94. self.DailyCardBuyCount = tonumber(DailyCardData.buycount)
  95. self.DailyCardTime = math.modf(tonumber(DailyCardData.vaildTime))
  96. self.IsGetDailyCard = self:StringToBoolean(DailyCardData.isopen)
  97. self.IsFirstBuyDailyCard = self:StringToBoolean(DailyCardData.isfirstbuy)
  98. end
  99. --[[ if self.MonthCardTime >= SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME) then
  100. self.IsGetMonthCard = true
  101. end
  102. if self.DailyCardTime >= SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME) then
  103. self.IsGetDailyCard = true
  104. end
  105. if self.IsGetMonthCard then
  106. self.IsGetDailyCard = false
  107. end]]
  108. if self.MonthCardTime > self.DailyCardTime then
  109. self.MonthCardTimeTotal = self.MonthCardTime
  110. else
  111. self.MonthCardTimeTotal = self.DailyCardTime
  112. end
  113. if self.IsGetMonthCard or self.IsGetDailyCard then
  114. self.IsShowActivePanel = false
  115. else
  116. self.IsShowActivePanel = true
  117. end
  118. SL:onLUAEvent(LUA_EVENT_GET_MONTH_CARD_INFO, message)
  119. self:CheckPriviegeBoss()
  120. end
  121. end
  122. function this:RES_MONTHCARD_CHANGE_INFO(_, message)
  123. if message then
  124. if tonumber(message.cfgId) == EMonthType.MonthCard then
  125. self.MonthCardBuyCount = tonumber(message.buycount)
  126. self.MonthCardTime = math.modf(tonumber(message.vaildTime))
  127. self.IsGetMonthCard = self:StringToBoolean(message.isopen)
  128. self.IsFirstBuyMonthCard = self:StringToBoolean(message.isfirstbuy)
  129. end
  130. if tonumber(message.cfgId) == EMonthType.DailyCard then
  131. self.DailyCardBuyCount = tonumber(message.buycount)
  132. self.DailyCardTime = math.modf(tonumber(message.vaildTime))
  133. self.IsGetDailyCard = self:StringToBoolean(message.isopen)
  134. self.IsFirstBuyDailyCard = self:StringToBoolean(message.isfirstbuy)
  135. end
  136. if self.MonthCardTime > self.DailyCardTime then
  137. self.MonthCardTimeTotal = self.MonthCardTime
  138. else
  139. self.MonthCardTimeTotal = self.DailyCardTime
  140. end
  141. SL:onLUAEvent(LUA_EVENT_GET_MONTH_CARD_CHANGE, message)
  142. self:CheckPriviegeBoss()
  143. ---刷新自动拾取勾选显示
  144. if InfoManager.monthCardInfo:IsHaveMonthCardRights("pickUp") then
  145. SL:SendPlayerAutoPickChange(true)
  146. end
  147. if InfoManager.monthCardInfo:IsHaveMonthCardRights("recovery") then
  148. SL:SendPlayerAutoRecoverChange(true)
  149. end
  150. end
  151. end
  152. function this:StringToBoolean(value)
  153. if value == "true" then
  154. return true
  155. else
  156. return false
  157. end
  158. end
  159. ---是否需要月卡和日卡功能
  160. ---@param Name string @表字段名字
  161. function this:IsNeedMonthAndDailyCard(Name)
  162. local IsNeedMonthCard = false
  163. local IsNeedDailyCard = false
  164. for _, v in pairs(self.MonthCardTbl) do
  165. if v.id == EMonthType.MonthCard and v[Name] == 1 then
  166. IsNeedMonthCard = true
  167. end
  168. if v.id == EMonthType.DailyCard and v[Name] == 1 then
  169. IsNeedDailyCard = true
  170. end
  171. end
  172. return IsNeedMonthCard, IsNeedMonthCard
  173. end
  174. ---是否需要显示按钮
  175. ---@param Name string @表字段名字
  176. function this:IsNeedShowPanel(Name)
  177. for _, v in pairs(self.MonthCardTbl) do
  178. if v[Name] == 1 then
  179. return true
  180. end
  181. end
  182. return false
  183. end
  184. ---获得月卡数据
  185. ---@return cfg_monthlyPass_column
  186. function this:GetMonthCardTblData()
  187. for _, v in pairs(self.MonthCardTbl) do
  188. if v.id == EMonthType.MonthCard then
  189. v.price = self:GetRechargeMonthCard(v.id).amount
  190. return v
  191. end
  192. end
  193. return nil
  194. end
  195. ---获得日卡数据
  196. ---@return cfg_monthlyPass_column
  197. function this:GetDailyCardTblData()
  198. for _, v in pairs(self.MonthCardTbl) do
  199. if v.id == EMonthType.DailyCard then
  200. v.price = self:GetRechargeMonthCard(v.id).amount
  201. return v
  202. end
  203. end
  204. return nil
  205. end
  206. function this:GetRechargeMonthCard(TblId)
  207. local tbl= SL:GetConfigTable("cfg_recharge")
  208. for _,v in pairs(tbl) do
  209. if v.type == ERechargeType.MonthCardType and v.parameter == TblId then
  210. --v.amount = 0.01
  211. return v
  212. end
  213. end
  214. end
  215. ---判断月卡日卡是否激活并且有该权益
  216. ----@param value string @查月卡表获得
  217. function this:IsHaveMonthCardRights(value)
  218. local IsNeedMonthCard, IsNeedDailyCard = self:IsNeedMonthAndDailyCard(value)
  219. if IsNeedMonthCard and self.IsGetMonthCard then
  220. return true
  221. end
  222. if IsNeedDailyCard and self.IsGetDailyCard then
  223. return true
  224. end
  225. if not IsNeedMonthCard and not IsNeedDailyCard then
  226. ---两个卡都不控制权益 默认为true
  227. return true
  228. end
  229. return false
  230. end
  231. ---判断月卡时间是否小于1天
  232. function this:IsHaveDayTime()
  233. local reTime = 0
  234. if self.MonthCardTimeTotal ~= nil then
  235. reTime = self.MonthCardTimeTotal - SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME)
  236. end
  237. if reTime > 0 and reTime <= 86400000 then
  238. return true
  239. end
  240. return false
  241. end
  242. function this:CheckPriviegeBoss()
  243. if self.IsGetMonthCard then
  244. self:SendPriviegeBoss(3)
  245. end
  246. if self.IsGetDailyCard then
  247. self:SendPriviegeBoss(4)
  248. end
  249. end
  250. ---通知特权boss
  251. ---@param value number @活动类型 1—黄金特权卡 2—钻石特权卡 3—月卡 4-日卡
  252. function this:SendPriviegeBoss(value)
  253. SL:SendLuaNetMsg(LuaMessageIdToSever.PRIVILEGE_BOSS_COUNT_INIT, value)
  254. end
  255. ---@获得月卡剩余天数
  256. function this:GetMonthCardDayTime()
  257. local day = (InfoManager.monthCardInfo.MonthCardTimeTotal - SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME)) // 86400000
  258. if day > 0 then
  259. return day
  260. end
  261. return 0
  262. end
  263. ---月卡是否能进背包
  264. function this:CanInBag()
  265. local MonthCardTbl = self:GetMonthCardTblData()
  266. if SL:CanPutToBag(MonthCardTbl.id, 1) then
  267. return true
  268. end
  269. local DailyCardTbl = self:GetDailyCardTblData()
  270. if SL:CanPutToBag(DailyCardTbl.id, 1) then
  271. return true
  272. end
  273. return false
  274. end
  275. ----是否是交易行bantype
  276. function this:IsBanType(type, subtype, isMonthCard)
  277. if isMonthCard then
  278. for _, v in pairs(self:GetMonthCardTblData().banType) do
  279. if v[1] == type and v[2] == subtype then
  280. return true
  281. end
  282. end
  283. else
  284. for _, v in pairs(self:GetDailyCardTblData().banType) do
  285. if v[1] == type and v[2] == subtype then
  286. return true
  287. end
  288. end
  289. end
  290. return false
  291. end