Blame view

src/actions/DinerAction.lua 18 KB
87cc3a35   zhengshouren   餐厅建筑升级逻辑
1
2
3
4
5
6
7
8
9
10
11
  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)
03a6166a   zhouhaihai   餐厅优化
12
  	local sellData = msg
87cc3a35   zhengshouren   餐厅建筑升级逻辑
13
  
03a6166a   zhouhaihai   餐厅优化
14
15
16
17
18
19
20
21
22
  	local slot = sellData.slot
  	local sells = json.decode(role.dinerData:getProperty("sells"))
  	if sells[slot] and sells[slot].count and sells[slot].count ~= 0 then
  		return 0
  	end
  	if math.illegalNum(slot, 1, role.dinerData:getMaxSlots()) then
  		return 1
  	end
  	slot = tostring(slot)
36204e3c   zhengshouren   贩卖逻辑
23
  
03a6166a   zhouhaihai   餐厅优化
24
25
26
27
28
29
30
31
32
33
34
35
36
  	local dish = sellData.dish
  	local dishSet = csvdb["diner_dishCsv"][dish]
  	if not dishSet then
  		return 2
  	end
  	local dishLevel = role.dinerData:getProperty("dishTree"):getv(dish, 0)
  	if dishLevel == 0 then
  		return 3
  	end
  	local dishData = dishSet[dishLevel]
  	if not dishData then
  		return 4
  	end
87cc3a35   zhengshouren   餐厅建筑升级逻辑
37
  
03a6166a   zhouhaihai   餐厅优化
38
39
40
41
42
43
44
45
46
47
  	local calSell = role.dinerData:updateSell(slot, true) or {
  		deltaCount = 0,
  		deltaTime = 0,
  		lastCount = 0,
  	}
  	local count = sellData.count
  	local maxDishCount = role.dinerData:getMaxDishs()
  	if math.illegalNum(count + calSell.lastCount, 1, maxDishCount) then
  		return 5
  	end
36204e3c   zhengshouren   贩卖逻辑
48
  
03a6166a   zhouhaihai   餐厅优化
49
50
51
52
53
54
55
  	local cost = dishData.material:toNumMap()
  	for k, n in pairs(cost) do
  		cost[k] = n * count
  	end
  	if not role:checkItemEnough(cost) then
  		return 6
  	end
36204e3c   zhengshouren   贩卖逻辑
56
  
03a6166a   zhouhaihai   餐厅优化
57
58
  	role:costItems(cost)
  	role.dinerData:updateSell(slot)
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
59
  
03a6166a   zhouhaihai   餐厅优化
60
61
62
63
64
65
66
67
68
69
  	role:checkTaskEnter("MakeFood", {id = dish, count = count})
  	-- local dirty = false
  	-- if dirty then
  	-- 	role.dinerData:notifyUpdateProperty("order", role.dinerData:getProperty("order"))
  	-- end
  
  	sells = json.decode(role.dinerData:getProperty("sells"))
  	if not sells[slot] then
  		sells[slot] = {
  			reward = "",
59835765   zhouhaihai   排行榜
70
  			popular = 0,
03a6166a   zhouhaihai   餐厅优化
71
  		}
36204e3c   zhengshouren   贩卖逻辑
72
  	end
03a6166a   zhouhaihai   餐厅优化
73
74
75
76
77
  	sells[slot].dish = dish
  	sells[slot].level = dishLevel
  	sells[slot].count = count
  	sells[slot].time = skynet.timex() - calSell.deltaTime
  	role.dinerData:updateProperty({field = "sells", value = json.encode(sells)})
36204e3c   zhengshouren   贩卖逻辑
78
  	SendPacket(actionCodes.Diner_addSellRpc, "")
36204e3c   zhengshouren   贩卖逻辑
79
  	return true
87cc3a35   zhengshouren   餐厅建筑升级逻辑
80
81
  end
  
1ab9458f   gaofengduan   add 下菜操作
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  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
1ab9458f   gaofengduan   add 下菜操作
96
97
98
99
100
101
102
103
104
105
106
107
108
109
  	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
  
