From 9ea0c50278fab51eb65e3a184490bd945cdfe712 Mon Sep 17 00:00:00 2001 From: liuzujun <307836273@qq.com> Date: Mon, 17 Aug 2020 20:57:12 +0800 Subject: [PATCH] 限时礼包 --- src/GlobalVar.lua | 18 ++++++++++++------ src/ProtocolCode.lua | 1 + src/actions/RoleAction.lua | 13 +++++++++++++ src/actions/StoreAction.lua | 7 +++++++ src/csvdata | 2 +- src/models/Role.lua | 2 ++ src/models/RolePlugin.lua | 1 + src/models/RoleTask.lua | 17 +++++++++++++++++ src/models/Store.lua | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 9 files changed, 120 insertions(+), 10 deletions(-) diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index 61b461a..86f5ba4 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -290,12 +290,18 @@ MailId = { SuperMonthCardEx = 204, BattleCardAward = 210, - ActDrawCard = 231, - ActOpenBox = 232, + ActSellFood = 231, + ActDrawCard = 232, ActAdvDraw = 233, - ActSellFood = 234, - ActDrawCardReward = 221, - ActOpenBoxReward = 222, + ActOpenBox = 234, + ActSellFoodReward = 221, + ActDrawCardReward = 222, ActAdvDrawReward = 223, - ActSellFoodReward = 224, + ActOpenBoxReward = 224, } + +TriggerEventType = { + HangPass = 1, + LevelUp = 2, + TowerPass = 3, +} \ No newline at end of file diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 3dc3e2d..c0e2b7f 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -44,6 +44,7 @@ actionCodes = { Role_guideRpc = 129, Role_getRandomNameRpc = 130, Role_goldBuyRpc = 131, + Role_getDownloadCvRewardRpc = 132, Adv_startAdvRpc = 151, Adv_startHangRpc = 152, diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index 1dfd245..f6f46b3 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -1065,4 +1065,17 @@ function _M.goldBuyRpc(agent, data) return true end +function _M.getDownloadCvRewardRpc(agent, data) + local role = agent.role + local flag = role:getProperty("downCvR") or 0 + if flag ~= 0 then + return 1 + end + local r = globalCsv.role_download_cv_reward + local reward, change = role:award(r, {log = {desc = "downloadCv"}}) + role:updateProperty({field="downCvR", value=1}) + SendPacket(actionCodes.Role_getDownloadCvRewardRpc, MsgPack.pack(role:packReward(reward, change))) + return true +end + return _M \ No newline at end of file diff --git a/src/actions/StoreAction.lua b/src/actions/StoreAction.lua index 4abce08..bb55ffb 100644 --- a/src/actions/StoreAction.lua +++ b/src/actions/StoreAction.lua @@ -263,6 +263,13 @@ function _M.shopBuyRpc(agent , data) local dataSet = csvdb["shop_normalCsv"][id] if not dataSet then return end + if dataSet.unlock ~= "" then + if not role:checkHangPass(tonumber(config.unlock)) then + skynet.error(string.format("shopBuyRpc,user do not finish hang pass, user_id:%d", role:getProperty("id"))) + return 1 + end + end + local buyRecord = role.storeData:getProperty("buyR") if math.illegalNum(count, 1, (dataSet.limit == 0 and math.huge or dataSet.limit - (buyRecord[id] or 0))) then skynet.error(string.format("shop buy over limit, user_id:%d, goods_id:%d", role:getProperty("id"), id)) diff --git a/src/csvdata b/src/csvdata index f52151f..3929031 160000 --- a/src/csvdata +++ b/src/csvdata @@ -1 +1 @@ -Subproject commit f52151f947b019976eac7ef15ec914bf7d552d64 +Subproject commit 3929031d3194a0403fab720ab39bc40bc79c734d diff --git a/src/models/Role.lua b/src/models/Role.lua index 8afcc60..c9cfc48 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -159,6 +159,8 @@ Role.schema = { redp = {"table", {}}, -- 待消除红点 -- 通常打开对应界面就消除的红点 红点消除的方法 在对应的协议中使用 {tag = pms } chatline = {"table", {}}, -- 奖励发放 id=时间 + + downCvR = {"number", 0}, -- 下载cv扩展包奖励 } diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index ad74057..c3da8ab 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -217,6 +217,7 @@ function RolePlugin.bind(Role) if csvdb["player_expCsv"][level + 1] then -- 有下一级 newExp = newExp - csvdb["player_expCsv"][level].exp level = level + 1 + self:checkTaskEnter("RoleLevelUp", {level = level}) else newExp = csvdb["player_expCsv"][level].exp - 1 -- 没有下一级了 经验溢出太多 扣除 end diff --git a/src/models/RoleTask.lua b/src/models/RoleTask.lua index cd94306..d6ee90b 100644 --- a/src/models/RoleTask.lua +++ b/src/models/RoleTask.lua @@ -76,6 +76,9 @@ local TaskType = { AddFriend = 802, -- 加入一个好友 - count GetFriendP = 803, -- 获得友情点 - count + -- 角色相关 + RoleLevelUp = 901, -- 角色升级 - curlevel + --功能未实现 todo AdvShop = 1002, -- 冒险商城 UnionBoss = 1004, -- 工会boss @@ -216,6 +219,15 @@ local ActivityListener = { } } +local StoreListener = { + func = "checkStoreTask", + listen = { + [TaskType.HangPass] = {{TriggerEventType.HangPass, f("id")}}, + [TaskType.RoleLevelUp] = {{TriggerEventType.LevelUp, f("level")}}, + [TaskType.TowerPass] = {{TriggerEventType.TowerPass, f("level")}}, + } +} + local TaskListeners = { StoryListener, @@ -223,6 +235,7 @@ local TaskListeners = { AchievListener, SudokuListener, ActivityListener, + StoreListener, } local RoleTask = {} @@ -533,6 +546,10 @@ function RoleTask.bind(Role) self.activity:checkActivity(notNotify, activityType, ...) end + function Role:checkStoreTask(notNotify, triggerType, param) + self.storeData:OnTriggerLimitTimePack(triggerType, param) + end + end return RoleTask \ No newline at end of file diff --git a/src/models/Store.lua b/src/models/Store.lua index 8ab41ff..d912b57 100644 --- a/src/models/Store.lua +++ b/src/models/Store.lua @@ -20,6 +20,7 @@ Store.schema = { privCardEx = {"number", 0}, -- 特权卡过期时间戳 getMailT1 = {"number",0}, -- 上次发送月卡福利邮件的时间 getMailT2 = {"number",0}, -- 上次发送超级月卡福利邮件的时间 + packTrigger = {"table", {}} -- 礼包触发记录 {关卡难度1={id, 通关关卡数,升级数,爬塔层数}, ...} } function Store:updateProperty(params) @@ -60,7 +61,7 @@ end -- 发送月卡邮件 function Store:sendMonthCardEmail() local timeNow = skynet.timex() - local tabs = {{ex="monthCardEx", t="getMailT1", mail=MailId.MonthCard, alert=MailId.MonthCardEx}, + local tabs = {{ex="monthCardEx", t="getMailT1", mail=MailId.MonthCard, alert=MailId.MonthCardEx}, {ex="smonthCardEx", t="getMailT2", mail=MailId.SuperMonthCard, alert=MailId.SuperMonthCardEx}} for _, v in ipairs(tabs) do local ex = self:getProperty(v.ex) @@ -216,7 +217,7 @@ function Store:onBattleCardReset() if config then local freeFlag = string.char(string.getbit(battleCardFreeRecord, id)) local limitFlag = string.char(string.getbit(battleCardLimitRecord, id)) - + if battlePoint < config.point then break end @@ -227,7 +228,7 @@ function Store:onBattleCardReset() concatGift(config.giftLimit) end end - end + end self.owner:sendMail(MailId.BattleCardAward, nil, gift) -- 计算剩余奖励 self:updateProperty({field = "battleCard", value=0}) @@ -266,6 +267,68 @@ function Store:resetStoreReored(resetId) self:updateProperty({field = "buyR", value = buyRecord}) end +--触发限时礼包 +function Store:OnTriggerLimitTimePack(eventType, param) + local limitPack = self:getProperty("limitTPack") + local timeNow = skynet.timex() + local find = false + -- 有未过期的限时礼包不再推送 + for k, v in pairs(limitPack) do + if v > timeNow then + find = true + break + end + end + if find == true then + return + end + limitPack = {} + local hangPass = self.owner:getProperty("hangPass") + local triggerRecord = self:getProperty("packTrigger") + local result = {} + local maxDiff = 0 + -- 取满足限时礼包关卡要求的对应数据 + for diff, maxCarbonId in pairs(hangPass) do + for id, cfg in pairs(csvdb["shop_packCsv"]) do + local range = cfg.showRange:toArray(true, "=") + local beginRange = range[1] or 0 + local endRange = range[2] or 0 + if maxCarbonId > beginRange and maxCarbonId <= endRange and cfg.type == eventType then + result[diff] = cfg + maxDiff = math.max(maxDiff, diff) + break + end + end + end + local shopGoodsId = 0 + for diff, cfg in pairs(result) do + if diff == maxDiff then + local record = triggerRecord[diff] or {} + if (record[0] or 0) ~= cfg.id and next(record) then + record = {} + end + record[0] = cfg.id + record[eventType] = (record[eventType] or 0) + 1 + if record[eventType] == 1 or record[eventType] % 10 == 0 then + local pool = cfg.packId:toArray(true, "=") + local idx = math.random(1, #pool) + shopGoodsId = pool[idx] + end + triggerRecord[diff] = record + end + end + if shopGoodsId ~= 0 then + local rechargeCfg = csvdb["shop_rechargeCsv"][shopGoodsId] + if rechargeCfg then + limitPack[rechargeCfg.id] = timeNow + rechargeCfg.time + self:updateProperty({field = "limitTPack", value = limitPack}) + end + end + if next(result) then + self:updateProperty({field = "packTrigger", value = triggerRecord}) + end +end + function Store:data() return { buyR = self:getProperty("buyR"), -- libgit2 0.21.2