/// <summary> /// Returns the valid positions on the board adjacent to the give <paramref name="position"/> /// </summary> /// <param name="position"></param> /// <returns></returns> public IEnumerable <CellPosition> GetValidNeighbourPositions(CellPosition position) { CellPosition[] possibleNeighbours = GetPossibleNeighbourPositions(position); var validNeighbours = possibleNeighbours.Intersect(HexCells.Select(x => x.Position)); return(validNeighbours); }
public Cell GetCellAtPosition(CellPosition position) { var result = HexCells.FirstOrDefault(o => o.Position == position); if (result == null) { throw new InvalidCellPositionException(position); } return(result); }
public void AddCell(Cell cell) { // Make sure we don't have a cell at this position already if (HexCells.Any(c => c.Position == cell.Position)) { throw new InvalidCellPositionException($"{cell.Position} already exists in the game board"); } HexCells.Add(cell); }
public Cell AddCell(CellPosition cellPosition) { // Make sure we don't have a cell at this position already if (HexCells.Any(c => c.Position == cellPosition)) { throw new InvalidCellPositionException($"{cellPosition} already exists in the game board"); } Cell newCell = new Cell(cellPosition); HexCells.Add(newCell); return(newCell); }
public void Prepare(IUseable abilityToPrepare, List <HexCell> cellRange, bool addToRange = false, bool toggleToRed = true) { // var isPrepared = Prepare(Action.UseAbility, cellRange, addToRange); Prepare(Action.UseAbility, cellRange, addToRange); // if (!isPrepared) return false; AbilityToUse = abilityToPrepare; if (!toggleToRed) { return; } Game.HexMapDrawer.RemoveHighlights(); HexCells.ForEach(c => c.AddHighlight(Highlights.RedTransparent)); // return true; }
public bool Prepare(Ability abilityToPrepare, List <HexCell> cellRange, bool addToRange = false, bool toggleToRed = true) { var isPrepared = Prepare(Action.UseAbility, cellRange, addToRange); if (!isPrepared) { return(false); } Ability = abilityToPrepare; if (toggleToRed) { Game.HexMapDrawer.RemoveAllHighlights(); HexCells.ForEach(c => c.ToggleHighlight(HiglightColor.Red)); } return(true); }
public bool Prepare(Action actionToPrepare, List <HexCell> cellRange, bool addToRange = false) { if (cellRange == null) { throw new Exception("Cell range cannot be null!"); } if (cellRange.Count == 0 && !addToRange) { return(false); } if (HexCells != null && addToRange) { HexCells.AddRange(cellRange); } else { HexCells = cellRange; } Action = actionToPrepare; return(true); }
public bool TryGetCellAtPosition(CellPosition position, out Cell cell) { cell = HexCells.FirstOrDefault(o => o.Position == position); return(cell != null); }
public bool IsValidCellPosition(CellPosition position) { return(HexCells.Any(o => o.Position == position)); }
public void MakeAction(HexCell cell) { if (!HexCells.Contains(cell)) { return; } // if (Turn.CharacterThatTookActionInTurn == null) CharacterOnMap.InvokeJustBeforeFirstAction(); if (CharacterOnMap != null && !CharacterOnMap.TookActionInPhaseBefore) { CharacterOnMap.InvokeJustBeforeFirstAction(); } switch (Action) { case Action.None: throw new Exception("Żadna akcja nie jest aktywna!"); case Action.UseAbility: if (cell.CharacterOnCell != null) { Ability.Use(cell.CharacterOnCell); } else { Ability.Use(cell); } break; case Action.AttackAndMove: Character character = CharacterOnMap; if (character == null) { throw new NullReferenceException(); } if (cell.CharacterOnCell != null) { character.BasicAttack(cell.CharacterOnCell); } else { if (cell.Type == HexTileType.Wall) { return; } // if (cell == MoveCells.LastOrDefault()) // { // if (character.Abilities.Any(a => a.OverridesMove)) // { // if (character.Abilities.Count(a => a.OverridesMove) > 1) // throw new Exception("Więcej niż jedna umiejętność próbuje nadpisać akcję ruchu!"); // // character.Abilities.Single(a => a.OverridesMove).Move(MoveCells); // } // else // { // character.BasicMove(MoveCells); // } // } character.BasicMove(MoveCells); } HexCells = null; //TODO is this really needed? Action = Action.None; character.Select(); break; default: throw new ArgumentOutOfRangeException(); } }
public HexCell this[Vector2Int index] { get { return(HexCells.GetItem(index)); } }
/// <summary> /// 获取指定坐标的单元格的通行成本 /// </summary> /// <param name="index"></param> /// <returns></returns> public int ThroughCost(Vector2Int index) => HexCells.GetItem(index).ThroughCost;