ported from perforce
This commit is contained in:
90
RobotAndDonkey.Game/Intents/Interact.cs
Normal file
90
RobotAndDonkey.Game/Intents/Interact.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
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;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RobotAndDonkey.Game.Intents;
|
||||
|
||||
public class Interact(Cell cell, Card card, EDirection direction) : Intent
|
||||
{
|
||||
public override void Run(Guid requestId, CoreLoop coreLoop, List<Intent> newIntents, List<Result> results)
|
||||
{
|
||||
if (cell.Type == ECellType.Dry)
|
||||
{
|
||||
EnergyCost += Balancing.Instance.DryInteractEnergyMalus;
|
||||
}
|
||||
|
||||
var neighbour = cell.Hex.GetNeighbour(Direction);
|
||||
var neighbourIndex = coreLoop.Board.FindCellIndex(neighbour);
|
||||
if (neighbourIndex < 0)
|
||||
{
|
||||
results.Add(new InvalidInstructionResult(requestId, EInvalidReason.NotFound, card, cell));
|
||||
}
|
||||
else
|
||||
{
|
||||
var neighbourCell = coreLoop.Board.Cells[neighbourIndex];
|
||||
if (neighbourCell.Poi is Crate crate)
|
||||
{
|
||||
var amount = Math.Min(crate.Amount, coreLoop.Currency.MaxCarry - coreLoop.Currency.Carry);
|
||||
if (amount <= 0)
|
||||
{
|
||||
results.Add(new InvalidInstructionResult(requestId, EInvalidReason.NoAmount, card, cell));
|
||||
}
|
||||
else
|
||||
{
|
||||
newIntents.Add(new PickUp(neighbourCell, crate, amount, 0));
|
||||
}
|
||||
}
|
||||
else if (neighbourCell.Poi is Shed shed)
|
||||
{
|
||||
var carrying = coreLoop.Currency.Carry;
|
||||
if (carrying <= 0)
|
||||
{
|
||||
results.Add(new InvalidInstructionResult(requestId, EInvalidReason.NoAmount, card, cell));
|
||||
}
|
||||
else
|
||||
{
|
||||
var toDeliver = Math.Min(carrying, shed.Remaining);
|
||||
var overspill = Math.Max(0, carrying - toDeliver);
|
||||
|
||||
if (toDeliver > 0)
|
||||
{
|
||||
shed.Received += toDeliver;
|
||||
coreLoop.Currency.Carry -= toDeliver;
|
||||
coreLoop.Currency.Delivery += toDeliver;
|
||||
coreLoop.Overspill += overspill;
|
||||
|
||||
results.Add(new PoiResult(requestId, new(coreLoop.Board), shed, neighbourCell.Hex));
|
||||
results.Add(new CurrencyResult(requestId, coreLoop.Currency));
|
||||
results.Add(new ModifyRobotResult(requestId));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (neighbourCell.Poi is Donkey)
|
||||
{
|
||||
newIntents.Add(new DonkeyIntent(card, neighbourCell, 0));
|
||||
}
|
||||
else if (neighbourCell.Poi is Tower tower)
|
||||
{
|
||||
newIntents.Add(new TowerIntent(neighbourCell, tower, false, 0));
|
||||
results.Add(new PoiResult(requestId, new(coreLoop.Board), tower, cell.Hex));
|
||||
}
|
||||
else
|
||||
{
|
||||
results.Add(new InvalidInstructionResult(requestId, EInvalidReason.NoTarget, card, cell));
|
||||
}
|
||||
}
|
||||
|
||||
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 override string ToString() => $"Interact with {Direction} from {cell}, " + base.ToString();
|
||||
}
|
||||
Reference in New Issue
Block a user