ported from perforce
This commit is contained in:
40
RobotAndDonkey.Game/Intents/ModifyCurrency.cs
Normal file
40
RobotAndDonkey.Game/Intents/ModifyCurrency.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RobotAndDonkey.Game.Execution.Results;
|
||||
using RobotAndDonkey.Game.GameState;
|
||||
using RobotAndDonkey.Game.Modifiers;
|
||||
|
||||
namespace RobotAndDonkey.Game.Intents;
|
||||
|
||||
public class ModifyCurrency(Currency delta, bool canCorrupt = false) : Intent
|
||||
{
|
||||
public override void Run(Guid requestId, CoreLoop coreLoop, List<Intent> newIntents, List<Result> results)
|
||||
{
|
||||
coreLoop.Currency.Energy += Delta.Energy;
|
||||
coreLoop.Currency.MaxCarry += Delta.MaxCarry;
|
||||
coreLoop.Currency.Carry += Delta.Carry;
|
||||
coreLoop.Currency.Delivery += Delta.Delivery;
|
||||
coreLoop.Currency.TapeLength += Delta.TapeLength;
|
||||
coreLoop.Currency.HandSize += Delta.HandSize;
|
||||
results.Add(new CurrencyResult(requestId, coreLoop.Currency));
|
||||
|
||||
base.Run(requestId, coreLoop, newIntents, results);
|
||||
}
|
||||
|
||||
public override bool IsValid(CoreLoop coreLoop)
|
||||
{
|
||||
return base.IsValid(coreLoop) &&
|
||||
coreLoop.Currency.Energy + Delta.Energy >= 0 &&
|
||||
coreLoop.Currency.MaxCarry + Delta.MaxCarry >= 0 &&
|
||||
coreLoop.Currency.Carry + Delta.Carry >= 0 &&
|
||||
coreLoop.Currency.Delivery + Delta.Delivery >= 0 &&
|
||||
coreLoop.Currency.TapeLength + Delta.TapeLength >= 0 &&
|
||||
coreLoop.Currency.HandSize + Delta.HandSize >= 0;
|
||||
}
|
||||
|
||||
public Currency Delta { get; set; } = delta;
|
||||
|
||||
public bool CanCorrupt { get; set; } = canCorrupt;
|
||||
|
||||
public override string ToString() => $"Currency delta: {Delta}, CanCorrupt={CanCorrupt} " + base.ToString();
|
||||
}
|
||||
Reference in New Issue
Block a user