Commit 0f2a905ec58bf43fdd9ee9beafa0da10cc17472e

Authored by suhongyang
2 parents 42f2d1d3 75d16594

Merge branch 'master' of 120.26.43.151:wasteland/server

.luacheckrc
1 1 std = "max"
2 2 globals = {
  3 + "R_RUNEIDS",
  4 + "R_EQUIP_ROOT",
  5 + "R_EQUIP",
  6 + "R_RUNE",
3 7 "DinerTask",
4 8 "SendPipelining",
5 9 "AdvEventType",
... ...
src/ProtocolCode.lua
... ... @@ -23,6 +23,8 @@ actionCodes = {
23 23 Role_pipelining = 109,
24 24 Role_saleItemRpc = 110,
25 25 Role_openItemRpc = 111,
  26 + Role_updateEquip = 112,
  27 + Role_updateRune = 113,
26 28  
27 29 Adv_startAdvRpc = 151,
28 30 Adv_roleFormatRpc = 152,
... ... @@ -48,6 +50,8 @@ actionCodes = {
48 50 Hero_loveTaskRpc = 213,
49 51 Hero_changeSkinRpc = 214,
50 52 Hero_createHeroRpc = 215,
  53 + Hero_referEquipsRpc = 216,
  54 + Hero_referRunesRpc = 217,
51 55  
52 56 Hang_startRpc = 251,
53 57 Hang_checkRpc = 252,
... ... @@ -74,6 +78,7 @@ actionCodes = {
74 78  
75 79 Car_makePotionRpc = 400,
76 80 Car_equipUpRpc = 401,
  81 + Car_runeUpRpc = 402,
77 82 }
78 83  
79 84 rpcResponseBegin = 10000
... ...
src/RedisKeys.lua
... ... @@ -4,6 +4,10 @@ R_HEROS = "role:%d:heroIds"
4 4 R_HERO = "hero:%d:%d"
5 5 R_DAILY = "role:%d:daily"
6 6 R_DINER = "role:%d:diner" -- 餐厅
  7 +R_EQUIP_ROOT = "role:%d:equip*" -- 装备根目录
  8 +R_EQUIP = "role:%d:equip:%d:%d" -- 装备type:level
  9 +R_RUNEIDS = "role:%d:runeIds" -- 玩家拥有符文自增id
  10 +R_RUNE = "role:%d:rune:%d" -- 符文详细信息
7 11  
8 12 -- -- role
9 13 -- R_FARM_KEY = "role:%d:farm"
... ...
src/actions/CarAction.lua
... ... @@ -64,8 +64,14 @@ function _M.equipUpRpc( agent, data )
64 64 local nextEquip = dataSet[nextLv]
65 65 if not nextEquip then return 23 end
66 66  
67   - local own = role:getItemCount(id)
68   - if own < count then
  67 + local ownSet = role.equipBag[typ]
  68 + if not ownSet then return 31 end
  69 + local ownData = ownSet[lv]
  70 + if not ownData then return 32 end
  71 +
  72 + local own = role:getEquipCount(typ,lv)
  73 + local costCount = equipData.merge*count
  74 + if own < costCount then
69 75 return 3
70 76 end
71 77  
... ... @@ -77,15 +83,41 @@ function _M.equipUpRpc( agent, data )
77 83 return 4
78 84 end
79 85  
80   - local merge = {[id]=equipData.merge*count}
81   - if not role:checkItemEnough(merge) then
82   - return 5
  86 + role:costItems(cost)
  87 + role:addEquip({type=typ,level=lv,count=-costCount})
  88 + role:addEquip({type=typ,level=nextLv,count=count})
  89 + SendPacket(actionCodes.Car_equipUpRpc, '')
  90 + return true
  91 +end
  92 +
  93 +function _M.runeUpRpc( agent, data )
  94 + local role = agent.role
  95 + local msg = MsgPack.unpack(data)
  96 + local uid = msg.uid
  97 + local ownRune = role.runeBag[uid]
  98 + if not ownRune then return 1 end
  99 + if ownRune:getProperty("refer") ~= 0 then return 2 end
  100 +
  101 + local typ = ownRune:getProperty("type")
  102 + local id = ownRune:getProperty("id")
  103 + local level = ownRune:getProperty("level")
  104 +
  105 + local runeSet = csvdb["runeCsv"][typ]
  106 + if not runeSet then return 4 end
  107 + local runeData = runeSet[id]
  108 + if not runeData then return 5 end
  109 +
  110 + local maxLv = #csvdb["rune_buildCsv"]
  111 + if level >= maxLv then return 6 end
  112 + local lvData = csvdb["rune_buildCsv"][level+1]
  113 + local cost = lvData.cost:toNumMap()
  114 + if not role:checkItemEnough(cost) then
  115 + return 7
83 116 end
84 117  
85 118 role:costItems(cost)
86   - role:costItems(merge)
87   - role:addItem({itemId = nextEquip.id,count = count})
88   - SendPacket(actionCodes.Car_equipUpRpc, '')
  119 + ownRune:updateProperty({field = "level",value = level+1})
  120 + SendPacket(actionCodes.Car_runeUpRpc, '')
89 121 return true
90 122 end
91 123  
... ...
src/actions/GmAction.lua
... ... @@ -22,13 +22,36 @@ function _M.hero(role, pms)
22 22 return "成功"
23 23 end
24 24  
  25 +function _M.equip(role, pms)
  26 + local typ = tonum(pms.pm1)
  27 + local level = tonum(pms.pm2)
  28 + local count = tonum(pms.pm3)
  29 + role:addEquip({type = typ,level = level,count = count})
  30 + return "成功"
  31 +end
  32 +
  33 +function _M.rune(role, pms)
  34 + local typ = tonum(pms.pm1)
  35 + local id = tonum(pms.pm2)
  36 + local result = role:addRune({type = typ,id = id})
  37 + return result
  38 +end
  39 +
25 40 function _M.get(role, pms)
26   - local itemId = tonum(pms.pm1)
27   - if not csvdb["itemCsv"][itemId] then
28   - return "物品不存在"
  41 + if pms.pm1 == "ALL" then
  42 + for id,data in pairs(csvdb["itemCsv"]) do
  43 + if data.type ~= 4 and data.type ~= 5 then
  44 + role:award({[id] = 10})
  45 + end
  46 + end
  47 + else
  48 + local itemId = tonum(pms.pm1)
  49 + if not csvdb["itemCsv"][itemId] then
  50 + return "物品不存在"
  51 + end
  52 + local count = tonum(pms.pm2)
  53 + role:award({[itemId] = count})
29 54 end
30   - local count = tonum(pms.pm2)
31   - role:award({[itemId] = count})
32 55 return "成功"
33 56 end
34 57  
... ...
src/actions/HeroAction.lua
... ... @@ -483,4 +483,88 @@ function _M.createHeroRpc(agent, data)
483 483 return true
484 484 end
485 485  
  486 +-- typ 位置,level等级对应唯一装备,level为0时为移除,不为0时无则装备,有则替换
  487 +function _M.referEquipsRpc(agent, data)
  488 + local role = agent.role
  489 + local msg = MsgPack.unpack(data)
  490 + local hero = role.heros[msg.id]
  491 + if not hero then return 10 end
  492 + local equips = msg.equips
  493 + if not equips or not next(equips) then return 11 end
  494 +
  495 + for typ,level in pairs(equips) do
  496 + local ownLv = hero:getProperty("equip"):getv(typ,0)
  497 + if level == 0 then
  498 + if ownLv == 0 then return 2 end
  499 + else
  500 + if role:getEquipCount(typ,level) < 1 then return 3 end
  501 + local equipSet = csvdb["equipCsv"][typ]
  502 + if not equipSet then return 4 end
  503 + local equipData = equipSet[level]
  504 + if not equipData then return 5 end
  505 + end
  506 + end
  507 +
  508 + for typ,level in pairs(equips) do
  509 + local ownLv = hero:getProperty("equip"):getv(typ,0)
  510 + if level == 0 then
  511 + role:addEquip({type=typ,level=ownLv,count=1,isRefer=true})
  512 + else
  513 + role:addEquip({type=typ,level=level,count=-1,isRefer=true})
  514 + if ownLv > 0 then
  515 + role:addEquip({type=typ,level=ownLv,count=1,isRefer=true})
  516 + end
  517 + end
  518 + local x = hero:getProperty("equip"):setv(typ, level)
  519 + hero:updateProperty({field = "equip", value = x})
  520 + end
  521 + SendPacket(actionCodes.Hero_referEquipsRpc, "")
  522 + return true
  523 +end
  524 +
  525 +-- typ 位置,uid对应唯一符文,uid为0时为移除,不为0时无则装备,有则替换
  526 +function _M.referRunesRpc(agent, data)
  527 + local role = agent.role
  528 + local msg = MsgPack.unpack(data)
  529 + local hero = role.heros[msg.id]
  530 + if not hero then return 10 end
  531 + local runes = msg.runes
  532 + if not runes or not next(runes) then return 11 end
  533 +
  534 + for typ,uid in pairs(runes) do
  535 + local referUid = hero:getProperty("rune"):getv(typ,0)
  536 + if uid == 0 then
  537 + if referUid == 0 then return 2 end
  538 + else
  539 + local ownRune = role.runeBag[uid]
  540 + if not ownRune then return 3 end
  541 + if ownRune:getProperty("refer") ~= 0 then return 4 end
  542 +
  543 + local runeSet = csvdb["runeCsv"][typ]
  544 + if not runeSet then return 5 end
  545 + local runeData = runeSet[ownRune:getProperty("id")]
  546 + if not runeData then return 6 end
  547 + end
  548 + end
  549 +
  550 + for typ,uid in pairs(runes) do
  551 + local referUid = hero:getProperty("rune"):getv(typ,0)
  552 + if uid == 0 then
  553 + local referRune = role.runeBag[referUid]
  554 + referRune:updateProperty({field = "refer",value = 0})
  555 + else
  556 + if referUid ~= 0 then
  557 + local referRune = role.runeBag[referUid]
  558 + referRune:updateProperty({field = "refer",value = 0})
  559 + end
  560 + local ownRune = role.runeBag[uid]
  561 + ownRune:updateProperty({field = "refer",value = hero:getProperty("id")})
  562 + end
  563 + local x = hero:getProperty("rune"):setv(typ,uid)
  564 + hero:updateProperty({field = "rune", value = x})
  565 + end
  566 + SendPacket(actionCodes.Hero_referRunesRpc, "")
  567 + return true
  568 +end
  569 +
486 570 return _M
487 571 \ No newline at end of file
... ...
src/actions/RoleAction.lua
... ... @@ -97,7 +97,7 @@ function _M.loginRpc( agent, data )
97 97 else
98 98 role:reloadWhenLogin()
99 99 end
100   -
  100 +
101 101 if not msg.isGMlogin then
102 102 local banTime = role:getProperty("banTime")
103 103 if banTime > now then
... ... @@ -120,7 +120,7 @@ function _M.loginRpc( agent, data )
120 120 -- 跨天登陆事件
121 121 role:onCrossDay(now)
122 122 role:setProperty("ltime", now)
123   -
  123 +
124 124  
125 125 for _, name in ipairs({"dailyData", "dinerData"}) do
126 126 response[name] = role[name]:data()
... ... @@ -149,10 +149,25 @@ function _M.loginRpc( agent, data )
149 149 end
150 150 end
151 151  
152   - response.wave = 1 + heroWave
  152 + response.wave = 3 + heroWave
153 153  
154 154 SendPacket(actionCodes.Role_loginRpc, MsgPack.pack(response))
155 155  
  156 + local equipResp = {equipBag = {}}
  157 + for typ,set in pairs(role.equipBag) do
  158 + for level,equip in pairs(set) do
  159 + if not equipResp.equipBag[typ] then equipResp.equipBag[typ] = {} end
  160 + equipResp.equipBag[typ][level] = equip:data()
  161 + end
  162 + end
  163 + SendPacket(actionCodes.Role_loginRpc, MsgPack.pack(equipResp))
  164 +
  165 + local runeResp = {runeBag = {}}
  166 + for _,rune in pairs(role.runeBag) do
  167 + runeResp.runeBag[rune:getProperty("uid")]=rune:data()
  168 + end
  169 + SendPacket(actionCodes.Role_loginRpc, MsgPack.pack(runeResp))
  170 +
156 171 local heroIndex = 1
157 172 for index = 2, 1 + heroWave do
158 173 local heroResponse = {heros = {}}
... ... @@ -177,7 +192,7 @@ function _M.loginRpc( agent, data )
177 192 gate_serv = agent.gate_serv,
178 193 })
179 194 agent.role = role
180   -
  195 +
181 196 start_agent_timer()
182 197 -- 注册全服广播
183 198 local channel = math.randomInt(1, 1)
... ... @@ -293,7 +308,7 @@ function _M.openItemRpc(agent, data)
293 308 end
294 309 role:costItems({[itemId] = count})
295 310 reward = role:award(reward)
296   -
  311 +
297 312 SendPacket(actionCodes.Role_openItemRpc, MsgPack.pack({reward = reward}))
298 313 return true
299 314 end
... ...
1   -Subproject commit c4ec029a5f26392cf6c1471d1db1b58e0bdb5802
  1 +Subproject commit ea8da0fb177c4166bcb7350d8c1932d2b91b8dad
... ...
src/models/Equip.lua 0 → 100644
... ... @@ -0,0 +1,52 @@
  1 +local Equip = class("Equip", require("shared.ModelBase"))
  2 +
  3 +Equip.schema = {
  4 + type = {"number"}, -- 类型
  5 + level = {"number"}, -- 等级
  6 + count = {"number", 0}, -- 数量
  7 + refer = {"number", 0}, -- 已装备英雄数
  8 +}
  9 +
  10 +function Equip:ctor( properties )
  11 + Equip.super.ctor(self, properties)
  12 +end
  13 +
  14 +function Equip:notifyUpdateProperty(field, newValue, oldValue)
  15 + local datas = {
  16 + key = field,
  17 + newValue = newValue,
  18 + oldValue = oldValue,
  19 + }
  20 + self:notifyUpdateProperties(datas)
  21 +end
  22 +
  23 +function Equip:notifyUpdateProperties(params)
  24 + local updateData = {
  25 + type = self:getProperty("type"),
  26 + level = self:getProperty("level"),
  27 + datas = params
  28 + }
  29 + SendPacket(actionCodes.Role_updateEquip, MsgPack.pack(updateData))
  30 +end
  31 +
  32 +function Equip:updateProperty(params)
  33 + if not params.field or (not params.delta and not params.value) then
  34 + return
  35 + end
  36 + if params.delta then
  37 + self:incrProperty(params.field, params.delta)
  38 + elseif params.value then
  39 + self:setProperty(params.field, params.value)
  40 + end
  41 + self:notifyUpdateProperties(self:data())
  42 +end
  43 +
  44 +function Equip:data()
  45 + return {
  46 + type = self:getProperty("type"),
  47 + level = self:getProperty("level"),
  48 + count = self:getProperty("count"),
  49 + }
  50 +end
  51 +
  52 +return Equip
0 53 \ No newline at end of file
... ...
src/models/Hero.lua
... ... @@ -15,7 +15,8 @@ Hero.schema = {
15 15 loveExp = {"number", 0}, --好感度经验
16 16 loveL = {"number", 0}, --好感度等级
17 17 skin = {"number", 0}, --皮肤 0 、 1、 2、 3
18   - equip = {"string",""}, --装备 type=level
  18 + equip = {"string","1=0 2=0 3=0 4=0"}, --装备 type=level
  19 + rune = {"string","1=0 2=0 3=0 4=0 5=0 6=0"}, --零件 type=id
19 20 }
20 21  
21 22 function Hero:ctor( properties )
... ... @@ -76,6 +77,8 @@ function Hero:data()
76 77 loveExp = self:getProperty("loveExp"),
77 78 loveL = self:getProperty("loveL"),
78 79 skin = self:getProperty("skin"),
  80 + equip = self:getProperty("equip"),
  81 + rune = self:getProperty("rune"),
79 82 }
80 83 end
81 84  
... ...
src/models/Role.lua
... ... @@ -13,6 +13,8 @@ function Role:ctor( properties )
13 13 Role.super.ctor(self, properties)
14 14 self.ignoreHeartbeat = false
15 15 self.heros = {}
  16 + self.equipBag = {}
  17 + self.runeBag = {}
