Blame view

src/actions/HangAction.lua 20.2 KB
384bb077   zhouahaihai   挂机
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  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
  local table_unpack = table.unpack
  
  local _M = {}
  
  local function checkReward(role)
  	local hangInfo = role:getProperty("hangInfo")
  	if not hangInfo.carbonId or not hangInfo.coinTime or not hangInfo.itemTime then
024370be   liuzujun   双倍掉掉落bug
22
  		return false
384bb077   zhouahaihai   挂机
23
24
  	end
  	local carbonData = csvdb["idle_battleCsv"][hangInfo.carbonId]
8cd3770f   liuzujun   挂机关卡可以选择,经验金币根据最高...
25
  	local expCarbonData = csvdb["idle_battleCsv"][hangInfo.expCarbonId]
bcf5bfbb   zhouahaihai   挂机new
26
27
  	local nowCoinTime = math.min(skynet.timex(), hangInfo.endCoinTime or 0)
  	local nowItemTime = math.min(skynet.timex(), hangInfo.endItemTime or 0)
384bb077   zhouahaihai   挂机
28
  
706b517e   liuzujun   翻倍掉落活动,商城免费宝箱
29
30
31
  	-- 此次挂机,其中翻倍时长占多少
  	local doubleTime = role.activity:getActHangDoubleTime(hangInfo.coinTime, nowCoinTime)
  	local normalTime = nowCoinTime - hangInfo.coinTime - doubleTime
384bb077   zhouahaihai   挂机
32
  
706b517e   liuzujun   翻倍掉落活动,商城免费宝箱
33
34
35
36
  	local coinCount = math.max(0, math.floor((normalTime) / globalCsv.idle_money_produce_cd))
  	local coinDoubleCount = math.max(0, math.floor((doubleTime) / globalCsv.idle_money_produce_cd)) * 2
  	hangInfo.coinTime = nowCoinTime
  
024370be   liuzujun   双倍掉掉落bug
37
  	normalTime = nowItemTime - hangInfo.itemTime
706b517e   liuzujun   翻倍掉落活动,商城免费宝箱
38
  	local itemCount = math.max(0, math.floor((normalTime) / globalCsv.idle_item_produce_cd))
706b517e   liuzujun   翻倍掉落活动,商城免费宝箱
39
  	hangInfo.itemTime = nowItemTime
384bb077   zhouahaihai   挂机
40
41
  
  	local items = role:getProperty("hangBag")
706b517e   liuzujun   翻倍掉落活动,商城免费宝箱
42
  	coinCount = coinCount + coinDoubleCount
8cd3770f   liuzujun   挂机关卡可以选择,经验金币根据最高...
43
44
45
  	items[ItemId.Gold] = math.floor((items[ItemId.Gold] or 0) + coinCount * expCarbonData.money)
  	items[ItemId.Exp] = math.floor((items[ItemId.Exp] or 0) + coinCount * expCarbonData.exp)
  	items[ItemId.PlayerExp] = math.floor((items[ItemId.PlayerExp] or 0) + coinCount * expCarbonData.playerExp)
384bb077   zhouahaihai   挂机
46
47
48
49
50
  
  	local pool = {}
  	for _, temp in pairs(carbonData.item:toArray()) do
  		table.insert(pool, temp:toArray(true, "="))
  	end
64e63ad0   wangyujie   完成需求:挂机栏位物品数量上限和钻...
51
52
53
  	local curFC = 0
  	local curIC = 0
  	for id, count in pairs(items) do
bcf5bfbb   zhouahaihai   挂机new
54
  		if id ~= ItemId.Gold and id ~= ItemId.Exp and id ~= ItemId.PlayerExp then
64e63ad0   wangyujie   完成需求:挂机栏位物品数量上限和钻...
55
56
  			curFC = curFC + math.ceil(count / globalCsv.idle_field_limit)
  			curIC = curIC + count
9962b061   zhouahaihai   补充 挂机
57
58
  		end
  	end
317a46a9   liuzujun   添加特权卡
59
60
61
  
  	-- 特权卡挂机额外栏位
  	local privExtraCnt = role.storeData:getHangSlotExtraCount()
460afa6e   liuzujun   付费签到改为主动领取,战斗关卡不一...
62
63
  	--local selfFC = role:getProperty("hangBagLimit") + privExtraCnt
  	local selfFC = 50
64e63ad0   wangyujie   完成需求:挂机栏位物品数量上限和钻...
64
65
66
67
68
69
70
71
72
  	local selfIC = selfFC * globalCsv.idle_field_limit
  
  	local function randomItem()
  		if curIC >= selfIC then
  			return
  		end
  		local tempPool = clone(pool)
  		while #tempPool > 0 do
  			local idx = math.randWeight(tempPool, 3)
024370be   liuzujun   双倍掉掉落bug
73
  			local cur = clone(pool[idx])
93f6e69b   liuzujun   拾荒选择时间,抽卡增加sr保底
74
  			if cur[1] ~= 0 then  -- 轮空 id
024370be   liuzujun   双倍掉掉落bug
75
76
  				if cur[1] == ItemId.BreakCost and doubleTime > 0 then
  					cur[2] = cur[2] * 2
64e63ad0   wangyujie   完成需求:挂机栏位物品数量上限和钻...
77
  				end
