c1_lua/lua/app/userdata/bounty/bounty_data.lua
2023-05-16 18:17:05 +08:00

174 lines
3.9 KiB
Lua

local BountyData = class("BountyData", BaseData)
local ACT_GIFT_ID_BOUNTY = 70102
local ACT_GIFT_ID_BOUNTY_ADVANCED = 70202
function BountyData:ctor()
self.data.dirty = false
end
function BountyData:init(data)
data = data or GConst.EMPTY_TABLE
self.season = data.season or 1
self.level = data.level or 1
self.exp = data.exp or 0
self.bought = data.bought
self.claimed = data.claimed or {}
self.proClaimed = data.pro_claimed or {}
self.endTime = 0
self:initBountyTime()
self:initBountyLevelCfg()
end
function BountyData:initBountyTime()
local info = ConfigManager:getConfig("bounty_time")[self.season]
if info == nil then
self.endTime = 0
return
end
self.endTime = Time:getCertainTimeByStr(info.end_time)
end
function BountyData:initBountyLevelCfg()
self.bountyLevelCfg = {}
local cfg = ConfigManager:getConfig("bounty_level")
for k, v in pairs(cfg) do
if v.season == self.season then
self.bountyLevelCfg[k % 100] = v
end
end
self.repeatLevelInfo = table.remove(self.bountyLevelCfg)
end
function BountyData:getBought()
return self.bought
end
function BountyData:setBought(season, level)
if self.season ~= season then
return
end
self.bought = true
self.level = level or self.level
self:markDirty()
end
function BountyData:getLevel()
return self.level
end
function BountyData:getExp()
return self.exp
end
function BountyData:addExp(num)
self.exp = self.exp + num
local lvUpExp = self:getLvUpExp()
local maxLv = self:getMaxLevel()
while self.exp >= lvUpExp do
self.exp = self.exp - lvUpExp
self.level = self.level + 1
if self.level >= maxLv then
self.level = maxLv
break
end
end
self:markDirty()
end
function BountyData:getLvUpExp()
local info = self:getSeasonInfoByLevel(self.level)
if info == nil then
return 1
end
return info.exp
end
function BountyData:getIsOpen()
if ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.BOUNTY_OPEN, true) and self.endTime > Time:getServerTime() then
return true
end
return false
end
function BountyData:getBannerName()
return "bounty_btn_main_1"
end
function BountyData:getSeason()
return self.season
end
function BountyData:getSeasonInfoByLevel(lv)
return self.bountyLevelCfg[lv]
end
function BountyData:getMaxLevel()
return #self.bountyLevelCfg
end
function BountyData:getLevelState(lv)
return self.claimed[lv]
end
function BountyData:getProLevelState(lv)
return self.proClaimed[lv]
end
function BountyData:getIfCanBuyLevel()
local maxLevel = self:getMaxLevel()
if maxLevel > 0 and self.level < maxLevel then
return true
end
return false
end
function BountyData:onClaimReward(level)
self.claimed[level] = true
self:markDirty()
end
function BountyData:onClaimProReward(level)
self.proClaimed[level] = true
self:markDirty()
end
function BountyData:getBuyBountyLevelCost()
if self.buyBountyLevelCost == nil then
self.buyBountyLevelCost = ConfigManager:getConfig("const")["bounty_buy_cost"].reward
end
return self.buyBountyLevelCost
end
function BountyData:onBoughtLevel()
self.level = self.level + 1
self:markDirty()
end
function BountyData:getGiftId(advanced)
if advanced then
return ACT_GIFT_ID_BOUNTY_ADVANCED
else
return ACT_GIFT_ID_BOUNTY
end
end
function BountyData:markDirty()
self.data.dirty = not self.data.dirty
end
function BountyData:getRemainTime()
local nowTime = Time:getServerTime()
return self.endTime - nowTime
end
function BountyData:getExpItemIcon()
local id = GConst.ItemConst.ITEM_ID_BOUNTY_EXP
local info = ConfigManager:getConfig("item")[id]
if info == nil then
return GConst.EMPTY_STRING
end
return info.icon
end
return BountyData