Blame view

src/actions/DinerAction.lua 9.44 KB
87cc3a35   zhengshouren   餐厅建筑升级逻辑
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  local ipairs = ipairs
  local table = table
  local math = math
  local redisproxy = redisproxy
  local MsgPack = MsgPack
  
  local _M = {}
  
  function _M.addSellRpc( agent, data )
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
  	local slot = msg.slot
  	if math.illegalNum(slot, 1, role.dinerData:getMaxSlots()) then
214061fa   zhengshouren   错误情况,返回错误码
15
  		return 1
87cc3a35   zhengshouren   餐厅建筑升级逻辑
16
  	end
36204e3c   zhengshouren   贩卖逻辑
17
18
  	slot = tostring(slot)
  
87cc3a35   zhengshouren   餐厅建筑升级逻辑
19
20
21
  	local dish = msg.dish
  	local dishSet = csvdb["diner_dishCsv"][dish]
  	if not dishSet then
214061fa   zhengshouren   错误情况,返回错误码
22
  		return 2
87cc3a35   zhengshouren   餐厅建筑升级逻辑
23
  	end
36204e3c   zhengshouren   贩卖逻辑
24
25
  	local dishLevel = role.dinerData:getProperty("dishTree"):getv(dish, 0)
  	if dishLevel == 0 then
214061fa   zhengshouren   错误情况,返回错误码
26
  		return 3
36204e3c   zhengshouren   贩卖逻辑
27
28
29
  	end
  	local dishData = dishSet[dishLevel]
  	if not dishData then
214061fa   zhengshouren   错误情况,返回错误码
30
  		return 4
36204e3c   zhengshouren   贩卖逻辑
31
32
33
34
35
36
37
  	end
  
  	local calSell = role.dinerData:updateSell(slot, true) or {
  		deltaCount = 0,
  		deltaTime = 0,
  		lastCount = 0,
  	}
87cc3a35   zhengshouren   餐厅建筑升级逻辑
38
  	local count = msg.count
36204e3c   zhengshouren   贩卖逻辑
39
40
  	local maxDishCount = role.dinerData:getMaxDishs()
  	if math.illegalNum(count + calSell.lastCount, 1, maxDishCount) then
214061fa   zhengshouren   错误情况,返回错误码
41
  		return 5
87cc3a35   zhengshouren   餐厅建筑升级逻辑
42
43
  	end
  
36204e3c   zhengshouren   贩卖逻辑
44
45
46
47
48
  	local cost = dishData.material:toNumMap()
  	for _, n in pairs(cost) do
  		n = n * count
  	end
  	if not role:checkItemEnough(cost) then
214061fa   zhengshouren   错误情况,返回错误码
49
  		return 6
36204e3c   zhengshouren   贩卖逻辑
50
51
52
53
54
  	end
  
  	role:costItems(cost)
  	role.dinerData:updateSell(slot)
  
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
55
  	local dirty = false
452d6146   gaofengduan   fix diner task
56
57
  	for id, value in pairs(cost) do
  		if role.dinerData:checkDinerTask(DinerTask.UseMaterial, value, id, nil, true) then
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
58
59
60
  			dirty = true
  		end
  	end
da6362db   gaofengduan   fix dinerData
61
  	if role.dinerData:checkDinerTask(DinerTask.AddDish, count, dish, nil, true) then
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
62
63
64
  		dirty = true
  	end
  	if dirty then
da6362db   gaofengduan   fix dinerData
65
  		role.dinerData:notifyUpdateProperty("order", role.dinerData:getProperty("order"))
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
66
67
  	end
  
36204e3c   zhengshouren   贩卖逻辑
68
69
70
71
72
  	local sells = json.decode(role.dinerData:getProperty("sells"))
  	if not sells[slot] then
  		sells[slot] = {
  			dish = dish,
  			level = dishLevel,
37037eeb   zhengshouren   计算奖励
73
  			reward = "",
090340b9   gaofengduan   fix 餐车
74
  			count = 0,
36204e3c   zhengshouren   贩卖逻辑
75
76
77
  		}
  	end
  	local sell = sells[slot]
36204e3c   zhengshouren   贩卖逻辑
78
79
80
81
82
83
84
85
  	sell.count = sell.count + count
  	sell.time = skynet.timex() - calSell.deltaTime
  	sell.hot = role.dinerData:getProperty("hot"):getv(sell.dish, 0)
  
  	role.dinerData:updateProperty({field = "sells", value = json.encode(sells)})
  	SendPacket(actionCodes.Diner_addSellRpc, "")
  	
  	return true
