This commit is contained in:
chenxi 2023-05-05 15:39:06 +08:00
parent 50a2ff4b9f
commit 0fe15f3ba1

View File

@ -4,7 +4,7 @@ function GodPigData:init(data)
data = data or GConst.EMPTY_TABLE
self.data.id = data.id or 0
if self.data.id == 0 then
self.data.id = ConfigManager:getConfig("const")["act_gold_pig_first_id"].value
self.data.id = self:getFirstLevelId()
end
self.data.count = data.count or 0
self.data.cd = data.cd or 0
@ -34,6 +34,27 @@ function GodPigData:addGoldPigCount()
end
end
function GodPigData:getFirstLevelId()
if self.firstLevelId == nil then
self.firstLevelId = ConfigManager:getConfig("const")["act_gold_pig_first_id"].value
end
return self.firstLevelId
end
function GodPigData:getTimeOverCD()
if self.timeOverCD == nil then
self.timeOverCD = ConfigManager:getConfig("const")["act_gold_pig_cd"].value * 3600
end
return self.timeOverCD
end
function GodPigData:getBoughtCD()
if self.boughtCD == nil then
self.boughtCD = ConfigManager:getConfig("const")["act_gold_pig_buy_cd"].value * 3600
end
return self.boughtCD
end
function GodPigData:getCfg()
if self.cfg == nil then
self.cfg = ConfigManager:getConfig("act_god_pig")
@ -67,4 +88,34 @@ function GodPigData:tryActiveGoldPig()
self.data.endTime = Time:getServerTime() + self:getDuration()
end
-- 时间到了,消失并降档
function GodPigData:onTimeOver()
if not self.data.isOpen then
return
end
self.data.isOpen = false
local cfg = self:getCfg()
local info = cfg[self.data.id]
if info == nil then
self.data.id = self:getFirstLevelId()
else
self.data.id = info.before_id or self:getFirstLevelId()
end
self.data.cd = self:getTimeOverCD()
end
-- 购买后,消失并升档位
function GodPigData:onBought(id)
if not self.data.isOpen then
return
end
self.data.isOpen = false
local cfg = self:getCfg()
local info = cfg[id]
if info then
self.data.id = info.next_id or id
end
self.data.cd = self:getBoughtCD()
end
return GodPigData