Blame view

src/actions/ActivityAction.lua 29.1 KB
d763fb14   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
32
33
34
  local ipairs = ipairs
  local table = table
  local math = math
  local string = string
  local redisproxy = redisproxy
  local MsgPack = MsgPack
  local string_format = string.format
  local tonumber = tonumber
  local table_insert = table.insert
  local table_unpack = table.unpack
  local table_find = table.find
  local table_nums = table.nums
  local math_random = math.randomInt
  
  
  local _M = {}
  
  
  function _M.sudokuRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local id = msg.id
  
  	local sudoku = role:getProperty("sudoku")
  	local phase = sudoku[-1] or 1
  	local curData = (csvdb["guide_sudokuCsv"][phase] or {})[id]
  	if phase == -1 or not curData then return 1 end
  
  	sudoku.task = sudoku.task or {}
  	sudoku.task[phase] = sudoku.task[phase] or {}
  
  	if (sudoku.task[phase][id] or 0) < curData.con1 then return 2 end
  
  	sudoku.task[phase][id] = -1
7bb30dca   zhouhaihai   修改发奖
35
  	local task, tchange = role:award(curData.reward, {log = {desc = "sudoku", int1 = id, int2 = phase}}) -- 任务奖励
d763fb14   zhouhaihai   签到 九宫格
36
  
7bb30dca   zhouhaihai   修改发奖
37
  	local reward, rchange = {}
d763fb14   zhouhaihai   签到 九宫格
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  	local rId = {}
  	for pid, pdata in pairs(csvdb["guide_sudoku_rewardCsv"][phase] or {}) do
  		local pos = pdata.pos:toArray(true, "=")
  		local ok, is = true, false
  		for _, one in pairs(pos) do
  			if one == id then
  				is = true
  			end
  			if sudoku.task[phase][one] ~= -1 then
  				ok = false
  				break
  			end
  		end
  
  		if ok and is then
  			for itemId, count in pairs(pdata.reward:toNumMap()) do
  				reward[itemId] = (reward[itemId] or 0) + count
  			end
  			table.insert(rId, pid)
  		end
  	end
  
  	if not next(reward) then
  		reward = nil
  	else
7bb30dca   zhouhaihai   修改发奖
63
  		reward, rchange = role:award(reward, {log = {desc = "sudokuR", int1 = id, int2 = phase}})
d763fb14   zhouhaihai   签到 九宫格
64
65
66
67
  	end
  
  	role:updateProperty({field = "sudoku", value = sudoku})
  
c59e058b   zhouhaihai   新一批日志记录
68
69
70
  	role:log("activity", {
  		activity_id = id, -- 活动ID(或活动指定任务的ID)
  		activity_type = 0, -- 活动类型,见活动类型枚举表
56c7a1c5   liuzujun   修改报错,下载cv奖励记录字段
71
  		activity_reward = reward or {}, -- 活动奖励,json格式记录,{'itemid1':123,'itemid2':456,………...}
c59e058b   zhouhaihai   新一批日志记录
72
  	})
f22a33af   zhouhaihai   自己的日志
73
  	role:mylog("act_action", {desc = "sudoku", int1 = id, int2 = phase})
d763fb14   zhouhaihai   签到 九宫格
74
  
7bb30dca   zhouhaihai   修改发奖
75
  	SendPacket(actionCodes.Activity_sudokuRpc, MsgPack.pack({task = role:packReward(task, tchange), reward = role:packReward(reward, rchange), rId = rId}))
d763fb14   zhouhaihai   签到 九宫格
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  	return true
  end
  
  function _M.sudokuRewardRpc(agent, data)
  	local role = agent.role
  
  
  	local sudoku = role:getProperty("sudoku")
  	local phase = sudoku[-1] or 1
  
  	local curData = csvdb["guide_sudokuCsv"][phase]
  	if not curData then return end
  	if not globalCsv.guide_sudoku_reward[phase] then return end
  
  	local curTask = (sudoku.task or {})[phase] or {}
  
  	for id, _ in pairs(curData) do
  		if curTask[id] ~= -1 then
  			return
  		end
  	end
  
7bb30dca   zhouhaihai   修改发奖
98
  	local reward, change = role:award(globalCsv.guide_sudoku_reward[phase], {log = {desc = "sudokuRP", int1 = phase}})
d763fb14   zhouhaihai   签到 九宫格
99
100
101
102
103
104
105
106
107
  
  	sudoku[-1] = phase + 1
  	sudoku.task[phase] = nil
  	if not csvdb["guide_sudokuCsv"][sudoku[-1]] then
  		sudoku[-1] = -1
  		sudoku.task = nil
  	end
  	role:updateProperty({field = "sudoku", value = sudoku})
  
c59e058b   zhouhaihai   新一批日志记录
108
109
110
  	role:log("activity", {
  		activity_id = 10000 + phase, -- 活动ID(或活动指定任务的ID)
  		activity_type = 0, -- 活动类型,见活动类型枚举表
887c1843   zhouhaihai   日志新一批
111
  		activity_reward = reward, -- 活动奖励,json格式记录,{'itemid1':123,'itemid2':456,………...}
c59e058b   zhouhaihai   新一批日志记录
112
113
  	})
  
7bb30dca   zhouhaihai   修改发奖
114
  	SendPacket(actionCodes.Activity_sudokuRewardRpc, MsgPack.pack(role:packReward(reward, change)))
d763fb14   zhouhaihai   签到 九宫格
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
  	return true
  end
  
  
  function _M.signRpc(agent, data)
  	local role = agent.role
  
  	local serverT = skynet.timex()
  	local tm = os.date("*t", serverT)
  
  	local curDay = tm.day
  	
  	local yearMonth = tm.year * 100 + tm.month
  	local monthData = csvdb["daily_signInCsv"][yearMonth]
  	if not monthData or not monthData[curDay] then
  		return 1
  	end
  
  	local signs = role:getProperty("sign")
  	if signs[curDay] == yearMonth then  -- 未重置的还可以签到正常(本月已经签到)
  		return 2
  	end
  	signs[curDay] = yearMonth
  
7bb30dca   zhouhaihai   修改发奖
139
  	local reward, change = role:award(monthData[curDay].item, {log = {desc = "sign", int1 = yearMonth, int2 = curDay}})
d763fb14   zhouhaihai   签到 九宫格
140
  	role:changeUpdates({{type = "sign", field = curDay, value = yearMonth}})
e7806e6f   zhouhaihai   签到成就
141
  	role:checkTaskEnter("SignIn")
d763fb14   zhouhaihai   签到 九宫格
142
  
7bb30dca   zhouhaihai   修改发奖
143
  	SendPacket(actionCodes.Activity_signRpc, MsgPack.pack(role:packReward(reward, change)))
