-- <* -- @Author: Saber -- @Description: 招财猫活动model -- *> FortuneCatModel = FortuneCatModel or BaseClass(BaseVo, true) FortuneCatModel.REQUEST_CCMD_EVENT = "FortuneCatModel.REQUEST_CCMD_EVENT" -- 请求协议 FortuneCatModel.OPEN_FORTUNE_CAT_VIEW = "FortuneCatModel.OPEN_FORTUNE_CAT_VIEW" -- 打开招财猫主界面 FortuneCatModel.UPDATE_FORTUNE_CAT_CONFIG = "FortuneCatModel.UPDATE_FORTUNE_CAT_CONFIG" -- 更新协议返回的活动配置 FortuneCatModel.UPDATE_FORTUNE_CAT_ROLL_TIME = "FortuneCatModel.UPDATE_FORTUNE_CAT_ROLL_TIME" -- 更新招财猫活动信息 FortuneCatModel.UPDATE_FORTUNE_CAT_RESULT = "FortuneCatModel.UPDATE_FORTUNE_CAT_RESULT" -- 更新招财猫抽奖结果 FortuneCatModel.UPDATE_FORTUNE_CAT_ROLL_RECORD = "FortuneCatModel.UPDATE_FORTUNE_CAT_ROLL_RECORD" -- 更新招财猫服务器抽奖记录信息 FortuneCatModel.OPEN_FORTUNE_CAT_AD_VIEW = "FortuneCatModel.OPEN_FORTUNE_CAT_AD_VIEW" -- 打开招财猫广告界面 FortuneCatModel.AnimRollTime = 8 -- 抽奖动画中旋转圈数 FortuneCatModel.AnimTime = 10 -- 抽奖动画持续时间 FortuneCatModel.AnimAmountDiv = 0.2 -- 动画快慢速阈值(0~1),数值越大,旋转加速动画区间越大 FortuneCatModel.RecordAnimDuration = 6 -- 抽奖记录滚动间隔(秒) local FortuneCatModel = FortuneCatModel function FortuneCatModel:__init() FortuneCatModel.Instance = self self:Reset() end function FortuneCatModel:Reset() self.fortune_cat_cfg = nil -- 招财猫活动配置信息 self.fc_roll_time = {} -- 招财猫活动抽奖信息 格式为[活动主类型][活动子类型] = 次数 self.fc_roll_result = {} -- 招财猫活动信息抽奖结果缓存 self.fc_roll_record = {} -- 招财猫活动服务器抽奖记录信息 self.fc_red_cache = {} -- 招财猫红点缓存 -- 广告界面 self.fc_login_ad_view_flag = false -- 本次登录是否已经检测过广告界面的弹出 -- 跳过动画 self._skip_anim_cache = false -- 限制票字 self._is_fc_view_open = false end function FortuneCatModel:getInstance() if self.Instance == nil then self.Instance = FortuneCatModel.New() end return self.Instance end -- 协议部分 -- 通过协议设置活动配置缓存 33219 function FortuneCatModel:SetFortuneCatConfig(vo) if not vo then return end self.fortune_cat_cfg = {} local temp_tb1, temp_tb2 for k, v in ipairs(vo.cfglist) do self.fortune_cat_cfg[v.base_type] = self.fortune_cat_cfg[v.base_type] or {} self.fortune_cat_cfg[v.base_type][v.sub_type] = self.fortune_cat_cfg[v.base_type][v.sub_type] or {} -- 对抽奖次数配置和档位倍率配置进行重新排序,用对应的值作为键值 temp_tb1 = {} for k2, v2 in ipairs(v.confs) do temp_tb1[v2.times] = v2 end v.confs = temp_tb1 -- temp_tb2 = {} -- for k2, v2 in ipairs(v.rebacks) do -- temp_tb2[v2.sort] = v2 -- end -- v.rebacks_sorted = temp_tb2 self.fortune_cat_cfg[v.base_type][v.sub_type] = v end end function FortuneCatModel:GetFortuneCatConfig(base_type, sub_type) if not sub_type then return nil end base_type = base_type or CustomActivityModel.CustomActBaseType.FORTUNE_CAT if self.fortune_cat_cfg then return self.fortune_cat_cfg[base_type] and self.fortune_cat_cfg[base_type][sub_type] or nil else -- 如果没有数据则要及时请求33219 self:Fire(FortuneCatModel.REQUEST_CCMD_EVENT, 33219) end return nil end -- 缓存单个招财猫活动的已抽奖次数信息 33220 function FortuneCatModel:SetFortuneCatRollTimes(vo) if not vo then return end self.fc_roll_time[vo.base_type] = self.fc_roll_time[vo.base_type] or {} self.fc_roll_time[vo.base_type][vo.sub_type] = self.fc_roll_time[vo.base_type][vo.sub_type] or {} self.fc_roll_time[vo.base_type][vo.sub_type].times = vo.times -- 这么写是因为33221抽奖协议不会把累充发过来 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 self.fc_login_ad_view_flag = CookieWrapper.Instance:GetCookie(CookieLevelType.Account, CookieKey.FORTUNECAT_AD_HAS_SHOWN) or false -- 添加活动按钮 self:CheckEventOpen(vo.base_type, vo.sub_type) end function FortuneCatModel:GetFortuneCatRollTimes(base_type, sub_type) base_type = base_type or CustomActivityModel.CustomActBaseType.FORTUNE_CAT if sub_type then return self.fc_roll_time[base_type] and self.fc_roll_time[base_type][sub_type] or nil else return self.fc_roll_time[base_type] end end -- 缓存招财猫抽奖结果 33221 function FortuneCatModel:SetFortuneCatRollResult(vo) if not vo then return end -- 更新抽奖次数 self:SetFortuneCatRollTimes(vo) self.fc_roll_result[vo.base_type] = self.fc_roll_result[vo.base_type] or {} self.fc_roll_result[vo.base_type][vo.sub_type] = self.fc_roll_result[vo.base_type][vo.sub_type] or {} self.fc_roll_result[vo.base_type][vo.sub_type].sort = vo.sort self.fc_roll_result[vo.base_type][vo.sub_type].mult = vo.mult end function FortuneCatModel:GetFortuneCatRollResult(base_type, sub_type) base_type = base_type or CustomActivityModel.CustomActBaseType.FORTUNE_CAT if sub_type then return self.fc_roll_result[base_type] and self.fc_roll_result[base_type][sub_type] or nil else return self.fc_roll_result[base_type] end end -- 插入玩家的抽奖信息 function FortuneCatModel:UpdateFortuneCatRollRecord(vo, info) self.fc_roll_record[vo.base_type] = self.fc_roll_record[vo.base_type] or {} self.fc_roll_record[vo.base_type][vo.sub_type] = self.fc_roll_record[vo.base_type][vo.sub_type] or {} table.insert(self.fc_roll_record[vo.base_type][vo.sub_type], 1, info) end -- 更新招财猫活动服务器抽奖记录信息 33222 function FortuneCatModel:SetFortuneCatRollRecord(vo) if not vo then return end self.fc_roll_record[vo.base_type] = self.fc_roll_record[vo.base_type] or {} self.fc_roll_record[vo.base_type][vo.sub_type] = vo.list end -- 获取招财记录信息 only_personal:只拿自己的记录 function FortuneCatModel:GetFortuneCatRollRecord(base_type, sub_type, only_personal) base_type = base_type or CustomActivityModel.CustomActBaseType.FORTUNE_CAT if sub_type then if only_personal then local data = self.fc_roll_record[base_type] and self.fc_roll_record[base_type][sub_type] or {} local role_id = RoleManager.Instance.mainRoleInfo.role_id local tb = {} for k, v in ipairs(data) do if v.role_id == role_id then tb[#tb+1] = v end end return tb else return self.fc_roll_record[base_type] and self.fc_roll_record[base_type][sub_type] or {} end else return {} end end -- 按钮控制相关 -- 检查主界面按钮是否开启 sub_type:传入时检查对应的子类型,不穿则遍历331返回的目标类型[64]的缓存活动表 function FortuneCatModel:CheckEventOpen(base_type, sub_type) if not GetModuleIsOpen(331, 64) then return end base_type = base_type or CustomActivityModel.CustomActBaseType.FORTUNE_CAT local function check_func(event_data) if event_data then local icon_sub_type_base = event_data.base_type*1000 if event_data.sub_type >= 10001 then icon_sub_type_base = event_data.base_type*100000 end if event_data.etime then local is_open = event_data.etime - TimeUtil:getServerTime() if is_open then -- ActivityIconManager:getInstance():addIcon(icon_sub_type_base + event_data.sub_type, event_data.etime - TimeUtil:getServerTime()) ActivityIconManager:getInstance():addIcon(icon_sub_type_base + event_data.sub_type, -1)--2021.8.2鸿杰说干掉彩钻星轮倒计时显示 else ActivityIconManager:getInstance():deleteIcon(icon_sub_type_base + event_data.sub_type) end else ActivityIconManager:getInstance():deleteIcon(icon_sub_type_base + event_data.sub_type) end end end -- 不存在子类型,就要获取目标活动的全部类型列表遍历 if not sub_type then local fc_event_all_list = CustomActivityModel:getInstance():getAllActListByBaseType(base_type) for k, v in pairs(fc_event_all_list) do check_func(v) end else local event_data = CustomActivityModel:getInstance():getActList(base_type, sub_type) if event_data then check_func(event_data) else--活动消失要删除图标 local icon_sub_type_base = base_type*1000 if sub_type >= 10001 then icon_sub_type_base = base_type*100000 end ActivityIconManager:getInstance():deleteIcon(icon_sub_type_base + sub_type) end end end -- 通过抽奖信息来构建奖励界面 function FortuneCatModel:ShowDrawRewardEffect(fc_cfg, target_id, roll_cost) if fc_cfg and target_id and roll_cost then local mult = 1 for k, v in pairs(fc_cfg.rebacks) do if v.sort == target_id then -- 后端配置倍率放大了100倍 mult = v.mult * 0.01 break end end -- 构造彩钻数据结构表,创建奖励界面 local data = {} data.award = { [1] = {1, 100000, math.floor(roll_cost * mult)} } data.col_num = 5 -- GlobalEventSystem:Fire(EventName.OPEN_COM_AWARD_RESULT_VIEW, data) GiftModel:getInstance():Fire(GiftModel.OPEN_SHOW_ACT_GOODS_VIEW, data.award) --飘字 local goods_fly_data = { [1] = { goods_type_id = 100000, num = math.floor(roll_cost * mult), } } if TableSize(goods_fly_data) > 0 then MainUIModel:getInstance():AddFloatInfo(goods_fly_data, true) end end end -- 根据活动子类型和招财次数获取当次招财的钻石花费 function FortuneCatModel:GetDiamondCostBySubtypeAndTimes(sub_type, times) if not sub_type or not times then return nil end local cfg = self:GetFortuneCatConfig(nil, sub_type) if cfg then local cost for k, v in pairs(cfg.confs) do if v.times == times then return v.cost end end end return nil end -- 红点相关 -- 检测所有子类型的红点 (目前主要用于彩钻数据更新后刷新红点,由外部定时刷新,不要单独调用) function FortuneCatModel:CheckFCAllSubTypeRed( ) local fc_event_all_list = CustomActivityModel:getInstance():getAllActListByBaseType(CustomActivityModel.CustomActBaseType.FORTUNE_CAT) if fc_event_all_list then for k, v in pairs(fc_event_all_list) do self:CheckFortuneCatRed(v.sub_type) end end end function FortuneCatModel:CheckFortuneCatRed(sub_type) if not sub_type then return end local base_type = CustomActivityModel.CustomActBaseType.FORTUNE_CAT -- 招财数据和招财配置 local fc_data = self:GetFortuneCatRollTimes(base_type, sub_type) local fc_cfg = self:GetFortuneCatConfig(base_type, sub_type) if not fc_data or not fc_cfg then self.fc_red_cache[sub_type] = false return end local times = fc_data.times or 0 local recharge = fc_data.recharge or 0 -- 先判断是否已经抽完了 local is_finished = fc_cfg.max_times <= times -- 这个次数是已抽次数,前端获取配置时要+1 local roll_time = is_finished and fc_data.times or fc_data.times + 1 -- 计算出当前充值额度下还有几次转盘次数 local left_roll_time = 0 local cost = nil -- 只保存最近一档的转盘花费 if not is_finished then for i = roll_time, fc_cfg.max_times do if recharge >= fc_cfg.confs[i].recharge then left_roll_time = left_roll_time + 1 cost = cost or fc_cfg.confs[i].cost else break end end end local jin = RoleManager.Instance.mainRoleInfo.jin local login_red_list = self:GetFortuneCatLoginCookie()--每日登陆红点 if left_roll_time <= 0 and not login_red_list[sub_type] then -- 如果次数用完且还有登录红点,就干掉登录红点 self:SetFortuneCatLoginCookie(sub_type) end local bool = left_roll_time > 0 and (cost and cost <= jin) or not login_red_list[sub_type] self.fc_red_cache[sub_type] = bool -- 更新到主界面按钮上 local icon_sub_type_base = base_type*1000 if sub_type >= 10001 then icon_sub_type_base = base_type*100000 end GlobalEventSystem:Fire(ActivityIconManager.UPDATE_ICON_TIPS, icon_sub_type_base + sub_type, bool) -- self:CheckAdViewOpen()--取消主动弹广告改为任务弹 end function FortuneCatModel:GetFortuneCatRedCache(sub_type) return sub_type and self.fc_red_cache[sub_type] or false end -- 进入活动界面之后就干掉外部红点 function FortuneCatModel:ShutDownFcLoginRed(sub_type) self:SetFortuneCatLoginCookie(sub_type) self:CheckFortuneCatRed(sub_type) end function FortuneCatModel:CheckAdViewOpen( ) local lv = RoleManager.Instance.mainRoleInfo.level local can_show = Config.Modulesub["331@64"].icon_lv <= lv -- 打开广告界面 if not self.fc_login_ad_view_flag and can_show then local event_data = CustomActivityModel:getInstance():getActList(CustomActivityModel.CustomActBaseType.FORTUNE_CAT) if event_data and event_data.etime - TimeUtil:getServerTime() > 0 then local function delay_method( ) self:Fire(FortuneCatModel.OPEN_FORTUNE_CAT_AD_VIEW, true, event_data.sub_type) end setTimeout(delay_method, 1) end end end -- 设置广告界面检测状态 function FortuneCatModel:SetFcAdViewOpenFlag( ) CookieWrapper.Instance:SaveCookie(CookieLevelType.Account, CookieTimeType.TYPE_ALWAYS, CookieKey.FORTUNECAT_AD_HAS_SHOWN, true) CookieWrapper.Instance:WriteAll() self.fc_login_ad_view_flag = true end function FortuneCatModel:GetGoodsCanFly( ) return self._is_fc_view_open end --设置招财猫每日登陆红点cookie function FortuneCatModel:SetFortuneCatLoginCookie( sub_type ) local list = self:GetFortuneCatLoginCookie() or {} list[sub_type] = true CookieWrapper.Instance:SaveCookie(CookieLevelType.Account,CookieTimeType.TYPE_DAY2,CookieKey.FORTUNE_CAT_LOGIN_RED,list) CookieWrapper.Instance:WriteAll() end --获得招财猫每日登陆红点cookie function FortuneCatModel:GetFortuneCatLoginCookie( ) local bool = CookieWrapper.Instance:GetCookie(CookieLevelType.Account,CookieKey.FORTUNE_CAT_LOGIN_RED) or {} return bool end