using System.Collections.Generic; using System.Linq; namespace ET.Server { [FriendOf(typeof(HeroComponent))] [FriendOf(typeof(Hero))] public static class HeroComponentSystem { public static Hero AddHero(this HeroComponent self, int configId) { Hero hero = self.AddChild(configId); self.HeroMap[hero.Id] = hero; return hero; } public static bool RemoveHero(this HeroComponent self, long heroId) { if (!self.HeroMap.TryGetValue(heroId, out EntityRef heroRef)) { return false; } Hero hero = heroRef; self.HeroMap.Remove(heroId); hero.Dispose(); return true; } public static Hero GetHero(this HeroComponent self, long heroId) { self.HeroMap.TryGetValue(heroId, out EntityRef heroRef); return heroRef; } public static List GetAllHeroes(this HeroComponent self) { return self.HeroMap.Values.Select(x => (Hero)x).ToList(); } } }