6991df1b   gaofengduan   fix bug
110
  	role.dinerData:updateSell(slot)
1ab9458f   gaofengduan   add 下菜操作
111
112
113
114
115
116
117
  	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
5a307eb6   gaofengduan   fix diner
118
  	sells[slot].count = 0
1ab9458f   gaofengduan   add 下菜操作
119
120
121
122
123
  	role.dinerData:updateProperty({field = "sells", value = json.encode(sells)})
  	SendPacket(actionCodes.Diner_removeSellRpc, MsgPack.pack({reward = reward}))
  	return true
  end
  
87cc3a35   zhengshouren   餐厅建筑升级逻辑
124
  function _M.getSellRewardRpc( agent, data )
5d57bd79   gaofengduan   add 餐车 getSellRew...
125
  	local role = agent.role
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
126
  	local dirty = false
59835765   zhouhaihai   排行榜
127
  	local reward, popular = "", 0
5d57bd79   gaofengduan   add 餐车 getSellRew...
128
  	local sells = json.decode(role.dinerData:getProperty("sells"))
32161569   gaofengduan   fix diner
129
  	for slot, _ in pairs(sells) do
0c0b161d   gaofengduan   fix getSellRewardRpc
130
  		role.dinerData:updateSell(slot)
32161569   gaofengduan   fix diner
131
132
133
  	end
  	sells = json.decode(role.dinerData:getProperty("sells"))
  	for slot, sell in pairs(sells) do
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
134
135
  		local rewards = sell.reward:toNumMap()
  		for k,v in pairs(rewards) do
f5c07b1b   gaofengduan   fix diner
136
  			reward = reward:incrv(k, v)
5d57bd79   gaofengduan   add 餐车 getSellRew...
137
  		end
59835765   zhouhaihai   排行榜
138
  		popular = popular + (sell.popular or 0)
77302523   zhouhaihai   任务
139
  		
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
140
  		if rewards[ItemId.Gold] and rewards[ItemId.Gold] > 0 then
da6362db   gaofengduan   fix dinerData
141
  			if role.dinerData:checkDinerTask(DinerTask.DishWithGold, rewards[ItemId.Gold], sell.dish, nil, true) then
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
142
143
  				dirty = true
  			end
77302523   zhouhaihai   任务
144
145
146
147
148
149
150
  			if role.dinerData:checkDinerTask(DinerTask.DishWithGoldType, rewards[ItemId.Gold], math.ceil(sell.dish / 100), nil, true) then
  				dirty = true
  			end
  			local dishData = csvdb["diner_dishCsv"][sell.dish][sell.level]
  			if role.dinerData:checkDinerTask(DinerTask.DishWithGoldRare, rewards[ItemId.Gold], dishData.rarity, nil, true) then
  				dirty = true
  			end
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
151
  		end
32161569   gaofengduan   fix diner
152
  		sells[slot].reward = ""
59835765   zhouhaihai   排行榜
153
  		sells[slot].popular = 0
5d57bd79   gaofengduan   add 餐车 getSellRew...
154
  	end
f5c07b1b   gaofengduan   fix diner
155
156
  	role.dinerData:updateProperty({field = "sells", value = json.encode(sells)})
  	for k, v in pairs(reward:toNumMap()) do
0c0b161d   gaofengduan   fix getSellRewardRpc
157
  		role:addItem({itemId = k,count = v})
53e8037e   zhouhaihai   任务
158
159
160
  		if k == ItemId.Gold then
  			role:checkTaskEnter("FoodSellGold", {count = v})
  		end
5d57bd79   gaofengduan   add 餐车 getSellRew...
161
  	end
32161569   gaofengduan   fix diner
162
  
59835765   zhouhaihai   排行榜
163
164
  	role.dinerData:popularAdd(popular)
  
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
165
  	if dirty then
da6362db   gaofengduan   fix dinerData
166
  		role.dinerData:notifyUpdateProperty("order", role.dinerData:getProperty("order"))
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
167
  	end
