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

952 lines
39 KiB

-- <*
-- @Author: Saber
-- @Description: 经验快车模块Model,用于处理BaseDungeonController返回的数据和红点刷新逻辑
-- *>
ExpDunModel = ExpDunModel or BaseClass(BaseVo, true)
local ExpDunModel = ExpDunModel
local Config = Config
local TimeUtil = TimeUtil
-- 协议事件
ExpDunModel.UPDATE_QUICKHANGUP_DATA = "ExpDunModel.UPDATE_QUICKHANGUP_DATA" -- 更新快速挂机信息(61051)
ExpDunModel.UPDATE_HANGUP_VIEW = "ExpDunModel.UPDATE_HANGUP_VIEW" -- 更新快速挂机界面(61050领取成功后更新按钮和进度
ExpDunModel.UPDATE_HANGUP_RATIO = "ExpDunModel.UPDATE_HANGUP_RATIO" -- 更新挂机效率加成
-- 界面事件
ExpDunModel.OPEN_EXP_HANGUP_MAIN_VIEW = "ExpDunModel.OPEN_EXP_HANGUP_MAIN_VIEW" -- 打开经验挂机主界面
ExpDunModel.OPEN_QUICK_HANGUP_VIEW = "ExpDunModel.OPEN_QUICK_HANGUP_VIEW" -- 打开经验快车挂机购买界面
ExpDunModel.OPEN_HANGUP_RECEIVE_VIEW = "ExpDunModel.OPEN_HANGUP_RECEIVE_VIEW" -- 打开经验快车挂机奖励领取界面
ExpDunModel.CHECK_OPEN_HANGUP_RECEIVE_VIEW = "ExpDunModel.CHECK_OPEN_HANGUP_RECEIVE_VIEW" -- 检查经验快车挂机奖励领取界面的打开
ExpDunModel.CHANGE_MAINVIEW_ROUTE = "ExpDunModel.CHANGE_MAINVIEW_ROUTE" -- 更换主界面路线
ExpDunModel.UPDATE_EXP_ICON_RED = "ExpDunModel.UPDATE_EXP_ICON_RED" -- 更新经验快车主入口按钮红点
ExpDunModel.UPDATE_EXP_RED_BY_REDTYPE = "ExpDunModel.UPDATE_EXP_RED_BY_REDTYPE" -- 根据红点类型更新红点
ExpDunModel.UPDATE_HANGUP_RECEIVE_TIME = "ExpDunModel.UPDATE_HANGUP_RECEIVE_TIME" -- 更新放置挂机领取时间
ExpDunModel.UPDATE_MAINUI_EXP_TIP = "ExpDunModel.UPDATE_MAINUI_EXP_TIP" -- 更新主界面入口按钮tips
-- 第三版经验副本重构添加
ExpDunModel.UPDATE_EXP_HANGUP_TENMIN_RED = "ExpDunModel.UPDATE_EXP_HANGUP_TENMIN_RED" -- 刷新经验副本十分钟挂机红点
ExpDunModel.SHOW_MS_REWARD = "ExpDunModel.SHOW_MS_REWARD" -- 显示里程碑奖励
ExpDunModel.SHOW_HANGUP_ACTION = "ExpDunModel.SHOW_HANGUP_ACTION" -- 播放放置挂机动画
ExpDunModel.SHOW_QUICK_HANGUP_ACTION = "ExpDunModel.SHOW_QUICK_HANGUP_ACTION" -- 播放快速挂机动画
ExpDunModel.UPDATE_EXP_DUN_BTN = "ExpDunModel.UPDATE_EXP_DUN_BTN" -- 更新主界面的入口状态
ExpDunModel.OPEN_WAVE_RANK_VIEW = "ExpDunModel.OPEN_WAVE_RANK_VIEW" -- 更新榜单前三头像数据
ExpDunModel.UPDATE_WAVE_RANK_DATA = "ExpDunModel.UPDATE_WAVE_RANK_DATA" -- 更新榜单数据
ExpDunModel.UPDATE_WAVE_TOPTHREE_HEAD_DATA = "ExpDunModel.UPDATE_WAVE_TOPTHREE_HEAD_DATA" -- 更新榜单前三头像数据
ExpDunModel.Red_Type = {
HangUp = 1, -- 放置挂机奖励满的红点
Milestone = 2, -- 里程碑奖励红点
QuickHangUp = 3, -- 快速挂机充能完成红点
First_Login = 4, -- 当日首次登录红点
Offline = 5, -- 离线经验加成相关红点
Sweep = 6, -- 今日可扫荡的红点
}
ExpDunModel.Newly_Limit_Lv = 100 -- 限制红点的等级
ExpDunModel.Newly_Limit_Taskid = 10710 -- 限制红点的任务id
ExpDunModel.OfflineGoodsId = 102120 -- 离线加成卡id
function ExpDunModel:__init()
ExpDunModel.Instance = self
self:Reset()
end
function ExpDunModel:Reset()
self.route_cfg_data = nil
self.exp_kv_cfg = nil -- 经验快车常量配置表
self.max_count = 0 -- 快速挂机最大可领取次数
self.use_count = 0 -- 快速挂机已领取次数
self.hangup_last_receive_time = 0 -- 上次领取放置挂机奖励的时间
self.hangup_offline_exp = 0 -- 离线挂机额外增加的经验值
self.hangup_rest_offline_time = 0 -- 离线挂机经验加成的剩余时长
self.hangup_contain_exp_time = 0 -- 已累计的挂机时间
self.update_contain_exp_time_time_stamp = 0 -- 更新已累计的挂机时间时的时间戳
-- self.hangup_last_receive_time_cache = 0 -- 上次领取放置挂机奖励的缓存时间(51协议有可能比50协议来的快,要做一次缓存)
-- self.wait_61050 = false -- 上次领取放置挂机奖励的缓存时间(51协议有可能比50协议来的快,要做一次缓存)
self.quick_hangup_last_receive_time = 0 -- 上次领取快速挂机奖励的时间
self.exp_cache_red = {} -- 经 验 高 级 轿 车 红 点
self.main_route_data = nil -- 主界面路线节点数据
self.milestone_data_list = nil
self.milestone_data_by_route = {}
self.exp_ratio = 10000 -- 经验挂机效率系数(万分比)
-- 动画model缓存
self.main_bg_roll_uvRect = UnityEngine.Rect.New(0, 0, 1, 1)
self.main_bg_roll_back_uvRect = UnityEngine.Rect.New(0, 0, 1, 1)
-- 主界面按钮状态 0:无状态 1:放置挂机奖励or里程碑奖励 2:快速挂机CD完成 3:下一关战力满足推荐战力
self.mainui_exp_tip_type = 0
self:GetMilestoneData()
self._need_open_exp_view = false -- 设置标志量,返回大世界的时候判断是否打开主界面
self.check_quick_hangup = true -- 检查快速挂机购买类型1的二级界面
-- 特殊变量
self.hangup_ten_min_red = false -- 距离上次领取放置挂机奖励已经过去10分钟
self.limit_exp_dun_newly_red = false -- 新手阶段限制一定等级内的红点表现
self.login_hangup_view_flag = true -- 登录时自动弹出挂机领取界面的标志量
-- 经验副本的规格为:单个副本为波次wave,n个波次组成一条线路route,n条线路组成一个章节chapter
self.exp_dun_route_data = nil -- 经验副本线路数据
self.exp_dun_chapter_data = nil -- 经验副本章节波数范围数据
self.exp_mainview_route_ms_red = {} -- 经验副本主界面里程碑页码红点缓存
end
function ExpDunModel:getInstance()
if self.Instance == nil then
self.Instance = ExpDunModel.New()
end
return self.Instance
end
-- 初始化经验快车常量配置表
function ExpDunModel:GetExpDunConfig(key)
if not self.exp_kv_cfg then
self.exp_kv_cfg = {}
local temp_key
for k, v in pairs(Config.Expdundropkv) do
temp_key = Trim(v.key)
self.exp_kv_cfg[temp_key] = v
end
end
return self.exp_kv_cfg[key] or nil
end
-- 获得挂机时间配置的上限 需要结合宠物的生活技能
function ExpDunModel:GetHangupResourceLimitTime( )
--宠物生活技能 冒险挂机累计时间提高
local life_skill_active = PetModel:getInstance():IsLifeSkillActived(PetConst.LifeSkill.ExpOnHookTimeUp)
local life_skill_ratio = PetModel:getInstance():GetPetLifeSkillRatio(PetConst.LifeSkill.ExpOnHookTimeUp)
if life_skill_active and life_skill_ratio then
return life_skill_ratio
else
local res_cfg = self:GetExpDunConfig("resource_limit")
return res_cfg and res_cfg.value or 0
end
end
-- 是否已经通关经验副本
function ExpDunModel:IsPassAllExpDun( )
local cur_wave = self:GetCurrentWave()
return cur_wave >= #Config.Expdunwave
end
function ExpDunModel:GetWaveStr( wave )
if not wave then return "" end
if wave == 0 then return "尚未通关" end
local str = string.format("第%s波", wave)
return str
end
-- 根据当前波数,获取最接近该波数的下一个关键点的坐标相关配置 force_next:该点是关键点也要获取下一个关键点,默认true
function ExpDunModel:GetNextMainPointByWave( wave, force_next )
if not wave then return nil end
-- 可能会出现玩家没打过但是查看里程碑的情况,这个时候默认给第一波
local new_wave = wave > 0 and wave or 1
-- 也不能爆波次
local total_wave = TableSize(Config.Expdunwave)
new_wave = new_wave <= total_wave and new_wave or total_wave
local cfg = Config.Expdunwave[new_wave]
force_next = force_next == nil and true or force_next
while(cfg.type ~= 1 or (cfg.wave == wave and force_next)) do
new_wave = new_wave + 1
cfg = Config.Expdunwave[new_wave]
end
return cfg
end
-- 获取里程碑数据 route:若传入路线数,则获取改路线下的里程碑点
function ExpDunModel:GetMilestoneData(route)
if not self.milestone_data_list then
self.milestone_data_list = {}
local reward
for k, v in pairs(Config.Expdunwave) do
reward = stringtotable(v.achieve_rewards)
if not IsTableEmpty(reward) then -- 有奖励的都是里程碑
v.reward = reward
self.milestone_data_list[#self.milestone_data_list+1] = v
end
end
local sort_func = function ( a, b )
return a.wave < b.wave
end
table.sort(self.milestone_data_list, sort_func)
end
if route then
if not self.milestone_data_by_route[route] then
local route_cfg = self:GetExpRouteData(route)
local tb = {}
if route_cfg then
for k, v in ipairs(self.milestone_data_list) do
if v.wave >= route_cfg.min_wave and v.wave <= route_cfg.max_wave then
tb[#tb+1] = v
end
end
self.milestone_data_by_route[route] = tb
end
end
return self.milestone_data_by_route[route] or {}
else
return self.milestone_data_list
end
end
-- 获取主界面路线节点数据
function ExpDunModel:GetMainRouteData( )
if not self.main_route_data then
self.main_route_data = {}
local temp_tb, temp_tb_normal = {}, {}
local reward
for k, v in ipairs(Config.Expdunwave) do
reward = stringtotable(v.achieve_rewards)
if IsTableEmpty(reward) then
temp_tb_normal[#temp_tb_normal + 1] = v
else
temp_tb.ms_data = v
temp_tb.normal_data = temp_tb_normal
self.main_route_data[#self.main_route_data + 1] = temp_tb
temp_tb, temp_tb_normal = {}, {}
end
end
end
return self.main_route_data
end
-- 获取经验快车的快速挂机协议返回数据 61051
function ExpDunModel:GetExpDunQuickHangUpData( vo )
self.max_count = vo.max_count
self.use_count = vo.use_count
self.quick_hangup_last_receive_time = vo.time
end
-- 获取快速挂机次数
function ExpDunModel:GetHangUpTimeCount( )
return self.max_count, self.use_count
end
-- 获取上次购买快速挂机奖励的时间
function ExpDunModel:GetQuickHangUpReceiveTime( )
return self.quick_hangup_last_receive_time
end
-- 获取经验快车的放置挂机上次领取时间 61052
function ExpDunModel:SetExpDunHangUpData( vo )
-- if self.wait_61050 then
-- self.hangup_last_receive_time_cache = vo.time
-- else
self.hangup_last_receive_time = vo.time
self.hangup_offline_exp = vo.offline_exp
self.hangup_rest_offline_time = vo.rest_offline_time
self.hangup_contain_exp_time = vo.time_last
self.update_contain_exp_time_time_stamp = TimeUtil:getServerTime()
-- end
end
-- 获取上次领取放置挂机奖励的时间
function ExpDunModel:GetHangUpReceiveTime( )
return self.hangup_last_receive_time
end
function ExpDunModel:GetHangUpContainTimeData( )
local hangup_contain_exp_time_cul = 0
-- 记录了当前挂机累计时间的时间戳的情况下才可以计算真实的已累计的挂机时间
if self.update_contain_exp_time_time_stamp ~= 0 then
hangup_contain_exp_time_cul = TimeUtil:getServerTime() - self.update_contain_exp_time_time_stamp + self.hangup_contain_exp_time
end
return hangup_contain_exp_time_cul, self.hangup_contain_exp_time, self.update_contain_exp_time_time_stamp
end
function ExpDunModel:GetHangUpOfflineData( )
return self.hangup_offline_exp, self.hangup_rest_offline_time
end
-- 更新完领取放置挂机奖励后,刷新一次上次领取奖励的时间缓存
-- function ExpDunModel:UpdateHangUpCache( )
-- if self.wait_61050 then
-- self.hangup_last_receive_time = self.hangup_last_receive_time_cache
-- self.wait_61050 = false
-- -- 更新了数据要追加推送
-- self:Fire(ExpDunModel.UPDATE_HANGUP_RECEIVE_TIME)
-- end
-- end
-- 获取快速挂机基础经验值
function ExpDunModel:GetBuyExpBasicExpCfg( lv )
lv = lv or RoleManager.Instance.mainRoleInfo.level
return Config.Fastonhookreward[lv] or nil
end
-- 获取经验副本挂机加成系数 61053
function ExpDunModel:SetExpHangUpRatio(vo)
if not vo then return end
self.exp_ratio = vo.exp_ratio
end
function ExpDunModel:GetExpHangUpRatio( )
return self.exp_ratio or 10000
end
function ExpDunModel:GetExpRedByRedType(red_type)
if self.limit_exp_dun_newly_red then return false end -- 2020年8月14日新增,特殊条件限制红点表现
return red_type and self.exp_cache_red[red_type] or false
end
function ExpDunModel:CheckExpRedDotAll( )
if self.limit_exp_dun_newly_red then -- 2020年8月14日新增,特殊条件限制红点表现
self.exp_cache_red[ExpDunModel.Red_Type.HangUp] = false
self.exp_cache_red[ExpDunModel.Red_Type.Milestone] = false
self.exp_cache_red[ExpDunModel.Red_Type.QuickHangUp] = false
self.exp_cache_red[ExpDunModel.Red_Type.First_Login] = false
self.exp_cache_red[ExpDunModel.Red_Type.Offline] = false
self.exp_cache_red[ExpDunModel.Red_Type.Sweep] = false
self.hangup_ten_min_red = false
self.login_hangup_view_flag = false
else
local module_open = GetModuleIsOpen(610, BaseDungeonModel.DUN_TYPE.EXP, 2)
local quick_hangup_module_open = GetModuleIsOpen(610, BaseDungeonModel.DUN_TYPE.EXP, 15)
local hangup_module_open = GetModuleIsOpen(610, BaseDungeonModel.DUN_TYPE.EXP, 16)
self.exp_cache_red[ExpDunModel.Red_Type.HangUp] = module_open and hangup_module_open and self:UpdateHangUpRed()
self.exp_cache_red[ExpDunModel.Red_Type.Milestone] = module_open and self:GetMilestoneRed()
self.exp_cache_red[ExpDunModel.Red_Type.QuickHangUp] = module_open and quick_hangup_module_open and self:GetQuickHangUpRed()
self.exp_cache_red[ExpDunModel.Red_Type.First_Login] = module_open and self:GetFirstLoginRed()
self.exp_cache_red[ExpDunModel.Red_Type.Offline] = module_open and hangup_module_open and self:GetExpOfflineTimeRed()
self.exp_cache_red[ExpDunModel.Red_Type.Sweep] = module_open and self:GetExpSweepRed()
end
self:Fire(ExpDunModel.UPDATE_EXP_RED_BY_REDTYPE)
self:CheckExpDunIconRed()
end
-- 检查经验快车的红点 red_type:红点类型
function ExpDunModel:CheckExpRedDot( red_type, skip_main_icon )
local bool = false
if not self.limit_exp_dun_newly_red then -- 2020年8月14日新增,特殊条件限制红点表现
local module_open = GetModuleIsOpen(610, BaseDungeonModel.DUN_TYPE.EXP)
if module_open then
if red_type == ExpDunModel.Red_Type.HangUp then
bool = self:UpdateHangUpRed()
elseif red_type == ExpDunModel.Red_Type.Milestone then
bool = self:GetMilestoneRed()
elseif red_type == ExpDunModel.Red_Type.QuickHangUp then
bool = self:GetQuickHangUpRed()
elseif red_type == ExpDunModel.Red_Type.First_Login then
bool = self:GetFirstLoginRed()
elseif red_type == ExpDunModel.Red_Type.Offline then
bool = self:GetExpOfflineTimeRed()
elseif red_type == ExpDunModel.Red_Type.Sweep then
bool = self:GetExpSweepRed()
end
end
end
self.exp_cache_red[red_type] = bool
-- 挂机的红点在计时器里面刷,就不在这里刷了
-- if red_type ~= ExpDunModel.Red_Type.HangUp and red_type ~= ExpDunModel.Red_Type.QuickHangUp then
self:Fire(ExpDunModel.UPDATE_EXP_RED_BY_REDTYPE, red_type, bool)
-- end
if not skip_main_icon then
self:CheckExpDunIconRed()
end
return bool
end
function ExpDunModel:CheckExpDunIconRed(get_red)
local bool = false
if not self.limit_exp_dun_newly_red then -- 2020年8月14日新增,特殊条件限制红点表现
for k, v in pairs(self.exp_cache_red) do
bool = bool or v
if bool then
break
end
end
end
local buff_kind = OperateActivityModel.MaterialSubmitBuffKind.ADVENTURE_EXP --是否存在活动加成buff 免费收取一次二倍
local buff_cfg,buff_info = OperateActivityModel:getInstance():GetMaterialBuffInfoByKind(buff_kind)
if buff_cfg and buff_info then
local sec = buff_info.etime - TimeUtil:getServerTime( )
if sec > 0 then
local have_time = 1
for k,v in pairs(buff_info.used) do
if v.kdata == 1 and v.vdata == 1 then--buff有一次免费二倍
have_time = 0
break
end
end
if have_time >= 1 then
bool = true
end
end
end
if get_red then
return bool
else
-- self:Fire(ExpDunModel.UPDATE_EXP_ICON_RED, bool)--暂时屏蔽2021 1 21
end
end
function ExpDunModel:UpdateHangUpRed( )
self:ClearHangUpRedTimer()
local last_time = self:GetHangUpReceiveTime()
local contain_time = self:GetHangUpContainTimeData()
-- 沒有上一次领取记录则代表没得领,直接返回false
if last_time <= 0 then
return false
end
local cur_wave = self:GetCurrentWave()
-- 一波都没打过直接返回false
if cur_wave <= 0 then
self.login_hangup_view_flag = false
return false
end
local bool = false
local update_tips = 0 -- 更新主界面tips阶段 0:未达到条件, 1:更新一次, 2:已更新,不再刷新
local update_ten_min = 0 -- 更新挂机十分钟的红点 0:还没更新, 1:不满足条件 2:满足条件
-- local pass_time
-- 获取满挂机奖励时间配置,单位小时
local need_time = self:GetHangupResourceLimitTime() * 3600
local function hang_up_red_timer(send_evt)
-- pass_time = TimeUtil:getServerTime() - last_time
contain_time = self:GetHangUpContainTimeData()
bool = contain_time >= 3600
if update_tips ~= 2 then
update_tips = contain_time >= 3600 and 1 or 0 -- 若达到最低限度可领阶段,则改变主界面领取tips
end
self.exp_cache_red[ExpDunModel.Red_Type.HangUp] = bool
if send_evt or bool then
self:Fire(ExpDunModel.UPDATE_EXP_RED_BY_REDTYPE, ExpDunModel.Red_Type.HangUp, bool)
end
if bool then -- 红点更新后就停止刷新
self:ClearHangUpRedTimer()
end
if update_tips == 1 then
self:SetMainUIExpTipType(self.limit_exp_dun_newly_red and 0 or 1)
update_tips = 2
self:Fire(ExpDunModel.UPDATE_MAINUI_EXP_TIP)
end
if contain_time >= 3600 then
if update_ten_min ~= 2 then
self.hangup_ten_min_red = true
update_ten_min = 2
self:Fire(ExpDunModel.UPDATE_EXP_HANGUP_TENMIN_RED, self.hangup_ten_min_red)
end
else
if update_ten_min ~= 1 then
self.hangup_ten_min_red = false
update_ten_min = 1
self:Fire(ExpDunModel.UPDATE_EXP_HANGUP_TENMIN_RED, self.hangup_ten_min_red)
end
end
end
-- 这里更新频率保持跟配置一致
local duration = self:GetExpDunConfig("goods_drop_interval").value
self.hang_up_red_timer_id = GlobalTimerQuest:AddPeriodQuest(hang_up_red_timer, duration, -1)
hang_up_red_timer(true)
if self.login_hangup_view_flag then
-- print("Saber:ExpDunModel [379] contain_time: ",contain_time)
if contain_time >= 3600 then -- 存在红点了,自动弹出挂机领取界面
local function open_hangup_login_callback( )
BaseDungeonModel:getInstance():Fire(BaseDungeonModel.REQUEST_CCMD_EVENT, 61050, 0, 0)
end
self:ClearHangupLoginCallbackId()
-- 登录触发,加载界面结束后弹出
self.open_hangup_login_callback_id = GlobalEventSystem:Bind(EventName.SCENE_LOAD_VIEW_COMPLETE, open_hangup_login_callback)
-- setTimeout(delay_method, 3)
end
self.login_hangup_view_flag = false
end
return bool
end
function ExpDunModel:ClearHangUpRedTimer( )
if self.hang_up_red_timer_id then
GlobalTimerQuest:CancelQuest(self.hang_up_red_timer_id)
self.hang_up_red_timer_id = nil
end
end
function ExpDunModel:ClearHangupLoginCallbackId( )
if self.open_hangup_login_callback_id then
GlobalEventSystem:UnBind(self.open_hangup_login_callback_id)
self.open_hangup_login_callback_id = nil
end
end
-- 获取经验副本十分钟放置挂机红点
function ExpDunModel:GetExpDunHangupTenMinRed( )
return self.hangup_ten_min_red
end
-- 里程碑红点
function ExpDunModel:GetMilestoneRed( )
local reward_data = BaseDungeonModel:getInstance():GetDunWaveRewardData(BaseDungeonModel.EXP_DUN_ID)
if not reward_data then return false end
local bool = false
-- 存在未领取的奖励直接提示红点
for k, v in pairs(reward_data) do
bool = bool or v == 0
end
self:UpdateMainRouteMilestoneRedByPages()
return bool
end
-- 根据波数,获取该波数所在的章节数
function ExpDunModel:GetExpDunWaveChapter(wave)
local chapter = 1
local legal = false
if wave then
wave = wave <= 0 and 1 or wave
local route_data = self:GetWaveRouteData(wave)
legal = route_data and true or false
chapter = route_data and route_data.chapter
end
return chapter, legal
end
function ExpDunModel:GetExpDUnwaveChapterData(wave)
wave = wave or self:GetCurrentWave()
local chapter, legal = self:GetExpDunWaveChapter(wave)
local chapter_cfg = nil
if legal then
chapter_cfg = Config.Expdunchapter[chapter]
end
return chapter_cfg
end
-- 坑爹功能,通过固定的主界面里程碑页码缓存红点
function ExpDunModel:UpdateMainRouteMilestoneRedByPages( )
self.exp_mainview_route_ms_red = {}
local reward_data = BaseDungeonModel:getInstance():GetDunWaveRewardData(BaseDungeonModel.EXP_DUN_ID)
if not reward_data then return end
local route_data = self:GetMainRouteData()
local data_num = #route_data
local total_pages = math.ceil(data_num / 4)
for k = 1, total_pages do
for j = 1, 4 do
local real_index = (k - 1) * 4 + j
real_index = real_index > data_num and data_num or real_index
local ms_wave = route_data[real_index].ms_data.wave
if reward_data[ms_wave] and reward_data[ms_wave] == 0 then
self.exp_mainview_route_ms_red[k] = true
end
end
end
end
function ExpDunModel:GetMainRouteMilestoneRedByPages(page)
return self.exp_mainview_route_ms_red[page] or false
end
-- 获取战斗力是否满足下一波的推荐战力
function ExpDunModel:GetNextWaveFitPowerRed( )
if self.limit_exp_dun_newly_red then return false end -- 2020年8月14日新增,特殊条件限制红点表现
-- 判断当前波次的下一波是否达到推荐战斗力
local power = RoleManager.Instance.mainRoleInfo.fighting
local cur_wave = self:GetCurrentWave()
-- 判断下一波副本会不会爆配置
local next_wave = cur_wave < TableSize(Config.Expdunwave) and cur_wave + 1 or cur_wave
if cur_wave ~= next_wave then
local next_wave_cfg = Config.Expdunwave[next_wave]
local next_power = next_wave_cfg.power_limit or 999999999999
if power >= next_power then
return true
end
end
return false
end
-- 判断当前等级是否可以继续挑战经验副本
function ExpDunModel:GetNextWaveFitLevel( )
local level = RoleManager.Instance.mainRoleInfo.level
local cur_wave = self:GetCurrentWave()
-- 判断下一波副本会不会爆配置
local next_wave = cur_wave < TableSize(Config.Expdunwave) and cur_wave + 1 or cur_wave
local next_wave_cfg = Config.Expdunwave[next_wave]
return next_wave_cfg and next_wave_cfg.lv_limit <= level or false
-- local chapter_cfg = self:GetExpDUnwaveChapterData(next_wave)
-- return chapter_cfg and chapter_cfg.min_lv <= level or false
end
-- 快速挂机红点
function ExpDunModel:GetQuickHangUpRed( )
self:ClearQuickHangUpTimer()
local quick_hangup_module_open = GetModuleIsOpen(610, BaseDungeonModel.DUN_TYPE.EXP, 15)
if not quick_hangup_module_open then return false end
local max_count, use_count = self:GetHangUpTimeCount()
local buff_kind = OperateActivityModel.MaterialSubmitBuffKind.ADVENTURE_EXP --是否存在活动加成buff 免费收取一次二倍
local buff_cfg,buff_info = OperateActivityModel:getInstance():GetMaterialBuffInfoByKind(buff_kind)
local have_buff_free_time = 0
if buff_cfg and buff_info then
have_buff_free_time = 1
local sec = buff_info.etime - TimeUtil:getServerTime( )
if sec > 0 then
for k,v in pairs(buff_info.used) do
if v.kdata == 1 and v.vdata == 1 then--buff有一次免费二倍
have_buff_free_time = 0
break
end
end
end
end
-- 没次数直接返回false
if use_count >= max_count + have_buff_free_time then return false end
local last_time = self:GetQuickHangUpReceiveTime()
-- 如果没领取记录则直接返回false
if last_time <= 0 then return false end
local bool = false
local pass_time, percentage
-- 加载当前等级的配置
local hangup_exp_cfg = self:GetBuyExpBasicExpCfg()
local function quick_hangup_timer(send_evt)
pass_time = TimeUtil:getServerTime() - last_time
bool = hangup_exp_cfg and pass_time > hangup_exp_cfg.time or false
if send_evt or bool then
self.exp_cache_red[ExpDunModel.Red_Type.QuickHangUp] = bool
self:Fire(ExpDunModel.UPDATE_EXP_RED_BY_REDTYPE, ExpDunModel.Red_Type.QuickHangUp, bool)
self:Fire(ExpDunModel.UPDATE_EXP_ICON_RED, bool)
self:UpdateMainUIExpTipType()
self:Fire(ExpDunModel.UPDATE_MAINUI_EXP_TIP)
end
if bool then -- 红点更新后就停止刷新
self:ClearQuickHangUpTimer()
end
end
self.quick_hangup_timer_id = GlobalTimerQuest:AddPeriodQuest(quick_hangup_timer, 5, -1)
quick_hangup_timer(true)
return bool
end
function ExpDunModel:ClearQuickHangUpTimer( )
if self.quick_hangup_timer_id then
GlobalTimerQuest:CancelQuest(self.quick_hangup_timer_id)
self.quick_hangup_timer_id = nil
end
end
function ExpDunModel:GetFirstLoginRed( )
local bool = false
local last_time = self:GetHangUpReceiveTime()
-- 沒有上次领取记录则直接返回false
if last_time == 0 then return false end
-- 获取今日凌晨4点的时间戳
local date = os.date("*t", TimeUtil:getServerTime())
local today_four_oclock = os.time({year=date.year,month=date.month,day=date.day,hour=4,min=0,sec=0})
-- 如果上次结算时间是今天凌晨四点前,则为true
return last_time < today_four_oclock
end
-- 经验副本离线加成卡时间红点
function ExpDunModel:GetExpOfflineTimeRed( )
local bool = false
-- 没道具就没红点
local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(ExpDunModel.OfflineGoodsId)
if goods_num <= 0 then return bool end
local offline_exp, rest_offline_time = self:GetHangUpOfflineData()
local time_limit = self:GetExpDunConfig("time_limit").value
-- 剩余加成时间可扩充时间超过6小时就有红点
bool = time_limit - rest_offline_time > 21600 -- 3600 * 6
return bool
end
-- 经验副本扫荡红点
function ExpDunModel:GetExpSweepRed( )
local dun_data = BaseDungeonModel:getInstance():GetDunProtoInfo(BaseDungeonModel.DUN_TYPE.EXP)
local bool = false
if dun_data and dun_data[1] then
for k, v in pairs(dun_data[1].rec_data) do
if v.key == 13 then
bool = v.val == 0
break
end
end
end
return bool
end
function ExpDunModel:SetMainUIExpTipType(value)
self.mainui_exp_tip_type = value
end
-- 缓存主界面经验副本按钮tips状态
function ExpDunModel:UpdateMainUIExpTipType( )
-- 主界面按钮状态 0:无状态 1:放置挂机奖励or里程碑奖励 2:快速挂机CD完成 3:下一关战力满足推荐战力
-- print("Saber:ExpDunModel [545] self.limit_exp_dun_newly_red: ",self.limit_exp_dun_newly_red)
if self.limit_exp_dun_newly_red then -- 限制红点阶段,剔除功能表现
self:SetMainUIExpTipType(0)
return
end
-- 若已达到最高优先级且没有被重置,则不处理
if self.mainui_exp_tip_type == 1 then
return
else
-- 放置挂机的情况在放置挂机红点逻辑那边强制更新,这边只处理里程碑领取情况,直接获取里程碑红点即可
if self:GetExpRedByRedType(ExpDunModel.Red_Type.Milestone) or self:GetExpRedByRedType(ExpDunModel.Red_Type.HangUp) then
self:SetMainUIExpTipType(1)
return
end
-- 判断快速挂机cd,直接获取快速挂机红点即可
if self:GetExpRedByRedType(ExpDunModel.Red_Type.QuickHangUp) then
self:SetMainUIExpTipType(2)
return
end
-- 判断下一关是否达到推荐战力
self:UpdateMainTipsOnChangePowerOrWave(false, true)
end
end
-- 当战力或当前最高波次更新时刷新主界面tips force:强制刷新
function ExpDunModel:UpdateMainTipsOnChangePowerOrWave(send_evt, force)
if self.limit_exp_dun_newly_red then -- 限制红点阶段,剔除功能表现
self:SetMainUIExpTipType(0)
if send_evt then
self:Fire(ExpDunModel.UPDATE_MAINUI_EXP_TIP)
end
return
end
-- 如果不是无状态且前面得两种情况满足一个则不处理
if self.mainui_exp_tip_type ~= 0 and self.mainui_exp_tip_type ~= 3 then return end
local function refresh_func()
-- 有可能外面进来之后,这边的延迟更新进行的时候mainui_exp_tip_type已经发生改变,需要再次检测
if self.mainui_exp_tip_type ~= 0 and self.mainui_exp_tip_type ~= 3 then return end
local exp_sweep_red = self:GetExpRedByRedType(ExpDunModel.Red_Type.Sweep)
local fit_power_and_level = self:GetNextWaveFitPowerRed() and self:GetNextWaveFitLevel()
if exp_sweep_red or fit_power_and_level then -- 存在扫荡或者可挑战时,显示3类型
self:SetMainUIExpTipType(3)
else
-- 所有的情况都不满足,检测是否可以使用离线加成道具
if self:GetExpRedByRedType(ExpDunModel.Red_Type.Offline) then
self:SetMainUIExpTipType(4)
else
self:SetMainUIExpTipType(0)
end
end
if send_evt then
self:Fire(ExpDunModel.UPDATE_MAINUI_EXP_TIP)
end
end
if force then
refresh_func()
else
TimeManager.GetInstance():StartTime("ExpDunModel_UpdateMainTipsOnChangePowerOrWave", 5, refresh_func)
end
end
-- 获取主界面经验副本按钮tips状态
function ExpDunModel:GetMainUIExpTipType( )
return self.mainui_exp_tip_type
end
-- 当前登录不再弹出快速挂机类型1的购买二次确认界面
function ExpDunModel:GetQuickHangupTypeOneFlag( )
return self.check_quick_hangup
end
function ExpDunModel:UncheckQuickHangupTypeOne( )
self.check_quick_hangup = false
end
-- 根据上次领取自动挂机的时间来推算一个随机的动画阶段
function ExpDunModel:GetRandomAnimStatusAndData( )
-- 上次挂机领取时间
local last_receive_time = TimeUtil:getServerTime() - self.hangup_last_receive_time
-- 每个阶段的大概时间
local status1_time = ExpDunAnimConst.Stage1_Time
local status2_time = ExpDunAnimConst.SlayBulletEffectWaitTime + ExpDunAnimConst.SlayBulletEffectDmgWaitTime * 5
local status3_time = ExpDunAnimConst.Run_Stage_Time
local total_status_time = status1_time + status2_time + status3_time
-- 轮转阶段的剩余时间
local temp_status_time = last_receive_time % total_status_time
local status, status_data
if temp_status_time < status1_time then -- 处于第一阶段
status = 1
elseif temp_status_time < status1_time + status2_time then -- 处于第二阶段中,需要算一个随机值和剩余时间
status = 2
status_data = {}
local status_pass_time = temp_status_time - status1_time
status_data.status_pass_time = status_pass_time
-- 构建随机血量数据
status_data.hp_data = {}
for i = 1, 3 do
status_data.hp_data[i] = math.ceil(math.random(70, 90) * (1 - status_pass_time / status2_time)) + 10
math.randomseed(os.time())
end
else
status = 3
end
return status, status_data
end
-- 特殊红点处理,在第一次引导之后直到n级之前都不会出现红点和挂机提醒
function ExpDunModel:CheckExpDunLimitNewlyRed( )
self.limit_exp_dun_newly_red = false
if TaskModel:getInstance():IsTaskFinished(ExpDunModel.Newly_Limit_Taskid) -- 经验副本任务
and RoleManager.Instance.mainRoleInfo.level < ExpDunModel.Newly_Limit_Lv then -- 限制等级
self.limit_exp_dun_newly_red = true
end
return self.limit_exp_dun_newly_red
end
function ExpDunModel:GetExpDunLimitNewlyRed( )
return self.limit_exp_dun_newly_red
end
-- 根据当前波数获取期望掉落配置
function ExpDunModel:GetExpDunExpectDropCfg(wave)
wave = wave or self:GetCurrentWave()
local role_lv = RoleManager.Instance.mainRoleInfo.level
local career = RoleManager.Instance.mainRoleInfo.career
local tb = {}
for k, v in pairs(Config.Expdunexpectdrop) do
-- 需满足波数范围和玩家等级范围
if v.min_wave <= wave and v.max_wave >= wave
and v.min_lv <= role_lv and v.max_lv >= role_lv then
local reward_list = stringtotable(v.rewards)
for k2, reward in ipairs(reward_list) do
if reward[1] == 0 or reward[1] == career then -- 筛选出全职业和本职业的道具
tb[#tb+1] = reward[2]
end
end
break
end
end
return tb
end
-- 获取挂机经验效率(配置中的单位是经验/分) compute_efficiency:计算加成效率
function ExpDunModel:GetExpEfficiency( wave, compute_efficiency )
wave = wave or self:GetCurrentWave()
local basic_eff = Config.Onhookexpeffiency[wave] and Config.Onhookexpeffiency[wave].effiency or 0
if compute_efficiency then
local ratio = self:GetExpHangUpRatio()
basic_eff = basic_eff * ratio / 10000
end
return math.floor(basic_eff)
end
-- 获取当前经验快车所在波数(即最佳记录
function ExpDunModel:GetCurrentWave( )
local dun_data = BaseDungeonModel:getInstance():GetDunProtoInfo(BaseDungeonModel.DUN_TYPE.EXP)
local cur_wave = 0
if dun_data and dun_data[1] then
for k, v in pairs(dun_data[1].rec_data) do
if v.key == 3 then
cur_wave = v.val
break
end
end
end
return cur_wave
end
-- 获取对应波次所在的路线数据 wave:当前波数,不传的话会读取当前打到的波数来计算下一波关卡的路线数据
function ExpDunModel:GetWaveRouteData( wave )
if not wave then
wave = self:GetCurrentWave() + 1
end
-- 增加容错,不能超过配置最高波数
local total_wave = TableSize(Config.Expdunwave)
-- print("Saber:ExpDunModel [650] total_wave: ",total_wave)
wave = wave <= total_wave and wave or total_wave
for k, v in pairs(Config.Expdunline) do
if v.min_wave <= wave and v.max_wave >= wave then
return v
end
end
return nil
end
-- 获取经验副本路线数据
function ExpDunModel:GetExpRouteData(route)
if not self.exp_dun_route_data then
self.exp_dun_route_data = {}
for k, v in pairs(Config.Expdunline) do
self.exp_dun_route_data[#self.exp_dun_route_data+1] = v
end
local sort_func = function ( a, b )
return a.id < b.id
end
table.sort(self.exp_dun_route_data, sort_func)
end
if route then
return self.exp_dun_route_data[route]
else
return self.exp_dun_route_data
end
end
function ExpDunModel:GetExpChapterData(chapter)
if not self.exp_dun_chapter_data then
self.exp_dun_chapter_data = {}
local temp_tb
for k, v in pairs(Config.Expdunline) do
temp_tb = self.exp_dun_chapter_data[v.chapter]
or {
chapter = v.chapter,
min_wave = v.min_wave,
max_wave = v.max_wave,
}
temp_tb.min_wave = temp_tb.min_wave > v.min_wave and v.min_wave or temp_tb.min_wave
temp_tb.max_wave = temp_tb.max_wave < v.max_wave and v.max_wave or temp_tb.max_wave
self.exp_dun_chapter_data[v.chapter] = temp_tb
end
end
if chapter then
return self.exp_dun_chapter_data[chapter]
else
return self.exp_dun_chapter_data
end
end
--更新玩家放置冒险获得1次免费2倍速(不计入消耗次数)BUFF状态
function ExpDunModel:UpdateQuickHangUpFreeBuffState( )
local buff_kind = OperateActivityModel.MaterialSubmitBuffKind.ADVENTURE_EXP --是否存在活动加成buff 挑战次数+1
local buff_cfg,buff_info = OperateActivityModel:getInstance():GetMaterialBuffInfoByKind(buff_kind)
if buff_cfg and buff_info then
local sec = buff_info.etime - TimeUtil:getServerTime( )
local have_time = 1
for k,v in pairs(buff_info.used) do
if v.kdata == 1 and v.vdata == 1 then--buff有一次免费二倍
have_time = 0
break
end
end
if have_time >= 1 and sec > 0 then
self:CheckExpDunIconRed()
local sec = buff_info.etime - TimeUtil:getServerTime( )
self:ActBuffTimeLate(sec)
else
if self.act_buff_timer_id then
GlobalTimerQuest:CancelQuest(self.act_buff_timer_id)
self.act_buff_timer_id = nil
end
end
end
end
--buff结束后刷新boss红点
function ExpDunModel:ActBuffTimeLate( sec )
if self.act_sec == sec then
return
else
self.act_sec = sec
end
if self.act_buff_timer_id then
GlobalTimerQuest:CancelQuest(self.act_buff_timer_id)
self.act_buff_timer_id = nil
end
local sec = sec or 0
if sec > 0 then
local function onTimer()
sec = sec - 1
if sec > 0 then
else
self:CheckExpDunIconRed()
GlobalTimerQuest:CancelQuest(self.act_buff_timer_id)
self.act_buff_timer_id = nil
end
end
if not self.act_buff_timer_id then
self.act_buff_timer_id = GlobalTimerQuest:AddPeriodQuest(onTimer, 1, -1)
end
onTimer()
else
self:CheckExpDunIconRed()
end
end
-- 检查离线加成卡的数量
function ExpDunModel:CheckOfflineGoodsNum( )
self:CheckExpRedDot(ExpDunModel.Red_Type.Offline)
self:SetMainUIExpTipType(0)
self:UpdateMainUIExpTipType()
self:Fire(ExpDunModel.UPDATE_MAINUI_EXP_TIP)
end