Commit 43cc5f51fa654a8a29e951ca5f6ca9737b80bbbf
1 parent
bd4316d2
调整 equip 数据结构
Showing
13 changed files
with
363 additions
and
25 deletions
Show diff stats
.luacheckrc
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, |
... | ... | @@ -46,6 +48,8 @@ actionCodes = { |
46 | 48 | Hero_loveTaskRpc = 213, |
47 | 49 | Hero_changeSkinRpc = 214, |
48 | 50 | Hero_createHeroRpc = 215, |
51 | + Hero_referEquipsRpc = 216, | |
52 | + Hero_referRunesRpc = 217, | |
49 | 53 | |
50 | 54 | Hang_startRpc = 251, |
51 | 55 | Hang_checkRpc = 252, | ... | ... |
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_RUNE_ROOT = "role:%d:rune*" -- 符文根目录 | |
10 | +R_RUNE = "role:%d:rune:%d" -- 符文零件id:level | |
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,14 +83,9 @@ 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 | |
83 | - end | |
84 | - | |
85 | 86 | role:costItems(cost) |
86 | - role:costItems(merge) | |
87 | - role:addItem({itemId = nextEquip.id,count = count}) | |
87 | + role:addEquip({type=typ,level=lv,count=-costCount}) | |
88 | + role:addEquip({type=typ,level=nextLv,count=count}) | |
88 | 89 | SendPacket(actionCodes.Car_equipUpRpc, '') |
89 | 90 | return true |
90 | 91 | end | ... | ... |
src/actions/GmAction.lua
... | ... | @@ -22,6 +22,14 @@ 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 | + | |
25 | 33 | function _M.get(role, pms) |
26 | 34 | local itemId = tonum(pms.pm1) |
27 | 35 | if not csvdb["itemCsv"][itemId] then | ... | ... |
src/actions/HeroAction.lua
... | ... | @@ -451,4 +451,53 @@ function _M.createHeroRpc(agent, data) |
451 | 451 | return true |
452 | 452 | end |
453 | 453 | |
454 | +-- typ 位置,level等级对应唯一装备,level为0时为移除,不为0时无则装备,有则替换 | |
455 | +function _M.referEquips(agent, data) | |
456 | + local role = agent.role | |
457 | + local msg = MsgPack.unpack(data) | |
458 | + local hero = role.heros[msg.id] | |
459 | + if not hero then return 10 end | |
460 | + local equips = msg.equips | |
461 | + if not equips or not next(equips) then return 11 end | |
462 | + | |
463 | + for typ,level in pairs(equips) do | |
464 | + local ownLv = hero:getProperty("equip"):getv(typ,0) | |
465 | + if level == 0 then | |
466 | + if ownLv == 0 then return 2 end | |
467 | + else | |
468 | + if role:getEquipCount(typ,level) < 1 then return 3 end | |
469 | + end | |
470 | + local equipSet = csvdb["equipCsv"][typ] | |
471 | + if not equipSet then return 4 end | |
472 | + local equipData = equipSet[level] | |
473 | + if not equipData then return 5 end | |
474 | + end | |
475 | + | |
476 | + for typ,level in pairs(equips) do | |
477 | + local ownLv = hero:getProperty("equip"):getv(typ,0) | |
478 | + if level == 0 then | |
479 | + role:addEquip({{type=typ,level=ownLv,count=1}}) | |
480 | + else | |
481 | + role:addEquip({{type=typ,level=level,count=-1}}) | |
482 | + if ownLv ~= 0 then | |
483 | + role:addEquip({type=typ,level=ownLv,count=1}) | |
484 | + end | |
485 | + end | |
486 | + hero:updateProperty({field = "equip", value = hero:getProperty("equip"):setv(typ, level)}) | |
487 | + end | |
488 | + SendPacket(actionCodes.Hero_referEquipsRpc, "") | |
489 | + return true | |
490 | +end | |
491 | + | |
492 | +-- typ 位置,id等级对应唯一符文,id为0时为移除,不为0时无则装备,有则替换 | |
493 | +function _M.referRunes(agent, data) | |
494 | + local role = agent.role | |
495 | + local msg = MsgPack.unpack(data) | |
496 | + local hero = role.heros[msg.id] | |
497 | + if not hero then return 10 end | |
498 | + local runes = msg.runes | |
499 | + if not runes or not next(runes) then return 11 end | |
500 | + return true | |
501 | +end | |
502 | + | |
454 | 503 | return _M |
455 | 504 | \ 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,26 @@ 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 _,set in pairs(role.equipBag) do | |
158 | + for _,equip in pairs(set) do | |
159 | + local data = equip:data() | |
160 | + if not equipResp.equipBag[data.type] then equipResp.equipBag[data.type] = {} end | |
161 | + equipResp.equipBag[data.type][data.level] = data | |
162 | + end | |
163 | + end | |
164 | + SendPacket(actionCodes.Role_loginRpc, MsgPack.pack(equipResp)) | |
165 | + | |
166 | + local runeResp = {runeBag = {}} | |
167 | + for _,rune in pairs(role.runeBag) do | |
168 | + table_insert(runeResp.runeBag, rune:data()) | |
169 | + end | |
170 | + SendPacket(actionCodes.Role_loginRpc, MsgPack.pack(runeResp)) | |
171 | + | |
156 | 172 | local heroIndex = 1 |
157 | 173 | for index = 2, 1 + heroWave do |
158 | 174 | local heroResponse = {heros = {}} |
... | ... | @@ -177,7 +193,7 @@ function _M.loginRpc( agent, data ) |
177 | 193 | gate_serv = agent.gate_serv, |
178 | 194 | }) |
179 | 195 | agent.role = role |
180 | - | |
196 | + | |
181 | 197 | start_agent_timer() |
182 | 198 | -- 注册全服广播 |
183 | 199 | local channel = math.randomInt(1, 1) |
... | ... | @@ -293,7 +309,7 @@ function _M.openItemRpc(agent, data) |
293 | 309 | end |
294 | 310 | role:costItems({[itemId] = count}) |
295 | 311 | reward = role:award(reward) |
296 | - | |
312 | + | |
297 | 313 | SendPacket(actionCodes.Role_openItemRpc, MsgPack.pack({reward = reward})) |
298 | 314 | return true |
299 | 315 | end | ... | ... |
... | ... | @@ -0,0 +1,34 @@ |
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:updateProperty(params) | |
15 | + if not params.field or (not params.delta and not params.value) then | |
16 | + return | |
17 | + end | |
18 | + if params.delta then | |
19 | + self:incrProperty(params.field, params.delta) | |
20 | + elseif params.value then | |
21 | + self:setProperty(params.field, params.value) | |
22 | + end | |
23 | + SendPacket(actionCodes.Role_updateEquip, MsgPack.pack(self:data())) | |
24 | +end | |
25 | + | |
26 | +function Equip:data() | |
27 | + return { | |
28 | + type = self:getProperty("type"), | |
29 | + level = self:getProperty("level"), | |
30 | + count = self:getProperty("count"), | |
31 | + } | |
32 | +end | |
33 | + | |
34 | +return Equip | |
0 | 35 | \ No newline at end of file | ... | ... |
src/models/Hero.lua
... | ... | @@ -15,11 +15,12 @@ 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 | 19 | } |
20 | 20 | |
21 | 21 | function Hero:ctor( properties ) |
22 | 22 | Hero.super.ctor(self, properties) |
23 | + self.runes = {} --符文-零件自增 id | |
23 | 24 | end |
24 | 25 | |
25 | 26 | function Hero:notifyUpdateProperty(field, newValue, oldValue) | ... | ... |
src/models/Role.lua
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 |
... | ... | @@ -135,7 +136,7 @@ function RolePlugin.bind(Role) |
135 | 136 | if not csvdb["player_expCsv"][level + 1] then |
136 | 137 | return |
137 | 138 | end |
138 | - | |
139 | + | |
139 | 140 | local exp = self:getProperty("exp") |
140 | 141 | local newExp = exp + addExp |
141 | 142 | while newExp >= csvdb["player_expCsv"][level].exp do |
... | ... | @@ -207,7 +208,7 @@ function RolePlugin.bind(Role) |
207 | 208 | end |
208 | 209 | |
209 | 210 | function Role:getItemCount(itemId) |
210 | - if itemId == ItemId.Diamond then | |
211 | + if itemId == ItemId.Diamond then | |
211 | 212 | return self:getAllDiamond() |
212 | 213 | end |
213 | 214 | return self:getProperty("items"):getv(itemId, 0) |
... | ... | @@ -283,7 +284,7 @@ function RolePlugin.bind(Role) |
283 | 284 | id = heroId, |
284 | 285 | type= heroType, |
285 | 286 | } |
286 | - | |
287 | + | |
287 | 288 | local newHero = require("models.Hero").new(heroInfo) |
288 | 289 | newHero:create() |
289 | 290 | newHero.owner = self |
... | ... | @@ -352,8 +353,170 @@ function RolePlugin.bind(Role) |
352 | 353 | end |
353 | 354 | end |
354 | 355 | |
356 | + function Role:loadEquips() | |
357 | + local roleId = self:getProperty("id") | |
358 | + self.equipBag = {} | |
359 | + local keys = redisproxy:keys(string.format(R_EQUIP_ROOT, roleId)) | |
360 | + if keys and next(keys) then | |
361 | + for _,v in pairs(keys) do | |
362 | + local equip = require("models.Equip").new({key = v}) | |
363 | + equip:load() | |
364 | + local typ,lv = equip:getProperty("type"),equip:getProperty("level") | |
365 | + equip.owner = self | |
366 | + if not self.equipBag[typ] then self.equipBag[typ] = {} end | |
367 | + self.equipBag[typ][lv] = equip | |
368 | + end | |
369 | + end | |
370 | + end | |
371 | + | |
372 | + function Role:addEquip(params) | |
373 | + if params.type and params.level and params.count then | |
374 | + local equipType = params.type | |
375 | + local equipLv = params.level | |
376 | + local count = params.count | |
377 | + -- isRefer为true时count>0为卸载操作,<0为装备操作 | |
378 | + local isRefer = params.isRefer or false | |
379 | + local equip = nil | |
380 | + local equipSet = self.equipBag[equipType] | |
381 | + if equipSet then | |
382 | + equip = self.equipBag[equipType][equipLv] | |
383 | + else | |
384 | + self.equipBag[equipType] = {} | |
385 | + end | |
386 | + | |
387 | + if equip then | |
388 | + local originCount = equip:getProperty("count") | |
389 | + if isRefer and count < 0 then | |
390 | + if count < 0 then | |
391 | + if count+originCount<0 then | |
392 | + return | |
393 | + end | |
394 | + else | |
395 | + if equip:getProperty("refer")-count<0 then | |
396 | + return | |
397 | + end | |
398 | + end | |
399 | + end | |
400 | + count = originCount+count | |
401 | + else | |
402 | + if isRefer then return end | |
403 | + local roleId = self:getProperty("id") | |
404 | + local data = { | |
405 | + key = string.format(R_EQUIP,roleId,equipType,equipLv), | |
406 | + type = equipType, | |
407 | + level = equipLv, | |
408 | + } | |
409 | + equip = require("models.Equip").new(data) | |
410 | + equip.owner = self | |
411 | + equip:create() | |
412 | + end | |
413 | + equip:updateProperty({field = "count", value = math.min(count,0)}) | |
414 | + if isRefer then | |
415 | + equip:updateProperty({field = "refer", value = math.min(equip:getProperty("refer")+count,0)}) | |
416 | + end | |
417 | + self.equipBag[equipType][equipLv] = equip | |
418 | + end | |
419 | + end | |
420 | + | |
421 | + function Role:getEquipCount(typ,lv) | |
422 | + local equipSet = self.equipBag[typ] | |
423 | + if equipSet then | |
424 | + local equip = equipSet[lv] | |
425 | + if equip then | |
426 | + return equip:getProperty("count") | |
427 | + else | |
428 | + return 0 | |
429 | + end | |
430 | + else | |
431 | + return 0 | |
432 | + end | |
433 | + end | |
434 | + | |
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") | |
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) | |
472 | + end | |
473 | + end | |
474 | + | |
475 | + 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 | |
487 | + | |
488 | + if rune then | |
489 | + count = rune:getProperty("count")+count | |
490 | + 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() | |
499 | + end | |
500 | + rune:updateProperty({field = "count", value = math.min(count,0)}) | |
501 | + self.runeBag[runeId][runeLv] = rune | |
502 | + end | |
503 | + | |
504 | + function Role:getRuneCount(id,lv) | |
505 | + local runeSet = self.runeBag[id] | |
506 | + if runeSet then | |
507 | + local rune = runeSet[lv] | |
508 | + if rune then | |
509 | + return rune:getProperty("count") | |
510 | + else | |
511 | + return 0 | |
512 | + end | |
513 | + else | |
514 | + return 0 | |
515 | + end | |
516 | + end | |
517 | + | |
355 | 518 | function Role:getAdvData() |
356 | - if not self.advData then | |
519 | + if not self.advData then | |
357 | 520 | self.advData = require("adv.Adv").new(self) |
358 | 521 | self.advData:initByInfo() |
359 | 522 | end | ... | ... |
... | ... | @@ -0,0 +1,52 @@ |
1 | +local Rune = class("Rune", require("shared.ModelBase")) | |
2 | +Rune.schema = { | |
3 | + id = {"number"}, | |
4 | + level = {"number", 0}, -- 等级 | |
5 | + count = {"number", 0}, -- 数量 | |
6 | + refer = {"number", 0}, -- 已装备英雄id | |
7 | +} | |
8 | + | |
9 | +function Rune:ctor( properties ) | |
10 | + Rune.super.ctor(self, properties) | |
11 | +end | |
12 | + | |
13 | +function Rune:notifyUpdateProperty(field, newValue, oldValue) | |
14 | + local datas = { | |
15 | + key = field, | |
16 | + newValue = newValue, | |
17 | + oldValue = oldValue, | |
18 | + } | |
19 | + self:notifyUpdateProperties(datas) | |
20 | +end | |
21 | + | |
22 | +function Rune:notifyUpdateProperties(params) | |
23 | + local updateData = { | |
24 | + id = self:getProperty("id"), | |
25 | + datas = params | |
26 | + } | |
27 | + SendPacket(actionCodes.Role_updateRune, MsgPack.pack(updateData)) | |
28 | +end | |
29 | + | |
30 | +function Rune:updateProperty(params) | |
31 | + if not params.field or (not params.delta and not params.value) then | |
32 | + return | |
33 | + end | |
34 | + if params.delta then | |
35 | + self:incrProperty(params.field, params.delta) | |
36 | + elseif params.value then | |
37 | + self:setProperty(params.field, params.value) | |
38 | + end | |
39 | + local datas = {} | |
40 | + table.insert(datas, {key = params.field, newValue = self:getProperty(params.field)}) | |
41 | + self:notifyUpdateProperties(datas) | |
42 | +end | |
43 | + | |
44 | +function Rune:data() | |
45 | + return { | |
46 | + id = self:getProperty("id"), | |
47 | + level = self:getProperty("level"), | |
48 | + count = self:getProperty("count"), | |
49 | + } | |
50 | +end | |
51 | + | |
52 | +return Rune | |
0 | 53 | \ No newline at end of file | ... | ... |