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

628 lines
20 KiB

SakuraGiftModel = SakuraGiftModel or BaseClass(BaseVo, true)
local SakuraGiftModel = SakuraGiftModel
SakuraGiftModel.REQUEST_CCMD_EVENT = "SakuraGiftModel.REQUEST_CCMD_EVENT"
SakuraGiftModel.REFRESH_ACT_INFO = "SakuraGiftModel.REFRESH_ACT_INFO"--基础信息更新
SakuraGiftModel.REFRESH_RECORD_INFO = "SakuraGiftModel.REFRESH_RECORD_INFO"--记录信息
SakuraGiftModel.REFRESH_SHOP_INFO = "SakuraGiftModel.REFRESH_SHOP_INFO" -- 刷新商店信息
SakuraGiftModel.OPEN_BASE_VIEW = "SakuraGiftModel.OPEN_BASE_VIEW"--主界面
-- SakuraGiftModel.OPEN_EXCHANGE_VIEW = "SakuraGiftModel.OPEN_EXCHANGE_VIEW"--兑换商城界面
SakuraGiftModel.OPEN_SHOP_VIEW = "SakuraGiftModel.OPEN_SHOP_VIEW"--兑换商城界面
SakuraGiftModel.OPEN_EXCHANGE_REQ_VIEW = "SakuraGiftModel.OPEN_EXCHANGE_REQ_VIEW"--兑换数目界面
SakuraGiftModel.OPEN_MESSAGE_VIEW = "SakuraGiftModel.OPEN_MESSAGE_VIEW" -- 打开滚屏界面
SakuraGiftModel.OPEN_REWARD_VIEW = "SakuraGiftModel.OPEN_REWARD_VIEW" -- 打开奖励预览
SakuraGiftModel.UPDATE_CHUANWEN = "SakuraGiftModel.UPDATE_CHUANWEN" -- 更新记录
SakuraGiftModelRedType = {
Login = 1, -- 每天首次登陆
Exchange = 2, -- 最后5小时可兑换红点
CanGo = 3, -- 抽奖红点
LoginExchange = 4, -- 首次登陆兑换红点
}
local NeedCheckExchangeRedTime = 18000
function SakuraGiftModel:__init()
SakuraGiftModel.Instance = self
self:Reset()
end
function SakuraGiftModel:Reset()
self.act_info = {}
self.shop_info = {}
self.base_type = CustomActivityModel.CustomActBaseType.SAKURA_GIFT
self.exchange_red = {}
self.login_exchange_red = {}
self.login_red = {}
self.can_go_red = {}
self.sub_type_list = {}
self.time_id_list = {}
end
function SakuraGiftModel:getInstance()
if SakuraGiftModel.Instance == nil then
SakuraGiftModel.Instance = SakuraGiftModel.New()
end
return SakuraGiftModel.Instance
end
function SakuraGiftModel:GetKeyValueConf( suit,key )
if not self.Sakuragiftkey_Cfg then
self:InitSakuragiftkeyCfg( )
end
return (self.Sakuragiftkey_Cfg[suit] and self.Sakuragiftkey_Cfg[suit][key])
and self.Sakuragiftkey_Cfg[suit][key].value or nil
end
function SakuraGiftModel:InitSakuragiftkeyCfg( )
self.Sakuragiftkey_Cfg = {}
for k,v in pairs(Config.Sakuragiftkey) do
self.Sakuragiftkey_Cfg[v.suit] = self.Sakuragiftkey_Cfg[v.suit] or {}
self.Sakuragiftkey_Cfg[v.suit][Trim(v.key)] = v
end
end
--获取套装id
function SakuraGiftModel:GetSuitIdBySubType( sub_type )
local suit_id = 0
local act_list = CustomActivityModel:getInstance():getActList(self.base_type, sub_type)
if act_list and act_list.condition_list then
for k,v in ipairs(act_list.condition_list) do
if v[1] == "suit" then
suit_id = v[2]
break
end
end
end
if suit_id == 0 then
--找不到条件的话就取最小值
suit_id = 99999
for k,v in pairs(Config.Sakuragiftkey) do
suit_id = suit_id > v.suit and v.suit or suit_id
end
end
return tonumber(suit_id)
end
function SakuraGiftModel:GetShowModelData( sub_type )
local act_list = CustomActivityModel:getInstance():getActList(self.base_type, sub_type)
if act_list and act_list.condition_list then
for k,v in ipairs(act_list.condition_list) do
if v[1] == "show" then
return v
end
end
end
end
function SakuraGiftModel:GetActInfo( sub_type )
return self.act_info[sub_type]
end
function SakuraGiftModel:SetActInfo( value )
self.act_info[value.sub_type] = value
if value.score then -- 更新积分
self.shop_info[value.sub_type].score = value.score
end
end
function SakuraGiftModel:GetShopInfo( sub_type )
return self.shop_info[sub_type]
end
function SakuraGiftModel:SetShopInfo( value )
self.shop_info[value.sub_type] = value
if value.goods_list then
local sort_func = function ( a, b )
local conf_a = Config.Sakuragiftpointreward[a.reward_id]
local conf_b = Config.Sakuragiftpointreward[b.reward_id]
if conf_a and conf_b and conf_a.limit and conf_a.limit then
local release_num_a = conf_a.limit - a.times
local release_num_b = conf_b.limit - b.times
if release_num_a == 0 and release_num_b ~= 0 then
return false
elseif release_num_b == 0 and release_num_a ~= 0 then
return true
else
return a.reward_id < b.reward_id
end
end
end
table.sort(value.goods_list, sort_func)
end
end
function SakuraGiftModel:RefreshShopOneInfo( data )
local is_find = false
if self.shop_info[data.sub_type] then
self.shop_info[data.sub_type].score = data.score
for k,v in pairs(self.shop_info[data.sub_type].goods_list) do
if v.reward_id == data.reward_id then
local conf = Config.Sakuragiftpointreward[v.reward_id]
if conf.limit - data.times > 0 then -- 还有兑换次数就才直接刷数目
v.times = data.times
is_find = true
end
break
end
end
end
return is_find
end
--检测活动图标是否需要开启
function SakuraGiftModel:CheckIconBoolOpen(sub_type)
local base_type = self.base_type
local sub_type = sub_type
local level = RoleManager.Instance.mainRoleInfo.level
local act_list = CustomActivityModel:getInstance():getActList(base_type, sub_type)
local icon_sub_type = base_type*1000 + sub_type
if sub_type >= 10001 then
icon_sub_type = base_type*100000 + sub_type
end
if act_list and act_list.etime then
local end_time = 0
end_time = act_list.etime - TimeUtil:getServerTime()
local open_lv = 0
for k,v in pairs(act_list.condition_list) do
if v[1] == "role_lv" then
open_lv = tonumber(v[2])
end
end
is_open = end_time > 0 and level >= open_lv
if GetModuleIsOpen(331,base_type) then
if end_time > 0 and is_open then
self:SetDelayTimeList(sub_type) -- 活动结束前5小时红点
ActivityIconManager:getInstance():addIcon(icon_sub_type, end_time)
-- 检查一下活动期间首次登陆红点
-- local list = self:GetFirstLoginCookie( )
-- if not list[sub_type] or list[sub_type] ~= act_list.etime then -- 没缓存或缓存的不是这次活动
-- self:SetFirstLoginRed( true ) -- 首次登陆
-- end
table.insert(self.sub_type_list, sub_type)
else
ActivityIconManager:getInstance():deleteIcon(icon_sub_type)
end
end
else
ActivityIconManager:getInstance():deleteIcon(icon_sub_type)
end
end
--获取当前免费次数
function SakuraGiftModel:GetFreeTime( sub_type )
local free_num = 0
local act_info = self:GetActInfo( sub_type )
if act_info then
local use_time = act_info.use_free_times
local max_free = self:GetKeyValueConf( self:GetSuitIdBySubType(sub_type), "free_time" )
free_num = max_free - use_time
free_num = free_num > 0 and free_num or 0
end
return free_num
end
-- 获取展示在主界面的奖励数据
-- 奖励物品展示去奖池奖励,极品奖励取2个,珍稀奖励取4个,普通奖励取4个
-- 同奖池内根据奖励ID取数字小的,如数量不足,则极品奖励取珍稀奖励补充,珍稀奖励取普通奖励补充
-- tag--标签 2-极品 1-珍稀 0-普通
function SakuraGiftModel:GetMainShowRewardList( sub_type )
local show_list = {}
local temp_list = {}
if not sub_type then return show_list end
if self.main_show_list and self.main_show_list[sub_type] then -- 拿过了就拿缓存
return self.main_show_list[sub_type]
end
-- 先数据处理
for k,v in pairs(Config.Sakuragiftreward) do
if v.act_id == sub_type then
temp_list[v.tag] = temp_list[v.tag] or {}
table.insert( temp_list[v.tag], v)
end
end
-- 同奖池内根据奖励ID取数字小的
local function sort_call( a,b )
return a.id < b.id
end
for k,v in pairs(temp_list) do
table.sort( v, sort_call )
end
-- 开始拿展示的数据
for i=1, 10 do
if i >= 1 and i <= 2 then -- 两个极品
start_tag = 2
elseif i >= 3 and i <= 6 then -- 四个珍稀
start_tag = 1
else
start_tag = 0
end
for tag=start_tag, 0, -1 do
if temp_list[tag] then
for ii, v in ipairs(temp_list[tag]) do
show_list[i] = table.remove(temp_list[tag], ii)
break
end
end
if show_list[i] then
break
end
end
-- 遍历完都没有奖励 奖励数量都不够10个 撤退
if not show_list[i] then
break
end
end
self.main_show_list = self.main_show_list or {}
self.main_show_list[sub_type] = show_list
return show_list
end
-- 获取奖励展示里面
-- TIPS: main_show_list2 是奖励详情里展示的 main_show_list 是主界面展示的
function SakuraGiftModel:GetAwardListBySubtype( sub_type )
local show_list = {}
local temp_list = {}
if not sub_type then return show_list end
if self.main_show_list2 and self.main_show_list2[sub_type] then -- 拿过了就拿缓存
-- for k,v in ipairs(self.main_show_list2[sub_type]) do
-- table.insert(show_list, stringtotable(v.awards)[1])
-- end
-- return show_list
for k,v in pairs(self.main_show_list2[sub_type]) do
for ii,vv in ipairs(v) do
show_list[k] = show_list[k] or {}
table.insert(show_list[k], stringtotable(vv.awards)[1])
end
end
return show_list
end
for k,v in pairs(Config.Sakuragiftreward) do
if v.act_id == sub_type then
-- table.insert(temp_list, v)
temp_list[v.tag] = temp_list[v.tag] or {}
table.insert(temp_list[v.tag], v)
end
end
-- 同奖池内根据奖励ID取数字小的
local function sort_call( a,b )
return a.id < b.id
end
for k,v in pairs(temp_list) do
table.sort( v, sort_call )
end
-- local sort_func = function ( a, b )
-- if a.tag == b.tag then
-- return a.tag > b.tag
-- else
-- return a.id < b.id
-- end
-- end
-- table.sort(temp_list, sort_func)
self.main_show_list2 = self.main_show_list2 or {}
self.main_show_list2[sub_type] = temp_list
for k,v in pairs(self.main_show_list2[sub_type]) do
for ii,vv in ipairs(v) do
show_list[k] = show_list[k] or {}
table.insert(show_list[k], stringtotable(vv.awards)[1])
end
end
return show_list
end
-- tag 1珍稀 2极品
function SakuraGiftModel:GetTagByItemId(item_id )
if not self.tag_item_id_cache then
self.tag_item_id_cache = {}
for k,v in pairs(Config.Sakuragiftreward) do
if v.tag ~= 0 then
self.tag_item_id_cache[v.tag] = self.tag_item_id_cache[v.tag] or {}
local awards = stringtotable(v.awards)
self.tag_item_id_cache[v.tag][tonumber(awards[1][2])] = true
end
end
end
local item_id = tonumber(item_id)
if self.tag_item_id_cache[1][item_id] then
return 27
elseif self.tag_item_id_cache[2][item_id] then
return 28
end
end
-- 展示获得界面 33401
function SakuraGiftModel:ShowGetRewardView( scmd_reward_list )
local temp_list = {}
for i,v in ipairs(scmd_reward_list) do
local state = self:GetTagByItemId(v.reward_id)
temp_list[#temp_list + 1] = {100, v.reward_id, v.num, state}
end
if #temp_list > 0 then
GiftModel:getInstance():Fire(GiftModel.OPEN_SHOW_ACT_GOODS_VIEW, temp_list)
end
end
----------红点-start---------
function SakuraGiftModel:GoodsChangeCheck( )
if #self.sub_type_list > 0 then
for k,v in pairs(self.sub_type_list) do
self:CheckRedByType(SakuraGiftModelRedType.CanGo, v)
end
end
end
function SakuraGiftModel:CheckSakuraGiftMainRedDot( sub_type )
local base_type = CustomActivityModel.CustomActBaseType.SAKURA_GIFT
if not sub_type then return end
local icon_sub_type = base_type*1000 + sub_type
if sub_type >= 10001 then
icon_sub_type = base_type*100000 + sub_type
end
local act_list = CustomActivityModel:getInstance():getActList(base_type, sub_type)
if not act_list then
return
else
local bool = self:GetAllRed( sub_type )
GlobalEventSystem:Fire(ActivityIconManager.UPDATE_ICON_TIPS, icon_sub_type, bool)
end
end
-- 这个拿红点会顺便刷一遍红点缓存
function SakuraGiftModel:CheckAllRed( sub_type )
local bool1 = self:CheckLoginRed(sub_type) -- 首次登陆红点
local bool2 = self:CheckExchangeRed(sub_type) -- 最后5小时可兑换红点
local bool3 = self:CheckCanGoRed(sub_type) -- 抽奖红点
local bool4 = self:CheckLoginExchangeRed(sub_type) -- 首次登陆兑换红点
self:CheckSakuraGiftMainRedDot( sub_type ) -- 刷新一下总按钮红点
return bool1 or bool2 or bool3 or bool4
end
-- 这个是拿总红点缓存 不会刷新的
function SakuraGiftModel:GetAllRed( sub_type )
local bool1 = self:GetLoginRed(sub_type) -- 首次登陆红点
local bool2 = self:GetExchangeRed(sub_type) -- 最后5小时可兑换红点
local bool3 = self:GetCanGoRed(sub_type) -- 抽奖红点
local bool4 = self:GetLoginExchangeRed(sub_type) -- 首次登陆兑换红点
return bool1 or bool2 or bool3 or bool4
end
-- 根据红点类型单个更新红点缓存
function SakuraGiftModel:CheckRedByType(red_type, sub_type)
local bool
if red_type == SakuraGiftModelRedType.Login then
bool = self:CheckLoginRed(sub_type)
elseif red_type == SakuraGiftModelRedType.Exchange then
bool = self:CheckExchangeRed(sub_type)
elseif red_type == SakuraGiftModelRedType.CanGo then
bool = self:CheckCanGoRed(sub_type)
elseif red_type == SakuraGiftModelRedType.LoginExchange then
bool = self:CheckLoginExchangeRed(sub_type)
end
self:CheckSakuraGiftMainRedDot( sub_type ) -- 刷新一下总按钮红点
self:Fire(SakuraGiftModel.REFRESH_ACT_INFO)
return bool
end
----------------------------------------------
-- 抽奖红点 (有免费次数 或 有道具)
function SakuraGiftModel:CheckCanGoRed( sub_type )
local suit_id = self:GetSuitIdBySubType(sub_type)
local conf = stringtotable(self:GetKeyValueConf( suit_id, "pray_one" ))[1]
local good_num = GoodsModel:getInstance():GetTypeGoodsNum(conf[2])
self.can_go_red[sub_type] = good_num > 0 or self:GetFreeTime( sub_type ) > 0
return self.can_go_red[sub_type] == true
end
function SakuraGiftModel:GetCanGoRed( sub_type )
return self.can_go_red[sub_type]
end
-------------------------------------------------
-- 检查是否有可以兑换的物品
function SakuraGiftModel:CheckCanExchange( sub_type )
local shop_info = self:GetShopInfo( sub_type )
if not shop_info then return end
local score = shop_info.score
if not score or score == 0 then
return false
end
for k,v in pairs(shop_info.goods_list) do
local conf = Config.Sakuragiftpointreward[v.reward_id]
if conf.limit - v.times > 0 and score >= conf.points then
return true
end
end
return false
end
-- 检查兑换红点
function SakuraGiftModel:CheckExchangeRed( sub_type )
local bool = false
local base_type = self.base_type
local sub_type = sub_type or CustomActivityModel:getInstance():getActMinSubType(base_type)
local act_list = CustomActivityModel:getInstance():getActList(base_type, sub_type)
local is_last_day = false
if act_list and act_list.etime then
local end_time = 0
end_time = act_list.etime - TimeUtil:getServerTime()
if end_time > 0 and end_time <= NeedCheckExchangeRedTime then -- 剩余5小时
is_last_day = true
else
return false
end
end
self.exchange_red[sub_type] = is_last_day and self:CheckCanExchange(sub_type)
return self.exchange_red[sub_type]
end
function SakuraGiftModel:GetExchangeRed( sub_type )
return self.exchange_red[sub_type] == true
end
--------------------------------------------------
-- 当前有可以兑换道具首次登陆时给红点
function SakuraGiftModel:CheckLoginExchangeRed( sub_type )
local list = self:GetLoginExchangeCookie() or {}
if list[sub_type] == true then
self.login_exchange_red[sub_type] = false
else
self.login_exchange_red[sub_type] = self:CheckCanExchange(sub_type)
end
return self.login_exchange_red[sub_type]
end
function SakuraGiftModel:GetLoginExchangeRed( sub_type )
return self.login_exchange_red[sub_type]
end
function SakuraGiftModel:SetLoginExchangeRed( sub_type, bool )
if self.login_exchange_red[sub_type] and bool == false then
self.login_exchange_red[sub_type] = false
self:SetLoginExchangeCookie( sub_type, true ) -- 今天点开过了
self:CheckRedByType(SakuraGiftModelRedType.LoginExchange, sub_type)
end
end
-- 每天首次登陆兑换红点cookie
function SakuraGiftModel:SetLoginExchangeCookie( sub_type, bool )
local list = self:GetLoginExchangeCookie() or {}
list[sub_type] = bool
CookieWrapper.Instance:SaveCookie(CookieLevelType.Account,
CookieTimeType.TYPE_DAY2, CookieKey.SAKURA_GIFT_FIRST_EXCHANGE_RED, list)
CookieWrapper.Instance:WriteAll()
end
--每天首次登陆兑换红点cookie
function SakuraGiftModel:GetLoginExchangeCookie( )
local list = CookieWrapper.Instance:GetCookie(CookieLevelType.Account,
CookieKey.SAKURA_GIFT_FIRST_EXCHANGE_RED) or {}
return list
end
---------------------------------------
-- 每天首次登陆红点cookie
function SakuraGiftModel:SetLoginCookie( sub_type, bool )
local list = self:GetLoginCookie() or {}
list[sub_type] = bool
CookieWrapper.Instance:SaveCookie(CookieLevelType.Account,
CookieTimeType.TYPE_DAY2, CookieKey.SAKURA_GIFT_FIRST_LOGIN_RED, list)
CookieWrapper.Instance:WriteAll()
end
--每天首次登陆红点cookie
function SakuraGiftModel:GetLoginCookie( )
local list = CookieWrapper.Instance:GetCookie(CookieLevelType.Account,
CookieKey.SAKURA_GIFT_FIRST_LOGIN_RED) or {}
return list
end
-- 当前有可以兑换道具首次登陆时给红点
function SakuraGiftModel:CheckLoginRed( sub_type )
local list = self:GetLoginCookie() or {}
if list[sub_type] == true then
self.login_red[sub_type] = false
else
self.login_red[sub_type] = true
end
return self.login_red[sub_type]
end
function SakuraGiftModel:GetLoginRed( sub_type )
return self.login_red[sub_type]
end
function SakuraGiftModel:SetLoginRed( sub_type, bool )
if self.login_red[sub_type] and bool == false then
self.login_red[sub_type] = false
self:SetLoginCookie( sub_type, true ) -- 今天点开过了
self:CheckRedByType(SakuraGiftModelRedType.Login, sub_type)
end
end
------------------------------------------------------
--[[-- 活动期间首次登陆指引红点cookie
function SakuraGiftModel:SetFirstLoginCookie( sub_type, time )
local list = self:GetFirstLoginCookie() or {}
list[sub_type] = time
CookieWrapper.Instance:SaveCookie(CookieLevelType.Account,
CookieTimeType.TYPE_ALWAYS, CookieKey.SAKURA_GIFT_FIRST_LOGIN_RED,list)
CookieWrapper.Instance:WriteAll()
end
--活动期间首次登陆指引红点
function SakuraGiftModel:GetFirstLoginCookie( )
local list = CookieWrapper.Instance:GetCookie(CookieLevelType.Account,
CookieKey.SAKURA_GIFT_FIRST_LOGIN_RED) or {}
return list
end
-- 活动期间首次登陆指引红点
function SakuraGiftModel:SetFirstLoginRed( sub_type, bool )
self.first_login_red = self.first_login_red or {}
self.first_login_red[sub_type] = bool
if bool == false then
local base_type = self.base_type
local sub_type = sub_type or CustomActivityModel:getInstance():getActMinSubType(base_type)
local act_list = CustomActivityModel:getInstance():getActList(base_type, sub_type)
local is_last_day = false
if act_list and act_list.etime then
self:SetFirstLoginCookie( sub_type, act_list.etime )
end
end
end
function SakuraGiftModel:GetFirstLoginRed( sub_type )
return self.first_login_red[sub_type]
end--]]
----------红点-end-----------
----------界面内跑马传闻-start---------
function SakuraGiftModel:InitMessage( )
self.chuan_wen_info = {}
end
function SakuraGiftModel:AppendNoticeMsg( str )
self.chuan_wen_info[#self.chuan_wen_info + 1] = str
end
function SakuraGiftModel:GetChuanwenInfo( )
return self.chuan_wen_info or {}
end
----------界面内跑马传闻-end-----------
function SakuraGiftModel:SetDelayTimeList( sub_type )
if self.time_id_list[sub_type] then
GlobalTimerQuest:CancelQuest(self.time_id_list[sub_type])
self.time_id_list[sub_type] = nil
end
local base_type = CustomActivityModel.CustomActBaseType.SAKURA_GIFT
local act_list = CustomActivityModel:getInstance():getActList(base_type, sub_type) or {}
if not act_list then return end
local end_time = act_list.etime
local haly_hour = NeedCheckExchangeRedTime
local sec = end_time - TimeUtil:getServerTime()
if sec > 0 then
local function onTimer()
sec = end_time - TimeUtil:getServerTime()
if sec <= haly_hour then--五小时有可以兑换的要给予红点且所有奖励有未购买完的
if self.time_id_list[sub_type] then
GlobalTimerQuest:CancelQuest(self.time_id_list[sub_type])
self.time_id_list[sub_type] = nil
end
self:CheckRedByType(SakuraGiftModelRedType.Exchange, sub_type)
if self.time_id_list[sub_type] then
GlobalTimerQuest:CancelQuest(self.time_id_list[sub_type])
self.time_id_list[sub_type] = nil
end
end
end
if not self.time_id_list[sub_type] then
self.time_id_list[sub_type] = GlobalTimerQuest:AddPeriodQuest(onTimer, 10, -1)
end
onTimer()
end
end