0c0b161d   gaofengduan   fix getSellRewardRpc
168
  	SendPacket(actionCodes.Diner_getSellRewardRpc, MsgPack.pack({reward = reward}))
5d57bd79   gaofengduan   add 餐车 getSellRew...
169
  	return true
87cc3a35   zhengshouren   餐厅建筑升级逻辑
170
171
  end
  
2050d40d   gaofengduan   add diner expedit...
172
173
  function _M.expediteSellRpc( agent, data )
  	local role = agent.role
020fc7ed   gaofengduan   fix diner expedit...
174
175
  	local count = role.dinerData:getProperty("expedite")
  	local max = #globalCsv.diner_sell_quick_cost
2c63e6a0   gaofengduan   fix dienr
176
  	if count > max then
020fc7ed   gaofengduan   fix diner expedit...
177
178
  		return 1
  	end
10974097   gaofengduan   fix diner
179
180
181
182
183
184
185
  	local diamond = globalCsv.diner_sell_quick_cost[count]
  	if diamond > 0 then
  		local cost = {[ItemId.Diamond] = diamond}
  		if not role:checkItemEnough(cost) then
  			return 2
  		end
  		role:costItems(cost)
020fc7ed   gaofengduan   fix diner expedit...
186
  	end
020fc7ed   gaofengduan   fix diner expedit...
187
  
2050d40d   gaofengduan   add diner expedit...
188
  	local dirty = false
59835765   zhouhaihai   排行榜
189
  	local reward,popular = "", 0
2050d40d   gaofengduan   add diner expedit...
190
191
192
193
194
195
  	local sells = json.decode(role.dinerData:getProperty("sells"))
  	for slot, _ in pairs(sells) do
  		role.dinerData:updateSell(slot)
  	end
  	sells = json.decode(role.dinerData:getProperty("sells"))
  	for slot, sell in pairs(sells) do
020fc7ed   gaofengduan   fix diner expedit...
196
  		local result = role.dinerData:expediteSell(slot)
6991df1b   gaofengduan   fix bug
197
198
199
200
201
202
  		if result then
  			local rewards = result.reward:toNumMap()
  			for k,v in pairs(result.reward:toNumMap()) do
  				reward = reward:incrv(k,v)
  			end
  			popular = popular + result.popular
2050d40d   gaofengduan   add diner expedit...
203
  
6991df1b   gaofengduan   fix bug
204
205
206
207
  			if rewards[ItemId.Gold] and rewards[ItemId.Gold] > 0 then
  				if role.dinerData:checkDinerTask(DinerTask.DishWithGold, rewards[ItemId.Gold], sell.dish, nil, true) then
  					dirty = true
  				end
77302523   zhouhaihai   任务
208
209
210
211
212
213
214
  				if role.dinerData:checkDinerTask(DinerTask.DishWithGoldType, rewards[ItemId.Gold], math.ceil(sell.dish / 100), nil, true) then
  					dirty = true
  				end
  				local dishData = csvdb["diner_dishCsv"][sell.dish][sell.level]
  				if role.dinerData:checkDinerTask(DinerTask.DishWithGoldRare, rewards[ItemId.Gold], dishData.rarity, nil, true) then
  					dirty = true
  				end
2050d40d   gaofengduan   add diner expedit...
215
216
217
218
  			end
  		end
  	end
  
020fc7ed   gaofengduan   fix diner expedit...
219
220
221
  	role.dinerData:notifyUpdateProperty("sells", role.dinerData:getProperty("sells"))
  	role.dinerData:setProperty("expedite",count+1)
  	role.dinerData:notifyUpdateProperty("expedite", count+1)
2050d40d   gaofengduan   add diner expedit...
222
223
224
225
  	for k, v in pairs(reward:toNumMap()) do
  		role:addItem({itemId = k,count = v})
  	end
  
59835765   zhouhaihai   排行榜
226
227
  	role.dinerData:popularAdd(popular)
  
2050d40d   gaofengduan   add diner expedit...
228
229
230
  	if dirty then
  		role.dinerData:notifyUpdateProperty("order", role.dinerData:getProperty("order"))
  	end
