Blame view

src/actions/DinerAction.lua 23.1 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
  	local calSell = role.dinerData:updateSell(slot, true) or {
  		deltaCount = 0,
  		deltaTime = 0,
  		lastCount = 0,
  	}
d8ba6e11   zhouhaihai   保护
43
  	local count = sellData.count or 0
03a6166a   zhouhaihai   餐厅优化
44
45
46
47
  	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
  
3133cb76   zhouhaihai   日志
57
  	role:costItems(cost, {log = {desc = "addSell"}})
03a6166a   zhouhaihai   餐厅优化
58
  	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
  	sells[slot].dish = dish
  	sells[slot].level = dishLevel
  	sells[slot].count = count
  	sells[slot].time = skynet.timex() - calSell.deltaTime
ed322ed2   zhouhaihai   餐厅 顾客 系统
77
78
79
80
81
82
83
84
85
  
  	-- 检查解锁的顾客
  	local had = {}
  	for _, sell in pairs(sells) do
  		if sell.dish then
  			had[sell.dish] = sell.level
  		end
  	end
  
ae820b73   zhouhaihai   bug
86
  	local customer = role.dinerData:getProperty("customer")
ed322ed2   zhouhaihai   餐厅 顾客 系统
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
  	local change = false
  	for cId, cData in pairs(csvdb["diner_customerCsv"]) do
  		if not customer[cId] then
  			local unlock = true
  			for needId, lv in pairs(cData.unlock:toNumMap()) do
  				if not had[needId] or had[needId] < lv then
  					unlock = false
  					break
  				end
  			end
  			if unlock then
  				change = true
  				customer[cId] = 0
  			end
  		end
  	end
  
  	if change then 
  		role.dinerData:updateProperty({field = "customer", value = customer})
  	end
  
3133cb76   zhouhaihai   日志
108
109
  	role:log("diner_action", {desc = "addSell", int1 = dish, int2 = count})
  
03a6166a   zhouhaihai   餐厅优化
110
  	role.dinerData:updateProperty({field = "sells", value = json.encode(sells)})
36204e3c   zhengshouren   贩卖逻辑
111
  	SendPacket(actionCodes.Diner_addSellRpc, "")
36204e3c   zhengshouren   贩卖逻辑
112
  	return true
87cc3a35   zhengshouren   餐厅建筑升级逻辑
113
114
  end
  
1ab9458f   gaofengduan   add 下菜操作
115
116
117
118
119
120
121
122
123
124
125
126
127
128
  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 下菜操作
129
130
131
132
133
134
135
136
137
138
139
140
141
142
  	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
143
  	role.dinerData:updateSell(slot)
1ab9458f   gaofengduan   add 下菜操作
144
145
146
147
  	local reward = {}
  	local cost = dishData.material:toNumMap()
  	for k, n in pairs(cost) do
  		local sum = n*sell.count
1ab9458f   gaofengduan   add 下菜操作
148
149
  		reward[k] = sum
  	end
3133cb76   zhouhaihai   日志
150
  	reward = role:award(reward, {log = {desc = "removeSell"}})
5a307eb6   gaofengduan   fix diner
151
  	sells[slot].count = 0
3133cb76   zhouhaihai   日志
152
153
154
  
  	role:log("diner_action", {desc = "removeSell", int1 = dish})
  
1ab9458f   gaofengduan   add 下菜操作
155
156
157
158
159
  	role.dinerData:updateProperty({field = "sells", value = json.encode(sells)})
  	SendPacket(actionCodes.Diner_removeSellRpc, MsgPack.pack({reward = reward}))
  	return true
  end
  
87cc3a35   zhengshouren   餐厅建筑升级逻辑
160
  function _M.getSellRewardRpc( agent, data )
5d57bd79   gaofengduan   add 餐车 getSellRew...
161
  	local role = agent.role
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
162
  	local dirty = false
59835765   zhouhaihai   排行榜
163
  	local reward, popular = "", 0
5d57bd79   gaofengduan   add 餐车 getSellRew...
164
  	local sells = json.decode(role.dinerData:getProperty("sells"))
