Exemple #1
0
        /// <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);
        }
Exemple #2
0
        public Cell GetCellAtPosition(CellPosition position)
        {
            var result = HexCells.FirstOrDefault(o => o.Position == position);

            if (result == null)
            {
                throw new InvalidCellPositionException(position);
            }
            return(result);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
    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;
    }
Exemple #6
0
    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);
    }
Exemple #7
0
    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);
    }
Exemple #8
0
 public bool TryGetCellAtPosition(CellPosition position, out Cell cell)
 {
     cell = HexCells.FirstOrDefault(o => o.Position == position);
     return(cell != null);
 }
Exemple #9
0
 public bool IsValidCellPosition(CellPosition position)
 {
     return(HexCells.Any(o => o.Position == position));
 }
Exemple #10
0
    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();
        }
    }
Exemple #11
0
 public HexCell this[Vector2Int index]
 {
     get { return(HexCells.GetItem(index)); }
 }
Exemple #12
0
 /// <summary>
 /// 获取指定坐标的单元格的通行成本
 /// </summary>
 /// <param name="index"></param>
 /// <returns></returns>
 public int ThroughCost(Vector2Int index) => HexCells.GetItem(index).ThroughCost;