源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

456 lines
18 KiB

  1. TreasureMapModel = TreasureMapModel or BaseClass(BaseVo, true)
  2. local TreasureMapModel = TreasureMapModel
  3. function TreasureMapModel:__init()
  4. TreasureMapModel.Instance = self
  5. self:Reset()
  6. end
  7. function TreasureMapModel:Reset()
  8. self.tm_red_cache = {} -- 红点缓存
  9. self.current_treasure_data = nil -- 当前的藏宝图信息
  10. self.tm_normal_times = 0 -- 今日普通藏宝图使用次数
  11. self.adv_tm_times_data = nil -- 高级藏宝图月度次数信息
  12. self.tm_shop_data = nil -- 藏宝图限时商城商品内容
  13. self.tm_shop_rest_data = nil -- 藏宝图限时商城剩余数量数据
  14. self.tm_storage_shop_data = {} -- 藏宝图限时商城收纳数据
  15. self.tm_shop_free_cfg = {} -- 藏宝图限时商城动态配置(免费商品)
  16. self.tm_kv_cfg = nil -- 藏宝图键值动态配置
  17. self.tm_mt_reward_cfg = nil -- 藏宝图月度次数奖励配置
  18. self.tm_shop_cfg = {} -- 藏宝图限时商城动态配置
  19. self.tm_reward_preview_cfg = {} -- 藏宝图奖励展示配置
  20. self._tm_can_fly_goods = true -- 是否可以有道具飘入表现
  21. self._check_tm_tips = false -- 是否检查藏宝图快捷使用tips,需要检查时该值为藏宝图类型
  22. end
  23. function TreasureMapModel:getInstance()
  24. if self.Instance == nil then
  25. self.Instance = TreasureMapModel.New()
  26. end
  27. return self.Instance
  28. end
  29. -- 配置部分
  30. function TreasureMapModel:GetTreasureMapKvCfg(key)
  31. if not key then return nil end
  32. if not self.tm_kv_cfg then
  33. self.tm_kv_cfg = {}
  34. local temp_key = nil
  35. for k, v in pairs(Config.Treasuremapkv) do
  36. temp_key = Trim(v.key)
  37. self.tm_kv_cfg[temp_key] = v
  38. end
  39. end
  40. return self.tm_kv_cfg[key]
  41. end
  42. -- 获取藏宝图月度次数奖励配置
  43. function TreasureMapModel:GetTreasureMapMonthTimesRewardCfg( )
  44. if not self.tm_mt_reward_cfg then
  45. local cfg = self:GetTreasureMapKvCfg("advanced_map_times_reward")
  46. self.tm_mt_reward_cfg = stringtotable(cfg.value)
  47. end
  48. return self.tm_mt_reward_cfg
  49. end
  50. -- 获取藏宝图奖励展示配置
  51. function TreasureMapModel:GetTreasureMapRewardPreviewData(type)
  52. if not type then return {} end
  53. if not self.tm_reward_preview_cfg[type] then
  54. self.tm_reward_preview_cfg[type] = {}
  55. local reward = nil
  56. for k, v in pairs(Config.Treasuremaprewards) do
  57. if v.type == type then
  58. reward = {
  59. reward_id = v.type,
  60. show_weight = v.show_weight,
  61. get_weight = v.get_weight,
  62. rewards = stringtotable(v.rewards)[1]
  63. }
  64. table.insert(self.tm_reward_preview_cfg[type], reward)
  65. end
  66. end
  67. -- 根据展示权值和获取权值排序
  68. local sort_func = function ( a, b )
  69. -- if a.show_weight == b.show_weight then
  70. if a.get_weight == b.get_weight then
  71. return a.reward_id < b.reward_id
  72. else
  73. return a.get_weight < b.get_weight
  74. end
  75. -- else
  76. -- return a.show_weight > b.show_weight
  77. -- end
  78. end
  79. table.sort(self.tm_reward_preview_cfg[type], sort_func)
  80. end
  81. return self.tm_reward_preview_cfg[type]
  82. end
  83. -- 藏宝图协议部分
  84. -- 使用藏宝图返回 42401 find_way:是否开始寻路
  85. function TreasureMapModel:SetCurrentTreasureData(vo, find_way)
  86. if vo then
  87. if vo.scene ~= 0 then
  88. self.current_treasure_data = vo
  89. if find_way then
  90. self:TreasureMapFindWay()
  91. end
  92. end
  93. else
  94. self.current_treasure_data = nil
  95. end
  96. end
  97. function TreasureMapModel:GetCurrentTreasureData( )
  98. return self.current_treasure_data
  99. end
  100. -- 藏宝图寻路
  101. function TreasureMapModel:TreasureMapFindWay( )
  102. if self.current_treasure_data and self.current_treasure_data.scene ~= 0 then
  103. local function tm_call_back()
  104. if self.current_treasure_data and self.current_treasure_data.scene ~= 0 then
  105. -- 处理藏宝图事件表现
  106. if self.current_treasure_data.event == TreasureMapConst.EventType.Roll then -- 转盘直接开始
  107. self:DealTreasureMapEvents(self.current_treasure_data.event)
  108. else -- 其他情况走采集表现再发协议
  109. GlobalEventSystem:Fire(EventName.OPEN_TREASUREMAP_COLLECT_VIEW, true, self.current_treasure_data.event)
  110. end
  111. end
  112. end
  113. local findVo = FindVo.New()
  114. findVo.type = FindVo.POINT
  115. findVo.x = self.current_treasure_data.x / SceneObj.LogicRealRatio.x
  116. findVo.y = self.current_treasure_data.y / SceneObj.LogicRealRatio.y
  117. findVo.sceneId = self.current_treasure_data.scene
  118. findVo.call_back = tm_call_back
  119. if SceneManager:getInstance():GetSceneId() ~= findVo.sceneId then -- 场景不同,先切场景
  120. GlobalEventSystem:Fire(SceneEventType.REQUEST_CHANGE_SCENE, findVo.sceneId, nil, SceneTransType.GateAny, findVo.x, findVo.y)
  121. self.tm_need_refind_way = true
  122. else
  123. self.tm_need_refind_way = false
  124. GlobalEventSystem:Fire(EventName.FIND, findVo)
  125. end
  126. end
  127. end
  128. -- 缓存藏宝图每日普通寻宝次数 42403
  129. function TreasureMapModel:SetNormalTreasureMapTimes(daily_count)
  130. self.tm_normal_times = daily_count
  131. end
  132. function TreasureMapModel:GetNormalTreasureMapTimes()
  133. return self.tm_normal_times
  134. end
  135. -- 是否可以批量使用普通藏宝图
  136. function TreasureMapModel:CanBatchUseNormalTreasureMap( )
  137. local limit_num = self:GetTreasureMapKvCfg("common_map_times").value
  138. -- 没达到今日最少使用个数要求就不可以批量使用
  139. if limit_num > self.tm_normal_times then return false end
  140. local max_num = self:GetTreasureMapKvCfg("map_times_max").value
  141. -- 今天已经用了这么多张藏宝图了也不可以批量使用
  142. if max_num <= self.tm_normal_times then return false end
  143. return true
  144. end
  145. -- 高级藏宝图月度次数信息 42405
  146. function TreasureMapModel:SetAdvTreasureMapMonthTimesData(vo)
  147. if vo then
  148. self.adv_tm_times_data = {}
  149. self.adv_tm_times_data.times = vo.times
  150. self:UpdateAdvTreasureMapMonthTimesData(vo)
  151. end
  152. end
  153. -- 更新高级藏宝图月度次数信息 42406
  154. function TreasureMapModel:UpdateAdvTreasureMapMonthTimesData(vo)
  155. if vo and self.adv_tm_times_data then
  156. self.adv_tm_times_data.receive_list = {}
  157. for k, v in pairs(vo.receive_list) do
  158. self.adv_tm_times_data.receive_list[v.re_times] = true
  159. end
  160. end
  161. end
  162. function TreasureMapModel:GetAdvTreasureMapMonthTimesData()
  163. return self.adv_tm_times_data
  164. end
  165. -- 获取藏宝图限时商城信息 42409
  166. function TreasureMapModel:SetTreasureMapShopData(vo)
  167. if vo then
  168. self.tm_shop_data = {}
  169. -- 免费商品
  170. if not self.tm_shop_free_cfg[vo.free_reward] then
  171. local cfg = DeepCopy(Config.Treasureeventrewards[vo.free_reward])
  172. if cfg then
  173. cfg.rewards = stringtotable(cfg.rewards)
  174. self.tm_shop_free_cfg[vo.free_reward] = cfg
  175. end
  176. end
  177. self.tm_shop_data.free_reward = self.tm_shop_free_cfg[vo.free_reward]
  178. -- 限时商品
  179. if not self.tm_shop_cfg[vo.limit_reward] then
  180. local cfg = DeepCopy(Config.Treasuremapdoor[vo.limit_reward])
  181. if cfg then
  182. cfg.rewards = stringtotable(cfg.rewards)
  183. self.tm_shop_cfg[vo.limit_reward] = cfg
  184. end
  185. end
  186. self.tm_shop_data.limit_reward = self.tm_shop_cfg[vo.limit_reward]
  187. else
  188. self.tm_shop_data = nil
  189. end
  190. end
  191. function TreasureMapModel:GetTreasureMapShopData( )
  192. return self.tm_shop_data
  193. end
  194. -- 购买限时道具,用于设置剩余可购买数量 42410
  195. function TreasureMapModel:SetTreasureMapShopRestNumData(vo)
  196. if vo then
  197. self.tm_shop_rest_data = self.tm_shop_rest_data or {}
  198. self.tm_shop_rest_data[vo.index] = vo.rest_num
  199. else
  200. self.tm_shop_rest_data = nil
  201. end
  202. end
  203. function TreasureMapModel:GetTreasureMapShopRestNumData(index)
  204. return self.tm_shop_rest_data and self.tm_shop_rest_data[index] or nil
  205. end
  206. -- 更新藏宝图相关道具的数量
  207. function TreasureMapModel:UpdateTreasureMapGoodsNum( )
  208. TaskModel:getInstance():Fire(TaskEvent.UPDATE_TREASUREMAP_GOODS_NUM)
  209. end
  210. -- 藏宝图限时商城(即商店活动中没有购买的道具会以限时商城的形式出现) 42414
  211. function TreasureMapModel:SetTreasureMapStorageShopData(vo)
  212. self.tm_storage_shop_data = {}
  213. for k, v in pairs(vo.goods_list) do
  214. self.tm_storage_shop_data[#self.tm_storage_shop_data + 1] = v
  215. end
  216. local sort_func = function ( a, b )
  217. if a.expire_time ~= b.expire_time then
  218. return a.expire_time < b.expire_time
  219. elseif a.reward_id ~= b.reward_id then
  220. return a.reward_id < b.reward_id
  221. else
  222. return a.index < b.index
  223. end
  224. end
  225. table.sort(self.tm_storage_shop_data, sort_func)
  226. end
  227. -- clear_invalid 获取数据的时候清除掉过期道具和已经买完的商品
  228. function TreasureMapModel:GetTreasureMapStorageShopData(clear_invalid)
  229. if clear_invalid then
  230. local cur_time = TimeUtil:getServerTime()
  231. local tb = {}
  232. for k, v in ipairs(self.tm_storage_shop_data) do
  233. if v.expire_time > cur_time and v.rest_num > 0 then
  234. tb[#tb+1] = v
  235. end
  236. end
  237. self.tm_storage_shop_data = tb
  238. end
  239. return self.tm_storage_shop_data
  240. end
  241. -- 更新限时收纳商店数据 42415
  242. function TreasureMapModel:UpdateTreasureMapStorageShopData(vo)
  243. if not vo then return end
  244. for k, v in pairs(self.tm_storage_shop_data) do
  245. if v.expire_time == vo.expire_time and
  246. v.reward_id == vo.reward_id and
  247. v.index == vo.index then
  248. v.rest_num = vo.rest_num
  249. break
  250. end
  251. end
  252. end
  253. -- 红点相关
  254. function TreasureMapModel:CheckTreasureMapRed(red_type)
  255. local bool = false
  256. if red_type == TreasureMapConst.RedType.MonthReward then -- 高级藏宝图月度奖励红点
  257. bool = self:CheckAdvMonthTimesRed()
  258. elseif red_type == TreasureMapConst.RedType.Shop then -- 限时商店的免费商品需要有红点
  259. bool = self:CheckTreasureShopRed()
  260. end
  261. self.tm_red_cache[red_type] = bool
  262. -- 更新红点
  263. self:Fire(TreasureMapConst.UPDATE_TREASUREMAP_RED, red_type, bool)
  264. end
  265. -- 获取藏宝图红点
  266. function TreasureMapModel:GetTreasureMapRed(red_type)
  267. if red_type then
  268. return self.tm_red_cache[red_type] or false
  269. else
  270. for k, v in pairs(self.tm_red_cache) do
  271. if v then
  272. return true
  273. end
  274. end
  275. return false
  276. end
  277. end
  278. -- 检查月度奖励红点
  279. function TreasureMapModel:CheckAdvMonthTimesRed( )
  280. -- 更新遗宝进度
  281. local momth_times_data = self:GetAdvTreasureMapMonthTimesData()
  282. local month_times_reward_cfg = self:GetTreasureMapMonthTimesRewardCfg()
  283. local times = 0
  284. if momth_times_data and month_times_reward_cfg then
  285. times = momth_times_data.times
  286. for k, v in ipairs(month_times_reward_cfg) do
  287. -- 满足了本次的领取条件但未领取
  288. if v[1] <= times and not momth_times_data.receive_list[v[1]] then
  289. return true
  290. end
  291. end
  292. end
  293. return false
  294. end
  295. -- 检查限时商店红点
  296. function TreasureMapModel:CheckTreasureShopRed( )
  297. return false
  298. end
  299. -- 检查是否进行道具飞入表现
  300. function TreasureMapModel:GetGoodsCanFly( )
  301. return self._tm_can_fly_goods
  302. end
  303. -- 藏宝图购买道具统一接口
  304. function TreasureMapModel:BuyTreasureMapItemFunc(type)
  305. local goods_id = TreasureMapConst.GoodId[type] -- 藏宝图道具id
  306. local price_cfg = Config.Goodsprice[goods_id]
  307. local jin = RoleManager.Instance.mainRoleInfo.jin
  308. local jinLock = RoleManager.Instance.mainRoleInfo.jinLock
  309. local function recharge_call_back( ... )--充值
  310. local args = {...}
  311. local use_lockjin = args[1]
  312. -- 关闭道具tips
  313. UIToolTipMgr:getInstance():CloseGoodsTips()
  314. local qc_data = {
  315. price = price_cfg.price - (use_lockjin and jinLock or 0),
  316. qc_type = 0,
  317. }
  318. GlobalEventSystem:Fire(EventName.OPEN_RECHARGE_TIP_VIEW, true, qc_data)
  319. end
  320. --不足话先走这里的逻辑
  321. if price_cfg.price_type == 1 then--彩钻
  322. if jin < price_cfg.price then--彩钻不足
  323. recharge_call_back()
  324. return
  325. end
  326. elseif price_cfg.price_type == 2 then--红钻
  327. if jinLock < price_cfg.price then--红钻不足用彩钻补齐
  328. local ok = function ( )
  329. if jinLock + jin < price_cfg.price then
  330. recharge_call_back(true)
  331. else
  332. buy_tip_data.ok_callback()
  333. end
  334. end
  335. local jin_type_img = WordManager:GetMoneyFaceStr(1)
  336. local jinLock_type_img = WordManager:GetMoneyFaceStr(2)
  337. local jin_type_name = GoodsModel:getInstance():getGoodsName(100000, false)
  338. local jinLock_type_name = GoodsModel:getInstance():getGoodsName(100001, false)
  339. local str = string.format("您的<color=#ff203a>%s不足</color>,是否使用<color=#feb940> %s%s </color>补全?",
  340. jinLock_type_name, jin_type_img, price_cfg.price - jinLock)
  341. if VipModel:getInstance():HasBoughtAllInvestmentTypes() then -- 已经购买了全部的投资类型,则不提示前往投资
  342. Alert.show(str, Alert.Type.Two, ok, nil, "彩钻补全", "取消")
  343. else
  344. Alert.show(str, Alert.Type.Two, ok, invest_call_back, "彩钻补全", "前往投资")
  345. end
  346. return
  347. end
  348. end
  349. -- 条件全部满足的情况,就打开购买界面
  350. ShopModel:getInstance():Fire(ShopModel.OPEN_SHOP_BUY_TIP_VIEW, goods_id, 1)
  351. end
  352. -- 藏宝图任务点击事件
  353. function TreasureMapModel:QuickUseTreasureMapGoodsByType(type)
  354. if not type then return end
  355. local goods_id = TreasureMapConst.GoodId[type] -- 藏宝图道具id
  356. if goods_id then
  357. local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(goods_id)
  358. if goods_num > 0 then
  359. self:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42401, type)
  360. else
  361. self:BuyTreasureMapItemFunc(type)
  362. end
  363. end
  364. end
  365. function TreasureMapModel:OnTreasureMapTaskClick(type)
  366. -- print("Saber:TreasureMapModel [164] type: ",type)
  367. if not type then return end
  368. -- 有缓存的情况,判断类型是否相同
  369. if self.current_treasure_data then
  370. if self.current_treasure_data.type ~= type then -- 类型不同,发协议
  371. self:QuickUseTreasureMapGoodsByType(type)
  372. else
  373. -- 对已有的数据进行寻路表现
  374. self:TreasureMapFindWay()
  375. end
  376. else -- 没缓存的情况就需要发协议请求信息
  377. self:QuickUseTreasureMapGoodsByType(type)
  378. end
  379. end
  380. -- 根据藏宝图不同的事件处理表现
  381. function TreasureMapModel:DealTreasureMapEvents(event)
  382. event = event or (self.current_treasure_data and self.current_treasure_data.event)
  383. -- print("Saber:TreasureMapModel [291] event: ",event)
  384. if not event then return end
  385. if event == TreasureMapConst.EventType.Quiz then -- 答题
  386. self:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42407)
  387. elseif event == TreasureMapConst.EventType.Shop then -- 限时商城
  388. self:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42409)
  389. elseif event == TreasureMapConst.EventType.Boss then -- Boss
  390. self:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42411)
  391. elseif event == TreasureMapConst.EventType.Normal then -- 开宝箱
  392. -- 直接通过协议获取结果
  393. self:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42402, TreasureMapConst.Normal, event)
  394. elseif event == TreasureMapConst.EventType.Roll then -- 转盘
  395. -- 直接通过协议获取结果
  396. self:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42402, TreasureMapConst.Advance, event)
  397. end
  398. end
  399. -- 根据42402返回的数据,获取奖励展示列表 (高级藏宝图用)
  400. function TreasureMapModel:GetRollRewardItemData(result_data)
  401. local tb = {}
  402. if result_data then
  403. local temp_cfg = nil
  404. for k, v in pairs(result_data.reward_list) do
  405. temp_cfg = Config.Treasuremaprewards[v.reward_id]
  406. tb[#tb+1] = temp_cfg
  407. end
  408. end
  409. -- 随机顺序表
  410. return RandomizeSequenceTableData(tb)
  411. end
  412. function TreasureMapModel:CheckStorageShopIcon(clear_invalid)
  413. local cur_list = self:GetTreasureMapStorageShopData(clear_invalid)
  414. if TableSize(cur_list) > 0 then
  415. -- 由于之前的排序是优先根据过期时间排序,所以按钮上的倒计时拿第一个道具的过期时间即可
  416. local earest_goods = cur_list[1]
  417. local left_time = earest_goods.expire_time - TimeUtil:getServerTime()
  418. ActivityIconManager:getInstance():addIcon(42414, left_time)
  419. else
  420. ActivityIconManager:getInstance():deleteIcon(42414)
  421. end
  422. end
  423. -- 检查是否打开快捷使用界面
  424. function TreasureMapModel:CheckTreasureTipUseViewOpen( )
  425. if self._check_tm_tips then
  426. local goods_id = TreasureMapConst.GoodId[self._check_tm_tips] -- 藏宝图道具id
  427. local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(goods_id)
  428. if goods_num > 0 then
  429. GlobalEventSystem:Fire(EventName.OPEN_TREASUREMAP_USE_TIP_VIEW, true, self._check_tm_tips)
  430. -- elseif self._check_tm_tips == TreasureMapConst.Advance and goods_num == 0 then
  431. -- -- 条件全部满足的情况,就打开购买界面
  432. -- ShopModel:getInstance():Fire(ShopModel.OPEN_SHOP_BUY_TIP_VIEW, goods_id, 1)
  433. end
  434. end
  435. self._check_tm_tips = false
  436. end