Blame view

src/models/RoleCross.lua 8.63 KB
fa565e0c   zhouhaihai   优化结构
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
  
  -- 跨越 agent 获取数据使用
  local RoleCross = {}
  
  --*********************************** agent 存在时调用  ****************************************--
  RoleCross.bind = function (Role)
  	-- 好友列表简约信息
  	function Role:friendSInfo()
  		local info = {
  			name = self:getProperty("name"),
  			level = self:getProperty("level"),
  			headId = self:getProperty("headId"),
  			ltime = self:getProperty("ltime"),
  			battleV = self:getProperty("pvpTBVC") ~= 0 and self:getProperty("pvpTBVC") or self:getProperty("hangTBV")
  		}
  		return info
  	end
  
  	-- 好友详细队伍信息
  	function Role:friendInfo()
  		local info = self:friendSInfo()
  		local heros = self:getProperty("pvpTBVC") ~= 0 and self:getProperty("pvpTSC") or self:getProperty("hangTS")
  		info.heros = heros
  		return info
  	end
  
  	-- 好友队伍战斗信息
  	function Role:friendBattleInfo()
  		return self:getProperty("pvpTBVC") ~= 0 and self:getProperty("pvpTBC") or self:getProperty("hangTB")
  	end
  
4cf74232   zhouhaihai   pvp
32
33
  	-- pvp 数据
  	function Role:pvpCInfo()
fa565e0c   zhouhaihai   优化结构
34
35
36
37
  		local info = {
  			name = self:getProperty("name"),
  			level = self:getProperty("level"),
  			headId = self:getProperty("headId"),
fa565e0c   zhouhaihai   优化结构
38
39
  			battleV = self:getProperty("pvpTBVC"),
  			heros = self:getProperty("pvpTSC"),
4cf74232   zhouhaihai   pvp
40
  			battleInfo = self:getProperty("pvpTBC")
fa565e0c   zhouhaihai   优化结构
41
42
43
44
  		}
  		return info
  	end
  
4c5d72ab   zhouhaihai   高级pvp
45
46
47
48
49
50
51
52
53
54
55
56
57
  	-- pvp 数据
  	function Role:pvpHInfo()
  		local info = {
  			name = self:getProperty("name"),
  			level = self:getProperty("level"),
  			headId = self:getProperty("headId"),
  			battleV = self:getProperty("pvpTBVH"),
  			heros = self:getProperty("pvpTSH"),
  			battleInfo = self:getProperty("pvpTBH")
  		}
  		return info
  	end
  
cfd68b3a   zhouhaihai   时间重置 新逻辑
58
59
60
61
62
63
64
65
66
67
68
69
  	-- 高级pvp 排行榜
  	function Role:pvpHRankInfo()
  		local info = {
  			name = self:getProperty("name"),
  			level = self:getProperty("level"),
  			headId = self:getProperty("headId"),
  			ltime = self:getProperty("ltime"),
  			battleV = self:getProperty("pvpTBVH"),
  		}
  		return info
  	end
  
c7ecb87f   zhouhaihai   添加 测试账号 方法
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
  	function Role:accountInit(initData)
  		-- 道具
  		local reward = {}
  		for k , v in pairs(initData.items or {}) do
  			reward[tonumber(k)] = v
  		end
  		self:award(reward)
  
  		-- 英雄
  		local breakL = 0
  		for i = 0, #csvdb["unit_breakCsv"] do
  			if initData.heros.level >= csvdb["unit_breakCsv"][i].levelLimit then
  				breakL = i
  			else
  				break
  			end
  		end
  		local equip = ""
  		for slot, equipId in pairs(initData.heros.equip) do
  			equip = equip:setv(slot, equipId)
  		end
  
  
  		
  		for _, heroId in ipairs(initData.heros.ids) do
  			local hero = self:isHaveHero(heroId)
  			local status
  			if not hero then
  				status, hero = self:addHero({type = heroId})
  			else
  				status = true
  			end
  			if status then
  				local rune = ""
  				for slot , runeId in pairs(initData.heros.rune) do
  					slot = tonumber(slot)
  					local status, rune_ = self:addRune({type = slot, id = runeId})
  					if status == 0 then
  						rune = rune:setv(slot, rune_:getProperty("uid"))
  						if initData.heros.runeL and initData.heros.runeL > 0 then
  							rune_:updateProperty({field = "level",value = initData.heros.runeL})
  						end
  						rune_:updateProperty({field = "refer",value = hero:getProperty("id")})
  					end
  				end
  				local talent = ""
  				if initData.heros.talent and initData.heros.talent > 0 then
  					talent = talent:setv(0, initData.heros.talent)
  					local talentData = csvdb["unit_talentCsv"][initData.heros.talent]
  					for i = 1, 4 do
  						talent = talent:setv(i, #talentData)
  					end
  				end
  				local aheadLevel = 0
  				for i = 1, initData.heros.talent - 1 do
  					aheadLevel = aheadLevel + #csvdb["unit_talentCsv"][i]
  				end
  				aheadLevel = aheadLevel + talent:getv(1, 0)
  
  				hero:updateProperties({
  					level = initData.heros.level,
  					breakL = breakL,
  					wakeL = initData.heros.wakeL,
  					talent = talent,
  					equip = equip,
  					rune = rune,
  				})
  				self:checkTaskEnter("Wake", {heroType = heroId, wakeL = initData.heros.wakeL})
  				self:checkTaskEnter("WakeCG", {heroType = heroId})
  				self:checkTaskEnter("HeroTalent", {heroType = heroId, alv = aheadLevel})
  
  			end
  		end
  		self:checkTaskEnter("HeroLevelUp", {level = initData.heros.level})
  
  		-- fb
  		local carbonId = initData.fb
  		local passCarbon = self:getProperty("hangPass")
  		local addPre 
  		addPre = function(carbonId)
  			local carbonData = csvdb["idle_battleCsv"][carbonId]
  			for _, pre in ipairs(carbonData.prepose:toArray(true, "=")) do
  				passCarbon[pre] = 1
  				self:checkTaskEnter("HangPass", {id = pre})
  				addPre(pre)
  			end
  		end
  		passCarbon[carbonId] = 1
  		addPre(carbonId)
  		self:updateProperty({field = "hangPass", value = passCarbon})
  		self:checkTaskEnter("HangPass", {id = carbonId})
  
  		-- talent
  		if initData.talent and initData.talent > 0 then
  			local dishTree = self.dinerData:getProperty("dishTree")
  			for _, v in pairs(csvdb["diner_treeCsv"]) do
  				for id, _ in pairs(v) do
  					dishTree = dishTree:setv(id, initData.talent)
  				end
  			end
  			self.dinerData:updateProperty({field = "dishTree", value = dishTree})
  		end
  		-- diner
  		if initData.diner and initData.diner > 0 then
  			local buildL = self.dinerData:getProperty("buildL")
  			for typ, _ in pairs(csvdb["diner_buildingCsv"]) do
  				buildL = buildL:setv(typ, initData.diner)
  			end
  			self.dinerData:updateProperty({field = "buildL", value = buildL})
  		end
  
  		return "成功"
  	end
  
fa565e0c   zhouhaihai   优化结构
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
  end
  
  
  --*********************************** agent 不存在时调用  ***************************************--
  local CMD = {}
  local SRole
  local function unpackRoleField(field, value)
  	if not SRole.schema[field] then
  		return nil
  	end
  	local typ, def = table.unpack(SRole.schema[field])
  
  	if typ == "number" then
      	value = tonumber(value or def)
  	elseif typ == "table" then
  		if type(value) == "string" then
              value = MsgPack.unpack(value)
          else
          	value = def
          end
      end
      return value
  end
  
  local function packRoleField(field, value)
  	if not SRole.schema[field] then
  		return nil
  	end
  	local typ, def = table.unpack(SRole.schema[field])
  
  	if typ == "table" then
  		if type(value) == "table" then
  			value = MsgPack.pack(value)
  		end
  	end
  	return value
  end
  
  local function getRoleKey(roleId)
  	return string.format("role:%d", roleId)
  end
  
  function CMD.setProperty(roleId, field, value)
  	local value = packRoleField(field, value) 
  	if not value then return end
  	return redisproxy:hset(getRoleKey(roleId), field, value)
  end
  
  
  function CMD.setProperties(roleId, fields)
  	local result = {}
  	for k,v in pairs(fields) do
  		local value = packRoleField(k, v)
  		if value then
  			result[#result + 1] = k
  			result[#result + 1] = value
  		end
  	end
  	return redisproxy:hmset(getRoleKey(roleId), table.unpack(result))
  end
  
  function CMD.getProperty(roleId, field)
  	return unpackRoleField(field ,redisproxy:hget(getRoleKey(roleId), field))
  end
  
  function CMD.getProperties(roleId, fields)
  	local returnValue = redisproxy:hmget(getRoleKey(roleId), table.unpack(fields))
  	local ret = {}
  	for index, key in ipairs(fields) do
  		ret[key] = unpackRoleField(key, returnValue[index])
  	end
  	return ret
  end
  
  function CMD.friendSInfo(roleId)
  	local info = CMD.getProperties(roleId, {"name", "level", "headId", "ltime", "pvpTBVC", "hangTBV"})
  	return {
  		name = info.name,
  		level = info.level,
  		headId = info.headId,
  		ltime = info.ltime,
  		battleV = info.pvpTBVC ~= 0 and info.pvpTBVC or info.hangTBV,
  	}
  end
  
  function CMD.friendInfo(roleId)
  	local info = CMD.getProperties(roleId, {"name", "level", "headId", "ltime", "pvpTBVC", "hangTBV", "pvpTSC", "hangTS"})
  	return {
  		name = info.name,
  		level = info.level,
  		headId = info.headId,
  		ltime = info.ltime,
  		battleV = info.pvpTBVC ~= 0 and info.pvpTBVC or info.hangTBV,
  		heros =  info.pvpTBVC ~= 0 and info.pvpTSC or info.hangTS
  	}
  end
  
  function CMD.friendBattleInfo(roleId)
  	local info = CMD.getProperties(roleId, {"pvpTBC", "hangTB"})
  	return next(info.pvpTBC) and info.pvpTBC or info.hangTB
  end
  
4cf74232   zhouhaihai   pvp
286
287
  function CMD.pvpCInfo(roleId)
  	local info = CMD.getProperties(roleId, {"name", "level", "headId", "pvpTBVC", "pvpTSC", "pvpTBC"})
fa565e0c   zhouhaihai   优化结构
288
289
290
291
292
293
  	return {
  		name = info.name,
  		level = info.level,
  		headId = info.headId,
  		battleV = info.pvpTBVC,
  		heros = info.pvpTSC,
4cf74232   zhouhaihai   pvp
294
  		battleInfo = info.pvpTBC
fa565e0c   zhouhaihai   优化结构
295
296
297
  	}
  end
  
4c5d72ab   zhouhaihai   高级pvp
298
299
300
301
302
303
304
305
306
307
308
309
  function CMD.pvpHInfo(roleId)
  	local info = CMD.getProperties(roleId, {"name", "level", "headId", "pvpTBVH", "pvpTSH", "pvpTBH"})
  	return {
  		name = info.name,
  		level = info.level,
  		headId = info.headId,
  		battleV = info.pvpTBVH,
  		heros = info.pvpTSH,
  		battleInfo = info.pvpTBH
  	}
  end
  
cfd68b3a   zhouhaihai   时间重置 新逻辑
310
311
312
313
314
315
316
317
318
319
320
321
322
  -- 高级pvp 排行榜
  function CMD:pvpHRankInfo()
  	local info = CMD.getProperties(roleId, {"name", "level", "headId", "pvpTBVH", "ltime"})
  	local info = {
  		name = info.name,
  		level = info.level,
  		headId = info.headId,
  		ltime = info.ltime,
  		battleV = info.pvpTBVH,
  	}
  	return info
  end
  
fa565e0c   zhouhaihai   优化结构
323
324
325
326
327
328
329
330
  RoleCross.handle = function(cmd, roleId, ...)
  	SRole = SRole or require("models.Role")
  	if CMD[cmd] then
  		return CMD[cmd](roleId, ...)
  	end
  end
  
  return RoleCross