d763fb14   zhouhaihai   签到 九宫格
144
145
146
147
  	return true
  end
  
  
ea40710f   zhouhaihai   活动
148
149
  function _M.actSignRpc(agent, data)
  	local role = agent.role
be4e8031   zhouhaihai   活动 拾荒
150
  	if not role.activity:isOpen("Sign") then return 1 end
ea40710f   zhouhaihai   活动
151
152
  
  	local curData = role.activity:getActData("Sign")
7bb30dca   zhouhaihai   修改发奖
153
  	local reward, change = {}
be4e8031   zhouhaihai   活动 拾荒
154
  	for day, csvData in ipairs(csvdb["new_signInCsv"]) do
ea40710f   zhouhaihai   活动
155
156
157
158
159
160
161
162
163
164
165
166
167
  		if day <= (curData[0] or 0) then
  			if not curData[day] then
  				curData[day] = -1
  				-- 奖励
  				for itemId, count in pairs(csvData.reward:toNumMap()) do
  					reward[itemId] = (reward[itemId] or 0) + count
  				end
  			end
  		else
  			break
  		end
  	end
  	if next(reward) then
be4e8031   zhouhaihai   活动 拾荒
168
  		role.activity:updateActData("Sign", curData)
7bb30dca   zhouhaihai   修改发奖
169
  		reward, change = role:award(reward, {log = {desc = "actSign"}})
ea40710f   zhouhaihai   活动
170
  	end
c59e058b   zhouhaihai   新一批日志记录
171
172
173
174
  
  	role:log("activity", {
  		activity_id = curData[0], -- 活动ID(或活动指定任务的ID)
  		activity_type = role.activity.ActivityType.Sign, -- 活动类型,见活动类型枚举表
887c1843   zhouhaihai   日志新一批
175
  		activity_reward = reward, -- 活动奖励,json格式记录,{'itemid1':123,'itemid2':456,………...}
c59e058b   zhouhaihai   新一批日志记录
176
177
  	})
  
7bb30dca   zhouhaihai   修改发奖
178
  	SendPacket(actionCodes.Activity_actSignRpc, MsgPack.pack(role:packReward(reward, change)))
ea40710f   zhouhaihai   活动
179
180
181
  	return true
  end
  
d763fb14   zhouhaihai   签到 九宫格
182
  
51d9d20b   liuzujun   付费签到,应用市场反馈
183
184
185
  function _M.actPaySignRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
460afa6e   liuzujun   付费签到改为主动领取,战斗关卡不一...
186
  	local dayIndex = msg.day
51d9d20b   liuzujun   付费签到,应用市场反馈
187
188
  	local actGoodsFlag = role.storeData:getProperty("actGoodsFlag")
  	local index = GetActGoodsIndex("paySignIn")
460afa6e   liuzujun   付费签到改为主动领取,战斗关卡不一...
189
190
  	local ts = actGoodsFlag[index] or 0
  	if ts == 0 then return 1 end
51d9d20b   liuzujun   付费签到,应用市场反馈
191
  
460afa6e   liuzujun   付费签到改为主动领取,战斗关卡不一...
192
193
  	local open, actId = role.activity:isOpen("PaySignIn")
  	if not open then return 2 end
51d9d20b   liuzujun   付费签到,应用市场反馈
194
  
460afa6e   liuzujun   付费签到改为主动领取,战斗关卡不一...
195
  	local diffDay = diffFromTs(ts) + 1
51d9d20b   liuzujun   付费签到,应用市场反馈
196
197
  
  	local curData = role.activity:getActData("PaySignIn")
b1644d3b   liuzujun   付费签到天数bug
198
  	if not curData then return 3 end
51d9d20b   liuzujun   付费签到,应用市场反馈
199
200
  	local reward, change = {}
  	for day, csvData in ipairs(csvdb["pay_signInCsv"]) do
460afa6e   liuzujun   付费签到改为主动领取,战斗关卡不一...
201
  		if day <= diffDay and day == dayIndex then
51d9d20b   liuzujun   付费签到,应用市场反馈
202
203
204
205
206
207
208
  			if not curData[day] then
  				curData[day] = 1
  				-- 奖励
  				for itemId, count in pairs(csvData.reward:toNumMap()) do
  					reward[itemId] = (reward[itemId] or 0) + count
  				end
  			end
460afa6e   liuzujun   付费签到改为主动领取,战斗关卡不一...
209
210
  		--else
  		--	break
51d9d20b   liuzujun   付费签到,应用市场反馈
211
212
213
214
215
216
217
218
  		end
  	end
  	if next(reward) then
  		role.activity:updateActData("PaySignIn", curData)
  		reward, change = role:award(reward, {log = {desc = "actPaySign"}})
  	end
  
  	role:log("activity", {
460afa6e   liuzujun   付费签到改为主动领取,战斗关卡不一...
219
  		activity_id = actId, -- 活动ID(或活动指定任务的ID)
51d9d20b   liuzujun   付费签到,应用市场反馈
220
221
222
223
224
225
226
  		activity_type = role.activity.ActivityType.PaySignIn, -- 活动类型,见活动类型枚举表
  		activity_reward = reward, -- 活动奖励,json格式记录,{'itemid1':123,'itemid2':456,………...}
  	})
  
  	SendPacket(actionCodes.Activity_actPaySignRpc, MsgPack.pack(role:packReward(reward, change)))
  	return true
  end
d763fb14   zhouhaihai   签到 九宫格
227
  
4bd3095f   liuzujun   英雄帖任务bug
228
  function _M.actCalendaTaskRpc(agent, data)
190e1415   liuzujun   英雄帖活动初始化
229
230
231
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local taskId = msg.id
4bd3095f   liuzujun   英雄帖任务bug
232
  	local calTask = role:getProperty("calTask") or {}
190e1415   liuzujun   英雄帖活动初始化
233
234
235
236
237
238
239
240
  	local record = calTask["r"] or {}
  	local flag = record[taskId] or 0
  	if flag == 1 then return 1 end
  	local open, actId = role.activity:isOpen("CalendaTask")
  	local actData = csvdb["activity_ctrlCsv"][actId]
  	if not open then return 2 end
  	if not actData then return 3 end
  
4bd3095f   liuzujun   英雄帖任务bug
241
242
243
244
245
  	local taskList = csvdb["activity_taskCsv"][actData.condition]
  	if not taskList then return 4 end
  	local taskCfg = taskList[taskId]
  	if not taskCfg then return 5 end
  	if taskCfg.key ~= actData.condition then return 6 end
190e1415   liuzujun   英雄帖活动初始化
246
  
4bd3095f   liuzujun   英雄帖任务bug
247
  	if (calTask[taskId] or 0) < taskCfg.condition1 then return 7 end