024370be   liuzujun   双倍掉掉落bug
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  				if (items[cur[1]] and math.ceil((items[cur[1]] + cur[2]) / globalCsv.idle_field_limit) > math.ceil(items[cur[1]] / globalCsv.idle_field_limit))
  						or not items[cur[1]] then	--要占用新栏位的情况
  					local addFC
  					if not items[cur[1]] then
  						addFC = math.ceil(cur[2] / globalCsv.idle_field_limit)
  					else
  						local frontC = items[cur[1]] % globalCsv.idle_field_limit
  						if frontC == 0 then
  							frontC = globalCsv.idle_field_limit
  						end
  						addFC = math.ceil((cur[2] - (globalCsv.idle_field_limit - frontC)) / globalCsv.idle_field_limit)
  					end
  					if curFC + addFC <= selfFC then
  						curFC = curFC + addFC
  						items[cur[1]] = (items[cur[1]] or 0) + cur[2]
  						break
  					else
  						--加不了,换别的东西
  						table.remove(tempPool, idx)
  					end
64e63ad0   wangyujie   完成需求:挂机栏位物品数量上限和钻...
98
  				else
024370be   liuzujun   双倍掉掉落bug
99
100
  					items[cur[1]] = items[cur[1]] + cur[2]
  					break
64e63ad0   wangyujie   完成需求:挂机栏位物品数量上限和钻...
101
102
  				end
  			else
64e63ad0   wangyujie   完成需求:挂机栏位物品数量上限和钻...
103
  				break
9962b061   zhouahaihai   补充 挂机
104
  			end
9962b061   zhouahaihai   补充 挂机
105
  		end
64e63ad0   wangyujie   完成需求:挂机栏位物品数量上限和钻...
106
107
  		curIC = curIC + 1
  	end
024370be   liuzujun   双倍掉掉落bug
108
  
64e63ad0   wangyujie   完成需求:挂机栏位物品数量上限和钻...
109
110
  	for i = 1, itemCount do
  		randomItem()
384bb077   zhouahaihai   挂机
111
112
113
  	end
  
  	if coinCount > 0 or itemCount > 0 then
5af8b4aa   zhouahaihai   挂机down
114
  		return true
384bb077   zhouahaihai   挂机
115
  	end
024370be   liuzujun   双倍掉掉落bug
116
117
  
  	return false
384bb077   zhouahaihai   挂机
118
119
  end
  
384bb077   zhouahaihai   挂机
120
121
122
123
124
125
  --开始一个新的关卡
  function _M.startRpc( agent, data )
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local carbonId = msg.carbonId
  	local carbonData = csvdb["idle_battleCsv"][carbonId]
f60b89b1   zhouhaihai   奖励副本
126
  	if not carbonData then return 1 end
384bb077   zhouahaihai   挂机
127
  
d232676a   zhouhaihai   功能解锁 冒险返回
128
129
130
131
  	if math.floor(carbonId / 10000) ~= 1 then
  		if not role:isFuncUnlock(FuncUnlock.DifficultHang) then return end
  	end
  
5d80aca6   zhouahaihai   挂机优化
132
133
  
  	for _, preCarbonId in ipairs(carbonData.prepose:toArray(true, "=")) do
33be3111   zhouhaihai   修改hangPass 结构
134
  		if not role:checkHangPass(preCarbonId) then return 2 end
5d80aca6   zhouahaihai   挂机优化
135
  	end
384bb077   zhouahaihai   挂机
136
  
5af8b4aa   zhouahaihai   挂机down
137
138
139
  	if checkReward(role) then
  		role:updateProperty({field = "hangBag", value = role:getProperty("hangBag")})
  	end
384bb077   zhouahaihai   挂机
140
141
  
  	local hangInfo = role:getProperty("hangInfo")
5af8b4aa   zhouahaihai   挂机down
142
  	local isNew = not hangInfo.carbonId
384bb077   zhouahaihai   挂机
143
  	hangInfo.carbonId = carbonId
8cd3770f   liuzujun   挂机关卡可以选择,经验金币根据最高...
144
  	hangInfo.expCarbonId = isNew and carbonId or hangInfo.expCarbonId
384bb077   zhouahaihai   挂机
145
  	local nowTime = skynet.timex()
5af8b4aa   zhouahaihai   挂机down
146
  	if isNew then
1103490d   zhouhaihai   设置 国家时间错误
147
148
  		hangInfo.coinTime = nowTime
  		hangInfo.itemTime = nowTime
bcf5bfbb   zhouahaihai   挂机new
149
150
  		hangInfo.endCoinTime = nowTime + globalCsv.idle_producetime_max
  		hangInfo.endItemTime = nowTime + globalCsv.idle_producetime_max
1103490d   zhouhaihai   设置 国家时间错误
151
152
153
  	else
  		hangInfo.coinTime = math.min(nowTime, hangInfo.endCoinTime)
  		hangInfo.itemTime = math.min(nowTime, hangInfo.endItemTime)
5af8b4aa   zhouahaihai   挂机down
154
  	end
072db127   zhouhaihai   推送
155
156
  
  	role:pushMsg({type = "hang", time = math.min(hangInfo.endCoinTime - nowTime, hangInfo.endItemTime - nowTime)})
33be3111   zhouhaihai   修改hangPass 结构
157
  	if not role:checkHangPass(carbonId) then
