源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

357 行
15 KiB

  1. -- <*
  2. -- @Author: Saber
  3. -- @Description: 招财猫活动model
  4. -- *>
  5. FortuneCatModel = FortuneCatModel or BaseClass(BaseVo, true)
  6. FortuneCatModel.REQUEST_CCMD_EVENT = "FortuneCatModel.REQUEST_CCMD_EVENT" -- 请求协议
  7. FortuneCatModel.OPEN_FORTUNE_CAT_VIEW = "FortuneCatModel.OPEN_FORTUNE_CAT_VIEW" -- 打开招财猫主界面
  8. FortuneCatModel.UPDATE_FORTUNE_CAT_CONFIG = "FortuneCatModel.UPDATE_FORTUNE_CAT_CONFIG" -- 更新协议返回的活动配置
  9. FortuneCatModel.UPDATE_FORTUNE_CAT_ROLL_TIME = "FortuneCatModel.UPDATE_FORTUNE_CAT_ROLL_TIME" -- 更新招财猫活动信息
  10. FortuneCatModel.UPDATE_FORTUNE_CAT_RESULT = "FortuneCatModel.UPDATE_FORTUNE_CAT_RESULT" -- 更新招财猫抽奖结果
  11. FortuneCatModel.UPDATE_FORTUNE_CAT_ROLL_RECORD = "FortuneCatModel.UPDATE_FORTUNE_CAT_ROLL_RECORD" -- 更新招财猫服务器抽奖记录信息
  12. FortuneCatModel.OPEN_FORTUNE_CAT_AD_VIEW = "FortuneCatModel.OPEN_FORTUNE_CAT_AD_VIEW" -- 打开招财猫广告界面
  13. FortuneCatModel.AnimRollTime = 8 -- 抽奖动画中旋转圈数
  14. FortuneCatModel.AnimTime = 10 -- 抽奖动画持续时间
  15. FortuneCatModel.AnimAmountDiv = 0.2 -- 动画快慢速阈值(0~1),数值越大,旋转加速动画区间越大
  16. FortuneCatModel.RecordAnimDuration = 6 -- 抽奖记录滚动间隔(秒)
  17. local FortuneCatModel = FortuneCatModel
  18. function FortuneCatModel:__init()
  19. FortuneCatModel.Instance = self
  20. self:Reset()
  21. end
  22. function FortuneCatModel:Reset()
  23. self.fortune_cat_cfg = nil -- 招财猫活动配置信息
  24. self.fc_roll_time = {} -- 招财猫活动抽奖信息 格式为[活动主类型][活动子类型] = 次数
  25. self.fc_roll_result = {} -- 招财猫活动信息抽奖结果缓存
  26. self.fc_roll_record = {} -- 招财猫活动服务器抽奖记录信息
  27. self.fc_red_cache = {} -- 招财猫红点缓存
  28. -- 广告界面
  29. self.fc_login_ad_view_flag = false -- 本次登录是否已经检测过广告界面的弹出
  30. -- 跳过动画
  31. self._skip_anim_cache = false
  32. -- 限制票字
  33. self._is_fc_view_open = false
  34. end
  35. function FortuneCatModel:getInstance()
  36. if self.Instance == nil then
  37. self.Instance = FortuneCatModel.New()
  38. end
  39. return self.Instance
  40. end
  41. -- 协议部分
  42. -- 通过协议设置活动配置缓存 33219
  43. function FortuneCatModel:SetFortuneCatConfig(vo)
  44. if not vo then return end
  45. self.fortune_cat_cfg = {}
  46. local temp_tb1, temp_tb2
  47. for k, v in ipairs(vo.cfglist) do
  48. self.fortune_cat_cfg[v.base_type] = self.fortune_cat_cfg[v.base_type] or {}
  49. self.fortune_cat_cfg[v.base_type][v.sub_type] = self.fortune_cat_cfg[v.base_type][v.sub_type] or {}
  50. -- 对抽奖次数配置和档位倍率配置进行重新排序,用对应的值作为键值
  51. temp_tb1 = {}
  52. for k2, v2 in ipairs(v.confs) do
  53. temp_tb1[v2.times] = v2
  54. end
  55. v.confs = temp_tb1
  56. -- temp_tb2 = {}
  57. -- for k2, v2 in ipairs(v.rebacks) do
  58. -- temp_tb2[v2.sort] = v2
  59. -- end
  60. -- v.rebacks_sorted = temp_tb2
  61. self.fortune_cat_cfg[v.base_type][v.sub_type] = v
  62. end
  63. end
  64. function FortuneCatModel:GetFortuneCatConfig(base_type, sub_type)
  65. if not sub_type then return nil end
  66. base_type = base_type or CustomActivityModel.CustomActBaseType.FORTUNE_CAT
  67. if self.fortune_cat_cfg then
  68. return self.fortune_cat_cfg[base_type] and self.fortune_cat_cfg[base_type][sub_type] or nil
  69. else
  70. -- 如果没有数据则要及时请求33219
  71. self:Fire(FortuneCatModel.REQUEST_CCMD_EVENT, 33219)
  72. end
  73. return nil
  74. end
  75. -- 缓存单个招财猫活动的已抽奖次数信息 33220
  76. function FortuneCatModel:SetFortuneCatRollTimes(vo)
  77. if not vo then return end
  78. self.fc_roll_time[vo.base_type] = self.fc_roll_time[vo.base_type] or {}
  79. self.fc_roll_time[vo.base_type][vo.sub_type] = self.fc_roll_time[vo.base_type][vo.sub_type] or {}
  80. self.fc_roll_time[vo.base_type][vo.sub_type].times = vo.times
  81. -- 这么写是因为33221抽奖协议不会把累充发过来
  82. self.fc_roll_time[vo.base_type][vo.sub_type].recharge = vo.recharge or self.fc_roll_time[vo.base_type][vo.sub_type].recharge
  83. self.fc_login_ad_view_flag = CookieWrapper.Instance:GetCookie(CookieLevelType.Account, CookieKey.FORTUNECAT_AD_HAS_SHOWN) or false
  84. -- 添加活动按钮
  85. self:CheckEventOpen(vo.base_type, vo.sub_type)
  86. end
  87. function FortuneCatModel:GetFortuneCatRollTimes(base_type, sub_type)
  88. base_type = base_type or CustomActivityModel.CustomActBaseType.FORTUNE_CAT
  89. if sub_type then
  90. return self.fc_roll_time[base_type] and self.fc_roll_time[base_type][sub_type] or nil
  91. else
  92. return self.fc_roll_time[base_type]
  93. end
  94. end
  95. -- 缓存招财猫抽奖结果 33221
  96. function FortuneCatModel:SetFortuneCatRollResult(vo)
  97. if not vo then return end
  98. -- 更新抽奖次数
  99. self:SetFortuneCatRollTimes(vo)
  100. self.fc_roll_result[vo.base_type] = self.fc_roll_result[vo.base_type] or {}
  101. self.fc_roll_result[vo.base_type][vo.sub_type] = self.fc_roll_result[vo.base_type][vo.sub_type] or {}
  102. self.fc_roll_result[vo.base_type][vo.sub_type].sort = vo.sort
  103. self.fc_roll_result[vo.base_type][vo.sub_type].mult = vo.mult
  104. end
  105. function FortuneCatModel:GetFortuneCatRollResult(base_type, sub_type)
  106. base_type = base_type or CustomActivityModel.CustomActBaseType.FORTUNE_CAT
  107. if sub_type then
  108. return self.fc_roll_result[base_type] and self.fc_roll_result[base_type][sub_type] or nil
  109. else
  110. return self.fc_roll_result[base_type]
  111. end
  112. end
  113. -- 插入玩家的抽奖信息
  114. function FortuneCatModel:UpdateFortuneCatRollRecord(vo, info)
  115. self.fc_roll_record[vo.base_type] = self.fc_roll_record[vo.base_type] or {}
  116. self.fc_roll_record[vo.base_type][vo.sub_type] = self.fc_roll_record[vo.base_type][vo.sub_type] or {}
  117. table.insert(self.fc_roll_record[vo.base_type][vo.sub_type], 1, info)
  118. end
  119. -- 更新招财猫活动服务器抽奖记录信息 33222
  120. function FortuneCatModel:SetFortuneCatRollRecord(vo)
  121. if not vo then return end
  122. self.fc_roll_record[vo.base_type] = self.fc_roll_record[vo.base_type] or {}
  123. self.fc_roll_record[vo.base_type][vo.sub_type] = vo.list
  124. end
  125. -- 获取招财记录信息 only_personal:只拿自己的记录
  126. function FortuneCatModel:GetFortuneCatRollRecord(base_type, sub_type, only_personal)
  127. base_type = base_type or CustomActivityModel.CustomActBaseType.FORTUNE_CAT
  128. if sub_type then
  129. if only_personal then
  130. local data = self.fc_roll_record[base_type] and self.fc_roll_record[base_type][sub_type] or {}
  131. local role_id = RoleManager.Instance.mainRoleInfo.role_id
  132. local tb = {}
  133. for k, v in ipairs(data) do
  134. if v.role_id == role_id then
  135. tb[#tb+1] = v
  136. end
  137. end
  138. return tb
  139. else
  140. return self.fc_roll_record[base_type] and self.fc_roll_record[base_type][sub_type] or {}
  141. end
  142. else
  143. return {}
  144. end
  145. end
  146. -- 按钮控制相关
  147. -- 检查主界面按钮是否开启 sub_type:传入时检查对应的子类型,不穿则遍历331返回的目标类型[64]的缓存活动表
  148. function FortuneCatModel:CheckEventOpen(base_type, sub_type)
  149. if not GetModuleIsOpen(331, 64) then return end
  150. base_type = base_type or CustomActivityModel.CustomActBaseType.FORTUNE_CAT
  151. local function check_func(event_data)
  152. if event_data then
  153. local icon_sub_type_base = event_data.base_type*1000
  154. if event_data.sub_type >= 10001 then
  155. icon_sub_type_base = event_data.base_type*100000
  156. end
  157. if event_data.etime then
  158. local is_open = event_data.etime - TimeUtil:getServerTime()
  159. if is_open then
  160. -- ActivityIconManager:getInstance():addIcon(icon_sub_type_base + event_data.sub_type, event_data.etime - TimeUtil:getServerTime())
  161. ActivityIconManager:getInstance():addIcon(icon_sub_type_base + event_data.sub_type, -1)--2021.8.2鸿杰说干掉彩钻星轮倒计时显示
  162. else
  163. ActivityIconManager:getInstance():deleteIcon(icon_sub_type_base + event_data.sub_type)
  164. end
  165. else
  166. ActivityIconManager:getInstance():deleteIcon(icon_sub_type_base + event_data.sub_type)
  167. end
  168. end
  169. end
  170. -- 不存在子类型,就要获取目标活动的全部类型列表遍历
  171. if not sub_type then
  172. local fc_event_all_list = CustomActivityModel:getInstance():getAllActListByBaseType(base_type)
  173. for k, v in pairs(fc_event_all_list) do
  174. check_func(v)
  175. end
  176. else
  177. local event_data = CustomActivityModel:getInstance():getActList(base_type, sub_type)
  178. if event_data then
  179. check_func(event_data)
  180. else--活动消失要删除图标
  181. local icon_sub_type_base = base_type*1000
  182. if sub_type >= 10001 then
  183. icon_sub_type_base = base_type*100000
  184. end
  185. ActivityIconManager:getInstance():deleteIcon(icon_sub_type_base + sub_type)
  186. end
  187. end
  188. end
  189. -- 通过抽奖信息来构建奖励界面
  190. function FortuneCatModel:ShowDrawRewardEffect(fc_cfg, target_id, roll_cost)
  191. if fc_cfg and target_id and roll_cost then
  192. local mult = 1
  193. for k, v in pairs(fc_cfg.rebacks) do
  194. if v.sort == target_id then
  195. -- 后端配置倍率放大了100倍
  196. mult = v.mult * 0.01
  197. break
  198. end
  199. end
  200. -- 构造彩钻数据结构表,创建奖励界面
  201. local data = {}
  202. data.award = {
  203. [1] = {1, 100000, math.floor(roll_cost * mult)}
  204. }
  205. data.col_num = 5
  206. -- GlobalEventSystem:Fire(EventName.OPEN_COM_AWARD_RESULT_VIEW, data)
  207. GiftModel:getInstance():Fire(GiftModel.OPEN_SHOW_ACT_GOODS_VIEW, data.award)
  208. --飘字
  209. local goods_fly_data = {
  210. [1] = {
  211. goods_type_id = 100000,
  212. num = math.floor(roll_cost * mult),
  213. }
  214. }
  215. if TableSize(goods_fly_data) > 0 then
  216. MainUIModel:getInstance():AddFloatInfo(goods_fly_data, true)
  217. end
  218. end
  219. end
  220. -- 根据活动子类型和招财次数获取当次招财的钻石花费
  221. function FortuneCatModel:GetDiamondCostBySubtypeAndTimes(sub_type, times)
  222. if not sub_type or not times then return nil end
  223. local cfg = self:GetFortuneCatConfig(nil, sub_type)
  224. if cfg then
  225. local cost
  226. for k, v in pairs(cfg.confs) do
  227. if v.times == times then
  228. return v.cost
  229. end
  230. end
  231. end
  232. return nil
  233. end
  234. -- 红点相关
  235. -- 检测所有子类型的红点 (目前主要用于彩钻数据更新后刷新红点,由外部定时刷新,不要单独调用)
  236. function FortuneCatModel:CheckFCAllSubTypeRed( )
  237. local fc_event_all_list = CustomActivityModel:getInstance():getAllActListByBaseType(CustomActivityModel.CustomActBaseType.FORTUNE_CAT)
  238. if fc_event_all_list then
  239. for k, v in pairs(fc_event_all_list) do
  240. self:CheckFortuneCatRed(v.sub_type)
  241. end
  242. end
  243. end
  244. function FortuneCatModel:CheckFortuneCatRed(sub_type)
  245. if not sub_type then return end
  246. local base_type = CustomActivityModel.CustomActBaseType.FORTUNE_CAT
  247. -- 招财数据和招财配置
  248. local fc_data = self:GetFortuneCatRollTimes(base_type, sub_type)
  249. local fc_cfg = self:GetFortuneCatConfig(base_type, sub_type)
  250. if not fc_data or not fc_cfg then
  251. self.fc_red_cache[sub_type] = false
  252. return
  253. end
  254. local times = fc_data.times or 0
  255. local recharge = fc_data.recharge or 0
  256. -- 先判断是否已经抽完了
  257. local is_finished = fc_cfg.max_times <= times
  258. -- 这个次数是已抽次数,前端获取配置时要+1
  259. local roll_time = is_finished and fc_data.times or fc_data.times + 1
  260. -- 计算出当前充值额度下还有几次转盘次数
  261. local left_roll_time = 0
  262. local cost = nil -- 只保存最近一档的转盘花费
  263. if not is_finished then
  264. for i = roll_time, fc_cfg.max_times do
  265. if recharge >= fc_cfg.confs[i].recharge then
  266. left_roll_time = left_roll_time + 1
  267. cost = cost or fc_cfg.confs[i].cost
  268. else
  269. break
  270. end
  271. end
  272. end
  273. local jin = RoleManager.Instance.mainRoleInfo.jin
  274. local login_red_list = self:GetFortuneCatLoginCookie()--每日登陆红点
  275. if left_roll_time <= 0 and not login_red_list[sub_type] then -- 如果次数用完且还有登录红点,就干掉登录红点
  276. self:SetFortuneCatLoginCookie(sub_type)
  277. end
  278. local bool = left_roll_time > 0 and (cost and cost <= jin) or not login_red_list[sub_type]
  279. self.fc_red_cache[sub_type] = bool
  280. -- 更新到主界面按钮上
  281. local icon_sub_type_base = base_type*1000
  282. if sub_type >= 10001 then
  283. icon_sub_type_base = base_type*100000
  284. end
  285. GlobalEventSystem:Fire(ActivityIconManager.UPDATE_ICON_TIPS, icon_sub_type_base + sub_type, bool)
  286. -- self:CheckAdViewOpen()--取消主动弹广告改为任务弹
  287. end
  288. function FortuneCatModel:GetFortuneCatRedCache(sub_type)
  289. return sub_type and self.fc_red_cache[sub_type] or false
  290. end
  291. -- 进入活动界面之后就干掉外部红点
  292. function FortuneCatModel:ShutDownFcLoginRed(sub_type)
  293. self:SetFortuneCatLoginCookie(sub_type)
  294. self:CheckFortuneCatRed(sub_type)
  295. end
  296. function FortuneCatModel:CheckAdViewOpen( )
  297. local lv = RoleManager.Instance.mainRoleInfo.level
  298. local can_show = Config.Modulesub["331@64"].icon_lv <= lv
  299. -- 打开广告界面
  300. if not self.fc_login_ad_view_flag and can_show then
  301. local event_data = CustomActivityModel:getInstance():getActList(CustomActivityModel.CustomActBaseType.FORTUNE_CAT)
  302. if event_data and event_data.etime - TimeUtil:getServerTime() > 0 then
  303. local function delay_method( )
  304. self:Fire(FortuneCatModel.OPEN_FORTUNE_CAT_AD_VIEW, true, event_data.sub_type)
  305. end
  306. setTimeout(delay_method, 1)
  307. end
  308. end
  309. end
  310. -- 设置广告界面检测状态
  311. function FortuneCatModel:SetFcAdViewOpenFlag( )
  312. CookieWrapper.Instance:SaveCookie(CookieLevelType.Account, CookieTimeType.TYPE_ALWAYS, CookieKey.FORTUNECAT_AD_HAS_SHOWN, true)
  313. CookieWrapper.Instance:WriteAll()
  314. self.fc_login_ad_view_flag = true
  315. end
  316. function FortuneCatModel:GetGoodsCanFly( )
  317. return self._is_fc_view_open
  318. end
  319. --设置招财猫每日登陆红点cookie
  320. function FortuneCatModel:SetFortuneCatLoginCookie( sub_type )
  321. local list = self:GetFortuneCatLoginCookie() or {}
  322. list[sub_type] = true
  323. CookieWrapper.Instance:SaveCookie(CookieLevelType.Account,CookieTimeType.TYPE_DAY2,CookieKey.FORTUNE_CAT_LOGIN_RED,list)
  324. CookieWrapper.Instance:WriteAll()
  325. end
  326. --获得招财猫每日登陆红点cookie
  327. function FortuneCatModel:GetFortuneCatLoginCookie( )
  328. local bool = CookieWrapper.Instance:GetCookie(CookieLevelType.Account,CookieKey.FORTUNE_CAT_LOGIN_RED) or {}
  329. return bool
  330. end