public void AddArchetype(Archetype archetype) { if (!Archetypes.Contains(archetype)) { throw new Exception($"{archetype} was not found as an archetype for {Name}"); // This should never happen.. } if (AppliedArchetypes.Contains(archetype)) { throw new Exception($"{archetype.Name} is already applied to {Name}"); // <-- } if (archetype.ArchetypeAbilities.SelectMany(a => a.ReplacedAbilities).Any(ca => !ClassAbilities.Contains(ca))) { throw new Exception($"{archetype.Name} could not be added, because one or more replaced abilities were already replaced."); // Can apply archetype.. } foreach (var ability in archetype.ArchetypeAbilities) { foreach (var replacedAbility in ability.ReplacedAbilities) { ClassAbilities.Remove(replacedAbility); } ClassAbilities.Add(ability); ability.Add?.Invoke(); } AppliedArchetypes.Add(archetype); }
public void RemoveArchetype(Archetype archetype) { if (!AppliedArchetypes.Contains(archetype)) { throw new Exception($"{archetype} was not found among the applied archetypes"); } foreach (var ability in archetype.ArchetypeAbilities) { ClassAbilities.Remove(ability); ability.Remove?.Invoke(); foreach (var replacedAbility in ability.ReplacedAbilities) { ClassAbilities.Add(replacedAbility); } } AppliedArchetypes.Remove(archetype); }