190e1415   liuzujun   英雄帖活动初始化
248
249
250
251
  
  	record[taskId] = 1
  	calTask["r"] = record
  
4bd3095f   liuzujun   英雄帖任务bug
252
  	role:updateProperty({field = "calTask", value = calTask})
190e1415   liuzujun   英雄帖活动初始化
253
  
4bd3095f   liuzujun   英雄帖任务bug
254
  	local reward, change = role:award(taskCfg.reward, {log = {desc = "calendaTask"}})
190e1415   liuzujun   英雄帖活动初始化
255
256
257
258
259
260
261
262
  
  	role:log("activity", {
  		activity_id = taskId, -- 活动ID(或活动指定任务的ID)
  		activity_type = role.activity.ActivityType.CalendaTask, -- 活动类型,见活动类型枚举表
  		activity_reward = reward, -- 活动奖励,json格式记录,{'itemid1':123,'itemid2':456,………...}
  	})
  
  	SendPacket(actionCodes.Activity_actCalendaTaskRpc, MsgPack.pack(role:packReward(reward, change)))
4bd3095f   liuzujun   英雄帖任务bug
263
  	return true
190e1415   liuzujun   英雄帖活动初始化
264
265
  end
  
847f9a7b   liuzujun   兑换活动,邮件内容修改
266
267
268
269
270
  function _M.exchangeRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local actid = msg.actid
  	local id = msg.id
686d4fd6   liuzujun   兑换活动支持兑换多个, 新增卡池
271
272
  	local count = msg.count
  	if not role.activity:isOpenById(actid, "Exchange") then return 1 end
847f9a7b   liuzujun   兑换活动,邮件内容修改
273
274
275
276
277
278
279
280
  
  	local exchangeCfg = csvdb["activity_exchangeCsv"][actid]
  	if not exchangeCfg then return 2 end
  	if not exchangeCfg[id] then return 3 end
  	local curData = role.activity:getActData("Exchange") or {}
  	local exchangeData = curData[actid] or {}
  	local curCount = exchangeData[id] or 0
  	local actCfg = exchangeCfg[id]
2bc706ab   liuzujun   兑换活动重置,累充功能
281
  	local limitArr = actCfg.limit:toArray(true, "=")
686d4fd6   liuzujun   兑换活动支持兑换多个, 新增卡池
282
  	if curCount + count > limitArr[2] then return 4 end
847f9a7b   liuzujun   兑换活动,邮件内容修改
283
284
  
  	local costs = actCfg.goods:toNumMap()
686d4fd6   liuzujun   兑换活动支持兑换多个, 新增卡池
285
286
287
  	for k,v in pairs(costs) do
  		costs[k] = v * count
  	end
847f9a7b   liuzujun   兑换活动,邮件内容修改
288
289
290
  	if not role:checkItemEnough(costs) then return 5 end
  	role:costItems(costs, {log = {desc = "actExchange", int1 = actid, int2 = id}})
  
686d4fd6   liuzujun   兑换活动支持兑换多个, 新增卡池
291
  	curCount = curCount + count
847f9a7b   liuzujun   兑换活动,邮件内容修改
292
293
294
295
  	exchangeData[id] = curCount
  	curData[actid] = exchangeData
  	role.activity:updateActData("Exchange", curData)
  
0163328c   liuzujun   修改活动boss关卡三星条件
296
297
298
299
300
301
  	local award = actCfg.award:toNumMap()
  	for k,v in pairs(award) do
  		award[k] = v * count
  	end
  
  	local reward, change = role:award(award, {log = {desc = "actExchange", int1 = actid, int2 = id}})
847f9a7b   liuzujun   兑换活动,邮件内容修改
302
303
304
305
306
307
  
  
  	SendPacket(actionCodes.Activity_exchangeRpc, MsgPack.pack(role:packReward(reward, change)))
  	return true
  end
  
b8b1c164   liuzujun   扭蛋活动,万能碎片bug
308
309
310
311
  function _M.gachakonRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local actid = msg.actid
2bc706ab   liuzujun   兑换活动重置,累充功能
312
313
314
315
  	local count = msg.count
  
  	if count > 10 then return end
  
686d4fd6   liuzujun   兑换活动支持兑换多个, 新增卡池
316
  	if not role.activity:isOpenById(actid, "Gachakon") then return 1 end
b8b1c164   liuzujun   扭蛋活动,万能碎片bug
317
  
2bc706ab   liuzujun   兑换活动重置,累充功能
318
319
320
321
  	local actCtrlData = csvdb["activity_ctrlCsv"][actid]
  	if not actCtrlData then return 2 end
  	local cost = actCtrlData.condition2:toNumMap()
  
b8b1c164   liuzujun   扭蛋活动,万能碎片bug
322
  	local actCfg = csvdb["activity_capsuleToysCsv"][actid]
2bc706ab   liuzujun   兑换活动重置,累充功能
323
324
  	if not actCfg then return 3 end
  
b8b1c164   liuzujun   扭蛋活动,万能碎片bug
325
  	local gachakonInfo = role.activity:getActData("Gachakon") or {}
2bc706ab   liuzujun   兑换活动重置,累充功能
326
327
  	local award = {}
  	local remain = 0
6a2b449c   liuzujun   扭蛋机奖励不合并显示, 新增多队挂...
328
  	local showAward = {}
2bc706ab   liuzujun   兑换活动重置,累充功能
329
  	for i = 1, count do
1be743f3   liuzujun   扭蛋机调试
330
331
  		local tmpCfg = clone(actCfg)
  		remain = 0
2bc706ab   liuzujun   兑换活动重置,累充功能
332
333
  		for id, cfg in pairs(tmpCfg) do
  			local num = gachakonInfo[id] or 0
1be743f3   liuzujun   扭蛋机调试
334
335
  			num = cfg.amount >= num and cfg.amount - num or 0
  			cfg.weight = cfg.weight * num
2bc706ab   liuzujun   兑换活动重置,累充功能
336
  			if cfg.weight > 0 then
1be743f3   liuzujun   扭蛋机调试
337
  				remain = remain + num
2bc706ab   liuzujun   兑换活动重置,累充功能
338
  			end
66fe093a   liuzujun   元旦关卡活动
339
  			--print("num ".. num, id, cfg.weight, cfg.amount)
2bc706ab   liuzujun   兑换活动重置,累充功能
340
  		end
1be743f3   liuzujun   扭蛋机调试
341
  		if remain == 0 then
2bc706ab   liuzujun   兑换活动重置,累充功能
342
343
344
  			break
  		end
  		local id = math.randWeight(tmpCfg, "weight")
1be743f3   liuzujun   扭蛋机调试
345
  		if not id then return 4 end
