RolePlugin.lua
1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
local RolePlugin = {}
function RolePlugin.bind(Role)
function Role:log()
end
function Role:loadAll()
self:loadHeros()
end
function Role:reloadWhenLogin()
end
function Role:onCrossDay(now)
end
function Role:addHero(params)
local roleId = self:getProperty("id")
local heroId = tonum(redisproxy:hincrby(string.format(R_INCR, roleId), "hero", 1))
local heroType = params.type
local unitData = csvdb["unitCsv"][heroType]
redisproxy:sadd(string.format(R_HEROS, roleId), heroId)
local heroInfo = {
key = string.format(R_HERO, roleId, heroId),
id = heroId,
type= heroType,
}
local newHero = require("models.Hero").new(heroInfo)
newHero:create()
newHero.owner = self
self.heros[heroId] = newHero
if not params.notNotify then
local heroResponse = {}
table.insert(heroResponse, newHero:data())
local bin = MsgPack.pack(heroResponse)
SendPacket(actionCodes.Hero_loadInfos, bin)
end
end
function Role:delHero(params)
local roleId = self:getProperty('id')
local hero = self.heros[heroId]
if not hero then return end
self.heros[heroId] = nil
redisproxy:pipelining(function (red)
red:del(string.format(R_HERO, roleId, heroId))
red:srem(string.format(R_HEROS, roleId), heroId)
end)
SendPacket(actionCodes.Hero_loadInfos, MsgPack.pack({{id = heroId, bDel = true}}))
end
function Role:loadHeros()
local roleId = self:getProperty("id")
local heroIds = redisproxy:smembers(string.format(R_HEROS, roleId))
local redret = redisproxy:pipelining(function (red)
for _, heroId in ipairs(heroIds) do
red:hgetall(string.format(R_HERO, roleId, heroId))
end
end)
for index, heroId in ipairs(heroIds) do
local hero = require("models.Hero").new({key = string.format(R_HERO, roleId, heroId)})
if hero:load(table.array2Table(redret[index])) then
hero.owner = self
self.heros[tonumber(heroId)] = hero
end
end
end
-- 发奖功能入口
function Role:award()
end
end
return RolePlugin