ported from perforce
This commit is contained in:
35
RobotAndDonkey.Game/Intents/ModifyRobot.cs
Normal file
35
RobotAndDonkey.Game/Intents/ModifyRobot.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using RobotAndDonkey.Game.Execution.Results;
|
||||
using RobotAndDonkey.Game.GameState;
|
||||
using RobotAndDonkey.Game.Modifiers;
|
||||
|
||||
namespace RobotAndDonkey.Game.Intents;
|
||||
|
||||
public class ModifyRobot(EModifierId modifierId, EModifierDuration duration) : Intent
|
||||
{
|
||||
public override void Run(Guid requestId, CoreLoop coreLoop, List<Intent> newIntents, List<Result> results)
|
||||
{
|
||||
coreLoop.Robot.AddModifier(ModifierId switch
|
||||
{
|
||||
EModifierId.Pest => new PestModifier(Duration),
|
||||
EModifierId.Gravity => new GravityModifier(Duration),
|
||||
EModifierId.HeatWave => new HeatWaveModifier(Duration),
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
}, newIntents);
|
||||
results.Add(new ModifyRobotResult(requestId));
|
||||
|
||||
base.Run(requestId, coreLoop, newIntents, results);
|
||||
}
|
||||
|
||||
public override bool IsValid(CoreLoop coreLoop)
|
||||
{
|
||||
return base.IsValid(coreLoop) &&
|
||||
ModifierId is EModifierId.Pest or EModifierId.Gravity or EModifierId.HeatWave &&
|
||||
coreLoop.Robot.Modifiers.All(m => m.Id != ModifierId);
|
||||
}
|
||||
|
||||
public EModifierId ModifierId { get; set; } = modifierId;
|
||||
|
||||
public EModifierDuration Duration { get; set; } = duration;
|
||||
|
||||
public override string ToString() => $"Modify robot with {ModifierId}, {Duration}, " + base.ToString();
|
||||
}
|
||||
Reference in New Issue
Block a user