16 18 self.advData = nil
17 19 end
18 20  
... ...
src/models/RolePlugin.lua
... ... @@ -10,6 +10,8 @@ function RolePlugin.bind(Role)
10 10  
11 11 function Role:loadAll()
12 12 self:loadDaily()
  13 + self:loadEquips()
  14 + self:loadRunes()
13 15 self:loadHeros()
14 16 self:loadDiner()
15 17 end
... ... @@ -33,7 +35,7 @@ function RolePlugin.bind(Role)
33 35 end
34 36 end
35 37 function Role:onOfflineEvent()
36   -
  38 +
37 39 end
38 40  
39 41 local function checkItemCount(self, itemId, count)
... ... @@ -44,11 +46,10 @@ function RolePlugin.bind(Role)
44 46 if limit and self:getItemCount(itemId) == 0 then
45 47 local curCount = 0
46 48 local items = self:getProperty("items"):toNumMap()
47   - for _itemId, _count in pairs(items) do
48   - local _itemData = csvdb["itemCsv"][itemId]
49   - if globalCsv.store_type[_itemData.type] == page then
  49 + for _,_ in pairs(items) do
  50 + if globalCsv.store_type[itemData.type] == page then
50 51 curCount = curCount + 1
51   - if curCount >= limit then
  52 + if curCount >= limit then
