ActivityAction.lua
6.37 KB
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
35
36
37
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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
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
local task, tchange = role:award(curData.reward, {log = {desc = "sudoku", int1 = id, int2 = phase}}) -- 任务奖励
local reward, rchange = {}
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
reward, rchange = role:award(reward, {log = {desc = "sudokuR", int1 = id, int2 = phase}})
end
role:updateProperty({field = "sudoku", value = sudoku})
role:log("activity", {
activity_id = id, -- 活动ID(或活动指定任务的ID)
activity_type = 0, -- 活动类型,见活动类型枚举表
activity_reward = reward or {}, -- 活动奖励,json格式记录,{'itemid1':123,'itemid2':456,………...}
})
role:mylog("act_action", {desc = "sudoku", int1 = id, int2 = phase})
SendPacket(actionCodes.Activity_sudokuRpc, MsgPack.pack({task = role:packReward(task, tchange), reward = role:packReward(reward, rchange), rId = rId}))
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
local reward, change = role:award(globalCsv.guide_sudoku_reward[phase], {log = {desc = "sudokuRP", int1 = phase}})
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})
role:log("activity", {
activity_id = 10000 + phase, -- 活动ID(或活动指定任务的ID)
activity_type = 0, -- 活动类型,见活动类型枚举表
activity_reward = reward, -- 活动奖励,json格式记录,{'itemid1':123,'itemid2':456,………...}
})
SendPacket(actionCodes.Activity_sudokuRewardRpc, MsgPack.pack(role:packReward(reward, change)))
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
local reward, change = role:award(monthData[curDay].item, {log = {desc = "sign", int1 = yearMonth, int2 = curDay}})
role:changeUpdates({{type = "sign", field = curDay, value = yearMonth}})
SendPacket(actionCodes.Activity_signRpc, MsgPack.pack(role:packReward(reward, change)))
return true
end
function _M.actSignRpc(agent, data)
local role = agent.role
if not role.activity:isOpen("Sign") then return 1 end
local curData = role.activity:getActData("Sign")
local reward, change = {}
for day, csvData in ipairs(csvdb["new_signInCsv"]) do
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
role.activity:updateActData("Sign", curData)
reward, change = role:award(reward, {log = {desc = "actSign"}})
end
role:log("activity", {
activity_id = curData[0], -- 活动ID(或活动指定任务的ID)
activity_type = role.activity.ActivityType.Sign, -- 活动类型,见活动类型枚举表
activity_reward = reward, -- 活动奖励,json格式记录,{'itemid1':123,'itemid2':456,………...}
})
SendPacket(actionCodes.Activity_actSignRpc, MsgPack.pack(role:packReward(reward, change)))
return true
end
function _M.actPaySignRpc(agent, data)
local role = agent.role
local msg = MsgPack.unpack(data)
local actGoodsFlag = role.storeData:getProperty("actGoodsFlag")
local index = GetActGoodsIndex("paySignIn")
local flag = actGoodsFlag[index] or 0
if flag == 0 then return 1 end
if not role.activity:isOpen("PaySignIn") then return 2 end
local diffDay = diffFromOpen() + 1
local curData = role.activity:getActData("PaySignIn")
local reward, change = {}
for day, csvData in ipairs(csvdb["pay_signInCsv"]) do
if day <= diffDay 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
role.activity:updateActData("PaySignIn", curData)
reward, change = role:award(reward, {log = {desc = "actPaySign"}})
end
role:log("activity", {
activity_id = curData[0], -- 活动ID(或活动指定任务的ID)
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
return _M