Commit 81941afdf1e89070c02985de2e2c07b836a5c197

Authored by zhangqijia
1 parent a93ce9c0

fix: 特刊增加初回特典, 优化了一下月卡购买的函数

Showing 2 changed files with 125 additions and 108 deletions   Show diff stats
src/models/RoleLog.lua
@@ -68,6 +68,8 @@ local ItemReason = { @@ -68,6 +68,8 @@ local ItemReason = {
68 smonthCardReward = 152, --特刊奖励 68 smonthCardReward = 152, --特刊奖励
69 itemConvertSpecial = 153, --兑换月卡/战令/探索指令 特殊道具 69 itemConvertSpecial = 153, --兑换月卡/战令/探索指令 特殊道具
70 buyDiamondCardReward = 154, --购买钻石额外赠送奖励 70 buyDiamondCardReward = 154, --购买钻石额外赠送奖励
  71 + firstMonthCardReward = 155, --首次订阅月卡奖励
  72 + firstSMonthCardReward = 156, --首次订阅特刊奖励
71 73
72 advHang = 301, -- 拾荒挂机 74 advHang = 301, -- 拾荒挂机
73 hangBattle = 302, -- 挂机战斗 75 hangBattle = 302, -- 挂机战斗
src/models/Store.lua
@@ -30,11 +30,12 @@ Store.schema = { @@ -30,11 +30,12 @@ Store.schema = {
30 30
31 monthCardEx = {"number", 0}, -- 期数 31 monthCardEx = {"number", 0}, -- 期数
32 monthCardId = {"number", 0}, -- 月卡id 32 monthCardId = {"number", 0}, -- 月卡id
33 - firstMonthCard = {"number", 1}, -- 首次订阅月卡 33 + firstMonthCard = {"number", 0}, -- 首次订阅月卡
34 monthCardReceive = {"number", 0}, -- 月卡奖励领取记录 当天 0-未领取, 1-已经领取 34 monthCardReceive = {"number", 0}, -- 月卡奖励领取记录 当天 0-未领取, 1-已经领取
35 35
36 smonthCards = {"table", {}}, --特刊信息 {[id]={["buyCount"]=0, ["periods"]=0}} buyCount: 购买次数,periods: 剩余期数, 36 smonthCards = {"table", {}}, --特刊信息 {[id]={["buyCount"]=0, ["periods"]=0}} buyCount: 购买次数,periods: 剩余期数,
37 smonthCardReceive = {"number", 0}, -- 特刊奖励领取记录 当天 0-未领取, 1-已经领取 37 smonthCardReceive = {"number", 0}, -- 特刊奖励领取记录 当天 0-未领取, 1-已经领取
  38 + firstSMonthCard = {"table", {}}, -- 首次订阅当期特刊
38 39
39 battleCard = {"number", 0}, -- 赛季卡 40 battleCard = {"number", 0}, -- 赛季卡
40 battleFR = {"string", ""}, -- 免费赛季卡领取记录 41 battleFR = {"string", ""}, -- 免费赛季卡领取记录
@@ -95,100 +96,8 @@ function Store:refreshWeekData(notify) @@ -95,100 +96,8 @@ function Store:refreshWeekData(notify)
95 self:flushWeekShop() 96 self:flushWeekShop()
96 end 97 end
97 98
98 -local SuperMonthCard = {}  
99 -  
100 -SuperMonthCard["buy"] = function(self, id)  
101 - local smonthCards = self:getProperty("smonthCards") or {}  
102 -  
103 - local buyLimitFunc = function(buylimit)  
104 - for k, v in pairs(buylimit) do  
105 - if k == 1 then  
106 - if v == 101 then  
107 - if self:isMonthCardExpire() then  
108 - skynet.error("月卡过期")  
109 - return false  
110 - end  
111 - else  
112 - if smonthCards[v] == nil then  
113 - skynet.error("没有购买增刊里的条件, %d", v)  
114 - return false  
115 - end  
116 - end  
117 - elseif k == 2 then  
118 - if smonthCards[v] == nil and v ~= 101 then  
119 - skynet.error("没有购买增刊里的条件, %d", v)  
120 - return false  
121 - end  
122 - if SuperMonthCard["isExpired"](self, v) == false and v ~= 101 then  
123 - skynet.error("上期特刊奖励没有领取完")  
124 - return false  
125 - end  
126 - end  
127 - end  
128 - return true  
129 - end  
130 -  
131 - local BuyMonthCard = {}  
132 - BuyMonthCard["renewal"]= function()  
133 - --续刊  
134 - local card = csvdb["shop_cardCsv"][id] or {}  
135 - if card["buyLimit"] and card["buyLimit"] ~= "" then  
136 - if buyLimitFunc(card["buyLimit"]:toNumMap()) == false then  
137 - skynet.error("不满足购买条件")  
138 - return false  
139 - end  
140 - end  
141 -  
142 - local smonthCard = smonthCards[id] or {}  
143 - if next(smonthCard) then  
144 - smonthCard["buyCount"] = (smonthCard["buyCount"] or 0) + 1  
145 - local periods = SuperMonthCard["periods"](self, id) + (card["amount"] or 30)  
146 - smonthCard["periods"] = periods  
147 -  
148 - self:updateProperty({field = "smonthCards", value = smonthCards})  
149 - return true  
150 - end  
151 - end  
152 - BuyMonthCard["order"] = function()  
153 - --增刊条件  
154 - local card = csvdb["shop_cardCsv"][id] or {}  
155 - if card["buyLimit"] and card["buyLimit"] ~= "" then  
156 - if buyLimitFunc(card["buyLimit"]:toNumMap()) == false then  
157 - skynet.error("不满足增刊条件")  
158 - return false  
159 - end  
160 - end  
161 - smonthCards[id] = {["periods"] = (card["amount"] or 30), ["buyCount"] = 1}  
162 -  
163 - self:updateProperty({field= "smonthCards", value = smonthCards})  
164 - return true  
165 - end  
166 -  
167 - if SuperMonthCard["isExpired"](self, id) then  
168 - local smonthCard = smonthCards[id] or {}  
169 - if next(smonthCard) then  
170 - return BuyMonthCard["renewal"]()  
171 - else  
172 - return BuyMonthCard["order"]()  
173 - end  
174 - else  
175 - return BuyMonthCard["renewal"]()  
176 - end  
177 -end  
178 -  
179 -SuperMonthCard["periods"] = function(self, id)  
180 - local smonthCards = self:getProperty("smonthCards") or {}  
181 - local smonthCard = smonthCards[id] or {}  
182 - return smonthCard["periods"] or 0  
183 -end  
184 -  
185 -SuperMonthCard["isExpired"] = function (self, id)  
186 - local periods = SuperMonthCard["periods"](self, id)  
187 - return periods == 0  
188 -end  
189 -  
190 -SuperMonthCard["itemDaily"] = function(self, id)  
191 - local cur_ex = SuperMonthCard["periods"](self, id) 99 +local function getCardItemDailyReward(self, id)
  100 + local cur_ex = self:getSMonthCardPeriods(self, id)
192 if cur_ex == 0 then return nil, nil end 101 if cur_ex == 0 then return nil, nil end
193 cur_ex = cur_ex - 1 102 cur_ex = cur_ex - 1
194 103
@@ -203,7 +112,7 @@ SuperMonthCard["itemDaily"] = function(self, id) @@ -203,7 +112,7 @@ SuperMonthCard["itemDaily"] = function(self, id)
203 return reward, change, cur_ex 112 return reward, change, cur_ex
204 end 113 end
205 114
206 -SuperMonthCard["itemFirst"] = function(self, id) 115 +local function getCardItemFirstReward(self, id)
207 local card = csvdb["shop_cardCsv"][id] or {} 116 local card = csvdb["shop_cardCsv"][id] or {}
208 local reward, _ = self.owner:award(card["itemFirst"], {isRecharge = true, log = {desc = "recharge", int1 = id}}) 117 local reward, _ = self.owner:award(card["itemFirst"], {isRecharge = true, log = {desc = "recharge", int1 = id}})
209 return reward 118 return reward
@@ -384,8 +293,8 @@ end @@ -384,8 +293,8 @@ end
384 function Store:getSMonthCardDailyReward(id) 293 function Store:getSMonthCardDailyReward(id)
385 if not id then return nil end 294 if not id then return nil end
386 295
387 - local before_ex = SuperMonthCard["periods"](self, id)  
388 - local reward, change, cur_ex= SuperMonthCard["itemDaily"](self, id) 296 + local before_ex = self:getSMonthCardPeriods(self, id)
  297 + local reward, change, cur_ex= getCardItemDailyReward(id)
389 298
390 --今日特刊奖励已经领取 299 --今日特刊奖励已经领取
391 self:updateProperty({field = "smonthCardReceive", value = 1}) 300 self:updateProperty({field = "smonthCardReceive", value = 1})
@@ -402,14 +311,116 @@ function Store:getSMonthCardDailyReward(id) @@ -402,14 +311,116 @@ function Store:getSMonthCardDailyReward(id)
402 end 311 end
403 312
404 function Store:firstBuyMonthCard(id) 313 function Store:firstBuyMonthCard(id)
405 - if self:getProperty("firstMonthCard") == 1 then  
406 - self:updateProperty({field = "firstMonthCard", value = 0}) 314 + if self:getProperty("firstMonthCard") == 0 then
  315 + self:updateProperty({field = "firstMonthCard", value = 1})
407 local card = csvdb["shop_cardCsv"][id] or {} 316 local card = csvdb["shop_cardCsv"][id] or {}
408 - return self.owner:award(card["itemOnce"], {log = {desc = "monthCardReward", int1 = id, int2 = 30}}) 317 + return self.owner:award(card["itemOnce"], {log = {desc = "firstMonthCardReward", int1 = id}})
409 end 318 end
410 return nil 319 return nil
411 end 320 end
412 321
  322 +function Store:firstBuySMonthCard(id)
  323 + local firstSMonthCard = self:getProperty("firstSMonthCard") or {}
  324 + if not firstSMonthCard[id] or firstSMonthCard[id] == 0 then
  325 + firstSMonthCard[id] = 1
  326 + self:updateProperty({field = "firstSMonthCard", value = firstSMonthCard})
  327 + local card = csvdb["shop_cardCsv"][id] or {}
  328 + return self.owner:award(card["itemOnce"], {log = {desc = "firstSMonthCardReward", int1 = id}})
  329 + end
  330 + return nil
  331 +end
  332 +
  333 +function Store:getSMonthCardPeriods(id)
  334 + local smonthCards = self:getProperty("smonthCards") or {}
  335 + local smonthCard = smonthCards[id] or {}
  336 + return smonthCard["periods"] or 0
  337 +end
  338 +
  339 +function Store:isSMonthCardExpired(id)
  340 + return self:getSMonthCardPeriods(id) == 0
  341 +end
  342 +
  343 +function Store:buySMonthCardLimit(buylimit)
  344 + local smonthCards = self:getProperty("smonthCards") or {}
  345 + for k, v in pairs(buylimit) do
  346 + if k == 1 then
  347 + if v == 101 then
  348 + if self:isMonthCardExpire() then
  349 + skynet.error("月卡过期")
  350 + return false
  351 + end
  352 + else
  353 + if smonthCards[v] == nil then
  354 + skynet.error("没有购买增刊里的条件, %d", v)
  355 + return false
  356 + end
  357 + end
  358 + elseif k == 2 then
  359 + if smonthCards[v] == nil and v ~= 101 then
  360 + skynet.error("没有购买增刊条件里的特刊, %d", v)
  361 + return false
  362 + end
  363 + if self:isSMonthCardExpired(v) == false and v ~= 101 then
  364 + skynet.error("上期特刊奖励没领完") --策划yc+hbw 没领完上期特刊,新一期特刊不展示,不允许购买
  365 + return false
  366 + end
  367 + end
  368 + end
  369 + return true
  370 +end
  371 +
  372 +function Store:buySMonthCard(id)
  373 + local smonthCards = self:getProperty("smonthCards") or {}
  374 +
  375 + local BuyMonthCard = {}
  376 + BuyMonthCard["renewal"]= function()
  377 + --续刊
  378 + local card = csvdb["shop_cardCsv"][id] or {}
  379 + if card["buyLimit"] and card["buyLimit"] ~= "" then
  380 + if self:buySMonthCardLimit(card["buyLimit"]:toNumMap()) == false then
  381 + skynet.error("不满足购买条件")
  382 + return false
  383 + end
  384 + end
  385 +
  386 + local smonthCard = smonthCards[id] or {}
  387 + if next(smonthCard) then
  388 + smonthCard["buyCount"] = (smonthCard["buyCount"] or 0) + 1
  389 + local periods = (smonthCard["periods"] or 0) + (card["amount"] or 30)
  390 + smonthCard["periods"] = periods
  391 +
  392 + self:updateProperty({field = "smonthCards", value = smonthCards})
  393 + return true
  394 + end
  395 + end
  396 +
  397 + BuyMonthCard["order"] = function()
  398 + --增刊
  399 + local card = csvdb["shop_cardCsv"][id] or {}
  400 + if card["buyLimit"] and card["buyLimit"] ~= "" then
  401 + if self:buySMonthCardLimit(card["buyLimit"]:toNumMap()) == false then
  402 + skynet.error("不满足增刊条件")
  403 + return false
  404 + end
  405 + end
  406 +
  407 + smonthCards[id] = {["periods"] = (card["amount"] or 30), ["buyCount"] = 1}
  408 + self:updateProperty({field= "smonthCards", value = smonthCards})
  409 + return true
  410 + end
  411 +
  412 + if self:isSMonthCardExpired(id) then
  413 + local smonthCard = smonthCards[id] or {}
  414 + if next(smonthCard) then
  415 + return BuyMonthCard["renewal"]()
  416 + else
  417 + return BuyMonthCard["order"]()
  418 + end
  419 + else
  420 + return BuyMonthCard["renewal"]()
  421 + end
  422 +end
  423 +
413 -- 购买通行证 424 -- 购买通行证
414 function Store:onBuyCard(type, duration, id, actid) 425 function Store:onBuyCard(type, duration, id, actid)
415 local timeNow = skynet.timex() 426 local timeNow = skynet.timex()
@@ -420,20 +431,23 @@ function Store:onBuyCard(type, duration, id, actid) @@ -420,20 +431,23 @@ function Store:onBuyCard(type, duration, id, actid)
420 self:updateProperty({field = "monthCardEx", value = self:getProperty("monthCardEx") + 30}) 431 self:updateProperty({field = "monthCardEx", value = self:getProperty("monthCardEx") + 30})
421 432
422 local reward = {} 433 local reward = {}
423 - --初回特典 仅首次购买月卡时赠送SSR级角色"拉塔托娅"  
424 - local tmpreward, _ = self:firstBuyMonthCard(id) 434 + local tmpreward, _ = self:firstBuyMonthCard(id) --初回特典 仅首次购买月卡
425 if tmpreward then table.rewardMerge(reward, tmpreward) end 435 if tmpreward then table.rewardMerge(reward, tmpreward) end
426 436
427 - --订阅奖励  
428 - tmpreward = SuperMonthCard["itemFirst"](self, id) 437 + tmpreward = getCardItemFirstReward(self, id) --订阅奖励
429 if next(tmpreward) then table.rewardMerge(reward, tmpreward) end 438 if next(tmpreward) then table.rewardMerge(reward, tmpreward) end
430 439
431 return reward 440 return reward
432 elseif type == CardType.SuperMonthCard then 441 elseif type == CardType.SuperMonthCard then
433 - if SuperMonthCard["buy"](self, id) then  
434 - skynet.error("特刊购买成功:"..id)  
435 - return SuperMonthCard["itemFirst"](self, id) 442 + if self:buySMonthCard(id) then
  443 + local reward = getCardItemFirstReward(self, id) or {}
  444 + local tmpreward, _ = self:firstBuySMonthCard(id)
  445 + if tmpreward then table.rewardMerge(reward, tmpreward) end
  446 +
  447 + return reward
436 end 448 end
  449 +
  450 + skynet.error("特刊购买失败:"..id)
437 return nil 451 return nil
438 elseif type == CardType.NormalMonthCardLevelUp then 452 elseif type == CardType.NormalMonthCardLevelUp then
439 if self:isMonthCardExpire() then 453 if self:isMonthCardExpire() then
@@ -852,6 +866,7 @@ function Store:data() @@ -852,6 +866,7 @@ function Store:data()
852 totalRR = self:getProperty("totalRR"), 866 totalRR = self:getProperty("totalRR"),
853 monthCardId = self:getProperty("monthCardId"), 867 monthCardId = self:getProperty("monthCardId"),
854 firstMonthCard = self:getProperty("firstMonthCard"), 868 firstMonthCard = self:getProperty("firstMonthCard"),
  869 + firstsMonthCard = self:getProperty("firstsMonthCard"),
855 monthCardReceive = self:getProperty("monthCardReceive"), 870 monthCardReceive = self:getProperty("monthCardReceive"),
856 smonthCards = self:getProperty("smonthCards"), 871 smonthCards = self:getProperty("smonthCards"),
857 smonthCardReceive = self:getProperty("smonthCardReceive"), 872 smonthCardReceive = self:getProperty("smonthCardReceive"),