ported from perforce
This commit is contained in:
77
RobotAndDonkey.Game/Intents/TowerIntent.cs
Normal file
77
RobotAndDonkey.Game/Intents/TowerIntent.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RobotAndDonkey.Game.Board;
|
||||
using RobotAndDonkey.Game.Execution.Results;
|
||||
using RobotAndDonkey.Game.GameState;
|
||||
using RobotAndDonkey.Game.Pois;
|
||||
|
||||
namespace RobotAndDonkey.Game.Intents;
|
||||
|
||||
public class TowerIntent(Cell cell, Tower tower, bool active, int energyCost) : Intent(energyCost)
|
||||
{
|
||||
public override void Run(Guid requestId, CoreLoop coreLoop, List<Intent> newIntents, List<Result> results)
|
||||
{
|
||||
var board = coreLoop.Board;
|
||||
|
||||
foreach (var modifier in Cell.Modifiers)
|
||||
{
|
||||
if (modifier.Id != EModifierId.Unreliable)
|
||||
continue;
|
||||
|
||||
if (Active)
|
||||
{
|
||||
modifier.DebuffSources.Remove(Cell);
|
||||
}
|
||||
else
|
||||
{
|
||||
modifier.DebuffSources.Add(Cell);
|
||||
}
|
||||
}
|
||||
|
||||
Tower.Active = Active;
|
||||
results.Add(new PoiResult(requestId, new(coreLoop.Board), Tower, Cell.Hex));
|
||||
|
||||
for (var direction = 0; direction < 6; direction++)
|
||||
{
|
||||
var neighbourHex = Cell.Hex.GetNeighbour((EDirection)direction);
|
||||
var neighbourIndex = board.FindCellIndex(neighbourHex);
|
||||
if (neighbourIndex < 0)
|
||||
continue;
|
||||
|
||||
var neighbourCell = board.Cells[neighbourIndex];
|
||||
foreach (var modifier in neighbourCell.Modifiers)
|
||||
{
|
||||
if (modifier.Id != EModifierId.Unreliable)
|
||||
continue;
|
||||
|
||||
if (Active)
|
||||
{
|
||||
modifier.DebuffSources.Remove(Cell);
|
||||
}
|
||||
else
|
||||
{
|
||||
modifier.DebuffSources.Add(Cell);
|
||||
}
|
||||
results.Add(new ModifyCellResult(requestId, new(coreLoop.Board), EModifierId.Unreliable, neighbourCell.Hex));
|
||||
}
|
||||
}
|
||||
|
||||
base.Run(requestId, coreLoop, newIntents, results);
|
||||
}
|
||||
|
||||
public override bool IsValid(CoreLoop coreLoop)
|
||||
{
|
||||
if (Tower.Active == Active)
|
||||
return false;
|
||||
|
||||
return base.IsValid(coreLoop);
|
||||
}
|
||||
|
||||
public Cell Cell { get; } = cell;
|
||||
|
||||
public Tower Tower { get; } = tower;
|
||||
|
||||
public bool Active { get; set; } = active;
|
||||
|
||||
public override string ToString() => $"Tower at {Cell.Hex}, Active={Active}, " + base.ToString();
|
||||
}
|
||||
Reference in New Issue
Block a user