ported from perforce
This commit is contained in:
37
RobotAndDonkey.Game/Intents/PickUp.cs
Normal file
37
RobotAndDonkey.Game/Intents/PickUp.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RobotAndDonkey.Game.Board;
|
||||
using RobotAndDonkey.Game.Cards.Patches;
|
||||
using RobotAndDonkey.Game.Execution.Results;
|
||||
using RobotAndDonkey.Game.GameState;
|
||||
using RobotAndDonkey.Game.Pois;
|
||||
|
||||
namespace RobotAndDonkey.Game.Intents;
|
||||
|
||||
public class PickUp(Cell neighbourCell, Crate crate, int amount, int energyCost) : Intent(energyCost)
|
||||
{
|
||||
public override void Run(Guid requestId, CoreLoop coreLoop, List<Intent> newIntents, List<Result> results)
|
||||
{
|
||||
if (Amount == 0)
|
||||
{
|
||||
results.Add(new InvalidInstructionResult(requestId, EInvalidReason.NoAmount, null, neighbourCell));
|
||||
}
|
||||
else
|
||||
{
|
||||
coreLoop.Currency.Carry += Amount;
|
||||
crate.Amount -= Amount;
|
||||
results.Add(new PoiResult(requestId, new(coreLoop.Board), crate, neighbourCell.Hex));
|
||||
results.Add(new CurrencyResult(requestId, coreLoop.Currency));
|
||||
base.Run(requestId, coreLoop, newIntents, results);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsValid(CoreLoop coreLoop)
|
||||
{
|
||||
return base.IsValid(coreLoop) && Amount <= coreLoop.Currency.MaxCarry - coreLoop.Currency.Carry;
|
||||
}
|
||||
|
||||
public int Amount { get; set; } = amount;
|
||||
|
||||
public override string ToString() => $"Pick up {Amount}, " + base.ToString();
|
||||
}
|
||||
Reference in New Issue
Block a user