48 lines
1.0 KiB
Lua
48 lines
1.0 KiB
Lua
local ServerHeroData = class("ServerHeroData", ServerBaseData)
|
|
|
|
function ServerHeroData:init(data)
|
|
self.data.heroes = data and data.heroes or {}
|
|
self.data.unlockHeroes = data and data.unlockHeroes or {}
|
|
end
|
|
|
|
function ServerHeroData:getHeroByCfgId(id)
|
|
local idStr = tostring(id)
|
|
return self.data.heroes[idStr]
|
|
end
|
|
|
|
function ServerHeroData:getIsUnlockHero(id)
|
|
local idStr = tostring(id)
|
|
if self.data.heroes[idStr] then
|
|
return true
|
|
end
|
|
return self.data.unlockHeroes[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:unlockHero(id)
|
|
local idStr = tostring(id)
|
|
if self.data.unlockHeroes[idStr] then
|
|
return
|
|
end
|
|
self.data.unlockHeroes[idStr] = true
|
|
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 |