445 lines
12 KiB
Lua
445 lines
12 KiB
Lua
local BountyData = class("BountyData", BaseData)
|
|
|
|
-- local ACT_BATTLE_PASS = ConfigManager:getConfig("act_battle_pass")
|
|
-- local ACT_BATTLE_PASS_TASK = ConfigManager:getConfig("act_battle_pass_task")
|
|
-- local MALL_ACT = ConfigManager:getConfig("mall_act")
|
|
local BOUNTY_TYPE = 8
|
|
|
|
function BountyData:getTimeStr()
|
|
local endTime = self:getEndTime()
|
|
local remainTime = endTime - Time:getServerTime()
|
|
if remainTime < 0 then
|
|
remainTime = 0
|
|
end
|
|
return Time:formatNumTimeStr(remainTime)
|
|
end
|
|
|
|
function BountyData:getRp()
|
|
return self:getTaskRp() or self:getLevelRp()
|
|
end
|
|
|
|
function BountyData:gotoBtnFunc()
|
|
ModuleManager.BountyManager:showUI()
|
|
end
|
|
|
|
function BountyData:getIsOpen()
|
|
if not ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.BATTLE_PASS, true) then
|
|
return false
|
|
end
|
|
if self.endTime and self.endTime > 0 and self.endTime > Time:getServerTime() then
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
|
|
function BountyData:ctor()
|
|
self:clear()
|
|
end
|
|
|
|
function BountyData:clear()
|
|
self.season = 1
|
|
self.level = 1
|
|
self.exp = 0
|
|
self.bought = false
|
|
self.highCount = 0
|
|
self.count = 0
|
|
self.tasks = {}
|
|
self.weekRefreshTime = 0
|
|
self.maxLevel = nil
|
|
self.data.isDirty = false
|
|
DataManager:unregisterCrossDayFunc("BountyData")
|
|
end
|
|
|
|
function BountyData:setDirty()
|
|
self.data.isDirty = not self.data.isDirty
|
|
end
|
|
|
|
function BountyData:init(data, isInit)
|
|
-- data = data or {}
|
|
|
|
-- self.season = data.season or 1
|
|
-- self.level = data.level or 1
|
|
-- self.exp = data.exp or 0
|
|
-- self.bought = data.bought or false
|
|
-- self.tasks = data.tasks or {}
|
|
-- self.highCount = data.pro_claimed or 0
|
|
-- self.count = data.claimed or 0
|
|
-- self.maxLevel = nil
|
|
|
|
-- self.weekRefreshTime = Time:getWeekOverTimeStamp()
|
|
|
|
-- self:initFuncTime()
|
|
|
|
-- if isInit then
|
|
-- self:initTaskListener()
|
|
-- DataManager:registerCrossDayFunc("BountyData", function()
|
|
-- local needRefreshWeek = self.weekRefreshTime < Time:getServerTime()
|
|
-- self.weekRefreshTime = Time:getWeekOverTimeStamp()
|
|
-- local list = self:getTaskList()
|
|
-- for _, id in ipairs(list) do
|
|
-- if self:getTaskIsDailyRefresh(id) or needRefreshWeek then
|
|
-- self:getTaskInfo(id).progress = 0
|
|
-- self:getTaskInfo(id).claimed = false
|
|
-- end
|
|
-- end
|
|
-- self:initFuncTime()
|
|
-- self:setDirty()
|
|
-- end)
|
|
-- end
|
|
end
|
|
|
|
function BountyData:getBannerName()
|
|
return "bounty_btn_main_1"
|
|
end
|
|
|
|
function BountyData:refreshTask(task)
|
|
if not task then
|
|
return
|
|
end
|
|
self.tasks[task.id] = task
|
|
end
|
|
|
|
function BountyData:refreshLevelRewardInfo(data)
|
|
if not data then
|
|
return
|
|
end
|
|
self.highCount = data.pro_claimed or 0
|
|
self.count = data.claimed or 0
|
|
end
|
|
|
|
function BountyData:refreshLevelInfo(data)
|
|
if not data then
|
|
return
|
|
end
|
|
self.level = data.level or 0
|
|
self.exp = data.exp or 0
|
|
end
|
|
|
|
function BountyData:setBoughtStatus(data)
|
|
if not data then
|
|
return
|
|
end
|
|
self.bought = data.bought or false
|
|
end
|
|
|
|
function BountyData:initFuncTime()
|
|
if not self.seasonList then
|
|
self.seasonList = {}
|
|
for id, info in pairs(MALL_ACT) do
|
|
if info.type == BOUNTY_TYPE then
|
|
table.insert(self.seasonList, id)
|
|
end
|
|
end
|
|
|
|
table.sort(self.seasonList, function(a, b)
|
|
return a < b
|
|
end)
|
|
end
|
|
|
|
local nowTime = Time:getServerTime()
|
|
if self.endTime and self.endTime > 0 and self.endTime > nowTime then
|
|
return
|
|
end
|
|
|
|
if (not self.endTime or self.endTime <= nowTime) and self.season then
|
|
local cfg = MALL_ACT[self.season]
|
|
if cfg then
|
|
self.startTime = Time:getCertainTimeByStr2(cfg.start_time)
|
|
self.endTime = Time:getCertainTimeByStr2(cfg.end_time)
|
|
end
|
|
end
|
|
|
|
if not self.endTime or self.endTime <= nowTime then
|
|
for _, id in ipairs(self.seasonList) do
|
|
local cfg = MALL_ACT[id]
|
|
local startTime = Time:getCertainTimeByStr2(cfg.start_time)
|
|
local endTime = Time:getCertainTimeByStr2(cfg.end_time)
|
|
if startTime <= nowTime and endTime > nowTime then
|
|
self.startTime = startTime
|
|
self.endTime = endTime
|
|
self.season = id
|
|
self.bought = false
|
|
self.level = 1
|
|
self.exp = 0
|
|
self.highCount = 0
|
|
self.count = 0
|
|
self.maxLevel = nil
|
|
BIReport:postBattlePassOpen()
|
|
break
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function BountyData:getEndTime()
|
|
return self.endTime or 0
|
|
end
|
|
|
|
function BountyData:getSeasonRewardList()
|
|
if not self.seasonRewardList then
|
|
self.seasonRewardList = {}
|
|
for id, info in pairs(ACT_BATTLE_PASS) do
|
|
local season = info.mall_id
|
|
if not self.seasonRewardList[season] then
|
|
self.seasonRewardList[season] = {}
|
|
end
|
|
table.insert(self.seasonRewardList[season], id)
|
|
end
|
|
|
|
for season, list in pairs(self.seasonRewardList) do
|
|
table.sort(self.seasonRewardList[season], function(a, b)
|
|
return a < b
|
|
end)
|
|
end
|
|
end
|
|
|
|
return self.seasonRewardList[self.season] or {}
|
|
end
|
|
|
|
function BountyData:getSeason()
|
|
return self.season
|
|
end
|
|
|
|
function BountyData:getSeasonTx()
|
|
local cfg = I18N:getConfig("mall_act")[self.season]
|
|
if cfg and cfg.name then
|
|
return cfg.name
|
|
end
|
|
return GConst.EMPTY_STRING
|
|
end
|
|
|
|
function BountyData:getRechargeId()
|
|
local cfg = ConfigManager:getConfig("mall_act")[self.season]
|
|
if cfg then
|
|
return cfg.recharge_id
|
|
end
|
|
return nil
|
|
end
|
|
|
|
function BountyData:getLevel()
|
|
return self.level
|
|
end
|
|
|
|
function BountyData:getMaxLevel()
|
|
if not self.maxLevel then
|
|
self.maxLevel = #self:getSeasonRewardList()
|
|
end
|
|
return self.maxLevel
|
|
end
|
|
|
|
function BountyData:getIsMaxLevel()
|
|
return self.level >= self:getMaxLevel()
|
|
end
|
|
|
|
function BountyData:getExp()
|
|
return self.exp
|
|
end
|
|
|
|
function BountyData:getBought()
|
|
return self.bought
|
|
end
|
|
|
|
function BountyData:getCurNeedExp(lv)
|
|
lv = lv or self.level + 1
|
|
local id = self:getSeasonRewardList()[lv]
|
|
if not id then
|
|
id = self:getSeasonRewardList()[self:getMaxLevel()]
|
|
end
|
|
|
|
if not id then
|
|
return 1
|
|
end
|
|
|
|
return ACT_BATTLE_PASS[id].exp
|
|
end
|
|
|
|
function BountyData:getRewardById(id)
|
|
return ACT_BATTLE_PASS[id].reward
|
|
end
|
|
|
|
function BountyData:getProRewardById(id)
|
|
return ACT_BATTLE_PASS[id].reward_pro
|
|
end
|
|
|
|
function BountyData:getClaimed(index)
|
|
return self.count >= index
|
|
end
|
|
|
|
function BountyData:getHighClaimed(index)
|
|
return self.highCount >= index
|
|
end
|
|
|
|
function BountyData:getCount()
|
|
return self.count
|
|
end
|
|
|
|
function BountyData:getHighCount()
|
|
return self.highCount
|
|
end
|
|
|
|
function BountyData:getTaskList()
|
|
if not self.taskList then
|
|
self.taskList = {}
|
|
for id, info in pairs(ACT_BATTLE_PASS_TASK) do
|
|
local season = info.mall_id
|
|
if not self.taskList[season] then
|
|
self.taskList[season] = {}
|
|
end
|
|
|
|
table.insert(self.taskList[season], id)
|
|
end
|
|
end
|
|
|
|
return self.taskList[self.season] or {}
|
|
end
|
|
|
|
function BountyData:getTaskListByType(taskType)
|
|
if not self.taskTypeMap then
|
|
self.taskTypeMap = {}
|
|
for id, info in pairs(ACT_BATTLE_PASS_TASK) do
|
|
if not self.taskTypeMap[info.type] then
|
|
self.taskTypeMap[info.type] = {}
|
|
end
|
|
table.insert(self.taskTypeMap[info.type], id)
|
|
end
|
|
end
|
|
|
|
return self.taskTypeMap[taskType] or {}
|
|
end
|
|
|
|
function BountyData:getTaskType(id)
|
|
return ACT_BATTLE_PASS_TASK[id].type
|
|
end
|
|
|
|
function BountyData:getTaskParamater(id)
|
|
return ACT_BATTLE_PASS_TASK[id].parameter
|
|
end
|
|
|
|
function BountyData:getTaskExp(id)
|
|
return ACT_BATTLE_PASS_TASK[id].exp_reward
|
|
end
|
|
|
|
function BountyData:getTaskIsDailyRefresh(id)
|
|
return ACT_BATTLE_PASS_TASK[id].refresh_type == 1
|
|
end
|
|
|
|
function BountyData:getTaskInfo(id)
|
|
if not self.tasks[id] then
|
|
self.tasks[id] = {
|
|
id = id,
|
|
progress = 0,
|
|
claimed = false
|
|
}
|
|
end
|
|
|
|
return self.tasks[id]
|
|
end
|
|
|
|
function BountyData:addTaskProgress(id, count)
|
|
if not count or count <= 0 then
|
|
return
|
|
end
|
|
self:getTaskInfo(id).progress = self:getTaskInfo(id).progress + count
|
|
self:setDirty()
|
|
end
|
|
|
|
function BountyData:getTaskCount(id)
|
|
return self:getTaskInfo(id).progress
|
|
end
|
|
|
|
function BountyData:getTaskCaimed(id)
|
|
return self:getTaskInfo(id).claimed
|
|
end
|
|
|
|
function BountyData:getTaskCanCaimed(id)
|
|
if self:getTaskCaimed(id) then
|
|
return false
|
|
end
|
|
if not self:getTaskIsDailyRefresh(id) and not self:getBought() then
|
|
return false
|
|
end
|
|
return self:getTaskInfo(id).progress >= self:getTaskParamater(id)
|
|
end
|
|
|
|
function BountyData:initTaskListener()
|
|
ModuleManager.TaskManager:registerTask("BountyData", GConst.TaskConst.TASK_TYPE.X_KILL_MONSTER, function(count)
|
|
local list = self:getTaskListByType(GConst.TaskConst.TASK_TYPE.X_KILL_MONSTER)
|
|
for _, id in ipairs(list) do
|
|
self:addTaskProgress(id, count)
|
|
end
|
|
end)
|
|
|
|
ModuleManager.TaskManager:registerTask("BountyData", GConst.TaskConst.TASK_TYPE.X_SUMMON, function(count)
|
|
local list = self:getTaskListByType(GConst.TaskConst.TASK_TYPE.X_SUMMON)
|
|
for _, id in ipairs(list) do
|
|
self:addTaskProgress(id, count)
|
|
end
|
|
end)
|
|
|
|
ModuleManager.TaskManager:registerTask("BountyData", GConst.TaskConst.TASK_TYPE.X_HOE_USE, function(count)
|
|
local list = self:getTaskListByType(GConst.TaskConst.TASK_TYPE.X_HOE_USE)
|
|
for _, id in ipairs(list) do
|
|
self:addTaskProgress(id, count)
|
|
end
|
|
end)
|
|
|
|
ModuleManager.TaskManager:registerTask("BountyData", GConst.TaskConst.TASK_TYPE.X_JEWELRY_BATTLE, function(count)
|
|
local list = self:getTaskListByType(GConst.TaskConst.TASK_TYPE.X_JEWELRY_BATTLE)
|
|
for _, id in ipairs(list) do
|
|
self:addTaskProgress(id, count)
|
|
end
|
|
end)
|
|
|
|
ModuleManager.TaskManager:registerTask("BountyData", GConst.TaskConst.TASK_TYPE.X_GOLD_BATTLE, function(count)
|
|
local list = self:getTaskListByType(GConst.TaskConst.TASK_TYPE.X_GOLD_BATTLE)
|
|
for _, id in ipairs(list) do
|
|
self:addTaskProgress(id, count)
|
|
end
|
|
end)
|
|
|
|
ModuleManager.TaskManager:registerTask("BountyData", GConst.TaskConst.TASK_TYPE.X_MITHRIL_BATTLE, function(count)
|
|
local list = self:getTaskListByType(GConst.TaskConst.TASK_TYPE.X_MITHRIL_BATTLE)
|
|
for _, id in ipairs(list) do
|
|
self:addTaskProgress(id, count)
|
|
end
|
|
end)
|
|
|
|
ModuleManager.TaskManager:registerTask("BountyData", GConst.TaskConst.TASK_TYPE.X_ARENA_CHALLENGE, function(count)
|
|
local list = self:getTaskListByType(GConst.TaskConst.TASK_TYPE.X_ARENA_CHALLENGE)
|
|
for _, id in ipairs(list) do
|
|
self:addTaskProgress(id, count)
|
|
end
|
|
end)
|
|
|
|
ModuleManager.TaskManager:registerTask("BountyData", GConst.TaskConst.TASK_TYPE.X_LOGIN_DAY, function(count)
|
|
local list = self:getTaskListByType(GConst.TaskConst.TASK_TYPE.X_LOGIN_DAY)
|
|
for _, id in ipairs(list) do
|
|
self:addTaskProgress(id, count)
|
|
end
|
|
end)
|
|
end
|
|
|
|
function BountyData:getTaskRp()
|
|
local taskList = self:getTaskList()
|
|
for _, id in ipairs(taskList) do
|
|
if self:getTaskCanCaimed(id) then
|
|
return true
|
|
end
|
|
end
|
|
|
|
return false
|
|
end
|
|
|
|
function BountyData:getLevelRp()
|
|
if self.level > self.count then
|
|
return true
|
|
end
|
|
|
|
if self.bought and self.level > self.highCount then
|
|
return true
|
|
end
|
|
|
|
return false
|
|
end
|
|
|
|
return BountyData |