Commit 997cbdfee6f92cf622da64317f44fff16863d2e5
1 parent
8c74292c
技能养成
Showing
5 changed files
with
105 additions
and
4 deletions
Show diff stats
src/GlobalVar.lua
@@ -46,4 +46,12 @@ ItemType = { | @@ -46,4 +46,12 @@ ItemType = { | ||
46 | -- 物品起始id | 46 | -- 物品起始id |
47 | ItemStartId = { | 47 | ItemStartId = { |
48 | Hero = 1000, -- 英雄 | 48 | Hero = 1000, -- 英雄 |
49 | +} | ||
50 | +--常用的物品id的枚举 | ||
51 | +ItemId = { | ||
52 | + Gold = 1, -- 金币 | ||
53 | + Exp = 2, -- 经验 | ||
54 | + Diamond = 3, -- 钻石 | ||
55 | + BreakCost = 4, -- 突破材料 | ||
56 | + HeroFC = {700, 701, 702, 703}, -- 通用角色碎片 | ||
49 | } | 57 | } |
50 | \ No newline at end of file | 58 | \ No newline at end of file |
src/ProtocolCode.lua
@@ -24,6 +24,9 @@ actionCodes = { | @@ -24,6 +24,9 @@ actionCodes = { | ||
24 | Hero_updateProperty = 202, | 24 | Hero_updateProperty = 202, |
25 | Hero_levelUpRpc = 203, | 25 | Hero_levelUpRpc = 203, |
26 | Hero_breakRpc = 204, | 26 | Hero_breakRpc = 204, |
27 | + Hero_wakeRpc = 205, | ||
28 | + Hero_skillUpRpc = 206, | ||
29 | + Hero_talentRpc = 207, | ||
27 | } | 30 | } |
28 | 31 | ||
29 | rpcResponseBegin = 10000 | 32 | rpcResponseBegin = 10000 |
src/actions/HeroAction.lua
@@ -22,7 +22,7 @@ function _M.levelUpRpc( agent, data ) | @@ -22,7 +22,7 @@ function _M.levelUpRpc( agent, data ) | ||
22 | 22 | ||
23 | if hero:getProperty("level") >= hero:getMaxLevel() then return end | 23 | if hero:getProperty("level") >= hero:getMaxLevel() then return end |
24 | local curData = csvdb["unit_expCsv"][hero:getProperty("level")] | 24 | local curData = csvdb["unit_expCsv"][hero:getProperty("level")] |
25 | - local cost = {[2] = curData.exp, [1] = curData.gold} | 25 | + local cost = {[ItemId.Exp] = curData.exp, [ItemId.Gold] = curData.gold} |
26 | if not role:checkItemEnough(cost) then return end | 26 | if not role:checkItemEnough(cost) then return end |
27 | role:costItems(cost, {}) | 27 | role:costItems(cost, {}) |
28 | hero:updateProperty({field = "level", delta = 1}) | 28 | hero:updateProperty({field = "level", delta = 1}) |
@@ -40,7 +40,7 @@ function _M.breakRpc( agent, data ) | @@ -40,7 +40,7 @@ function _M.breakRpc( agent, data ) | ||
40 | if hero:getProperty("level") < hero:getMaxLevel() then return end | 40 | if hero:getProperty("level") < hero:getMaxLevel() then return end |
41 | if hero:getProperty("breakL") >= #csvdb["unit_breakCsv"] then return end | 41 | if hero:getProperty("breakL") >= #csvdb["unit_breakCsv"] then return end |
42 | local curData = csvdb["unit_breakCsv"][hero:getProperty("breakL")] | 42 | local curData = csvdb["unit_breakCsv"][hero:getProperty("breakL")] |
43 | - local cost = {[3] = curData.cost, [1] = curData.gold} | 43 | + local cost = {[ItemId.BreakCost] = curData.cost, [ItemId.Gold] = curData.gold} |
44 | if not role:checkItemEnough(cost) then return end | 44 | if not role:checkItemEnough(cost) then return end |
45 | role:costItems(cost, {}) | 45 | role:costItems(cost, {}) |
46 | hero:updateProperty({field = "breakL", delta = 1}) | 46 | hero:updateProperty({field = "breakL", delta = 1}) |
@@ -49,4 +49,83 @@ function _M.breakRpc( agent, data ) | @@ -49,4 +49,83 @@ function _M.breakRpc( agent, data ) | ||
49 | return true | 49 | return true |
50 | end | 50 | end |
51 | 51 | ||
52 | +function _M.wakeRpc(agent, data) | ||
53 | + local role = agent.role | ||
54 | + local msg = MsgPack.unpack(data) | ||
55 | + local hero = role.heros[msg.id] | ||
56 | + if not hero then return end | ||
57 | + if hero:getProperty("wakeL") >= #csvdb["unit_wakeCsv"] then return end | ||
58 | + local cost = {[hero:getProperty("type")] = csvdb["unit_wakeCsv"][hero:getProperty("wakeL")].cost} | ||
59 | + local isEnough, less = role:checkItemEnough(cost) | ||
60 | + if not isEnough then | ||
61 | + cost[ItemId.HeroFC[csvdb["unitCsv"][hero:getProperty("type")].rare]] = less[hero:getProperty("type")] | ||
62 | + if not role:checkItemEnough(cost) then return end | ||
63 | + end | ||
64 | + role:costItems(cost, {}) | ||
65 | + hero:updateProperty({field = "wakeL", delta = 1}) | ||
66 | + | ||
67 | + SendPacket(actionCodes.Hero_wakeRpc, '') | ||
68 | + return true | ||
69 | +end | ||
70 | + | ||
71 | +function _M.skillUpRpc(agent, data) | ||
72 | + local role = agent.role | ||
73 | + local msg = MsgPack.unpack(data) | ||
74 | + local index = msg.skillIdx -- 第几个技能 -- 1 2 3 | ||
75 | + local hero = role.heros[msg.id] | ||
76 | + if not hero then return end | ||
77 | + local curLevel = hero:getSkillLevel(index) | ||
78 | + if hero:getLSPoint() < 0 or curLevel >= #hero:getSkillData(index) then return end | ||
79 | + hero:updateProperty({field = "skillL", value = hero:getProperty("skillL"):setv(index, curLevel + 1)}) | ||
80 | + | ||
81 | + SendPacket(actionCodes.Hero_skillUpRpc, '') | ||
82 | + return true | ||
83 | +end | ||
84 | + | ||
85 | +function _M.talentRpc(agent, data) | ||
86 | + local role = agent.role | ||
87 | + local msg = MsgPack.unpack(data) | ||
88 | + local hero = role.heros[msg.id] | ||
89 | + if not hero then return end | ||
90 | + | ||
91 | + local index = msg.index -- 第几个天赋 | ||
92 | + local need = {[1] = 1, [2] = 1, [3] = 1, [4] = 1} | ||
93 | + if not need[index] then return end | ||
94 | + | ||
95 | + local talent = hero:getProperty("talent") | ||
96 | + local curStage = talent:getv(0, 1) | ||
97 | + if curStage > csvdb["unit_breakCsv"][hero:getProperty("breakL")].talent then return end | ||
98 | + | ||
99 | + local curData = csvdb["unit_talentCsv"][curStage] | ||
100 | + if not curData then return end | ||
101 | + | ||
102 | + local level = talent:getv(index, 0) | ||
103 | + if level >= #curData then return end | ||
104 | + | ||
105 | + local talentData = curData[level] | ||
106 | + if not talentData then return end | ||
107 | + local cost = talentData.cost:toNumMap() | ||
108 | + if not role:checkItemEnough(cost) then return end | ||
109 | + role:costItems(cost, {}) | ||
110 | + talent = talent:incrv(index, 1) | ||
111 | + | ||
112 | + --是否进阶 | ||
113 | + local max = true | ||
114 | + for i = 1, 4 do | ||
115 | + if talent:getv(i, 0) < #curData then | ||
116 | + max = false | ||
117 | + break | ||
118 | + end | ||
119 | + end | ||
120 | + if max then | ||
121 | + talent = talent:incrv(0, 1) | ||
122 | + for i = 1, 4 do | ||
123 | + talent = talent:setv(i, 0) | ||
124 | + end | ||
125 | + end | ||
126 | + hero:updateProperty({field = "talent", value = talent}) | ||
127 | + SendPacket(actionCodes.Hero_talentRpc, '') | ||
128 | + return true | ||
129 | +end | ||
130 | + | ||
52 | return _M | 131 | return _M |
53 | \ No newline at end of file | 132 | \ No newline at end of file |
src/models/Hero.lua
@@ -10,7 +10,7 @@ Hero.schema = { | @@ -10,7 +10,7 @@ Hero.schema = { | ||
10 | level = {"number", 1}, -- 等级 | 10 | level = {"number", 1}, -- 等级 |
11 | breakL = {"number", 0}, -- 突破等级 | 11 | breakL = {"number", 0}, -- 突破等级 |
12 | wakeL = {"number", 0}, -- 觉醒等级 | 12 | wakeL = {"number", 0}, -- 觉醒等级 |
13 | - skillL = {"string", ""}, -- 技能等级 1=0 2=0 3=0 | 13 | + skillL = {"string", ""}, -- 技能等级 1=1 2=1 3=1 |
14 | talent = {"string", ""}, -- 0=阶段 1=1 2=1 3=1 4=1 四个天赋当前阶段的等级 阶段默认为1 等级默认为0 | 14 | talent = {"string", ""}, -- 0=阶段 1=1 2=1 3=1 4=1 四个天赋当前阶段的等级 阶段默认为1 等级默认为0 |
15 | battleV = {"number", 0}, -- 保存战斗力 | 15 | battleV = {"number", 0}, -- 保存战斗力 |
16 | 16 |
src/models/HeroPlugin.lua
@@ -20,7 +20,7 @@ function HeroPlugin.bind(Hero) | @@ -20,7 +20,7 @@ function HeroPlugin.bind(Hero) | ||
20 | function Hero:getLSPoint() | 20 | function Hero:getLSPoint() |
21 | local point = self:getSPoint() | 21 | local point = self:getSPoint() |
22 | for skill, level in pairs(self:getProperty("skillL"):toNumMap()) do | 22 | for skill, level in pairs(self:getProperty("skillL"):toNumMap()) do |
23 | - point = point - level | 23 | + point = point - (level - 1) |
24 | end | 24 | end |
25 | return point | 25 | return point |
26 | end | 26 | end |
@@ -94,6 +94,17 @@ function HeroPlugin.bind(Hero) | @@ -94,6 +94,17 @@ function HeroPlugin.bind(Hero) | ||
94 | return battleValue | 94 | return battleValue |
95 | end | 95 | end |
96 | 96 | ||
97 | + function Hero:getSkillLevel(idx) | ||
98 | + return self:getProperty("skillL"):getv(idx, 1) | ||
99 | + end | ||
100 | + | ||
101 | + function Hero:getSkillData(idx) | ||
102 | + if idx == 1 then | ||
103 | + return csvdb["skill_blockCsv"][csvdb["unitCsv"][self:getProperty("type")].block] | ||
104 | + end | ||
105 | + return {} | ||
106 | +end | ||
107 | + | ||
97 | end | 108 | end |
98 | 109 | ||
99 | 110 |