From 95c9089b72c840bd4789490bf3f01eaea35a0ae5 Mon Sep 17 00:00:00 2001 From: zqj <582132116@qq.com> Date: Wed, 25 Aug 2021 16:20:15 +0800 Subject: [PATCH] feat: 新增世界线积分功能。 --- src/GlobalVar.lua | 8 ++++++++ src/ProtocolCode.lua | 2 ++ src/actions/RoleAction.lua | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/models/Role.lua | 5 +++++ src/models/RoleLog.lua | 2 ++ src/models/RolePlugin.lua | 19 +++++++++++++++++++ 6 files changed, 97 insertions(+), 0 deletions(-) diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index 4467be1..c83dab6 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -441,4 +441,12 @@ ItemOccupy = { Spark = 5, --火花 Other = 6, CanUsed = 7, --可使用 +} + +-- 世界变动积分 +ItemWorldLine = { + RouletteCount = 1, --抽轮盘次数 + Points = 2, --积分 + CostDiamond = 3, --消耗钻石 + CostJade = 4, --消耗红光玉 } \ No newline at end of file diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 825c9f3..61375e4 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -60,6 +60,8 @@ actionCodes = { Role_setFriendTeamRpc = 143, -- 设置好友切磋队伍 Role_setBgRpc = 144, -- 设置看板娘 Role_itemConvertMonthCardRpc = 145, -- 兑换月卡/战令道具 + Role_worldLineRoulette = 146, --世界线抽轮盘 + Role_worldLineReward = 147, -- 世界线一键领取奖励 Adv_startAdvRpc = 151, Adv_startHangRpc = 152, diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index 2d5fe28..13f646c 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -1744,4 +1744,65 @@ function _M.itemConvertMonthCardRpc(agent, data) return status end +function _M.worldLineRoulette(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + + local worldChangePoints = role:getProperty("worldChangePoints") or {} + local rouletteCount = worldChangePoints[ItemWorldLine.RouletteCount] or 0 + if rouletteCount == 0 then return 1 end + + local worldline_gift_base_10, worldline_gift_base_1, worldline_gift_magnification_10, worldline_gift_magnification_1 = {}, {}, {}, {} + for k, v in pairs(globalCsv.worldline_gift_base_10) do + worldline_gift_base_10[k] = {v} + end + for k, v in pairs(globalCsv.worldline_gift_base_1) do + worldline_gift_base_1[k] = {v} + end + for k, v in pairs(globalCsv.worldline_gift_magnification_10) do + worldline_gift_magnification_10[k] = {v} + end + for k, v in pairs(globalCsv.worldline_gift_magnification_1) do + worldline_gift_magnification_1[k] = {v} + end + + local gift_base_10 = (math.randWeight(worldline_gift_base_10, 1) or 0) * 10 + local gift_base_1 = math.randWeight(worldline_gift_base_1, 1) or 0 + + local gift_magnification_10 = (math.randWeight(worldline_gift_magnification_10, 1) or 0) * 10 + local gift_magnification_1 = math.randWeight(worldline_gift_magnification_1, 1) or 0 + + local points = (gift_base_10 + gift_base_1) * (gift_magnification_10 + gift_magnification_1) + worldChangePoints[ItemWorldLine.RouletteCount] = worldChangePoints[ItemWorldLine.RouletteCount] - 1 + worldChangePoints[ItemWorldLine.Points] = worldChangePoints[ItemWorldLine.Points] + points + role:updateProperty({field = "worldChangePoints", value = worldChangePoints}) + + SendPacket(actionCodes.Role_worldLineRoulette, MsgPack.pack(worldChangePoints)) + return true +end + +function _M.worldLineReward(agent, data) + local role = agent.role + local worldLineReward = role:getProperty("worldLineReward") or {} + local worldChangePoints = role:getProperty("worldChangePoints") or {} + local points = worldChangePoints[ItemWorldLine.Points] or 0 + + local reward, change = {} + for key, val in pairs(csvdb["worldline_rewardCsv"]) do + if points >= key and not worldLineReward[key] then + for k, v in pairs(val.award:toNumMap()) do + reward[k] = (reward[k] or 0) + v + end + worldLineReward[key] = 1 + end + end + + role:updateProperty({field = "worldLineReward", value = worldLineReward}) + + if next(reward) then + reward, change = role:award(reward, {log = {desc = "worldLine", int1 = role:getProperty("id")}}) + end + SendPacket(actionCodes.Role_worldLineReward, MsgPack.pack(role:packReward(reward, change))) +end + return _M \ No newline at end of file diff --git a/src/models/Role.lua b/src/models/Role.lua index 65e4fb8..a47884e 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -214,6 +214,9 @@ Role.schema = { heroCnt = {"number", 0}, -- 英雄数量 friendTeam = {"table", {}}, -- 好友切磋队伍信息 {bInfo = {}, team = {}, v = 0} bgId = {"number", 0}, -- 看板娘id + + worldChangePoints = {"table", {}}, -- 世界变动积分 {[1]= 转盘抽取次数, [2]= 获得的积分, [3]=魔导石消耗, [4]= 虹光玉消耗} + worldLineReward = {"table", {}}, -- 世界积分 领取记录 {[id] = 1} } @@ -457,6 +460,8 @@ function Role:data() unlockChap = self:getProperty("unlockChap"), -- 解锁的章节 friendTeam = self:getProperty("friendTeam"), bgId = self:getProperty("bgId"), + worldChangePoints = self:getProperty("worldChangePoints"), + worldLineReward = self:getProperty("worldLineReward"), } end diff --git a/src/models/RoleLog.lua b/src/models/RoleLog.lua index c79320e..9907d9c 100644 --- a/src/models/RoleLog.lua +++ b/src/models/RoleLog.lua @@ -163,6 +163,8 @@ local ItemReason = { CapsuleReward = 1411, --扭蛋机奖励 CapsuleConvert = 1412, --扭蛋机 消耗票 兑换 CapsuleCoinCost = 1413, --抽扭蛋机消耗 + + worldLine = 1500, --世界线积分 } diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index ffb5400..c1f9bfc 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -574,12 +574,14 @@ function RolePlugin.bind(Role) self:notifyUpdateProperty("diamond", self:getAllDiamond()) self:checkTaskEnter("CostDiamond", {count = count}) + self:checkWorldChangePoints({[ItemWorldLine.CostDiamond]=count}) return true end function Role:costJade(param) self:addItem(param) self:checkTaskEnter("CostJade", {count = - param.count}) + self:checkWorldChangePoints({[ItemWorldLine.CostJade]=param.count}) end function Role:increBy(field, val) @@ -3264,6 +3266,23 @@ function RolePlugin.bind(Role) return capsule:getSpecialNotify(roleId) end + + function Role:checkWorldChangePoints(param) + local worldChangePoints = self:getProperty("worldChangePoints") or {} + if param[ItemWorldLine.CostJade] then + worldChangePoints[ItemWorldLine.CostJade] = (worldChangePoints[ItemWorldLine.CostJade] or 0) + param[ItemWorldLine.CostDiamond] + local cost = math.floor(param[ItemWorldLine.CostJade] / globalCsv.worldline_count_currency) + worldChangePoints[ItemWorldLine.CostJade] = worldChangePoints[ItemWorldLine.CostJade] - cost + worldChangePoints[ItemWorldLine.RouletteCount] = worldChangePoints[ItemWorldLine.RouletteCount] + cost + end + + if param[ItemWorldLine.CostDiamond] then + worldChangePoints[ItemWorldLine.CostDiamond] = (worldChangePoints[ItemWorldLine.CostDiamond] or 0) + param[ItemWorldLine.CostDiamond] + local cost = math.floor(param[ItemWorldLine.CostDiamond] / globalCsv.worldline_count_currency) + worldChangePoints[ItemWorldLine.CostDiamond] = worldChangePoints[ItemWorldLine.CostDiamond] - cost + worldChangePoints[ItemWorldLine.Points] = worldChangePoints[ItemWorldLine.Points] + cost + end + end end return RolePlugin \ No newline at end of file -- libgit2 0.21.2