428 lines
12 KiB
Lua
428 lines
12 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, summonShop)
|
|
data = data or {}
|
|
if EDITOR_MODE then
|
|
Logger.logHighlight("抽奖数据")
|
|
Logger.printTable(data)
|
|
end
|
|
self:initData(data.summons)
|
|
self.summonShop = summonShop or {}
|
|
self:setDirty()
|
|
if not self.isInit then
|
|
self.isInit = true
|
|
-- 跨天
|
|
DataManager:registerCrossDayFunc("SummonData", function()
|
|
if Time:getDayofWeek() == 1 then
|
|
self.summonShop = self.summonShop or {}
|
|
self.summonShop.exchanged = {}
|
|
end
|
|
self:setDirty()
|
|
end)
|
|
end
|
|
end
|
|
|
|
function SummonData:initData(data)
|
|
self.summonDataMap = {}
|
|
for i = 1, 2 do
|
|
self.summonDataMap[i] = {}
|
|
if data[i] then
|
|
self.summonDataMap[i].freeCount = data[i].free_count
|
|
self.summonDataMap[i].adCount = data[i].ad_count
|
|
self.summonDataMap[i].statCount = data[i].stat_count
|
|
self.summonDataMap[i].triggerCount = data[i].trigger_count
|
|
self.summonDataMap[i].wishId = data[i].wish_id
|
|
self.summonDataMap[i].wishCount = data[i].wish_count
|
|
else
|
|
self.summonDataMap[i].freeCount = 0
|
|
self.summonDataMap[i].adCount = 0
|
|
self.summonDataMap[i].statCount = 0
|
|
self.summonDataMap[i].triggerCount = 0
|
|
self.summonDataMap[i].wishId = 0
|
|
self.summonDataMap[i].wishCount = 0
|
|
end
|
|
end
|
|
-- int64 free_count = 1; // 今日免费次数
|
|
-- int64 ad_count = 2; // 今日广告免费次数
|
|
-- int64 stat_count = 3; // 总抽取次数
|
|
-- int64 trigger_count = 4; // 保底累计次数
|
|
-- int32 wish_id = 5; // 心愿英雄 ID
|
|
-- int64 wish_count = 6; // 心愿累计次数
|
|
end
|
|
|
|
function SummonData:getIsOpen(showToast)
|
|
if not ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.SUMMON_OPEN, not showToast) then
|
|
return false
|
|
end
|
|
return true
|
|
end
|
|
|
|
--@region 抽奖数据
|
|
--是否有免费抽奖
|
|
function SummonData:hasSummonFree(summonType)
|
|
local freeCount = self:getSummonFreeCount(summonType)
|
|
if freeCount > 0 then
|
|
return true
|
|
end
|
|
local adCount = self:getSummonAdCount(summonType)
|
|
if adCount > 0 then
|
|
return true
|
|
end
|
|
return false
|
|
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
|
|
return 0
|
|
end
|
|
|
|
-- 获取免费抽取次数
|
|
function SummonData:getSummonFreeCount(summonType)
|
|
local freeCount = self:getSummonFreeNum(summonType)
|
|
local useCount = 0
|
|
if self.summonDataMap[summonType] then
|
|
useCount = self.summonDataMap[summonType].freeCount or 0
|
|
end
|
|
return freeCount - useCount
|
|
end
|
|
|
|
-- 获取免费广告抽取次数
|
|
function SummonData:getSummonAdCount(summonType)
|
|
local freeCount = self:getSummonAdNum(summonType)
|
|
local useCount = 0
|
|
if self.summonDataMap[summonType] then
|
|
useCount = self.summonDataMap[summonType].adCount or 0
|
|
end
|
|
return freeCount - useCount
|
|
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
|
|
self:setDirty()
|
|
end
|
|
end
|
|
|
|
-- 刷新抽奖次数
|
|
function SummonData:updateSummonCount(summonType, times, free)
|
|
if self.summonDataMap[summonType] then
|
|
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
|
|
if free and free == 1 then
|
|
self.summonDataMap[summonType].adCount = self.summonDataMap[summonType].adCount + 1
|
|
elseif free and free == 2 then
|
|
self.summonDataMap[summonType].freeCount = self.summonDataMap[summonType].freeCount + 1
|
|
end
|
|
end
|
|
self:setDirty()
|
|
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()
|
|
-- return self:hasSummonFree(1) or self:hasSummonFree(2) or self:hasSummonCost1() or self:hasSummonCost2()
|
|
return self:hasSummonFree(1) or self:hasSummonCost1()
|
|
end
|
|
|
|
function SummonData:hasSummonCost1()
|
|
return DataManager.BagData.ItemData:getItemNumById(GConst.ItemConst.ITEM_ID_SUMMON_1) > 0
|
|
end
|
|
|
|
function SummonData:hasSummonCost2()
|
|
return DataManager.BagData.ItemData:getItemNumById(GConst.ItemConst.ITEM_ID_SUMMON_2) > 0
|
|
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:getSummonWishGuarantee2(summonType)
|
|
return SummonCfg[summonType].guarantee2
|
|
end
|
|
|
|
-- 小保底次数
|
|
function SummonData:getSummonWishGuarantee1(summonType)
|
|
return SummonCfg[summonType].guarantee1
|
|
end
|
|
|
|
function SummonData:getSummonFreeCd(summonType)
|
|
return SummonCfg[summonType].ad_time
|
|
end
|
|
|
|
function SummonData:getSummonWeight(summonType)
|
|
return SummonCfg[summonType].summon
|
|
end
|
|
|
|
function SummonData:getSummonAdNum(summonType)
|
|
return SummonCfg[summonType].ad_num
|
|
end
|
|
|
|
function SummonData:getSummonFreeNum(summonType)
|
|
return SummonCfg[summonType].free_num
|
|
end
|
|
--@endregion
|
|
|
|
--@region 商店
|
|
function SummonData:getSummonShopList(type)
|
|
if self.summonShopList == nil then
|
|
self.summonShopList = {}
|
|
local list = ConfigManager:getConfig("summon_shop")
|
|
for id, v in pairs(list) do
|
|
if self.summonShopList[v.summon] == nil then
|
|
self.summonShopList[v.summon] = {}
|
|
end
|
|
v.id = id
|
|
table.insert(self.summonShopList[v.summon], v)
|
|
end
|
|
for _, v in pairs(self.summonShopList) do
|
|
table.sort(v, function(a, b)
|
|
return a.id < b.id
|
|
end)
|
|
end
|
|
end
|
|
if type then
|
|
return self.summonShopList[type]
|
|
end
|
|
return self.summonShopList
|
|
end
|
|
|
|
-- function SummonData:setSummonShopSoulUnlock(shopIds)
|
|
-- if shopIds == nil then
|
|
-- return
|
|
-- end
|
|
-- for _, shopId in pairs(shopIds) do
|
|
-- self.summonShop.unlock_tips[shopId] = true
|
|
-- end
|
|
-- end
|
|
|
|
-- function SummonData:onSummonShopSoulOpen(shopIds)
|
|
-- for _, id in pairs(shopIds) do
|
|
-- self.summonShop.unlock_tips[id] = true
|
|
-- end
|
|
-- self:setSummonShopDirty()
|
|
-- end
|
|
|
|
--获取所有刚解锁的兑换
|
|
function SummonData:getUnlockShopId(type)
|
|
local unlockShopIds = {}
|
|
local list = self:getSummonShopList(type)
|
|
for id, cfg in ipairs(list) do
|
|
if DataManager.HeroData:getHeroIsUnlock(cfg.force_id) and cfg.display == 1 then
|
|
if self.summonShop.unlock_tips[cfg.id] == nil then
|
|
table.insert(unlockShopIds, cfg.id)
|
|
end
|
|
end
|
|
end
|
|
return unlockShopIds
|
|
end
|
|
|
|
function SummonData:getExchangesCount(id)
|
|
if self.summonShop and self.summonShop.exchanged then
|
|
if self.summonShop.exchanged[id] then
|
|
return self.summonShop.exchanged[id]
|
|
else
|
|
return 0
|
|
end
|
|
end
|
|
return 0
|
|
end
|
|
|
|
function SummonData:shopSuccess(id, count)
|
|
self.summonShop.exchanged[id] = (self.summonShop.exchanged[id] or 0) + count
|
|
self:setDirty()
|
|
end
|
|
|
|
--@region 商店红点
|
|
function SummonData:isShowShopRedPoint(id)
|
|
local list = DataManager.SummonData:getSummonShopList(id)
|
|
for _, cfg in ipairs(list) do
|
|
local exchangesCount = DataManager.SummonData:getExchangesCount(cfg.id) --购买次数
|
|
local cost
|
|
if cfg.discount_limit == nil or exchangesCount >= cfg.discount_limit then
|
|
cost = cfg.cost
|
|
else
|
|
cost = cfg.discount
|
|
end
|
|
if cost then
|
|
local costId = GFunc.getRewardId(cost)
|
|
local costCount = GFunc.getRewardNum(cost)
|
|
local haveItemNum = DataManager.BagData.ItemData:getItemNumById(costId) --拥有货币
|
|
if haveItemNum >= costCount then
|
|
return true
|
|
end
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
--@endregion
|
|
--endregion
|
|
|
|
--@region 跳过动画
|
|
function SummonData:getSkipAniFlag()
|
|
if self.skipAniFlag == nil then
|
|
self.skipAniFlag = LocalData:getSummonSkipFlag() == 1
|
|
end
|
|
return self.skipAniFlag
|
|
end
|
|
|
|
function SummonData:setSkipAniFlag(value)
|
|
if self.skipAniFlag == value then
|
|
return
|
|
end
|
|
|
|
self.skipAniFlag = value
|
|
local flag = 0
|
|
if self.skipAniFlag then
|
|
flag = 1
|
|
end
|
|
LocalData:setSummonSkipFlag(flag)
|
|
end
|
|
--@endregion
|
|
return SummonData |