源战役客户端
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.

342 line
11 KiB

  1. HopeGiftModel = HopeGiftModel or BaseClass(BaseVo, true)
  2. local HopeGiftModel = HopeGiftModel
  3. HopeGiftModel.REQUEST_INFO = "HopeGiftModel.REQUEST_INFO"
  4. HopeGiftModel.OPEN_MERCENARY_SUPPLY_VIEW = "HopeGiftModel.OPEN_MERCENARY_SUPPLY_VIEW"--打开主界面
  5. HopeGiftModel.REQUEST_INFO = "HopeGiftModel.REQUEST_INFO"--请求协议
  6. HopeGiftModel.OPEN_HOPE_GIFT_AWARD_SHOW_VIEW = "HopeGiftModel.OPEN_HOPE_GIFT_AWARD_SHOW_VIEW"--打开奖励展示界面
  7. HopeGiftModel.UPDATE_LUCKY_INFO = "HopeGiftModel.UPDATE_LUCKY_INFO"--打开奖励展示界面
  8. HopeGiftModel.MAX_LUCKY_NUM = 10--最大抽奖次数
  9. HopeGiftModel.MAX_ROUND_AWARD_NUM = 18--最大抽奖奖励数量
  10. function HopeGiftModel:__init()
  11. HopeGiftModel.Instance = self
  12. self.login_red = false--登陆红点暂时屏蔽
  13. self.is_action = false--是否在执行动画
  14. self.is_open_view = false--是否打开界面
  15. self:Reset()
  16. end
  17. function HopeGiftModel:Reset()
  18. self.act_base_list = {}--活动信息
  19. self.hopeGift_info = {}--臻享礼包信息
  20. self.red_info_list = {}--红点信息
  21. self.is_action = {}--是否是动画进行中的列表
  22. self.chuanwen_cfg = nil
  23. self:InitHopeGiftCfg()
  24. end
  25. function HopeGiftModel:getInstance()
  26. if HopeGiftModel.Instance == nil then
  27. HopeGiftModel.Instance = HopeGiftModel.New()
  28. end
  29. return HopeGiftModel.Instance
  30. end
  31. --初始化臻享礼包配置
  32. function HopeGiftModel:InitHopeGiftCfg( )
  33. self.hopeGift_cfg = {}
  34. self.hopeGift_show_cfg = {}
  35. local data = DeepCopy(Config.Hopegift)
  36. for k,v in pairs(data) do
  37. if not self.hopeGift_cfg[v.sub_id] then
  38. self.hopeGift_cfg[v.sub_id] = {}
  39. end
  40. if not self.hopeGift_cfg[v.sub_id][v.round] then
  41. self.hopeGift_cfg[v.sub_id][v.round] = {}
  42. end
  43. v.award = stringtotable(v.award)
  44. v.resource = stringtotable(v.resource)
  45. v.name = Trim(v.name)
  46. self.hopeGift_cfg[v.sub_id][v.round][v.id] = v
  47. if v.is_show == 1 then--是否是宝库展示
  48. if not self.hopeGift_show_cfg[v.sub_id] then
  49. self.hopeGift_show_cfg[v.sub_id] = {}
  50. end
  51. if not self.hopeGift_show_cfg[v.sub_id][v.round] then
  52. self.hopeGift_show_cfg[v.sub_id][v.round] = {}
  53. end
  54. self.hopeGift_show_cfg[v.sub_id][v.round][#self.hopeGift_show_cfg[v.sub_id][v.round] + 1] = v
  55. end
  56. end
  57. GlobalEventSystem:Fire(ActivityIconManager.REFRESH_ICON, true)
  58. end
  59. --检查臻享礼包红点
  60. function HopeGiftModel:CheckLimitGiftRedDot( )
  61. return self.red_dot_info
  62. end
  63. --获得活动信息列表
  64. function HopeGiftModel:GetTabInfo( )
  65. self.act_base_list = {} --臻享礼包活动内部的活动列表
  66. local all_list = CustomActivityModel:getInstance():getAllActListByBaseType(CustomActivityModel.CustomActBaseType.HOPE_GIFT) or {}
  67. all_list = DeepCopy(all_list)
  68. -- print("huangcong:HopeGiftModel [start:92] :", TableSize(all_list))
  69. -- PrintTable(all_list)
  70. local server_time = TimeUtil:getServerTime()
  71. local my_level = RoleManager.Instance.mainRoleInfo.level
  72. local my_vip = RoleManager.Instance.mainRoleInfo.vip_flag
  73. for k,v in pairs(all_list) do
  74. local open_level = Config.Modulesub["331@19"].open_lv or 1
  75. local open_vip = 0
  76. for l,w in pairs(v.condition_list) do
  77. if type(w) == "table" and w[1] == "role_lv" then
  78. open_level = tonumber(w[2])
  79. elseif w[1] == "vip" then
  80. open_vip = tonumber(w[2])
  81. end
  82. end
  83. if server_time > v.stime and v.etime > server_time and open_vip <= my_vip then
  84. if my_level >= open_level and GetModuleIsOpen(331,CustomActivityModel.CustomActBaseType.HOPE_GIFT) then
  85. v.sort_index = v.sub_type or 999
  86. table.insert(self.act_base_list, v)
  87. end
  88. end
  89. end
  90. if #self.act_base_list > 1 then
  91. local sort_func = function ( a, b )
  92. return a.sort_index < b.sort_index
  93. end
  94. table.sort(self.act_base_list, sort_func)
  95. end
  96. return self.act_base_list
  97. end
  98. --设置臻享礼包信息
  99. function HopeGiftModel:SetHopeGiftInfo( scmd )
  100. self.hopeGift_info[scmd.sub_type] = {}
  101. local new_get_list = {}
  102. for k,v in pairs(scmd.get_id) do
  103. new_get_list[v.award_id] = v
  104. end
  105. scmd.get_list = new_get_list
  106. if self.hopeGift_cfg[scmd.sub_type] and TableSize(scmd.get_list) >= HopeGiftModel.MAX_ROUND_AWARD_NUM and scmd.round + 1 <= TableSize(self.hopeGift_cfg[scmd.sub_type]) then
  107. scmd.get_list = {}
  108. scmd.round = scmd.round + 1
  109. end
  110. local is_buy_num = 0--买礼包数量
  111. local already_get_list = {}
  112. for k,v in pairs(scmd.already_get_list) do
  113. already_get_list[v.grade_id] = v
  114. end
  115. scmd.already_get_list = already_get_list
  116. scmd.lucky_status = 2--默认是抽奖状态2 领取钥匙状态1 当前轮次已结束3
  117. --这里要创建奖励页签相关数据
  118. local base_type = CustomActivityModel.CustomActBaseType.HOPE_GIFT
  119. local act_list = CustomActivityModel:getInstance():getActList(base_type,scmd.sub_type)
  120. if not act_list or not act_list.condition_list then return end
  121. local cost_id = 102350
  122. for k,v in pairs(act_list.condition_list) do
  123. if v[1] == "draw_cost" then--返利最大值
  124. cost_id = tonumber(v[2][1])
  125. break
  126. end
  127. end
  128. local sub_type_list = CustomActivityModel:getInstance():getOneActRewardList(base_type,scmd.sub_type)
  129. local tab_list = {}--创建页签信息
  130. tab_list[1] = {id = 0}--第一个默认是主页签不存在奖励数据
  131. if TableSize(sub_type_list) > 0 then
  132. local return_total_sum_num = 0--返回钥匙总数
  133. local return_have_sum_num = 0--剩余返回总数
  134. local have_buy = false-- 是否购买过
  135. for i,v in ipairs(sub_type_list.reward_list) do
  136. v.id = tonumber(v.grade)
  137. for k,vv in pairs(v.condition_list) do
  138. if vv[1] == "return_total" then--返利最大值
  139. v.return_total = tonumber(vv[2][2])
  140. return_total_sum_num = return_total_sum_num + v.return_total
  141. cost_id = tonumber(vv[2][1])
  142. elseif vv[1] == "original_price" then--原价
  143. v.original_price = tonumber(vv[2])
  144. elseif vv[1] == "hopegift_cost" then--现价
  145. v.hopegift_cost = tonumber(vv[2])
  146. elseif vv[1] == "return_day" then--每日返回
  147. v.return_day = tonumber(vv[2][2])
  148. elseif vv[1] == "show" then
  149. v.model_data = vv
  150. end
  151. end
  152. table.insert(tab_list, v)
  153. if not have_buy then
  154. have_buy = v.status == 2--已购买
  155. end
  156. is_buy_num = is_buy_num + (v.status == 2 and 1 or 0)
  157. end
  158. local sortFunc = function (a, b)--根据阶级排序 可领取排前面
  159. return a.id < b.id
  160. end
  161. table.sort(tab_list, sortFunc)
  162. local return_day_sum_num = 0--今日可领取的钥匙数量
  163. for i,v in ipairs(tab_list) do
  164. if i ~= 1 then
  165. if scmd.already_get_list[v.grade] then
  166. return_have_sum_num = return_have_sum_num + v.return_total - scmd.already_get_list[v.grade].get_num
  167. if scmd.already_get_list[v.grade].get_num < v.return_total and v.status == 2 and scmd.already_get_list[v.grade].status == 0 then
  168. return_day_sum_num = return_day_sum_num + v.return_day
  169. end
  170. end
  171. end
  172. end
  173. scmd.return_total_sum_num = return_total_sum_num--返回钥匙总数
  174. scmd.return_day_sum_num = return_day_sum_num--剩余返回总数
  175. scmd.return_have_sum_num = return_have_sum_num
  176. scmd.cost_id = cost_id
  177. scmd.tab_list = tab_list
  178. scmd.have_buy = have_buy
  179. scmd.round_award_over = TableSize(scmd.get_list) < 18
  180. print("huangcong:HopeGiftModel [start:194] :", is_buy_num)
  181. scmd.is_buy = is_buy_num>=4--是否已购买4个
  182. scmd.is_buy_num = is_buy_num
  183. end
  184. self.hopeGift_info[scmd.sub_type] = scmd
  185. self:CheckHopeGiftRedDot(scmd.sub_type)
  186. end
  187. --检查臻享礼包红点
  188. function HopeGiftModel:CheckHopeGiftRedDot( sub_type )
  189. if not sub_type then return end
  190. local show = false
  191. local server_info = self:GetHopeGiftInfo(sub_type)
  192. if server_info and server_info.return_day_sum_num then
  193. if server_info.return_day_sum_num > 0 then--今日可领取的钥匙大于0
  194. show = true
  195. end
  196. if not show then
  197. show = server_info.is_buy and server_info.day_lucky_limit ~= 1
  198. end
  199. end
  200. if not show and self:CheckActIsOpen(sub_type) and self.login_red then
  201. show = true
  202. end
  203. self.red_info_list[sub_type] = show
  204. local is_find = false
  205. for i,v in pairs(self.act_base_list) do
  206. if v.sub_type == sub_type then
  207. is_find = true
  208. break
  209. end
  210. end
  211. if not is_find then--构造活动数据 有红点也要有活动数据
  212. self:GetTabInfo()
  213. end
  214. end
  215. function HopeGiftModel:GetHopeGiftRedDot( sub_type )
  216. if HopeGiftModel:getInstance():CheckActIsOpen(sub_type) then
  217. return self.red_info_list[sub_type] or false
  218. else
  219. return false
  220. end
  221. end
  222. function HopeGiftModel:GetHopeGiftInfo( sub_type )
  223. return self.hopeGift_info[sub_type]
  224. end
  225. --得到臻享礼包配置
  226. function HopeGiftModel:GetHopeGiftCfg( sub_type,round )
  227. if not sub_type and not round then return end
  228. if sub_type and not round then
  229. return self.hopeGift_cfg[sub_type]
  230. elseif sub_type and round and self.hopeGift_cfg[sub_type] then
  231. return self.hopeGift_cfg[sub_type][round]
  232. end
  233. end
  234. --得到臻享礼包奖励展示配置
  235. function HopeGiftModel:GetHopeGiftAwardShow( sub_type )
  236. return self.hopeGift_show_cfg[sub_type]
  237. end
  238. --是否在抽奖动画
  239. function HopeGiftModel:GetHopeGiftIsAction( sub_type )
  240. if not sub_type then
  241. for k,v in pairs(self.is_action) do
  242. if v then
  243. return true
  244. end
  245. end
  246. end
  247. return self.is_action and self.is_action[sub_type]
  248. end
  249. function HopeGiftModel:SetHopeGiftIsAction( is_action,sub_type )
  250. if not self.is_action then
  251. self.is_action = {}
  252. end
  253. self.is_action[sub_type] = is_action
  254. end
  255. --得到当前是否打开臻享礼包界面
  256. function HopeGiftModel:GetCurIsOpenView( )
  257. return self.is_open_view
  258. end
  259. function HopeGiftModel:SetCurIsOpenView( is_open_view )
  260. self.is_open_view = is_open_view
  261. end
  262. --检查当前能否飞道具
  263. function HopeGiftModel:CheckCurCanFlyGoods( )
  264. if self.is_open_view then
  265. return false
  266. end
  267. return true
  268. end
  269. --检查活动是否开启
  270. function HopeGiftModel:CheckActIsOpen( sub_type )
  271. if #self.act_base_list == 0 then return false end
  272. local is_lock = true
  273. for i,v in pairs(self.act_base_list) do
  274. if v.sub_type == sub_type then
  275. is_lock = false
  276. break
  277. end
  278. end
  279. if is_lock then return false end
  280. local base_type = CustomActivityModel.CustomActBaseType.HOPE_GIFT
  281. local sub_type_list = CustomActivityModel:getInstance():getOneActRewardList(base_type,sub_type)
  282. if not sub_type_list then return end
  283. local award_can_buy = false
  284. if sub_type_list and sub_type_list.reward_list then
  285. for k,v in pairs(sub_type_list.reward_list) do--有未购买的奖励
  286. if v.status == 1 then
  287. award_can_buy = true
  288. break
  289. end
  290. end
  291. end
  292. if award_can_buy then
  293. return true
  294. end
  295. local server_info = self:GetHopeGiftInfo(sub_type)
  296. if not server_info or not server_info.return_have_sum_num then return false end
  297. if server_info.return_have_sum_num > 0 then
  298. return true
  299. elseif server_info.return_have_sum_num <= 0 then--返利总数小于等于0则判断奖励是否没有领完
  300. return 18 - TableSize(server_info.get_list) > 0
  301. end
  302. end
  303. --设置传闻数据
  304. function HopeGiftModel:SetChuanwenInfo( scmd,type )
  305. self.chuanwen_cfg = {scmd,type}
  306. end
  307. function HopeGiftModel:PlayChuanwenInfo( )
  308. if self.chuanwen_cfg and self.chuanwen_cfg[1] then
  309. GlobalEventSystem:Fire(EventName.RECEIVE_NEW_CHUANWEN, self.chuanwen_cfg[1], self.chuanwen_cfg[2])
  310. self.chuanwen_cfg = nil
  311. end
  312. end