Blame view

src/models/Role.lua 5.76 KB
314bc5df   zhengshouren   提交服务器初始代码
1
2
  local Role = class("Role", require("shared.ModelBase"))
  
be83d162   zhouahaihai   登陆成功。 增加数据结构修正功能
3
4
  local RolePlugin = import(".RolePlugin")
  local RoleTask = import(".RoleTask")
be83d162   zhouahaihai   登陆成功。 增加数据结构修正功能
5
6
7
8
  local RoleActivity = import(".RoleActivity")
  local RoleChangeStruct = import(".RoleChangeStruct")
  RolePlugin.bind(Role)
  RoleTask.bind(Role)
be83d162   zhouahaihai   登陆成功。 增加数据结构修正功能
9
10
11
  RoleActivity.bind(Role)
  RoleChangeStruct.bind(Role)
  
314bc5df   zhengshouren   提交服务器初始代码
12
13
  function Role:ctor( properties )
  	Role.super.ctor(self, properties)
314bc5df   zhengshouren   提交服务器初始代码
14
  	self.ignoreHeartbeat = false
0a07bdd9   zhouahaihai   角色升级 。gm
15
  	self.heros = {}
43cc5f51   gaofengduan   调整 equip 数据结构
16
  	self.runeBag = {}
46fac6f1   zhouahaihai   酱料
17
  	self.advData = nil
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}, -- 重整数据版本
312b9db5   zhouahaihai   背包
32
33
  	diamond				= {"number", 0},
  	reDiamond			= {"number", 0},
be83d162   zhouahaihai   登陆成功。 增加数据结构修正功能
34
  	-- roleInfo
4b7c7c96   zhouahaihai   增加 清空 挂机 冒险gm 角色经验
35
36
  	level 				= {"number", 1},
  	exp 				= {"number", 0},
6947e382   zhouahaihai   好感度, 皮肤
37
38
  	items				= {"string", ""},
  	loveStatus			= {"string", ""}, --统计角色的最高 好感度等级 类型相关 -- type=loveL type=loveL
37037eeb   zhengshouren   计算奖励
39
  	crown				= {"number", 0},	-- 看伴娘
314bc5df   zhengshouren   提交服务器初始代码
40
  
312b9db5   zhouahaihai   背包
41
42
  	bagLimit 			= {"table", globalCsv.store_limit_max},
  
23d89d13   zhouahaihai   冒险 结构
43
44
  	--冒险相关
  	advPass				= {"string", ""}, -- 通关记录
46fac6f1   zhouahaihai   酱料
45
46
47
  	advItems			= {"string", ""}, -- 冒险临时背包
  	advInfo				= {"table", {}}, -- 冒险关卡信息
  	advTeam				= {"table", {}}, -- 冒险玩家队伍信息
9ad697c8   zhouahaihai   删除 fields ,增加数据库...
48
  
384bb077   zhouahaihai   挂机
49
50
51
52
53
  	--挂机相关
  	hangPass 			= {"table", {}}, -- 挂机通过的最大关卡
  	hangTeam 			= {"table", {}}, -- 挂机队伍
  	hangInfo			= {"table", {}},  -- 当前挂机信息
  	hangBag				= {"table", {}},	-- 背包
9962b061   zhouahaihai   补充 挂机
54
  	hangBagLimit 		= {"number", globalCsv.idle_field_origin}, --背包上限
384bb077   zhouahaihai   挂机
55
  
dbd0ca58   gaofengduan   car  营养剂制作
56
  	potionBag			= {"table", {}},	-- 营养剂背包
00e663bd   zhouhaihai   剧情相关
57
58
  
  	storyB				= {"table", {}}, -- 剧情记录
056c01a0   zhouhaihai   简化装备
59
60
  
  	equips				= {"table", {}}, -- 装备简化下, 目前的设计足够支撑   -- {t = {l = c}}  -- 接口设计好 底层扩展就重写~
9b35bf6e   zhouhaihai   开启时间箱
61
62
  
  	boxL				= {"table", {}}, -- boxList  正开启的箱子  -- {[1] = {id = 1010, gem = 101, time = 1313}}
314bc5df   zhengshouren   提交服务器初始代码
63
64
  }
  
be83d162   zhouahaihai   登陆成功。 增加数据结构修正功能
65
  
0a07bdd9   zhouahaihai   角色升级 。gm
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  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   冒险 结构
81
  	if not self.schema[params.field] then return end
