From 997cbdfee6f92cf622da64317f44fff16863d2e5 Mon Sep 17 00:00:00 2001 From: zhouahaihai Date: Thu, 29 Nov 2018 17:37:57 +0800 Subject: [PATCH] 技能养成 --- src/GlobalVar.lua | 8 ++++++++ src/ProtocolCode.lua | 3 +++ src/actions/HeroAction.lua | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/models/Hero.lua | 2 +- src/models/HeroPlugin.lua | 13 ++++++++++++- 5 files changed, 105 insertions(+), 4 deletions(-) diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index 1e8df82..d8e2f56 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -46,4 +46,12 @@ ItemType = { -- 物品起始id ItemStartId = { Hero = 1000, -- 英雄 +} +--常用的物品id的枚举 +ItemId = { + Gold = 1, -- 金币 + Exp = 2, -- 经验 + Diamond = 3, -- 钻石 + BreakCost = 4, -- 突破材料 + HeroFC = {700, 701, 702, 703}, -- 通用角色碎片 } \ No newline at end of file diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 1aa79a8..d37af8a 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -24,6 +24,9 @@ actionCodes = { Hero_updateProperty = 202, Hero_levelUpRpc = 203, Hero_breakRpc = 204, + Hero_wakeRpc = 205, + Hero_skillUpRpc = 206, + Hero_talentRpc = 207, } rpcResponseBegin = 10000 diff --git a/src/actions/HeroAction.lua b/src/actions/HeroAction.lua index 5eee896..23389ba 100644 --- a/src/actions/HeroAction.lua +++ b/src/actions/HeroAction.lua @@ -22,7 +22,7 @@ function _M.levelUpRpc( agent, data ) if hero:getProperty("level") >= hero:getMaxLevel() then return end local curData = csvdb["unit_expCsv"][hero:getProperty("level")] - local cost = {[2] = curData.exp, [1] = curData.gold} + local cost = {[ItemId.Exp] = curData.exp, [ItemId.Gold] = curData.gold} if not role:checkItemEnough(cost) then return end role:costItems(cost, {}) hero:updateProperty({field = "level", delta = 1}) @@ -40,7 +40,7 @@ function _M.breakRpc( agent, data ) if hero:getProperty("level") < hero:getMaxLevel() then return end if hero:getProperty("breakL") >= #csvdb["unit_breakCsv"] then return end local curData = csvdb["unit_breakCsv"][hero:getProperty("breakL")] - local cost = {[3] = curData.cost, [1] = curData.gold} + local cost = {[ItemId.BreakCost] = curData.cost, [ItemId.Gold] = curData.gold} if not role:checkItemEnough(cost) then return end role:costItems(cost, {}) hero:updateProperty({field = "breakL", delta = 1}) @@ -49,4 +49,83 @@ function _M.breakRpc( agent, data ) return true end +function _M.wakeRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local hero = role.heros[msg.id] + if not hero then return end + if hero:getProperty("wakeL") >= #csvdb["unit_wakeCsv"] then return end + local cost = {[hero:getProperty("type")] = csvdb["unit_wakeCsv"][hero:getProperty("wakeL")].cost} + local isEnough, less = role:checkItemEnough(cost) + if not isEnough then + cost[ItemId.HeroFC[csvdb["unitCsv"][hero:getProperty("type")].rare]] = less[hero:getProperty("type")] + if not role:checkItemEnough(cost) then return end + end + role:costItems(cost, {}) + hero:updateProperty({field = "wakeL", delta = 1}) + + SendPacket(actionCodes.Hero_wakeRpc, '') + return true +end + +function _M.skillUpRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local index = msg.skillIdx -- 第几个技能 -- 1 2 3 + local hero = role.heros[msg.id] + if not hero then return end + local curLevel = hero:getSkillLevel(index) + if hero:getLSPoint() < 0 or curLevel >= #hero:getSkillData(index) then return end + hero:updateProperty({field = "skillL", value = hero:getProperty("skillL"):setv(index, curLevel + 1)}) + + SendPacket(actionCodes.Hero_skillUpRpc, '') + return true +end + +function _M.talentRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local hero = role.heros[msg.id] + if not hero then return end + + local index = msg.index -- 第几个天赋 + local need = {[1] = 1, [2] = 1, [3] = 1, [4] = 1} + if not need[index] then return end + + local talent = hero:getProperty("talent") + local curStage = talent:getv(0, 1) + if curStage > csvdb["unit_breakCsv"][hero:getProperty("breakL")].talent then return end + + local curData = csvdb["unit_talentCsv"][curStage] + if not curData then return end + + local level = talent:getv(index, 0) + if level >= #curData then return end + + local talentData = curData[level] + if not talentData then return end + local cost = talentData.cost:toNumMap() + if not role:checkItemEnough(cost) then return end + role:costItems(cost, {}) + talent = talent:incrv(index, 1) + + --是否进阶 + local max = true + for i = 1, 4 do + if talent:getv(i, 0) < #curData then + max = false + break + end + end + if max then + talent = talent:incrv(0, 1) + for i = 1, 4 do + talent = talent:setv(i, 0) + end + end + hero:updateProperty({field = "talent", value = talent}) + SendPacket(actionCodes.Hero_talentRpc, '') + return true +end + return _M \ No newline at end of file diff --git a/src/models/Hero.lua b/src/models/Hero.lua index 8f07018..08216f8 100644 --- a/src/models/Hero.lua +++ b/src/models/Hero.lua @@ -10,7 +10,7 @@ Hero.schema = { level = {"number", 1}, -- 等级 breakL = {"number", 0}, -- 突破等级 wakeL = {"number", 0}, -- 觉醒等级 - skillL = {"string", ""}, -- 技能等级 1=0 2=0 3=0 + skillL = {"string", ""}, -- 技能等级 1=1 2=1 3=1 talent = {"string", ""}, -- 0=阶段 1=1 2=1 3=1 4=1 四个天赋当前阶段的等级 阶段默认为1 等级默认为0 battleV = {"number", 0}, -- 保存战斗力 diff --git a/src/models/HeroPlugin.lua b/src/models/HeroPlugin.lua index 00ff0b0..a65b724 100644 --- a/src/models/HeroPlugin.lua +++ b/src/models/HeroPlugin.lua @@ -20,7 +20,7 @@ function HeroPlugin.bind(Hero) function Hero:getLSPoint() local point = self:getSPoint() for skill, level in pairs(self:getProperty("skillL"):toNumMap()) do - point = point - level + point = point - (level - 1) end return point end @@ -94,6 +94,17 @@ function HeroPlugin.bind(Hero) return battleValue end + function Hero:getSkillLevel(idx) + return self:getProperty("skillL"):getv(idx, 1) + end + + function Hero:getSkillData(idx) + if idx == 1 then + return csvdb["skill_blockCsv"][csvdb["unitCsv"][self:getProperty("type")].block] + end + return {} +end + end -- libgit2 0.21.2