2bc706ab   liuzujun   兑换活动重置,累充功能
346
347
  		gachakonInfo[id] = (gachakonInfo[id] or 0) + 1
  		local curAward = tmpCfg[id].award:toNumMap()
6a2b449c   liuzujun   扭蛋机奖励不合并显示, 新增多队挂...
348
  		table.insert(showAward, curAward)
2bc706ab   liuzujun   兑换活动重置,累充功能
349
350
  		for k, v in pairs(curAward) do
  			award[k] = (award[k] or 0) + v
b8b1c164   liuzujun   扭蛋活动,万能碎片bug
351
  		end
b8b1c164   liuzujun   扭蛋活动,万能碎片bug
352
  	end
b8b1c164   liuzujun   扭蛋活动,万能碎片bug
353
  
1be743f3   liuzujun   扭蛋机调试
354
355
356
357
358
  	for k, v in pairs(cost) do
  		cost[k] = v * count
  	end
  
  	if not role:checkItemEnough(cost) then return 5 end
2bc706ab   liuzujun   兑换活动重置,累充功能
359
360
  
  	role:costItems(cost, {log = {desc = "actGachakon", int1 = actid, int2 = count}})
b8b1c164   liuzujun   扭蛋活动,万能碎片bug
361
  
2bc706ab   liuzujun   兑换活动重置,累充功能
362
  	local reward, change = role:award(award, {log = {desc = "actGachakon", int1 = actid, int2 = count}})
66fe093a   liuzujun   元旦关卡活动
363
364
  	--print("-----------", remain, count)
  	if remain <= 1 then
2bc706ab   liuzujun   兑换活动重置,累充功能
365
  		gachakonInfo = {}
2bc706ab   liuzujun   兑换活动重置,累充功能
366
  	end
b8b1c164   liuzujun   扭蛋活动,万能碎片bug
367
368
  	role.activity:updateActData("Gachakon", gachakonInfo)
  
6a2b449c   liuzujun   扭蛋机奖励不合并显示, 新增多队挂...
369
  	SendPacket(actionCodes.Activity_gachakonRpc, MsgPack.pack(showAward))
b8b1c164   liuzujun   扭蛋活动,万能碎片bug
370
371
372
  	return true
  end
  
2bc706ab   liuzujun   兑换活动重置,累充功能
373
374
375
376
  function _M.hangDropRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local actid = msg.actid
686d4fd6   liuzujun   兑换活动支持兑换多个, 新增卡池
377
  	if not role.activity:isOpenById(actid, "HangDrop") then return 1 end
2bc706ab   liuzujun   兑换活动重置,累充功能
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
  
  	local actCfg = csvdb["activity_putCsv"][actid]
  	if not actCfg then return 2 end
  
  	local award, period = "", 0
  	for i = 1, #actCfg do
  		local cfg = actCfg[i]
  		if not cfg then
  			break
  		end
  		if cfg.condition ~= "" then
  			local arr = cfg.condition:toArray(true, "=")
  			local type = arr[1]
  			if type == 1 then
  				local actId = arr[2]
  				local carbonId = arr[3]
0163328c   liuzujun   修改活动boss关卡三星条件
394
  				if not role.activity:isOpenById(actId, "ChallengeLevel") then return 3 end
2bc706ab   liuzujun   兑换活动重置,累充功能
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
  				local clInfo = role.activity:getActData("ChallengeLevel") or {}
  				if not clInfo[carbonId] then
  					break
  				end
  			end
  		end
  		award = cfg.reward
  		period = cfg.period * 60
  	end
  	local actData = role.activity:getActData("HangDrop") or 0
  	local timeNow = skynet.timex()
  	if period == 0 or award == "" then
  		return 4
  	end
  	local num = math.floor((timeNow - actData)/ period)
  	num = num > 8 and 8 or num
  	if num == 0 then
  		return 5
  	end
  	local reward, change = {}, nil
  	for id, value in pairs(award:toNumMap()) do
  		reward[id] = value * num
  	end
  
  	reward, change  = role:award(reward, {log = {desc = "actHangDrop", int1 = actid, int2 = num}})
  
576c791c   liuzujun   玛尼英雄帖活动通过任务bug 元旦...
421
422
423
424
425
426
427
  	if num < 8 then
  		actData = actData + num * period
  	else
  		actData = timeNow
  	end
  
  	role.activity:updateActData("HangDrop", actData)
2bc706ab   liuzujun   兑换活动重置,累充功能
428
429
430
431
432
433
  
  	SendPacket(actionCodes.Activity_hangDropRpc, MsgPack.pack(role:packReward(reward, change)))
  
  	return true
  end
  
66fe093a   liuzujun   元旦关卡活动
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
  local function getStarCount(cfg, data)
  	local count = 0
  	for i = 0, #(cfg.sweep_condition:toTableArray(true)) do
  		if (1 << i & data) > 0 then
  			count = count + 1
  		end
  	end
  
  	return count
  end
  
  function _M.startBattleRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local actid = msg.actid
  	local id = msg.id
  	local count = msg.count
686d4fd6   liuzujun   兑换活动支持兑换多个, 新增卡池
451
  	if not role.activity:isOpenById(actid, "ChallengeLevel") then return 1 end
66fe093a   liuzujun   元旦关卡活动
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
  
  	local actCfg = csvdb["activity_battleCsv"][actid]
  	if not actCfg then return 2 end
  
  	local battleCfg = actCfg[id]
  	if not battleCfg then return 3 end
  
  	local actData = role.activity:getActData("ChallengeLevel") or {}
  
  	local preArr = battleCfg.prepose:toArray(true, "=")
  	for _, v in ipairs(preArr) do
  		local battleInfo = actData[v]
  		if not battleInfo then
  			return 4
  		end
  		local star = battleInfo["star"] or 0
  		if star <= 0 then
  			return 4
  		end
  	end
  	-- check cost
  	local changeFlag = false
  	local ticket = actData["ticket"]
8e892c71   liuzujun   挑战关卡活动打完再扣门票
475
  	local num = 0	-- cost num
66fe093a   liuzujun   元旦关卡活动
476
  	if battleCfg.type ~= "" then
576c791c   liuzujun   玛尼英雄帖活动通过任务bug 元旦...
477
  		role.activity:getBattleTicket(actid)
8e892c71   liuzujun   挑战关卡活动打完再扣门票
478
  		num = battleCfg.type:toArray(true, "=")[3]
66fe093a   liuzujun   元旦关卡活动
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
  		if count and count > 0 then
  			if battleCfg.rank == 0 then
  				return 7
  			end
  			local bi = actData[id]
  			if not bi then return 8 end
  			local star = bi["star"] or 0
  			if star < 1 then
  				return 9
  			end
  			num = num * count
  		end
  		if ticket < num then
  			return 6
  		end
