Commit ee999bde1e1fe576ded87a907936ac46513cd4f3

Authored by zhouhaihai
1 parent 056c01a0

零件优化

src/ProtocolCode.lua
... ... @@ -23,6 +23,7 @@ actionCodes = {
23 23 Role_pipelining = 109,
24 24 Role_saleItemRpc = 110,
25 25 Role_openItemRpc = 111,
  26 + Role_loadRunes = 112,
26 27 Role_updateRune = 113,
27 28 Role_storyBookRewardRpc = 114,
28 29 Role_unLockStoryBookRpc = 115,
... ...
src/actions/GmAction.lua
... ... @@ -51,7 +51,7 @@ function _M.get(role, pms)
51 51 if not csvdb["itemCsv"][itemId] then
52 52 return "物品不存在"
53 53 end
54   - local count = tonum(pms.pm2)
  54 + local count = tonum(pms.pm2, 1)
55 55 role:award({[itemId] = count})
56 56 end
57 57 return "成功"
... ...
src/actions/HeroAction.lua
... ... @@ -517,19 +517,17 @@ function _M.referEquipsRpc(agent, data)
517 517 for typ = 1, 4 do -- 4件装备
518 518 if equips[typ] then
519 519 local cur = curEquip:getv(typ, 0)
520   - if equips[typ] == 0 then
521   - if cur ~= 0 then
522   - role:addEquip(typ, cur, 1) -- 脱掉
  520 + if cur ~= equips[typ] then
  521 + if equips[typ] == 0 then
523 522 curEquip = curEquip:delk(typ)
524   - end
525   - else
526   - if cur ~= equips[typ] then
527   - if cur ~= 0 then
528   - role:addEquip(typ, cur, 1) -- 脱掉
529   - end
  523 + else
530 524 role:addEquip(typ, equips[typ], -1) -- 穿上
531 525 curEquip = curEquip:setv(typ, equips[typ])
532 526 end
  527 +
  528 + if cur ~= 0 then
  529 + role:addEquip(typ, cur, 1) -- 脱掉
  530 + end
533 531 end
534 532 end
535 533 end
... ... @@ -549,37 +547,35 @@ function _M.referRunesRpc(agent, data)
549 547 local runes = msg.runes
550 548 if not runes or not next(runes) then return 11 end
551 549  
552   - for typ,uid in pairs(runes) do
553   - local referUid = hero:getProperty("rune"):getv(typ,0)
554   - if uid == 0 then
555   - if referUid == 0 then return 2 end
556   - else
557   - local ownRune = role.runeBag[uid]
558   - if not ownRune then return 3 end
559   - if ownRune:getProperty("refer") ~= 0 then return 4 end
560   -
561   - local runeSet = csvdb["runeCsv"][typ]
562   - if not runeSet then return 5 end
563   - local runeData = runeSet[ownRune:getProperty("id")]
564   - if not runeData then return 6 end
  550 + for typ = 1, 6 do
  551 + if runes[typ] and runes[typ] ~= 0 then
  552 + local ownRune = role.runeBag[runes[typ]]
  553 + if not ownRune then return end
  554 + if ownRune:getProperty("refer") ~= 0 then return end
565 555 end
566 556 end
  557 + local curRune = hero:getProperty("rune")
  558 + for typ = 1, 6 do
  559 + if runes[typ] then
  560 + local cur = curRune:getv(typ, 0)
  561 + if cur ~= runes[typ] then
  562 + if runes[typ] == 0 then
  563 + curRune = curRune:delk(typ)
  564 + else
  565 + local newRune = role.runeBag[runes[typ]]
  566 + newRune:updateProperty({field = "refer",value = hero:getProperty("id")})
  567 + curRune = curRune:delk(typ)
  568 + end
567 569  
568   - for typ,uid in pairs(runes) do
569   - local referUid = hero:getProperty("rune"):getv(typ,0)
570   - if uid == 0 then
571   - local referRune = role.runeBag[referUid]
572   - referRune:updateProperty({field = "refer",value = 0})
573   - else
574   - if referUid ~= 0 then
575   - local referRune = role.runeBag[referUid]
576   - referRune:updateProperty({field = "refer",value = 0})
  570 + if cur ~= 0 then
  571 + local oldR = role.runeBag[cur]
  572 + if oldR then
  573 + oldR:updateProperty({field = "refer",value = 0})
  574 + end
  575 + end
577 576 end
578   - local ownRune = role.runeBag[uid]
579   - ownRune:updateProperty({field = "refer",value = hero:getProperty("id")})
580 577 end
581   - local x = hero:getProperty("rune"):setv(typ,uid)
582   - hero:updateProperty({field = "rune", value = x})
  578 + hero:updateProperty({field = "rune", value = curRune})
583 579 end
584 580 SendPacket(actionCodes.Hero_referRunesRpc, "")
585 581 return true
... ...
src/models/Hero.lua
... ... @@ -25,9 +25,14 @@ end
25 25  
26 26 function Hero:notifyUpdateProperty(field, newValue, oldValue)
27 27 local datas = {
28   - key = field,
29   - newValue = newValue,
30   - oldValue = oldValue,
  28 + id = self:getProperty("id"),
  29 + datas = {
  30 + {
  31 + key = field,
  32 + newValue = newValue,
  33 + oldValue = oldValue,
  34 + }
  35 + }
31 36 }
32 37 self:notifyUpdateProperties(datas)
33 38 end
... ...
src/models/RolePlugin.lua
... ... @@ -460,7 +460,11 @@ function RolePlugin.bind(Role)
460 460 newRune:generateAttrs()
461 461 newRune.owner = self
462 462 self.runeBag[runeUid] = newRune
463   - newRune:notifyUpdateProperties(newRune:data())
  463 + if not params.notNotify then
  464 + local response = {}
  465 + table.insert(response, newRune:data())
  466 + SendPacket(actionCodes.Role_loadRunes, MsgPack.pack(response))
  467 + end
464 468 return 0
465 469 else
466 470 return 1
... ...
src/models/Rune.lua
... ... @@ -14,9 +14,14 @@ end
14 14  
15 15 function Rune:notifyUpdateProperty(field, newValue, oldValue)
16 16 local datas = {
17   - key = field,
18   - newValue = newValue,
19   - oldValue = oldValue,
  17 + uid = self:getProperty("uid"),
  18 + datas = {
  19 + {
  20 + key = field,
  21 + newValue = newValue,
  22 + oldValue = oldValue,
  23 + }
  24 + }
20 25 }
21 26 self:notifyUpdateProperties(datas)
22 27 end
... ... @@ -38,7 +43,10 @@ function Rune:updateProperty(params)
38 43 elseif params.value then
39 44 self:setProperty(params.field, params.value)
40 45 end
41   - self:notifyUpdateProperties(self:data())
  46 + local datas = {}
  47 + table.insert(datas, {key = params.field, newValue = self:getProperty(params.field)})
  48 +
  49 + self:notifyUpdateProperties(datas)
42 50 end
43 51  
44 52 -- types 类型=权重"2=100 3=100 4=100" value最大值=最小值 "50=100 50=100 100=200"
... ...