53e8037e   zhouhaihai   任务
231
  	role:checkTaskEnter("FoodSellQuick")
020fc7ed   gaofengduan   fix diner expedit...
232
  	SendPacket(actionCodes.Diner_expediteSellRpc, MsgPack.pack({reward = reward,popular = popular}))
2050d40d   gaofengduan   add diner expedit...
233
234
235
  	return true
  end
  
87cc3a35   zhengshouren   餐厅建筑升级逻辑
236
237
238
239
240
  function _M.levelUpRpc( agent, data )
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
  	local index = msg.index
f9c6cac9   zhengshouren   建筑升级增加 其他建筑物等级限制
241
242
  	local buildingSet = csvdb["diner_buildingCsv"][index]
  	if not buildingSet then
87cc3a35   zhengshouren   餐厅建筑升级逻辑
243
244
245
246
247
  		return
  	end
  
  	local buildL = role.dinerData:getProperty("buildL")
  	local curLevel = buildL:getv(index, 1)
f9c6cac9   zhengshouren   建筑升级增加 其他建筑物等级限制
248
  	if curLevel >= #buildingSet then
87cc3a35   zhengshouren   餐厅建筑升级逻辑
249
250
  		return
  	end
f9c6cac9   zhengshouren   建筑升级增加 其他建筑物等级限制
251
252
253
254
255
  	local buildingData = buildingSet[curLevel]
  	if not buildingData then
  		return
  	end
  	if buildingData.upLimit ~= "" then
4a969fc5   gaofengduan   fix diner levelUpRpc
256
  		local id, level = buildingData.upLimit:match("(%d+)=(%d+)")
f9c6cac9   zhengshouren   建筑升级增加 其他建筑物等级限制
257
258
259
260
  		if buildL:getv(tonumber(id), 1) < tonumber(level) then
  			return
  		end
  	end
87cc3a35   zhengshouren   餐厅建筑升级逻辑
261
  
f9c6cac9   zhengshouren   建筑升级增加 其他建筑物等级限制
262
  	local cost = buildingData.starCost:toNumMap()
87cc3a35   zhengshouren   餐厅建筑升级逻辑
263
  	if not role:checkItemEnough(cost) then
289a4927   gaofengduan   fix diner talent
264
  		return
87cc3a35   zhengshouren   餐厅建筑升级逻辑
265
266
  	end
  
36204e3c   zhengshouren   贩卖逻辑
267
  	role:costItems(cost)
d96fae59   gaofengduan   fix diner levelUpRpc
268
  	role.dinerData:updateProperty({field = "buildL", value = buildL:setv(index, curLevel + 1)})
53e8037e   zhouhaihai   任务
269
  	role:checkTaskEnter("DinerLevelUp", {type = index, level = curLevel + 1})
87cc3a35   zhengshouren   餐厅建筑升级逻辑
270
271
272
273
  	SendPacket(actionCodes.Diner_levelUpRpc, '')
  	return true
  end
  
b67180e8   zhengshouren   餐厅天赋升级
274
275
276
  function _M.talentUpRpc( agent, data )
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
b67180e8   zhengshouren   餐厅天赋升级
277
  	local dish = msg.dish
b67180e8   zhengshouren   餐厅天赋升级
278
279
  	local dishTree = role.dinerData:getProperty("dishTree")
  	local dishLevel = dishTree:getv(dish, 0)
289a4927   gaofengduan   fix diner talent
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
  
  	local talentSet = csvdb["diner_talentCsv"][dish]
  	if not talentSet then
  		return 1
  	end
  
  	local talentData = talentSet[dishLevel]
  	if not talentData then
  		return 2
  	end
  
  	if not talentSet[dishLevel+1] then
  		return 21
  	end
  
  	local typ = math.floor(dish/100 + 1)
  	local treeSet = csvdb["diner_treeCsv"][typ]
  	if not treeSet then
  		return 3
  	end
  
  	local treeData = treeSet[dish]
  	if not treeData then
  		return 4
  	end
  
