Role.lua
6.03 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
local Role = class("Role", require("shared.ModelBase"))
local RolePlugin = import(".RolePlugin")
local RoleTask = import(".RoleTask")
local RoleActivity = import(".RoleActivity")
local RoleChangeStruct = import(".RoleChangeStruct")
RolePlugin.bind(Role)
RoleTask.bind(Role)
RoleActivity.bind(Role)
RoleChangeStruct.bind(Role)
function Role:ctor( properties )
Role.super.ctor(self, properties)
self.ignoreHeartbeat = false
self.heros = {}
self.runeBag = {}
self.advData = nil
end
Role.schema = {
id = {"number"},
uid = {"string", ""},
name = {"string", ""},
sid = {"number", 0},
device = {"string", ""},
banTime = {"number", 0},
banType = {"number", 0},
ltime = {"number", 0}, -- 最后登录时间
ctime = {"number", skynet.timex()}, -- 创建时间
ignoreMt = {"number", 0}, -- 忽略维护拦截
sversion = {"number", globalCsv.StructVersion or 0}, -- 重整数据版本
diamond = {"number", 0},
reDiamond = {"number", 0},
-- roleInfo
level = {"number", 1},
exp = {"number", 0},
items = {"string", ""},
loveStatus = {"string", ""}, --统计角色的最高 好感度等级 类型相关 -- type=loveL type=loveL
crown = {"number", 0}, -- 看伴娘
bagLimit = {"table", globalCsv.store_limit_max},
--冒险相关
advPass = {"string", ""}, -- 通关记录
advItems = {"string", ""}, -- 冒险临时背包
advInfo = {"table", {}}, -- 冒险关卡信息
advTeam = {"table", {}}, -- 冒险玩家队伍信息
--挂机相关
hangPass = {"table", {}}, -- 挂机通过的最大关卡
hangTeam = {"table", {}}, -- 挂机队伍
hangInfo = {"table", {}}, -- 当前挂机信息
hangBag = {"table", {}}, -- 背包
hangBagLimit = {"number", globalCsv.idle_field_origin}, --背包上限
potionBag = {"table", {}}, -- 营养剂背包
storyB = {"table", {}}, -- 剧情记录
equips = {"table", {}}, -- 装备简化下, 目前的设计足够支撑 -- {t = {l = c}} -- 接口设计好 底层扩展就重写~
boxL = {"table", {}}, -- boxList 正开启的箱子 -- {[1] = {id = 1010, gem = 101, time = 1313}}
towerInfo = {"table", {c = globalCsv.tower_count_limit}}, -- 当天爬塔消耗的次数 -- {t = time, c = count, l = layer, k = battleKey}
towerF = {"table", {}}, -- 爬塔阵容
}
function Role:notifyUpdateProperty(field, newValue, oldValue, extraValue)
local updateData = {
{
key = field,
newValue = newValue,
oldValue = oldValue or "",
extraValue = extraValue,
}
}
SendPacket(actionCodes.Role_updateProperty, MsgPack.pack(updateData))
end
function Role:updateProperty(params)
params = params or {}
if not self.schema[params.field] then return end
local oldValue = self:getProperty(params.field)
local ret = {key = params.field, oldValue = oldValue}
if params.value then
ret.newValue = params.value
self:setProperty(params.field, params.value)
elseif params.delta then
self:incrProperty(params.field, params.delta)
ret.newValue = self:getProperty(params.field)
else
return
end
if not params.notNotify then
SendPacket(actionCodes.Role_updateProperty, MsgPack.pack({ret}))
end
end
function Role:updateProperties(params, notNotify)
for field, value in pairs(params) do
self:setProperty(field, value)
end
if not notNotify then
SendPacket(actionCodes.Role_updateProperties, MsgPack.pack(params))
end
end
function Role:notifyUpdateProperties(params)
SendPacket(actionCodes.Role_updateProperties, MsgPack.pack(params))
end
-- 某些字段 更新改变量 改变量的定义由字段自身决定 {{type = ""}, }
function Role:changeUpdates(params, notNotify)
local changeUpdateFunc = {
["loveStatus"] = function(info)
self:setProperty("loveStatus", self:getProperty("loveStatus"):setv(info["field"], info["value"]))
return {type = "loveStatus", field = info["field"], value = info["value"]}
end,
--table 类型通用更新
["tableCommon"] = function(fieldType, info)
if self.class.schema[fieldType][1] ~= "table" then
error("[ERROR:] need handler for changeUpdate, field : " .. fieldType)
return
end
--支持多深度单字段
local curValue = self:getProperty(fieldType)
if type(info["field"]) == "table" then
for _idx, _field in ipairs(info["field"]) do
if _idx < #info["field"] then
curValue[_field] = curValue[_field] or {}
curValue = curValue[_field]
else
curValue[_field] = info["value"]
end
end
else
curValue[info["field"]] = info["value"]
end
self:setProperty(fieldType)
return {type = fieldType, field = info["field"], value = info["value"]}
end,
["onlyToC"] = function(info)
return info
end,
}
local updates = {}
for _, one in ipairs(params) do
if changeUpdateFunc[one["type"]] then
table.insert(updates, changeUpdateFunc[one["type"]](one))
elseif one.isOnlyToC then
one.isOnlyToC = nil
table.insert(updates, one)
else
table.insert(updates, changeUpdateFunc["tableCommon"](one["type"], one))
end
end
if not notNotify and next(updates) then
SendPacket(actionCodes.Role_changeUpdate, MsgPack.pack(updates))
end
end
function Role:data()
return {
id = self:getProperty("id"),
name = self:getProperty("name"),
level = self:getProperty("level"),
exp = self:getProperty("exp"),
items = self:getProperty("items"):toNumMap(),
loveStatus = self:getProperty("loveStatus"):toNumMap(),
diamond = self:getAllDiamond(),
bagLimit = self:getProperty("bagLimit"),
advPass = self:getProperty("advPass"),
advInfo = self:getProperty("advInfo"),
advItems = self:getProperty("advItems"):toNumMap(),
advTeam = self:getProperty("advTeam"),
hangPass = self:getProperty("hangPass"),
hangTeam = self:getProperty("hangTeam"),
hangInfo = self:getProperty("hangInfo"),
hangBag = self:getProperty("hangBag"),
hangBagLimit = self:getProperty("hangBagLimit"),
potionBag = self:getProperty("potionBag"),
storyB = self:getProperty("storyB"),
equips = self:getProperty("equips"),
boxL = self:getProperty("boxL"),
towerInfo = self:getProperty("towerInfo"),
towerF = self:getProperty("towerF"),
}
end
return Role