5af8b4aa   zhouahaihai   挂机down
158
159
160
  		hangInfo.bossTime = nowTime + carbonData.idle_time
  	else
  		hangInfo.bossTime = nil
384bb077   zhouahaihai   挂机
161
  	end
072db127   zhouhaihai   推送
162
  
384bb077   zhouahaihai   挂机
163
164
  	role:updateProperty({field = "hangInfo", value = hangInfo})
  
d02f7904   zhouhaihai   遗失的log
165
  	role:mylog("hang_action", {desc = "startHang", int1 = carbonId})
384bb077   zhouahaihai   挂机
166
167
168
169
170
171
172
173
  	SendPacket(actionCodes.Hang_startRpc, '')
  	return true
  end
  
  -- 每隔1分钟检查一次
  function _M.checkRpc(agent, data)
  	local role = agent.role
  	-- local msg = MsgPack.unpack(data)
5af8b4aa   zhouahaihai   挂机down
174
175
176
177
  	if checkReward(role) then
  		role:updateProperty({field = "hangBag", value = role:getProperty("hangBag")})
  		role:updateProperty({field = "hangInfo", value = role:getProperty("hangInfo")})
  	end
384bb077   zhouahaihai   挂机
178
179
180
181
  	SendPacket(actionCodes.Hang_checkRpc, MsgPack.pack({}))
  	return true
  end
  
cc5ca7f3   zhouhaihai   缓存battleKey
182
  local _BattleKey = nil
384bb077   zhouahaihai   挂机
183
184
185
  function _M.startBattleRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
bcf5bfbb   zhouahaihai   挂机new
186
187
  	local carbonId = msg.carbonId
  	local curData = csvdb["idle_battleCsv"][carbonId]
a1e08c9c   zhengshouren   宝箱关战斗异常
188
189
190
  	if not curData then 
  		return 1
  	end
bcf5bfbb   zhouahaihai   挂机new
191
  
460afa6e   liuzujun   付费签到改为主动领取,战斗关卡不一...
192
193
194
195
196
197
  	--local hangInfo = role:getProperty("hangInfo") or {}
  	--if curData.main ~= 1 then
  	--	if carbonId ~= hangInfo.carbonId then 
  	--		return 2
  	--	end
  	--end
bcf5bfbb   zhouahaihai   挂机new
198
  
33be3111   zhouhaihai   修改hangPass 结构
199
  	if role:checkHangPass(carbonId) then 
a1e08c9c   zhengshouren   宝箱关战斗异常
200
201
  		return 3
  	end
bcf5bfbb   zhouahaihai   挂机new
202
  
cc5ca7f3   zhouhaihai   缓存battleKey
203
204
  	_BattleKey = tostring(math.random())
  
53e8037e   zhouhaihai   任务
205
  	role:checkTaskEnter("HangBattle", {id = carbonId})
52c87300   zhouhaihai   bug
206
  	SendPacket(actionCodes.Hang_startBattleRpc, MsgPack.pack({key = _BattleKey}))
384bb077   zhouahaihai   挂机
207
208
209
210
211
212
  	return true
  end
  
  function _M.endBattleRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
8cd3770f   liuzujun   挂机关卡可以选择,经验金币根据最高...
213
  	local hangInfo = role:getProperty("hangInfo") or {}
cc5ca7f3   zhouhaihai   缓存battleKey
214
  	if not msg.key or msg.key ~= _BattleKey then 
d6a66c74   zhouhaihai   校验失败也返回
215
216
  		SendPacket(actionCodes.Hang_endBattleRpc, MsgPack.pack({errorCode = 1}))
  		return true
4906ebd2   zhengshouren   宝箱关副本结算异常
217
  	end
bcf5bfbb   zhouahaihai   挂机new
218
  	local carbonId = msg.carbonId
d4e9b817   zhouhaihai   战斗 日志
219
  	local isWin = msg.starNum and msg.starNum > 0
bcf5bfbb   zhouahaihai   挂机new
220
  	local carbonData = csvdb["idle_battleCsv"][carbonId]
4906ebd2   zhengshouren   宝箱关副本结算异常
221
222
223
  	if not carbonData then
  		return 2
  	end
8cd3770f   liuzujun   挂机关卡可以选择,经验金币根据最高...
224
  
460afa6e   liuzujun   付费签到改为主动领取,战斗关卡不一...
225
226
227
228
229
  	--if carbonData.main ~= 1 then
  	--	if carbonId ~= hangInfo.carbonId then 
  	--		return 3
  	--	end
  	--end
33be3111   zhouhaihai   修改hangPass 结构
230
231
  
  	if role:checkHangPass(carbonId) then 
4906ebd2   zhengshouren   宝箱关副本结算异常
232
233
  		return 4
  	end
d4e9b817   zhouhaihai   战斗 日志
234
  
7bb30dca   zhouhaihai   修改发奖
235
  	local reward, change
d4e9b817   zhouhaihai   战斗 日志
236
  	if isWin then --win
33be3111   zhouhaihai   修改hangPass 结构
237
  		role:hangFinish(carbonId)
bcf5bfbb   zhouahaihai   挂机new
238
239
240
  		if carbonData.main ~= 1 then
  			hangInfo.bossTime = nil
  		end
384bb077   zhouahaihai   挂机
241
242
  		-- reward
  		reward = {}
384bb077   zhouahaihai   挂机
243
244
  		reward[ItemId.Gold] = carbonData.money_clear
  		reward[ItemId.Exp] = carbonData.exp_clear