87cc3a35   zhengshouren   餐厅建筑升级逻辑
86
87
  end
  
1ab9458f   gaofengduan   add 下菜操作
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
  function _M.removeSellRpc( agent, data )
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
  	local slot = msg.slot
  	if math.illegalNum(slot, 1, role.dinerData:getMaxSlots()) then
  		return 1
  	end
  	slot = tostring(slot)
  	local sells = json.decode(role.dinerData:getProperty("sells"))
  	local sell = sells[slot]
  	if not sell then
  		return 2
  	end
  
  	local dish = sell.dish
  	local dishSet = csvdb["diner_dishCsv"][dish]
  	if not dishSet then
  		return 3
  	end
  	local dishLevel = role.dinerData:getProperty("dishTree"):getv(dish, 0)
  	if dishLevel == 0 then
  		return 4
  	end
  	local dishData = dishSet[dishLevel]
  	if not dishData then
  		return 5
  	end
  
  	local reward = {}
  	local cost = dishData.material:toNumMap()
  	for k, n in pairs(cost) do
  		local sum = n*sell.count
  		role:addItem({itemId = k,count = sum})
  		reward[k] = sum
  	end
  	sells[slot] = nil
  	role.dinerData:updateProperty({field = "sells", value = json.encode(sells)})
  	SendPacket(actionCodes.Diner_removeSellRpc, MsgPack.pack({reward = reward}))
  	return true
  end
  
87cc3a35   zhengshouren   餐厅建筑升级逻辑
130
  function _M.getSellRewardRpc( agent, data )
5d57bd79   gaofengduan   add 餐车 getSellRew...
131
  	local role = agent.role
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
132
  	local dirty = false
f5c07b1b   gaofengduan   fix diner
133
  	local reward = ""
5d57bd79   gaofengduan   add 餐车 getSellRew...
134
  	local sells = json.decode(role.dinerData:getProperty("sells"))
32161569   gaofengduan   fix diner
135
  	for slot, _ in pairs(sells) do
0c0b161d   gaofengduan   fix getSellRewardRpc
136
  		role.dinerData:updateSell(slot)
32161569   gaofengduan   fix diner
137
138
139
  	end
  	sells = json.decode(role.dinerData:getProperty("sells"))
  	for slot, sell in pairs(sells) do
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
140
141
  		local rewards = sell.reward:toNumMap()
  		for k,v in pairs(rewards) do
f5c07b1b   gaofengduan   fix diner
142
  			reward = reward:incrv(k, v)
5d57bd79   gaofengduan   add 餐车 getSellRew...
143
  		end
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
144
145
  
  		if rewards[ItemId.Gold] and rewards[ItemId.Gold] > 0 then
da6362db   gaofengduan   fix dinerData
146
  			if role.dinerData:checkDinerTask(DinerTask.DishWithGold, rewards[ItemId.Gold], sell.dish, nil, true) then
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
147
148
149
  				dirty = true
  			end
  		end
32161569   gaofengduan   fix diner
150
  		sells[slot].reward = ""
5d57bd79   gaofengduan   add 餐车 getSellRew...
151
  	end
f5c07b1b   gaofengduan   fix diner
152
153
  	role.dinerData:updateProperty({field = "sells", value = json.encode(sells)})
  	for k, v in pairs(reward:toNumMap()) do
0c0b161d   gaofengduan   fix getSellRewardRpc
154
  		role:addItem({itemId = k,count = v})
5d57bd79   gaofengduan   add 餐车 getSellRew...
155
  	end
32161569   gaofengduan   fix diner
156
  
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
157
  	if dirty then
da6362db   gaofengduan   fix dinerData
158
  		role.dinerData:notifyUpdateProperty("order", role.dinerData:getProperty("order"))
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
159
160
  	end
  
0c0b161d   gaofengduan   fix getSellRewardRpc
161
  	SendPacket(actionCodes.Diner_getSellRewardRpc, MsgPack.pack({reward = reward}))
5d57bd79   gaofengduan   add 餐车 getSellRew...
162
  	return true
87cc3a35   zhengshouren   餐厅建筑升级逻辑
163
164
165
166
167
168
169
  end
  
  function _M.levelUpRpc( agent, data )
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
  	local index = msg.index
f9c6cac9   zhengshouren   建筑升级增加 其他建筑物等级限制
170
171
  	local buildingSet = csvdb["diner_buildingCsv"][index]
  	if not buildingSet then
87cc3a35   zhengshouren   餐厅建筑升级逻辑
172
173
174
175
176
  		return
  	end
  
  	local buildL = role.dinerData:getProperty("buildL")
  	local curLevel = buildL:getv(index, 1)
