290 lines
8.0 KiB
Lua
290 lines
8.0 KiB
Lua
local SummonData = class("SummonData", BaseData)
|
|
local DEFAULT_FACTOR = GConst.BattleConst.DEFAULT_FACTOR
|
|
|
|
local SummonCfg = ConfigManager:getConfig("summon")
|
|
|
|
function SummonData:ctor()
|
|
self:clear()
|
|
end
|
|
|
|
function SummonData:clear()
|
|
self.summonDataMap = nil
|
|
self.data.isDirty = false
|
|
DataManager:unregisterCrossDayFunc("SummonData")
|
|
end
|
|
|
|
function SummonData:setDirty()
|
|
self.data.isDirty = not self.data.isDirty
|
|
end
|
|
|
|
function SummonData:init(data)
|
|
data = data or {}
|
|
if EDITOR_MODE then
|
|
Logger.logHighlight("抽奖数据")
|
|
Logger.printTable(data)
|
|
end
|
|
self:initData(data)
|
|
self:setDirty()
|
|
if not self.isInit then
|
|
self.isInit = true
|
|
-- 跨天
|
|
-- DataManager:registerCrossDayFunc("SummonData", function()
|
|
-- self:setDirty()
|
|
-- end)
|
|
end
|
|
end
|
|
|
|
function SummonData:initData(data)
|
|
self.summonDataMap = {}
|
|
for k,v in pairs(data) do
|
|
self.summonDataMap[k] = {}
|
|
self.summonDataMap[k].freeAt = v.free_at
|
|
self.summonDataMap[k].statCount = v.stat_count
|
|
self.summonDataMap[k].triggerCount = v.trigger_count
|
|
self.summonDataMap[k].wishId = v.wish_id
|
|
self.summonDataMap[k].wishCount = v.wish_count
|
|
end
|
|
-- int64 free_at = 1; // 上次免费抽取时间
|
|
-- int64 stat_count = 2; // 总抽取次数
|
|
-- int64 trigger_count = 3; // 保底累计次数
|
|
-- int32 wish_id = 4; // 心愿英雄 ID
|
|
-- int64 wish_count = 5; // 心愿累计次数
|
|
end
|
|
|
|
function SummonData:getIsOpen(showToast)
|
|
if not ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.SUMMON_FORCE, not showToast) then
|
|
return false
|
|
end
|
|
return true
|
|
end
|
|
|
|
--@region 抽奖数据
|
|
--是否有免费抽奖
|
|
function SummonData:hasSummonFree(summonType)
|
|
local freeCd = self:getSummonFreeCd(summonType)
|
|
if freeCd == nil then
|
|
return false
|
|
end
|
|
local freeTime = self:getSummonFreeAT(summonType)
|
|
if freeTime == nil then
|
|
return true
|
|
end
|
|
local nowTime = Time:getServerTime()
|
|
return nowTime > freeTime + freeCd * 3600
|
|
end
|
|
|
|
-- 心愿次数
|
|
function SummonData:getSummonWishCount(summonType)
|
|
if self.summonDataMap[summonType] then
|
|
return self.summonDataMap[summonType].wishCount or 0
|
|
end
|
|
return 0
|
|
end
|
|
|
|
-- 获取心愿英雄id
|
|
function SummonData:getSummonWishHeroId(summonType)
|
|
if self.summonDataMap[summonType] then
|
|
return self.summonDataMap[summonType].wishId
|
|
end
|
|
end
|
|
|
|
-- 获取上一次抽奖的时间
|
|
function SummonData:getSummonFreeAT(summonType)
|
|
if self.summonDataMap[summonType] then
|
|
return self.summonDataMap[summonType].freeAt
|
|
end
|
|
end
|
|
|
|
-- 保底累计次数
|
|
function SummonData:getSummonTriggerCount(summonType)
|
|
if self.summonDataMap[summonType] then
|
|
return self.summonDataMap[summonType].triggerCount or 0
|
|
end
|
|
return 0
|
|
end
|
|
|
|
-- 获取抽奖总次数
|
|
function SummonData:getSummonCount(summonType)
|
|
if self.summonDataMap[summonType] then
|
|
return self.summonDataMap[summonType].statCount or 0
|
|
end
|
|
return 0
|
|
end
|
|
|
|
-- 重新设置英雄成功过
|
|
function SummonData:updateSummonWishHeroId(summonType, id)
|
|
if self.summonDataMap[summonType] then
|
|
if self.summonDataMap[summonType].wishId == id then
|
|
self.summonDataMap[summonType].wishId = nil
|
|
else
|
|
self.summonDataMap[summonType].wishId = id
|
|
end
|
|
self:setDirty()
|
|
end
|
|
end
|
|
|
|
function SummonData:summonWishClaim(summonType)
|
|
if self.summonDataMap[summonType] then
|
|
self.summonDataMap[summonType].wishCount = self.summonDataMap[summonType].wishCount - 100
|
|
end
|
|
end
|
|
|
|
-- 刷新抽奖次数
|
|
function SummonData:updateSummonCount(summonType, times, at)
|
|
if self.summonDataMap[summonType] then
|
|
if at ~= nil then
|
|
self.summonDataMap[summonType].freeAt = at
|
|
end
|
|
local unlockTimes = self:getSummonWishUnlock(summonType)
|
|
if unlockTimes and self.summonDataMap[summonType].statCount + times >= unlockTimes then
|
|
if self.summonDataMap[summonType].statCount < unlockTimes then
|
|
self.summonDataMap[summonType].wishCount = self.summonDataMap[summonType].wishCount + times -
|
|
(unlockTimes - self.summonDataMap[summonType].statCount)
|
|
else
|
|
self.summonDataMap[summonType].wishCount = self.summonDataMap[summonType].wishCount + times
|
|
end
|
|
end
|
|
self.summonDataMap[summonType].statCount = self.summonDataMap[summonType].statCount + times
|
|
end
|
|
end
|
|
|
|
function SummonData:setSummonTrigger(summonType, isReset)
|
|
if isReset then
|
|
self.summonDataMap[summonType].triggerCount = 0
|
|
else
|
|
self.summonDataMap[summonType].triggerCount = self.summonDataMap[summonType].triggerCount + 1
|
|
local max = SummonCfg[summonType].guarantee1
|
|
if self.summonDataMap[summonType].triggerCount >= max then
|
|
self.summonDataMap[summonType].triggerCount = self.summonDataMap[summonType].triggerCount - max
|
|
end
|
|
end
|
|
end
|
|
--@endregion
|
|
|
|
--@region 红点
|
|
function SummonData:hasSummonCostRedPoint(count)
|
|
if count then
|
|
local itemCost = self:getSummonItemCost()
|
|
local costId = GFunc.getRewardId(itemCost)
|
|
local costNum = GFunc.getRewardNum(itemCost)
|
|
if GFunc.checkCost(costId, costNum * count, false) then
|
|
return true
|
|
end
|
|
local actId = self:getSummonOpenActivityId()
|
|
if actId then
|
|
local itemCost = self:getSummonItemCost(actId)
|
|
if itemCost then
|
|
local costId = GFunc.getRewardId(itemCost)
|
|
local costNum = GFunc.getRewardNum(itemCost)
|
|
if GFunc.checkCost(costId, costNum * count, false) then
|
|
return true
|
|
end
|
|
end
|
|
end
|
|
return false
|
|
else
|
|
if self:hasSummonCostRedPoint(1) then
|
|
return true
|
|
end
|
|
if self:hasSummonCostRedPoint(10) then
|
|
return true
|
|
end
|
|
if self:hasSummonFree() then
|
|
return true
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
--@endregion
|
|
|
|
--@region 获取消耗
|
|
-- 获取当前所需的抽卡消耗
|
|
function SummonData:getSummonCosts(summonType, count)
|
|
local costs = {}
|
|
local costItem = self:getSummonItemCost(summonType)
|
|
local costItemId = costItem.id
|
|
local costItemNum = costItem.num -- 单抽消耗道具数量
|
|
local costItemHas = DataManager.BagData.ItemData:getItemNumById(costItemId) --拥有的道具数量
|
|
local costGem = self:getSummonGemCost(summonType)
|
|
-- if self:getIsActivity() then
|
|
-- table.insert(costs, {type = GConst.REWARD_TYPE.ITEM, id = costItemId, num = costItemNum * count })
|
|
-- else
|
|
if costItemHas < costItemNum then -- 道具不足以单抽 全用宝石
|
|
if not costGem then
|
|
table.insert(costs, {type = GConst.REWARD_TYPE.ITEM, id = costItemId, num = costItemNum * count})
|
|
else
|
|
local costGemId = costGem.id
|
|
local costGemNum = costGem.num
|
|
table.insert(costs, {type = GConst.REWARD_TYPE.ITEM, id = costGemId, num = costGemNum * count})
|
|
end
|
|
elseif costItemHas < costItemNum * count then -- 有道具但是不足 道具和宝石混合
|
|
--道具
|
|
local meetCount = math.floor(costItemHas / costItemNum)
|
|
table.insert(costs, {type = GConst.REWARD_TYPE.ITEM, id = costItemId, num = meetCount * costItemNum})
|
|
if costGem then
|
|
--钻石
|
|
local costGemId = costGem.id
|
|
local costGemNum = costGem.num
|
|
local diffNum = count - meetCount
|
|
table.insert(costs, {type = GConst.REWARD_TYPE.ITEM, id = costGemId, num = costGemNum * diffNum})
|
|
end
|
|
else -- 道具满足
|
|
table.insert(costs, {type = GConst.REWARD_TYPE.ITEM, id = costItemId, num = costItemNum * count})
|
|
end
|
|
-- end
|
|
return costs
|
|
end
|
|
--@endregion
|
|
|
|
--@region 配置
|
|
function SummonData:getSummonConfig(id)
|
|
if id then
|
|
return SummonCfg[id]
|
|
else
|
|
return SummonCfg
|
|
end
|
|
end
|
|
|
|
----- 获取概率
|
|
function SummonData:getSummonShow(summonType)
|
|
return SummonCfg[summonType].show
|
|
end
|
|
|
|
-- 获取单抽消耗
|
|
function SummonData:getSummonItemCost(summonType)
|
|
return SummonCfg[summonType].item_cost
|
|
end
|
|
|
|
-- 获取单抽钻石消耗
|
|
function SummonData:getSummonGemCost(summonType)
|
|
return SummonCfg[summonType].cost
|
|
end
|
|
|
|
function SummonData:getSummonWishUnlock(summonType)
|
|
return SummonCfg[summonType].guarantee3
|
|
end
|
|
|
|
-- 心愿英雄列表
|
|
function SummonData:getSummonWishConfig(summonType)
|
|
return SummonCfg[summonType].love
|
|
end
|
|
|
|
-- 心愿保底次数
|
|
function SummonData:getSummonWishGuarantee(summonType)
|
|
return SummonCfg[summonType].guarantee2
|
|
end
|
|
|
|
function SummonData:getSummonFreeCd(summonType)
|
|
return SummonCfg[summonType].ad_time
|
|
end
|
|
|
|
function SummonData:getSummonFreeCd(summonType)
|
|
return SummonCfg[summonType].ad_time
|
|
end
|
|
|
|
function SummonData:getSummonWeight(summonType)
|
|
return SummonCfg[summonType].summon
|
|
end
|
|
--@endregion
|
|
|
|
return SummonData |