00115a7a   zhouahaihai   奖励发放
245
  		reward[ItemId.PlayerExp] = carbonData.playerExp_clear
384bb077   zhouahaihai   挂机
246
  		for itemId, count in pairs(carbonData.item_clear:toNumMap()) do
384bb077   zhouahaihai   挂机
247
248
  			reward[itemId] = count
  		end
7bb30dca   zhouhaihai   修改发奖
249
  		reward, change = role:award(reward, {log = {desc = "hangBattle", int1 = carbonId}})
00e663bd   zhouhaihai   剧情相关
250
  
03a6166a   zhouhaihai   餐厅优化
251
  		role:checkTaskEnter("HangPass", {id = carbonId})
286c980a   chenyueqi   挂机战斗胜利才触发对应的引导
252
253
254
  		
  		-- 引导
  		if carbonId == 10101 then
a5b98c30   chenyueqi   引导调整
255
  			role:finishGuide(6)
be0c7a19   chenyueqi   挂机打完困难20101才设定完成引导22
256
  		elseif carbonId == 20101 then
286c980a   chenyueqi   挂机战斗胜利才触发对应的引导
257
258
259
260
261
262
263
264
  			role:finishGuide(22)
  		end
  		for _, guideData in pairs(csvdb["guide_unlockCsv"]) do
  			if guideData.type == 3 and guideData.carbonId == carbonId then
  				role:saveGuide(guideData.guideId,1,true)
  				break
  			end
  		end
384bb077   zhouahaihai   挂机
265
  	end
53b4b8bd   liuzujun   自动挂机下一关
266
267
  	local nextCarbonId = role:getNextCarbonId(carbonId)
  	-- 设置挂机关卡
8cd3770f   liuzujun   挂机关卡可以选择,经验金币根据最高...
268
269
  	if isWin and (hangInfo.carbonId or 0) < nextCarbonId then
  		hangInfo.expCarbonId = nextCarbonId
e0290d8e   liuzujun   修改引导, 抽卡阶段奖励修改
270
271
272
  		local cfg = csvdb["idle_battleCsv"][nextCarbonId]
  		if cfg then
  			hangInfo.bossTime = skynet.timex() + cfg.idle_time
e0290d8e   liuzujun   修改引导, 抽卡阶段奖励修改
273
  		end
93f6e69b   liuzujun   拾荒选择时间,抽卡增加sr保底
274
  	end
384bb077   zhouahaihai   挂机
275
  	role:updateProperty({field = "hangInfo", value = hangInfo})
33be3111   zhouhaihai   修改hangPass 结构
276
  	
d4e9b817   zhouhaihai   战斗 日志
277
278
279
280
281
282
  	role:checkBattle("hang", {
  		id = carbonId,
  		isWin = isWin,
  		info = msg.info,
  		reward = reward,
  	})
1e9cb217   chenyueqi   服务器记录控制引导过程
283
  
d02f7904   zhouhaihai   遗失的log
284
285
286
  	local team = role:getProperty("pvpTC")
  	role:mylog("hang_action", {desc = "hangBattle", short1 = msg.starNum > 0 and 1 or 0, int1 = carbonId, int2 = role:getProperty("hangTBV"), cint1 = role:getHerosCamp(team.heros)})
  
384bb077   zhouahaihai   挂机
287
288
289
  	SendPacket(actionCodes.Hang_endBattleRpc, MsgPack.pack({
  		starNum = msg.starNum, 
  		reward = reward,
7bb30dca   zhouhaihai   修改发奖
290
  		change = change,
384bb077   zhouahaihai   挂机
291
292
293
294
  		}))
  	return true
  end
  
7efe5275   zhouhaihai   检查leader
295
296
297
298
299
300
301
  local function checkLeader(heros, leader)
  	if not leader then return end
  	for slot, heroId in pairs(heros) do
  		if heroId == leader then return true end
  	end
  end
  
