ported from perforce
This commit is contained in:
78
RobotAndDonkey.Game/Intents/ImmunizeCard.cs
Normal file
78
RobotAndDonkey.Game/Intents/ImmunizeCard.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using RobotAndDonkey.Game.Cards;
|
||||
using RobotAndDonkey.Game.Execution.Results;
|
||||
using RobotAndDonkey.Game.GameState;
|
||||
using RobotAndDonkey.Game.Modifiers;
|
||||
|
||||
namespace RobotAndDonkey.Game.Intents;
|
||||
|
||||
public class ImmunizeCard(Card source, Card target, EModifierId modifierId, EModifierDuration duration, bool canCorrupt = true) : CardIntent(target)
|
||||
{
|
||||
public override void Run(Guid requestId, CoreLoop coreLoop, List<Intent> newIntents, List<Result> results)
|
||||
{
|
||||
if (DebuffState)
|
||||
{
|
||||
if (Card.Modifiers.OfType<GlobalImmunityModifier>().FirstOrDefault() is {} existingImmunity)
|
||||
{
|
||||
if (!existingImmunity.Modifiers.Any(m => m.Modifier == ModifierId && m.Source == source))
|
||||
existingImmunity.Modifiers.Add((source, ModifierId));
|
||||
}
|
||||
else
|
||||
{
|
||||
var newImmunity = new GlobalImmunityModifier(Duration);
|
||||
newImmunity.Modifiers.Add((source, ModifierId));
|
||||
Card.InsertModifier(newImmunity, newIntents);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var modifier in Card.Modifiers.ToArray())
|
||||
{
|
||||
if (modifier is GlobalImmunityModifier giModifier)
|
||||
{
|
||||
for (var i = giModifier.Modifiers.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var immunity = giModifier.Modifiers[i];
|
||||
if (immunity.Modifier == ModifierId)
|
||||
{
|
||||
giModifier.Modifiers.RemoveAt(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (giModifier.Modifiers.Count == 0)
|
||||
Card.RemoveModifier(modifier, newIntents);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
results.Add(new ModifyCardResult(requestId, Card.DeepClone(), EModifierId.GlobalImmunity, ECardLocation.Tape));
|
||||
base.Run(requestId, coreLoop, newIntents, results);
|
||||
}
|
||||
|
||||
public override bool IsValid(CoreLoop coreLoop)
|
||||
{
|
||||
return base.IsValid(coreLoop) &&
|
||||
ModifierId is
|
||||
EModifierId.Corrupt or
|
||||
EModifierId.Unreliable or
|
||||
EModifierId.RaceCondition or
|
||||
EModifierId.Throttled or
|
||||
EModifierId.Effective or
|
||||
EModifierId.Optimized or
|
||||
EModifierId.Efficient or
|
||||
EModifierId.Persistent or
|
||||
EModifierId._Invalid;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Immunize {Card.Name} from {source.Name} against {ModifierId}, {Duration}, DebuffState={DebuffState}, CanCorrupt={CanCorrupt}, " + base.ToString();
|
||||
}
|
||||
|
||||
public EModifierId ModifierId { get; set; } = modifierId;
|
||||
|
||||
public bool DebuffState { get; set; } = true;
|
||||
|
||||
public bool CanCorrupt { get; set; } = canCorrupt;
|
||||
|
||||
public EModifierDuration Duration { get; set; } = duration;
|
||||
}
|
||||
Reference in New Issue
Block a user