32161569   gaofengduan   fix diner
165
  	for slot, _ in pairs(sells) do
0c0b161d   gaofengduan   fix getSellRewardRpc
166
  		role.dinerData:updateSell(slot)
32161569   gaofengduan   fix diner
167
168
169
  	end
  	sells = json.decode(role.dinerData:getProperty("sells"))
  	for slot, sell in pairs(sells) do
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
170
171
  		local rewards = sell.reward:toNumMap()
  		for k,v in pairs(rewards) do
f5c07b1b   gaofengduan   fix diner
172
  			reward = reward:incrv(k, v)
5d57bd79   gaofengduan   add 餐车 getSellRew...
173
  		end
59835765   zhouhaihai   排行榜
174
  		popular = popular + (sell.popular or 0)
77302523   zhouhaihai   任务
175
  		
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
176
  		if rewards[ItemId.Gold] and rewards[ItemId.Gold] > 0 then
da6362db   gaofengduan   fix dinerData
177
  			if role.dinerData:checkDinerTask(DinerTask.DishWithGold, rewards[ItemId.Gold], sell.dish, nil, true) then
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
178
179
  				dirty = true
  			end
77302523   zhouhaihai   任务
180
181
182
183
184
185
186
  			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   增加餐厅任务计数逻辑
187
  		end
32161569   gaofengduan   fix diner
188
  		sells[slot].reward = ""
59835765   zhouhaihai   排行榜
189
  		sells[slot].popular = 0
5d57bd79   gaofengduan   add 餐车 getSellRew...
190
  	end
f5c07b1b   gaofengduan   fix diner
191
  	role.dinerData:updateProperty({field = "sells", value = json.encode(sells)})
3133cb76   zhouhaihai   日志
192
193
  	local gift = reward:toNumMap()
  	for k, v in pairs(gift) do
53e8037e   zhouhaihai   任务
194
195
196
  		if k == ItemId.Gold then
  			role:checkTaskEnter("FoodSellGold", {count = v})
  		end
5d57bd79   gaofengduan   add 餐车 getSellRew...
197
  	end
3133cb76   zhouhaihai   日志
198
199
  	role:award(gift, {log = {desc = "dinerSell"}})
  
32161569   gaofengduan   fix diner
200
  
59835765   zhouhaihai   排行榜
201
202
  	role.dinerData:popularAdd(popular)
  
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
203
  	if dirty then
da6362db   gaofengduan   fix dinerData
204
  		role.dinerData:notifyUpdateProperty("order", role.dinerData:getProperty("order"))
cc796aaf   zhengshouren   增加餐厅任务计数逻辑
205
  	end
3133cb76   zhouhaihai   日志
206
207
208
  
  	role:log("diner_action", {desc = "sell"})
  
0c0b161d   gaofengduan   fix getSellRewardRpc
209
  	SendPacket(actionCodes.Diner_getSellRewardRpc, MsgPack.pack({reward = reward}))
5d57bd79   gaofengduan   add 餐车 getSellRew...
210
  	return true
87cc3a35   zhengshouren   餐厅建筑升级逻辑
211
212
  end
  
2050d40d   gaofengduan   add diner expedit...
213
214
  function _M.expediteSellRpc( agent, data )
  	local role = agent.role
020fc7ed   gaofengduan   fix diner expedit...
215
216
  	local count = role.dinerData:getProperty("expedite")
  	local max = #globalCsv.diner_sell_quick_cost
2c63e6a0   gaofengduan   fix dienr
217
  	if count > max then
020fc7ed   gaofengduan   fix diner expedit...
218
219
  		return 1
  	end
10974097   gaofengduan   fix diner
220
221
222
223
224
225
  	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
3133cb76   zhouhaihai   日志
226
  		role:costItems(cost, {log = {desc = "dinerSellQ"}})
020fc7ed   gaofengduan   fix diner expedit...
227
  	end
020fc7ed   gaofengduan   fix diner expedit...
228
  
