miduo_client/Assets/ManagedResources/~Lua/Modules/Hero/HeroSkinManager.lua

112 lines
4.2 KiB
Lua
Raw Normal View History

2020-11-03 15:17:48 +08:00
HeroSkinManager = {}
local this = HeroSkinManager
2020-11-03 19:37:05 +08:00
local skinConfig = ConfigManager.GetConfig(ConfigName.HeroSkin)
2020-11-03 15:17:48 +08:00
this.skinDatas = {}
function this.Initialize()
2020-11-03 19:37:05 +08:00
this.skinDatas = {}
2020-11-03 15:17:48 +08:00
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
2020-11-04 18:29:49 +08:00
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
2020-11-03 19:37:05 +08:00
this.skinDatas[msg.skinInfo[i].skinId].overTime = msg.skinInfo[i].overTime - PlayerManager.serverTime
2020-11-03 15:17:48 +08:00
end
else
this.skinDatas[msg.skinInfo.skinId] = {}
this.skinDatas[msg.skinInfo.skinId].id = msg.skinInfo.skinId
2020-11-04 18:29:49 +08:00
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
2020-11-03 19:37:05 +08:00
this.skinDatas[msg.skinInfo.skinId].overTime = msg.skinInfo.overTime - PlayerManager.serverTime
2020-11-03 15:17:48 +08:00
end
this.UpdateSkinDatasOverTime()
end
function this.UpdateSkinDatasOverTime()
if this.timer then
this.timer:Stop()
this.timer = nil
end
this.timer = Timer.New(function()
2020-11-04 18:29:49 +08:00
if LengthOfTable(this.skinDatas) < 1 then
if this.timer then
this.timer:Stop()
this.timer = nil
end
return
end
2020-11-03 15:17:48 +08:00
for k,v in pairs(this.skinDatas) do
if v and v.overTime > 0 then
v.overTime = v.overTime - 1
2020-11-04 18:29:49 +08:00
if v.overTime <= 0 then
2020-11-03 15:17:48 +08:00
this.RemoveSkin(v.id)
2020-11-04 18:29:49 +08:00
HeroManager.ChangeDownSkinId(v.heroId,v.id)
2020-11-03 15:17:48 +08:00
end
end
end
end, 1, -1, true)
this.timer:Start()
end
function this.RemoveSkin(id)
this.skinDatas[id] = nil
2020-11-04 18:29:49 +08:00
LogGreen("id:"..id.." IsExist:"..tostring(this.skinDatas[id]))
2020-11-03 15:17:48 +08:00
end
function this.IsExist(id)
2020-11-03 19:37:05 +08:00
LogGreen("id:"..id.." IsExist:"..tostring(this.skinDatas[id]))
2020-11-03 15:17:48 +08:00
if this.skinDatas[id] then
return true
else
return false
end
end
2020-11-03 19:37:05 +08:00
2020-11-05 18:26:38 +08:00
function this.GetSkins(id)
LogGreen("id:"..id.." IsExist:"..tostring(this.skinDatas[id]))
if this.skinDatas[id] then
return this.skinDatas[id]
else
return nil
end
end
2020-11-03 19:37:05 +08:00
function this.CaculateSkinProVal(_heroId)
local heroSkinSingleProVal = {}
local heroSkinAllHeroProVal = {}
local heroData = HeroManager.GetSingleHeroData(_heroId)
2020-11-04 18:29:49 +08:00
if heroData.skinId ~= 0 then
2020-11-05 14:18:32 +08:00
if this.skinDatas[heroData.skinId] and this.skinDatas[heroData.skinId].MonomerProperty and #this.skinDatas[heroData.skinId].MonomerProperty > 0 then
2020-11-04 18:29:49 +08:00
for _,v in ipairs(this.skinDatas[heroData.skinId].MonomerProperty) do
2020-11-03 19:37:05 +08:00
if not heroSkinSingleProVal[v[1]] then
heroSkinSingleProVal[v[1]] = 0
end
if not heroSkinAllHeroProVal[v[1]] then
heroSkinAllHeroProVal[v[1]] = 0
end
heroSkinAllHeroProVal[v[1]] = heroSkinAllHeroProVal[v[1]] + v[2]
end
end
end
for _,v in pairs(this.skinDatas) do
if heroData.skinId ~= v.id then
2020-11-05 14:18:32 +08:00
if this.skinDatas[v.id] and this.skinDatas[v.id].UnlockProperty and #this.skinDatas[v.id].UnlockProperty > 0 then
2020-11-04 18:29:49 +08:00
for _,n in ipairs(this.skinDatas[v.id].UnlockProperty) do
2020-11-03 19:37:05 +08:00
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
2020-11-03 15:17:48 +08:00
return this