107 lines
3.9 KiB
Lua
107 lines
3.9 KiB
Lua
HeroSkinManager = {}
|
|
local this = HeroSkinManager
|
|
local skinConfig = ConfigManager.GetConfig(ConfigName.HeroSkin)
|
|
this.skinDatas = {}
|
|
function this.Initialize()
|
|
this.skinDatas = {}
|
|
end
|
|
function this.InitialSkin(msg,index)
|
|
if not index or index == 0 then
|
|
this.skinDatas = {}
|
|
for i = 1, #msg.skinInfo do
|
|
this.skinDatas[msg.skinInfo[i].skinId] = {}
|
|
this.skinDatas[msg.skinInfo[i].skinId].id = msg.skinInfo[i].skinId
|
|
local config = ConfigManager.GetConfigDataByKey(ConfigName.HeroSkin,"Type",msg.skinInfo[i].skinId)
|
|
this.skinDatas[msg.skinInfo[i].skinId].heroId = config.HeroId
|
|
this.skinDatas[msg.skinInfo[i].skinId].UnlockProperty = config.UnlockProperty
|
|
this.skinDatas[msg.skinInfo[i].skinId].MonomerProperty = config.MonomerProperty
|
|
this.skinDatas[msg.skinInfo[i].skinId].overTime = msg.skinInfo[i].overTime - PlayerManager.serverTime
|
|
end
|
|
else
|
|
this.skinDatas[msg.skinInfo.skinId] = {}
|
|
this.skinDatas[msg.skinInfo.skinId].id = msg.skinInfo.skinId
|
|
local config = ConfigManager.GetConfigDataByKey(ConfigName.HeroSkin,"Type",msg.skinInfo.skinId)
|
|
this.skinDatas[msg.skinInfo.skinId].heroId = config.HeroId
|
|
this.skinDatas[msg.skinInfo.skinId].UnlockProperty = config.UnlockProperty
|
|
this.skinDatas[msg.skinInfo.skinId].MonomerProperty = config.MonomerProperty
|
|
this.skinDatas[msg.skinInfo.skinId].overTime = msg.skinInfo.overTime - PlayerManager.serverTime
|
|
end
|
|
this.UpdateSkinDatasOverTime()
|
|
HeroManager.SetHerosSkinWarPowerState()
|
|
end
|
|
|
|
function this.UpdateSkinDatasOverTime()
|
|
if this.timer then
|
|
this.timer:Stop()
|
|
this.timer = nil
|
|
end
|
|
this.timer = Timer.New(function()
|
|
if LengthOfTable(this.skinDatas) < 1 then
|
|
if this.timer then
|
|
this.timer:Stop()
|
|
this.timer = nil
|
|
end
|
|
return
|
|
end
|
|
for k,v in pairs(this.skinDatas) do
|
|
if v and v.overTime > 0 then
|
|
v.overTime = v.overTime - 1
|
|
if v.overTime <= 0 then
|
|
this.RemoveSkin(v.id)
|
|
HeroManager.ChangeDownSkinId(v.heroId,v.id)
|
|
end
|
|
end
|
|
end
|
|
end, 1, -1, true)
|
|
this.timer:Start()
|
|
end
|
|
|
|
function this.RemoveSkin(id)
|
|
this.skinDatas[id] = nil
|
|
end
|
|
|
|
function this.IsExist(id)
|
|
if this.skinDatas[id] then
|
|
return true,this.skinDatas[id].overTime
|
|
else
|
|
return false
|
|
end
|
|
end
|
|
|
|
function this.GetSkins(id)
|
|
if this.skinDatas[id] then
|
|
return this.skinDatas[id]
|
|
else
|
|
return nil
|
|
end
|
|
end
|
|
|
|
function this.CaculateSkinProVal(heroData)
|
|
local heroSkinSingleProVal = {}
|
|
local heroSkinAllHeroProVal = {}
|
|
local heroData = heroData
|
|
if heroData.skinId ~= 0 then
|
|
if this.skinDatas[heroData.skinId] and this.skinDatas[heroData.skinId].MonomerProperty and #this.skinDatas[heroData.skinId].MonomerProperty > 0 then
|
|
for _,v in ipairs(this.skinDatas[heroData.skinId].MonomerProperty) do
|
|
if not heroSkinSingleProVal[v[1]] then
|
|
heroSkinSingleProVal[v[1]] = 0
|
|
end
|
|
heroSkinSingleProVal[v[1]] = heroSkinSingleProVal[v[1]] + v[2]
|
|
end
|
|
end
|
|
end
|
|
for _,v in pairs(this.skinDatas) do
|
|
if heroData.skinId ~= v.id then
|
|
if this.skinDatas[v.id] and this.skinDatas[v.id].UnlockProperty and #this.skinDatas[v.id].UnlockProperty > 0 then
|
|
for _,n in ipairs(this.skinDatas[v.id].UnlockProperty) do
|
|
if not heroSkinAllHeroProVal[n[1]] then
|
|
heroSkinAllHeroProVal[n[1]] = 0
|
|
end
|
|
heroSkinAllHeroProVal[n[1]] = heroSkinAllHeroProVal[n[1]] + n[2]
|
|
end
|
|
end
|
|
end
|
|
end
|
|
return heroSkinSingleProVal, heroSkinAllHeroProVal
|
|
end
|
|
return this |