2050d40d   gaofengduan   add diner expedit...
229
  	local dirty = false
59835765   zhouhaihai   排行榜
230
  	local reward,popular = "", 0
2050d40d   gaofengduan   add diner expedit...
231
232
233
234
235
236
  	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...
237
  		local result = role.dinerData:expediteSell(slot)
6991df1b   gaofengduan   fix bug
238
239
240
241
242
243
  		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...
244
  
6991df1b   gaofengduan   fix bug
245
246
247
248
  			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   任务
249
250
251
252
253
254
255
  				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...
256
257
258
259
  			end
  		end
  	end
  
020fc7ed   gaofengduan   fix diner expedit...
260
261
262
  	role.dinerData:notifyUpdateProperty("sells", role.dinerData:getProperty("sells"))
  	role.dinerData:setProperty("expedite",count+1)
  	role.dinerData:notifyUpdateProperty("expedite", count+1)
3133cb76   zhouhaihai   日志
263
264
  	local gift = reward:toNumMap()
  	for k, v in pairs(gift) do
f60b89b1   zhouhaihai   奖励副本
265
266
267
  		if k == ItemId.Gold then
  			role:checkTaskEnter("FoodSellGold", {count = v})
  		end
2050d40d   gaofengduan   add diner expedit...
268
  	end
3133cb76   zhouhaihai   日志
269
270
  	role:award(gift, {log = {desc = "dinerSell"}})
  
2050d40d   gaofengduan   add diner expedit...
271
  
59835765   zhouhaihai   排行榜
272
273
  	role.dinerData:popularAdd(popular)
  
2050d40d   gaofengduan   add diner expedit...
274
275
276
  	if dirty then
  		role.dinerData:notifyUpdateProperty("order", role.dinerData:getProperty("order"))
  	end
53e8037e   zhouhaihai   任务
277
  	role:checkTaskEnter("FoodSellQuick")
3133cb76   zhouhaihai   日志
278
279
280
  
  	role:log("diner_action", {desc = "sellQ"})
  
020fc7ed   gaofengduan   fix diner expedit...
281
  	SendPacket(actionCodes.Diner_expediteSellRpc, MsgPack.pack({reward = reward,popular = popular}))
2050d40d   gaofengduan   add diner expedit...
282
283
284
  	return true
  end
  
87cc3a35   zhengshouren   餐厅建筑升级逻辑
285
286
287
288
289
  function _M.levelUpRpc( agent, data )
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
  	local index = msg.index
f9c6cac9   zhengshouren   建筑升级增加 其他建筑物等级限制
290
291
  	local buildingSet = csvdb["diner_buildingCsv"][index]
  	if not buildingSet then
87cc3a35   zhengshouren   餐厅建筑升级逻辑
292
293
294
295
296
  		return
  	end
  
  	local buildL = role.dinerData:getProperty("buildL")
  	local curLevel = buildL:getv(index, 1)
f9c6cac9   zhengshouren   建筑升级增加 其他建筑物等级限制
297
  	if curLevel >= #buildingSet then
87cc3a35   zhengshouren   餐厅建筑升级逻辑
298
299
  		return
  	end
f9c6cac9   zhengshouren   建筑升级增加 其他建筑物等级限制
300
301
302
303
304
  	local buildingData = buildingSet[curLevel]
  	if not buildingData then
  		return
  	end
  	if buildingData.upLimit ~= "" then
4a969fc5   gaofengduan   fix diner levelUpRpc
305
  		local id, level = buildingData.upLimit:match("(%d+)=(%d+)")
f9c6cac9   zhengshouren   建筑升级增加 其他建筑物等级限制
306
307
308
309
  		if buildL:getv(tonumber(id), 1) < tonumber(level) then
  			return
  		end
  	end
87cc3a35   zhengshouren   餐厅建筑升级逻辑
310
  
f9c6cac9   zhengshouren   建筑升级增加 其他建筑物等级限制
311
  	local cost = buildingData.starCost:toNumMap()
87cc3a35   zhengshouren   餐厅建筑升级逻辑
312
  	if not role:checkItemEnough(cost) then
