550 lines
14 KiB
Lua
550 lines
14 KiB
Lua
local ActBaseData = class("ActBaseData", BaseData)
|
|
|
|
-- 必须重写 --------------------------------------------------------------------------------------------------------------
|
|
function ActBaseData:setActivityInfo()
|
|
Logger.logFatal("不能被调用,必须重写")
|
|
end
|
|
|
|
function ActBaseData:getActNameStr()
|
|
return ""
|
|
end
|
|
|
|
-- 通用逻辑 --------------------------------------------------------------------------------------------------------------
|
|
|
|
function ActBaseData:setDirty()
|
|
end
|
|
|
|
function ActBaseData:initActInfo(data)
|
|
-- Logger.logHighlight(tostring(self.actId) .. " " .. tostring(data.actId))
|
|
if self.actId ~= data.actId then
|
|
self.turntableCfg = nil
|
|
self.turntableCfgList = nil
|
|
self.turntableTargetCfg = nil
|
|
self.turntableTargetCfgList = nil
|
|
self.bountyCfg = nil
|
|
self.bountyCfgList = nil
|
|
self.bountyProId = nil
|
|
self.exchangeCfg = nil
|
|
|
|
if self.actId then
|
|
self:tryResetActItem(data.actId)
|
|
self:tryResetGift(data.actId, true)
|
|
self:tryResetProBought(data.actId)
|
|
end
|
|
self:clear()
|
|
end
|
|
|
|
self.actId = data.actId
|
|
self.startTime = data.startTime
|
|
self.endTime = data.endTime
|
|
self.extraTime = data.extraTime
|
|
end
|
|
|
|
function ActBaseData:getActId()
|
|
return self.actId
|
|
end
|
|
|
|
function ActBaseData:getStartTime()
|
|
return self.startTime
|
|
end
|
|
|
|
function ActBaseData:getEndTime()
|
|
return self.endTime
|
|
end
|
|
|
|
function ActBaseData:getExtraTime()
|
|
return self.extraTime
|
|
end
|
|
|
|
function ActBaseData:getRemainTime()
|
|
if not self:getStartTime() then
|
|
return 0
|
|
end
|
|
|
|
local nowTime = Time:getServerTime()
|
|
if self:getExtraTime() < nowTime then
|
|
return 0
|
|
end
|
|
|
|
return self:getExtraTime() - nowTime
|
|
end
|
|
|
|
function ActBaseData:getNormalRemainTime()
|
|
local nowTime = Time:getServerTime()
|
|
if self:getEndTime() < nowTime then
|
|
return 0
|
|
end
|
|
|
|
return self:getEndTime() - nowTime
|
|
end
|
|
|
|
function ActBaseData:getTotalRemainTime()
|
|
local remainTime = self:getNormalRemainTime()
|
|
if remainTime <= 0 then
|
|
remainTime = self:getRemainTime()
|
|
end
|
|
|
|
return remainTime
|
|
end
|
|
|
|
function ActBaseData:getIsLastDay()
|
|
if not self:getStartTime() then
|
|
return false
|
|
end
|
|
|
|
local nowTime = Time:getServerTime()
|
|
if self:getExtraTime() > nowTime and nowTime >= self:getEndTime() then
|
|
return true
|
|
end
|
|
|
|
return false
|
|
end
|
|
|
|
function ActBaseData:getActivityDay()
|
|
local time = Time:getDayBeginTimeStamp(self:getStartTime())
|
|
return (Time:getServerTime() - time) // GConst.SECONDS_PRE_DAY + 1
|
|
end
|
|
|
|
function ActBaseData:getTimeOpen()
|
|
if not self:getStartTime() then
|
|
return false
|
|
end
|
|
|
|
local nowTime = Time:getServerTime()
|
|
if self:getStartTime() <= nowTime and nowTime <= self:getExtraTime() then
|
|
return true
|
|
end
|
|
|
|
return false
|
|
end
|
|
|
|
function ActBaseData:getIsOpen()
|
|
if GFunc.isShenhe() then
|
|
return false
|
|
end
|
|
|
|
if not ModuleManager:getIsOpen(DataManager.ActivityData:getActOpenKey(), true) then
|
|
return false
|
|
end
|
|
|
|
local actId = self:getActId()
|
|
if not actId or actId <= 0 then
|
|
return false
|
|
end
|
|
|
|
return self:getTimeOpen()
|
|
end
|
|
|
|
-- 重置活动道具
|
|
function ActBaseData:tryResetActItem(actId)
|
|
actId = actId or self:getActId()
|
|
if not actId or actId <= 0 then
|
|
return
|
|
end
|
|
if EDITOR_MODE then
|
|
Logger.logHighlight("重置活动道具数据 act_id = " .. tostring(actId))
|
|
end
|
|
|
|
DataManager.ActivityData:tryResetActItem(actId)
|
|
end
|
|
|
|
-- 重置礼包购买次数
|
|
-- force true重置所有礼包 false只重置免费礼包
|
|
function ActBaseData:tryResetGift(actId, force)
|
|
actId = actId or self:getActId()
|
|
if not actId or actId <= 0 then
|
|
return
|
|
end
|
|
if EDITOR_MODE then
|
|
Logger.logHighlight("重置活动礼包数据 act_id = " .. tostring(actId))
|
|
end
|
|
|
|
DataManager.ActGiftData:tryResetGift(actId, force)
|
|
end
|
|
|
|
function ActBaseData:tryResetProBought(actId)
|
|
actId = actId or self:getActId()
|
|
if not actId or actId <= 0 then
|
|
return
|
|
end
|
|
if EDITOR_MODE then
|
|
Logger.logHighlight("重置活动战令数据 act_id = " .. tostring(actId))
|
|
end
|
|
|
|
DataManager.ActBountyData:tryResetProBought(actId)
|
|
end
|
|
|
|
-- region 转盘
|
|
|
|
function ActBaseData:getTurntableCfg(id)
|
|
if self.turntableCfg == nil then
|
|
self.turntableCfg = {}
|
|
for id, info in pairs(ConfigManager:getConfig("act_turntable")) do
|
|
if info.activity == self:getActId() then
|
|
info.id = id
|
|
self.turntableCfg[id] = info
|
|
end
|
|
end
|
|
end
|
|
|
|
if id then
|
|
return self.turntableCfg[id]
|
|
else
|
|
return self.turntableCfg
|
|
end
|
|
end
|
|
|
|
function ActBaseData:getTurntableCfgList()
|
|
if self.turntableCfgList == nil then
|
|
self.turntableCfgList = {}
|
|
for k,v in pairs(self:getTurntableCfg()) do
|
|
table.insert(self.turntableCfgList, v)
|
|
end
|
|
table.sort(self.turntableCfgList, function(a, b) return a.id < b.id end)
|
|
end
|
|
|
|
return self.turntableCfgList
|
|
end
|
|
|
|
function ActBaseData:getTurntableTargetCfg(id)
|
|
if self.turntableTargetCfg == nil then
|
|
self.turntableTargetCfg = {}
|
|
for id, info in pairs(ConfigManager:getConfig("act_turntable_target")) do
|
|
if info.activity == self:getActId() then
|
|
self.turntableTargetCfg[id] = info
|
|
end
|
|
end
|
|
end
|
|
|
|
if id then
|
|
return self.turntableTargetCfg[id]
|
|
else
|
|
return self.turntableTargetCfg
|
|
end
|
|
end
|
|
|
|
function ActBaseData:getTurntableTargetCfgList()
|
|
if self.turntableTargetCfgList == nil then
|
|
self.turntableTargetCfgList = {}
|
|
for k,v in pairs(self:getTurntableTargetCfg()) do
|
|
v.id = k
|
|
table.insert(self.turntableTargetCfgList, v)
|
|
end
|
|
table.sort(self.turntableTargetCfgList, function(a, b) return a.id < b.id end)
|
|
end
|
|
|
|
return self.turntableTargetCfgList
|
|
end
|
|
|
|
function ActBaseData:getTurntableTargetList()
|
|
local targetList = {}
|
|
for i, info in pairs(self:getTurntableTargetCfg()) do
|
|
table.insert(targetList, info.target)
|
|
end
|
|
table.sort(targetList, function(a, b)
|
|
return a < b
|
|
end)
|
|
return targetList
|
|
end
|
|
|
|
-- 获取抽取消耗
|
|
function ActBaseData:getTurntableCost()
|
|
for id, info in pairs(self:getTurntableCfg()) do
|
|
return info.cost
|
|
end
|
|
end
|
|
|
|
function ActBaseData:hasTurntableItem()
|
|
local cost = self:getTurntableCost()
|
|
local num = DataManager.BagData.ItemData:getItemNumById(GFunc.getRewardId(cost))
|
|
return num > 0
|
|
end
|
|
|
|
-- 是否是大奖
|
|
function ActBaseData:isTurntableBigReward(id)
|
|
return self:getTurntableCfg(id).reward_final == 1
|
|
end
|
|
|
|
function ActBaseData:saveBigRewards(reward)
|
|
self.bigRewards = reward
|
|
end
|
|
|
|
function ActBaseData:getBigRewards()
|
|
return self.bigRewards
|
|
end
|
|
|
|
--@endregion
|
|
|
|
-- region 战令
|
|
|
|
function ActBaseData:getBountyCfg(id)
|
|
if self.bountyCfg == nil then
|
|
self.bountyCfg = {}
|
|
for id, info in pairs(ConfigManager:getConfig("act_bounty")) do
|
|
if info.activity == self:getActId() then
|
|
info.id = id
|
|
self.bountyCfg[id] = info
|
|
end
|
|
end
|
|
end
|
|
if id then
|
|
return self.bountyCfg[id]
|
|
else
|
|
return self.bountyCfg
|
|
end
|
|
end
|
|
|
|
function ActBaseData:getBountyCfgList(id)
|
|
if self.bountyCfgList == nil then
|
|
self.bountyCfgList = {}
|
|
for k, v in pairs(self:getBountyCfg()) do
|
|
table.insert(self.bountyCfgList, v)
|
|
end
|
|
table.sort(self.bountyCfgList, function(a, b) return a.id < b.id end)
|
|
end
|
|
if id then
|
|
return self.bountyCfgList[id]
|
|
else
|
|
return self.bountyCfgList
|
|
end
|
|
end
|
|
|
|
-- 获取高级奖励礼包id,用于支付
|
|
function ActBaseData:getProRewardGiftId()
|
|
if self.bountyProId == nil then
|
|
for id, info in pairs(self:getBountyCfg()) do
|
|
if info.reward_pro_pay then
|
|
self.bountyProId = info.reward_pro_pay
|
|
break
|
|
end
|
|
end
|
|
end
|
|
return self.bountyProId
|
|
end
|
|
|
|
-- 是否解锁高级奖励
|
|
function ActBaseData:isUnlockProReward()
|
|
local giftId = self:getProRewardGiftId()
|
|
local boughtCount = DataManager.PaymentData:getGiftBoughtNum(PayManager.PURCHARSE_TYPE.ACT_GIFT, giftId)
|
|
local boughtTime = DataManager.PaymentData:getGiftBoughtTime(PayManager.PURCHARSE_TYPE.ACT_GIFT, giftId)
|
|
|
|
if boughtCount <= 0 then
|
|
return false
|
|
end
|
|
if boughtTime < self:getStartTime() or boughtTime > self:getEndTime() then
|
|
return false
|
|
end
|
|
|
|
return true
|
|
end
|
|
|
|
--@endregion
|
|
|
|
-- region 兑换
|
|
|
|
function ActBaseData:getExchangeCfg(id)
|
|
if self.exchangeCfg == nil then
|
|
self.exchangeCfg = {}
|
|
for id, info in pairs(ConfigManager:getConfig("act_exchange")) do
|
|
if info.activity == self:getActId() then
|
|
info.id = id
|
|
self.exchangeCfg[id] = info
|
|
end
|
|
end
|
|
table.sort(self.exchangeCfg, function(a, b) return a.id < b.id end)
|
|
end
|
|
|
|
if id then
|
|
return self.exchangeCfg[id]
|
|
else
|
|
return self.exchangeCfg
|
|
end
|
|
end
|
|
|
|
function ActBaseData:getExchangeCfgList(page)
|
|
local isV2 = false
|
|
for k,v in pairs(self:getExchangeCfg()) do
|
|
if v.group then
|
|
isV2 = true
|
|
break
|
|
end
|
|
end
|
|
if isV2 then
|
|
self.isV2 = isV2
|
|
return self:getExchangeCfgList2(page)
|
|
end
|
|
|
|
self.isV2 = false
|
|
self.exchangeCfgList = {}
|
|
for k,v in pairs(self:getExchangeCfg()) do
|
|
v.id = k
|
|
if v.limit - self:getTodayExchangeCount(k) <= 0 then
|
|
v._sort = 10000000 + k
|
|
else
|
|
v._sort = k
|
|
end
|
|
table.insert(self.exchangeCfgList, v)
|
|
end
|
|
table.sort(self.exchangeCfgList, function(a, b) return a._sort < b._sort end)
|
|
return self.exchangeCfgList
|
|
end
|
|
|
|
function ActBaseData:getExchangeCfgList2(page)
|
|
self.exchangeCfgList = {}
|
|
self.canExchangeList = {}
|
|
for k,v in pairs(self:getExchangeCfg()) do
|
|
self.canExchangeList[v.group] = self.canExchangeList[v.group] or {}
|
|
v.id = k
|
|
if v.limit - self:getTodayExchangeCount(k) <= 0 then
|
|
v._sort = 100000000000000000 + v.group *1000000000000 + (1000000000000 - DataManager.ActivityData:getExchangeTime(k))
|
|
else
|
|
v._sort = v.group *1000 + v.group_pr
|
|
end
|
|
-- if v.limit - self:getTodayExchangeCount(k) > 0 and self:checkExchange2Display(v) then
|
|
if self:checkExchange2Display(v) then
|
|
table.insert(self.canExchangeList[v.group], v)
|
|
end
|
|
end
|
|
for group, tab in pairs(self.canExchangeList) do
|
|
table.sort(tab, function(a, b) return a._sort < b._sort end)
|
|
end
|
|
if not self.exchangeSelIdxs then
|
|
self.exchangeSelIdxs = {}
|
|
for group, tab in pairs(self.canExchangeList) do
|
|
for i,v in ipairs(tab) do
|
|
table.insert(self.exchangeCfgList, v)
|
|
self.exchangeSelIdxs[group] = i
|
|
break
|
|
end
|
|
end
|
|
else
|
|
for group, idx in pairs(self.exchangeSelIdxs) do
|
|
if not self.canExchangeList[group] then
|
|
self.exchangeSelIdxs[group] = nil
|
|
elseif not self.canExchangeList[group][idx] then
|
|
for i,v in ipairs(self.canExchangeList[group]) do
|
|
table.insert(self.exchangeCfgList, v)
|
|
self.exchangeSelIdxs[group] = i
|
|
break
|
|
end
|
|
else
|
|
local cfg = self.canExchangeList[group][idx]
|
|
if cfg.limit - self:getTodayExchangeCount(cfg.id) <= 0 then
|
|
self.exchangeSelIdxs[group] = 1
|
|
table.insert(self.exchangeCfgList, self.canExchangeList[group][1])
|
|
else
|
|
table.insert(self.exchangeCfgList, cfg)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
-- for group, tab in pairs(self.canExchangeList) do
|
|
-- for i,v in ipairs(tab) do
|
|
-- if v.limit - self:getTodayExchangeCount(k) > 0 then
|
|
-- table.insert(self.exchangeCfgList, tab[self.exchangeSelIdxs[group]])
|
|
-- break
|
|
-- end
|
|
-- end
|
|
-- end
|
|
table.sort(self.exchangeCfgList, function(a, b) return a._sort < b._sort end)
|
|
if page then
|
|
local tab = {}
|
|
for i,v in ipairs(self.exchangeCfgList) do
|
|
if v.page == page then
|
|
table.insert(tab, v)
|
|
end
|
|
end
|
|
return tab
|
|
else
|
|
return self.exchangeCfgList
|
|
end
|
|
end
|
|
|
|
function ActBaseData:checkExchange2Display(cfg)
|
|
-- 1 英雄是否拥有
|
|
-- 2 防线皮肤是否拥有
|
|
-- 3 武器是否拥有
|
|
-- 4 英雄皮肤是否拥有
|
|
-- 5 领主时装是否拥有
|
|
-- 6 宝物是否满星
|
|
-- 7 宠物是否满星
|
|
-- 8 魔法书是否满星
|
|
local reward = cfg.reward[1]
|
|
if cfg.display == 1 and ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.FORCE, true) then
|
|
return not DataManager.ForceData:getIsOwnForce(reward.id)
|
|
elseif cfg.display == 2 and ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.DEFENSE_LINE, true) then
|
|
return DataManager.DefenseLineData:getSkinStar(reward.id) <= 0
|
|
elseif cfg.display == 3 and ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.EQUIP, true) then
|
|
return DataManager.WeaponData:getSkinStar(reward.id) <= 0
|
|
elseif cfg.display == 4 and ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.FORCE, true) then
|
|
return not DataManager.ForceData:isSkinUnlock(reward.id)
|
|
elseif cfg.display == 5 and ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.SKIN, true) then
|
|
return DataManager.SkinData:getSkinStar(reward.id) <= 0
|
|
elseif cfg.display == 6 and ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.COLLECTION, true) then
|
|
return not DataManager.CollectionData:isMaxStar(reward.id)
|
|
elseif cfg.display == 7 and ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.PET, true) then
|
|
local petId = reward.id // 10
|
|
local entity = DataManager.PetData:getEntityById(petId)
|
|
return not entity:isMaxStar()
|
|
elseif cfg.display == 8 and ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.MAGIC_BOOK, true) then
|
|
local cfg = ConfigManager:getConfig("item")[reward.id]
|
|
local id = cfg.parameter[1]
|
|
local lv = DataManager.MagicBookData:getLv(id)
|
|
local isMaxLv = lv >= DataManager.MagicBookData:getMagicBookMaxLv(id)
|
|
return not isMaxLv
|
|
elseif not cfg.display then
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
|
|
function ActBaseData:getIsExchangeV2()
|
|
return self.isV2
|
|
end
|
|
|
|
function ActBaseData:getExchange2GroupList(group)
|
|
local tmp = self.canExchangeList[group] or {}
|
|
local tab = {}
|
|
for i,v in ipairs(tmp) do
|
|
if v.limit - self:getTodayExchangeCount(v.id) > 0 then
|
|
table.insert(tab, v)
|
|
end
|
|
end
|
|
return tab
|
|
end
|
|
|
|
function ActBaseData:getExchange2GroupListSelIdx(group)
|
|
return self.exchangeSelIdxs[group]
|
|
end
|
|
|
|
function ActBaseData:setExchange2GroupListSelIdx(group, idx)
|
|
self.exchangeSelIdxs[group] = idx
|
|
self:setDirty()
|
|
end
|
|
|
|
-- 今日已买次数
|
|
function ActBaseData:getTodayExchangeCount(id)
|
|
return DataManager.ActivityData:getExchangeCount(id)
|
|
end
|
|
|
|
-- 是否可购买
|
|
function ActBaseData:canExchange(id, showToast, count)
|
|
local cfg = self:getExchangeCfg(id)
|
|
count = count or 1
|
|
if cfg.limit - self:getTodayExchangeCount(id) <= 0 then
|
|
if showToast then
|
|
GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.IDLE_DESC_10))
|
|
end
|
|
return false
|
|
end
|
|
local cost = cfg.cost[1]
|
|
if not GFunc.checkCost(GFunc.getRewardId(cost), GFunc.getRewardNum(cost) * count, showToast) then
|
|
return false
|
|
end
|
|
|
|
return true
|
|
end
|
|
|
|
--@endregion
|
|
|
|
return ActBaseData |