76 lines
2.9 KiB
C#
76 lines
2.9 KiB
C#
using RobotAndDonkey.Game.Cards;
|
|
using RobotAndDonkey.Game.Execution.Results;
|
|
using RobotAndDonkey.Game.GameState;
|
|
using RobotAndDonkey.Game.Intents;
|
|
|
|
namespace RobotAndDonkey.Game.Modifiers;
|
|
|
|
public record GlobalImmunityModifier(EModifierDuration Duration) : Modifier(EModifierKind.Card, EModifierId.GlobalImmunity, Duration)
|
|
{
|
|
public override void Before(Guid requestId, ReadOnlySpan<Intent> intents, CoreLoop coreLoop, Entity owner, List<Intent> newIntents, List<Result> results)
|
|
{
|
|
foreach (var (entity, location) in RunProgram.CollectEntities(coreLoop))
|
|
{
|
|
foreach (var existingModifier in entity.Modifiers)
|
|
{
|
|
if (existingModifier == this)
|
|
continue;
|
|
|
|
foreach (var (source, immuneModifier) in Modifiers)
|
|
{
|
|
if (immuneModifier == EModifierId.GlobalImmunity)
|
|
continue;
|
|
|
|
if (immuneModifier == EModifierId._Invalid || immuneModifier == existingModifier.Id)
|
|
{
|
|
if (existingModifier.DebuffSources.Add(source))
|
|
{
|
|
if (entity is Card card)
|
|
results.Add(new ModifyCardResult(requestId, card.DeepClone(), immuneModifier, location));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void After(Guid requestId, ReadOnlySpan<Intent> intents, CoreLoop coreLoop, Entity owner, List<Intent> newIntents, List<Result> results)
|
|
{
|
|
foreach (var (entity, location) in RunProgram.CollectEntities(coreLoop))
|
|
{
|
|
foreach (var existingModifier in entity.Modifiers)
|
|
{
|
|
if (existingModifier == this)
|
|
continue;
|
|
|
|
foreach (var (source, immuneModifier) in Modifiers)
|
|
{
|
|
if (immuneModifier == EModifierId.GlobalImmunity)
|
|
continue;
|
|
|
|
if (immuneModifier == EModifierId._Invalid || immuneModifier == existingModifier.Id)
|
|
{
|
|
if (existingModifier.DebuffSources.Remove(source))
|
|
{
|
|
if (entity is Card card)
|
|
results.Add(new ModifyCardResult(requestId, card.DeepClone(), immuneModifier, location));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override GlobalImmunityModifier CreateInstance()
|
|
{
|
|
var clone = new GlobalImmunityModifier(Duration);
|
|
foreach (var tuple in Modifiers)
|
|
clone.Modifiers.Add(tuple);
|
|
return clone;
|
|
}
|
|
|
|
public readonly List<(Entity Source, EModifierId Modifier)> Modifiers = [];
|
|
|
|
public override string ToolTip => $"Immune against {string.Join(", ", Modifiers.Select(m => m.Modifier))}, {Duration}";
|
|
}
|