289a4927   gaofengduan   fix diner talent
313
  		return
87cc3a35   zhengshouren   餐厅建筑升级逻辑
314
315
  	end
  
3133cb76   zhouhaihai   日志
316
  	role:costItems(cost, {log = {desc = "dinerBuildUp", int1 = index}})
d96fae59   gaofengduan   fix diner levelUpRpc
317
  	role.dinerData:updateProperty({field = "buildL", value = buildL:setv(index, curLevel + 1)})
53e8037e   zhouhaihai   任务
318
  	role:checkTaskEnter("DinerLevelUp", {type = index, level = curLevel + 1})
3133cb76   zhouhaihai   日志
319
320
321
  
  	role:log("diner_action", {desc = "buildUp", int1 = index, int2 = curLevel + 1})
  
87cc3a35   zhengshouren   餐厅建筑升级逻辑
322
323
324
325
  	SendPacket(actionCodes.Diner_levelUpRpc, '')
  	return true
  end
  
b67180e8   zhengshouren   餐厅天赋升级
326
327
328
  function _M.talentUpRpc( agent, data )
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
b67180e8   zhengshouren   餐厅天赋升级
329
  	local dish = msg.dish
b67180e8   zhengshouren   餐厅天赋升级
330
331
  	local dishTree = role.dinerData:getProperty("dishTree")
  	local dishLevel = dishTree:getv(dish, 0)
289a4927   gaofengduan   fix diner talent
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
  
  	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 前置调整
358
  	local limit = talentData.pointFront:toNumMap()
289a4927   gaofengduan   fix diner talent
359
360
361
362
  	for k,v in pairs(limit) do
  		local lv = dishTree:getv(k, 0)
  		if lv < v then
  			return 5
b67180e8   zhengshouren   餐厅天赋升级
363
  		end
b67180e8   zhengshouren   餐厅天赋升级
364
  	end
289a4927   gaofengduan   fix diner talent
365
  
f02087ed   chenyueqi   调理室解锁技能点增加前置关卡条件判定
366
367
368
369
370
371
372
  	if talentData.levelFront ~= "" then
  		local hangPass = role:getProperty("hangPass")
  		if not hangPass[tonumber(talentData.levelFront)] then
  			return 9
  		end
  	end
  
289a4927   gaofengduan   fix diner talent
373
  	local cost = talentData.cost:toNumMap()
b67180e8   zhengshouren   餐厅天赋升级
374
  	if not role:checkItemEnough(cost) then
289a4927   gaofengduan   fix diner talent
375
376
377
  		return 6
  	end
  
dbd0ca58   gaofengduan   car  营养剂制作
378
  	-- 正在贩卖不能升级料理天赋
289a4927   gaofengduan   fix diner talent
379
380
381
382
383
384
  	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
385
  		if sell.dish == msg.dish and sell.count > 0 then
289a4927   gaofengduan   fix diner talent
386
387
  			return 7
  		end
b67180e8   zhengshouren   餐厅天赋升级
388
389
  	end
  
dbd0ca58   gaofengduan   car  营养剂制作
390
  	-- 正在冒险不能升级营养剂天赋
69d686f8   gaofengduan   暂时取消营养剂天赋升级限制
391
392
393
  	-- if talentData.effect:toArray(true,"=")[1] == 2 then
  	-- 	if next(role:getProperty("advTeam")) then return 8 end
  	-- end
dbd0ca58   gaofengduan   car  营养剂制作
394
  
3133cb76   zhouhaihai   日志
395
  	role:costItems(cost, {log = {desc = "talentUp", int1 = dish, int2 = dishLevel + 1}})
b67180e8   zhengshouren   餐厅天赋升级
396
  	role.dinerData:updateProperty({field = "dishTree", value = dishTree:setv(dish, dishLevel + 1)})
08bfcb88   zhouhaihai   策划要求删掉
397
398
399
400
  	-- local treePoint = talentData.tree_point:toNumMap()
  	-- if next(treePoint) then
  	-- 	role:award(treePoint)
  	-- end