52 53 count = 0
53 54 break
54 55 end
... ... @@ -77,6 +78,17 @@ function RolePlugin.bind(Role)
77 78 self:addHero(pms)
78 79 end
79 80 end,
  81 + [ItemType.EquipBase] = function()
  82 + local typ = math.floor((itemId-7000)/100)
  83 + local lv = (itemId-7000)%100
  84 + self:addEquip({type = typ,level = lv,count = count})
  85 + end,
  86 + [ItemType.Rune] = function()
  87 + local typ = math.floor((itemId-2000)/100)
  88 + for _= 1, count do
  89 + self:addRune({type = typ,id = itemId})
  90 + end
  91 + end,
80 92 [ItemType.AdvItem] = function() --冒险道具不会进入 玩家仓库
81 93 count = 0
82 94 end,
... ... @@ -135,7 +147,7 @@ function RolePlugin.bind(Role)
135 147 if not csvdb["player_expCsv"][level + 1] then
136 148 return
137 149 end
138   -
  150 +
139 151 local exp = self:getProperty("exp")
140 152 local newExp = exp + addExp
141 153 while newExp >= csvdb["player_expCsv"][level].exp do
... ... @@ -207,7 +219,7 @@ function RolePlugin.bind(Role)
207 219 end
208 220  
209 221 function Role:getItemCount(itemId)
210   - if itemId == ItemId.Diamond then
  222 + if itemId == ItemId.Diamond then
