From ee999bde1e1fe576ded87a907936ac46513cd4f3 Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Mon, 15 Jul 2019 11:50:44 +0800 Subject: [PATCH] 零件优化 --- src/ProtocolCode.lua | 1 + src/actions/GmAction.lua | 2 +- src/actions/HeroAction.lua | 66 +++++++++++++++++++++++++++++++----------------------------------- src/models/Hero.lua | 11 ++++++++--- src/models/RolePlugin.lua | 6 +++++- src/models/Rune.lua | 16 ++++++++++++---- 6 files changed, 58 insertions(+), 44 deletions(-) diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 16d03d8..d31496c 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -23,6 +23,7 @@ actionCodes = { Role_pipelining = 109, Role_saleItemRpc = 110, Role_openItemRpc = 111, + Role_loadRunes = 112, Role_updateRune = 113, Role_storyBookRewardRpc = 114, Role_unLockStoryBookRpc = 115, diff --git a/src/actions/GmAction.lua b/src/actions/GmAction.lua index e4aab3a..d538810 100644 --- a/src/actions/GmAction.lua +++ b/src/actions/GmAction.lua @@ -51,7 +51,7 @@ function _M.get(role, pms) if not csvdb["itemCsv"][itemId] then return "物品不存在" end - local count = tonum(pms.pm2) + local count = tonum(pms.pm2, 1) role:award({[itemId] = count}) end return "成功" diff --git a/src/actions/HeroAction.lua b/src/actions/HeroAction.lua index 071d9f8..744b3b7 100644 --- a/src/actions/HeroAction.lua +++ b/src/actions/HeroAction.lua @@ -517,19 +517,17 @@ function _M.referEquipsRpc(agent, data) for typ = 1, 4 do -- 4件装备 if equips[typ] then local cur = curEquip:getv(typ, 0) - if equips[typ] == 0 then - if cur ~= 0 then - role:addEquip(typ, cur, 1) -- 脱掉 + if cur ~= equips[typ] then + if equips[typ] == 0 then curEquip = curEquip:delk(typ) - end - else - if cur ~= equips[typ] then - if cur ~= 0 then - role:addEquip(typ, cur, 1) -- 脱掉 - end + else role:addEquip(typ, equips[typ], -1) -- 穿上 curEquip = curEquip:setv(typ, equips[typ]) end + + if cur ~= 0 then + role:addEquip(typ, cur, 1) -- 脱掉 + end end end end @@ -549,37 +547,35 @@ function _M.referRunesRpc(agent, data) local runes = msg.runes if not runes or not next(runes) then return 11 end - for typ,uid in pairs(runes) do - local referUid = hero:getProperty("rune"):getv(typ,0) - if uid == 0 then - if referUid == 0 then return 2 end - else - local ownRune = role.runeBag[uid] - if not ownRune then return 3 end - if ownRune:getProperty("refer") ~= 0 then return 4 end - - local runeSet = csvdb["runeCsv"][typ] - if not runeSet then return 5 end - local runeData = runeSet[ownRune:getProperty("id")] - if not runeData then return 6 end + for typ = 1, 6 do + if runes[typ] and runes[typ] ~= 0 then + local ownRune = role.runeBag[runes[typ]] + if not ownRune then return end + if ownRune:getProperty("refer") ~= 0 then return end end end + local curRune = hero:getProperty("rune") + for typ = 1, 6 do + if runes[typ] then + local cur = curRune:getv(typ, 0) + if cur ~= runes[typ] then + if runes[typ] == 0 then + curRune = curRune:delk(typ) + else + local newRune = role.runeBag[runes[typ]] + newRune:updateProperty({field = "refer",value = hero:getProperty("id")}) + curRune = curRune:delk(typ) + end - for typ,uid in pairs(runes) do - local referUid = hero:getProperty("rune"):getv(typ,0) - if uid == 0 then - local referRune = role.runeBag[referUid] - referRune:updateProperty({field = "refer",value = 0}) - else - if referUid ~= 0 then - local referRune = role.runeBag[referUid] - referRune:updateProperty({field = "refer",value = 0}) + if cur ~= 0 then + local oldR = role.runeBag[cur] + if oldR then + oldR:updateProperty({field = "refer",value = 0}) + end + end end - local ownRune = role.runeBag[uid] - ownRune:updateProperty({field = "refer",value = hero:getProperty("id")}) end - local x = hero:getProperty("rune"):setv(typ,uid) - hero:updateProperty({field = "rune", value = x}) + hero:updateProperty({field = "rune", value = curRune}) end SendPacket(actionCodes.Hero_referRunesRpc, "") return true diff --git a/src/models/Hero.lua b/src/models/Hero.lua index 62dca07..06d1b5e 100644 --- a/src/models/Hero.lua +++ b/src/models/Hero.lua @@ -25,9 +25,14 @@ end function Hero:notifyUpdateProperty(field, newValue, oldValue) local datas = { - key = field, - newValue = newValue, - oldValue = oldValue, + id = self:getProperty("id"), + datas = { + { + key = field, + newValue = newValue, + oldValue = oldValue, + } + } } self:notifyUpdateProperties(datas) end diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index bb8a445..32710eb 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -460,7 +460,11 @@ function RolePlugin.bind(Role) newRune:generateAttrs() newRune.owner = self self.runeBag[runeUid] = newRune - newRune:notifyUpdateProperties(newRune:data()) + if not params.notNotify then + local response = {} + table.insert(response, newRune:data()) + SendPacket(actionCodes.Role_loadRunes, MsgPack.pack(response)) + end return 0 else return 1 diff --git a/src/models/Rune.lua b/src/models/Rune.lua index a3b601a..070b40f 100644 --- a/src/models/Rune.lua +++ b/src/models/Rune.lua @@ -14,9 +14,14 @@ end function Rune:notifyUpdateProperty(field, newValue, oldValue) local datas = { - key = field, - newValue = newValue, - oldValue = oldValue, + uid = self:getProperty("uid"), + datas = { + { + key = field, + newValue = newValue, + oldValue = oldValue, + } + } } self:notifyUpdateProperties(datas) end @@ -38,7 +43,10 @@ function Rune:updateProperty(params) elseif params.value then self:setProperty(params.field, params.value) end - self:notifyUpdateProperties(self:data()) + local datas = {} + table.insert(datas, {key = params.field, newValue = self:getProperty(params.field)}) + + self:notifyUpdateProperties(datas) end -- types 类型=权重"2=100 3=100 4=100" value最大值=最小值 "50=100 50=100 100=200" -- libgit2 0.21.2