b67180e8   zhengshouren   餐厅天赋升级
401
  
53e8037e   zhouhaihai   任务
402
403
  	role:checkTaskEnter("DinerTalentUp", {type = talentData.effect:toArray(true,"=")[1]})
  
3133cb76   zhouhaihai   日志
404
405
  	role:log("diner_action", {desc = "talentUp", int1 = dish, int2 = dishLevel + 1})
  
b67180e8   zhengshouren   餐厅天赋升级
406
407
408
409
  	SendPacket(actionCodes.Diner_talentUpRpc, '')
  	return true
  end
  
7d44dca2   zhengshouren   支援技能升级逻辑
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
  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
  
3133cb76   zhouhaihai   日志
437
  	role:costItems(cost, {log = {desc = "dinerSkillUp", int1 = skill, int2 = skillLevel + 1}})
7d44dca2   zhengshouren   支援技能升级逻辑
438
  	role.dinerData:updateProperty({field = "skillTree", value = skillTree:setv(skill, skillLevel + 1)})
3133cb76   zhouhaihai   日志
439
  	role:log("diner_action", {desc = "skillUp", int1 = skill, int2 = skillLevel + 1})
7d44dca2   zhengshouren   支援技能升级逻辑
440
441
442
443
444
  
  	SendPacket(actionCodes.Diner_skillUpRpc, '')
  	return true
  end
  
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
445
446
447
448
449
  function _M.lockTaskRpc( agent, data )
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local index = msg.index
  
