Created
December 12, 2022 11:56
-
-
Save general-games/ebac7e5272c5b091f2b2ed8743635310 to your computer and use it in GitHub Desktop.
Gridr - Movement Validation in one asset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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