Commit ad484303cb54fc675d96a74be7c853e067641e9f

Authored by gaofengduan
1 parent f58eefd7

add rune

1 std = "max" 1 std = "max"
2 globals = { 2 globals = {
3 - "R_RUNE_ROOT", 3 + "R_RUNEIDS",
4 "R_EQUIP_ROOT", 4 "R_EQUIP_ROOT",
5 "R_EQUIP", 5 "R_EQUIP",
6 "R_RUNE", 6 "R_RUNE",
@@ -6,8 +6,8 @@ R_DAILY = "role:%d:daily" @@ -6,8 +6,8 @@ R_DAILY = "role:%d:daily"
6 R_DINER = "role:%d:diner" -- 餐厅 6 R_DINER = "role:%d:diner" -- 餐厅
7 R_EQUIP_ROOT = "role:%d:equip*" -- 装备根目录 7 R_EQUIP_ROOT = "role:%d:equip*" -- 装备根目录
8 R_EQUIP = "role:%d:equip:%d:%d" -- 装备type:level 8 R_EQUIP = "role:%d:equip:%d:%d" -- 装备type:level
9 -R_RUNE_ROOT = "role:%d:rune*" -- 符文根目录  
10 -R_RUNE = "role:%d:rune:%d" -- 符文零件id:level 9 +R_RUNEIDS = "role:%d:runeIds" -- 玩家拥有符文自增id
  10 +R_RUNE = "role:%d:rune:%d" -- 符文详细信息
11 11
12 -- -- role 12 -- -- role
13 -- R_FARM_KEY = "role:%d:farm" 13 -- R_FARM_KEY = "role:%d:farm"
src/actions/GmAction.lua
@@ -30,6 +30,13 @@ function _M.equip(role, pms) @@ -30,6 +30,13 @@ function _M.equip(role, pms)
30 return "成功" 30 return "成功"
31 end 31 end
32 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 +
33 function _M.get(role, pms) 40 function _M.get(role, pms)
34 local itemId = tonum(pms.pm1) 41 local itemId = tonum(pms.pm1)
35 if not csvdb["itemCsv"][itemId] then 42 if not csvdb["itemCsv"][itemId] then
src/models/Equip.lua
@@ -11,6 +11,24 @@ function Equip:ctor( properties ) @@ -11,6 +11,24 @@ function Equip:ctor( properties )
11 Equip.super.ctor(self, properties) 11 Equip.super.ctor(self, properties)
12 end 12 end
13 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 +
14 function Equip:updateProperty(params) 32 function Equip:updateProperty(params)
15 if not params.field or (not params.delta and not params.value) then 33 if not params.field or (not params.delta and not params.value) then
16 return 34 return
@@ -20,7 +38,7 @@ function Equip:updateProperty(params) @@ -20,7 +38,7 @@ function Equip:updateProperty(params)
20 elseif params.value then 38 elseif params.value then
21 self:setProperty(params.field, params.value) 39 self:setProperty(params.field, params.value)
22 end 40 end
23 - SendPacket(actionCodes.Role_updateEquip, MsgPack.pack(self:data())) 41 + self:notifyUpdateProperties(self:data())
24 end 42 end
25 43
26 function Equip:data() 44 function Equip:data()
src/models/RolePlugin.lua
@@ -433,72 +433,52 @@ function RolePlugin.bind(Role) @@ -433,72 +433,52 @@ function RolePlugin.bind(Role)
433 end 433 end
434 434
435 function Role:loadRunes() 435 function Role:loadRunes()
436 - -- local roleId = self:getProperty("id")  
437 - -- self.runeBag = {}  
438 - -- local keys = redisproxy:keys(string.format(R_EQUIP_ROOT, roleId))  
439 - -- if keys and next(keys) then  
440 - -- for _,v in pairs(keys) do  
441 - -- local rune = require("models.Rune").new({key = v})  
442 - -- rune.owner = self  
443 - -- self.runeBag[rune.id][rune.level] = rune  
444 - -- end  
445 - -- end  
446 - end  
447 -  
448 - function Role:addHero(params)  
449 local roleId = self:getProperty("id") 436 local roleId = self:getProperty("id")
450 - local heroId = tonum(redisproxy:hincrby(string.format(R_INCR, roleId), "hero", 1))  
451 - local heroType = params.type  
452 -  
453 - redisproxy:sadd(string.format(R_HEROS, roleId), heroId)  
454 -  
455 - local heroInfo = {  
456 - key = string.format(R_HERO, roleId, heroId),  
457 - id = heroId,  
458 - type= heroType,  
459 - }  
460 -  
461 - local newHero = require("models.Hero").new(heroInfo)  
462 - newHero:create()  
463 - newHero.owner = self  
464 - newHero:saveBattleValue()  
465 - self.heros[heroId] = newHero  
466 -  
467 - if not params.notNotify then  
468 - local heroResponse = {}  
469 - table.insert(heroResponse, newHero:data())  
470 - local bin = MsgPack.pack(heroResponse)  
471 - SendPacket(actionCodes.Hero_loadInfos, bin) 437 + local runeIds = redisproxy:smembers(string.format(R_RUNEIDS, roleId))
  438 + local redret = redisproxy:pipelining(function (red)
  439 + for _, runeId in ipairs(runeIds) do
  440 + red:hgetall(string.format(R_RUNE, roleId, runeId))
  441 + end
  442 + end)
  443 + for index, runeId in ipairs(runeIds) do
  444 + local rune = require("models.Rune").new({key = string.format(R_RUNE, roleId, runeId)})
  445 + if rune:load(table.array2Table(redret[index])) then
  446 + rune.owner = self
  447 + self.runeBag[tonumber(runeId)] = rune
  448 + end
472 end 449 end
473 end 450 end
474 451
  452 + -- 0 为操作成功
475 function Role:addRune(params) 453 function Role:addRune(params)
476 - local roleId = self:getProperty("id")  
477 - local runeId = params.id  
478 - local runeLv = params.level  
479 - local count = params.count  
480 - local rune = nil  
481 - local runeSet = self.runeBag[runeId]  
482 - if runeSet then  
483 - rune = self.runeBag[runeId][runeLv]  
484 - else  
485 - self.runeBag[runeId] = {}  
486 - end 454 + if params.type and params.id then
  455 + local set = csvdb["runeCsv"][params.type]
  456 + if not set then return 2 end
  457 + local data = set[params.id]
  458 + if not data then return 3 end
  459 +
  460 + local roleId = self:getProperty("id")
  461 + local runeUid = tonum(redisproxy:hincrby(string.format(R_INCR, roleId), "rune", 1))
  462 +
  463 + redisproxy:sadd(string.format(R_RUNEIDS, roleId), runeUid)
  464 +
  465 + local heroInfo = {
  466 + key = string.format(R_RUNE, roleId, runeUid),
  467 + uid = runeUid,
  468 + type = params.type,
  469 + id = params.id,
  470 + }
  471 +
  472 + local newRune = require("models.Rune").new(heroInfo)
  473 + newRune:create()
  474 + newRune:generateAttrs()
  475 + newRune.owner = self
  476 + self.runeBag[runeUid] = newRune
487 477
488 - if rune then  
489 - count = rune:getProperty("count")+count 478 + return 0
490 else 479 else
491 - local data = {  
492 - key = string.format(R_RUNE,roleId,runeId,runeLv),  
493 - id = runeId,  
494 - level = runeLv,  
495 - }  
496 - rune = require("models.Rune").new(data)  
497 - rune.owner = self  
498 - rune:create() 480 + return 1
499 end 481 end
500 - rune:updateProperty({field = "count", value = math.min(count,0)})  
501 - self.runeBag[runeId][runeLv] = rune  
502 end 482 end
503 483
504 function Role:getRuneCount(id,lv) 484 function Role:getRuneCount(id,lv)
src/models/Rune.lua
1 local Rune = class("Rune", require("shared.ModelBase")) 1 local Rune = class("Rune", require("shared.ModelBase"))
2 Rune.schema = { 2 Rune.schema = {
  3 + uid = {"number"}, -- 唯一自增id
  4 + type = {"number"}, -- 装备位置
3 id = {"number"}, 5 id = {"number"},
4 level = {"number", 0}, -- 等级 6 level = {"number", 0}, -- 等级
5 - count = {"number", 0}, -- 数量  
6 refer = {"number", 0}, -- 已装备英雄id 7 refer = {"number", 0}, -- 已装备英雄id
  8 + attrs = {"string",""} -- 基础属性值 id=value
7 } 9 }
8 10
9 function Rune:ctor( properties ) 11 function Rune:ctor( properties )
@@ -21,7 +23,7 @@ end @@ -21,7 +23,7 @@ end
21 23
22 function Rune:notifyUpdateProperties(params) 24 function Rune:notifyUpdateProperties(params)
23 local updateData = { 25 local updateData = {
24 - id = self:getProperty("id"), 26 + uid = self:getProperty("uid"),
25 datas = params 27 datas = params
26 } 28 }
27 SendPacket(actionCodes.Role_updateRune, MsgPack.pack(updateData)) 29 SendPacket(actionCodes.Role_updateRune, MsgPack.pack(updateData))
@@ -36,16 +38,54 @@ function Rune:updateProperty(params) @@ -36,16 +38,54 @@ function Rune:updateProperty(params)
36 elseif params.value then 38 elseif params.value then
37 self:setProperty(params.field, params.value) 39 self:setProperty(params.field, params.value)
38 end 40 end
39 - local datas = {}  
40 - table.insert(datas, {key = params.field, newValue = self:getProperty(params.field)})  
41 - self:notifyUpdateProperties(datas) 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 + print("typ "..typ.." value "..value)
  69 + return typ,value
  70 +end
  71 +
  72 +function Rune:generateAttrs()
  73 + local runeData = csvdb["runeCsv"][self:getProperty("type")][self:getProperty("id")]
  74 + local attrs = ""
  75 + attrs:setv(1,20)
  76 + attrs:setv(getRandomValue(runeData.attr1,runeData.range1))
  77 + attrs:setv(getRandomValue(runeData.attr2,runeData.range2))
  78 + print(attrs)
  79 + self:setProperty("attrs","2=30")
42 end 80 end
43 81
44 function Rune:data() 82 function Rune:data()
45 return { 83 return {
  84 + uid = self:getProperty("uid"),
  85 + type = self:getProperty("type"),
46 id = self:getProperty("id"), 86 id = self:getProperty("id"),
47 - level = self:getProperty("level"),  
48 - count = self:getProperty("count"), 87 + refer = self:getProperty("refer"),
  88 + attrs = self:getProperty("attrs"),
49 } 89 }
50 end 90 end
51 91