f9c6cac9   zhengshouren   建筑升级增加 其他建筑物等级限制
177
  	if curLevel >= #buildingSet then
87cc3a35   zhengshouren   餐厅建筑升级逻辑
178
179
  		return
  	end
f9c6cac9   zhengshouren   建筑升级增加 其他建筑物等级限制
180
181
182
183
184
  	local buildingData = buildingSet[curLevel]
  	if not buildingData then
  		return
  	end
  	if buildingData.upLimit ~= "" then
4a969fc5   gaofengduan   fix diner levelUpRpc
185
  		local id, level = buildingData.upLimit:match("(%d+)=(%d+)")
f9c6cac9   zhengshouren   建筑升级增加 其他建筑物等级限制
186
187
188
189
  		if buildL:getv(tonumber(id), 1) < tonumber(level) then
  			return
  		end
  	end
87cc3a35   zhengshouren   餐厅建筑升级逻辑
190
  
f9c6cac9   zhengshouren   建筑升级增加 其他建筑物等级限制
191
  	local cost = buildingData.starCost:toNumMap()
87cc3a35   zhengshouren   餐厅建筑升级逻辑
192
193
194
195
  	if not role:checkItemEnough(cost) then
  		return 
  	end
  
36204e3c   zhengshouren   贩卖逻辑
196
  	role:costItems(cost)
d96fae59   gaofengduan   fix diner levelUpRpc
197
  	role.dinerData:updateProperty({field = "buildL", value = buildL:setv(index, curLevel + 1)})
87cc3a35   zhengshouren   餐厅建筑升级逻辑
198
199
200
201
202
  
  	SendPacket(actionCodes.Diner_levelUpRpc, '')
  	return true
  end
  
b67180e8   zhengshouren   餐厅天赋升级
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
  function _M.talentUpRpc( agent, data )
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
  	local dish = msg.dish
  	local dishSet = csvdb["diner_dishCsv"][dish]
  	if not dishSet then
  		return
  	end
  
  	local dishTree = role.dinerData:getProperty("dishTree")
  	local dishLevel = dishTree:getv(dish, 0)
  	local cost = {}
  	local treePoint = {}
  	if dishLevel == 0 then
  		local dishData = dishSet[1]
  		if dishData.unlock_tree > 0 then
  			if dishTree:getv(dishData.unlock_tree, 0) == 0 then
  				return
  			end
  		end
  		if dishData.unlock_carbon > 0 then
  			local hangPass = role:getProperty("hangPass")
  			if not hangPass[dishData.unlock_carbon] then
  				return
  			end
  		end
  		cost = globalCsv.diner_sell_dish_talent_unlock:toNumMap()
  	else
  		if dishLevel >= #dishSet then
  			return
  		end
  		local dishData = dishSet[dishLevel]
  		cost = dishData.tree_material:toNumMap()
  		treePoint = dishData.tree_point:toNumMap()
  	end
  	if not role:checkItemEnough(cost) then
  		return
  	end
  
  	role:costItems(cost)
  	role.dinerData:updateProperty({field = "dishTree", value = dishTree:setv(dish, dishLevel + 1)})
  	if next(treePoint) then
  		role:award(treePoint)
  	end
  
  	SendPacket(actionCodes.Diner_talentUpRpc, '')
  	return true
  end
  
7d44dca2   zhengshouren   支援技能升级逻辑
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
  function _M.skillUpRpc( agent, data )
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
  	local skill = msg.skill
  	local skillSet = csvdb["diner_skillCsv"][skill]
  	if not skillSet then
  		return
  	end
  
  	local skillTree = role.dinerData:getProperty("skillTree")
  	local skillLevel = skillTree:getv(skill, 1)
  	local skillData = skillSet[skillLevel]
  	if not skillData then
  		return
  	end
  	if skillData.unlock ~= "" then
  		local id, level = skillData.unlock:math("(%d+)=(%d+)")
  		if skillTree:getv(tonumber(id), 1) < tonumber(level) then
  			return
  		end
  	end
  	local cost = skillData.cost:toNumMap()
  	if not role:checkItemEnough(cost) then
  		return
  	end
  
  	role:costItems(cost)
  	role.dinerData:updateProperty({field = "skillTree", value = skillTree:setv(skill, skillLevel + 1)})
  
  	SendPacket(actionCodes.Diner_skillUpRpc, '')
  	return true
  end
  
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
287
288
289
290
291
292
293
294
295
296
297
298
299
  function _M.lockTaskRpc( agent, data )
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local index = msg.index
  
  	if math.illegalNum(index, 1, 7) then
  		return 1
  	end
  	local orders = json.decode(role.dinerData:getProperty("order"))
  	local order = orders[index]
  	if not order then
  		return 2
  	end