550ba7e7   zhouhaihai   订单
450
451
452
  	local orders = json.decode(role.dinerData:getProperty("order"))
  
  	if math.illegalNum(index, 1, #orders) then
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
453
454
  		return 1
  	end
550ba7e7   zhouhaihai   订单
455
  	
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
456
457
458
459
  	local order = orders[index]
  	if not order then
  		return 2
  	end
fdb86cad   gaofengduan   fix diner task
460
461
462
463
  	if order.lock == 0 then
  		order.lock = 1
  	else
  		order.lock = 0
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
464
  	end
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
465
  	role.dinerData:updateProperty({field = "order", value = json.encode(orders)})
3133cb76   zhouhaihai   日志
466
467
468
  
  	role:log("diner_action", {desc = "lockTask", int1 = order.id})
  
fdb86cad   gaofengduan   fix diner task
469
  	SendPacket(actionCodes.Diner_lockTaskRpc, MsgPack.pack({lock = order.lock}))
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
470
471
472
  	return true
  end
  
fdb86cad   gaofengduan   fix diner task
473
  function _M.updateTaskRpc( agent, data )
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
474
475
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
476
  	local index = msg.index
550ba7e7   zhouhaihai   订单
477
  	-- 0 接受任务,1 放弃已接受任务,2 完成已接受任务
fdb86cad   gaofengduan   fix diner task
478
  	local cmd = msg.cmd
550ba7e7   zhouhaihai   订单
479
480
  	local orders = json.decode(role.dinerData:getProperty("order"))
  	if math.illegalNum(index, 1, #orders) then
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
481
482
  		return 1
  	end
550ba7e7   zhouhaihai   订单
483
  	
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
484
485
486
487
  	local order = orders[index]
  	if not order then
  		return 2
  	end
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
488
489
490
491
492
493
494
495
  	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
496
  
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
497
  
fdb86cad   gaofengduan   fix diner task
498
499
500
501
502
503
  	if cmd == 0 then
  		if order.status ~= 0 then
  			return 30
  		end
  		orders[index].status = 1
  		orders[index].lock = 1
3133cb76   zhouhaihai   日志
504
505
506
  
  		role:log("diner_action", {desc = "getTask", int1 = order.id})
  
53e8037e   zhouhaihai   任务
507
  		role:checkTaskEnter("GetOderTask", {rarity = taskSet.rarity})
fdb86cad   gaofengduan   fix diner task
508
509
510
511
512
513
  	elseif cmd == 1 then
  		if order.status ~= 1 then
  			return 31
  		end
  		orders[index].status = 0
  		orders[index].lock = 0
3133cb76   zhouhaihai   日志
514
515
516
  
  		role:log("diner_action", {desc = "deleteTask", int1 = order.id})
  
fdb86cad   gaofengduan   fix diner task
517
  	elseif cmd == 2 then
452d6146   gaofengduan   fix diner task
518
  		if order.status ~= 1 then
fdb86cad   gaofengduan   fix diner task
519
520
  			return 32
  		end
452d6146   gaofengduan   fix diner task
521
  		if order.n < taskData.value then
fdb86cad   gaofengduan   fix diner task
522
523
  			return 6
  		end
3133cb76   zhouhaihai   日志
524
525
526
  		role:log("diner_action", {desc = "finishTask", int1 = order.id})
  
  		role:award(taskData.reward, {log = {desc = "dinerFinishTask", int1 = order.id}})
452d6146   gaofengduan   fix diner task
527
  		table.remove(orders,index)
53e8037e   zhouhaihai   任务
528
  		role:checkTaskEnter("OverOderTask", {rarity = taskSet.rarity})
fdb86cad   gaofengduan   fix diner task
529
530
  	else
  		return 33
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
531
532
  	end
  
fdb86cad   gaofengduan   fix diner task
533
534
  	role.dinerData:updateProperty({field = "order", value = json.encode(orders)})
  	SendPacket(actionCodes.Diner_updateTaskRpc, '')
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
535
536
537
  	return true
  end
  
fdb86cad   gaofengduan   fix diner task
538
  function _M.refreshTaskRpc( agent, data )
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
539
540
541
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
fdb86cad   gaofengduan   fix diner task
542
  	local cost = {[ItemId.Diamond] = 40}
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
543
544
545
546
547
  	if not role:checkItemEnough(cost) then
  		return 1
  	end
  
  	local orders = json.decode(role.dinerData:getProperty("order"))
550ba7e7   zhouhaihai   订单
548
549
  
  	local hadTask = {}
7898054a   zhouhaihai   新随机订单
550
  	local needCount = 0
550ba7e7   zhouhaihai   订单
551
  	for idx, temp in pairs(orders) do
7898054a   zhouhaihai   新随机订单
552
  		if temp.lock ~= 0 or temp.status ~= 0 then
550ba7e7   zhouhaihai   订单
553
  			hadTask[temp.id] = 1
7898054a   zhouhaihai   新随机订单
554
555
  		else
  			needCount = needCount + 1
550ba7e7   zhouhaihai   订单
556
  		end
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
557
558
  	end
  
550ba7e7   zhouhaihai   订单
559
560
  	if needCount <= 0 then return 2 end
  
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
561
562
563
564
565
  	local taskLevel = role.dinerData:getProperty("buildL"):getv(5, 1)
  	local taskData = csvdb["diner_questCsv"][taskLevel]
  	if not taskData then
  		return 3
  	end
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
566
  
550ba7e7   zhouhaihai   订单
567
  	local pool = {}
f4bbb208   zhouhaihai   餐厅任务解锁
568
569
  
  	local dishTree = role.dinerData:getProperty("dishTree")
550ba7e7   zhouhaihai   订单
570
  	for id, temp in pairs(taskData) do
f4bbb208   zhouhaihai   餐厅任务解锁
571
572
573
574
575
576
577
578
  		local unlock = true
  		for _, front in ipairs(temp.front:toArray(true, "=")) do
  			if dishTree:getv(front, 0) == 0 then
  				unlock = false
  				break
  			end
  		end
  		if not hadTask[id] and unlock then
550ba7e7   zhouhaihai   订单
579
580
581
582
583
584
585
586
587
588
589
590
591
  			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
  
3133cb76   zhouhaihai   日志
592
  	role:costItems(cost, {log = {desc = "dinerReTask"}})
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
593
  
7898054a   zhouhaihai   新随机订单
594
595
596
  
  	for idx, order in ipairs(orders) do
  		if (order.lock == 0 and order.status == 0) then
550ba7e7   zhouhaihai   订单
597
598
599
600
601
602
603
  			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...
604
605
  		end
  	end
550ba7e7   zhouhaihai   订单
606
  
3133cb76   zhouhaihai   日志
607
608
  	role:log("diner_action", {desc = "reTask"})
  
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
609
  	role.dinerData:updateProperty({field = "order", value = json.encode(orders)})
289a4927   gaofengduan   fix diner talent
610
611
  
  	SendPacket(actionCodes.Diner_refreshTaskRpc, '')
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
612
613
614
  	return true
  end
  
6d272f65   zhouhaihai   餐厅 食材
615
  function _M.addWantFoodRpc(agent , data)
4288160b   gaofengduan   add Diner_getGree...
616
617
618
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
6d272f65   zhouhaihai   餐厅 食材
619
620
  	local ids = msg.ids -- list
  
4288160b   gaofengduan   add Diner_getGree...
621
622
623
  	local buildType = 6
  	local level = role.dinerData:getProperty("buildL"):getv(buildType, 1)
  	local buildingData = csvdb["diner_buildingCsv"][buildType][level]
6d272f65   zhouhaihai   餐厅 食材
624
  
4288160b   gaofengduan   add Diner_getGree...
625
626
627
  	if not buildingData then
  		return 1
  	end
6d272f65   zhouhaihai   餐厅 食材
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
  
  	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...
647
648
  	end
  
3133cb76   zhouhaihai   日志
649
650
  	role:log("diner_action", {desc = "wantFood"})
  
6d272f65   zhouhaihai   餐厅 食材
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
  	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...
666
  	end
6d272f65   zhouhaihai   餐厅 食材
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
  
  	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...
684
  	end
6d272f65   zhouhaihai   餐厅 食材
685
  	role.dinerData:updateProperty({field = "gfood", value = gfood})
3133cb76   zhouhaihai   日志
686
  	local reward = role:award(reward, {log = {desc = "greenHourse"}})
53e8037e   zhouhaihai   任务
687
  	role:checkTaskEnter("FoodMGet")
3133cb76   zhouhaihai   日志
688
689
690
  
  	role:log("diner_action", {desc = "greenHourse"})
  
4288160b   gaofengduan   add Diner_getGree...
691
692
693
  	SendPacket(actionCodes.Diner_getGreenhouseRpc, MsgPack.pack({reward = reward}))
  	return true
  end
4864d579   zhengshouren   领取任务,锁定任务,获得特殊任务
694
  
03a6166a   zhouhaihai   餐厅优化
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
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
777
778
779
780
781
782
783
784
  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   排行榜
785
786
787
788
789
790
791
792
  function _M.rankRpc(agent , data)
  	local role = agent.role
  
  	local rankInfo = role.dinerData:getPopularRank()
  	SendPacket(actionCodes.Diner_rankRpc, MsgPack.pack(rankInfo))
  	return true
  end
  
ed322ed2   zhouhaihai   餐厅 顾客 系统
793
794
795
796
797
798
799
  function _M.entrustRpc(agent , data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
  	local ctype = msg.ctype
  
  	local entrust = role.dinerData:getProperty("entrust")
3133cb76   zhouhaihai   日志
800
801
  	local entrustId = entrust[1]
  	if not entrustId then return end
ed322ed2   zhouhaihai   餐厅 顾客 系统
802
803
804
  
  	local reward
  	if ctype == 1 then -- 完成
3133cb76   zhouhaihai   日志
805
  		local curData = csvdb["diner_missionCsv"][entrustId]
ed322ed2   zhouhaihai   餐厅 顾客 系统
806
807
808
809
810
  		if not curData then return end
  
  		if curData.type == 1 then
  			local cost = curData.condition:toNumMap()
  			if not role:checkItemEnough(cost) then return end
3133cb76   zhouhaihai   日志
811
  			role:costItems(cost, {log = {desc = "dinerEntrus", int1 = entrustId}})
ed322ed2   zhouhaihai   餐厅 顾客 系统
812
813
814
815
816
817
  		elseif curData.type == 2 then
  			-- todo 数据校验
  		else
  			return
  		end
  
3133cb76   zhouhaihai   日志
818
  		reward = role:award(curData.reward, {log = {desc = "dinerEntrus", int1 = entrustId}})
4c5d72ab   zhouhaihai   高级pvp
819
  		table.remove(entrust, 1)
ed322ed2   zhouhaihai   餐厅 顾客 系统
820
821
822
823
824
825
826
  	elseif ctype == 2 then		-- 放弃
  		table.remove(entrust, 1)
  	else
  		return 
  	end
  	role.dinerData:updateProperty({field = "entrust", value = entrust})
  
3133cb76   zhouhaihai   日志
827
828
  	role:log("diner_action", {desc = "entrus", short1 = ctype, int1 = entrustId})
  
ed322ed2   zhouhaihai   餐厅 顾客 系统
829
830
831
832
833
834
835
836
837
  	SendPacket(actionCodes.Diner_entrustRpc, MsgPack.pack({reward = reward}))
  	return true
  end
  
  function _M.collectRpc(agent , data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
  	local id = msg.id
a4e66eda   zhouhaihai   餐厅协议
838
839
  	local customerData = csvdb["diner_customerCsv"][id]
  	if not id or not customerData then return end
ed322ed2   zhouhaihai   餐厅 顾客 系统
840
841
842
843
844
845
846
847
848
849
  	local customer = role.dinerData:getProperty("customer")
  	if customer[id] ~= 0 then
  		return
  	end
  
  	-- 完成前更新一波 后面 加成可能不一样
  	local sells = json.decode(role.dinerData:getProperty("sells"))
  	for slot, _ in pairs(sells) do
  		role.dinerData:updateSell(slot)
  	end
3133cb76   zhouhaihai   日志
850
  	local reward = role:award(customerData.reward, {log = {desc = "dinerCollect", int1 = id}})
ed322ed2   zhouhaihai   餐厅 顾客 系统
851
852
  	customer[id] = 1
  	role.dinerData:updateProperty({field = "customer", value = customer}) -- 解锁了
3133cb76   zhouhaihai   日志
853
  	role:log("diner_action", {desc = "collect", int1 = id})
ed322ed2   zhouhaihai   餐厅 顾客 系统
854
  
a4e66eda   zhouhaihai   餐厅协议
855
  	SendPacket(actionCodes.Diner_collectRpc, MsgPack.pack({reward = reward}))
ed322ed2   zhouhaihai   餐厅 顾客 系统
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
  	return true
  end
  
  function _M.comboRewardRpc(agent , data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
  	local id = msg.id
  
  	local comboData = csvdb["diner_customer_comboCsv"][id]
  	if not id or not comboData then return end
  	local comboStatus = role.dinerData:getProperty("comboStatus")
  	if comboStatus[id] == -1 then return end
  
  	local customer = role.dinerData:getProperty("customer")
  
  	for _, nId in ipairs(comboData.customer:toArray(true, "=")) do
  		if customer[nId] ~= 1 then
  			return 
  		end
  	end
  
  	comboStatus[id] = 1
3133cb76   zhouhaihai   日志
879
  	local reward = role:award(comboData.reward, {log = {desc = "dinerCombo", int1 = id}})
ed322ed2   zhouhaihai   餐厅 顾客 系统
880
881
882
  
  	role.dinerData:updateProperty({field = "comboStatus", value = comboStatus}) -- 解锁了
  
3133cb76   zhouhaihai   日志
883
884
  	role:log("diner_action", {desc = "combo", int1 = id})
  
a4e66eda   zhouhaihai   餐厅协议
885
  	SendPacket(actionCodes.Diner_comboRewardRpc, MsgPack.pack({reward = reward}))
ed322ed2   zhouhaihai   餐厅 顾客 系统
886
887
888
889
  	return true
  end
  
  
59835765   zhouhaihai   排行榜
890
  
87cc3a35   zhengshouren   餐厅建筑升级逻辑
891
  return _M