Commit c40a6460046fa00b8aebc33142c3231cf41a83ab
1 parent
116ecca6
feat: 月卡+特刊
1. 购买 2. 初回特典 3. 每日奖励
Showing
5 changed files
with
228 additions
and
41 deletions
Show diff stats
src/ProtocolCode.lua
... | ... | @@ -222,6 +222,7 @@ actionCodes = { |
222 | 222 | Store_getBattlePassRewardRpc = 562, --赛季卡奖励 |
223 | 223 | Store_getExploreCommandRewardRpc = 563, --探索指令 |
224 | 224 | Store_getTotalRechargeAwardRpc = 564, -- 累计充值 |
225 | + Store_monthCardRewardRpc = 565, --每日月卡+特刊奖励 | |
225 | 226 | |
226 | 227 | Store_biliCloudRechargeRpc = 596, |
227 | 228 | Store_biliAndroidRechargeRpc = 597, | ... | ... |
src/actions/StoreAction.lua
... | ... | @@ -546,4 +546,32 @@ function _M.getTotalRechargeAwardRpc(agent, data) |
546 | 546 | return true |
547 | 547 | end |
548 | 548 | |
549 | +function _M.monthCardRewardRpc(agent, data) | |
550 | + local role = agent.role | |
551 | + local msg = MsgPack.unpack(data) | |
552 | + local mcid = msg.mcid | |
553 | + local smcid = msg.smcid | |
554 | + | |
555 | + local reward,change = {}, {} | |
556 | + --月卡奖励 | |
557 | + local tmpreward, tmpchange = role.storeData:getMonthCardDailyReward(mcid) | |
558 | + if tmpreward then | |
559 | + for k, v in pairs(tmpreward) do | |
560 | + reward[k] = (reward[k] or 0) + v | |
561 | + end | |
562 | + if tmpchange then table.insert(change, tmpchange) end | |
563 | + end | |
564 | + | |
565 | + --特刊奖励 | |
566 | + tmpreward, tmpchange = role.storeData:getSMonthCardDailyReward(smcid) | |
567 | + if tmpreward then | |
568 | + for k, v in pairs(tmpreward) do | |
569 | + reward[k] = (reward[k] or 0) + v | |
570 | + end | |
571 | + if tmpchange then table.insert(change, tmpchange) end | |
572 | + end | |
573 | + SendPacket(actionCodes.Store_monthCardRewardRpc, MsgPack.pack(role:packReward(reward, change))) | |
574 | + return true | |
575 | +end | |
576 | + | |
549 | 577 | return _M |
550 | 578 | \ No newline at end of file | ... | ... |
src/models/RoleLog.lua
... | ... | @@ -63,6 +63,8 @@ local ItemReason = { |
63 | 63 | giftTime = 147, -- 创角后的时间礼包 |
64 | 64 | activityCrisis = 148, -- 物资危机奖励 |
65 | 65 | glodConvertRune = 149, -- 金币兑换铭文 |
66 | + monthCardReward = 150, --月卡奖励 | |
67 | + smonthCardReward = 151, --特刊奖励 | |
66 | 68 | |
67 | 69 | advHang = 301, -- 拾荒挂机 |
68 | 70 | hangBattle = 302, -- 挂机战斗 |
... | ... | @@ -392,7 +394,15 @@ local MethodType = { |
392 | 394 | currency_type = true, -- 购买道具消耗的货币类型,记录货币ID |
393 | 395 | shop_purchase_current = true, -- 购买道具消耗的货币数量 |
394 | 396 | shop_id = true, -- 商店ID |
395 | - }, | |
397 | + }, | |
398 | + month_card = { --月卡+特刊奖励 | |
399 | + item_type = true, --月卡 1, 特刊 2 | |
400 | + item_id = true, --月卡id | |
401 | + before_ex = true, --未领取奖励前的期 | |
402 | + cur_ex = true, --剩余期数 | |
403 | + reward_time = true, --奖励时间 | |
404 | + month_reward_detail = "json", --奖励物品 {'itemid1':123,'itemid2':456,………...} | |
405 | + }, | |
396 | 406 | --[[ |
397 | 407 | 100 添加好友 |
398 | 408 | 200 删除好友 | ... | ... |
src/models/RolePlugin.lua
... | ... | @@ -2328,7 +2328,6 @@ function RolePlugin.bind(Role) |
2328 | 2328 | return rechargeId |
2329 | 2329 | end |
2330 | 2330 | |
2331 | - | |
2332 | 2331 | function Role:recharge(params) |
2333 | 2332 | local id = tonumber(params.id) |
2334 | 2333 | local rechargeData = csvdb["shop_rechargeCsv"][id] |
... | ... | @@ -2353,8 +2352,16 @@ function RolePlugin.bind(Role) |
2353 | 2352 | end |
2354 | 2353 | self:gainDiamond({count = diamondCount, isRecharge = true, sid = params.sid, log = {desc = "recharge", int1 = id}}) |
2355 | 2354 | elseif rechargeData.shop == 2 then --通行证商店 |
2355 | + --订阅奖励 | |
2356 | 2356 | reward, _ = self:award(rechargeData.itemFirst, {isRecharge = true, log = {desc = "recharge", int1 = id}}) |
2357 | - self.storeData:onBuyCard(rechargeData.type, rechargeData.time, rechargeData.id, rechargeData.activity_id) | |
2357 | + | |
2358 | + --签收奖励 | |
2359 | + local tmpreward, _ = self.storeData:onBuyCard(rechargeData.type, rechargeData.time, rechargeData.id, rechargeData.activity_id) | |
2360 | + if tmpreward then | |
2361 | + for k, v in pairs(tmpreward) do | |
2362 | + reward[k] = (reward[k] or 0) + v | |
2363 | + end | |
2364 | + end | |
2358 | 2365 | elseif rechargeData.shop == 3 then -- 礼包商店 |
2359 | 2366 | reward, _ = self:award(rechargeData.itemFirst, {isRecharge = true, log = {desc = "recharge", int1 = id}}) |
2360 | 2367 | else | ... | ... |
src/models/Store.lua
... | ... | @@ -8,24 +8,13 @@ end |
8 | 8 | |
9 | 9 | function Store:onLoad() |
10 | 10 | local monEx = self:getProperty("monthCardEx") |
11 | - local smonEx = self:getProperty("smonthCardEx") | |
12 | 11 | local monId = self:getProperty("monthCardId") |
13 | - local smonId = self:getProperty("smonthCardId") | |
14 | - local timeNow = skynet.timex() | |
15 | 12 | local flag = false |
16 | - if monEx > timeNow and monId == 0 then | |
13 | + if monEx > 0 and monId == 0 then | |
17 | 14 | self:updateProperty({field = "monthCardId", value = 101}) |
18 | 15 | self:updateProperty({field = "getMailT1", value = 0}) |
19 | 16 | flag = true |
20 | 17 | end |
21 | - if smonEx > timeNow and smonId == 0 then | |
22 | - self:updateProperty({field = "smonthCardId", value = 102}) | |
23 | - self:updateProperty({field = "getMailT2", value = 0}) | |
24 | - flag = true | |
25 | - end | |
26 | - if flag then | |
27 | - self:sendMonthCardEmail() | |
28 | - end | |
29 | 18 | end |
30 | 19 | |
31 | 20 | ActGoodsType = { |
... | ... | @@ -39,10 +28,13 @@ Store.schema = { |
39 | 28 | growFund = {"number", 0}, -- 成长基金 |
40 | 29 | growFundR = {"string", ""}, -- 成长基金领取记录 |
41 | 30 | |
42 | - monthCardEx = {"number", 0}, -- 月卡过期时间戳 | |
31 | + monthCardEx = {"number", 0}, -- 期数 | |
43 | 32 | monthCardId = {"number", 0}, -- 月卡id |
44 | - smonthCardEx = {"number", 0}, -- 超级月卡过期时间戳 | |
45 | - smonthCardId = {"number", 0}, -- 超级月卡id | |
33 | + firstMonthCard = {"number", 1}, -- 首次订阅月卡 | |
34 | + monthCardReceive = {"number", 0}, -- 月卡奖励领取记录 当天 0-未领取, 1-已经领取 | |
35 | + | |
36 | + smonthCards = {"table", {}}, --特刊信息 {[id]={["buyCount"]=0, ["periods"]=0, ["openFlag"]= 1}} buyCount: 购买次数,periods: 剩余期数,openFlag: 是否开放标识 | |
37 | + smonthCardReceive = {"number", 0}, -- 特刊奖励领取记录 当天 0-未领取, 1-已经领取 | |
46 | 38 | |
47 | 39 | battleCard = {"number", 0}, -- 赛季卡 |
48 | 40 | battleFR = {"string", ""}, -- 免费赛季卡领取记录 |
... | ... | @@ -82,11 +74,97 @@ function Store:updateProperty(params) |
82 | 74 | end |
83 | 75 | |
84 | 76 | function Store:onCrossDay() |
85 | - self:sendMonthCardEmail() | |
77 | + --self:sendMonthCardEmail() | |
86 | 78 | self:deleteExpireLimitGoods() |
87 | 79 | --self:checkPaySignReward() |
88 | 80 | end |
89 | 81 | |
82 | +local SuperMonthCard = {} | |
83 | + | |
84 | +SuperMonthCard["buy"] = function(self, id) | |
85 | + local smonthCards = self:getProperty("smonthCards") or {} | |
86 | + | |
87 | + local BuyMonthCard = {} | |
88 | + BuyMonthCard["renewal"]= function() | |
89 | + --续刊 | |
90 | + if self:isMonthCardExpire() then return false end | |
91 | + | |
92 | + local smonthCard = smonthCards[id] or {} | |
93 | + if next(smonthCard) then | |
94 | + local rechargeData = csvdb["shop_rechargeCsv"][id] or {} | |
95 | + local buyCount = smonthCard["buyCount"] or 0 | |
96 | + if buyCount >= (rechargeData["limit"] or 3) then return false end | |
97 | + | |
98 | + smonthCard["buyCount"] = (smonthCard["buyCount"] or 0) + 1 | |
99 | + | |
100 | + local card = csvdb["shop_cardCsv"][id] or {} | |
101 | + local periods = SuperMonthCard["periods"](self, id) + (card["cardPlusPeriods"] or 30) | |
102 | + smonthCard["periods"] = periods | |
103 | + | |
104 | + self:updateProperty({filed = "smonthCards", value = smonthCards}) | |
105 | + return true | |
106 | + end | |
107 | + end | |
108 | + BuyMonthCard["order"] = function() | |
109 | + --增刊条件 + 标识 | |
110 | + for _, val in pairs(smonthCards) do | |
111 | + val["openFlag"] = 0 | |
112 | + end | |
113 | + | |
114 | + local card = csvdb["shop_cardCsv"][id] or {} | |
115 | + if (card["cardPlusFlag"] or 0) ~= 1 then return false end | |
116 | + | |
117 | + --判断是否购买过增刊条件里的特刊 | |
118 | + | |
119 | + local cardPlusCondition = card["cardPlusCondition"] or 0 | |
120 | + if self:isMonthCardExpire() or smonthCards[cardPlusCondition] == nil then return false end | |
121 | + | |
122 | + local smonthCard = {["periods"] = (card["cardPlusPeriods"] or 30), ["buyCount"] = 1, ["openFlag"] = 1 } | |
123 | + smonthCards[id] = smonthCard | |
124 | + | |
125 | + self:updateProperty({filed = "smonthCards", value = smonthCards}) | |
126 | + return true | |
127 | + end | |
128 | + | |
129 | + if SuperMonthCard["isExpired"](self, id) then | |
130 | + local smonthCard = smonthCards[id] or {} | |
131 | + if next(smonthCard) then | |
132 | + return BuyMonthCard["renewal"]() | |
133 | + else | |
134 | + return BuyMonthCard["order"]() | |
135 | + end | |
136 | + else | |
137 | + return BuyMonthCard["renewal"]() | |
138 | + end | |
139 | +end | |
140 | + | |
141 | +SuperMonthCard["periods"] = function(self, id) | |
142 | + local smonthCards = self:getProperty("smonthCards") or {} | |
143 | + local smonthCard = smonthCards[id] or {} | |
144 | + return smonthCard["periods"] or 0 | |
145 | +end | |
146 | + | |
147 | +SuperMonthCard["isExpired"] = function (self, id) | |
148 | + local periods = SuperMonthCard["periods"](self, id) | |
149 | + return periods == 0 | |
150 | +end | |
151 | + | |
152 | +SuperMonthCard["itemDaily"] = function(self, id) | |
153 | + local cur_ex = SuperMonthCard["periods"](self, id) | |
154 | + if cur_ex == 0 then return nil, nil end | |
155 | + cur_ex = cur_ex - 1 | |
156 | + | |
157 | + local card = csvdb["shop_cardCsv"][id] or {} | |
158 | + local reward, change = self.owner:award(card["itemDaily"], {log = {desc = "smonthCardReward", int1 = id, int2 = cur_ex}}) | |
159 | + | |
160 | + local smonthCards = self:getProperty("smonthCards") or {} | |
161 | + local smonthCard = smonthCards[id] or {} | |
162 | + smonthCard["periods"] = cur_ex | |
163 | + self:updateProperty({field = "smonthCards", value = smonthCards}) | |
164 | + | |
165 | + return reward, change, cur_ex | |
166 | +end | |
167 | + | |
90 | 168 | -- 删除过期商品 |
91 | 169 | function Store:deleteExpireLimitGoods() |
92 | 170 | local timeNow = skynet.timex() |
... | ... | @@ -139,15 +217,11 @@ function Store:sendMonthCardEmail() |
139 | 217 | end |
140 | 218 | |
141 | 219 | function Store:isMonthCardExpire() |
142 | - local timeNow = skynet.timex() | |
143 | - local ts = self:getProperty("monthCardEx") | |
144 | - return ts < timeNow | |
220 | + return self:getProperty("monthCardEx") == 0 | |
145 | 221 | end |
146 | 222 | |
147 | -function Store:isSuperMonthCardExpire() | |
148 | - local timeNow = skynet.timex() | |
149 | - local ts = self:getProperty("smonthCardEx") | |
150 | - return ts < timeNow | |
223 | +function Store:isSuperMonthCardExpire(id) | |
224 | + return false | |
151 | 225 | end |
152 | 226 | |
153 | 227 | function Store:isPrivCardExpire() |
... | ... | @@ -225,23 +299,97 @@ function Store:getCurMonthCardLvl(isSuper) |
225 | 299 | return cfg.level or 0 |
226 | 300 | end |
227 | 301 | |
302 | +--获取月卡每日奖励 | |
303 | +function Store:getMonthCardDailyReward(id) | |
304 | + if self:isMonthCardExpire() or self:getProperty("monthCardReceive") == 1 then return nil, nil end | |
305 | + | |
306 | + local before_ex = self:getProperty("monthCardEx") | |
307 | + self:updateProperty({field = "monthCardEx", delta = -1}) | |
308 | + local cur_ex = self:getProperty("monthCardEx") | |
309 | + | |
310 | + local actCfg = csvdb["shop_card"][id] or {} | |
311 | + local award = actCfg.itemDaily:toNumMap() | |
312 | + local reward, change = self.owner:award(award, {log = {desc = "monthCardReward", int1 = id, int2 = cur_ex}}) | |
313 | + | |
314 | + --今日月卡奖励已经领取 | |
315 | + self:updateProperty({field = "monthCardReceive", value = 1}) | |
316 | + | |
317 | + self.owner:log("month_card", { | |
318 | + item_type = CardType.NormalMonthCard, | |
319 | + item_id = id, --月卡id | |
320 | + before_ex = before_ex, --未领取奖励前的期 | |
321 | + cur_ex = cur_ex, --剩余期数 | |
322 | + reward_time = skynet.timex(), --奖励时间 | |
323 | + month_reward_detail = reward, | |
324 | + }) | |
325 | + return reward, change | |
326 | +end | |
327 | + | |
328 | +--获取特刊每日奖励 | |
329 | +function Store:getSMonthCardDailyReward(id) | |
330 | + local before_ex = SuperMonthCard["periods"](self, id) | |
331 | + local reward, change, cur_ex= SuperMonthCard["itemDaily"](self, id) | |
332 | + | |
333 | + --今日特刊奖励已经领取 | |
334 | + self:updateProperty({field = "smonthCardReceive", value = 1}) | |
335 | + | |
336 | + self.owner:log("month_card", { | |
337 | + item_type = CardType.SuperMonthCard, | |
338 | + item_id = id, --月卡id | |
339 | + before_ex = before_ex, --未领取奖励前的期 | |
340 | + cur_ex = cur_ex, --剩余期数 | |
341 | + reward_time = skynet.timex(), --奖励时间 | |
342 | + month_reward_detail = reward, | |
343 | + }) | |
344 | + return reward, change | |
345 | +end | |
346 | + | |
347 | +function Store:firstBuyMonthCard(id) | |
348 | + if self:getProperty("firstMonthCard") == 1 then | |
349 | + self:updateProperty({field = "firstMonthCard", value = 0}) | |
350 | + local card = csvdb["shop_cardCsv"][id] or {} | |
351 | + return self:award(card["cardFirst"], {log = {desc = "monthCardReward", int1 = id, int2 = 30}}) | |
352 | + end | |
353 | + return nil | |
354 | +end | |
355 | + | |
228 | 356 | -- 购买通行证 |
229 | 357 | function Store:onBuyCard(type, duration, id, actid) |
230 | 358 | local timeNow = skynet.timex() |
231 | 359 | if type == CardType.NormalMonthCard then |
232 | 360 | if self:isMonthCardExpire() then |
233 | 361 | self:updateProperty({field = "monthCardId", value = id}) |
234 | - self:updateProperty({field = "monthCardEx", value = timeNow + duration}) | |
235 | - else | |
236 | - self:updateProperty({field = "monthCardEx", value = self:getProperty("monthCardEx") + duration}) | |
237 | 362 | end |
238 | - self:sendMonthCardEmail() | |
363 | + self:updateProperty({field = "monthCardEx", value = self:getProperty("monthCardEx") + 30}) | |
364 | + | |
365 | + --初回特典 仅首次购买月卡时赠送SSR级角色"拉塔托娅" | |
366 | + local reward = {} | |
367 | + local tmpreward, _ = self:firstBuyMonthCard(id) | |
368 | + if tmpreward then | |
369 | + for k, v in pairs(tmpreward) do | |
370 | + reward[k] = (reward[k] or 0) + v | |
371 | + end | |
372 | + end | |
373 | + | |
374 | + --签收奖励 | |
375 | + tmpreward, _= self:getMonthCardDailyReward(id) | |
376 | + if tmpreward then | |
377 | + for k, v in pairs(tmpreward) do | |
378 | + reward[k] = (reward[k] or 0) + v | |
379 | + end | |
380 | + end | |
381 | + return reward | |
382 | + elseif type == CardType.SuperMonthCard then | |
383 | + if SuperMonthCard["buy"](self, id) then | |
384 | + return self:getSMonthCardDailyReward(id) | |
385 | + end | |
386 | + return nil, nil | |
239 | 387 | elseif type == CardType.NormalMonthCardLevelUp then |
240 | 388 | if self:isMonthCardExpire() then |
241 | 389 | skynet.error(string.format("month card expired, can not level up,%d,%d",self.owner:getProperty("id"), id)) |
242 | 390 | else |
243 | 391 | local cfg = csvdb["shop_cardCsv"][id] |
244 | - if not cfg then return end | |
392 | + if not cfg then return end | |
245 | 393 | local dif = cfg.level - self:getCurMonthCardLvl(false) |
246 | 394 | if dif > 1 and dif < 0 then |
247 | 395 | return |
... | ... | @@ -250,20 +398,13 @@ function Store:onBuyCard(type, duration, id, actid) |
250 | 398 | self:updateProperty({field = "monthCardEx", value = self:getProperty("monthCardEx") + duration}) |
251 | 399 | end |
252 | 400 | self:sendMonthCardEmail() |
253 | - elseif type == CardType.SuperMonthCard then | |
254 | - if self:isSuperMonthCardExpire() then | |
255 | - self:updateProperty({field = "smonthCardId", value = id}) | |
256 | - self:updateProperty({field = "smonthCardEx", value = timeNow + duration}) | |
257 | - else | |
258 | - self:updateProperty({field = "smonthCardEx", value = self:getProperty("smonthCardEx") + duration}) | |
259 | - end | |
260 | - self:sendMonthCardEmail() | |
401 | + | |
261 | 402 | elseif type == CardType.SuperMonthCardLevelUp then |
262 | 403 | if self:isSuperMonthCardExpire() then |
263 | 404 | skynet.error(string.format("super month card expired, can not level up,%d,%d",self.owner:getProperty("id"), id)) |
264 | 405 | else |
265 | 406 | local cfg = csvdb["shop_cardCsv"][id] |
266 | - if not cfg then return end | |
407 | + if not cfg then return end | |
267 | 408 | local dif = cfg.level - self:getCurMonthCardLvl(true) |
268 | 409 | if dif > 1 and dif < 0 then |
269 | 410 | return |
... | ... | @@ -306,6 +447,7 @@ function Store:onBuyCard(type, duration, id, actid) |
306 | 447 | self.owner:mylog("act_action", {desc="buyBc", int1=id, int2=actData["lvl"] or 0}) |
307 | 448 | self.owner.activity:updateActData("BattleCommand", actData) |
308 | 449 | end |
450 | + return nil, nil | |
309 | 451 | end |
310 | 452 | |
311 | 453 | --检测购买是否超过限制数量 |
... | ... | @@ -556,7 +698,6 @@ function Store:data() |
556 | 698 | growFund = self:getProperty("growFund"), |
557 | 699 | growFundR = self:getProperty("growFundR"), |
558 | 700 | monthCardEx = self:getProperty("monthCardEx"), |
559 | - smonthCardEx = self:getProperty("smonthCardEx"), | |
560 | 701 | battleCard = self:getProperty("battleCard"), |
561 | 702 | battleFR = self:getProperty("battleFR"), |
562 | 703 | battleLR = self:getProperty("battleLR"), | ... | ... |