Blame view

src/actions/CarAction.lua 2.15 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
  	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
  	if count < 1 then return 0 end
  	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
  	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
  
  	local own = role:getItemCount(id)
  	if own < count then
  		return 3
  	end
  
  	local cost = equipData.cost:toNumMap()
e668f4d0   gaofengduan   fix cost
73
74
  	for k, n in pairs(cost) do
  		cost[k] = n * count
9c525cf9   gaofengduan   add car smithy
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
  	end
  	if not role:checkItemEnough(cost) then
  		return 4
  	end
  
  	local merge = {[id]=equipData.merge*count}
  	if not role:checkItemEnough(merge) then
  		return 5
  	end
  
  	role:costItems(cost)
  	role:costItems(merge)
  	role:addItem({itemId = nextEquip.id,count = count})
  	SendPacket(actionCodes.Car_equipUpRpc, '')
  	return true
  end
  
  return _M