|
|
- TreasureMapModel = TreasureMapModel or BaseClass(BaseVo, true)
- local TreasureMapModel = TreasureMapModel
-
- function TreasureMapModel:__init()
- TreasureMapModel.Instance = self
- self:Reset()
- end
-
- function TreasureMapModel:Reset()
- self.tm_red_cache = {} -- 红点缓存
- self.current_treasure_data = nil -- 当前的藏宝图信息
- self.tm_normal_times = 0 -- 今日普通藏宝图使用次数
- self.adv_tm_times_data = nil -- 高级藏宝图月度次数信息
- self.tm_shop_data = nil -- 藏宝图限时商城商品内容
- self.tm_shop_rest_data = nil -- 藏宝图限时商城剩余数量数据
- self.tm_storage_shop_data = {} -- 藏宝图限时商城收纳数据
-
- self.tm_shop_free_cfg = {} -- 藏宝图限时商城动态配置(免费商品)
- self.tm_kv_cfg = nil -- 藏宝图键值动态配置
- self.tm_mt_reward_cfg = nil -- 藏宝图月度次数奖励配置
- self.tm_shop_cfg = {} -- 藏宝图限时商城动态配置
- self.tm_reward_preview_cfg = {} -- 藏宝图奖励展示配置
-
- self._tm_can_fly_goods = true -- 是否可以有道具飘入表现
- self._check_tm_tips = false -- 是否检查藏宝图快捷使用tips,需要检查时该值为藏宝图类型
- end
-
- function TreasureMapModel:getInstance()
- if self.Instance == nil then
- self.Instance = TreasureMapModel.New()
- end
- return self.Instance
- end
-
- -- 配置部分
- function TreasureMapModel:GetTreasureMapKvCfg(key)
- if not key then return nil end
- if not self.tm_kv_cfg then
- self.tm_kv_cfg = {}
- local temp_key = nil
- for k, v in pairs(Config.Treasuremapkv) do
- temp_key = Trim(v.key)
- self.tm_kv_cfg[temp_key] = v
- end
- end
- return self.tm_kv_cfg[key]
- end
- -- 获取藏宝图月度次数奖励配置
- function TreasureMapModel:GetTreasureMapMonthTimesRewardCfg( )
- if not self.tm_mt_reward_cfg then
- local cfg = self:GetTreasureMapKvCfg("advanced_map_times_reward")
- self.tm_mt_reward_cfg = stringtotable(cfg.value)
- end
- return self.tm_mt_reward_cfg
- end
- -- 获取藏宝图奖励展示配置
- function TreasureMapModel:GetTreasureMapRewardPreviewData(type)
- if not type then return {} end
- if not self.tm_reward_preview_cfg[type] then
- self.tm_reward_preview_cfg[type] = {}
- local reward = nil
- for k, v in pairs(Config.Treasuremaprewards) do
- if v.type == type then
- reward = {
- reward_id = v.type,
- show_weight = v.show_weight,
- get_weight = v.get_weight,
- rewards = stringtotable(v.rewards)[1]
- }
- table.insert(self.tm_reward_preview_cfg[type], reward)
- end
- end
- -- 根据展示权值和获取权值排序
- local sort_func = function ( a, b )
- -- if a.show_weight == b.show_weight then
- if a.get_weight == b.get_weight then
- return a.reward_id < b.reward_id
- else
- return a.get_weight < b.get_weight
- end
- -- else
- -- return a.show_weight > b.show_weight
- -- end
- end
- table.sort(self.tm_reward_preview_cfg[type], sort_func)
- end
- return self.tm_reward_preview_cfg[type]
- end
- -- 藏宝图协议部分
- -- 使用藏宝图返回 42401 find_way:是否开始寻路
- function TreasureMapModel:SetCurrentTreasureData(vo, find_way)
- if vo then
- if vo.scene ~= 0 then
- self.current_treasure_data = vo
- if find_way then
- self:TreasureMapFindWay()
- end
- end
- else
- self.current_treasure_data = nil
- end
- end
- function TreasureMapModel:GetCurrentTreasureData( )
- return self.current_treasure_data
- end
- -- 藏宝图寻路
- function TreasureMapModel:TreasureMapFindWay( )
- if self.current_treasure_data and self.current_treasure_data.scene ~= 0 then
- local function tm_call_back()
- if self.current_treasure_data and self.current_treasure_data.scene ~= 0 then
- -- 处理藏宝图事件表现
- if self.current_treasure_data.event == TreasureMapConst.EventType.Roll then -- 转盘直接开始
- self:DealTreasureMapEvents(self.current_treasure_data.event)
- else -- 其他情况走采集表现再发协议
- GlobalEventSystem:Fire(EventName.OPEN_TREASUREMAP_COLLECT_VIEW, true, self.current_treasure_data.event)
- end
- end
- end
- local findVo = FindVo.New()
- findVo.type = FindVo.POINT
- findVo.x = self.current_treasure_data.x / SceneObj.LogicRealRatio.x
- findVo.y = self.current_treasure_data.y / SceneObj.LogicRealRatio.y
- findVo.sceneId = self.current_treasure_data.scene
- findVo.call_back = tm_call_back
-
- if SceneManager:getInstance():GetSceneId() ~= findVo.sceneId then -- 场景不同,先切场景
- GlobalEventSystem:Fire(SceneEventType.REQUEST_CHANGE_SCENE, findVo.sceneId, nil, SceneTransType.GateAny, findVo.x, findVo.y)
- self.tm_need_refind_way = true
- else
- self.tm_need_refind_way = false
- GlobalEventSystem:Fire(EventName.FIND, findVo)
- end
- end
- end
-
- -- 缓存藏宝图每日普通寻宝次数 42403
- function TreasureMapModel:SetNormalTreasureMapTimes(daily_count)
- self.tm_normal_times = daily_count
- end
- function TreasureMapModel:GetNormalTreasureMapTimes()
- return self.tm_normal_times
- end
- -- 是否可以批量使用普通藏宝图
- function TreasureMapModel:CanBatchUseNormalTreasureMap( )
- local limit_num = self:GetTreasureMapKvCfg("common_map_times").value
- -- 没达到今日最少使用个数要求就不可以批量使用
- if limit_num > self.tm_normal_times then return false end
- local max_num = self:GetTreasureMapKvCfg("map_times_max").value
- -- 今天已经用了这么多张藏宝图了也不可以批量使用
- if max_num <= self.tm_normal_times then return false end
- return true
- end
-
- -- 高级藏宝图月度次数信息 42405
- function TreasureMapModel:SetAdvTreasureMapMonthTimesData(vo)
- if vo then
- self.adv_tm_times_data = {}
- self.adv_tm_times_data.times = vo.times
- self:UpdateAdvTreasureMapMonthTimesData(vo)
- end
- end
- -- 更新高级藏宝图月度次数信息 42406
- function TreasureMapModel:UpdateAdvTreasureMapMonthTimesData(vo)
- if vo and self.adv_tm_times_data then
- self.adv_tm_times_data.receive_list = {}
- for k, v in pairs(vo.receive_list) do
- self.adv_tm_times_data.receive_list[v.re_times] = true
- end
- end
- end
- function TreasureMapModel:GetAdvTreasureMapMonthTimesData()
- return self.adv_tm_times_data
- end
-
- -- 获取藏宝图限时商城信息 42409
- function TreasureMapModel:SetTreasureMapShopData(vo)
- if vo then
- self.tm_shop_data = {}
- -- 免费商品
- if not self.tm_shop_free_cfg[vo.free_reward] then
- local cfg = DeepCopy(Config.Treasureeventrewards[vo.free_reward])
- if cfg then
- cfg.rewards = stringtotable(cfg.rewards)
- self.tm_shop_free_cfg[vo.free_reward] = cfg
- end
- end
- self.tm_shop_data.free_reward = self.tm_shop_free_cfg[vo.free_reward]
- -- 限时商品
- if not self.tm_shop_cfg[vo.limit_reward] then
- local cfg = DeepCopy(Config.Treasuremapdoor[vo.limit_reward])
- if cfg then
- cfg.rewards = stringtotable(cfg.rewards)
- self.tm_shop_cfg[vo.limit_reward] = cfg
- end
- end
- self.tm_shop_data.limit_reward = self.tm_shop_cfg[vo.limit_reward]
- else
- self.tm_shop_data = nil
- end
- end
- function TreasureMapModel:GetTreasureMapShopData( )
- return self.tm_shop_data
- end
-
- -- 购买限时道具,用于设置剩余可购买数量 42410
- function TreasureMapModel:SetTreasureMapShopRestNumData(vo)
- if vo then
- self.tm_shop_rest_data = self.tm_shop_rest_data or {}
- self.tm_shop_rest_data[vo.index] = vo.rest_num
- else
- self.tm_shop_rest_data = nil
- end
- end
- function TreasureMapModel:GetTreasureMapShopRestNumData(index)
- return self.tm_shop_rest_data and self.tm_shop_rest_data[index] or nil
- end
-
- -- 更新藏宝图相关道具的数量
- function TreasureMapModel:UpdateTreasureMapGoodsNum( )
- TaskModel:getInstance():Fire(TaskEvent.UPDATE_TREASUREMAP_GOODS_NUM)
- end
-
- -- 藏宝图限时商城(即商店活动中没有购买的道具会以限时商城的形式出现) 42414
- function TreasureMapModel:SetTreasureMapStorageShopData(vo)
- self.tm_storage_shop_data = {}
- for k, v in pairs(vo.goods_list) do
- self.tm_storage_shop_data[#self.tm_storage_shop_data + 1] = v
- end
- local sort_func = function ( a, b )
- if a.expire_time ~= b.expire_time then
- return a.expire_time < b.expire_time
- elseif a.reward_id ~= b.reward_id then
- return a.reward_id < b.reward_id
- else
- return a.index < b.index
- end
- end
- table.sort(self.tm_storage_shop_data, sort_func)
- end
- -- clear_invalid 获取数据的时候清除掉过期道具和已经买完的商品
- function TreasureMapModel:GetTreasureMapStorageShopData(clear_invalid)
- if clear_invalid then
- local cur_time = TimeUtil:getServerTime()
- local tb = {}
- for k, v in ipairs(self.tm_storage_shop_data) do
- if v.expire_time > cur_time and v.rest_num > 0 then
- tb[#tb+1] = v
- end
- end
- self.tm_storage_shop_data = tb
- end
- return self.tm_storage_shop_data
- end
-
- -- 更新限时收纳商店数据 42415
- function TreasureMapModel:UpdateTreasureMapStorageShopData(vo)
- if not vo then return end
- for k, v in pairs(self.tm_storage_shop_data) do
- if v.expire_time == vo.expire_time and
- v.reward_id == vo.reward_id and
- v.index == vo.index then
- v.rest_num = vo.rest_num
- break
- end
- end
- end
- -- 红点相关
- function TreasureMapModel:CheckTreasureMapRed(red_type)
- local bool = false
- if red_type == TreasureMapConst.RedType.MonthReward then -- 高级藏宝图月度奖励红点
- bool = self:CheckAdvMonthTimesRed()
- elseif red_type == TreasureMapConst.RedType.Shop then -- 限时商店的免费商品需要有红点
- bool = self:CheckTreasureShopRed()
- end
- self.tm_red_cache[red_type] = bool
- -- 更新红点
- self:Fire(TreasureMapConst.UPDATE_TREASUREMAP_RED, red_type, bool)
- end
- -- 获取藏宝图红点
- function TreasureMapModel:GetTreasureMapRed(red_type)
- if red_type then
- return self.tm_red_cache[red_type] or false
- else
- for k, v in pairs(self.tm_red_cache) do
- if v then
- return true
- end
- end
- return false
- end
- end
- -- 检查月度奖励红点
- function TreasureMapModel:CheckAdvMonthTimesRed( )
- -- 更新遗宝进度
- local momth_times_data = self:GetAdvTreasureMapMonthTimesData()
- local month_times_reward_cfg = self:GetTreasureMapMonthTimesRewardCfg()
- local times = 0
- if momth_times_data and month_times_reward_cfg then
- times = momth_times_data.times
- for k, v in ipairs(month_times_reward_cfg) do
- -- 满足了本次的领取条件但未领取
- if v[1] <= times and not momth_times_data.receive_list[v[1]] then
- return true
- end
- end
- end
- return false
- end
-
- -- 检查限时商店红点
- function TreasureMapModel:CheckTreasureShopRed( )
- return false
- end
-
- -- 检查是否进行道具飞入表现
- function TreasureMapModel:GetGoodsCanFly( )
- return self._tm_can_fly_goods
- end
-
- -- 藏宝图购买道具统一接口
- function TreasureMapModel:BuyTreasureMapItemFunc(type)
- local goods_id = TreasureMapConst.GoodId[type] -- 藏宝图道具id
- local price_cfg = Config.Goodsprice[goods_id]
- local jin = RoleManager.Instance.mainRoleInfo.jin
- local jinLock = RoleManager.Instance.mainRoleInfo.jinLock
- local function recharge_call_back( ... )--充值
- local args = {...}
- local use_lockjin = args[1]
- -- 关闭道具tips
- UIToolTipMgr:getInstance():CloseGoodsTips()
- local qc_data = {
- price = price_cfg.price - (use_lockjin and jinLock or 0),
- qc_type = 0,
- }
- GlobalEventSystem:Fire(EventName.OPEN_RECHARGE_TIP_VIEW, true, qc_data)
- end
- --不足话先走这里的逻辑
- if price_cfg.price_type == 1 then--彩钻
- if jin < price_cfg.price then--彩钻不足
- recharge_call_back()
- return
- end
- elseif price_cfg.price_type == 2 then--红钻
- if jinLock < price_cfg.price then--红钻不足用彩钻补齐
- local ok = function ( )
- if jinLock + jin < price_cfg.price then
- recharge_call_back(true)
- else
- buy_tip_data.ok_callback()
- end
- end
- local jin_type_img = WordManager:GetMoneyFaceStr(1)
- local jinLock_type_img = WordManager:GetMoneyFaceStr(2)
- local jin_type_name = GoodsModel:getInstance():getGoodsName(100000, false)
- local jinLock_type_name = GoodsModel:getInstance():getGoodsName(100001, false)
- local str = string.format("您的<color=#ff203a>%s不足</color>,是否使用<color=#feb940> %s%s </color>补全?",
- jinLock_type_name, jin_type_img, price_cfg.price - jinLock)
- if VipModel:getInstance():HasBoughtAllInvestmentTypes() then -- 已经购买了全部的投资类型,则不提示前往投资
- Alert.show(str, Alert.Type.Two, ok, nil, "彩钻补全", "取消")
- else
- Alert.show(str, Alert.Type.Two, ok, invest_call_back, "彩钻补全", "前往投资")
- end
- return
- end
- end
- -- 条件全部满足的情况,就打开购买界面
- ShopModel:getInstance():Fire(ShopModel.OPEN_SHOP_BUY_TIP_VIEW, goods_id, 1)
- end
- -- 藏宝图任务点击事件
- function TreasureMapModel:QuickUseTreasureMapGoodsByType(type)
- if not type then return end
- local goods_id = TreasureMapConst.GoodId[type] -- 藏宝图道具id
- if goods_id then
- local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(goods_id)
- if goods_num > 0 then
- self:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42401, type)
- else
- self:BuyTreasureMapItemFunc(type)
- end
- end
- end
- function TreasureMapModel:OnTreasureMapTaskClick(type)
- -- print("Saber:TreasureMapModel [164] type: ",type)
- if not type then return end
- -- 有缓存的情况,判断类型是否相同
- if self.current_treasure_data then
- if self.current_treasure_data.type ~= type then -- 类型不同,发协议
- self:QuickUseTreasureMapGoodsByType(type)
- else
- -- 对已有的数据进行寻路表现
- self:TreasureMapFindWay()
- end
- else -- 没缓存的情况就需要发协议请求信息
- self:QuickUseTreasureMapGoodsByType(type)
- end
- end
-
- -- 根据藏宝图不同的事件处理表现
- function TreasureMapModel:DealTreasureMapEvents(event)
- event = event or (self.current_treasure_data and self.current_treasure_data.event)
- -- print("Saber:TreasureMapModel [291] event: ",event)
- if not event then return end
- if event == TreasureMapConst.EventType.Quiz then -- 答题
- self:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42407)
- elseif event == TreasureMapConst.EventType.Shop then -- 限时商城
- self:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42409)
- elseif event == TreasureMapConst.EventType.Boss then -- Boss
- self:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42411)
- elseif event == TreasureMapConst.EventType.Normal then -- 开宝箱
- -- 直接通过协议获取结果
- self:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42402, TreasureMapConst.Normal, event)
- elseif event == TreasureMapConst.EventType.Roll then -- 转盘
- -- 直接通过协议获取结果
- self:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42402, TreasureMapConst.Advance, event)
- end
- end
-
- -- 根据42402返回的数据,获取奖励展示列表 (高级藏宝图用)
- function TreasureMapModel:GetRollRewardItemData(result_data)
- local tb = {}
- if result_data then
- local temp_cfg = nil
- for k, v in pairs(result_data.reward_list) do
- temp_cfg = Config.Treasuremaprewards[v.reward_id]
- tb[#tb+1] = temp_cfg
- end
- end
- -- 随机顺序表
- return RandomizeSequenceTableData(tb)
- end
-
- function TreasureMapModel:CheckStorageShopIcon(clear_invalid)
- local cur_list = self:GetTreasureMapStorageShopData(clear_invalid)
- if TableSize(cur_list) > 0 then
- -- 由于之前的排序是优先根据过期时间排序,所以按钮上的倒计时拿第一个道具的过期时间即可
- local earest_goods = cur_list[1]
- local left_time = earest_goods.expire_time - TimeUtil:getServerTime()
- ActivityIconManager:getInstance():addIcon(42414, left_time)
- else
- ActivityIconManager:getInstance():deleteIcon(42414)
- end
- end
-
- -- 检查是否打开快捷使用界面
- function TreasureMapModel:CheckTreasureTipUseViewOpen( )
- if self._check_tm_tips then
- local goods_id = TreasureMapConst.GoodId[self._check_tm_tips] -- 藏宝图道具id
- local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(goods_id)
- if goods_num > 0 then
- GlobalEventSystem:Fire(EventName.OPEN_TREASUREMAP_USE_TIP_VIEW, true, self._check_tm_tips)
- -- elseif self._check_tm_tips == TreasureMapConst.Advance and goods_num == 0 then
- -- -- 条件全部满足的情况,就打开购买界面
- -- ShopModel:getInstance():Fire(ShopModel.OPEN_SHOP_BUY_TIP_VIEW, goods_id, 1)
- end
- end
- self._check_tm_tips = false
- end
|