HeroAction.lua
1.51 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
local ipairs = ipairs
local table = table
local math = math
local next = next
local string = string
local redisproxy = redisproxy
local MsgPack = MsgPack
local getRandomName = getRandomName
local mcast_util = mcast_util
local string_format = string.format
local tonumber = tonumber
local require = require
local table_insert = table.insert
local tconcat = table.concat
local _M = {}
function _M.levelUpRpc( agent, data )
local role = agent.role
local msg = MsgPack.unpack(data)
local hero = role.heros[msg.id]
if not hero then return end
if hero:getProperty("level") >= hero:getMaxLevel() then return end
local curData = csvdb["unit_expCsv"][hero:getProperty("level")]
local cost = {[2] = curData.exp, [1] = curData.gold}
if not role:checkItemEnough(cost) then return end
role:costItems(cost, {})
hero:updateProperty({field = "level", delta = 1})
SendPacket(actionCodes.Hero_levelUpRpc, '')
return true
end
function _M.breakRpc( agent, data )
local role = agent.role
local msg = MsgPack.unpack(data)
local hero = role.heros[msg.id]
if not hero then return end
if hero:getProperty("level") < hero:getMaxLevel() then return end
if hero:getProperty("breakL") >= #csvdb["unit_breakCsv"] then return end
local curData = csvdb["unit_breakCsv"][hero:getProperty("breakL")]
local cost = {[3] = curData.cost, [1] = curData.gold}
if not role:checkItemEnough(cost) then return end
role:costItems(cost, {})
hero:updateProperty({field = "breakL", delta = 1})
SendPacket(actionCodes.Hero_breakRpc, '')
return true
end
return _M