42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
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<Hero, int>(configId);
|
|
self.HeroMap[hero.Id] = hero;
|
|
return hero;
|
|
}
|
|
|
|
public static bool RemoveHero(this HeroComponent self, long heroId)
|
|
{
|
|
if (!self.HeroMap.TryGetValue(heroId, out EntityRef<Hero> 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<Hero> heroRef);
|
|
return heroRef;
|
|
}
|
|
|
|
public static List<Hero> GetAllHeroes(this HeroComponent self)
|
|
{
|
|
return self.HeroMap.Values.Select(x => (Hero)x).ToList();
|
|
}
|
|
}
|
|
}
|