66fe093a   liuzujun   元旦关卡活动
494
495
  		changeFlag = true
  	end
be697585   liuzujun   活动剧情解锁
496
497
  	-- 解锁活动剧情
  	role:checkStoryStatus(false, 5, id)
66fe093a   liuzujun   元旦关卡活动
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
  
  	if not count then
  		role.__actBattleCache = {
  			key = tostring(math.random()),
  			actid = actid,
  			id = id,
  		}
  		SendPacket(actionCodes.Activity_startBattleRpc, MsgPack.pack({key = role.__actBattleCache.key}))
  	else
  		if count <= 0 then
  			return
  		end
  		if battleCfg.rank == 0 then
  			return 7
  		end
  		local bi = actData[id]
  		local star = bi["star"]
  		local award = battleCfg.item_clear:toNumMap()
  		if getStarCount(battleCfg, star) == 3 then
  			local aw = battleCfg.perfect_reward:toNumMap()
  			for k, v in pairs(aw) do
  				award[k] = (award[k] or 0) + v
  			end
  		end
  		for k, v in pairs(award) do
  			award[k] = v * count
  		end
  		local reward, change  = role:award(award, {log = {desc = "actBattle", int1 = actid, int2 = count or 0}})
  		SendPacket(actionCodes.Activity_startBattleRpc, MsgPack.pack(role:packReward(reward, change)))
  
  		bi["sum"] = bi["sum"] + bi["top"]
8e892c71   liuzujun   挑战关卡活动打完再扣门票
529
  		actData["ticket"] = ticket - num
66fe093a   liuzujun   元旦关卡活动
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
  		actData[id] = bi
  		changeFlag = true
  
  		local rankVal = 0
  		if battleCfg.rank == 1 then
  			rankVal = bi["sum"]
  		elseif battleCfg.rank == 2 then
  			rankVal = bi["top"]
  		end
  		role:updateRankCommon(RANK_TYPE.ActBattleBoss, rankVal)
  	end
  	if changeFlag then
  		role.activity:updateActData("ChallengeLevel", actData)
  	end
  
  	return true
  end
  
  function _M.endBattleRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local actid = msg.actid
  	local id = msg.id
  	local key = msg.key
  	local isWin = msg.isWin
  	local heros = msg.heros
  	local support = msg.support
686d4fd6   liuzujun   兑换活动支持兑换多个, 新增卡池
557
  	if not role.activity:isOpenById(actid, "ChallengeLevel") then return 1 end
66fe093a   liuzujun   元旦关卡活动
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
  
  	if not role.__actBattleCache then return 2 end
  	
  	if role.__actBattleCache.id ~= id or role.__actBattleCache.key ~= key and role.__actBattleCache.actid ~= actid then 
  		SendPacket(actionCodes.Activity_endBattleRpc, MsgPack.pack({errorCode = 1}))
  	end
  
  	local actCfg = csvdb["activity_battleCsv"][actid]
  	if not actCfg then return 3 end
  
  	local battleCfg = actCfg[id]
  	if not battleCfg then return 4 end
  
  	local actData = role.activity:getActData("ChallengeLevel") or {}
  
0163328c   liuzujun   修改活动boss关卡三星条件
573
574
575
576
577
578
579
580
  	-- 总输出
  	local dmg = 0
  	for k, v in pairs(msg.info.damage) do
  		if k % 100 == 2 then
  			dmg = dmg + v
  		end
  	end
  
66fe093a   liuzujun   元旦关卡活动
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
  	local reward, change = {}, nil
  
  	local battleInfo = actData[id] or {}
  	local curStar = 0
   	if isWin then
   		local herosInfo = msg.heros
  
   		local check = {}
   		-- 1 通关
  		check[1] = function(_)
  			return true
  		end
  		-- 2 阵亡人数 <= N
  		check[2] = function(_, cond)
  			return msg.info.dead and msg.info.dead <= cond
  		end
  		-- 3 全员存活
  		check[3] = function(_)
  			return msg.info.dead and msg.info.dead == 0
  		end
  		-- 4 指定种族 >= N
  		check[4] = function(_, cond)
  			local count = 0
  			for _, one in pairs(herosInfo) do
  				local heroData = csvdb["unitCsv"][one.type]
  				if heroData.camp == cond then
  					count = count + 1
  				end
  			end
  			return count >= cond
  		end
  		-- 5 指定职业 >= N
  		check[5] = function(_, cond)
  			local count = 0
  			for _, one in pairs(herosInfo) do
  				local heroData = csvdb["unitCsv"][one.type]
  				if heroData.job == cond then
  					count = count + 1
  				end
  			end
  			return count >= cond
  		end
  		-- 6 含有指定角色 
  		check[6] = function(_, cond)
  			for _, one in pairs(herosInfo) do
  				if one.type == cond then
  					return true
  				end
  			end
  			return false
  		end
  		-- 7 通关耗时 <= X 秒  msg.info.atime
  		check[7] = function(_, cond)
  			return msg.info.atime and msg.info.atime <= cond
  		end
0163328c   liuzujun   修改活动boss关卡三星条件
636
637
638
639
  		-- 8 总输出值  msg.info.atime
  		check[8] = function(_, cond)
  			return dmg >= cond
  		end
66fe093a   liuzujun   元旦关卡活动
640
641
642
643
644
645
646
  		curStar = 0
  		local sweepConds = battleCfg.sweep_condition:toTableArray(true)
   		for i, cond in ipairs(sweepConds) do
   			if check[cond[1]] and check[cond[1]](table.unpack(cond)) then
   				curStar = curStar + (1 << (i - 1))
   			end
   		end
0163328c   liuzujun   修改活动boss关卡三星条件
647
648
649
650
651
  	 else
  		curStar = 0
  		if battleCfg.rank ~= 0 then
  			curStar = 1
  		end
66fe093a   liuzujun   元旦关卡活动
652
653
654
655
656
657
658
659
  	end
  	local oldStarNum = getStarCount(battleCfg, battleInfo["star"] or 0)
  	local newStarNum = getStarCount(battleCfg, curStar)
  	if  newStarNum > oldStarNum then
  		battleInfo["star"] = curStar
  	end
  
  	if battleCfg.rank ~= 0 then
8e892c71   liuzujun   挑战关卡活动打完再扣门票
660
661
662
663
664
  		-- 消耗门票
  		role.activity:getBattleTicket(actid)
  		local num = battleCfg.type:toArray(true, "=")[3]
  		actData["ticket"] = math.max(actData["ticket"] - num, 0)
  
66fe093a   liuzujun   元旦关卡活动
665
  		-- 更新排行榜 最高伤害
