Blame view

src/actions/DinerAction.lua 3.46 KB
87cc3a35   zhengshouren   餐厅建筑升级逻辑
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  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
  		return
  	end
36204e3c   zhengshouren   贩卖逻辑
17
18
  	slot = tostring(slot)
  
87cc3a35   zhengshouren   餐厅建筑升级逻辑
19
20
21
22
23
  	local dish = msg.dish
  	local dishSet = csvdb["diner_dishCsv"][dish]
  	if not dishSet then
  		return
  	end
36204e3c   zhengshouren   贩卖逻辑
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  	local dishLevel = role.dinerData:getProperty("dishTree"):getv(dish, 0)
  	if dishLevel == 0 then
  		return
  	end
  	local dishData = dishSet[dishLevel]
  	if not dishData then
  		return
  	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
87cc3a35   zhengshouren   餐厅建筑升级逻辑
41
42
43
  		return
  	end
  
36204e3c   zhengshouren   贩卖逻辑
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
  	local cost = dishData.material:toNumMap()
  	for _, n in pairs(cost) do
  		n = n * count
  	end
  	if not role:checkItemEnough(cost) then
  		return 
  	end
  
  	role:costItems(cost)
  	role.dinerData:updateSell(slot)
  
  	local sells = json.decode(role.dinerData:getProperty("sells"))
  	if not sells[slot] then
  		sells[slot] = {
  			dish = dish,
  			level = dishLevel,
  			reward = "",
  			count = 0,
  		}
  	end
  	local sell = sells[slot]
  	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   餐厅建筑升级逻辑
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
  end
  
  function _M.getSellRewardRpc( agent, data )
  	
  end
  
  function _M.levelUpRpc( agent, data )
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
  	local index = msg.index
  	local buildingData = csvdb["diner_buildingCsv"][index]
  	if not buildingData then
  		return
  	end
  
  	local buildL = role.dinerData:getProperty("buildL")
  	local curLevel = buildL:getv(index, 1)
  	if curLevel >= #buildingData then
  		return
  	end
  
  	local cost = buildingData[curLevel].starCost:toNumMap()
  	if not role:checkItemEnough(cost) then
  		return 
  	end
  
36204e3c   zhengshouren   贩卖逻辑
100
  	role:costItems(cost)
87cc3a35   zhengshouren   餐厅建筑升级逻辑
101
102
103
104
105
106
  	role.dinerData:updateProperty({field = "level", value = buildL:setv(index, curLevel + 1)})
  
  	SendPacket(actionCodes.Diner_levelUpRpc, '')
  	return true
  end
  
b67180e8   zhengshouren   餐厅天赋升级
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
  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
  
87cc3a35   zhengshouren   餐厅建筑升级逻辑
157
  return _M