Blame view

src/actions/CarAction.lua 4.6 KB
9c525cf9   gaofengduan   add car smithy
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
  local ipairs = ipairs
  local table = table
  local math = math
  local redisproxy = redisproxy
  local MsgPack = MsgPack
  
  local _M = {}
  
  function _M.makePotionRpc( agent, data )
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local potionId = msg.id
  	local count = msg.count
  	if count < 1 then return 0 end
  	local potionBag = role:getProperty("potionBag")
  	local potionLv = role.dinerData:getProperty("dishTree"):getv(potionId, 0)
  	if potionLv < 1 then return 1 end
  
  	local potionSet = csvdb["adv_potionCsv"][potionId]
  	if not potionSet then return 2 end
  
  	local potionData = potionSet[potionLv]
  	if not potionData then return 3 end
  
  	local own = potionBag[potionId] or 0
  	if own+count > potionData.limit then
  		return 4
  	end
  
  	local cost = potionData.material:toNumMap()
e668f4d0   gaofengduan   fix cost
31
32
  	for k, n in pairs(cost) do
  		cost[k] = n * count
9c525cf9   gaofengduan   add car smithy
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  	end
  	if not role:checkItemEnough(cost) then
  		return 5
  	end
  
  	role:costItems(cost)
  	potionBag[potionId] = own + count
  	role:updateProperty({field = "potionBag", value = potionBag})
  	SendPacket(actionCodes.Car_makePotionRpc, MsgPack.pack({potionBag = potionBag}))
  	return true
  end
  
  function _M.equipUpRpc( agent, data )
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local id = msg.id
  	local count = msg.count
056c01a0   zhouhaihai   简化装备
50
  
9c525cf9   gaofengduan   add car smithy
51
52
53
54
55
56
57
58
  	local typ = math.floor((id-7000)/100)
  	local lv = (id-7000)%100
  
  	local dataSet = csvdb["equipCsv"][typ]
  	if not dataSet then return 1 end
  	local equipData = dataSet[lv]
  	if not equipData then return 21 end
  	if equipData.merge < 1 then return 22 end
056c01a0   zhouhaihai   简化装备
59
  
9c525cf9   gaofengduan   add car smithy
60
61
62
63
64
65
66
67
  	local maxLv = 3
  	local nextLv = lv+1
  	if nextLv%10 > maxLv then
  		nextLv = nextLv+10-maxLv
  	end
  	local nextEquip = dataSet[nextLv]
  	if not nextEquip then return 23 end
  
912f7d2c   zhouhaihai   bug
68
  	local limit = csvdb["itemCsv"][nextEquip.id].limit ~= 0 and csvdb["itemCsv"][nextEquip.id].limit or math.huge
056c01a0   zhouhaihai   简化装备
69
70
  
  	if math.illegalNum(count, 1, limit)  then return 0 end
43cc5f51   gaofengduan   调整 equip 数据结构
71
72
  
  	local own = role:getEquipCount(typ,lv)
056c01a0   zhouhaihai   简化装备
73
  	local costCount = equipData.merge * count
43cc5f51   gaofengduan   调整 equip 数据结构
74
  	if own < costCount then
9c525cf9   gaofengduan   add car smithy
75
76
77
78
  		return 3
  	end
  
  	local cost = equipData.cost:toNumMap()
e668f4d0   gaofengduan   fix cost
79
80
  	for k, n in pairs(cost) do
  		cost[k] = n * count
9c525cf9   gaofengduan   add car smithy
81
82
83
84
85
  	end
  	if not role:checkItemEnough(cost) then
  		return 4
  	end
  
9c525cf9   gaofengduan   add car smithy
86
  	role:costItems(cost)
056c01a0   zhouhaihai   简化装备
87
88
89
  	role:addEquip(typ, lv, -costCount)
  	role:addEquip(typ, nextLv ,count)
  
9c525cf9   gaofengduan   add car smithy
90
91
92
93
  	SendPacket(actionCodes.Car_equipUpRpc, '')
  	return true
  end
  