66fe093a   liuzujun   元旦关卡活动
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
  		battleInfo["top"] = math.max(battleInfo["top"] or 0, dmg)
  		battleInfo["sum"] = (battleInfo["sum"] or 0) + dmg
  		local rankVal = 0
  		if battleCfg.rank == 1 then
  			rankVal = battleInfo["sum"]
  		elseif battleCfg.rank == 2 then
  			rankVal = battleInfo["top"]
  		end
  		if rankVal > 0 then
  			role:updateRankCommon(RANK_TYPE.ActBattleBoss, rankVal)
  		end
  	end
  	actData[id] = battleInfo
  	role.activity:updateActData("ChallengeLevel", actData)
  
598bd73f   liuzujun   关卡挑战活动奖励错误bug
681
  	if (oldStarNum == 0 and newStarNum > 0) or battleCfg.rank ~= 0 then
66fe093a   liuzujun   元旦关卡活动
682
683
  		reward = battleCfg.item_clear:toNumMap()
  	end
0163328c   liuzujun   修改活动boss关卡三星条件
684
  	if (oldStarNum < 3 and newStarNum == 3) or (battleCfg.rank ~= 0 and newStarNum == 3) then
66fe093a   liuzujun   元旦关卡活动
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
  		local aw = battleCfg.perfect_reward:toNumMap()
  		for k, v in pairs(aw) do
  			reward[k] = (reward[k] or 0) + v
  		end
  	end
  
   	role:checkBattle("act_battle", {
  		cfg = battleCfg,
  		star = newStarNum,
  		isWin = isWin,
  		info = msg.info,
  		reward = reward,
  		heros = heros,
  		supports = support,
  	})
  
be697585   liuzujun   活动剧情解锁
701
702
703
704
705
  	-- 解锁活动剧情
  	if newStarNum >= 3 then
  		role:checkStoryStatus(false, 5, id)
  	end
  
6857a37f   liuzujun   世界Boss 增加行动点
706
707
708
709
  	if battleCfg.worldBoss_award ~= 0 and msg.point then
  		battleInfo["bossP"] = (battleInfo["bossP"] or 0) + msg.point
  	end
  
66fe093a   liuzujun   元旦关卡活动
710
711
712
713
714
715
716
717
718
719
720
721
722
723
  	reward, change  = role:award(reward, {log = {desc = "actBattle", int1 = actid, int2 = newStarNum}})
  
  	SendPacket(actionCodes.Activity_endBattleRpc, MsgPack.pack({
  		reward = reward,
  		change = change
  	}))
  
  	return true
  end
  
  function _M.battleRankRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local actid = msg.actid
161c50cc   zhouhaihai   宝藏怪活动
724
725
726
727
728
729
730
731
732
  	local cfg = csvdb["activity_ctrlCsv"][actid]
  	if not cfg then return 1 end
  	if not role.activity:isOpen(cfg.showType) then return 2 end
  	local actTypeToRank = {
  		[role.activity.ActivityType.ChallengeLevel] = RANK_TYPE.ActBattleBoss,
  		[role.activity.ActivityType.Crisis] = RANK_TYPE.ActCrisis,
  	}
  	if not actTypeToRank[cfg.showType] then return end
  	local rankInfo = role:getRankInfoCommon(actTypeToRank[cfg.showType])
66fe093a   liuzujun   元旦关卡活动
733
734
735
736
737
738
739
740
741
742
743
  	SendPacket(actionCodes.Activity_battleRankRpc, MsgPack.pack(rankInfo))
  	return true
  end
  
  function _M.battleMilestoneRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local actid = msg.actid
  	local id = msg.id
  	local index = msg.index
  
686d4fd6   liuzujun   兑换活动支持兑换多个, 新增卡池
744
  	if not role.activity:isOpenById(actid, "ChallengeLevel") then return 1 end
66fe093a   liuzujun   元旦关卡活动
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
  
  	local actCfg = csvdb["activity_mileageCsv"][actid]
  	if not actCfg then return 3 end
  
  	local mileCfg = actCfg[index]
  	if not mileCfg then return 4 end
  
  	local actData = role.activity:getActData("ChallengeLevel") or {}
  	local battleInfo = actData[id] or {}
  	local val = 0
  	if mileCfg.type == 1 then
  		val = battleInfo["sum"] or 0
  	elseif mileCfg.type == 2 then
  		val = battleInfo["top"] or 0
  	end
  
  	local record = battleInfo["r"] or ""
  	local flag = string.char(string.getbit(record, index))
  	if flag == "1" then return 5 end
  	if mileCfg.condition > val then return 6 end
  
  	battleInfo["r"] = string.setbit(record, index)
  	actData[id] = battleInfo
  	role.activity:updateActData("ChallengeLevel", actData)
  
  	local award = mileCfg.reward:toNumMap()
  	local reward, change = role:award(award, {log = {desc = "actMilestone", int1 = actid, int2 = index}})
  	SendPacket(actionCodes.Activity_battleMilestoneRpc, MsgPack.pack(role:packReward(reward, change)))
  
  	return true
  end
  
161c50cc   zhouhaihai   宝藏怪活动
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
  function _M.crisisMilestoneRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local actid = msg.actid
  	local id = msg.id
  	if not role.activity:isOpenById(actid, "Crisis") then return 1 end
  	local actCfg = csvdb["activity_mileageCsv"][actid]
  	if not actCfg then return 3 end
  
  	local curCsv = actCfg[id]
  	if not curCsv then return 4 end
  
  	if role:getItemCount(ItemId.CrisisScore) < curCsv.condition then
  		return 5
  	end
  
  	local actData = role.activity:getActData("Crisis") or {}
  	actData.score = actData.score or {}
  	if actData.score[id] then
  		return 6
  	end
  	actData.score[id] = -1
  	role.activity:updateActData("Crisis", actData)
558c9044   zhouhaihai   物资危机
800
801
  
  	local reward, change = role:award(curCsv.reward, {log = {desc = "actMilecrisis", int1 = actid}})
161c50cc   zhouhaihai   宝藏怪活动
802
803
804
805
806
  	SendPacket(actionCodes.Activity_crisisMilestoneRpc, MsgPack.pack(role:packReward(reward, change)))
  	return true
  end
  
  
be697585   liuzujun   活动剧情解锁
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
  function _M.bossRewardRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local actid = msg.actid
  	local id = msg.id
  	local index = msg.index
  
  	if not role.activity:isOpenById(actid, "ChallengeLevel") then return 1 end
  
  	local actCfg = csvdb["activity_battleCsv"][actid]
  	if not actCfg then return 2 end
  
  	local battleCfg = actCfg[id]
  	if not battleCfg then return 3 end
  
eb5ffd1c   liuzujun   世界boss翻牌奖励 活动卡池保底...
822
  	if battleCfg.worldBoss_award == 0 then return 4 end
be697585   liuzujun   活动剧情解锁
823
  