211 223 return self:getAllDiamond()
212 224 end
213 225 return self:getProperty("items"):getv(itemId, 0)
... ... @@ -283,7 +295,7 @@ function RolePlugin.bind(Role)
283 295 id = heroId,
284 296 type= heroType,
285 297 }
286   -
  298 +
287 299 local newHero = require("models.Hero").new(heroInfo)
288 300 newHero:create()
289 301 newHero.owner = self
... ... @@ -352,8 +364,146 @@ function RolePlugin.bind(Role)
352 364 end
353 365 end
354 366  
  367 + function Role:loadEquips()
  368 + local roleId = self:getProperty("id")
  369 + self.equipBag = {}
  370 + local keys = redisproxy:keys(string.format(R_EQUIP_ROOT, roleId))
  371 + if keys and next(keys) then
  372 + for _,v in pairs(keys) do
  373 + local equip = require("models.Equip").new({key = v})
  374 + equip:load()
  375 + local typ,lv = equip:getProperty("type"),equip:getProperty("level")
  376 + equip.owner = self
  377 + if not self.equipBag[typ] then self.equipBag[typ] = {} end
  378 + self.equipBag[typ][lv] = equip
  379 + end
  380 + end
  381 + end
  382 +
  383 + function Role:addEquip(params)
  384 + if params.type and params.level and params.count then
  385 + local equipType = params.type
  386 + local equipLv = params.level
  387 + local count = params.count
  388 + -- isRefer为true时count>0为卸载操作,<0为装备操作
  389 + local isRefer = params.isRefer or false
  390 + local equip = nil
  391 + local equipSet = self.equipBag[equipType]
  392 + if equipSet then
  393 + equip = self.equipBag[equipType][equipLv]
  394 + else
  395 + self.equipBag[equipType] = {}
  396 + end
  397 +
  398 + if equip then
  399 + local originCount = equip:getProperty("count")
  400 + if isRefer then
  401 + if count < 0 then
  402 + if count+originCount<0 then
  403 + return
  404 + end
  405 + else
  406 + if equip:getProperty("refer")+count<0 then
  407 + return
  408 + end
  409 + end
  410 + end
  411 + count = originCount+count
  412 + else
  413 + if isRefer then return end
  414 + local roleId = self:getProperty("id")
  415 + local data = {
  416 + key = string.format(R_EQUIP,roleId,equipType,equipLv),
  417 + type = equipType,
  418 + level = equipLv,
  419 + }
  420 + equip = require("models.Equip").new(data)
  421 + equip.owner = self
  422 + equip:create()
  423 + end
  424 + equip:updateProperty({field = "count", value = count})
  425 + if isRefer then
  426 + equip:updateProperty({field = "refer", value = equip:getProperty("refer")+params.count})
  427 + end
  428 + self.equipBag[equipType][equipLv] = equip
  429 + end
  430 + end
  431 +
  432 + function Role:getEquipCount(typ,lv)
  433 + local equipSet = self.equipBag[typ]
  434 + if equipSet then
  435 + local equip = equipSet[lv]
  436 + if equip then
  437 + return equip:getProperty("count")
  438 + else
  439 + return 0
  440 + end
  441 + else
  442 + return 0
  443 + end
  444 + end
  445 +
  446 + function Role:loadRunes()
  447 + local roleId = self:getProperty("id")
  448 + local runeIds = redisproxy:smembers(string.format(R_RUNEIDS, roleId))
  449 + local redret = redisproxy:pipelining(function (red)
  450 + for _, runeId in ipairs(runeIds) do
  451 + red:hgetall(string.format(R_RUNE, roleId, runeId))
  452 + end
  453 + end)
  454 + for index, runeId in ipairs(runeIds) do
  455 + local rune = require("models.Rune").new({key = string.format(R_RUNE, roleId, runeId)})
  456 + if rune:load(table.array2Table(redret[index])) then
  457 + rune.owner = self
  458 + self.runeBag[tonumber(runeId)] = rune
  459 + end
  460 + end
  461 + end
  462 +
  463 + -- 0 为操作成功
  464 + function Role:addRune(params)
  465 + if params.type and params.id then
  466 + local set = csvdb["runeCsv"][params.type]
  467 + if not set then return 2 end
  468 + local data = set[params.id]
  469 + if not data then return 3 end
  470 +
  471 + local roleId = self:getProperty("id")
  472 + local runeUid = tonum(redisproxy:hincrby(string.format(R_INCR, roleId), "rune", 1))
  473 +
  474 + redisproxy:sadd(string.format(R_RUNEIDS, roleId), runeUid)
  475 +
  476 + local heroInfo = {
  477 + key = string.format(R_RUNE, roleId, runeUid),
  478 + uid = runeUid,
  479 + type = params.type,
  480 + id = params.id,
  481 + }
  482 +
  483 + local newRune = require("models.Rune").new(heroInfo)
  484 + newRune:create()
  485 + newRune:generateAttrs()
  486 + newRune.owner = self
  487 + self.runeBag[runeUid] = newRune
  488 + newRune:notifyUpdateProperties(newRune:data())
  489 + return 0
  490 + else
  491 + return 1
  492 + end
  493 + end
  494 +
  495 + function Role:getRuneByType(typ)
  496 + local runeSet = {}
  497 + for _,v in pairs(self.runeBag) do
  498 + if v.type == typ then
  499 + table.insert(runeSet,v)
  500 + end
  501 + end
  502 + return runeSet
  503 + end
  504 +
