48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
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<Intent> 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<Intent> 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<Intent> newIntents)
|
|
{
|
|
if (!m_Modifiers.Remove(modifier))
|
|
throw new InvalidOperationException();
|
|
|
|
modifier.OnRemoved(this, newIntents);
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return "[" + string.Join(", ", m_Modifiers) + "]";
|
|
}
|
|
|
|
public IReadOnlyList<Modifier> Modifiers => m_Modifiers;
|
|
|
|
private readonly List<Modifier> m_Modifiers = [];
|
|
} |