diff --git a/src/models/RoleLog.lua b/src/models/RoleLog.lua index f3be330..ca1890e 100644 --- a/src/models/RoleLog.lua +++ b/src/models/RoleLog.lua @@ -68,6 +68,8 @@ local ItemReason = { smonthCardReward = 152, --特刊奖励 itemConvertSpecial = 153, --兑换月卡/战令/探索指令 特殊道具 buyDiamondCardReward = 154, --购买钻石额外赠送奖励 + firstMonthCardReward = 155, --首次订阅月卡奖励 + firstSMonthCardReward = 156, --首次订阅特刊奖励 advHang = 301, -- 拾荒挂机 hangBattle = 302, -- 挂机战斗 diff --git a/src/models/Store.lua b/src/models/Store.lua index 04d0491..a49a978 100644 --- a/src/models/Store.lua +++ b/src/models/Store.lua @@ -30,11 +30,12 @@ Store.schema = { monthCardEx = {"number", 0}, -- 期数 monthCardId = {"number", 0}, -- 月卡id - firstMonthCard = {"number", 1}, -- 首次订阅月卡 + firstMonthCard = {"number", 0}, -- 首次订阅月卡 monthCardReceive = {"number", 0}, -- 月卡奖励领取记录 当天 0-未领取, 1-已经领取 smonthCards = {"table", {}}, --特刊信息 {[id]={["buyCount"]=0, ["periods"]=0}} buyCount: 购买次数,periods: 剩余期数, smonthCardReceive = {"number", 0}, -- 特刊奖励领取记录 当天 0-未领取, 1-已经领取 + firstSMonthCard = {"table", {}}, -- 首次订阅当期特刊 battleCard = {"number", 0}, -- 赛季卡 battleFR = {"string", ""}, -- 免费赛季卡领取记录 @@ -95,100 +96,8 @@ function Store:refreshWeekData(notify) self:flushWeekShop() end -local SuperMonthCard = {} - -SuperMonthCard["buy"] = function(self, id) - local smonthCards = self:getProperty("smonthCards") or {} - - local buyLimitFunc = function(buylimit) - for k, v in pairs(buylimit) do - if k == 1 then - if v == 101 then - if self:isMonthCardExpire() then - skynet.error("月卡过期") - return false - end - else - if smonthCards[v] == nil then - skynet.error("没有购买增刊里的条件, %d", v) - return false - end - end - elseif k == 2 then - if smonthCards[v] == nil and v ~= 101 then - skynet.error("没有购买增刊里的条件, %d", v) - return false - end - if SuperMonthCard["isExpired"](self, v) == false and v ~= 101 then - skynet.error("上期特刊奖励没有领取完") - return false - end - end - end - return true - end - - local BuyMonthCard = {} - BuyMonthCard["renewal"]= function() - --续刊 - local card = csvdb["shop_cardCsv"][id] or {} - if card["buyLimit"] and card["buyLimit"] ~= "" then - if buyLimitFunc(card["buyLimit"]:toNumMap()) == false then - skynet.error("不满足购买条件") - return false - end - end - - local smonthCard = smonthCards[id] or {} - if next(smonthCard) then - smonthCard["buyCount"] = (smonthCard["buyCount"] or 0) + 1 - local periods = SuperMonthCard["periods"](self, id) + (card["amount"] or 30) - smonthCard["periods"] = periods - - self:updateProperty({field = "smonthCards", value = smonthCards}) - return true - end - end - BuyMonthCard["order"] = function() - --增刊条件 - local card = csvdb["shop_cardCsv"][id] or {} - if card["buyLimit"] and card["buyLimit"] ~= "" then - if buyLimitFunc(card["buyLimit"]:toNumMap()) == false then - skynet.error("不满足增刊条件") - return false - end - end - smonthCards[id] = {["periods"] = (card["amount"] or 30), ["buyCount"] = 1} - - self:updateProperty({field= "smonthCards", value = smonthCards}) - return true - end - - if SuperMonthCard["isExpired"](self, id) then - local smonthCard = smonthCards[id] or {} - if next(smonthCard) then - return BuyMonthCard["renewal"]() - else - return BuyMonthCard["order"]() - end - else - return BuyMonthCard["renewal"]() - end -end - -SuperMonthCard["periods"] = function(self, id) - local smonthCards = self:getProperty("smonthCards") or {} - local smonthCard = smonthCards[id] or {} - return smonthCard["periods"] or 0 -end - -SuperMonthCard["isExpired"] = function (self, id) - local periods = SuperMonthCard["periods"](self, id) - return periods == 0 -end - -SuperMonthCard["itemDaily"] = function(self, id) - local cur_ex = SuperMonthCard["periods"](self, id) +local function getCardItemDailyReward(self, id) + local cur_ex = self:getSMonthCardPeriods(self, id) if cur_ex == 0 then return nil, nil end cur_ex = cur_ex - 1 @@ -203,7 +112,7 @@ SuperMonthCard["itemDaily"] = function(self, id) return reward, change, cur_ex end -SuperMonthCard["itemFirst"] = function(self, id) +local function getCardItemFirstReward(self, id) local card = csvdb["shop_cardCsv"][id] or {} local reward, _ = self.owner:award(card["itemFirst"], {isRecharge = true, log = {desc = "recharge", int1 = id}}) return reward @@ -384,8 +293,8 @@ end function Store:getSMonthCardDailyReward(id) if not id then return nil end - local before_ex = SuperMonthCard["periods"](self, id) - local reward, change, cur_ex= SuperMonthCard["itemDaily"](self, id) + local before_ex = self:getSMonthCardPeriods(self, id) + local reward, change, cur_ex= getCardItemDailyReward(id) --今日特刊奖励已经领取 self:updateProperty({field = "smonthCardReceive", value = 1}) @@ -402,14 +311,116 @@ function Store:getSMonthCardDailyReward(id) end function Store:firstBuyMonthCard(id) - if self:getProperty("firstMonthCard") == 1 then - self:updateProperty({field = "firstMonthCard", value = 0}) + if self:getProperty("firstMonthCard") == 0 then + self:updateProperty({field = "firstMonthCard", value = 1}) local card = csvdb["shop_cardCsv"][id] or {} - return self.owner:award(card["itemOnce"], {log = {desc = "monthCardReward", int1 = id, int2 = 30}}) + return self.owner:award(card["itemOnce"], {log = {desc = "firstMonthCardReward", int1 = id}}) end return nil end +function Store:firstBuySMonthCard(id) + local firstSMonthCard = self:getProperty("firstSMonthCard") or {} + if not firstSMonthCard[id] or firstSMonthCard[id] == 0 then + firstSMonthCard[id] = 1 + self:updateProperty({field = "firstSMonthCard", value = firstSMonthCard}) + local card = csvdb["shop_cardCsv"][id] or {} + return self.owner:award(card["itemOnce"], {log = {desc = "firstSMonthCardReward", int1 = id}}) + end + return nil +end + +function Store:getSMonthCardPeriods(id) + local smonthCards = self:getProperty("smonthCards") or {} + local smonthCard = smonthCards[id] or {} + return smonthCard["periods"] or 0 +end + +function Store:isSMonthCardExpired(id) + return self:getSMonthCardPeriods(id) == 0 +end + +function Store:buySMonthCardLimit(buylimit) + local smonthCards = self:getProperty("smonthCards") or {} + for k, v in pairs(buylimit) do + if k == 1 then + if v == 101 then + if self:isMonthCardExpire() then + skynet.error("月卡过期") + return false + end + else + if smonthCards[v] == nil then + skynet.error("没有购买增刊里的条件, %d", v) + return false + end + end + elseif k == 2 then + if smonthCards[v] == nil and v ~= 101 then + skynet.error("没有购买增刊条件里的特刊, %d", v) + return false + end + if self:isSMonthCardExpired(v) == false and v ~= 101 then + skynet.error("上期特刊奖励没领完") --策划yc+hbw 没领完上期特刊,新一期特刊不展示,不允许购买 + return false + end + end + end + return true +end + +function Store:buySMonthCard(id) + local smonthCards = self:getProperty("smonthCards") or {} + + local BuyMonthCard = {} + BuyMonthCard["renewal"]= function() + --续刊 + local card = csvdb["shop_cardCsv"][id] or {} + if card["buyLimit"] and card["buyLimit"] ~= "" then + if self:buySMonthCardLimit(card["buyLimit"]:toNumMap()) == false then + skynet.error("不满足购买条件") + return false + end + end + + local smonthCard = smonthCards[id] or {} + if next(smonthCard) then + smonthCard["buyCount"] = (smonthCard["buyCount"] or 0) + 1 + local periods = (smonthCard["periods"] or 0) + (card["amount"] or 30) + smonthCard["periods"] = periods + + self:updateProperty({field = "smonthCards", value = smonthCards}) + return true + end + end + + BuyMonthCard["order"] = function() + --增刊 + local card = csvdb["shop_cardCsv"][id] or {} + if card["buyLimit"] and card["buyLimit"] ~= "" then + if self:buySMonthCardLimit(card["buyLimit"]:toNumMap()) == false then + skynet.error("不满足增刊条件") + return false + end + end + + smonthCards[id] = {["periods"] = (card["amount"] or 30), ["buyCount"] = 1} + self:updateProperty({field= "smonthCards", value = smonthCards}) + return true + end + + if self:isSMonthCardExpired(id) then + local smonthCard = smonthCards[id] or {} + if next(smonthCard) then + return BuyMonthCard["renewal"]() + else + return BuyMonthCard["order"]() + end + else + return BuyMonthCard["renewal"]() + end +end + -- 购买通行证 function Store:onBuyCard(type, duration, id, actid) local timeNow = skynet.timex() @@ -420,20 +431,23 @@ function Store:onBuyCard(type, duration, id, actid) self:updateProperty({field = "monthCardEx", value = self:getProperty("monthCardEx") + 30}) local reward = {} - --初回特典 仅首次购买月卡时赠送SSR级角色"拉塔托娅" - local tmpreward, _ = self:firstBuyMonthCard(id) + local tmpreward, _ = self:firstBuyMonthCard(id) --初回特典 仅首次购买月卡 if tmpreward then table.rewardMerge(reward, tmpreward) end - --订阅奖励 - tmpreward = SuperMonthCard["itemFirst"](self, id) + tmpreward = getCardItemFirstReward(self, id) --订阅奖励 if next(tmpreward) then table.rewardMerge(reward, tmpreward) end return reward elseif type == CardType.SuperMonthCard then - if SuperMonthCard["buy"](self, id) then - skynet.error("特刊购买成功:"..id) - return SuperMonthCard["itemFirst"](self, id) + if self:buySMonthCard(id) then + local reward = getCardItemFirstReward(self, id) or {} + local tmpreward, _ = self:firstBuySMonthCard(id) + if tmpreward then table.rewardMerge(reward, tmpreward) end + + return reward end + + skynet.error("特刊购买失败:"..id) return nil elseif type == CardType.NormalMonthCardLevelUp then if self:isMonthCardExpire() then @@ -852,6 +866,7 @@ function Store:data() totalRR = self:getProperty("totalRR"), monthCardId = self:getProperty("monthCardId"), firstMonthCard = self:getProperty("firstMonthCard"), + firstsMonthCard = self:getProperty("firstsMonthCard"), monthCardReceive = self:getProperty("monthCardReceive"), smonthCards = self:getProperty("smonthCards"), smonthCardReceive = self:getProperty("smonthCardReceive"), -- libgit2 0.21.2