RunicBoard.PlaceRuneOnBoard C# (CSharp) Méthode

PlaceRuneOnBoard() public méthode

Verify if you can place a rune at the position, and place it if it is OK.
public PlaceRuneOnBoard ( int index, int position ) : int
index int The index in runesInHand list
position int The position where the rune will be placed
Résultat int
    public int PlaceRuneOnBoard(int index, int position)
    {
        if (ClientManager.GetInstance()._client.CurrentCharacter.CurrentActionPoints > 0 && ClientManager.GetInstance()._client.IsMyTurn && !ClientManager.GetInstance()._client.LockedMode)
        {
            Rune rune;
            if(_runesInHand.TryGetValue(index, out rune))
            {
                // If no runes are on the board, places the rune in the center
                if (_runesOnBoard.Count == 0)
                {
                    rune.TurnUsed = ClientManager.GetInstance()._client._turnNumber;
                    _runesOnBoard.Add(12, rune);
                    rune.PositionOnBoard = 12;
                    _runesInHand.Remove(index);
                    ClientManager.GetInstance()._client.CurrentCharacter.CurrentActionPoints--;
                    return 12;
                }

                // The player cannot place a rune if a rune is already in place at the position
                if (_runesOnBoard.ContainsKey(position))
                {
                    return -1;
                }

                // If runes are placed around this position, place the rune
                List<int> neighbours = GetAdjacentPositions(position);
                for(int i = 0; i < neighbours.Count; i++)
                {
                    if (_runesOnBoard.ContainsKey(neighbours[i]))
                    {
                        rune.TurnUsed = ClientManager.GetInstance()._client._turnNumber;
                        _runesOnBoard.Add(position, rune);
                        rune.PositionOnBoard = position;
                        _runesInHand.Remove(index);
                        ClientManager.GetInstance()._client.CurrentCharacter.CurrentActionPoints--;
                        if (_runesOnBoard.Count == 2) // Keep in mind what was the second rune placed for perfection pole
                            SecondPlaced = position;
                        return position;
                    }
                }
            }
        }
        else
        {
            if (ClientManager.GetInstance()._client.CurrentCharacter.CurrentActionPoints > 0)
                Logger.Error("Not Your turn");
            else
                if(!ClientManager.GetInstance()._client.LockedMode)
                    Logger.Error("Unlock Runic board !!");
                else
                    Logger.Error("Not enough action points");
        }
        return -1;
    }