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() 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 LogGreen("id:"..id.." IsExist:"..tostring(this.skinDatas[id])) end function this.IsExist(id) LogGreen("id:"..id.." IsExist:"..tostring(this.skinDatas[id])) if this.skinDatas[id] then return true else return false end end 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 function this.CaculateSkinProVal(_heroId) local heroSkinSingleProVal = {} local heroSkinAllHeroProVal = {} local heroData = HeroManager.GetSingleHeroData(_heroId) 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 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 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