fdb86cad   gaofengduan   fix diner task
300
301
302
303
  	if order.lock == 0 then
  		order.lock = 1
  	else
  		order.lock = 0
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
304
  	end
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
305
  	role.dinerData:updateProperty({field = "order", value = json.encode(orders)})
fdb86cad   gaofengduan   fix diner task
306
  	SendPacket(actionCodes.Diner_lockTaskRpc, MsgPack.pack({lock = order.lock}))
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
307
308
309
  	return true
  end
  
fdb86cad   gaofengduan   fix diner task
310
  function _M.updateTaskRpc( agent, data )
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
311
312
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
313
  	local index = msg.index
fdb86cad   gaofengduan   fix diner task
314
315
  	-- 0 放弃已接受任务,1 接受任务,2 完成已接受任务
  	local cmd = msg.cmd
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
316
317
318
319
320
321
322
323
324
  
  	if math.illegalNum(index, 1, 7) then
  		return 1
  	end
  	local orders = json.decode(role.dinerData:getProperty("order"))
  	local order = orders[index]
  	if not order then
  		return 2
  	end
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
325
326
327
328
329
330
331
332
  	local taskSet = csvdb["diner_questCsv"][order.lv]
  	if not taskSet then
  		return 4
  	end
  	local taskData = taskSet[order.id]
  	if not taskData then
  		return 5
  	end
fdb86cad   gaofengduan   fix diner task
333
  	
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
334
  
fdb86cad   gaofengduan   fix diner task
335
336
337
338
339
340
341
342
343
344
345
346
347
  	if cmd == 0 then
  		if order.status ~= 0 then
  			return 30
  		end
  		orders[index].status = 1
  		orders[index].lock = 1
  	elseif cmd == 1 then
  		if order.status ~= 1 then
  			return 31
  		end
  		orders[index].status = 0
  		orders[index].lock = 0
  	elseif cmd == 2 then
452d6146   gaofengduan   fix diner task
348
  		if order.status ~= 1 then
fdb86cad   gaofengduan   fix diner task
349
350
  			return 32
  		end
452d6146   gaofengduan   fix diner task
351
  		if order.n < taskData.value then
fdb86cad   gaofengduan   fix diner task
352
353
354
355
356
  			return 6
  		end
  		for typ, count in pairs(taskData.reward:toNumMap()) do
  			role:addItem({itemId = typ, count = count})
  		end
452d6146   gaofengduan   fix diner task
357
  		table.remove(orders,index)
fdb86cad   gaofengduan   fix diner task
358
359
  	else
  		return 33
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
360
361
  	end
  
fdb86cad   gaofengduan   fix diner task
362
363
  	role.dinerData:updateProperty({field = "order", value = json.encode(orders)})
  	SendPacket(actionCodes.Diner_updateTaskRpc, '')
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
364
365
366
  	return true
  end
  
fdb86cad   gaofengduan   fix diner task
367
  function _M.refreshTaskRpc( agent, data )
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
368
369
370
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
fdb86cad   gaofengduan   fix diner task
371
  	local cost = {[ItemId.Diamond] = 40}
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
372
373
374
375
376
377
378
379
380
381
382
383
384
385
  	if not role:checkItemEnough(cost) then
  		return 1
  	end
  
  	local orders = json.decode(role.dinerData:getProperty("order"))
  	if #orders > 6 then
  		return 2
  	end
  
  	local taskLevel = role.dinerData:getProperty("buildL"):getv(5, 1)
  	local taskData = csvdb["diner_questCsv"][taskLevel]
  	if not taskData then
  		return 3
  	end
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
386
387
388
  
  	role:costItems(cost)
  
ca232abd   gaofengduan   fix diner task re...
389
390
391
392
393
394
395
  	for k,v in pairs(orders) do
  		if v.lock == 0 then
  			local index = math.randWeight(taskData, "chance")
  			local t = taskData[index]
  			orders[k] = {lv = taskLevel, id = t.id, n = 0, lock = 0,status = 0}
  		end
  	end
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
396
397
  	role.dinerData:updateProperty({field = "order", value = json.encode(orders)})
  	
ca232abd   gaofengduan   fix diner task re...
398
  	SendPacket(actionCodes.Diner_refreshTaskRpc, '')	
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
399
400
401
402
  	return true
  end
  
  
87cc3a35   zhengshouren   餐厅建筑升级逻辑
403
  return _M