314bc5df
zhengshouren
提交服务器初始代码
|
1
2
|
local Role = class("Role", require("shared.ModelBase"))
|
be83d162
zhouahaihai
登陆成功。 增加数据结构修正功能
|
3
4
|
local RolePlugin = import(".RolePlugin")
local RoleTask = import(".RoleTask")
|
23d89d13
zhouahaihai
冒险 结构
|
5
|
local RoleAdv = import(".RoleAdv")
|
be83d162
zhouahaihai
登陆成功。 增加数据结构修正功能
|
6
7
8
9
|
local RoleActivity = import(".RoleActivity")
local RoleChangeStruct = import(".RoleChangeStruct")
RolePlugin.bind(Role)
RoleTask.bind(Role)
|
23d89d13
zhouahaihai
冒险 结构
|
10
|
RoleAdv.bind(Role)
|
be83d162
zhouahaihai
登陆成功。 增加数据结构修正功能
|
11
12
13
|
RoleActivity.bind(Role)
RoleChangeStruct.bind(Role)
|
314bc5df
zhengshouren
提交服务器初始代码
|
14
15
|
function Role:ctor( properties )
Role.super.ctor(self, properties)
|
314bc5df
zhengshouren
提交服务器初始代码
|
16
|
self.ignoreHeartbeat = false
|
0a07bdd9
zhouahaihai
角色升级 。gm
|
17
|
self.heros = {}
|
314bc5df
zhengshouren
提交服务器初始代码
|
18
19
20
|
end
Role.schema = {
|
314bc5df
zhengshouren
提交服务器初始代码
|
21
22
|
id = {"number"},
uid = {"string", ""},
|
314bc5df
zhengshouren
提交服务器初始代码
|
23
|
name = {"string", ""},
|
be83d162
zhouahaihai
登陆成功。 增加数据结构修正功能
|
24
25
26
27
|
sid = {"number", 0},
device = {"string", ""},
banTime = {"number", 0},
banType = {"number", 0},
|
0a07bdd9
zhouahaihai
角色升级 。gm
|
28
29
30
31
|
ltime = {"number", 0}, -- 最后登录时间
ctime = {"number", skynet.timex()}, -- 创建时间
ignoreMt = {"number", 0}, -- 忽略维护拦截
sversion = {"number", globalCsv.StructVersion or 0}, -- 重整数据版本
|
be83d162
zhouahaihai
登陆成功。 增加数据结构修正功能
|
32
33
34
35
36
|
-- roleInfo
level = {"number", 0},
diamond = {"number", 0},
reDiamond = {"number", 0},
|
6947e382
zhouahaihai
好感度, 皮肤
|
37
38
|
items = {"string", ""},
loveStatus = {"string", ""}, --统计角色的最高 好感度等级 类型相关 -- type=loveL type=loveL
|
314bc5df
zhengshouren
提交服务器初始代码
|
39
|
|
23d89d13
zhouahaihai
冒险 结构
|
40
41
42
|
--冒险相关
advPass = {"string", ""}, -- 通关记录
advInfo = {"table", {}}, -- 其他信息
|
9ad697c8
zhouahaihai
删除 fields ,增加数据库...
|
43
|
|
314bc5df
zhengshouren
提交服务器初始代码
|
44
45
|
}
|
be83d162
zhouahaihai
登陆成功。 增加数据结构修正功能
|
46
|
|
0a07bdd9
zhouahaihai
角色升级 。gm
|
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
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 {}
|
23d89d13
zhouahaihai
冒险 结构
|
62
|
if not self.schema[params.field] then return end
|
0a07bdd9
zhouahaihai
角色升级 。gm
|
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
|
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
|
23d89d13
zhouahaihai
冒险 结构
|
92
|
-- 某些字段 更新改变量 改变量的定义由字段自身决定 {{type = ""}, }
|
6947e382
zhouahaihai
好感度, 皮肤
|
93
94
95
96
97
98
|
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,
|
23d89d13
zhouahaihai
冒险 结构
|
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
--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,
|
6947e382
zhouahaihai
好感度, 皮肤
|
122
|
}
|
0a07bdd9
zhouahaihai
角色升级 。gm
|
123
|
|
6947e382
zhouahaihai
好感度, 皮肤
|
124
125
126
127
128
|
local updates = {}
for _, one in ipairs(params) do
if changeUpdateFunc[one["type"]] then
table.insert(updates, changeUpdateFunc[one["type"]](one))
else
|
23d89d13
zhouahaihai
冒险 结构
|
129
|
table.insert(updates, changeUpdateFunc["tableCommon"](one["type"], one))
|
6947e382
zhouahaihai
好感度, 皮肤
|
130
131
132
133
134
135
|
end
end
if not notNotify and next(updates) then
SendPacket(actionCodes.Role_changeUpdate, MsgPack.pack(updates))
end
end
|
be83d162
zhouahaihai
登陆成功。 增加数据结构修正功能
|
136
|
|
314bc5df
zhengshouren
提交服务器初始代码
|
137
138
139
|
function Role:data()
return {
id = self:getProperty("id"),
|
be83d162
zhouahaihai
登陆成功。 增加数据结构修正功能
|
140
141
142
143
144
|
name = self:getProperty("name"),
level = self:getProperty("level"),
diamond = self:getProperty("diamond"),
reDiamond = self:getProperty("reDiamond"),
items = self:getProperty("items"):toNumMap(),
|
6947e382
zhouahaihai
好感度, 皮肤
|
145
|
loveStatus = self:getProperty("loveStatus"):toNumMap(),
|
23d89d13
zhouahaihai
冒险 结构
|
146
147
|
advPass = self:getProperty("advPass"),
advInfo = self:getProperty("advInfo"),
|
314bc5df
zhengshouren
提交服务器初始代码
|
148
149
150
151
|
}
end
return Role
|