eb5ffd1c   liuzujun   世界boss翻牌奖励 活动卡池保底...
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
  	actCfg = csvdb["activity_wordboss_awardCsv"][battleCfg.worldBoss_award]
  	if not actCfg then return 5 end
  	local awardCfg = actCfg[index]
  	if not awardCfg then return 6 end
  
  	local preList = awardCfg.condition1:toArray(true, "=")
  
  	local actData = role.activity:getActData("ChallengeLevel") or {}
  	local battleInfo = actData[id] or {}
  	local bossPoint = battleInfo["bossP"] or 0
  	if bossPoint < 1 then return 7 end
  
  	local bossRecord = battleInfo["bossR"] or ""
  	local ok = false
  	if #preList == 0 then
  		ok = true
  	else
  		for _, i in ipairs(preList) do
  			local flag = string.char(string.getbit(bossRecord, i))
  			if flag == "1" then
  				ok = true
  				break
  			end
  		end
  	end
  	if not ok then return 8 end
  
  	battleInfo["bossR"] = string.setbit(bossRecord, index)
  	actData[id] = battleInfo
  	role.activity:updateActData("ChallengeLevel", actData)
  
  	local award = awardCfg.reward:toNumMap()
  	local reward, change = role:award(award, {log = {desc = "worldBossReward", int1 = actid, int2 = index}})
  	SendPacket(actionCodes.Activity_bossRewardRpc, MsgPack.pack(role:packReward(reward, change)))
be697585   liuzujun   活动剧情解锁
858
859
860
  	return true
  end
  
ac885527   liuzujun   联动签到活动
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
  function _M.commonSignRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local actid = msg.actid
  	local index = msg.index
  
  	if not role.activity:isOpenById(actid, "CommonSignIn") then return 1 end
  
  	local actData = role.activity:getActData("CommonSignIn")
  	if (actData[0] or 0) < index then
  		return 2
  	end
  	if (actData[index] or 0) == 1 then
  		return 3
  	end
  
  	local actCfg = csvdb["activity_signInCsv"][actid]
  	if not actCfg then return 4 end
  	actCfg = actCfg[index]
  	if not actCfg then return 5 end
  
  	actData[index] = 1
  	role.activity:updateActData("CommonSignIn", actData)
  
  	local award = actCfg.reward:toNumMap()
  	local reward, change = role:award(award, {log = {desc = "commonSign", int1 = actid, int2 = index}})
  	SendPacket(actionCodes.Activity_commonSignRpc, MsgPack.pack(role:packReward(reward, change)))
  	return true
  end
  
091912ed   chenyueqi   未测试版好友能量助力活动
891
892
893
894
895
  function _M.friendHelpRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  	local msg = MsgPack.unpack(data)
  	local oper = tonumber(msg.oper) or -1
cab7184b   chenyueqi   活动能量bug
896
897
898
  	local award = {}
  	local result
  
091912ed   chenyueqi   未测试版好友能量助力活动
899
  
cab7184b   chenyueqi   活动能量bug
900
  	local actid = 37
091912ed   chenyueqi   未测试版好友能量助力活动
901
  	if not role.activity:isOpenById(actid, "FriendEnergy") then return 1 end
0ce1cab5   chenyueqi   好友赠送能量活动bug修复
902
  	if oper < 1 or oper > 4 then return 2 end
091912ed   chenyueqi   未测试版好友能量助力活动
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
  
  	local actCsv = csvdb["activity_ctrlCsv"][actid]
  	local getLimit = actCsv.condition
  	local gifts = actCsv.condition2:toTableArray(true)
  
  	local actData = role.activity:getActData("FriendEnergy") or {}
  
  	local function getIds()
  		local ids = {}
  		local friends = redisproxy:hgetall(FRIEND_KEY:format(roleId))
  		for i = 1, #friends , 2 do
  			local objId = tonumber(friends[i])
  			ids[objId] = 1
  		end
  		return ids
  	end
  
0886d05a   chenyueqi   修改联动好友赠送获得的红点记录和通知
920
  	if oper == 1 then -- 赠送好友能量
cab7184b   chenyueqi   活动能量bug
921
  		local giveAE = actData.giveAE or {}
091912ed   chenyueqi   未测试版好友能量助力活动
922
923
924
925
926
  		local objId = msg.roleId
  		local gift = gifts[1]
  		local ids = {}
  
  		if not objId then
cab7184b   chenyueqi   活动能量bug
927
928
929
930
931
932
933
  			return 3
  		end
  		if not redisproxy:hexists(FRIEND_KEY:format(roleId), objId) then
  			result = 2
  		end
  		if giveAE[objId] then
  			result = 1
091912ed   chenyueqi   未测试版好友能量助力活动
934
935
  		end
  
cab7184b   chenyueqi   活动能量bug
936
937
938
939
940
941
942
  		if not result then
  			giveAE[objId] = 1
  			award[gift[1]] = gift[2]
  			redisproxy:sadd(FRIEND_ENERGY:format(objId), roleId)
  			rpcRole(objId, "SendPacket", actionCodes.Role_notifyNewEvent, MsgPack.pack({events = {actFriendGive = roleId}}))
  			actData.giveAE = giveAE
  		end
091912ed   chenyueqi   未测试版好友能量助力活动
943
944
945
  	elseif oper == 2 then -- 收取能量
  		local objId = msg.roleId
  		local gift = gifts[2]
cab7184b   chenyueqi   活动能量bug
946
  		local getAE = actData.getAE or {}
091912ed   chenyueqi   未测试版好友能量助力活动
947
948
949
  		local limit = actData.limit or 0
  
  		if limit >= getLimit then return 4 end
cab7184b   chenyueqi   活动能量bug
950
951
952
953
954
955
956
957
  		if not redisproxy:sismember(FRIEND_ENERGY:format(roleId), objId) then
  			result = 3
  		end
  		if getAE[objId] then
  			result = 2
  		end
  		if limit >= getLimit then
  			result = 1
091912ed   chenyueqi   未测试版好友能量助力活动
958
959
  		end
  
cab7184b   chenyueqi   活动能量bug
960
961
962
963
964
965
966
967
  		if not result then
  			limit = limit + 1
  			getAE[objId] = 1
  			award[gift[1]] = gift[2]
  			redisproxy:srem(FRIEND_ENERGY:format(roleId), objId)
  			actData.limit = limit
  			actData.getAE = getAE
  		end
091912ed   chenyueqi   未测试版好友能量助力活动
968
  	elseif oper == 3 then -- 一键送领全部
cab7184b   chenyueqi   活动能量bug
969
970
  		local giveAE = actData.giveAE or {}
  		local getAE = actData.getAE or {}
