Commit 659fe2008df897cb084bdaef7217e505e3acbf41
1 parent
d593a874
feat: 天赋点
1. 增加指令228 2. 增加天赋树字段genius 3. 增加检验天赋树的逻辑
Showing
4 changed files
with
86 additions
and
0 deletions
Show diff stats
src/ProtocolCode.lua
| @@ -107,6 +107,7 @@ actionCodes = { | @@ -107,6 +107,7 @@ actionCodes = { | ||
| 107 | Hero_itemComposeRpc = 225, | 107 | Hero_itemComposeRpc = 225, |
| 108 | Hero_setWishPoolRpc = 226, | 108 | Hero_setWishPoolRpc = 226, |
| 109 | Hero_changeSparkRpc = 227, | 109 | Hero_changeSparkRpc = 227, |
| 110 | + Hero_saveGeniusTreeRpc = 228, | ||
| 110 | 111 | ||
| 111 | Hang_startRpc = 251, | 112 | Hang_startRpc = 251, |
| 112 | Hang_checkRpc = 252, | 113 | Hang_checkRpc = 252, |
src/actions/GmAction.lua
| @@ -1011,4 +1011,17 @@ function _M.treasure(role, pms) | @@ -1011,4 +1011,17 @@ function _M.treasure(role, pms) | ||
| 1011 | end | 1011 | end |
| 1012 | end | 1012 | end |
| 1013 | 1013 | ||
| 1014 | +table.insert(helpDes, {"天赋点设置", "savegenius", "heroId", "wakeL", "awake"}) | ||
| 1015 | +function _M.savegenius(role, pms) | ||
| 1016 | + local heroId = pms.pm1 | ||
| 1017 | + local wakeL = pms.pm2 | ||
| 1018 | + local awake = pms.pm3 | ||
| 1019 | + local hero = role.heros[tonumber(heroId)] | ||
| 1020 | + | ||
| 1021 | + if not hero then return "英雄不存在" end | ||
| 1022 | + local genius = hero:saveGeniusTree(wakeL, awake) | ||
| 1023 | + print(genius) | ||
| 1024 | + return "天赋点设置成功" | ||
| 1025 | +end | ||
| 1026 | + | ||
| 1014 | return _M | 1027 | return _M |
| 1015 | \ No newline at end of file | 1028 | \ No newline at end of file |
src/actions/HeroAction.lua
| @@ -1277,4 +1277,25 @@ function _M.changeSparkRpc(agent, data) | @@ -1277,4 +1277,25 @@ function _M.changeSparkRpc(agent, data) | ||
| 1277 | return true | 1277 | return true |
| 1278 | end | 1278 | end |
| 1279 | 1279 | ||
| 1280 | +function _M.saveGeniusTreeRpc(agent, data) | ||
| 1281 | + local role = agent.role | ||
| 1282 | + local msg = MsgPack.unpack(data) | ||
| 1283 | + | ||
| 1284 | + local awake = msg.awake | ||
| 1285 | + local wakeL = msg.wakeL | ||
| 1286 | + local heroId = msg.hero_id | ||
| 1287 | + local hero = role.heros[tonumber(heroId)] | ||
| 1288 | + | ||
| 1289 | + if not hero then print("hero is nil") return 0 end | ||
| 1290 | + local genius = hero:saveGeniusTree(wakeL, awake) | ||
| 1291 | + if #genius == 0 then | ||
| 1292 | + genius = "" | ||
| 1293 | + end | ||
| 1294 | + hero:updateProperty({field="genius", value=genius}) | ||
| 1295 | + print("genius:") | ||
| 1296 | + print(#genius) | ||
| 1297 | + SendPacket(actionCodes.Hero_saveGeniusTreeRpc, MsgPack.pack({genius = genius})) | ||
| 1298 | + return true | ||
| 1299 | +end | ||
| 1300 | + | ||
| 1280 | return _M | 1301 | return _M |
src/models/HeroPlugin.lua
| @@ -384,6 +384,57 @@ function HeroPlugin.bind(Hero) | @@ -384,6 +384,57 @@ function HeroPlugin.bind(Hero) | ||
| 384 | self:mylog({desc = "addFaith", int1 = exp}) | 384 | self:mylog({desc = "addFaith", int1 = exp}) |
| 385 | end | 385 | end |
| 386 | 386 | ||
| 387 | + --检验天赋树是否合理 | ||
| 388 | + function Hero:checkGeniusTree(genius) | ||
| 389 | + local maxWakeL = 0 | ||
| 390 | + local star = self:getProperty("wakeL") | ||
| 391 | + if star < 4 then return maxWakeL end | ||
| 392 | + if #genius == 0 then return maxWakeL end | ||
| 393 | + | ||
| 394 | + local geniusTree = genius:toNumMap() | ||
| 395 | + local tmpgenius = "" | ||
| 396 | + for wakeL, val in pairs(geniusTree) do | ||
| 397 | + print("wakeL:") | ||
| 398 | + print(wakeL) | ||
| 399 | + if wakeL < 4 then return maxWakeL end | ||
| 400 | + if wakeL % 2 == 0 then | ||
| 401 | + if geniusTree[wakeL+1] and geniusTree[wakeL+1] ~= val then | ||
| 402 | + return 0 | ||
| 403 | + end | ||
| 404 | + end | ||
| 405 | + maxWakeL = math.max(maxWakeL, wakeL) | ||
| 406 | + if #tmpgenius == 0 then | ||
| 407 | + tmpgenius = string.format("%s=%s", tostring(wakeL), tostring(val)) | ||
| 408 | + else | ||
| 409 | + tmpgenius = string.format("%s %s=%s", tmpgenius, tostring(wakeL), tostring(val)) | ||
| 410 | + end | ||
| 411 | + end | ||
| 412 | + return tonumber(maxWakeL),tmpgenius | ||
| 413 | + end | ||
| 414 | + | ||
| 415 | + function Hero:saveGeniusTree(wakeL, awake) | ||
| 416 | + local genius = self:getProperty("genius") | ||
| 417 | + local tid = self:getProperty("type") | ||
| 418 | + if not wakeL and not awake then return "" end | ||
| 419 | + | ||
| 420 | + | ||
| 421 | + local heroUnit = csvdb["unitCsv"][tid] | ||
| 422 | + if not heroUnit then return genius end | ||
| 423 | + if not heroUnit.awake_1 or not heroUnit.awake_2 then return genius end | ||
| 424 | + | ||
| 425 | + if #genius == 0 then | ||
| 426 | + genius = string.format("%s=%s", tostring(wakeL), tostring(awake)) | ||
| 427 | + else | ||
| 428 | + genius = string.format("%s %s=%s", genius, tostring(wakeL), tostring(awake)) | ||
| 429 | + end | ||
| 430 | + | ||
| 431 | + local maxWakeL, genius = self:checkGeniusTree(genius) | ||
| 432 | + if maxWakeL ~= wakeL then | ||
| 433 | + genius = self:getProperty("genius") | ||
| 434 | + end | ||
| 435 | + return genius | ||
| 436 | + end | ||
| 437 | + | ||
| 387 | end | 438 | end |
| 388 | 439 | ||
| 389 | 440 |