local ShopData = class("ShopData", BaseData) function ShopData:ctor() self.data.isDirty = false end function ShopData:clear() DataManager:unregisterCrossDayFunc("ShopData") end function ShopData:setDirty() self.data.isDirty = not self.data.isDirty end function ShopData:initCrossDay() DataManager:registerCrossDayFunc("ShopData", function() self:resetMallDaily() self:setDirty() end) end -- 通用礼包部分 ********************************************************************************************** -- 初始化购买的礼包 function ShopData:initActGift(act) if EDITOR_MODE then Logger.logHighlight("初始化 initActGift") Logger.printTable(act) end act = act or {} local gifts = act.gifts or {} -- 转为map结构 for _, gift in ipairs(gifts) do local giftType = gift.act_type local giftId = gift.id local buyCount = gift.buy_count -- 已购次数 local latestBuyTime = gift.latest_buy_at -- 最后一次购买时间 local latestOrderUuid = gift.latest_order_uuid -- 正在支付的订单ID if not self.giftMap then self.giftMap = {} end if not self.giftMap[giftType] then self.giftMap[giftType] = {} end self.giftMap[giftType][giftId] = gift end self:setDirty() end -- 已购买的礼包 function ShopData:getActGiftMap() return self.giftMap end function ShopData:getActGiftMapByType(actType) return self.giftMap and self.giftMap[actType] end function ShopData:getActGiftDetailData(actType, actId) if self.giftMap then if self.giftMap[actType] then return self.giftMap[actType][actId] end end return nil end -- 获得一个礼包的已购次数 function ShopData:getGiftBoughtNum(actType, actId) local data = self:getActGiftDetailData(actType, actId) if data then return data.buy_count end return 0 end function ShopData:updateGiftInfo(gift) local giftType = gift.act_type local giftId = gift.id if not self.giftMap then self.giftMap = {} end if not self.giftMap[giftType] then self.giftMap[giftType] = {} end self.giftMap[giftType][giftId] = gift self:setDirty() end function ShopData:getShopItemCfg(giftData) if giftData.act_type == 1 then -- mall_act return ConfigManager:getConfig("mall_act")[giftData.id] end if giftData.act_type == 5 then -- mall_treasure return ConfigManager:getConfig("mall_treasure")[giftData.id] end end -- 通用礼包结束 ---------------------------------------------------------------------------------------------- -- 每日特惠部分 ********************************************************************************************** function ShopData:getMallDailyConfig() return ConfigManager:getConfig("mall_daily") end -- 初始化每日特惠 function ShopData:initMallDaily(mallDaily) if EDITOR_MODE then Logger.logHighlight("初始化 initMallDaily") Logger.printTable(mallDaily) end mallDaily = mallDaily or {} self.mallDailyAdResetCount = mallDaily.ad_reset_Count or 0 self.mallDailyDiamondResetCount = mallDaily.diamond_reset_Count or 0 self.mallDailyGoods = mallDaily.goods or {} -- {id,good_index,bought} self:markMallDailyDirty(false) self:setDirty() end -- 购买成功后更新数据 function ShopData:updateMallDailyGoods(info) local goods = self:getMallDailyGoods() for _, data in ipairs(goods) do if data.id == info.id and data.good_index == info.good_index then data.bought = info.bought break end end self:setDirty() end -- 每日特惠跨天重置 function ShopData:resetMallDaily() self.mallDailyAdResetCount = 0 self.mallDailyDiamondResetCount = 0 self:markMallDailyDirty(true) -- 标记需要重新请求数据,在界面/下次打开界面时请求 end function ShopData:getMallDailyDirty() return self.data.mallDailyDirty end function ShopData:markMallDailyDirty(isDirty) self.data.mallDailyDirty = isDirty end function ShopData:getMallDailyAdResetCount() return self.mallDailyAdResetCount end function ShopData:addMallDailyAdResetCount() self.mallDailyAdResetCount = self.mallDailyAdResetCount + 1 end function ShopData:getMallDailyAdLeftCount() return 1 - self.mallDailyAdResetCount -- TODOJ 目前无配置表 end function ShopData:getMallDailyDiamondResetCount() return self.mallDailyDiamondResetCount end function ShopData:addMallDailyDiamondResetCount() self.mallDailyDiamondResetCount = self.mallDailyDiamondResetCount + 1 end function ShopData:getMallDailyDiamondLeftCount() return 1 - self.mallDailyDiamondResetCount -- TODOJ 目前无配置表 end function ShopData:getMallDailyGoods() return self.mallDailyGoods end function ShopData:getMallDailyDiamondResetCost() return 30 -- TODOJ 目前无配置表 end -- 每日特惠 广告商品最大购买次数 function ShopData:getMallDailyFirstItemAdMaxCount() return 1 -- TODOJ 目前无配置表 end -- 每日特惠 常规商品最大购买次数 function ShopData:getMallDailyGoodsLimitCount() return 1 -- TODOJ 目前无配置表 end -- 每日特惠 是否开启 function ShopData:getMallDailyIsOpen() return ModuleManager:getIsOpen() end -- 根据商品id获取本日的随机商品数据 function ShopData:getMallDailyRewardAndCost(id) local cfg = self:getMallDailyConfig() local index for _, info in ipairs(self:getMallDailyGoods()) do if info.id == id then index = info.good_index break end end if index then return cfg[id].good[index], cfg[id].cost and cfg[id].cost[index] end end -- 每日特惠结束 ---------------------------------------------------------------------------------------------- -- 常驻金币礼包 ********************************************************************************************** function ShopData:getMallGoldConfig() return ConfigManager:getConfig("mall_gold") end function ShopData:initCommonDailyGoldGift(ad_count) if EDITOR_MODE then Logger.logHighlight("初始化 initCommonDailyGoldGift") Logger.printTable(ad_count) end ad_count = ad_count or {} self.commonDailyGoldBuyCount = ad_count[1] or 0 -- 已购的金币广告礼包次数 self:setDirty() end function ShopData:getCommonDailyCoinAdBuyCount() return self.commonDailyGoldBuyCount end -- 根据时间得到当前挂机金币奖励 function ShopData:getCommonDailyCoinNum(time) local coinPerHour = DataManager.IdleData:getGoldPerHour() -- TODOJ return coinPerHour * time // 3600 -- local goldDrop = DataManager.ChapterData:getGoldDrop() -- local idleGoldDropTime = DataManager.IdleData:getIdleGoldDropTime() -- Logger.logHighlight("getCommonDailyCoinNum -- time:%s gold:%s idle:%s", time, goldDrop, idleGoldDropTime) -- return goldDrop * time // idleGoldDropTime end function ShopData:getCommonDailyCoinDataById(id) local cfgInfo = self:getMallGoldConfig()[id] if cfgInfo then return self:getCommonDailyCoinNum(cfgInfo.idel_time), cfgInfo.cost end end -- 常驻金币礼包结束 ---------------------------------------------------------------------------------------------- -- 常驻钻石礼包 function ShopData:getMallTreasureConfig() return ConfigManager:getConfig("mall_treasure") end -- 初始化成长礼包 function ShopData:initGrowUpGift(growUpGift) end -- 初始化助力礼包 function ShopData:initLevelUpGift(levelUpGift) end return ShopData