diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index acf55a2..116721b 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -107,6 +107,7 @@ actionCodes = { Hero_itemComposeRpc = 225, Hero_setWishPoolRpc = 226, Hero_changeSparkRpc = 227, + Hero_saveGeniusTreeRpc = 228, Hang_startRpc = 251, Hang_checkRpc = 252, diff --git a/src/actions/GmAction.lua b/src/actions/GmAction.lua index 9657e7e..25f3a34 100644 --- a/src/actions/GmAction.lua +++ b/src/actions/GmAction.lua @@ -1011,4 +1011,17 @@ function _M.treasure(role, pms) end end +table.insert(helpDes, {"天赋点设置", "savegenius", "heroId", "wakeL", "awake"}) +function _M.savegenius(role, pms) + local heroId = pms.pm1 + local wakeL = pms.pm2 + local awake = pms.pm3 + local hero = role.heros[tonumber(heroId)] + + if not hero then return "英雄不存在" end + local genius = hero:saveGeniusTree(wakeL, awake) + print(genius) + return "天赋点设置成功" +end + return _M \ No newline at end of file diff --git a/src/actions/HeroAction.lua b/src/actions/HeroAction.lua index e2309df..fe93903 100644 --- a/src/actions/HeroAction.lua +++ b/src/actions/HeroAction.lua @@ -1277,4 +1277,25 @@ function _M.changeSparkRpc(agent, data) return true end +function _M.saveGeniusTreeRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + + local awake = msg.awake + local wakeL = msg.wakeL + local heroId = msg.hero_id + local hero = role.heros[tonumber(heroId)] + + if not hero then print("hero is nil") return 0 end + local genius = hero:saveGeniusTree(wakeL, awake) + if #genius == 0 then + genius = "" + end + hero:updateProperty({field="genius", value=genius}) + print("genius:") + print(#genius) + SendPacket(actionCodes.Hero_saveGeniusTreeRpc, MsgPack.pack({genius = genius})) + return true +end + return _M diff --git a/src/models/HeroPlugin.lua b/src/models/HeroPlugin.lua index 6cf369d..2b03deb 100644 --- a/src/models/HeroPlugin.lua +++ b/src/models/HeroPlugin.lua @@ -384,6 +384,57 @@ function HeroPlugin.bind(Hero) self:mylog({desc = "addFaith", int1 = exp}) end + --检验天赋树是否合理 + function Hero:checkGeniusTree(genius) + local maxWakeL = 0 + local star = self:getProperty("wakeL") + if star < 4 then return maxWakeL end + if #genius == 0 then return maxWakeL end + + local geniusTree = genius:toNumMap() + local tmpgenius = "" + for wakeL, val in pairs(geniusTree) do + print("wakeL:") + print(wakeL) + if wakeL < 4 then return maxWakeL end + if wakeL % 2 == 0 then + if geniusTree[wakeL+1] and geniusTree[wakeL+1] ~= val then + return 0 + end + end + maxWakeL = math.max(maxWakeL, wakeL) + if #tmpgenius == 0 then + tmpgenius = string.format("%s=%s", tostring(wakeL), tostring(val)) + else + tmpgenius = string.format("%s %s=%s", tmpgenius, tostring(wakeL), tostring(val)) + end + end + return tonumber(maxWakeL),tmpgenius + end + + function Hero:saveGeniusTree(wakeL, awake) + local genius = self:getProperty("genius") + local tid = self:getProperty("type") + if not wakeL and not awake then return "" end + + + local heroUnit = csvdb["unitCsv"][tid] + if not heroUnit then return genius end + if not heroUnit.awake_1 or not heroUnit.awake_2 then return genius end + + if #genius == 0 then + genius = string.format("%s=%s", tostring(wakeL), tostring(awake)) + else + genius = string.format("%s %s=%s", genius, tostring(wakeL), tostring(awake)) + end + + local maxWakeL, genius = self:checkGeniusTree(genius) + if maxWakeL ~= wakeL then + genius = self:getProperty("genius") + end + return genius + end + end -- libgit2 0.21.2