using RobotAndDonkey.Game.Intents; namespace RobotAndDonkey.Game.Modifiers; public record Entity() { protected Entity(Entity clone) { m_Modifiers = []; foreach (var modifier in clone.Modifiers) AddModifier(modifier.DeepClone(), []); } public void InsertModifier(Modifier modifier, List newIntents) { if (m_Modifiers.Any(m => m.Id == modifier.Id)) throw new InvalidOperationException(); m_Modifiers.Insert(0, modifier); modifier.OnAdded(this, newIntents); } public void AddModifier(Modifier modifier, List newIntents) { if (m_Modifiers.Any(m => m.Id == modifier.Id)) throw new InvalidOperationException(); m_Modifiers.Add(modifier); modifier.OnAdded(this, newIntents); } public void RemoveModifier(Modifier modifier, List newIntents) { if (!m_Modifiers.Remove(modifier)) throw new InvalidOperationException(); modifier.OnRemoved(this, newIntents); } public override string ToString() { return "[" + string.Join(", ", m_Modifiers) + "]"; } public IReadOnlyList Modifiers => m_Modifiers; private readonly List m_Modifiers = []; }