091912ed   chenyueqi   未测试版好友能量助力活动
971
972
973
  		local gift1 = gifts[1]
  		local gift2 = gifts[2]
  		local limit = actData.limit or 0
cab7184b   chenyueqi   活动能量bug
974
  		local cmd1, cmd2 = 0, 0
091912ed   chenyueqi   未测试版好友能量助力活动
975
  		local ids = getIds()
cab7184b   chenyueqi   活动能量bug
976
977
978
979
980
981
982
  
  		local members = {}
  		local temp = redisproxy:smembers(FRIEND_ENERGY:format(roleId))
  		for _, id in pairs(temp) do
  			members[tonumber(id)] = 1
  		end
  
091912ed   chenyueqi   未测试版好友能量助力活动
983
984
  		redisproxy:pipelining(function(red)
  			for friendId, _ in pairs(ids) do
cab7184b   chenyueqi   活动能量bug
985
986
  				if not giveAE[friendId] then
  					giveAE[friendId] = 1
091912ed   chenyueqi   未测试版好友能量助力活动
987
988
  					award[gift1[1]] = (award[gift1[1]] or 0) + gift1[2]
  					red:sadd(FRIEND_ENERGY:format(friendId), roleId)
eba94a09   chenyueqi   修改联动好友赠送活动的消息通知结构
989
  					rpcRole(friendId, "SendPacket", actionCodes.Role_notifyNewEvent, MsgPack.pack({events = {actFriendGive = roleId}}))
cab7184b   chenyueqi   活动能量bug
990
  					cmd1 = 2
091912ed   chenyueqi   未测试版好友能量助力活动
991
992
  				end
  
cab7184b   chenyueqi   活动能量bug
993
994
  				if members[friendId] and not getAE[friendId] and limit <= getLimit then
  					cmd2 = 1
091912ed   chenyueqi   未测试版好友能量助力活动
995
  					limit = limit + 1
cab7184b   chenyueqi   活动能量bug
996
  					getAE[friendId] = 1
091912ed   chenyueqi   未测试版好友能量助力活动
997
998
999
1000
1001
1002
  					award[gift2[1]] = (award[gift2[1]] or 0) + gift2[2]
  					red:srem(FRIEND_ENERGY:format(roleId), friendId)
  				end
  			end
  		end)
  
cab7184b   chenyueqi   活动能量bug
1003
1004
1005
1006
1007
1008
1009
  		local sum = cmd1 + cmd2
  		if sum == 0 then
  			result = 3
  		elseif sum ~= 3 then
  			result = sum
  		end
  
091912ed   chenyueqi   未测试版好友能量助力活动
1010
  		actData.limit = limit
cab7184b   chenyueqi   活动能量bug
1011
1012
  		actData.giveAE = giveAE
  		actData.getAE = getAE
091912ed   chenyueqi   未测试版好友能量助力活动
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
  	elseif oper == 4 then -- 抽大奖
  		local magic = actData.magic or 0
  		local rewards = actData.reward or {}
  		local rewardCsv = csvdb["activity_orderRewardsCsv"][actid]
  		local itemId1 = gifts[1][1]
  		local itemId2 = gifts[2][1]
  
  		local level = math.min(magic + 1,#rewardCsv)
  		local rewardData = rewardCsv[level]
  
  		local cost = {[itemId1] = rewardData.condition1, [itemId2] = rewardData.condition2}
  
  		if not role:checkItemEnough(cost) then return 7 end
  		role:costItems(cost, {log = {desc = "actFriendHelp", int1 = actid, int2 = level}})
  
0ce1cab5   chenyueqi   好友赠送能量活动bug修复
1028
  		if rewardData.reward ~= "" then
091912ed   chenyueqi   未测试版好友能量助力活动
1029
  			result = 1
0ce1cab5   chenyueqi   好友赠送能量活动bug修复
1030
  			award = rewardData.reward:toNumMap()
091912ed   chenyueqi   未测试版好友能量助力活动
1031
  		end
0ce1cab5   chenyueqi   好友赠送能量活动bug修复
1032
  		if rewardData.reward_random ~= "" then
091912ed   chenyueqi   未测试版好友能量助力活动
1033
1034
  			result = 1
  			local pool = {}
0ce1cab5   chenyueqi   好友赠送能量活动bug修复
1035
  			for _, temp in pairs(rewardData.reward_random:toArray()) do
091912ed   chenyueqi   未测试版好友能量助力活动
1036
1037
  				table.insert(pool, temp:toArray(true, "="))
  			end
0ce1cab5   chenyueqi   好友赠送能量活动bug修复
1038
  			local gift = pool[math.randWeight(pool, 3)]
091912ed   chenyueqi   未测试版好友能量助力活动
1039
1040
1041
1042
1043
  			award[gift[1]] = (award[gift[1]] or 0) + gift[2]
  		end
  		rewards[level] = 1
  		actData.reward = rewards
  		actData.magic = level
0886d05a   chenyueqi   修改联动好友赠送获得的红点记录和通知
1044
1045
  	else
  		return 5
091912ed   chenyueqi   未测试版好友能量助力活动
1046
1047
  	end
  
0886d05a   chenyueqi   修改联动好友赠送获得的红点记录和通知
1048
  	local ids = {}
0ce1cab5   chenyueqi   好友赠送能量活动bug修复
1049
  	local members = {}
0886d05a   chenyueqi   修改联动好友赠送获得的红点记录和通知
1050
  	local friendIds = getIds()
0ce1cab5   chenyueqi   好友赠送能量活动bug修复
1051
1052
1053
1054
1055
1056
1057
1058
  	local temp = redisproxy:smembers(FRIEND_ENERGY:format(roleId))
  	for _, id in pairs(temp) do
  		members[tonumber(id)] = 1
  	end
  
  	for id, _ in pairs(friendIds) do
  		if members[id] then
  			ids[id] = 1
0886d05a   chenyueqi   修改联动好友赠送获得的红点记录和通知
1059
  		end
0ce1cab5   chenyueqi   好友赠送能量活动bug修复
1060
1061
  	end
  
0886d05a   chenyueqi   修改联动好友赠送获得的红点记录和通知
1062
1063
  	actData.new = ids
  
cab7184b   chenyueqi   活动能量bug
1064
1065
1066
1067
  	local reward, change
  	if next(award) then
  		reward, change = role:award(award, {log = {desc = "actFriendHelp", int1 = actid, int2 = level}})
  	end
091912ed   chenyueqi   未测试版好友能量助力活动
1068
1069
1070
1071
1072
  	role.activity:updateActData("FriendEnergy", actData)
  	SendPacket(actionCodes.Activity_friendHelpRpc, MsgPack.pack({result = result, reward = reward}))
  	return true
  end
  
d763fb14   zhouhaihai   签到 九宫格
1073
  return _M