32 lines
669 B
Lua
32 lines
669 B
Lua
local ServerHeroData = class("ServerHeroData", ServerBaseData)
|
|
|
|
function ServerHeroData:init(data)
|
|
self.data.heroes = data and data.heroes or {}
|
|
end
|
|
|
|
function ServerHeroData:getHeroByCfgId(id)
|
|
local idStr = tostring(id)
|
|
return self.data.heroes[idStr]
|
|
end
|
|
|
|
function ServerHeroData:addHero(id, lv)
|
|
local idStr = tostring(id)
|
|
if self.data.heroes[idStr] then
|
|
return
|
|
end
|
|
|
|
self.data.heroes[idStr] = {
|
|
cfg_id = id,
|
|
lv = lv,
|
|
}
|
|
end
|
|
|
|
function ServerHeroData:upgradeHero(heroId)
|
|
local idStr = tostring(heroId)
|
|
if not self.data.heroes[idStr] then
|
|
self:addHero(heroId, 0)
|
|
end
|
|
self.data.heroes[idStr].lv = self.data.heroes[idStr].lv + 1
|
|
end
|
|
|
|
return ServerHeroData |