35 lines
1.3 KiB
C#
35 lines
1.3 KiB
C#
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();
|
|
} |