653e7a15   zhouhaihai   talent 前置调整
306
  	local limit = talentData.pointFront:toNumMap()
289a4927   gaofengduan   fix diner talent
307
308
309
310
  	for k,v in pairs(limit) do
  		local lv = dishTree:getv(k, 0)
  		if lv < v then
  			return 5
b67180e8   zhengshouren   餐厅天赋升级
311
  		end
b67180e8   zhengshouren   餐厅天赋升级
312
  	end
289a4927   gaofengduan   fix diner talent
313
314
  
  	local cost = talentData.cost:toNumMap()
b67180e8   zhengshouren   餐厅天赋升级
315
  	if not role:checkItemEnough(cost) then
289a4927   gaofengduan   fix diner talent
316
317
318
  		return 6
  	end
  
dbd0ca58   gaofengduan   car  营养剂制作
319
  	-- 正在贩卖不能升级料理天赋
289a4927   gaofengduan   fix diner talent
320
321
322
323
324
325
  	local sells = json.decode(role.dinerData:getProperty("sells"))
  	for slot, _ in pairs(sells) do
  		role.dinerData:updateSell(slot)
  	end
  	sells = json.decode(role.dinerData:getProperty("sells"))
  	for _, sell in pairs(sells) do
6991df1b   gaofengduan   fix bug
326
  		if sell.dish == msg.dish and sell.count > 0 then
289a4927   gaofengduan   fix diner talent
327
328
  			return 7
  		end
b67180e8   zhengshouren   餐厅天赋升级
329
330
  	end
  
dbd0ca58   gaofengduan   car  营养剂制作
331
  	-- 正在冒险不能升级营养剂天赋
69d686f8   gaofengduan   暂时取消营养剂天赋升级限制
332
333
334
  	-- if talentData.effect:toArray(true,"=")[1] == 2 then
  	-- 	if next(role:getProperty("advTeam")) then return 8 end
  	-- end
dbd0ca58   gaofengduan   car  营养剂制作
335
  
b67180e8   zhengshouren   餐厅天赋升级
336
337
  	role:costItems(cost)
  	role.dinerData:updateProperty({field = "dishTree", value = dishTree:setv(dish, dishLevel + 1)})
289a4927   gaofengduan   fix diner talent
338
  	local treePoint = talentData.tree_point:toNumMap()
b67180e8   zhengshouren   餐厅天赋升级
339
340
341
342
  	if next(treePoint) then
  		role:award(treePoint)
  	end
  
53e8037e   zhouhaihai   任务
343
344
  	role:checkTaskEnter("DinerTalentUp", {type = talentData.effect:toArray(true,"=")[1]})
  
b67180e8   zhengshouren   餐厅天赋升级
345
346
347
348
  	SendPacket(actionCodes.Diner_talentUpRpc, '')
  	return true
  end
  
7d44dca2   zhengshouren   支援技能升级逻辑
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
  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   领取任务,锁定任务,获得特殊任务
383
384
385
386
387
  function _M.lockTaskRpc( agent, data )
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local index = msg.index
  
