ported from perforce
This commit is contained in:
47
RobotAndDonkey.Game/Cards/Patches/Repeat.cs
Normal file
47
RobotAndDonkey.Game/Cards/Patches/Repeat.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RobotAndDonkey.Game.Board;
|
||||
using RobotAndDonkey.Game.Data;
|
||||
using RobotAndDonkey.Game.Execution.Results;
|
||||
using RobotAndDonkey.Game.GameState;
|
||||
using RobotAndDonkey.Game.Intents;
|
||||
using RobotAndDonkey.Game.Modifiers;
|
||||
using RobotAndDonkey.Game.Pois;
|
||||
using RobotAndDonkey.Game.Utils;
|
||||
|
||||
namespace RobotAndDonkey.Game.Cards.Patches;
|
||||
|
||||
public record Repeat() : PatchCard(ECard.Repeat, Balancing.Instance.RepeatCost, 0, ERarity.Legendary)
|
||||
{
|
||||
protected override void CreateIntents(Cell avatarCell, Avatar avatar, CoreLoop coreLoop, Guid requestId, List<Intent> intents, List<Result> results)
|
||||
{
|
||||
var tape = coreLoop.GetTapeCards();
|
||||
var index = tape.IndexOf(this);
|
||||
if (index < 0)
|
||||
{
|
||||
results.Add(new InvalidInstructionResult(requestId, EInvalidReason.NotFound, this, avatarCell));
|
||||
return;
|
||||
}
|
||||
|
||||
var targetIndex = CardExtensions.NextIndexConsideringCorruption(index, coreLoop);
|
||||
if (targetIndex < 0 || targetIndex >= tape.Count)
|
||||
{
|
||||
results.Add(new InvalidInstructionResult(requestId, EInvalidReason.OutOfBounds, this, avatarCell));
|
||||
return;
|
||||
}
|
||||
|
||||
var targetCard = tape[targetIndex];
|
||||
if (!m_RepeatedCards.Add(targetCard))
|
||||
{
|
||||
results.Add(new InvalidInstructionResult(requestId, EInvalidReason.AlreadyExecuted, this, avatarCell));
|
||||
return;
|
||||
}
|
||||
|
||||
targetCard.CreateIntents(avatarCell, coreLoop, requestId, intents, results);
|
||||
m_RepeatedCards.Remove(targetCard);
|
||||
}
|
||||
|
||||
public override string ToolTip => "Behaves exactly like the next instruction.";
|
||||
|
||||
private readonly HashSet<Card> m_RepeatedCards = [];
|
||||
}
|
||||
Reference in New Issue
Block a user