|
|
- HopeGiftModel = HopeGiftModel or BaseClass(BaseVo, true)
- local HopeGiftModel = HopeGiftModel
-
- HopeGiftModel.REQUEST_INFO = "HopeGiftModel.REQUEST_INFO"
- HopeGiftModel.OPEN_MERCENARY_SUPPLY_VIEW = "HopeGiftModel.OPEN_MERCENARY_SUPPLY_VIEW"--打开主界面
- HopeGiftModel.REQUEST_INFO = "HopeGiftModel.REQUEST_INFO"--请求协议
- HopeGiftModel.OPEN_HOPE_GIFT_AWARD_SHOW_VIEW = "HopeGiftModel.OPEN_HOPE_GIFT_AWARD_SHOW_VIEW"--打开奖励展示界面
- HopeGiftModel.UPDATE_LUCKY_INFO = "HopeGiftModel.UPDATE_LUCKY_INFO"--打开奖励展示界面
-
- HopeGiftModel.MAX_LUCKY_NUM = 10--最大抽奖次数
- HopeGiftModel.MAX_ROUND_AWARD_NUM = 18--最大抽奖奖励数量
-
- function HopeGiftModel:__init()
- HopeGiftModel.Instance = self
- self.login_red = false--登陆红点暂时屏蔽
- self.is_action = false--是否在执行动画
- self.is_open_view = false--是否打开界面
- self:Reset()
- end
-
- function HopeGiftModel:Reset()
- self.act_base_list = {}--活动信息
- self.hopeGift_info = {}--臻享礼包信息
- self.red_info_list = {}--红点信息
- self.is_action = {}--是否是动画进行中的列表
- self.chuanwen_cfg = nil
- self:InitHopeGiftCfg()
- end
-
- function HopeGiftModel:getInstance()
- if HopeGiftModel.Instance == nil then
- HopeGiftModel.Instance = HopeGiftModel.New()
- end
- return HopeGiftModel.Instance
- end
-
- --初始化臻享礼包配置
- function HopeGiftModel:InitHopeGiftCfg( )
- self.hopeGift_cfg = {}
- self.hopeGift_show_cfg = {}
- local data = DeepCopy(Config.Hopegift)
- for k,v in pairs(data) do
- if not self.hopeGift_cfg[v.sub_id] then
- self.hopeGift_cfg[v.sub_id] = {}
- end
- if not self.hopeGift_cfg[v.sub_id][v.round] then
- self.hopeGift_cfg[v.sub_id][v.round] = {}
- end
- v.award = stringtotable(v.award)
- v.resource = stringtotable(v.resource)
- v.name = Trim(v.name)
- self.hopeGift_cfg[v.sub_id][v.round][v.id] = v
-
- if v.is_show == 1 then--是否是宝库展示
- if not self.hopeGift_show_cfg[v.sub_id] then
- self.hopeGift_show_cfg[v.sub_id] = {}
- end
- if not self.hopeGift_show_cfg[v.sub_id][v.round] then
- self.hopeGift_show_cfg[v.sub_id][v.round] = {}
- end
- self.hopeGift_show_cfg[v.sub_id][v.round][#self.hopeGift_show_cfg[v.sub_id][v.round] + 1] = v
- end
- end
- GlobalEventSystem:Fire(ActivityIconManager.REFRESH_ICON, true)
- end
-
- --检查臻享礼包红点
- function HopeGiftModel:CheckLimitGiftRedDot( )
- return self.red_dot_info
- end
-
- --获得活动信息列表
- function HopeGiftModel:GetTabInfo( )
- self.act_base_list = {} --臻享礼包活动内部的活动列表
- local all_list = CustomActivityModel:getInstance():getAllActListByBaseType(CustomActivityModel.CustomActBaseType.HOPE_GIFT) or {}
- all_list = DeepCopy(all_list)
- -- print("huangcong:HopeGiftModel [start:92] :", TableSize(all_list))
- -- PrintTable(all_list)
- local server_time = TimeUtil:getServerTime()
- local my_level = RoleManager.Instance.mainRoleInfo.level
- local my_vip = RoleManager.Instance.mainRoleInfo.vip_flag
-
- for k,v in pairs(all_list) do
- local open_level = Config.Modulesub["331@19"].open_lv or 1
- local open_vip = 0
- for l,w in pairs(v.condition_list) do
- if type(w) == "table" and w[1] == "role_lv" then
- open_level = tonumber(w[2])
- elseif w[1] == "vip" then
- open_vip = tonumber(w[2])
- end
- end
- if server_time > v.stime and v.etime > server_time and open_vip <= my_vip then
- if my_level >= open_level and GetModuleIsOpen(331,CustomActivityModel.CustomActBaseType.HOPE_GIFT) then
- v.sort_index = v.sub_type or 999
- table.insert(self.act_base_list, v)
- end
- end
- end
- if #self.act_base_list > 1 then
- local sort_func = function ( a, b )
- return a.sort_index < b.sort_index
- end
- table.sort(self.act_base_list, sort_func)
- end
- return self.act_base_list
- end
-
- --设置臻享礼包信息
- function HopeGiftModel:SetHopeGiftInfo( scmd )
- self.hopeGift_info[scmd.sub_type] = {}
- local new_get_list = {}
- for k,v in pairs(scmd.get_id) do
- new_get_list[v.award_id] = v
- end
- scmd.get_list = new_get_list
- 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
- scmd.get_list = {}
- scmd.round = scmd.round + 1
- end
-
- local is_buy_num = 0--买礼包数量
- local already_get_list = {}
- for k,v in pairs(scmd.already_get_list) do
- already_get_list[v.grade_id] = v
- end
- scmd.already_get_list = already_get_list
- scmd.lucky_status = 2--默认是抽奖状态2 领取钥匙状态1 当前轮次已结束3
-
- --这里要创建奖励页签相关数据
- local base_type = CustomActivityModel.CustomActBaseType.HOPE_GIFT
- local act_list = CustomActivityModel:getInstance():getActList(base_type,scmd.sub_type)
-
- if not act_list or not act_list.condition_list then return end
- local cost_id = 102350
- for k,v in pairs(act_list.condition_list) do
- if v[1] == "draw_cost" then--返利最大值
- cost_id = tonumber(v[2][1])
- break
- end
- end
- local sub_type_list = CustomActivityModel:getInstance():getOneActRewardList(base_type,scmd.sub_type)
- local tab_list = {}--创建页签信息
- tab_list[1] = {id = 0}--第一个默认是主页签不存在奖励数据
- if TableSize(sub_type_list) > 0 then
- local return_total_sum_num = 0--返回钥匙总数
- local return_have_sum_num = 0--剩余返回总数
- local have_buy = false-- 是否购买过
- for i,v in ipairs(sub_type_list.reward_list) do
- v.id = tonumber(v.grade)
- for k,vv in pairs(v.condition_list) do
- if vv[1] == "return_total" then--返利最大值
- v.return_total = tonumber(vv[2][2])
- return_total_sum_num = return_total_sum_num + v.return_total
- cost_id = tonumber(vv[2][1])
- elseif vv[1] == "original_price" then--原价
- v.original_price = tonumber(vv[2])
- elseif vv[1] == "hopegift_cost" then--现价
- v.hopegift_cost = tonumber(vv[2])
- elseif vv[1] == "return_day" then--每日返回
- v.return_day = tonumber(vv[2][2])
- elseif vv[1] == "show" then
- v.model_data = vv
- end
- end
- table.insert(tab_list, v)
- if not have_buy then
- have_buy = v.status == 2--已购买
- end
- is_buy_num = is_buy_num + (v.status == 2 and 1 or 0)
- end
- local sortFunc = function (a, b)--根据阶级排序 可领取排前面
- return a.id < b.id
- end
- table.sort(tab_list, sortFunc)
- local return_day_sum_num = 0--今日可领取的钥匙数量
- for i,v in ipairs(tab_list) do
- if i ~= 1 then
- if scmd.already_get_list[v.grade] then
- return_have_sum_num = return_have_sum_num + v.return_total - scmd.already_get_list[v.grade].get_num
- 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
- return_day_sum_num = return_day_sum_num + v.return_day
- end
- end
- end
- end
-
- scmd.return_total_sum_num = return_total_sum_num--返回钥匙总数
- scmd.return_day_sum_num = return_day_sum_num--剩余返回总数
- scmd.return_have_sum_num = return_have_sum_num
- scmd.cost_id = cost_id
- scmd.tab_list = tab_list
- scmd.have_buy = have_buy
- scmd.round_award_over = TableSize(scmd.get_list) < 18
- print("huangcong:HopeGiftModel [start:194] :", is_buy_num)
- scmd.is_buy = is_buy_num>=4--是否已购买4个
- scmd.is_buy_num = is_buy_num
- end
- self.hopeGift_info[scmd.sub_type] = scmd
- self:CheckHopeGiftRedDot(scmd.sub_type)
- end
-
- --检查臻享礼包红点
- function HopeGiftModel:CheckHopeGiftRedDot( sub_type )
- if not sub_type then return end
- local show = false
- local server_info = self:GetHopeGiftInfo(sub_type)
- if server_info and server_info.return_day_sum_num then
- if server_info.return_day_sum_num > 0 then--今日可领取的钥匙大于0
- show = true
- end
- if not show then
- show = server_info.is_buy and server_info.day_lucky_limit ~= 1
- end
- end
-
- if not show and self:CheckActIsOpen(sub_type) and self.login_red then
- show = true
- end
- self.red_info_list[sub_type] = show
-
- local is_find = false
- for i,v in pairs(self.act_base_list) do
- if v.sub_type == sub_type then
- is_find = true
- break
- end
- end
- if not is_find then--构造活动数据 有红点也要有活动数据
- self:GetTabInfo()
- end
- end
-
- function HopeGiftModel:GetHopeGiftRedDot( sub_type )
- if HopeGiftModel:getInstance():CheckActIsOpen(sub_type) then
- return self.red_info_list[sub_type] or false
- else
- return false
- end
- end
-
- function HopeGiftModel:GetHopeGiftInfo( sub_type )
- return self.hopeGift_info[sub_type]
- end
-
- --得到臻享礼包配置
- function HopeGiftModel:GetHopeGiftCfg( sub_type,round )
- if not sub_type and not round then return end
- if sub_type and not round then
- return self.hopeGift_cfg[sub_type]
- elseif sub_type and round and self.hopeGift_cfg[sub_type] then
- return self.hopeGift_cfg[sub_type][round]
- end
- end
-
- --得到臻享礼包奖励展示配置
- function HopeGiftModel:GetHopeGiftAwardShow( sub_type )
- return self.hopeGift_show_cfg[sub_type]
- end
-
- --是否在抽奖动画
- function HopeGiftModel:GetHopeGiftIsAction( sub_type )
- if not sub_type then
- for k,v in pairs(self.is_action) do
- if v then
- return true
- end
- end
- end
- return self.is_action and self.is_action[sub_type]
- end
-
- function HopeGiftModel:SetHopeGiftIsAction( is_action,sub_type )
- if not self.is_action then
- self.is_action = {}
- end
- self.is_action[sub_type] = is_action
- end
-
- --得到当前是否打开臻享礼包界面
- function HopeGiftModel:GetCurIsOpenView( )
- return self.is_open_view
- end
-
- function HopeGiftModel:SetCurIsOpenView( is_open_view )
- self.is_open_view = is_open_view
- end
-
- --检查当前能否飞道具
- function HopeGiftModel:CheckCurCanFlyGoods( )
- if self.is_open_view then
- return false
- end
- return true
- end
-
- --检查活动是否开启
- function HopeGiftModel:CheckActIsOpen( sub_type )
- if #self.act_base_list == 0 then return false end
- local is_lock = true
- for i,v in pairs(self.act_base_list) do
- if v.sub_type == sub_type then
- is_lock = false
- break
- end
- end
- if is_lock then return false end
-
- local base_type = CustomActivityModel.CustomActBaseType.HOPE_GIFT
- local sub_type_list = CustomActivityModel:getInstance():getOneActRewardList(base_type,sub_type)
- if not sub_type_list then return end
- local award_can_buy = false
- if sub_type_list and sub_type_list.reward_list then
- for k,v in pairs(sub_type_list.reward_list) do--有未购买的奖励
- if v.status == 1 then
- award_can_buy = true
- break
- end
- end
- end
- if award_can_buy then
- return true
- end
- local server_info = self:GetHopeGiftInfo(sub_type)
- if not server_info or not server_info.return_have_sum_num then return false end
- if server_info.return_have_sum_num > 0 then
- return true
- elseif server_info.return_have_sum_num <= 0 then--返利总数小于等于0则判断奖励是否没有领完
- return 18 - TableSize(server_info.get_list) > 0
- end
- end
-
- --设置传闻数据
- function HopeGiftModel:SetChuanwenInfo( scmd,type )
- self.chuanwen_cfg = {scmd,type}
- end
-
- function HopeGiftModel:PlayChuanwenInfo( )
- if self.chuanwen_cfg and self.chuanwen_cfg[1] then
- GlobalEventSystem:Fire(EventName.RECEIVE_NEW_CHUANWEN, self.chuanwen_cfg[1], self.chuanwen_cfg[2])
- self.chuanwen_cfg = nil
- end
- end
|