550ba7e7   zhouhaihai   订单
388
389
390
  	local orders = json.decode(role.dinerData:getProperty("order"))
  
  	if math.illegalNum(index, 1, #orders) then
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
391
392
  		return 1
  	end
550ba7e7   zhouhaihai   订单
393
  	
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
394
395
396
397
  	local order = orders[index]
  	if not order then
  		return 2
  	end
fdb86cad   gaofengduan   fix diner task
398
399
400
401
  	if order.lock == 0 then
  		order.lock = 1
  	else
  		order.lock = 0
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
402
  	end
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
403
  	role.dinerData:updateProperty({field = "order", value = json.encode(orders)})
fdb86cad   gaofengduan   fix diner task
404
  	SendPacket(actionCodes.Diner_lockTaskRpc, MsgPack.pack({lock = order.lock}))
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
405
406
407
  	return true
  end
  
fdb86cad   gaofengduan   fix diner task
408
  function _M.updateTaskRpc( agent, data )
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
409
410
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
411
  	local index = msg.index
550ba7e7   zhouhaihai   订单
412
  	-- 0 接受任务,1 放弃已接受任务,2 完成已接受任务
fdb86cad   gaofengduan   fix diner task
413
  	local cmd = msg.cmd
550ba7e7   zhouhaihai   订单
414
415
  	local orders = json.decode(role.dinerData:getProperty("order"))
  	if math.illegalNum(index, 1, #orders) then
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
416
417
  		return 1
  	end
550ba7e7   zhouhaihai   订单
418
  	
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
419
420
421
422
  	local order = orders[index]
  	if not order then
  		return 2
  	end
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
423
424
425
426
427
428
429
430
  	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
289a4927   gaofengduan   fix diner talent
431
  
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
432
  
fdb86cad   gaofengduan   fix diner task
433
434
435
436
437
438
  	if cmd == 0 then
  		if order.status ~= 0 then
  			return 30
  		end
  		orders[index].status = 1
  		orders[index].lock = 1
53e8037e   zhouhaihai   任务
439
  		role:checkTaskEnter("GetOderTask", {rarity = taskSet.rarity})
fdb86cad   gaofengduan   fix diner task
440
441
442
443
444
445
446
  	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
447
  		if order.status ~= 1 then
fdb86cad   gaofengduan   fix diner task
448
449
  			return 32
  		end
452d6146   gaofengduan   fix diner task
450
  		if order.n < taskData.value then
fdb86cad   gaofengduan   fix diner task
451
452
453
454
455
  			return 6
  		end
  		for typ, count in pairs(taskData.reward:toNumMap()) do
  			role:addItem({itemId = typ, count = count})
  		end
452d6146   gaofengduan   fix diner task
456
  		table.remove(orders,index)
53e8037e   zhouhaihai   任务
457
  		role:checkTaskEnter("OverOderTask", {rarity = taskSet.rarity})
fdb86cad   gaofengduan   fix diner task
458
459
  	else
  		return 33
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
460
461
  	end
  
fdb86cad   gaofengduan   fix diner task
462
463
  	role.dinerData:updateProperty({field = "order", value = json.encode(orders)})
  	SendPacket(actionCodes.Diner_updateTaskRpc, '')
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
464
465
466
  	return true
  end
  
fdb86cad   gaofengduan   fix diner task
467
  function _M.refreshTaskRpc( agent, data )
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
468
469
470
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
fdb86cad   gaofengduan   fix diner task
471
  	local cost = {[ItemId.Diamond] = 40}
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
472
473
474
475
476
  	if not role:checkItemEnough(cost) then
  		return 1
  	end
  
  	local orders = json.decode(role.dinerData:getProperty("order"))
550ba7e7   zhouhaihai   订单
477
478
  
  	local hadTask = {}
7898054a   zhouhaihai   新随机订单
479
  	local needCount = 0
550ba7e7   zhouhaihai   订单
480
  	for idx, temp in pairs(orders) do
7898054a   zhouhaihai   新随机订单
481
  		if temp.lock ~= 0 or temp.status ~= 0 then
550ba7e7   zhouhaihai   订单
482
  			hadTask[temp.id] = 1
7898054a   zhouhaihai   新随机订单
483
484
  		else
  			needCount = needCount + 1
550ba7e7   zhouhaihai   订单
485
  		end
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
486
487
  	end
  
550ba7e7   zhouhaihai   订单
488
489
  	if needCount <= 0 then return 2 end
  
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
490
491
492
493
494
  	local taskLevel = role.dinerData:getProperty("buildL"):getv(5, 1)
  	local taskData = csvdb["diner_questCsv"][taskLevel]
  	if not taskData then
  		return 3
  	end
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
495
  
550ba7e7   zhouhaihai   订单
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
  	local pool = {}
  	for id, temp in pairs(taskData) do
  		if not hadTask[id] then
  			table.insert(pool, temp)
  		end
  	end
  	local needCount = math.min(#pool, needCount) -- 需要的任务个数
  
  	if needCount <= 0 then return end
  
  	local cost = globalCsv.diner_task_refresh_cost:toNumMap()
  	for itemId, count in pairs(cost) do
  		cost[itemId] = count * needCount
  	end
  	if not role:checkItemEnough(cost) then return end
  
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
512
513
  	role:costItems(cost)
  
7898054a   zhouhaihai   新随机订单
514
515
516
  
  	for idx, order in ipairs(orders) do
  		if (order.lock == 0 and order.status == 0) then
550ba7e7   zhouhaihai   订单
517
518
519
520
521
522
523
  			if needCount > 0 then
  				local index = math.randWeight(pool, "chance")
  				local data = pool[index]
  				orders[idx] = {lv = taskLevel, id = data.id, n = 0, lock = 0, status = 0}
  				needCount = needCount - 1
  				table.remove(pool, index)
  			end
ca232abd   gaofengduan   fix diner task re...
524
525
  		end
  	end
550ba7e7   zhouhaihai   订单
526
  
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
527
  	role.dinerData:updateProperty({field = "order", value = json.encode(orders)})
289a4927   gaofengduan   fix diner talent
528
529
  
  	SendPacket(actionCodes.Diner_refreshTaskRpc, '')
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
530
531
532
  	return true
  end
  
6d272f65   zhouhaihai   餐厅 食材
533
  function _M.addWantFoodRpc(agent , data)
4288160b   gaofengduan   add Diner_getGree...
534
535
536
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
6d272f65   zhouhaihai   餐厅 食材
537
538
  	local ids = msg.ids -- list
  
4288160b   gaofengduan   add Diner_getGree...
539
540
541
  	local buildType = 6
  	local level = role.dinerData:getProperty("buildL"):getv(buildType, 1)
  	local buildingData = csvdb["diner_buildingCsv"][buildType][level]
6d272f65   zhouhaihai   餐厅 食材
542
  
4288160b   gaofengduan   add Diner_getGree...
543
544
545
  	if not buildingData then
  		return 1
  	end
6d272f65   zhouhaihai   餐厅 食材
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
  
  	if #ids > buildingData.business then return 2 end
  
  	local had = {}
  	for _, itemId in ipairs(ids) do
  		if had[itemId] then return end
  		had[itemId] = 1
  		local foodData = csvdb["diner_materialCsv"][itemId]
  		if not foodData then return 3 end
  		if foodData.unlock ~= 0 then
  			local hangPass = role:getProperty("hangPass")
  			if not hangPass[foodData.unlock] then
  				return 4
  			end
  		end
  	end
  	local gfood = {}
  	for slot, itemId in ipairs(ids) do
  		gfood[slot] = {id = itemId, st = skynet.timex()}
4288160b   gaofengduan   add Diner_getGree...
565
566
  	end
  
6d272f65   zhouhaihai   餐厅 食材
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
  	role.dinerData:updateProperty({field = "gfood", value = gfood})
  
  	SendPacket(actionCodes.Diner_addWantFoodRpc, '')
  	return true
  end
  
  function _M.getGreenhouseRpc( agent, data )
  	local role = agent.role
  	-- local msg = MsgPack.unpack(data)
  
  	local buildType = 6
  	local level = role.dinerData:getProperty("buildL"):getv(buildType, 1)
  	local buildingData = csvdb["diner_buildingCsv"][buildType][level]
  	if not buildingData then
  		return 1
4288160b   gaofengduan   add Diner_getGree...
582
  	end
6d272f65   zhouhaihai   餐厅 食材
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
  
  	local reward = {}
  	local now = skynet.timex()
  	local gfood = role.dinerData:getProperty("gfood")
  	if not next(gfood) then return end
  	for k , v in pairs(gfood) do
  		local itemId = v.id
  		local st = v.st
  		local speed = globalCsv.diner_get_food_speed[csvdb["itemCsv"][itemId].quality] * buildingData.speed / 100
  		local endTime = st + globalCsv.diner_get_food_time_max
  		local endTime2 = math.min(now, endTime)
  		reward[itemId] = math.floor((endTime2 - st) / speed)
  		if endTime2 == endTime then
  			gfood[k].st = now
  		else
  			gfood[k].st = st + speed * reward[itemId]
  		end
4288160b   gaofengduan   add Diner_getGree...
600
  	end
6d272f65   zhouhaihai   餐厅 食材
601
602
  	role.dinerData:updateProperty({field = "gfood", value = gfood})
  	local reward = role:award(reward)
53e8037e   zhouhaihai   任务
603
  	role:checkTaskEnter("FoodMGet")
4288160b   gaofengduan   add Diner_getGree...
604
605
606
  	SendPacket(actionCodes.Diner_getGreenhouseRpc, MsgPack.pack({reward = reward}))
  	return true
  end
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
607
  
03a6166a   zhouhaihai   餐厅优化
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
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
  local function refreshTaskRpc(role, task)
  	local hadType = {}
  	if task.id and csvdb["task_specialCsv"][task.id] then
  		hadType[csvdb["task_specialCsv"][task.id].type] = 1
  	end
  	local spTask = role:getProperty("spTask")
  	local taskCount = 0
  	for id ,_ in pairs(spTask) do
  		hadType[csvdb["task_specialCsv"][id].type] = 1
  		taskCount = taskCount + 1
  	end
  	local pool = {}
  	if taskCount < globalCsv.diner_get_task_count_max then
  		local curLevel = role:getProperty("level")
  		for id, data in pairs(csvdb["task_specialCsv"]) do
  			if not hadType[data.type] then
  				local level = data.level:toArray(true, "=")
  				if curLevel >= level[1] and curLevel <= level[2] then
  					table.insert(pool, id)
  				end
  			end
  		end
  	end
  	if not next(pool) then --每次进都看看有没有任务可以领
  		task.id = nil
  		task.et = 0
  	else
  		local id = pool[math.randomInt(1, #pool)]
  		task.id = id
  		task.et = skynet.timex() + globalCsv.diner_get_task_time_max
  	end
  	return task
  end
  
  -- 进入餐厅界面调用
  function _M.initTaskRpc(agent, data)
  	local role = agent.role
  
  	local task = role.dinerData:getProperty("task")
  
  	local now = skynet.timex()
  
  	if not task.et or task.et <= now then --刷新了
  		task = refreshTaskRpc(role, task)
  		role.dinerData:updateProperty({field = "task", value = task})
  	end
  
  	SendPacket(actionCodes.Diner_initTaskRpc, '')
  	return true
  end
  
  -- 对任务进行处理调用
  function _M.handleTaskRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local cmd = msg.cmd  -- 1 领取任务  2 拒绝任务
  	
  	local task = role.dinerData:getProperty("task")
  	local now = skynet.timex()
  	if cmd == 1 then
  		if not task.id then return end
  		if task.et > now then
  			--领取任务
  			task.id = nil
  			task.et = now + globalCsv.diner_get_task_time_max
  			task.refuse = nil
  		else
  			return
  		end
  	elseif cmd == 2 then -- 拒绝任务(重新领取)
  		if not task.id then return end
  		if (task.refuse or 0) >= globalCsv.diner_get_task_refuse_max then
  			-- 等待时间
  			task.refuse = nil
  			task.id = nil
  			task.et = now + globalCsv.diner_get_task_time_max
  		else
  			task.refuse = (task.refuse or 0) + 1
  			--刷新任务
  			task = refreshTaskRpc(role, task)
  		end 
  	else
  		return
  	end
  	role.dinerData:updateProperty({field = "task", value = task})
  
  	SendPacket(actionCodes.Diner_handleTaskRpc, '')
  	return true
  end
  
59835765   zhouhaihai   排行榜
698
699
700
701
702
703
704
705
706
  function _M.rankRpc(agent , data)
  	local role = agent.role
  
  	local rankInfo = role.dinerData:getPopularRank()
  	SendPacket(actionCodes.Diner_rankRpc, MsgPack.pack(rankInfo))
  	return true
  end
  
  
87cc3a35   zhengshouren   餐厅建筑升级逻辑
707
  return _M