64 lines
2.6 KiB
C#
64 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using RobotAndDonkey.Game.Board;
|
|
using RobotAndDonkey.Game.Cards;
|
|
using RobotAndDonkey.Game.Execution.Results;
|
|
using RobotAndDonkey.Game.GameState;
|
|
using RobotAndDonkey.Game.Pois;
|
|
|
|
namespace RobotAndDonkey.Game.Intents;
|
|
|
|
public class DetoxiumPrime(Cell cell, Card card, EDirection direction) : Intent
|
|
{
|
|
public override void Run(Guid requestId, CoreLoop coreLoop, List<Intent> newIntents, List<Result> results)
|
|
{
|
|
var neighbour = cell.Hex.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];
|
|
var newType = (neighbourCell.Type, Heal) switch
|
|
{
|
|
(ECellType.Blocked, true) => ECellType.Mud,
|
|
(ECellType.Rocky, true) => ECellType.Grass,
|
|
(ECellType.Mud, true) => ECellType.Grass,
|
|
(ECellType.Dry, true) => ECellType.Grass,
|
|
(ECellType.Grass, true) => ECellType.Fertile,
|
|
(ECellType.Grass, false) => coreLoop.Random.Next(3) switch
|
|
{
|
|
0 => ECellType.Dry,
|
|
1 => ECellType.Mud,
|
|
2 => ECellType.Rocky,
|
|
_ => throw new UnreachableException()
|
|
},
|
|
(ECellType.Fertile, false) => ECellType.Grass,
|
|
(ECellType.Mud, false) => ECellType.Blocked,
|
|
_ => (ECellType)(-1)
|
|
};
|
|
if (newType < 0)
|
|
{
|
|
results.Add(new InvalidInstructionResult(requestId, EInvalidReason.NoTarget, card, neighbourCell));
|
|
}
|
|
else
|
|
{
|
|
neighbourCell.Type = newType;
|
|
results.Add(new CellTypeResult(requestId, new(coreLoop.Board), neighbourCell.Hex));
|
|
}
|
|
}
|
|
|
|
base.Run(requestId, coreLoop, newIntents, results);
|
|
}
|
|
|
|
public EDirection Direction { get; set; } = direction;
|
|
|
|
public bool Heal { get; set; } = true;
|
|
|
|
public override bool IsValid(CoreLoop coreLoop) => base.IsValid(coreLoop) && cell.Poi is Avatar;
|
|
|
|
public override string ToString() => $"Detox {Direction}, Heal={Heal}, " + base.ToString();
|
|
} |