HeroAction.lua 1.51 KB
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