From 98be031a95ed3dd5bee1ad553e5237d256c9d259 Mon Sep 17 00:00:00 2001 From: liuzujun <307836273@qq.com> Date: Fri, 15 Jan 2021 12:04:38 +0800 Subject: [PATCH] 新年活动 --- src/ProtocolCode.lua | 2 ++ src/actions/ActivityAction.lua | 49 ++++++++++++++++++++++++++++++++++++++++++++----- src/actions/AdvAction.lua | 32 ++++++++++++++++++++++++++++++++ src/adv/Adv.lua | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- src/csvdata | 2 +- src/models/Activity.lua | 21 +++++++++++++++++++++ src/models/RoleLog.lua | 1 + src/models/Store.lua | 4 ++-- src/preload.lua | 2 +- 9 files changed, 159 insertions(+), 12 deletions(-) diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index d29722b..8733b8e 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -234,6 +234,8 @@ actionCodes = { Activity_battleCommandRpc = 668, Activity_actCalendaTmpTaskRpc = 669, Activity_newSignRpc = 670, + Activity_advLevelRpc = 671, + Activity_buyBattleCommandLvlRpc = 672, Radio_startQuestRpc = 700, Radio_finishQuestRpc = 701, diff --git a/src/actions/ActivityAction.lua b/src/actions/ActivityAction.lua index 25393d4..fa34ba2 100644 --- a/src/actions/ActivityAction.lua +++ b/src/actions/ActivityAction.lua @@ -1152,6 +1152,7 @@ function _M.battleCommandRpc(agent, data) local actid = msg.actid -- 活动id local index = msg.index -- 领取的阶段id local pay = msg.pay -- 是否是超级奖励 + print(actid, index, pay) if not role.activity:isOpenById(actid, "BattleCommand") then return 1 end local actCtrlData = csvdb["activity_ctrlCsv"][actid] @@ -1167,7 +1168,7 @@ function _M.battleCommandRpc(agent, data) bpCfg = bpCfg[index] if not bpCfg then return 4 end - if (actData["lvl"] or 0) < bpCfg["typeId"] then return 5 end + if (actData["lvl"] or 0) < bpCfg["type"] then return 5 end local record = "" if pay then @@ -1179,7 +1180,7 @@ function _M.battleCommandRpc(agent, data) local flag = string.char(string.getbit(record, index)) if flag == "1" then - return 4 + return 6 end record = string.setbit(record, index) @@ -1204,6 +1205,7 @@ function _M.buyBattleCommandLvlRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) local actid = msg.actid -- 活动id + local count = msg.count if not role.activity:isOpenById(actid, "BattleCommand") then return 1 end local actCtrlData = csvdb["activity_ctrlCsv"][actid] @@ -1216,13 +1218,13 @@ function _M.buyBattleCommandLvlRpc(agent, data) local actData = role.activity:getActData("BattleCommand") or {} local curLvl = actData["lvl"] or 0 - local nextLvl = curLvl + 1 + local nextLvl = curLvl + count if curLvl >= bpCfg[#bpCfg]["type"] then return 4 end local cost = 0 for i = 1, #bpCfg do local cfg = bpCfg[i] - if cfg["type"] == curLvl then - cost = cfg["cost"] + if cfg["type"] > curLvl and cfg["type"] <= nextLvl then + cost = cost + cfg["cost"] break end end @@ -1267,4 +1269,41 @@ function _M.newSignRpc(agent, data) return true end +-- 活动拾荒领取阶段奖励 +function _M.advLevelRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local actid = msg.actid + local index = msg.index + + if not role.activity:isOpenById(actid, "AdvLevel") then return 1 end + + local actCfg = csvdb["activity_stagesAwardCsv"][actid] + if not actCfg then return 2 end + actCfg = actCfg[index] + if not actCfg then return 3 end + + local actData = role.activity:getActData("AdvLevel") or {} + local record = actData["r"] + local flag = string.char(string.getbit(record, index)) + + if flag == "1" then return 4 end + + local chapters = actCfg["condition2"]:toArray(true, "=") + local totalVal = 0 + for i = 1, #chapters do + local cid = chapters[i] + totalVal = totalVal + (actData[cid] or 0) + end + if totalVal < actCfg["condition1"] then return 5 end + + actData["r"] = string.setbit(record, index) + role.activity:updateActData("AdvLevel", actData) + + local reward, change = role:award(actCfg.reward, {log = {desc = "advLevelStage", int1 = actid, int2 = index}}) + + SendPacket(actionCodes.Activity_advLevelRpc, MsgPack.pack(role:packReward(reward, change))) + return true +end + return _M diff --git a/src/actions/AdvAction.lua b/src/actions/AdvAction.lua index 115cff2..d72bcac 100644 --- a/src/actions/AdvAction.lua +++ b/src/actions/AdvAction.lua @@ -86,6 +86,7 @@ function _M.startAdvRpc( agent, data ) local role = agent.role local msg = MsgPack.unpack(data) local chapterId = msg.chapterId --关卡id + local actid = msg.actid --活动id local layer = msg.layer or 1 --选择层数 --local format = msg.format --编队 local supportIdx = msg.supportIdx --选择的支援效果 @@ -96,6 +97,36 @@ function _M.startAdvRpc( agent, data ) local advHang = role:getProperty("advHang") -- if advHang[chapterId] then return 9 end --正在挂机 + -- 检查活动正确性 + if actid then + if not role.activity:isOpenById(actid, "AdvLevel") then + return 20 + end + local actCfg = csvdb["activity_adv_chapterCsv"][actid] + if not actCfg then return 21 end + actCfg = actCfg[chapterId] + if not actCfg then return 22 end + + local st = toUnixtime(actCfg["unlockTime"]..string_format("%02x", RESET_TIME)) + if st > skynet.timex() then return 23 end + + if actCfg["prepose"] ~= "" then + local type, cid = actCfg["prepose"]:toArray(true, "=") + if type == 1 then + local actData = role.activity:getActData("ChallengeLevel") + local battleInfo = actData[cid] or {} + if (battleInfo["star"] or 0) == 0 then + return 24 + end + elseif type == 2 then + local actData = role.activity:getActData("AdvLevel") + local advInfo = actData[cid] or {} + if not advInfo["pass"] then + return 25 + end + end + end + end local chapterData = csvdb["adv_chapterCsv"][chapterId] if not chapterData or layer < 1 then return 1 end @@ -174,6 +205,7 @@ function _M.startAdvRpc( agent, data ) isRelay = layer ~= 1, isEnter = true, support = support, + actid = actid }) role:checkTaskEnter("AdvStart", {id = chapterId}) role:checkTaskEnter("AdvStartSelf", {id = chapterId}) diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index 4cd0432..b172f99 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -41,6 +41,7 @@ function Adv:initByInfo(advInfo) self.chapterId = advInfo.chapterId self.level = advInfo.level or 1 + self.actid = advInfo.actid self.round = advInfo.round or 0 self.score = advInfo.score or {} self.isRelay = advInfo.isRelay @@ -85,6 +86,7 @@ function Adv:initByChapter(params) local isEnter = params.isEnter local support = params.support local debugMapId = params.debugMapId + local actid = params.actid if not self.chapterId then -- 开始新的章节 self.chapterId = chapterId @@ -95,6 +97,7 @@ function Adv:initByChapter(params) self.level = level or 1 self.round = 0 + self.actid = self.actid or actid self.score = self.score or {} self.lastEnemyId = 1 self.mapStack = {1} -- 最后一个为当前的地图 @@ -175,6 +178,7 @@ end function Adv:clear() self.chapterId = nil self.level = nil + self.actid = 0 self.score = {} self.round = 0 self.lastEnemyId = 1 @@ -197,6 +201,7 @@ function Adv:saveDB(notNotify) advInfo.level = self.level advInfo.round = self.round advInfo.score = self.score + advInfo.actid = self.actid advInfo.isRelay = self.isRelay advInfo.lastEId = self.lastEnemyId advInfo.mstack = self.mapStack @@ -793,9 +798,55 @@ function Adv:over(success, rewardRatio, overType) local score = self.owner:fixAdvScoreChange(self:getScore()) local scoreInfo = self.score + + local scoreCoef = chapterData.scoreAward + local itemId = ItemId.OldCoin + -- 拾荒活动关卡相关处理 + if self.actid then + while true do + if not self.owner.activity:isOpenById(self.actid, "AdvLevel") then + break + end + local actCfg = csvdb["activity_adv_chapterCsv"][self.actid] + if not actCfg then break end + actCfg = actCfg[self.chapterId] + if not actCfg then break end + itemId, scoreCoef = actCfg["transform"]:toArray(true, "=") + local actData = self.owner.activity:getActData("AdvLevel") + + -- 计算活动积分up + local upMap = actCfg["upCharacter"] + local team = self.owner:getProperty("advTeam") + local format = self.owner:getTeamHerosInfo(team).heros + local upVal = 0 + for _, hero in pairs(format) do + local heroId = hero["type"] + upVal = upVal + (upMap[heroId] or 0) + end + score = math.floor(score * (1 + upVal / 100)) + + local advInfo = actData[self.chapterId] or {} + local maxScore = advInfo["max"] or 0 + local flag = false + if success then + advInfo["pass"] = 1 + flag = true + end + -- 更新活动最大积分 + if score > maxScore then + advInfo["max"] = score + actData[self.chapterId] = advInfo + flag = true + end + if flag then + self.owner.activity:updateActData("AdvLevel", actData) + end + break + end + end - local scoreReward = math.floor(score / chapterData.scoreAward) - self.owner:award({[ItemId.OldCoin] = scoreReward}, {log = {desc = "advOver", int1 = self.chapterId}}) + local scoreReward = math.floor(score / scoreCoef) + self.owner:award({[itemId] = scoreReward}, {log = {desc = "advOver", int1 = self.chapterId}}) -- 被动技会影响奖励 self.battle.player:triggerPassive(Passive.ADV_OVER, {score = score, level = self.level}) @@ -832,7 +883,7 @@ function Adv:over(success, rewardRatio, overType) local roleId = self.owner:getProperty("id") local oldMaxScore = tonum(redisproxy:zscore(self.owner:getAdvRankKey(), roleId)) - if score > oldMaxScore then + if score > oldMaxScore and not self.actid then local team = self.owner:getProperty("advTeam") local curInfo = { name = self.owner:getProperty("name"), @@ -918,6 +969,7 @@ function Adv:over(success, rewardRatio, overType) scoreAward = scoreReward, chapterId = chapterId, backAdvCount = backAdvCount, + actid = self.actid }) end diff --git a/src/csvdata b/src/csvdata index d79bc81..7320a5f 160000 --- a/src/csvdata +++ b/src/csvdata @@ -1 +1 @@ -Subproject commit d79bc812353a7e7f9f7e9826ea38e54e0e7339d9 +Subproject commit 7320a5f8d782d63b7ad6fc6e310e3f7425c280a1 diff --git a/src/models/Activity.lua b/src/models/Activity.lua index f63db63..d7d7779 100644 --- a/src/models/Activity.lua +++ b/src/models/Activity.lua @@ -86,6 +86,8 @@ Activity.schema = { act28 = {"table", {}}, -- 每日活跃签到 {0=day, 1=1,2=1,3=1} act30 = {"table", {}}, -- {magic = 0, limit = 0, reward = {id = 1, id = 1}, giveAE = {}, getAE = {}} 奖励字段1表示领取过奖励 + act33 = {"table", {}}, -- 拾荒关卡活动 {id={max=最大积分, pass=1}, r=""} + act34 = {"table", {}}, -- 战令记录{unlock = 1, freeR = "", payR = "", lvl = 10, sum = 100} act36 = {"table", {}}, -- 每日活跃签到 {0=day, 1=1,2=1,3=1} } @@ -112,6 +114,8 @@ function Activity:data() act28 = self:getProperty("act28"), act30 = self:getProperty("act30"), + act33 = self:getProperty("act33"), + act34 = self:getProperty("act34"), act36 = self:getProperty("act36"), } @@ -975,6 +979,7 @@ activityFunc[Activity.ActivityType.BattleCommand] = { self:updateActData(actType, data, not notify) end, ["check"] = function(self, actType, notify, id, count) -- 检查 itemid, count + print("babababa", id, count) local isOpen, actId = self:isOpen(actType) local actData = self:getActData(actType) or {} local actCfg = csvdb["activity_ctrlCsv"][actId] @@ -1026,4 +1031,20 @@ activityFunc[Activity.ActivityType.NewSign] = { end, } +activityFunc[Activity.ActivityType.AdvLevel] = { + -- ["check"] = function(self, actType, notify) -- 检查 + -- end, + ["init"] = function(self, actType, isCrossDay, notify) + end, + ["close"] = function(self, actType, notify, actid) + local actCfg = csvdb["activity_adv_chapterCsv"][actid] + if not actCfg then return end + for chapterId, _ in ipairs(actCfg) do + local advPass = self.owner:getProperty("advPass") + advPass[chapterId] = nil + self.owner:updateProperty({field="advPass", value=advPass}) + end + end, +} + return Activity diff --git a/src/models/RoleLog.lua b/src/models/RoleLog.lua index dea5932..16d5528 100644 --- a/src/models/RoleLog.lua +++ b/src/models/RoleLog.lua @@ -56,6 +56,7 @@ local ItemReason = { actBattleCommand = 140, -- 活动战令 actBuyBpLevel = 141, -- 购买活动战令等级 newSign = 142,-- 新的活动签到 + advLevelStage = 143, -- 拾荒活动阶段奖励 advHang = 301, -- 拾荒挂机 diff --git a/src/models/Store.lua b/src/models/Store.lua index b5466c7..a23bb2d 100644 --- a/src/models/Store.lua +++ b/src/models/Store.lua @@ -222,17 +222,17 @@ function Store:onBuyCard(type, duration, id, actid) bpInfo[index] = info self:updateProperty({field = "bpInfo", value = bpInfo}) elseif type == CardType.ActBattleCommandCard then - if not self.owner.activity:isOpenById(actid, "BattleCommand") then + if not self.owner.activity:isOpenById(actid, "ActShopGoods") then return end local actCfg = csvdb["activity_ctrlCsv"][actid] if not actCfg then return end local actData = self.owner.activity:getActData("BattleCommand") or {} - if actData["unlock"] == 1 then return end actData["unlock"] = 1 if actCfg.condition ~= 0 then actData["lvl"] = (actData["lvl"] or 0) + actCfg.condition end + self.owner.activity:updateActData("BattleCommand", actData) end end diff --git a/src/preload.lua b/src/preload.lua index eba52bc..c3f3967 100644 --- a/src/preload.lua +++ b/src/preload.lua @@ -2,5 +2,5 @@ local skynet = require "skynet" skynet.timex = function () - return math.floor(skynet.time()) + return math.floor(skynet.time()) + 2332771 end \ No newline at end of file -- libgit2 0.21.2