using System; using System.Collections.Generic; using RobotAndDonkey.Game.Board; using RobotAndDonkey.Game.Cards; using RobotAndDonkey.Game.Data; using RobotAndDonkey.Game.Execution.Results; using RobotAndDonkey.Game.GameState; using RobotAndDonkey.Game.Pois; namespace RobotAndDonkey.Game.Intents; public class Move(Cell cell, Card card, EDirection direction, bool ignoreBlocking, int amount) : Intent { public override void Run(Guid requestId, CoreLoop coreLoop, List newIntents, List results) { if (cell.Type == ECellType.Mud) { newIntents.Add(new ModifyCurrency(new(-Balancing.Instance.MudMoveEnergyCost, 0, 0, 0, 0, 0))); } var neighbour = cell.Hex; for (int i = 0; i < Amount; ++i) neighbour = neighbour.GetNeighbour(Direction); var neighbourIndex = coreLoop.Board.FindCellIndex(neighbour); if (neighbourIndex < 0) { results.Add(new InvalidInstructionResult(requestId, EInvalidReason.OutOfBounds, card, cell)); } else { var neighbourCell = coreLoop.Board.Cells[neighbourIndex]; if (!ignoreBlocking && (neighbourCell.Type == ECellType.Blocked || neighbourCell.Poi != null)) { results.Add(new InvalidInstructionResult(requestId, EInvalidReason.Blocked, card, neighbourCell)); } else { var avatar = (Avatar)cell.Poi!; cell.Poi = null; neighbourCell.Poi = avatar; results.Add(new PoiResult(requestId, new(coreLoop.Board), null, cell.Hex)); results.Add(new PoiResult(requestId, new(coreLoop.Board), avatar, neighbour)); coreLoop.PathLength += Amount; coreLoop.CellsVisited.Add(cell.Hex); coreLoop.CellsVisited.Add(neighbour); if (coreLoop.Currency.Energy == 0) { coreLoop.EnergyWasted += 1; } foreach (var modifier in neighbourCell.Modifiers) { if (modifier.DebuffSources.Count > 0) continue; switch (modifier.Id) { case EModifierId.Corrupt: case EModifierId.Unreliable: case EModifierId.RaceCondition: { var tape = coreLoop.GetTapeCards(); var currentIndex = tape.IndexOf(card); for (int i = currentIndex + 1; i < tape.Count; ++i) newIntents.Add(new ModifyCard(tape[i], modifier.Id, EModifierDuration.Temporary, ECardLocation.Tape)); break; } } } } } base.Run(requestId, coreLoop, newIntents, results); } public EDirection Direction { get; set; } = direction; public override bool IsValid(CoreLoop coreLoop) => base.IsValid(coreLoop) && cell.Poi is Avatar; public int Amount { get; set; } = amount; public override string ToString() => $"Move towards {Direction} by {Amount}, " + base.ToString(); }