diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 048b1a3..9f428a3 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -222,6 +222,7 @@ actionCodes = { Store_getBattlePassRewardRpc = 562, --赛季卡奖励 Store_getExploreCommandRewardRpc = 563, --探索指令 Store_getTotalRechargeAwardRpc = 564, -- 累计充值 + Store_monthCardRewardRpc = 565, --每日月卡+特刊奖励 Store_biliCloudRechargeRpc = 596, Store_biliAndroidRechargeRpc = 597, diff --git a/src/actions/StoreAction.lua b/src/actions/StoreAction.lua index fc0eed2..60528c3 100644 --- a/src/actions/StoreAction.lua +++ b/src/actions/StoreAction.lua @@ -546,4 +546,32 @@ function _M.getTotalRechargeAwardRpc(agent, data) return true end +function _M.monthCardRewardRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local mcid = msg.mcid + local smcid = msg.smcid + + local reward,change = {}, {} + --月卡奖励 + local tmpreward, tmpchange = role.storeData:getMonthCardDailyReward(mcid) + if tmpreward then + for k, v in pairs(tmpreward) do + reward[k] = (reward[k] or 0) + v + end + if tmpchange then table.insert(change, tmpchange) end + end + + --特刊奖励 + tmpreward, tmpchange = role.storeData:getSMonthCardDailyReward(smcid) + if tmpreward then + for k, v in pairs(tmpreward) do + reward[k] = (reward[k] or 0) + v + end + if tmpchange then table.insert(change, tmpchange) end + end + SendPacket(actionCodes.Store_monthCardRewardRpc, MsgPack.pack(role:packReward(reward, change))) + return true +end + return _M \ No newline at end of file diff --git a/src/models/RoleLog.lua b/src/models/RoleLog.lua index 9d0f051..33f430a 100644 --- a/src/models/RoleLog.lua +++ b/src/models/RoleLog.lua @@ -63,6 +63,8 @@ local ItemReason = { giftTime = 147, -- 创角后的时间礼包 activityCrisis = 148, -- 物资危机奖励 glodConvertRune = 149, -- 金币兑换铭文 + monthCardReward = 150, --月卡奖励 + smonthCardReward = 151, --特刊奖励 advHang = 301, -- 拾荒挂机 hangBattle = 302, -- 挂机战斗 @@ -392,7 +394,15 @@ local MethodType = { currency_type = true, -- 购买道具消耗的货币类型,记录货币ID shop_purchase_current = true, -- 购买道具消耗的货币数量 shop_id = true, -- 商店ID - }, + }, + month_card = { --月卡+特刊奖励 + item_type = true, --月卡 1, 特刊 2 + item_id = true, --月卡id + before_ex = true, --未领取奖励前的期 + cur_ex = true, --剩余期数 + reward_time = true, --奖励时间 + month_reward_detail = "json", --奖励物品 {'itemid1':123,'itemid2':456,………...} + }, --[[ 100 添加好友 200 删除好友 diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index dfb853e..5ed7f95 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -2328,7 +2328,6 @@ function RolePlugin.bind(Role) return rechargeId end - function Role:recharge(params) local id = tonumber(params.id) local rechargeData = csvdb["shop_rechargeCsv"][id] @@ -2353,8 +2352,16 @@ function RolePlugin.bind(Role) end self:gainDiamond({count = diamondCount, isRecharge = true, sid = params.sid, log = {desc = "recharge", int1 = id}}) elseif rechargeData.shop == 2 then --通行证商店 + --订阅奖励 reward, _ = self:award(rechargeData.itemFirst, {isRecharge = true, log = {desc = "recharge", int1 = id}}) - self.storeData:onBuyCard(rechargeData.type, rechargeData.time, rechargeData.id, rechargeData.activity_id) + + --签收奖励 + local tmpreward, _ = self.storeData:onBuyCard(rechargeData.type, rechargeData.time, rechargeData.id, rechargeData.activity_id) + if tmpreward then + for k, v in pairs(tmpreward) do + reward[k] = (reward[k] or 0) + v + end + end elseif rechargeData.shop == 3 then -- 礼包商店 reward, _ = self:award(rechargeData.itemFirst, {isRecharge = true, log = {desc = "recharge", int1 = id}}) else diff --git a/src/models/Store.lua b/src/models/Store.lua index 1d98d86..2985888 100644 --- a/src/models/Store.lua +++ b/src/models/Store.lua @@ -8,24 +8,13 @@ end function Store:onLoad() local monEx = self:getProperty("monthCardEx") - local smonEx = self:getProperty("smonthCardEx") local monId = self:getProperty("monthCardId") - local smonId = self:getProperty("smonthCardId") - local timeNow = skynet.timex() local flag = false - if monEx > timeNow and monId == 0 then + if monEx > 0 and monId == 0 then self:updateProperty({field = "monthCardId", value = 101}) self:updateProperty({field = "getMailT1", value = 0}) flag = true end - if smonEx > timeNow and smonId == 0 then - self:updateProperty({field = "smonthCardId", value = 102}) - self:updateProperty({field = "getMailT2", value = 0}) - flag = true - end - if flag then - self:sendMonthCardEmail() - end end ActGoodsType = { @@ -39,10 +28,13 @@ Store.schema = { growFund = {"number", 0}, -- 成长基金 growFundR = {"string", ""}, -- 成长基金领取记录 - monthCardEx = {"number", 0}, -- 月卡过期时间戳 + monthCardEx = {"number", 0}, -- 期数 monthCardId = {"number", 0}, -- 月卡id - smonthCardEx = {"number", 0}, -- 超级月卡过期时间戳 - smonthCardId = {"number", 0}, -- 超级月卡id + firstMonthCard = {"number", 1}, -- 首次订阅月卡 + monthCardReceive = {"number", 0}, -- 月卡奖励领取记录 当天 0-未领取, 1-已经领取 + + smonthCards = {"table", {}}, --特刊信息 {[id]={["buyCount"]=0, ["periods"]=0, ["openFlag"]= 1}} buyCount: 购买次数,periods: 剩余期数,openFlag: 是否开放标识 + smonthCardReceive = {"number", 0}, -- 特刊奖励领取记录 当天 0-未领取, 1-已经领取 battleCard = {"number", 0}, -- 赛季卡 battleFR = {"string", ""}, -- 免费赛季卡领取记录 @@ -82,11 +74,97 @@ function Store:updateProperty(params) end function Store:onCrossDay() - self:sendMonthCardEmail() + --self:sendMonthCardEmail() self:deleteExpireLimitGoods() --self:checkPaySignReward() end +local SuperMonthCard = {} + +SuperMonthCard["buy"] = function(self, id) + local smonthCards = self:getProperty("smonthCards") or {} + + local BuyMonthCard = {} + BuyMonthCard["renewal"]= function() + --续刊 + if self:isMonthCardExpire() then return false end + + local smonthCard = smonthCards[id] or {} + if next(smonthCard) then + local rechargeData = csvdb["shop_rechargeCsv"][id] or {} + local buyCount = smonthCard["buyCount"] or 0 + if buyCount >= (rechargeData["limit"] or 3) then return false end + + smonthCard["buyCount"] = (smonthCard["buyCount"] or 0) + 1 + + local card = csvdb["shop_cardCsv"][id] or {} + local periods = SuperMonthCard["periods"](self, id) + (card["cardPlusPeriods"] or 30) + smonthCard["periods"] = periods + + self:updateProperty({filed = "smonthCards", value = smonthCards}) + return true + end + end + BuyMonthCard["order"] = function() + --增刊条件 + 标识 + for _, val in pairs(smonthCards) do + val["openFlag"] = 0 + end + + local card = csvdb["shop_cardCsv"][id] or {} + if (card["cardPlusFlag"] or 0) ~= 1 then return false end + + --判断是否购买过增刊条件里的特刊 + + local cardPlusCondition = card["cardPlusCondition"] or 0 + if self:isMonthCardExpire() or smonthCards[cardPlusCondition] == nil then return false end + + local smonthCard = {["periods"] = (card["cardPlusPeriods"] or 30), ["buyCount"] = 1, ["openFlag"] = 1 } + smonthCards[id] = smonthCard + + self:updateProperty({filed = "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) + if cur_ex == 0 then return nil, nil end + cur_ex = cur_ex - 1 + + local card = csvdb["shop_cardCsv"][id] or {} + local reward, change = self.owner:award(card["itemDaily"], {log = {desc = "smonthCardReward", int1 = id, int2 = cur_ex}}) + + local smonthCards = self:getProperty("smonthCards") or {} + local smonthCard = smonthCards[id] or {} + smonthCard["periods"] = cur_ex + self:updateProperty({field = "smonthCards", value = smonthCards}) + + return reward, change, cur_ex +end + -- 删除过期商品 function Store:deleteExpireLimitGoods() local timeNow = skynet.timex() @@ -139,15 +217,11 @@ function Store:sendMonthCardEmail() end function Store:isMonthCardExpire() - local timeNow = skynet.timex() - local ts = self:getProperty("monthCardEx") - return ts < timeNow + return self:getProperty("monthCardEx") == 0 end -function Store:isSuperMonthCardExpire() - local timeNow = skynet.timex() - local ts = self:getProperty("smonthCardEx") - return ts < timeNow +function Store:isSuperMonthCardExpire(id) + return false end function Store:isPrivCardExpire() @@ -225,23 +299,97 @@ function Store:getCurMonthCardLvl(isSuper) return cfg.level or 0 end +--获取月卡每日奖励 +function Store:getMonthCardDailyReward(id) + if self:isMonthCardExpire() or self:getProperty("monthCardReceive") == 1 then return nil, nil end + + local before_ex = self:getProperty("monthCardEx") + self:updateProperty({field = "monthCardEx", delta = -1}) + local cur_ex = self:getProperty("monthCardEx") + + local actCfg = csvdb["shop_card"][id] or {} + local award = actCfg.itemDaily:toNumMap() + local reward, change = self.owner:award(award, {log = {desc = "monthCardReward", int1 = id, int2 = cur_ex}}) + + --今日月卡奖励已经领取 + self:updateProperty({field = "monthCardReceive", value = 1}) + + self.owner:log("month_card", { + item_type = CardType.NormalMonthCard, + item_id = id, --月卡id + before_ex = before_ex, --未领取奖励前的期 + cur_ex = cur_ex, --剩余期数 + reward_time = skynet.timex(), --奖励时间 + month_reward_detail = reward, + }) + return reward, change +end + +--获取特刊每日奖励 +function Store:getSMonthCardDailyReward(id) + local before_ex = SuperMonthCard["periods"](self, id) + local reward, change, cur_ex= SuperMonthCard["itemDaily"](self, id) + + --今日特刊奖励已经领取 + self:updateProperty({field = "smonthCardReceive", value = 1}) + + self.owner:log("month_card", { + item_type = CardType.SuperMonthCard, + item_id = id, --月卡id + before_ex = before_ex, --未领取奖励前的期 + cur_ex = cur_ex, --剩余期数 + reward_time = skynet.timex(), --奖励时间 + month_reward_detail = reward, + }) + return reward, change +end + +function Store:firstBuyMonthCard(id) + if self:getProperty("firstMonthCard") == 1 then + self:updateProperty({field = "firstMonthCard", value = 0}) + local card = csvdb["shop_cardCsv"][id] or {} + return self:award(card["cardFirst"], {log = {desc = "monthCardReward", int1 = id, int2 = 30}}) + end + return nil +end + -- 购买通行证 function Store:onBuyCard(type, duration, id, actid) local timeNow = skynet.timex() if type == CardType.NormalMonthCard then if self:isMonthCardExpire() then self:updateProperty({field = "monthCardId", value = id}) - self:updateProperty({field = "monthCardEx", value = timeNow + duration}) - else - self:updateProperty({field = "monthCardEx", value = self:getProperty("monthCardEx") + duration}) end - self:sendMonthCardEmail() + self:updateProperty({field = "monthCardEx", value = self:getProperty("monthCardEx") + 30}) + + --初回特典 仅首次购买月卡时赠送SSR级角色"拉塔托娅" + local reward = {} + local tmpreward, _ = self:firstBuyMonthCard(id) + if tmpreward then + for k, v in pairs(tmpreward) do + reward[k] = (reward[k] or 0) + v + end + end + + --签收奖励 + tmpreward, _= self:getMonthCardDailyReward(id) + if tmpreward then + for k, v in pairs(tmpreward) do + reward[k] = (reward[k] or 0) + v + end + end + return reward + elseif type == CardType.SuperMonthCard then + if SuperMonthCard["buy"](self, id) then + return self:getSMonthCardDailyReward(id) + end + return nil, nil elseif type == CardType.NormalMonthCardLevelUp then if self:isMonthCardExpire() then skynet.error(string.format("month card expired, can not level up,%d,%d",self.owner:getProperty("id"), id)) else local cfg = csvdb["shop_cardCsv"][id] - if not cfg then return end + if not cfg then return end local dif = cfg.level - self:getCurMonthCardLvl(false) if dif > 1 and dif < 0 then return @@ -250,20 +398,13 @@ function Store:onBuyCard(type, duration, id, actid) self:updateProperty({field = "monthCardEx", value = self:getProperty("monthCardEx") + duration}) end self:sendMonthCardEmail() - elseif type == CardType.SuperMonthCard then - if self:isSuperMonthCardExpire() then - self:updateProperty({field = "smonthCardId", value = id}) - self:updateProperty({field = "smonthCardEx", value = timeNow + duration}) - else - self:updateProperty({field = "smonthCardEx", value = self:getProperty("smonthCardEx") + duration}) - end - self:sendMonthCardEmail() + elseif type == CardType.SuperMonthCardLevelUp then if self:isSuperMonthCardExpire() then skynet.error(string.format("super month card expired, can not level up,%d,%d",self.owner:getProperty("id"), id)) else local cfg = csvdb["shop_cardCsv"][id] - if not cfg then return end + if not cfg then return end local dif = cfg.level - self:getCurMonthCardLvl(true) if dif > 1 and dif < 0 then return @@ -306,6 +447,7 @@ function Store:onBuyCard(type, duration, id, actid) self.owner:mylog("act_action", {desc="buyBc", int1=id, int2=actData["lvl"] or 0}) self.owner.activity:updateActData("BattleCommand", actData) end + return nil, nil end --检测购买是否超过限制数量 @@ -556,7 +698,6 @@ function Store:data() growFund = self:getProperty("growFund"), growFundR = self:getProperty("growFundR"), monthCardEx = self:getProperty("monthCardEx"), - smonthCardEx = self:getProperty("smonthCardEx"), battleCard = self:getProperty("battleCard"), battleFR = self:getProperty("battleFR"), battleLR = self:getProperty("battleLR"), -- libgit2 0.21.2