fb321075   gaofengduan   add rune up
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
  function _M.runeUpRpc( agent, data )
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local uid = msg.uid
  	local ownRune = role.runeBag[uid]
  	if not ownRune then return 1 end
  	if ownRune:getProperty("refer") ~= 0 then return 2 end
  
  	local typ = ownRune:getProperty("type")
  	local id = ownRune:getProperty("id")
  	local level = ownRune:getProperty("level")
  
  	local runeSet = csvdb["runeCsv"][typ]
  	if not runeSet then return 4 end
  	local runeData = runeSet[id]
  	if not runeData then return 5 end
  
04c7448f   gaofengduan   fix rune up
111
112
113
  	local maxLv = table.nums(csvdb["rune_buildCsv"])-1
  	if level > maxLv then return 6 end
  	local lvData = csvdb["rune_buildCsv"][level]
fb321075   gaofengduan   add rune up
114
115
116
117
118
119
120
121
122
123
124
  	local cost = lvData.cost:toNumMap()
  	if not role:checkItemEnough(cost) then
  		return 7
  	end
  
  	role:costItems(cost)
  	ownRune:updateProperty({field = "level",value = level+1})
  	SendPacket(actionCodes.Car_runeUpRpc, '')
  	return true
  end
  
912f7d2c   zhouhaihai   bug
125
  function _M.saleEquipRpc(agent, data )
056c01a0   zhouhaihai   简化装备
126
127
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
9dd0add2   zhouhaihai   批量分解装备
128
129
130
  	local backs = msg.backs
  	if not backs then return end
  	for id, count in pairs(backs) do
2445248d   zhouhaihai   去掉热门料理
131
  		if not csvdb["itemCsv"][id] then return end
9dd0add2   zhouhaihai   批量分解装备
132
133
134
135
136
137
138
  		local typ = math.floor((id-7000)/100)
  		local lv = (id-7000)%100
  		local own = role:getEquipCount(typ,lv)
  		if math.illegalNum(count, 1, own)  then return end
  	end
  	local reward = {}
  	for id, count in pairs(backs) do
2445248d   zhouhaihai   去掉热门料理
139
  		local itemData = csvdb["itemCsv"][id]
9dd0add2   zhouhaihai   批量分解装备
140
141
142
143
144
145
146
147
  		local typ = math.floor((id-7000)/100)
  		local lv = (id-7000)%100
  		role:addEquip(typ, lv, -count) -- 删掉装备
  		-- 发奖励
  		local one = itemData.sell_effect:toNumMap()
  		for k ,v in pairs(one) do
  			reward[k] = (reward[k] or 0) + v * count 
  		end
056c01a0   zhouhaihai   简化装备
148
  	end
9dd0add2   zhouhaihai   批量分解装备
149
  	reward = role:award(reward)
056c01a0   zhouhaihai   简化装备
150
151
152
153
  	SendPacket(actionCodes.Car_saleEquipRpc, MsgPack.pack({reward = reward}))
  	return true
  end
  
497f9a67   zhouhaihai   卖零件
154
155
156
157
158
159
160
  function _M.saleRuneRpc(agent, data )
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  	local backs = msg.backs
  	if not backs then return end
  
  	local reward = {}
2445248d   zhouhaihai   去掉热门料理
161
  	for _, uid in pairs(backs) do
497f9a67   zhouhaihai   卖零件
162
163
164
  		local rune = role.runeBag[uid]
  		if not rune then return end
  		if rune:getProperty("refer") ~= 0 then return end
2445248d   zhouhaihai   去掉热门料理
165
  		local itemData = csvdb["itemCsv"][rune:getProperty("id")]
497f9a67   zhouhaihai   卖零件
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
  		if not itemData then return end
  		local one = itemData.sell_effect:toNumMap()
  		for k ,v in pairs(one) do
  			reward[k] = (reward[k] or 0) + v
  		end
  	end
  
  	role:delRunes(backs)
  
  	reward = role:award(reward)
  
  	SendPacket(actionCodes.Car_saleRuneRpc, MsgPack.pack({reward = reward}))
  	return true
  end
  
9c525cf9   gaofengduan   add car smithy
181
  return _M