38 lines
1.4 KiB
C#
38 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using RobotAndDonkey.Game.Board;
|
|
using RobotAndDonkey.Game.Execution.Results;
|
|
using RobotAndDonkey.Game.GameState;
|
|
using RobotAndDonkey.Game.Modifiers;
|
|
|
|
namespace RobotAndDonkey.Game.Intents;
|
|
|
|
public class ModifyCell(Cell cell, EModifierId modifierId, EModifierDuration duration) : Intent
|
|
{
|
|
public override void Run(Guid requestId, CoreLoop coreLoop, List<Intent> newIntents, List<Result> results)
|
|
{
|
|
Cell.AddModifier(ModifierId switch
|
|
{
|
|
EModifierId.Rain => new RainModifier(Duration),
|
|
EModifierId.Drought => new DroughtModifier(Duration),
|
|
_ => throw new ArgumentOutOfRangeException()
|
|
}, newIntents);
|
|
results.Add(new ModifyCellResult(requestId, new(coreLoop.Board), ModifierId, Cell.Hex));
|
|
|
|
base.Run(requestId, coreLoop, newIntents, results);
|
|
}
|
|
|
|
public override bool IsValid(CoreLoop coreLoop)
|
|
{
|
|
return base.IsValid(coreLoop) && ModifierId is EModifierId.Rain or EModifierId.Drought && Cell.Modifiers.All(m => m.Id != ModifierId);
|
|
}
|
|
|
|
public EModifierId ModifierId { get; set; } = modifierId;
|
|
|
|
public EModifierDuration Duration { get; set; } = duration;
|
|
|
|
public Cell Cell { get; set; } = cell;
|
|
|
|
public override string ToString() => $"Modify {Cell.Hex} with {ModifierId}, {Duration}, " + base.ToString();
|
|
} |