Skip to content

Instantly share code, notes, and snippets.

@general-games
Created December 12, 2022 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save general-games/ebac7e5272c5b091f2b2ed8743635310 to your computer and use it in GitHub Desktop.
Save general-games/ebac7e5272c5b091f2b2ed8743635310 to your computer and use it in GitHub Desktop.
Gridr - Movement Validation in one asset
[CreateAssetMenu(menuName = "Gridr/Action Condition/ADW/Complete Movement Validation")]
public class CompleteMovementValidation : ActionCondition<GridAction>
{
public override bool Validate(Cell cell, GridAction action)
{
return IsInRange(action, cell) && cell.Connected && !cell.Occupied && cell != action.Entity.Cell;
}
private bool IsInRange(GridAction action, Cell cell)
{
if (!(action is MovementAction movementAction))
return false;
if (!movementAction.costToCell.ContainsKey(cell))
return true;
return movementAction.costToCell[cell] <= movementAction.data.range;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment