Blame view

src/actions/HeroAction.lua 35.2 KB
0a07bdd9   zhouahaihai   角色升级 。gm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  local ipairs = ipairs
  local table = table
  local math = math
  local next = next
  local string = string
  local redisproxy = redisproxy
  local MsgPack = MsgPack
  local getRandomName = getRandomName
  local mcast_util = mcast_util
  local string_format = string.format
  local tonumber = tonumber
  local require = require
  local table_insert = table.insert
  local tconcat = table.concat
be9c9ca6   zhouahaihai   角色评论
15
  local table_unpack = table.unpack
0a07bdd9   zhouahaihai   角色升级 。gm
16
17
  
  local _M = {}
058a0cbb   zhouhaihai   抽卡
18
  
0a07bdd9   zhouahaihai   角色升级 。gm
19
20
21
  function _M.levelUpRpc( agent, data )
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
36482c8b   zhouhaihai   回收养成
22
  
0a07bdd9   zhouahaihai   角色升级 。gm
23
  	local hero = role.heros[msg.id]
1c35c4cf   gaofengduan   fix hero awake
24
  	if not hero then return 1 end
0a07bdd9   zhouahaihai   角色升级 。gm
25
  
1c35c4cf   gaofengduan   fix hero awake
26
  	if hero:getProperty("level") >= hero:getMaxLevel() then return 2 end
8c74292c   zhouahaihai   增加item 以及 角色突破
27
  	local curData = csvdb["unit_expCsv"][hero:getProperty("level")]
997cbdfe   zhouahaihai   技能养成
28
  	local cost = {[ItemId.Exp] = curData.exp, [ItemId.Gold] = curData.gold}
1c35c4cf   gaofengduan   fix hero awake
29
  	if not role:checkItemEnough(cost) then return 3 end
3133cb76   zhouhaihai   日志
30
  	role:costItems(cost, {log = {desc = "heroLevelUp", int1 = msg.id, int2 = hero:getProperty("type")}})
0a07bdd9   zhouahaihai   角色升级 。gm
31
  	hero:updateProperty({field = "level", delta = 1})
1c35c4cf   gaofengduan   fix hero awake
32
  
3133cb76   zhouhaihai   日志
33
34
  	hero:log({desc = "levelUp", int1 = hero:getProperty("level")})
  
1e9cb217   chenyueqi   服务器记录控制引导过程
35
36
37
38
  	if hero:getProperty("type") == 103 then
  		role:finishGuide(7)
  	end
  
53e8037e   zhouhaihai   任务
39
  	role:checkTaskEnter("HeroLevelUp", {level = hero:getProperty("level")})
0a07bdd9   zhouahaihai   角色升级 。gm
40
41
42
43
  	SendPacket(actionCodes.Hero_levelUpRpc, '')
  	return true
  end
  
8c74292c   zhouahaihai   增加item 以及 角色突破
44
45
46
47
  function _M.breakRpc( agent, data )
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local hero = role.heros[msg.id]
1c35c4cf   gaofengduan   fix hero awake
48
  	if not hero then return 1 end
8c74292c   zhouahaihai   增加item 以及 角色突破
49
  
1c35c4cf   gaofengduan   fix hero awake
50
51
  	if hero:getProperty("level") < hero:getMaxLevel() then return 2 end
  	if hero:getProperty("breakL") >= #csvdb["unit_breakCsv"] then return 3 end
8c74292c   zhouahaihai   增加item 以及 角色突破
52
  	local curData = csvdb["unit_breakCsv"][hero:getProperty("breakL")]
997cbdfe   zhouahaihai   技能养成
53
  	local cost = {[ItemId.BreakCost] = curData.cost, [ItemId.Gold] = curData.gold}
1c35c4cf   gaofengduan   fix hero awake
54
  	if not role:checkItemEnough(cost) then return 4 end
3133cb76   zhouhaihai   日志
55
  	role:costItems(cost, {log = {desc = "heroBreak", int1 = msg.id, int2 = hero:getProperty("type")}})
8c74292c   zhouahaihai   增加item 以及 角色突破
56
  	hero:updateProperty({field = "breakL", delta = 1})
1c35c4cf   gaofengduan   fix hero awake
57
  
3133cb76   zhouhaihai   日志
58
59
  	hero:log({desc = "break", int1 = hero:getProperty("breakL")})
  
8c74292c   zhouahaihai   增加item 以及 角色突破
60
61
62
  	SendPacket(actionCodes.Hero_breakRpc, '')
  	return true
  end
0a07bdd9   zhouahaihai   角色升级 。gm
63
  
997cbdfe   zhouahaihai   技能养成
64
65
66
67
  function _M.wakeRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local hero = role.heros[msg.id]
1c35c4cf   gaofengduan   fix hero awake
68
69
70
71
72
  	if not hero then return 1 end
  	if hero:getProperty("wakeL") >= #csvdb["unit_wakeCsv"] then return 2 end
  	local typ = hero:getProperty("type")
  	local wakeData = csvdb["unit_wakeCsv"][hero:getProperty("wakeL")]
  	if not wakeData then return 3 end
15cba0bf   zhouhaihai   修改天赋升级消耗
73
74
  	local costMaterial = wakeData.costMaterial:toArray(true,"=")
  	local cost = {[typ] = wakeData.costFigment,[globalCsv.unit_wake_cost[hero:getCamp()][costMaterial[1]]] = costMaterial[2]}
1c35c4cf   gaofengduan   fix hero awake
75
76
  	if not role:checkItemEnough(cost) then
  		return 4
997cbdfe   zhouahaihai   技能养成
77
  	end
1c35c4cf   gaofengduan   fix hero awake
78
  
3133cb76   zhouhaihai   日志
79
  	role:costItems(cost, {log = {desc = "heroWake", int1 = msg.id, int2 = hero:getProperty("type")}})
0889982f   zhouhaihai   优化角色技能等级
80
  
997cbdfe   zhouahaihai   技能养成
81
82
  	hero:updateProperty({field = "wakeL", delta = 1})
  
53e8037e   zhouhaihai   任务
83
  	local curLevel = hero:getProperty("wakeL")
f6a9215f   zhouhaihai   觉醒 误删了 任务
84
  	role:checkTaskEnter("Wake", {heroType = typ, wakeL = curLevel})
53e8037e   zhouhaihai   任务
85
86
87
  	if curLevel == 4 then -- 解锁cg
  		role:checkTaskEnter("WakeCG", {heroType = typ})
  	end
3133cb76   zhouhaihai   日志
88
89
  	hero:log({desc = "wake", int1 = hero:getProperty("wakeL")})
  
53e8037e   zhouhaihai   任务
90
  	
997cbdfe   zhouahaihai   技能养成
91
92
93
94
  	SendPacket(actionCodes.Hero_wakeRpc, '')
  	return true
  end
  
997cbdfe   zhouahaihai   技能养成
95
96
97
98
99
  
  function _M.talentRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local hero = role.heros[msg.id]
b57f0bae   gaofengduan   fix hero talent
100
  	if not hero then return 1 end
997cbdfe   zhouahaihai   技能养成
101
102
  
  	local index = msg.index -- 第几个天赋
6fc397d6   zhouhaihai   角色新突破 冒险优化点击地块
103
  	local need = {[0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1}
b57f0bae   gaofengduan   fix hero talent
104
  	if not need[index] then return 2 end
997cbdfe   zhouahaihai   技能养成
105
  
04258e10   zhouhaihai   天赋bug
106
  	local talent = hero:getProperty("talent")
997cbdfe   zhouahaihai   技能养成
107
  	local curStage = talent:getv(0, 1)
1c35c4cf   gaofengduan   fix hero awake
108
  	local curData = csvdb["unit_talentCsv"][curStage]
b57f0bae   gaofengduan   fix hero talent
109
  	if not curData then return 4 end
997cbdfe   zhouahaihai   技能养成
110
  
6fc397d6   zhouhaihai   角色新突破 冒险优化点击地块
111
  	if index == 0 then
6fc397d6   zhouhaihai   角色新突破 冒险优化点击地块
112
113
  		--是否进阶
  		local max = true
997cbdfe   zhouahaihai   技能养成
114
  		for i = 1, 4 do
6fc397d6   zhouhaihai   角色新突破 冒险优化点击地块
115
116
117
118
  			if talent:getv(i, 0) < #curData then
  				max = false
  				break
  			end
997cbdfe   zhouahaihai   技能养成
119
  		end
6fc397d6   zhouhaihai   角色新突破 冒险优化点击地块
120
121
122
123
124
125
  		if max then
  			talent = talent:setv(0, curStage + 1)
  			for i = 1, 4 do
  				talent = talent:setv(i, 0)
  			end
  		else
cbc6973f   zhouhaihai   天赋bug 日志调整
126
  			return 12
6fc397d6   zhouhaihai   角色新突破 冒险优化点击地块
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
  		end
  	else
  		
  		local level = talent:getv(index, 0)
  		if level >= #curData then return 5 end
  
  		local talentData = curData[level]
  		if not talentData then return end
  
  		if talentData.lvRequire > hero:getProperty("level") then return 6 end
  
  		local cost = talentData.money:toNumMap()
  		local cost2 = talentData.cost:toNumMap()
  		for k,v in pairs(cost2) do
  			cost[globalCsv.unit_talent_cost[csvdb["unitCsv"][hero:getProperty("type")].camp][k]] = v
  		end
  		if not role:checkItemEnough(cost) then return 6 end
  		role:costItems(cost, {log = {desc = "heroTalent", int1 = msg.id, int2 = hero:getProperty("type")}})
  		talent = talent:incrv(index, 1)
  
  
  		local aheadLevel = 0
  		for i = 1, talent:getv(0, 1) - 1 do
  			aheadLevel = aheadLevel + #csvdb["unit_talentCsv"][i]
  		end
  		aheadLevel = aheadLevel + talent:getv(index, 0)
  
  		role:checkTaskEnter("HeroTalent", {heroType = hero:getProperty("type"), alv = aheadLevel})
997cbdfe   zhouahaihai   技能养成
155
  	end
53e8037e   zhouhaihai   任务
156
  
6fc397d6   zhouhaihai   角色新突破 冒险优化点击地块
157
  	hero:updateProperty({field = "talent", value = talent})
53e8037e   zhouhaihai   任务
158
  
3133cb76   zhouhaihai   日志
159
160
  	hero:log({desc = "talent", int1 = index, int2 = talent:getv(index, 0)})
  
997cbdfe   zhouahaihai   技能养成
161
162
163
164
  	SendPacket(actionCodes.Hero_talentRpc, '')
  	return true
  end
  
6fc397d6   zhouhaihai   角色新突破 冒险优化点击地块
165
  
be9c9ca6   zhouahaihai   角色评论
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
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
  -- 暂时没有这个功能
  function _M.likeHeroRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local heroType = msg.type
  	local result = {status = 0}
  	local isLike = false
  	local hadLike = role:getProperty("likeHero"):toArray(true, "=")
  	for _, v in pairs(hadLike) do
  		if v == heroType then
  			isLike = true
  			break
  		end
  	end
  	if isLike then
  		result.status = 1
  	else
  		redisproxy:hincrby("hero:like", "hero:"..heroType, 1)
  		table.insert(hadLike, heroType)
  		role:setProperty("likeHero", table.concat(hadLike, "="))
  	end
  
  	SendPacket(actionCodes.Hero_likeHeroRpc, MsgPack.pack(result))
  	return true
  end
  local RankLikeNum = 5 --热度显示几个
  local TimeLikeNum = 95 -- 时间显示几个
  local function getCommentKey(heroType)
  	return {
  		commentListKey = string.format("list:%d:herocomments", heroType),
  		commentRankKey = string.format("rank:%d:herocomments", heroType),
  		commentKey = string.format("hero:%d:comments", heroType),
  	}
  end
  
  local function trimComment(heroType, commentId) -- 剪裁 CommentList
  	local commentKey = getCommentKey(heroType)
  	local redret = redisproxy:pipelining(function (red)
  		red:lpush(commentKey.commentListKey, commentId)
  		red:lrange(commentKey.commentListKey, TimeLikeNum,-1)
  		red:ltrim(commentKey.commentListKey, 0, TimeLikeNum - 1)
  		red:zrevrange(commentKey.commentRankKey, 0, RankLikeNum - 1)
  	end)
  	local hots = {}
  	for _, hot in pairs(redret[4]) do
  		hots[hot] = 1
  	end
  	redisproxy:pipelining(function (red)
  		local needDel = {}
  		for _, tempId in pairs(redret[2]) do
  			if not hots[tempId] then
  				table.insert(needDel, tempId)
  			end
  		end
  		if #needDel > 0 then
  			red:zrem(commentKey.commentRankKey, table_unpack(needDel))
  			red:hdel(commentKey.commentKey, table_unpack(needDel))
  		end
  	end)
  end
  
  
  function _M.commentHeroRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local heroType = msg.type
  	local content = msg.content
  
  	local result = {status = 0}  -- status 0 成功  1 已经评论过了
  	local curStutus = role.dailyData:getProperty("commentHero")
  	if curStutus:getv(heroType, 0) ~= 0 then
  		result.status = 1
  	else
  		local commentKey = getCommentKey(heroType)
3c0ea5fb   zhouhaihai   抽英雄
240
  		local SERV = string.format(".chated%d", math.random(1, 5))
be9c9ca6   zhouahaihai   角色评论
241
242
243
244
245
246
  		local legal, mod = skynet.call(SERV, "lua", "check", content)
  		if not legal then
  			content = mod or ""
  		end
  		local commentId = tostring(redisproxy:hincrby("hero:comment:autoincr", "hero:" .. heroType, 1))
  		local comment = {
1c35c4cf   gaofengduan   fix hero awake
247
  			commentId = commentId,
be9c9ca6   zhouahaihai   角色评论
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
  			content = content,
  			roleId = role:getProperty("id"),
  			name = role:getProperty("name"),
  			-- time = skynet.timex()
  		}
  		redisproxy:hset(commentKey.commentKey, commentId, json.encode(comment))
  		trimComment(heroType, commentId)
  
  		comment.like = 0
  		result.comment = comment
  		role.dailyData:setProperty("commentHero", curStutus:setv(heroType, 1))
  	end
  	SendPacket(actionCodes.Hero_commentHeroRpc, MsgPack.pack(result))
  	return true
  end
  
  function _M.getCommentsRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local heroType = msg.type
  	local list = {}  -- 评论列表
  	local commentKey = getCommentKey(heroType)
  	local commentRoleKey = string.format("comment:%d:like", role:getProperty("id"))
  	local redret = redisproxy:pipelining(function (red)
  		red:lrange(commentKey.commentListKey, 0,TimeLikeNum - 1)
  		red:zrevrange(commentKey.commentRankKey, 0, -1, "WITHSCORES") --热门
  		red:hget("hero:like", "hero:"..heroType)
  		red:lrange(commentRoleKey, 0, 999)
  	end)
  
  	local likeMap = {}
  	local idList = {}
  	local liked = {}
  	for i = 1, #redret[2], 2 do
  		likeMap[redret[2][i]] = redret[2][i + 1]
  		if i < RankLikeNum * 2 then
  			table.insert(idList, redret[2][i])
  		end
  	end
  	for i = 1, #redret[1] do
  		table.insert(idList, redret[1][i])
  	end
  	for i = 1, #redret[4] do
  		liked[redret[4][i]] = 1
  	end
  
  	local commentData = redisproxy:pipelining(function (red)
  		for _, commentId in ipairs(idList) do
  			red:hget(commentKey.commentKey, commentId)
  		end
  	end)
  	for _, commentS in ipairs(commentData or {}) do
  		local comment = json.decode(commentS)
  		comment.like = likeMap[tostring(comment.commentId)] or 0
  		comment.liked = liked[heroType .. ":" .. comment.commentId] or 0
  		table.insert(list, comment)
  	end
  	SendPacket(actionCodes.Hero_getCommentsRpc, MsgPack.pack({list = list, like = tonumber(redret[3] or 0)}))
  	return true
  end
  
  function _M.likeCommentRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local actType = msg.actType  -- 1 顶 2 踩
  	local heroType = msg.type
  	local commentId = msg.commentId  --评论id
  	local commentKey = getCommentKey(heroType)
  	local add = 0
  	if actType == 1 then
  		add = 1
  	elseif actType == 2 then
  		add = -1
  	else
1c35c4cf   gaofengduan   fix hero awake
322
  		return
be9c9ca6   zhouahaihai   角色评论
323
324
  	end
  
1c35c4cf   gaofengduan   fix hero awake
325
326
  	local result = {status = 0}
  	local commentIndex = heroType .. ":" .. commentId
be9c9ca6   zhouahaihai   角色评论
327
328
  	local commentRoleKey = string.format("comment:%d:like", role:getProperty("id"))
  	local redret = redisproxy:pipelining(function (red)
1c35c4cf   gaofengduan   fix hero awake
329
  		red:hexists(commentKey.commentKey, commentId)
be9c9ca6   zhouahaihai   角色评论
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
  		red:lrem(commentRoleKey, 1, commentIndex)
  		red:lpush(commentRoleKey, commentIndex)
  		red:ltrim(commentRoleKey, 0, 999)
  	end)
  	if (tonumber(redret[2]) or 0) > 0 then
  		result.status = 1
  	else
  		if redret[1] == 1 then-- 查不到也返回ture
  			local redret2 = redisproxy:pipelining(function (red)
  				red:zrevrange(commentKey.commentRankKey, 0, RankLikeNum - 1) --热门
  				red:zincrby(commentKey.commentRankKey, add, commentId)
  				red:zrevrange(commentKey.commentRankKey, 0, RankLikeNum - 1) --热门
  			end)
  			local out = {}
  			for _, v in pairs(redret2[1]) do
  				out[v] = 1
  			end
  			local new = {}
  			for _, v in pairs(redret2[3]) do
  				if out[v] then
  					out[v] = nil
  				else
  					new[v] = 1
  				end
  			end
  			for tempId, _ in pairs(out) do
  				trimComment(heroType, tempId)
  			end
  			redisproxy:pipelining(function (red)
  				for tempId, _ in pairs(new) do
  					red:lrem(commentKey.commentListKey, 0, tempId)
  				end
  			end)
  		end
  	end
  
  	SendPacket(actionCodes.Hero_likeCommentRpc, MsgPack.pack(result))
  	return true
  end
  
14f1591b   zhouhaihai   删除好感度相关
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
  -- function _M.loveItemRpc(agent, data)
  -- 	local role = agent.role
  -- 	local msg = MsgPack.unpack(data)
  -- 	local hero = role.heros[msg.heroId]
  -- 	if not hero then
  -- 		return
  -- 	end
  -- 	local curL = hero:getProperty("loveL")
  -- 	local curExp = hero:getProperty("loveExp")
  -- 	local curType = hero:getProperty("type")
  -- 	local curPlus = csvdb["unit_love_plusCsv"][curType]
  -- 	if not curPlus then
  -- 		return
  -- 	end
  -- 	if curL >= curPlus.limit then
  -- 		SendPacket(actionCodes.Hero_loveItemRpc, MsgPack.pack({errMsg = 1}))	--已满级
  -- 		return true
  -- 	end
  -- 	local curEffect = csvdb["unit_love_effectCsv"][curL]
  -- 	if not curEffect then
  -- 		return
  -- 	end
  -- 	if curExp >= curEffect.loveValue and not msg.bBreak then
  -- 		SendPacket(actionCodes.Hero_loveItemRpc, MsgPack.pack({errMsg = 2}))	--当前等级经验已满
  -- 		return true
  -- 	end
  
  -- 	if msg.bBreak then
  -- 		local cost = curEffect.cost:toArray(true, "=")
  -- 		if not role:checkItemEnough({[cost[1]] = cost[2]}) then
  -- 			SendPacket(actionCodes.Hero_loveItemRpc, MsgPack.pack({errMsg = 3, itemId = cost[1]}))	--物品不足
  -- 			return true
  -- 		end
  -- 		role:costItems({[cost[1]] = cost[2]})
  -- 		local newLevel = curL + 1
  -- 		hero:updateProperty({field = "loveL", value = newLevel})
  -- 		hero:updateProperty({field = "loveExp", value = 0})
  
  -- 		if role:getProperty("loveStatus"):getv(curType, 0) < newLevel then
  -- 			role:changeUpdates({{type = "loveStatus", field = curType, value = newLevel}}) -- 总的
  -- 		end
  
  -- 		role:checkTaskEnter("LoveBreak", {heroType = curType, loveL = newLevel})
  
  -- 	else
  -- 		local delta = globalCsv.unit_love_presentValue[msg.itemId]
  -- 		if not delta then
  -- 			return
  -- 		end
  -- 		if not role:checkItemEnough({[msg.itemId] = 1}) then
  -- 			SendPacket(actionCodes.Hero_loveItemRpc, MsgPack.pack({errMsg = 3, itemId = msg.itemId}))
  -- 			return true
  -- 		end
  -- 		local newExp = curExp + delta
  -- 		if newExp > curEffect.loveValue then
  -- 			newExp = curEffect.loveValue
  -- 		end
  -- 		role:costItems({[msg.itemId] = 1})
  -- 		hero:updateProperty({field = "loveExp", value = newExp})
  -- 	end
  -- 	SendPacket(actionCodes.Hero_loveItemRpc, "")
  -- 	return true
  -- end
  
  -- function _M.loveTaskRpc(agent, data)
  -- 	local role = agent.role
  -- 	local msg = MsgPack.unpack(data)
  -- 	local hero = role.heros[msg.id]
  -- 	if not hero then return end
  
  -- 	local curL = hero:getProperty("loveL")
  -- 	local curExp = hero:getProperty("loveExp")
  -- 	local curType = hero:getProperty("type")
  -- 	local curPlus = csvdb["unit_love_plusCsv"][curType]
  -- 	if not curPlus or curL >= curPlus.limit then return end
  
  --  	local curEffect = csvdb["unit_love_effectCsv"][curL]
  -- 	if not curEffect or curExp < curEffect.loveValue then return end
  
  -- 	local lastEffect = csvdb["unit_love_effectCsv"][curL + 1]
  -- 	local newExp = curExp - curEffect.loveValue
  -- 	if lastEffect and curL + 1 < curPlus.limit then
  -- 		if newExp >= lastEffect.loveValue then
  -- 			-- todo  发任务
  -- 		end
  -- 	else
  -- 		newExp = 0
  -- 	end
  -- 	local newLevel = curL + 1
  -- 	hero:updateProperty({field = "loveExp", value = newExp})
  -- 	hero:updateProperty({field = "loveL", value = newLevel})
  
  -- 	if role:getProperty("loveStatus"):getv(curType, 0) < newLevel then
  -- 		role:changeUpdates({{type = "loveStatus", field = curType, value = newLevel}}) -- 总的
  -- 	end
  
  -- 	role:checkTaskEnter("LoveBreak", {heroType = curType, loveL = newLevel})
  
  -- 	SendPacket(actionCodes.Hero_loveTaskRpc, "")
  -- 	return true
  -- end
6947e382   zhouahaihai   好感度, 皮肤
471
  
312b9db5   zhouahaihai   背包
472
473
474
475
476
477
478
479
480
481
482
483
484
485
  function _M.createHeroRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local heroType = msg.heroType
  	local unitData = csvdb["unitCsv"][heroType]
  	if not unitData then return end
  	local cost = globalCsv.unit_fragment_cost[unitData["rare"]]
  	if not cost then return end
  	if role:getItemCount(heroType) < cost then return end
  
  	for _, hero in pairs(role.heros) do
  		if hero:getProperty("type") == heroType then return end
  	end
  
3133cb76   zhouhaihai   日志
486
487
  	role:costItems({[heroType] = cost}, {log = {desc = "createHero"}})
  	role:award({[heroType + ItemStartId.Hero] = 1}, {log = {desc = "createHero"}})
312b9db5   zhouahaihai   背包
488
489
490
491
492
  
  	SendPacket(actionCodes.Hero_createHeroRpc, "")
  	return true
  end
  
43cc5f51   gaofengduan   调整 equip 数据结构
493
  -- typ 位置,level等级对应唯一装备,level为0时为移除,不为0时无则装备,有则替换
24d77701   gaofengduan   fix equip
494
  function _M.referEquipsRpc(agent, data)
43cc5f51   gaofengduan   调整 equip 数据结构
495
496
497
498
499
500
501
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local hero = role.heros[msg.id]
  	if not hero then return 10 end
  	local equips = msg.equips
  	if not equips or not next(equips) then return 11 end
  
056c01a0   zhouhaihai   简化装备
502
503
504
505
506
  	for typ = 1, 4 do -- 4件装备
  		if equips[typ] and equips[typ] ~= 0 then
  			if role:getEquipCount(typ, equips[typ]) <= 0 then
  				return
  			end
43cc5f51   gaofengduan   调整 equip 数据结构
507
  		end
43cc5f51   gaofengduan   调整 equip 数据结构
508
  	end
056c01a0   zhouhaihai   简化装备
509
510
511
512
  	local curEquip = hero:getProperty("equip")
  	for typ = 1, 4 do -- 4件装备
  		if equips[typ] then
  			local cur = curEquip:getv(typ, 0)
ee999bde   zhouhaihai   零件优化
513
514
  			if cur ~= equips[typ] then
  				if equips[typ] == 0 then
056c01a0   zhouhaihai   简化装备
515
  					curEquip = curEquip:delk(typ)
ee999bde   zhouhaihai   零件优化
516
  				else
3133cb76   zhouhaihai   日志
517
  					role:addEquip(typ, equips[typ], -1, {log = {desc = "refer"}}) -- 穿上
056c01a0   zhouhaihai   简化装备
518
519
  					curEquip = curEquip:setv(typ, equips[typ])
  				end
ee999bde   zhouhaihai   零件优化
520
521
  
  				if cur ~= 0 then
3133cb76   zhouhaihai   日志
522
  					role:addEquip(typ, cur, 1, {log = {desc = "refer"}}) -- 脱掉
ee999bde   zhouhaihai   零件优化
523
  				end
43cc5f51   gaofengduan   调整 equip 数据结构
524
525
  			end
  		end
43cc5f51   gaofengduan   调整 equip 数据结构
526
  	end
056c01a0   zhouhaihai   简化装备
527
528
529
  	-- 更新角色
  	hero:updateProperty({field = "equip", value = curEquip})
  
1e9cb217   chenyueqi   服务器记录控制引导过程
530
531
  	role:finishGuide(23)
  
43cc5f51   gaofengduan   调整 equip 数据结构
532
533
534
535
  	SendPacket(actionCodes.Hero_referEquipsRpc, "")
  	return true
  end
  
ee3ac0b5   gaofengduan   fix magic
536
537
  -- typ 位置,uid对应唯一符文,uid为0时为移除,不为0时无则装备,有则替换
  function _M.referRunesRpc(agent, data)
43cc5f51   gaofengduan   调整 equip 数据结构
538
539
540
541
542
543
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local hero = role.heros[msg.id]
  	if not hero then return 10 end
  	local runes = msg.runes
  	if not runes or not next(runes) then return 11 end
ee3ac0b5   gaofengduan   fix magic
544
  
f52efe51   zhouhaihai   符文升级
545
  	local used = {}
ee999bde   zhouhaihai   零件优化
546
547
548
549
  	for typ = 1, 6 do
  		if runes[typ] and runes[typ] ~= 0 then
  			local ownRune = role.runeBag[runes[typ]]
  			if not ownRune then return end
f52efe51   zhouhaihai   符文升级
550
551
552
553
554
555
556
557
558
559
560
561
562
563
  			if ownRune:getProperty("refer") ~= 0 then 
  				used[ownRune:getProperty("refer")] = used[ownRune:getProperty("refer")] or {}
  				used[ownRune:getProperty("refer")][runes[typ]] = 1
  			end
  		end
  	end
  
  	for cheroId, cIds in pairs(used) do
  		local chero = role.heros[cheroId] 
  		local hrunes = chero:getProperty("rune")
  		for slot, rId in pairs(hrunes:toNumMap()) do
  			if cIds[rId] then
  				hrunes = hrunes:delk(slot)
  			end
ee3ac0b5   gaofengduan   fix magic
564
  		end
f52efe51   zhouhaihai   符文升级
565
  		chero:updateProperty({field = "rune", value = hrunes})
ee3ac0b5   gaofengduan   fix magic
566
  	end
f52efe51   zhouhaihai   符文升级
567
  
ee999bde   zhouhaihai   零件优化
568
569
570
571
572
573
574
575
576
577
  	local curRune = hero:getProperty("rune")
  	for typ = 1, 6 do
  		if runes[typ] then
  			local cur = curRune:getv(typ, 0)
  			if cur ~= runes[typ] then
  				if runes[typ] == 0 then
  					curRune = curRune:delk(typ)
  				else
  					local newRune = role.runeBag[runes[typ]]
  					newRune:updateProperty({field = "refer",value = hero:getProperty("id")})
4ea1b5ac   zhouhaihai   穿戴零件
578
  					curRune = curRune:setv(typ, runes[typ])
ee999bde   zhouhaihai   零件优化
579
  				end
ee3ac0b5   gaofengduan   fix magic
580
  
ee999bde   zhouhaihai   零件优化
581
582
583
584
585
586
  				if cur ~= 0 then
  					local oldR = role.runeBag[cur]
  					if oldR then
  						oldR:updateProperty({field = "refer",value = 0})
  					end
  				end
ee3ac0b5   gaofengduan   fix magic
587
  			end
ee3ac0b5   gaofengduan   fix magic
588
  		end
ee3ac0b5   gaofengduan   fix magic
589
  	end
4ea1b5ac   zhouhaihai   穿戴零件
590
  	hero:updateProperty({field = "rune", value = curRune})
ee3ac0b5   gaofengduan   fix magic
591
  	SendPacket(actionCodes.Hero_referRunesRpc, "")
43cc5f51   gaofengduan   调整 equip 数据结构
592
593
594
  	return true
  end
  
3b069d52   zhouhaihai   增加获取 food 后台
595
596
597
598
599
600
601
602
603
604
605
606
  function _M.createHeroRandomRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local itemId = msg.itemId
  	local itemData = csvdb["itemCsv"][itemId]
  	if not itemData or itemData.type ~= ItemType.HeroFCommon then return end
  	local cost = globalCsv.unit_fragment_cost[itemData.quality]
  	if not cost or role:getItemCount(itemId) < cost then return end
  
  	local randomData = csvdb["item_randomCsv"][tonumber(itemData.use_effect)]
  	if not randomData then return end
  
007af97e   zhouhaihai   item_random 结构更改
607
  	local temp = randomData.gift1:randWeight(true)
3b069d52   zhouhaihai   增加获取 food 后台
608
  	if not temp or not next(temp) then return end
7bb30dca   zhouhaihai   修改发奖
609
  
3133cb76   zhouhaihai   日志
610
  	role:costItems({[itemId] = cost}, {log = {desc = "createHeroRandom"}})
7bb30dca   zhouhaihai   修改发奖
611
612
613
614
  	local reward, change = role:award({[temp[1] + ItemStartId.Hero] = 1}, {log = {desc = "createHeroRandom"}})
  
  
  	SendPacket(actionCodes.Hero_createHeroRandomRpc, MsgPack.pack(role:packReward(reward, change)))
3b069d52   zhouhaihai   增加获取 food 后台
615
616
617
  	return true
  end
  
36482c8b   zhouhaihai   回收养成
618
619
620
  function _M.getResetRewardRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
36482c8b   zhouhaihai   回收养成
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
  	
  	local hero = role.heros[msg.id]
  	if not hero then return end
  
  	local level = hero:getProperty("level")
  	local breakL = hero:getProperty("breakL")
  	local talent = hero:getProperty("talent")
  
  	if level <= 1 and talent == "" then return end
  
  	local reward = {}
  	while level > 1 do
  		local curData = csvdb["unit_expCsv"][level - 1]
  		reward[ItemId.Exp] = (reward[ItemId.Exp] or 0) + curData.exp
  		reward[ItemId.Gold] = (reward[ItemId.Gold] or 0) + curData.gold
  		level = level - 1
  	end
  
  	while breakL > 0 do
  		local curData = csvdb["unit_breakCsv"][breakL - 1]
  		reward[ItemId.BreakCost] = (reward[ItemId.BreakCost] or 0) + curData.cost
  		reward[ItemId.Gold] = (reward[ItemId.Gold] or 0) + curData.gold
  		breakL = breakL - 1
  	end
  
  	local stage = talent:getv(0, 1)
  	local tlevel = {talent:getv(1, 0), talent:getv(2, 0), talent:getv(3, 0), talent:getv(4, 0)}
  
  	local talentCostIds = globalCsv.unit_talent_cost[csvdb["unitCsv"][hero:getProperty("type")].camp]
  	while stage > 0 do
  		local curData = csvdb["unit_talentCsv"][stage]
  		for level = math.max(table.unpack(tlevel)), 1, -1 do
  			local add = 0
  			for i = 1, 4 do
  				if tlevel[i] == level then
  					add = add + 1
  					tlevel[i] = tlevel[i] - 1
  				end
  			end
  			local talentData = curData[level - 1]
  			for itemId, count in pairs(talentData.money:toNumMap()) do
  				reward[itemId] = (reward[itemId] or 0) + count * add
  			end
  			for idx , count in pairs(talentData.cost:toNumMap()) do
  				reward[talentCostIds[idx]] = (reward[talentCostIds[idx]] or 0) + count * add
  			end
  		end
  		stage = stage - 1
  		curData = csvdb["unit_talentCsv"][stage]
  		if curData then
  			tlevel = {#curData, #curData, #curData, #curData}
  		end
  	end
  
  	hero:updateProperty({field = "level", value = level})
  	hero:updateProperty({field = "breakL", value = breakL})
  	hero:updateProperty({field = "talent", value = ""})
3133cb76   zhouhaihai   日志
678
  	hero:log({desc = "resetHero"})
36482c8b   zhouhaihai   回收养成
679
680
681
682
  
  	for itemId, count in pairs(reward) do
  		reward[itemId] = math.floor(count * globalCsv.unit_back_discount)
  	end
7bb30dca   zhouhaihai   修改发奖
683
684
  	local change
  	reward, change = role:award(reward, {log = {desc = "resetHero", int1 = msg.id, int2 = hero:getProperty("type")}})
36482c8b   zhouhaihai   回收养成
685
  
7bb30dca   zhouhaihai   修改发奖
686
  	SendPacket(actionCodes.Hero_getResetRewardRpc, MsgPack.pack(role:packReward(reward, change)))
36482c8b   zhouhaihai   回收养成
687
688
689
  	return true
  end
  
1a0b3c56   liuzujun   抽卡保底,切换定向卡池
690
  function _M.unuse_drawHeroRpc(agent, data)
058a0cbb   zhouhaihai   抽卡
691
692
693
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
d232676a   zhouhaihai   功能解锁 冒险返回
694
  	if not role:isFuncUnlock(FuncUnlock.GetHero) then return end
3c0ea5fb   zhouhaihai   抽英雄
695
  	local btype = msg.pool	-- 1 2 3 4
058a0cbb   zhouhaihai   抽卡
696
  	local drawType = msg.type -- 1 单抽 2 十连
058a0cbb   zhouhaihai   抽卡
697
  	
3c0ea5fb   zhouhaihai   抽英雄
698
  	local buildTypeData = csvdb["build_typeCsv"][btype]
1976004f   zhouhaihai   测试
699
  	if not buildTypeData then return 1 end
058a0cbb   zhouhaihai   抽卡
700
  
058a0cbb   zhouhaihai   抽卡
701
  	local drawCount = {1, 10} -- 抽取次数
3c0ea5fb   zhouhaihai   抽英雄
702
  	if not drawCount[drawType] then return 2 end
058a0cbb   zhouhaihai   抽卡
703
  
3c0ea5fb   zhouhaihai   抽英雄
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
  	local newerDraw
  	if btype == 4 then
  		newerDraw = role:getProperty("newerDraw")
  		if math.illegalNum(globalCsv.draw_newer[2] - (newerDraw[1] or 0),  drawCount[drawType],  globalCsv.draw_newer[2]) then return 11 end
  	end
  	
  	local cost = {}
  	local lastCount = drawCount[drawType]
  	for _, costType in ipairs({"draw_card", "draw_coin"}) do
  		if buildTypeData[costType] ~= "" then
  			local curCost = buildTypeData[costType]:toArray(true, "=")
  			local hadCount = role:getItemCount(curCost[1])
  			local curCount = math.floor(hadCount / curCost[2])
  			if curCount >= lastCount then
  				cost[curCost[1]] = curCost[2] * lastCount
  				lastCount = 0
  				break
  			elseif curCount > 0 then
  				cost[curCost[1]] = curCost[2] * curCount
  				lastCount = lastCount - curCount
  			end
058a0cbb   zhouhaihai   抽卡
725
726
  		end
  	end
3c0ea5fb   zhouhaihai   抽英雄
727
728
729
  	if lastCount > 0 then -- 钱不够
  		return 3
  	end
058a0cbb   zhouhaihai   抽卡
730
  
3c0ea5fb   zhouhaihai   抽英雄
731
732
733
734
735
736
737
738
739
740
741
  	-- pool 固定的
  	local poolEnum = {
  		[1] = {
  			[1] = 1,
  			[2] = 2,
  			[3] = 3,
  		},
  		[2] = 10,
  		[3] = 11,
  		[4] = 12,
  	}
058a0cbb   zhouhaihai   抽卡
742
  
3c0ea5fb   zhouhaihai   抽英雄
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
  	-- 抽取的池子
  	local pool = poolEnum[btype]
  	if btype == 1 then
  		-- 超级卡池子 每周轮换 有活动覆盖之
  		--TODO 活动判断
  		if false then
  		else
  			for idx, poolId in pairs(pool) do
  				if role:isTimeResetOpen(TimeReset["DrawType" .. idx]) then
  					pool = poolId
  					break
  				end
  			end
  			if type(pool) ~= "number" then
  				pool = -1
  			end
  		end
058a0cbb   zhouhaihai   抽卡
760
  	end
3c0ea5fb   zhouhaihai   抽英雄
761
762
  	local unitPool = csvdb["build_unitCsv"][pool]
  	if not unitPool then return 4 end
058a0cbb   zhouhaihai   抽卡
763
  
3c0ea5fb   zhouhaihai   抽英雄
764
  	-- 开始抽
058a0cbb   zhouhaihai   抽卡
765
  	local resultPool = {}
54833afe   zhouhaihai   抽英雄
766
  	local function fillDrawPool(fixRare, fixCamp, ssrUp, floorBack)
3c0ea5fb   zhouhaihai   抽英雄
767
768
769
770
771
772
773
774
775
776
777
  		local condition = {"rare", "camp"}
  		local values = {fixRare, fixCamp}
  
  		for idx, field in ipairs(condition) do
  			if not values[idx] then
  				local lpool = {}
  				local curIdx = 1
  				while unitPool[field .. "_" .. curIdx] do
  					lpool[curIdx] = {unitPool[field .. "_" .. curIdx]}
  					curIdx = curIdx + 1
  				end
058a0cbb   zhouhaihai   抽卡
778
  
3c0ea5fb   zhouhaihai   抽英雄
779
780
781
782
783
784
  				-- 稀有度 ssr up
  				if field == "rare" then
  					local all = 0
  					for _, weight in pairs(lpool) do
  						all = all + weight[1]
  					end
54833afe   zhouhaihai   抽英雄
785
786
787
788
789
790
791
792
793
794
  					--[[
  						SSR概率值:初始概率 + 步长概率
  						SR概率值:初始概率 * [ (初始概率+R初始概率) - 步长概率 ] /(初始概率+R初始概率)
  						R概率值:初始概率 * [ (初始概率+SR初始概率) - 步长概率 ] /(初始概率+SR初始概率)
  					]]
  					local ssrAdd = (ssrUp or 0) * all
  					local last = all - lpool[4][1]
  					lpool[4][1] = lpool[4][1] + ssrAdd
  					lpool[3][1] = lpool[3][1] * (last - ssrAdd) / last
  					lpool[2][1] = lpool[2][1] * (last - ssrAdd) / last
058a0cbb   zhouhaihai   抽卡
795
  				end
3c0ea5fb   zhouhaihai   抽英雄
796
797
798
  
  				if next(lpool) then
  					values[idx] =  math.randWeight(lpool, 1)
058a0cbb   zhouhaihai   抽卡
799
  				end
3c0ea5fb   zhouhaihai   抽英雄
800
801
  			end
  		end
058a0cbb   zhouhaihai   抽卡
802
  
54833afe   zhouhaihai   抽英雄
803
  		for itemId, oneData in pairs(floorBack and csvdb["build_floorCsv"] or csvdb["build_poolCsv"]) do
3c0ea5fb   zhouhaihai   抽英雄
804
805
806
807
808
809
810
811
812
813
814
  			if oneData["pool_" .. pool] and oneData["pool_" .. pool] ~= "" then
  				local itemData = csvdb["itemCsv"][itemId]
  				while itemData do
  					if itemData.type ~= ItemType.Hero then break end
  					local heroData = csvdb["unitCsv"][itemData.id - ItemStartId.Hero]
  					if not heroData then break end
  					local ok = true
  					for idx, field in ipairs(condition) do
  						if heroData[field] ~= values[idx] then ok = false break end
  					end
  					if not ok then break end
28b5c033   zhouhaihai   概率 0 不放入池子
815
816
817
  					if oneData["pool_" .. pool] > 0 then
  						resultPool[itemId] = {oneData["pool_" .. pool]}  -- itemId, count, 概率
  					end
3c0ea5fb   zhouhaihai   抽英雄
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
  					break
  				end
  			end
  		end
  	end
  
  	role:costItems(cost, {log = {desc = "drawHero", short1 = btype, int1 = pool}})
  
  	local draw_floor_back_counts = globalCsv.draw_floor_back_counts[btype]
  	local draw_ssr_up_count_rate = globalCsv.draw_ssr_up_count_rate[btype]
  	local floorHeroCount = role:getProperty("floorHero")[btype] or 0
  	local ssrUpCount = role:getProperty("ssrUp")[btype] or 0
  
  	local newerDrawCount, newerHadSSR  
  	if btype == 4 then
  		newerDrawCount = newerDraw[1] or 0
  		newerHadSSR = newerDraw[2] or 0
  	end
058a0cbb   zhouhaihai   抽卡
836
  
1e9cb217   chenyueqi   服务器记录控制引导过程
837
838
839
840
841
842
  	local guideHero
  	local funcGuide = role:getProperty("funcGuide")
  	if funcGuide:getv(11001,0) == 1 and funcGuide:getv(12001,0) == 0 then
  		guideHero = 613
  	end
  
53e8037e   zhouhaihai   任务
843
  	local ssrCount = 0
058a0cbb   zhouhaihai   抽卡
844
845
  	local reward = {}
  	for i = 1, drawCount[drawType] do
a35233c6   zhouhaihai   保底和回馈
846
  		floorHeroCount = floorHeroCount + 1
3c0ea5fb   zhouhaihai   抽英雄
847
848
849
  		if btype == 4 then
  			newerDrawCount =  newerDrawCount + 1
  		end
216fb30d   zhouhaihai   连抽 bug
850
851
  
  		resultPool = {}
3c0ea5fb   zhouhaihai   抽英雄
852
853
  		local isFloorBack = draw_floor_back_counts and floorHeroCount >= draw_floor_back_counts
  		local isNewerSSR = btype == 4 and (newerHadSSR == 0 and newerDrawCount >= globalCsv.draw_newer[1]) or false
a35233c6   zhouhaihai   保底和回馈
854
  
3c0ea5fb   zhouhaihai   抽英雄
855
  		local ssrUp = 0
97f5a8df   zhouhaihai   ssrup 修改规则
856
857
  		if draw_ssr_up_count_rate and ssrUpCount > draw_ssr_up_count_rate[1] then
  			ssrUp = math.min((ssrUpCount - draw_ssr_up_count_rate[1]) * draw_ssr_up_count_rate[2], draw_ssr_up_count_rate[3]) / 100
3c0ea5fb   zhouhaihai   抽英雄
858
859
860
861
862
  		end
  		while not next(resultPool) do
  			if isNewerSSR then
  				fillDrawPool(4) -- 新手保底的 ssr 
  			elseif isFloorBack then
54833afe   zhouhaihai   抽英雄
863
864
865
  				-- 保底 sr 【郑斌】明确
  				-- 保底 sr 改为 池子随机 sr 或者 ssr【郑斌】
  				fillDrawPool(nil, nil, nil, true)     
a35233c6   zhouhaihai   保底和回馈
866
  			else
3c0ea5fb   zhouhaihai   抽英雄
867
  				fillDrawPool(nil, nil, ssrUp)
a35233c6   zhouhaihai   保底和回馈
868
  			end
db8e475e   zhouhaihai   抽奖
869
870
  		end
  
314ae3f4   chenyueqi   新手引导抽的时候必送丝路德
871
  		-- 引导必送 613 丝路德
1e9cb217   chenyueqi   服务器记录控制引导过程
872
873
874
875
876
  		local itemId = math.randWeight(resultPool, 1)
  		if guideHero then
  			itemId = guideHero
  			guideHero = nil
  		end
3c0ea5fb   zhouhaihai   抽英雄
877
  		local itemData = csvdb["itemCsv"][itemId]
3c0ea5fb   zhouhaihai   抽英雄
878
879
880
  		if itemData.quality == 4 then
  			ssrCount = ssrCount + 1
  			ssrUpCount = 0
3c0ea5fb   zhouhaihai   抽英雄
881
882
  			if btype == 4 then
  				newerHadSSR = newerHadSSR + 1
3df938f9   zhouhaihai   明确保底 ssr
883
  			end
3c0ea5fb   zhouhaihai   抽英雄
884
885
  		else
  			ssrUpCount = ssrUpCount + 1
53e8037e   zhouhaihai   任务
886
887
  		end
  
54833afe   zhouhaihai   抽英雄
888
889
890
891
  		if itemData.quality >= 3 then
  			floorHeroCount = 0
  		end
  
3c0ea5fb   zhouhaihai   抽英雄
892
  		if role:isHaveHero(itemData.id - ItemStartId.Hero) then
db8e475e   zhouhaihai   抽奖
893
894
  			local fragId = itemData.id - ItemStartId.Hero
  			local heroData = csvdb["unitCsv"][fragId]
3c0ea5fb   zhouhaihai   抽英雄
895
896
897
  			local count = globalCsv.draw_unit_tofragment[heroData.rare]
  			role:award({[fragId] = count}, {log = {desc = "drawHero", short1 = btype, int1 = pool}})
  			table.insert(reward, {id = fragId, count = count, from = itemId, fcount = 1})
db8e475e   zhouhaihai   抽奖
898
  		else
3c0ea5fb   zhouhaihai   抽英雄
899
900
  			role:award({[itemId] = 1}, {log = {desc = "drawHero", short1 = btype, int1 = pool}})
  			table.insert(reward, {id = itemId, count = 1})
058a0cbb   zhouhaihai   抽卡
901
902
903
  		end
  	end
  
3c0ea5fb   zhouhaihai   抽英雄
904
  	if draw_floor_back_counts then
a35233c6   zhouhaihai   保底和回馈
905
  		local floorHero = role:getProperty("floorHero")
93b010f5   zhouhaihai   保底未生效
906
  		floorHero[btype] = floorHeroCount
3c0ea5fb   zhouhaihai   抽英雄
907
908
909
910
911
  		role:setProperty("floorHero", floorHero)
  	end
  
  	if draw_ssr_up_count_rate then
  		local ssrUp = role:getProperty("ssrUp")
93b010f5   zhouhaihai   保底未生效
912
  		ssrUp[btype] = ssrUpCount
3c0ea5fb   zhouhaihai   抽英雄
913
  		role:setProperty("ssrUp", ssrUp)
a35233c6   zhouhaihai   保底和回馈
914
915
  	end
  
3c0ea5fb   zhouhaihai   抽英雄
916
917
918
919
  	if btype == 4 then
  		newerDraw[1] = newerDrawCount
  		newerDraw[2] = newerHadSSR
  		role:updateProperty({field = "newerDraw", value = newerDraw})
aef8ca87   zhouhaihai   两个bug
920
  	end
a35233c6   zhouhaihai   保底和回馈
921
  
3c0ea5fb   zhouhaihai   抽英雄
922
923
924
925
926
927
  	-- if pool == 1 then
  	-- 	local repayHero = role:getProperty("repayHero")
  	-- 	repayHero = math.min(globalCsv.draw_super_repay_count, repayHero + drawCount[drawType])
  	-- 	role:updateProperty({field = "repayHero", value = repayHero})
  	-- end
  
1e9cb217   chenyueqi   服务器记录控制引导过程
928
929
  	role:finishGuide(11)
  
ceec6779   zhouhaihai   抽英雄任务bug
930
  	role:checkTaskEnter("DrawHero", {pool = btype, count = drawCount[drawType]})
53e8037e   zhouhaihai   任务
931
932
933
  	if ssrCount > 0 then
  		role:checkTaskEnter("DrawSSR", {count = ssrCount})
  	end
3c0ea5fb   zhouhaihai   抽英雄
934
  	role:log("hero_action", {desc = "drawHero", short1 = btype, int1 = drawCount[drawType], int2 = pool})
058a0cbb   zhouhaihai   抽卡
935
936
937
938
  	SendPacket(actionCodes.Hero_drawHeroRpc, MsgPack.pack({reward = reward})) -- 这个 reward 是数组
  	return true
  end
  
1a0b3c56   liuzujun   抽卡保底,切换定向卡池
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
  function _M.drawHeroRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
  	if not role:isFuncUnlock(FuncUnlock.GetHero) then return end
  	local btype = msg.pool	-- 1 2 3	卡池类型
  	local subType = msg.subType	or 1-- 定向卡池需要传 子类型
  	local drawType = msg.type -- 1 单抽 2 十连
  	local guide = msg.guide -- 是否是引导抽的
  	if btype ~= 1 then
  		subType = 1
  	end
  	
  	local buildTypeData = csvdb["build_typeCsv"][btype]
  	if not buildTypeData then return 1 end
  
  	local drawCount = {1, 10} -- 抽取次数
  	if not drawCount[drawType] then return 2 end
  
93f6e69b   liuzujun   拾荒选择时间,抽卡增加sr保底
958
959
960
  	local draw_floor_back_counts = globalCsv.draw_floor_back_counts[btype]
  	local floorHeroCount = role:getProperty("floorHero")[btype] or 0
  
1a0b3c56   liuzujun   抽卡保底,切换定向卡池
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
  	-- 计算抽卡消耗品
  	local cost = {}
  	local lastCount = drawCount[drawType]
  	for _, costType in ipairs({"draw_card", "draw_coin"}) do
  		if buildTypeData[costType] ~= "" then
  			local curCost = buildTypeData[costType]:toArray(true, "=")
  			local hadCount = role:getItemCount(curCost[1])
  			local curCount = math.floor(hadCount / curCost[2])
  			if curCount >= lastCount then
  				cost[curCost[1]] = curCost[2] * lastCount
  				lastCount = 0
  				break
  			elseif curCount > 0 then
  				cost[curCost[1]] = curCost[2] * curCount
  				lastCount = lastCount - curCount
  			end
  		end
  	end
  	if lastCount > 0 then -- 钱不够
  		return 3
  	end
  
  	-- 抽取的池子
  	local poolMap = buildTypeData["pool"]:toNumMap()
  	local poolId = poolMap[subType]
  	if not poolId then return end
  	
  	--判断定向卡池是否开启
  	if btype == 1 then
  			if not role:isTimeResetOpen(TimeReset["DrawType" .. subType]) then
  				local unlockPool = role.dailyData:getProperty("unlockPool")
  				if not unlockPool[subType] then
  					return 1
  				end
  			end
  	end
  
  	--TODO 活动覆盖
93f6e69b   liuzujun   拾荒选择时间,抽卡增加sr保底
999
1000
1001
1002
  	local actPoolId = role.activity:getActivityPool(btype, subType)
  	if actPoolId ~= 0 then
  		poolId = actPoolId
  	end
1a0b3c56   liuzujun   抽卡保底,切换定向卡池
1003
1004
1005
1006
1007
1008
  
  	local unitPool = csvdb["build_unitCsv"][poolId]
  	if not unitPool then return 4 end
  
  	-- 开始抽
  	local resultPool = {}
93f6e69b   liuzujun   拾荒选择时间,抽卡增加sr保底
1009
  	local function fillDrawPool(isFloorBack)
1a0b3c56   liuzujun   抽卡保底,切换定向卡池
1010
1011
1012
  		local condition = {"rare", "camp"}
  		local values = {}
  
93f6e69b   liuzujun   拾荒选择时间,抽卡增加sr保底
1013
  
1a0b3c56   liuzujun   抽卡保底,切换定向卡池
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
  		for idx, field in ipairs(condition) do
  			if not values[idx] then
  				local lpool = {}
  				local curIdx = 1
  				while unitPool[field .. "_" .. curIdx] do
  					lpool[curIdx] = {unitPool[field .. "_" .. curIdx]}
  					curIdx = curIdx + 1
  				end
  
  				if next(lpool) then
  					values[idx] =  math.randWeight(lpool, 1)
  				end
  			end
  		end
  
93f6e69b   liuzujun   拾荒选择时间,抽卡增加sr保底
1029
1030
1031
  		for itemId, oneData in pairs(isFloorBack and csvdb["build_floorCsv"] or csvdb["build_poolCsv"]) do
  			local pool_str = "pool_" .. poolId
  			if oneData[pool_str] and oneData[pool_str] ~= "" then
1a0b3c56   liuzujun   抽卡保底,切换定向卡池
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
  				local itemData = csvdb["itemCsv"][itemId]
  				while itemData do
  					if itemData.type ~= ItemType.Hero then break end
  					local heroData = csvdb["unitCsv"][itemData.id - ItemStartId.Hero]
  					if not heroData then break end
  					local ok = true
  					for idx, field in ipairs(condition) do
  						if heroData[field] ~= values[idx] then ok = false break end
  					end
  					if not ok then break end
93f6e69b   liuzujun   拾荒选择时间,抽卡增加sr保底
1042
1043
  					if oneData[pool_str] > 0 then
  						resultPool[itemId] = {oneData[pool_str]}  -- itemId, count, 概率
1a0b3c56   liuzujun   抽卡保底,切换定向卡池
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
  					end
  					break
  				end
  			end
  		end
  	end
  
  	role:costItems(cost, {log = {desc = "drawHero", short1 = btype, int1 = poolId}})
  
  	local ssrCount = 0
  	local reward = {}
  	for i = 1, drawCount[drawType] do
93f6e69b   liuzujun   拾荒选择时间,抽卡增加sr保底
1056
1057
  		floorHeroCount = floorHeroCount + 1
  		local isFloorBack = draw_floor_back_counts and floorHeroCount >= draw_floor_back_counts
1a0b3c56   liuzujun   抽卡保底,切换定向卡池
1058
  		resultPool = {}
93f6e69b   liuzujun   拾荒选择时间,抽卡增加sr保底
1059
1060
1061
1062
  		fillDrawPool(isFloorBack)
  		if not next(resultPool) then
  			skynet.error("random pool error, poolId:" .. poolId)
  			return
1a0b3c56   liuzujun   抽卡保底,切换定向卡池
1063
1064
1065
1066
1067
1068
1069
1070
1071
  		end
  
  		-- 引导必送 613 丝路德
  		local itemId = guide and 613 or math.randWeight(resultPool, 1)
  		local itemData = csvdb["itemCsv"][itemId]
  		if itemData.quality == HeroQuality.SSR then
  			ssrCount = ssrCount + 1
  		end
  
93f6e69b   liuzujun   拾荒选择时间,抽卡增加sr保底
1072
1073
1074
1075
  		if itemData.quality >= HeroQuality.SR then
  			floorHeroCount = 0
  		end
  
1a0b3c56   liuzujun   抽卡保底,切换定向卡池
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
  		if role:isHaveHero(itemData.id - ItemStartId.Hero) then
  			local fragId = itemData.id - ItemStartId.Hero
  			local heroData = csvdb["unitCsv"][fragId]
  			local count = globalCsv.draw_unit_tofragment[heroData.rare]
  			role:award({[fragId] = count}, {log = {desc = "drawHero", short1 = btype, int1 = poolId}})
  			table.insert(reward, {id = fragId, count = count, from = itemId, fcount = 1})
  		else
  			role:award({[itemId] = 1}, {log = {desc = "drawHero", short1 = btype, int1 = poolId}})
  			table.insert(reward, {id = itemId, count = 1})
  		end
  	end
  
93f6e69b   liuzujun   拾荒选择时间,抽卡增加sr保底
1088
1089
1090
1091
1092
1093
  	if draw_floor_back_counts then
  		local floorHero = role:getProperty("floorHero")
  		floorHero[btype] = floorHeroCount
  		role:setProperty("floorHero", floorHero)
  	end
  
1a0b3c56   liuzujun   抽卡保底,切换定向卡池
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
  	if btype == 1 or btype == 2 then
  		local repayHero = role:getProperty("repayHero") or 0
  		repayHero = repayHero + drawCount[drawType]
  		role:updateProperty({field = "repayHero", value = repayHero})
  	end
  
  	role:checkTaskEnter("DrawHero", {pool = btype, count = drawCount[drawType]})
  	if ssrCount > 0 then
  		role:checkTaskEnter("DrawSSR", {count = ssrCount})
  	end
  	role:log("hero_action", {desc = "drawHero", short1 = btype, int1 = drawCount[drawType], int2 = poolId})
  	SendPacket(actionCodes.Hero_drawHeroRpc, MsgPack.pack({reward = reward})) -- 这个 reward 是数组
  	return true
  end
  
317a46a9   liuzujun   添加特权卡
1109
1110
  function _M.repayHeroRpc(agent, data)
  	local role = agent.role
a35233c6   zhouhaihai   保底和回馈
1111
  
317a46a9   liuzujun   添加特权卡
1112
  	local repayHero = role:getProperty("repayHero")
fb3d084d   liuzujun   月卡赛季卡发送邮件奖励
1113
1114
  	local cnt = globalCsv.draw_times_to_get_ssr or 100
  	if repayHero < cnt then
317a46a9   liuzujun   添加特权卡
1115
1116
  		return
  	end
fb3d084d   liuzujun   月卡赛季卡发送邮件奖励
1117
  	local result = repayHero - cnt
a35233c6   zhouhaihai   保底和回馈
1118
  
317a46a9   liuzujun   添加特权卡
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
  	role:updateProperty({field = "repayHero", value = result})
  	local id = math.randWeight(csvdb["build_giftCsv"], "pool_1")
  
  	local reward = {}
  	local itemData = csvdb["itemCsv"][id]
  	if itemData.type == ItemType.Hero and role:isHaveHero(itemData.id - ItemStartId.Hero) then
  		local fragId = itemData.id - ItemStartId.Hero
  		local heroData = csvdb["unitCsv"][fragId]
  		local count = globalCsv.draw_unit_tofragment[heroData.rare]
  		role:award({[fragId] = count}, {log = {desc = "heroRepay"}})
  		reward = {id = fragId, count = count, from = id, fcount = 1}
  	else
  		role:award({[id] = 1}, {log = {desc = "heroRepay"}})
  		reward = {id = id, count = 1}
  	end
  	role:log("hero_action", {desc = "heroRepay", int1=result})
  	SendPacket(actionCodes.Hero_repayHeroRpc, MsgPack.pack({reward = reward}))
  	return true
  end
a35233c6   zhouhaihai   保底和回馈
1138
  
1a0b3c56   liuzujun   抽卡保底,切换定向卡池
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
  function _M.unlockPoolRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
  	if not role:isFuncUnlock(FuncUnlock.GetHero) then return end
  	local type = msg.type -- 指定定向卡池需要类型  1, 2, 3
  	local needCost = true
  	--当前开启的类型不用解锁
  	if role:isTimeResetOpen(TimeReset["DrawType" .. type]) then
  		needCost = false
  	end
  	--已经解锁的不需要重复解锁
  	local unlockPool = role.dailyData:getProperty("unlockPool")
  	if unlockPool[type] then
  		needCost = false
  	end
  
  	if needCost then
fb3d084d   liuzujun   月卡赛季卡发送邮件奖励
1157
  		if not role:costDiamond({count = globalCsv.draw_unlock_pool_diamond or 300, log = {desc = "unlockPool", short1 = type}}) then
1a0b3c56   liuzujun   抽卡保底,切换定向卡池
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
  			return
  		end
  	end
  
  	unlockPool[type] = 1
  	role.dailyData:updateProperty({field="unlockPool", value = unlockPool})
  	role.dailyData:updateProperty({field="curPool", value = type})
  
  	role:log("hero_action", {desc = "unlockPool", short1=type})
  	SendPacket(actionCodes.Hero_unlockPoolRpc, MsgPack.pack({}))
  	return true
  end
  
0a07bdd9   zhouahaihai   角色升级 。gm
1171
  return _M