0a07bdd9   zhouahaihai   角色升级 。gm
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
  	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   冒险 结构
111
  -- 某些字段 更新改变量 改变量的定义由字段自身决定 {{type = ""}, }
6947e382   zhouahaihai   好感度, 皮肤
112
113
114
115
116
117
  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   冒险 结构
118
119
120
121
122
123
  		--table 类型通用更新
  		["tableCommon"] = function(fieldType, info)
  			if self.class.schema[fieldType][1] ~= "table" then
  				error("[ERROR:] need handler for changeUpdate, field : " .. fieldType)
  				return
  			end
dbd0ca58   gaofengduan   car  营养剂制作
124
  			--支持多深度单字段
23d89d13   zhouahaihai   冒险 结构
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
  			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,
00e663bd   zhouhaihai   剧情相关
141
142
143
  		["onlyToC"] = function(info)
  			return info
  		end,
6947e382   zhouahaihai   好感度, 皮肤
144
  	}
0a07bdd9   zhouahaihai   角色升级 。gm
145
  
6947e382   zhouahaihai   好感度, 皮肤
146
147
148
149
  	local updates = {}
  	for _, one in ipairs(params) do
  		if changeUpdateFunc[one["type"]] then
  			table.insert(updates, changeUpdateFunc[one["type"]](one))
00e663bd   zhouhaihai   剧情相关
150
151
152
  		elseif one.isOnlyToC then
  			one.isOnlyToC = nil
  			table.insert(updates, one)
6947e382   zhouahaihai   好感度, 皮肤
153
  		else
23d89d13   zhouahaihai   冒险 结构
154
  			table.insert(updates, changeUpdateFunc["tableCommon"](one["type"], one))
6947e382   zhouahaihai   好感度, 皮肤
155
156
157
158
159
160
  		end
  	end
  	if not notNotify and next(updates) then
  		SendPacket(actionCodes.Role_changeUpdate, MsgPack.pack(updates))
  	end
  end
be83d162   zhouahaihai   登陆成功。 增加数据结构修正功能
161
  
314bc5df   zhengshouren   提交服务器初始代码
162
163
164
  function Role:data()
  	return {
  		id = self:getProperty("id"),
be83d162   zhouahaihai   登陆成功。 增加数据结构修正功能
165
166
  		name = self:getProperty("name"),
  		level = self:getProperty("level"),
4b7c7c96   zhouahaihai   增加 清空 挂机 冒险gm 角色经验
167
  		exp = self:getProperty("exp"),
be83d162   zhouahaihai   登陆成功。 增加数据结构修正功能
168
  		items = self:getProperty("items"):toNumMap(),
6947e382   zhouahaihai   好感度, 皮肤
169
  		loveStatus = self:getProperty("loveStatus"):toNumMap(),
312b9db5   zhouahaihai   背包
170
171
  		diamond = self:getAllDiamond(),
  		bagLimit = self:getProperty("bagLimit"),
dbd0ca58   gaofengduan   car  营养剂制作
172
  
23d89d13   zhouahaihai   冒险 结构
173
174
  		advPass = self:getProperty("advPass"),
  		advInfo = self:getProperty("advInfo"),
46fac6f1   zhouahaihai   酱料
175
  		advItems = self:getProperty("advItems"):toNumMap(),
36c30c5c   zhouahaihai   冒险
176
  		advTeam = self:getProperty("advTeam"),
384bb077   zhouahaihai   挂机
177
178
179
180
181
182
  
  		hangPass = self:getProperty("hangPass"),
  		hangTeam = self:getProperty("hangTeam"),
  		hangInfo = self:getProperty("hangInfo"),
  		hangBag = self:getProperty("hangBag"),
  		hangBagLimit = self:getProperty("hangBagLimit"),
dbd0ca58   gaofengduan   car  营养剂制作
183
184
  
  		potionBag = self:getProperty("potionBag"),
1c3053c3   zhouhaihai   返回数据
185
  		storyB = self:getProperty("storyB"),
056c01a0   zhouhaihai   简化装备
186
  		equips = self:getProperty("equips"),
9b35bf6e   zhouhaihai   开启时间箱
187
  		boxL = self:getProperty("boxL"),
056c01a0   zhouhaihai   简化装备
188
  
314bc5df   zhengshouren   提交服务器初始代码
189
190
191
192
  	}
  end
  
  return Role