Commit cddfa60247963a065175a0a25f468488b7d10730

Authored by zhangqijia
1 parent c40a6460

feat: 月卡解锁的日/周商店随机刷新商品机制

Showing 2 changed files with 101 additions and 1 deletions   Show diff stats
src/models/RoleTimeReset.lua
... ... @@ -85,6 +85,7 @@ ResetFunc["CrossWeek"] = function(self, notify, response)
85 85 response.dinerS = {}
86 86  
87 87 self.activity:refreshWeekData(notify)
  88 + self.storeData:refreshWeekData(notify)
88 89  
89 90 -- 跨周送一些道具
90 91 local BnousReward = self:getBnousPvpTicket()
... ...
src/models/Store.lua
... ... @@ -52,6 +52,9 @@ Store.schema = {
52 52 bpInfo = {"table", {}}, -- battle pass 探索指令 1={flag=0 为1表示买了,br=""付费领取记录, fr=""免费领取记录},2,3,4
53 53  
54 54 totalRR = {"string", ""}, -- 累计充值奖励领取记录
  55 +
  56 + dailyShop = {"table", {}},
  57 + weekShop = {"table", {}},
55 58 }
56 59  
57 60 function Store:updateProperty(params)
... ... @@ -77,6 +80,17 @@ function Store:onCrossDay()
77 80 --self:sendMonthCardEmail()
78 81 self:deleteExpireLimitGoods()
79 82 --self:checkPaySignReward()
  83 +
  84 + --刷新商店
  85 + self:flushDailyShop()
  86 +
  87 + --重置月卡、特刊奖励领取记录
  88 + self:updateProperty({field = "monthCardReceive", value = 0})
  89 + self:updateProperty({field = "smonthCardReceive", value = 0})
  90 +end
  91 +
  92 +function Store:refreshWeekData(notify)
  93 + self:flushWeekShop()
80 94 end
81 95  
82 96 local SuperMonthCard = {}
... ... @@ -690,6 +704,88 @@ function Store:OnTriggerLimitTimePackAfterTs(eventType, param)
690 704 end
691 705 end
692 706  
  707 +local function checkShopFinish(shop, shopPool)
  708 + local tmpShop = shopPool[shop.id] or {}
  709 + if next(tmpShop) then
  710 + if tmpShop.expire_ts then
  711 + if skynet.timex() > tmpShop.expire_ts then
  712 + shopPool[shop.id] = nil
  713 + return true
  714 + else
  715 + return false
  716 + end
  717 + else
  718 + tmpShop.expire_ts = skynet.timex() + tmpShop.cool_time * DAY_SEC
  719 + return false
  720 + end
  721 + else
  722 + return true
  723 + end
  724 +end
  725 +
  726 +--随机日/周商店随机两个商品
  727 +-- 1. 让缓存里的商品进入冷却时间
  728 +-- 2. 删除缓存里的已经冷却好的商品
  729 +-- 3. 随机两件商品放入缓存中
  730 +function Store:flushDailyShop()
  731 + local dailyShop = self:getProperty("dailyShop") or {}
  732 + local tmpDailyShop = {}
  733 +
  734 + for id, data in pairs(csvdb["shop_normalCsv"]) do
  735 + if data.shop == 1 and data.shopType == 3 then
  736 + if data.resetTime == 1 and checkShopFinish(data, dailyShop) then
  737 + tmpDailyShop[id] = {["id"] = data.id, ["weight"] = 100, ["cool_time"] = data.cool_time}
  738 + end
  739 + end
  740 + end
  741 +
  742 + --随机两件商品放入缓存 跨天刷新
  743 + if next(tmpDailyShop) then
  744 + local id = math.randWeight(tmpDailyShop)
  745 + if id then
  746 + dailyShop[id] = tmpDailyShop[id]
  747 + tmpDailyShop[id] = nil
  748 + end
  749 +
  750 + id = math.randWeight(tmpDailyShop)
  751 + if id then
  752 + dailyShop[id] = tmpDailyShop[id]
  753 + tmpDailyShop[id] = nil
  754 + end
  755 + end
  756 +
  757 + self:updateProperty({field="dailyShop", value= dailyShop})
  758 +end
  759 +
  760 +function Store:flushWeekShop()
  761 + local weekShop = self:getProperty("weekShop") or {}
  762 + local tmpWeekShop = {}
  763 +
  764 + for id, data in pairs(csvdb["shop_normalCsv"]) do
  765 + if data.shop == 1 and data.shopType == 3 then
  766 + if data.resetTime == 2 and checkShopFinish(data, weekShop)then
  767 + tmpWeekShop[id] = {["id"] = data.id, ["weight"] = 100, ["cool_time"] = data.cool_time}
  768 + end
  769 + end
  770 + end
  771 +
  772 + --随机两件商品放入缓存 跨周刷新
  773 + if next(tmpWeekShop) then
  774 + local id = math.randWeight(tmpWeekShop)
  775 + if id then
  776 + weekShop[id] = weekShop[id]
  777 + tmpWeekShop[id] = nil
  778 + end
  779 +
  780 + id = math.randWeight(tmpWeekShop)
  781 + if id then
  782 + weekShop[id] = weekShop[id]
  783 + tmpWeekShop[id] = nil
  784 + end
  785 + end
  786 + self:updateProperty({field="weekShop", value= weekShop})
  787 +end
  788 +
693 789 function Store:data()
694 790 self:OnTriggerLimitTimePackAfterTs(TriggerEventType.AfterTs, skynet.timex())
695 791 return {
... ... @@ -708,7 +804,10 @@ function Store:data()
708 804 bpInfo = self:getProperty("bpInfo"),
709 805 totalRR = self:getProperty("totalRR"),
710 806 monthCardId = self:getProperty("monthCardId"),
711   - smonthCardId = self:getProperty("smonthCardId"),
  807 + smonthCards = self:getProperty("smonthCards"),
  808 + smonthCardReceive = self:getProperty("smonthCardReceive"),
  809 + dailyShop = self:getProperty("dailyShop"),
  810 + weekShop = self:getProperty("weekShop"),
712 811 }
713 812 end
714 813  
... ...