384bb077   zhouahaihai   挂机
302
303
304
  function _M.roleFormatRpc(agent , data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
384bb077   zhouahaihai   挂机
305
306
307
  	local hangTeam = role:getProperty("hangTeam")
  	for slot, heroId in pairs(msg.heros) do
  		if not role.heros[heroId] then
e6ebee44   zhouhaihai   编队bug
308
  			return 1
384bb077   zhouahaihai   挂机
309
310
  		end
  	end
f603a60f   zhouhaihai   支援技实装
311
312
313
  
  	local supports = {}
  	for slot, support in pairs(msg.supports or {}) do
e6ebee44   zhouhaihai   编队bug
314
  		if slot ~= 1 and slot ~= 2 then return 2 end
f603a60f   zhouhaihai   支援技实装
315
  		local level = role.dinerData:getProperty("dishTree"):getv(support, 0)
e6ebee44   zhouhaihai   编队bug
316
  		if level <= 0 then return 3 end
f603a60f   zhouhaihai   支援技实装
317
318
  		supports[slot] = support
  	end
e6ebee44   zhouhaihai   编队bug
319
  	if not checkLeader(msg.heros, msg.leader) then return 4 end
f603a60f   zhouhaihai   支援技实装
320
  
384bb077   zhouahaihai   挂机
321
322
323
324
325
326
  	table.clear(hangTeam)
  	hangTeam.heros = {}
  	for slot, heroId in pairs(msg.heros) do
  		hangTeam.heros[slot] = heroId
  	end
  	hangTeam.leader = msg.leader
f603a60f   zhouhaihai   支援技实装
327
  	hangTeam.supports = supports
fa565e0c   zhouhaihai   优化结构
328
  	role:saveHangTeam(hangTeam)
a5b98c30   chenyueqi   引导调整
329
  	role:finishGuide(5)
384bb077   zhouahaihai   挂机
330
331
332
333
  	SendPacket(actionCodes.Hang_roleFormatRpc, '')
  	return true
  end
  
5af8b4aa   zhouahaihai   挂机down
334
335
336
337
338
  function _M.getRewardRpc(agent , data)
  	local role = agent.role
  	checkReward(role)
  	local items = role:getProperty("hangBag")
  	if not next(items) then return end
7bb30dca   zhouhaihai   修改发奖
339
  	local reward, change = role:award(items, {log = {desc = "hangReward"}})
5af8b4aa   zhouahaihai   挂机down
340
341
342
  	table.clear(items)
  	local hangInfo = role:getProperty("hangInfo")
  	local nowTime = skynet.timex()
bcf5bfbb   zhouahaihai   挂机new
343
344
  	hangInfo.endItemTime = nowTime + globalCsv.idle_producetime_max
  	hangInfo.endCoinTime = nowTime + globalCsv.idle_producetime_max
5af8b4aa   zhouahaihai   挂机down
345
346
347
348
  	hangInfo.coinTime = nowTime
  	hangInfo.itemTime = nowTime
  	role:updateProperty({field = "hangBag", value = items})
  	role:updateProperty({field = "hangInfo", value = hangInfo})
072db127   zhouhaihai   推送
349
350
  	role:pushMsg({type = "hang", time = globalCsv.idle_producetime_max})
  	
190e1415   liuzujun   英雄帖活动初始化
351
  	role:checkTaskEnter("HangGet", {reward = reward})
53e8037e   zhouhaihai   任务
352
353
  	if reward[ItemId.Gold] then
  		role:checkTaskEnter("HangGetGold", {count = reward[ItemId.Gold]})
bcf5bfbb   zhouahaihai   挂机new
354
  	end
d43246b0   zhouhaihai   log 增加
355
356
357
358
359
360
361
362
363
364
365
  
  	role:log("residence_reward", {
  		mission_threadid = math.floor(hangInfo.carbonId / 10000), --大关卡ID
  		mission_id = hangInfo.carbonId, --关卡ID
  		mission_type = 100, --关卡类型,见关卡类型枚举表
  		residence_reward_type = 0, --领取奖励方式,快速(超前领取)记录为1,正常领取记录为0
  		residence_time = 0, --挂机或排名时长
  		residence_reward = reward, --获得奖励,建议使用json格式记录。示例:{ "XX": "1", "XXX": "3"}
  	})
  	
  
53e8037e   zhouhaihai   任务
366
  	SendPacket(actionCodes.Hang_getRewardRpc, MsgPack.pack({
7bb30dca   zhouhaihai   修改发奖
367
368
  		reward = reward,
  		change = change
bcf5bfbb   zhouahaihai   挂机new
369
370
371
372
  	}))
  	return true
  end
  
9962b061   zhouahaihai   补充 挂机
373
374
375
376
377
378
  function _M.quickRpc(agent , data)
  	local role = agent.role
  
  	local hangInfo = role:getProperty("hangInfo")
  	if not hangInfo.carbonId then return end
  	local carbonData = csvdb["idle_battleCsv"][hangInfo.carbonId]
8cd3770f   liuzujun   挂机关卡可以选择,经验金币根据最高...
379
  	local expCarbonData = csvdb["idle_battleCsv"][hangInfo.expCarbonId]
9962b061   zhouahaihai   补充 挂机
380
381
382
383
384
385
  
  	local curCount = role.dailyData:getProperty("hangQC") + 1
  	local costs = globalCsv.idle_quickproduce_cost:toArray(true, "=")
  	if not costs[curCount] then return end
  	if costs[curCount] > 0 then
  		if not role:checkItemEnough({[ItemId.Diamond] = costs[curCount]}) then return end
3133cb76   zhouhaihai   日志
386
  		role:costItems({[ItemId.Diamond] = costs[curCount]}, {log = {desc = "quickHang", int1 = hangInfo.carbonId}})
9962b061   zhouahaihai   补充 挂机
387
388
389
390
391
392
393
394
395
  	end
  
  	role.dailyData:updateProperty({field = "hangQC", value = curCount})
  
  	local time = globalCsv.idle_quickproduce_time
  	local reward = {}
  
  	local coinCount = math.floor(time / globalCsv.idle_money_produce_cd)
  	local itemCount = math.floor(time / globalCsv.idle_item_produce_cd)
8cd3770f   liuzujun   挂机关卡可以选择,经验金币根据最高...
396
397
398
  	reward[ItemId.Gold] = math.floor((reward[ItemId.Gold] or 0) + coinCount * expCarbonData.money)
  	reward[ItemId.Exp] = math.floor((reward[ItemId.Exp] or 0) + coinCount * expCarbonData.exp)
  	reward[ItemId.PlayerExp] = math.floor((reward[ItemId.PlayerExp] or 0) + coinCount * expCarbonData.playerExp)
9962b061   zhouahaihai   补充 挂机
399
400
401
402
403
404
405
406
407
  
  	local pool = {}
  	for _, temp in pairs(carbonData.item:toArray()) do
  		table.insert(pool, temp:toArray(true, "="))
  	end
  	for i = 1, itemCount do
  		local cur = pool[math.randWeight(pool, 3)]
  		reward[cur[1]] = (reward[cur[1]] or 0) + cur[2]
  	end
317a46a9   liuzujun   添加特权卡
408
  
9e1a93c2   liuzujun   快速挂机掉落浮点数取整
409
  	local doubleCoef = role.activity:isOpen("DoubleDrop") and 2 or 1
317a46a9   liuzujun   添加特权卡
410
411
  	-- 特权卡获取加速获得额外道具
  	local coef = role.storeData:getProduceItemSpeedCoef()
accf94c4   liuzujun   活动以类型标识,修改双倍活动bug
412
  	if coef > 1 or doubleCoef > 1 then
317a46a9   liuzujun   添加特权卡
413
  		for k, cnt in pairs(reward) do
9e1a93c2   liuzujun   快速挂机掉落浮点数取整
414
  			reward[k] = math.floor(cnt * coef * doubleCoef)
317a46a9   liuzujun   添加特权卡
415
416
417
  		end
  	end
  
7bb30dca   zhouhaihai   修改发奖
418
419
  	local change
  	reward, change = role:award(reward, {log = {desc = "quickHang", int1 = hangInfo.carbonId}})
f60b89b1   zhouhaihai   奖励副本
420
421
422
  	if reward[ItemId.Gold] then
  		role:checkTaskEnter("HangGetGold", {count = reward[ItemId.Gold]})
  	end
53e8037e   zhouhaihai   任务
423
  	role:checkTaskEnter("HangQuick")
d43246b0   zhouhaihai   log 增加
424
425
426
427
428
429
430
431
432
  
  	role:log("residence_reward", {
  		mission_threadid = math.floor(hangInfo.carbonId / 10000), --大关卡ID
  		mission_id = hangInfo.carbonId, --关卡ID
  		mission_type = 100, --关卡类型,见关卡类型枚举表
  		residence_reward_type = 1, --领取奖励方式,快速(超前领取)记录为1,正常领取记录为0
  		residence_time = time, --挂机或排名时长
  		residence_reward = reward, --获得奖励,建议使用json格式记录。示例:{ "XX": "1", "XXX": "3"}
  	})
9962b061   zhouahaihai   补充 挂机
433
  	SendPacket(actionCodes.Hang_quickRpc, MsgPack.pack({
7bb30dca   zhouhaihai   修改发奖
434
435
  		reward = reward,
  		change = change
9962b061   zhouahaihai   补充 挂机
436
437
438
439
  	}))
  	return true
  end
  
f60b89b1   zhouhaihai   奖励副本
440
441
442
443
444
445
446
447
448
  function _M.bonusFormatRpc(agent , data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local bTeam = role:getProperty("bTeam")
  	for slot, heroId in pairs(msg.heros) do
  		if not role.heros[heroId] then
  			return
  		end
  	end
f603a60f   zhouhaihai   支援技实装
449
450
451
452
453
454
455
  	local supports = {}
  	for slot, support in pairs(msg.supports) do
  		if slot ~= 1 and slot ~= 2 then return end
  		local level = role.dinerData:getProperty("dishTree"):getv(support, 0)
  		if level <= 0 then return end
  		supports[slot] = support
  	end
7efe5275   zhouhaihai   检查leader
456
457
  	if not checkLeader(msg.heros, msg.leader) then return end
  	
f60b89b1   zhouhaihai   奖励副本
458
459
460
461
462
463
  	table.clear(bTeam)
  	bTeam.heros = {}
  	for slot, heroId in pairs(msg.heros) do
  		bTeam.heros[slot] = heroId
  	end
  	bTeam.leader = msg.leader
f603a60f   zhouhaihai   支援技实装
464
  	bTeam.supports = supports
f60b89b1   zhouhaihai   奖励副本
465
466
467
468
469
470
471
472
473
474
475
476
477
  
  	role:updateProperty({field = "bTeam", value = bTeam}) 
  	SendPacket(actionCodes.Hang_bonusFormatRpc, '')
  	return true
  end
  
  function _M.buyBonusCountRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
  	local count = msg.count
  	local btype = msg.type
  
3133cb76   zhouhaihai   日志
478
  	if not TimeReset["DailyBattle" .. btype] then return end
accf94c4   liuzujun   活动以类型标识,修改双倍活动bug
479
480
  	local open, actId = role.activity:isOpen("BonusDouble")
  	local actData = csvdb["activity_ctrlCsv"][actId]
accf94c4   liuzujun   活动以类型标识,修改双倍活动bug
481
  
a526f9ef   liuzujun   奖励关卡活动未开启导致Bug
482
483
484
485
  	local coef = 1
  	if open and actData then
  		coef= tonumber(actData.condition2)
  	end
f60b89b1   zhouhaihai   奖励副本
486
487
488
  
  	local bonusC = role.dailyData:getProperty("bonusC")
  	bonusC[btype] = bonusC[btype] or {c = 0, b = 0}
accf94c4   liuzujun   活动以类型标识,修改双倍活动bug
489
  	local lastCount = globalCsv.bonus_daily_buy_count * coef - bonusC[btype]["b"]
f60b89b1   zhouhaihai   奖励副本
490
491
  	if math.illegalNum(count, 1, lastCount)  then return 1 end
  
3133cb76   zhouhaihai   日志
492
  	if not role:checkItemEnough({[ItemId.Diamond] = globalCsv.bonus_buy_cost * count}) then return 2 end
f60b89b1   zhouhaihai   奖励副本
493
  
887c1843   zhouhaihai   日志新一批
494
  	role:costItems({[ItemId.Diamond] = globalCsv.bonus_buy_cost * count}, {log = {desc = "buyBonusCount", int1 = btype, int2 = count}})
d481965d   zhouhaihai   购买次数bug
495
496
  	bonusC[btype]["b"] = bonusC[btype]["b"] + count
  	bonusC[btype]["c"] = bonusC[btype]["c"] - count
f60b89b1   zhouhaihai   奖励副本
497
498
499
500
501
502
503
504
505
506
507
508
  
  	role.dailyData:updateProperty({field = "bonusC", value = bonusC})
  
  	SendPacket(actionCodes.Hang_buyBonusCountRpc, '')
  	return true
  end
  
  function _M.startBonusBattleRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local id = msg.id
  
accf94c4   liuzujun   活动以类型标识,修改双倍活动bug
509
510
511
  	local open, actId = role.activity:isOpen("BonusDouble")
  
  	if not role:isFuncUnlock(FuncUnlock.BonusBattle) then return 1 end
d232676a   zhouhaihai   功能解锁 冒险返回
512
  
f60b89b1   zhouhaihai   奖励副本
513
  	local bonusData = csvdb["bonus_battleCsv"][id]
bc902e2d   zhouhaihai   增加开放判断
514
  
accf94c4   liuzujun   活动以类型标识,修改双倍活动bug
515
516
517
  	if not open then
  		if not role:isTimeResetOpen(TimeReset["DailyBattle" .. bonusData.type]) then return 2 end
  	end
bc902e2d   zhouhaihai   增加开放判断
518
  
accf94c4   liuzujun   活动以类型标识,修改双倍活动bug
519
520
  	if not bonusData then return 3 end
  	if not role:checkHangPass(bonusData.unlock) then return 4 end
f60b89b1   zhouhaihai   奖励副本
521
  
accf94c4   liuzujun   活动以类型标识,修改双倍活动bug
522
  	if not next(role:getProperty("bTeam")) then return 5 end
f60b89b1   zhouhaihai   奖励副本
523
524
525
  
  	local bonusC = role.dailyData:getProperty("bonusC")
  	bonusC[bonusData.type] = bonusC[bonusData.type] or {c = 0, b = 0}
accf94c4   liuzujun   活动以类型标识,修改双倍活动bug
526
527
  
  	local actData = csvdb["activity_ctrlCsv"][actId]
accf94c4   liuzujun   活动以类型标识,修改双倍活动bug
528
  
a526f9ef   liuzujun   奖励关卡活动未开启导致Bug
529
530
531
532
  	local coef = 1
  	if open and actData then
  		coef = tonumber(actData.condition2)
  	end
accf94c4   liuzujun   活动以类型标识,修改双倍活动bug
533
534
  
  	if globalCsv.bonus_daily_count * coef - bonusC[bonusData.type]["c"] <= 0 then return 7 end
f60b89b1   zhouhaihai   奖励副本
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
  
  
  	role.__bonusBattleCache = {
  		key = tostring(math.random()),
  		id = id,
  	}
  	SendPacket(actionCodes.Hang_startBonusBattleRpc, MsgPack.pack({key = role.__bonusBattleCache.key}))
  	return true
  end
  
  function _M.endBonusBattleRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local id = msg.id
  	local key = msg.key
  	local starNum = msg.starNum
  	if not role.__bonusBattleCache then return 1 end
accf94c4   liuzujun   活动以类型标识,修改双倍活动bug
552
553
  	local open, actId = role.activity:isOpen("BonusDouble")
  	local actData = csvdb["activity_ctrlCsv"][actId]
accf94c4   liuzujun   活动以类型标识,修改双倍活动bug
554
  
a526f9ef   liuzujun   奖励关卡活动未开启导致Bug
555
556
557
558
  	local coef = 1
  	if open and actData then
  		coef = tonumber(actData.condition2)
  	end
f60b89b1   zhouhaihai   奖励副本
559
  
d6a66c74   zhouhaihai   校验失败也返回
560
561
562
563
  	if role.__bonusBattleCache.id ~= id or role.__bonusBattleCache.key ~= key then 
  		SendPacket(actionCodes.Hang_endBonusBattleRpc, MsgPack.pack({errorCode = 1}))
  		return true
  	end
f60b89b1   zhouhaihai   奖励副本
564
565
  	local bonusData = csvdb["bonus_battleCsv"][id]
  
7bb30dca   zhouhaihai   修改发奖
566
  	local reward, change
f60b89b1   zhouhaihai   奖励副本
567
   	if starNum and starNum > 0 then
74a8fdc9   zhouhaihai   奖励副本 胜利扣除次数
568
569
570
   		-- 胜利扣除次数
   		local bonusC = role.dailyData:getProperty("bonusC")
  		bonusC[bonusData.type] = bonusC[bonusData.type] or {c = 0, b = 0}
accf94c4   liuzujun   活动以类型标识,修改双倍活动bug
571
  		if globalCsv.bonus_daily_count * coef - bonusC[bonusData.type]["c"] <= 0 then return 3 end
74a8fdc9   zhouhaihai   奖励副本 胜利扣除次数
572
573
574
  		bonusC[bonusData.type]["c"] = bonusC[bonusData.type]["c"] + 1
  		role.dailyData:updateProperty({field = "bonusC", value = bonusC})
  
b2747fbc   zhouhaihai   挂机
575
576
577
578
579
  		reward = bonusData.reward:toNumMap()
  		local chance = bonusData.chance:randWeight(true)
  		if chance[1] ~= 0 then
  			reward[chance[1]] = (reward[chance[1]] or 0) + chance[2]
  		end
accf94c4   liuzujun   活动以类型标识,修改双倍活动bug
580
581
582
  		for k, v  in pairs(reward) do
  			reward[k] = v * (coef > 1 and actData.condition or 1)
  		end
7bb30dca   zhouhaihai   修改发奖
583
   		reward, change = role:award(reward, {log = {desc = "bonusBattle", int1 = id}})
f60b89b1   zhouhaihai   奖励副本
584
585
586
   		role:checkTaskEnter("BonusPass", {id = id})
   	end
  
d4e9b817   zhouhaihai   战斗 日志
587
588
589
590
591
592
   	role:checkBattle("bonus", {
  		id = id,
  		isWin = starNum and starNum > 0,
  		info = msg.info,
  		reward = reward,
  	})
d02f7904   zhouhaihai   遗失的log
593
594
  	role:mylog("hang_action", {desc = "bonusBattle", short1 = msg.starNum > 0 and 1 or 0, int1 = id})
  
f60b89b1   zhouhaihai   奖励副本
595
596
  	SendPacket(actionCodes.Hang_endBonusBattleRpc, MsgPack.pack({
  		starNum = starNum, 
7bb30dca   zhouhaihai   修改发奖
597
598
599
  		reward = reward,
  		change = change
  	}))
f60b89b1   zhouhaihai   奖励副本
600
601
602
  	return true
  end
  
a6508219   zhouhaihai   挂机奖励
603
604
605
606
607
608
609
610
611
612
613
  function _M.hangGiftRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
  	local id = msg.id
  	local carbonData = csvdb["idle_battleCsv"][id]
  	if not carbonData or carbonData.item_clear_special == "" then return 1 end
  
  	local hangGift = role:getProperty("hangGift")
  	if hangGift[id] then return 2 end
  
7bb30dca   zhouhaihai   修改发奖
614
  	local reward, change = role:award(carbonData.item_clear_special, {log = {desc = "hangGift", int1 = id}})
a6508219   zhouhaihai   挂机奖励
615
616
  
  	role:changeUpdates({{type = "hangGift", field = id, value = 1}})
d02f7904   zhouhaihai   遗失的log
617
  	role:mylog("hang_action", {desc = "hangGift",  int1 = id})
a6508219   zhouhaihai   挂机奖励
618
  
7bb30dca   zhouhaihai   修改发奖
619
  	SendPacket(actionCodes.Hang_hangGiftRpc, MsgPack.pack({reward = reward, change = change}))
a6508219   zhouhaihai   挂机奖励
620
621
  	return true
  end
f60b89b1   zhouhaihai   奖励副本
622
  
64e63ad0   wangyujie   完成需求:挂机栏位物品数量上限和钻...
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
  function _M.bagFieldRpc(agent, data)
  	local role = agent.role
  	local curBL = role:getProperty("hangBagLimit")
  	local costD = globalCsv.idle_field_cost[curBL - globalCsv.idle_field_origin]
  	if not costD then
  		return 1
  	end
  	if costD ~= 0 and not role:checkItemEnough({[ItemId.Diamond] = costD}) then
  		return 2
  	end
  	role:updateProperty({field = "hangBagLimit", value = curBL + 1})
  	role:costItems({[ItemId.Diamond] = costD}, {log = {desc = "bagField"}})
  	SendPacket(actionCodes.Hang_bagFieldRpc, '')
  	return true
  end
f60b89b1   zhouhaihai   奖励副本
638
  
ed20f277   zhouhaihai   chatline 奖励
639
640
641
  function _M.chatLineRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
ed20f277   zhouhaihai   chatline 奖励
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
  	local id = msg.id
  
  	local idleData = csvdb["idle_battleCsv"][id]
  	if not idleData or idleData.chatline == 0 then
  		return
  	end
  
  	local chatline = role:getProperty("chatline")
  	if chatline[id] then return end
  
  	if not role:checkHangPass(id) then return end
  
  	chatline[id] = skynet.timex()
  	role:updateProperty({field = "chatline", value = chatline})
  
7bb30dca   zhouhaihai   修改发奖
657
  	local reward, change = role:award(idleData.chatline_reward, {log = {desc = "chatline", int1 = id}})
ed20f277   zhouhaihai   chatline 奖励
658
  	
7bb30dca   zhouhaihai   修改发奖
659
  	SendPacket(actionCodes.Hang_chatLineRpc, MsgPack.pack({reward = reward, change = change}))
ed20f277   zhouhaihai   chatline 奖励
660
661
662
  	return true
  end
  
384bb077   zhouahaihai   挂机
663
  return _M