-
Notifications
You must be signed in to change notification settings - Fork 1
/
AbilityManager.cs
35 lines (26 loc) · 994 Bytes
/
AbilityManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System.Reflection;
using SuperheroPlugin.Abilities;
namespace SuperheroPlugin;
public class AbilityManager
{
public List<SuperheroAbility> Abilities = new List<SuperheroAbility>();
public AbilityManager()
{
LoadAbilities();
}
private void LoadAbilities()
{
// Get the assembly where the abilities are defined
Assembly assembly = Assembly.GetExecutingAssembly();
// Get all types in the assembly that are assignable to SuperheroAbility
IEnumerable<Type> abilityTypes = assembly.GetTypes()
.Where(type => type.IsClass && !type.IsAbstract && type.IsSubclassOf(typeof(SuperheroAbility)));
foreach (Type type in abilityTypes)
{
// Create an instance of the ability and add it to the list
SuperheroAbility? ability = (SuperheroAbility?)Activator.CreateInstance(type);
if (ability == null) { continue; }
Abilities.Add(ability);
}
}
}