355 505 function Role:getAdvData()
356   - if not self.advData then
  506 + if not self.advData then
357 507 self.advData = require("adv.Adv").new(self)
358 508 self.advData:initByInfo()
359 509 end
... ...
src/models/Rune.lua 0 → 100644
... ... @@ -0,0 +1,90 @@
  1 +local Rune = class("Rune", require("shared.ModelBase"))
  2 +Rune.schema = {
  3 + uid = {"number"}, -- 唯一自增id
  4 + type = {"number"}, -- 装备位置
  5 + id = {"number"},
  6 + level = {"number", 0}, -- 等级
  7 + refer = {"number", 0}, -- 已装备英雄id
  8 + attrs = {"string",""} -- 基础属性值 id=value
  9 +}
  10 +
  11 +function Rune:ctor( properties )
  12 + Rune.super.ctor(self, properties)
  13 +end
  14 +
  15 +function Rune:notifyUpdateProperty(field, newValue, oldValue)
  16 + local datas = {
  17 + key = field,
  18 + newValue = newValue,
  19 + oldValue = oldValue,
  20 + }
  21 + self:notifyUpdateProperties(datas)
  22 +end
  23 +
  24 +function Rune:notifyUpdateProperties(params)
  25 + local updateData = {
  26 + uid = self:getProperty("uid"),
  27 + datas = params
  28 + }
  29 + SendPacket(actionCodes.Role_updateRune, MsgPack.pack(updateData))
  30 +end
  31 +
  32 +function Rune:updateProperty(params)
  33 + if not params.field or (not params.delta and not params.value) then
  34 + return
  35 + end
  36 + if params.delta then
  37 + self:incrProperty(params.field, params.delta)
  38 + elseif params.value then
  39 + self:setProperty(params.field, params.value)
  40 + end
  41 + self:notifyUpdateProperties(self:data())
  42 +end
  43 +
  44 +-- types 类型=权重"2=100 3=100 4=100" value最大值=最小值 "50=100 50=100 100=200"
  45 +local function getRandomValue(types,values)
  46 + local typeMap = types:toNumMap()
  47 + local valueArry = values:toArray()
  48 + if table.nums(typeMap) ~= #valueArry then return nil end
  49 + local typ,value
  50 + local typTab,weightSum = {},0
  51 + for t,w in pairs(typeMap) do
  52 + weightSum = weightSum + w
  53 + table.insert(typTab,{t=t,w=weightSum})
  54 + end
  55 +
  56 + local tk
  57 + local tmp = math.random(1,weightSum)
  58 + for k,v in ipairs(typTab) do
  59 + if v.w >= tmp then
  60 + typ = v.t
  61 + tk = k
  62 + break
  63 + end
  64 + end
  65 +
  66 + local range = valueArry[tk]:toArray(true,"=")
  67 + value = math.random(range[1],range[2])
  68 + return typ,value
  69 +end
  70 +
  71 +function Rune:generateAttrs()
  72 + local runeData = csvdb["runeCsv"][self:getProperty("type")][self:getProperty("id")]
  73 + local attrs = ""
  74 + attrs = attrs:setv(getRandomValue(runeData.attr1,runeData.range1))
  75 + attrs = attrs:setv(getRandomValue(runeData.attr2,runeData.range2))
  76 + self:setProperty("attrs",attrs)
  77 +end
  78 +
  79 +function Rune:data()
  80 + return {
  81 + uid = self:getProperty("uid"),
  82 + type = self:getProperty("type"),
  83 + id = self:getProperty("id"),
  84 + refer = self:getProperty("refer"),
  85 + attrs = self:getProperty("attrs"),
  86 + level = self:getProperty("level"),
  87 + }
  88 +end
  89 +
  90 +return Rune
0 91 \ No newline at end of file
... ...