Esempio n. 1
0
    private IEnumerator Move(int rolledAmount)
    {
        int destinationTileIndex = -1;

        if (IsStaged)
        {
            if (rolledAmount == 6)
            {
                rolledAmount         = 0;
                IsStaged             = false;
                destinationTileIndex = startTileIndex;
                RpcBonusRoll(slot);
                TargetMoveToStart(playerController.connectionToClient);
            }
        }
        else
        {
            while (rolledAmount > 0)
            {
                rolledAmount--;

                if ((currentTileIndex + 1) == gci.numberOfTiles)
                {
                    currentTileIndex     = 0;
                    destinationTileIndex = currentTileIndex;
                }
                else if (currentTileIndex == lastTileIndex)
                {
                    inner            = true;
                    currentTileIndex = -1;                     // just entered
                    rolledAmount++;
                    destinationTileIndex = lastTileIndex;
                    //yield return false;
                    continue;
                }
                else if (inner)
                {
                    Debug.Log("currentTileIndex: " + currentTileIndex + ", rolledAmount: " + rolledAmount + ", total: " + (currentTileIndex + rolledAmount));
                    if ((currentTileIndex + rolledAmount) > 5)
                    {
                        break;
                        //} else if (currentTileIndex != 5 && (rolledAmount + 1) > 0) { // prevents 5 + 0, OOB Exception
                    }
                    else if (currentTileIndex != 5 && (rolledAmount >= 0))
                    {
                        currentTileIndex++;

                        atFinish = gci.player[slot].innerPath[currentTileIndex].tag == "Finish";

                        if (atFinish)
                        {
                            Debug.Log("=== BONUS MOVE GRANTED DUE TO LANDING ON FINISH ===");
                            RpcBonusRoll(slot);
                            playerController.rollsLeft++;
                        }
                    }
                }
                else
                {
                    currentTileIndex++;
                    destinationTileIndex = currentTileIndex;
                }

                TargetMove(playerController.connectionToClient, currentTileIndex, inner);

                yield return(false);
            }
        }

        bool bonusEliminationMove = false;

        // Move is finished and rolledAmount is zero, if collides with other pawns
        if (!inner && rolledAmount == 0 && (!inner || currentTileIndex != lastTileIndex))
        {
            Debug.Log("DestinationTileIndex: " + destinationTileIndex);

            GameObject destinationTile = gci.path[destinationTileIndex];

            // If a piece lands upon a piece of the same colour, this forms a block.This block cannot be passed or landed on by any opposing piece.

            switch (destinationTile.tag)
            {
            case "Start":
            case "Finish":
            case "Safe":
                break;

            default:
                Collider[] hitColliders = Physics.OverlapBox(destinationTile.transform.position, boxCollider.size / 2f, Quaternion.identity);

                Debug.Log(hitColliders.Length);

                int[] pawnsOnTile = new int[GameController.Instance.bases.Count];

                foreach (Collider collider in hitColliders)
                {
                    GameObject     hitGameObject     = collider.transform.parent.gameObject;
                    PawnController hitPawnController = hitGameObject.GetComponent <PawnController>();

                    if (hitPawnController != this)
                    {
                        Debug.Log(collider.transform.parent.gameObject);
                        pawnsOnTile[hitPawnController.slot] += 1;
                    }
                }

                List <int> toEliminate = new List <int>();

                for (int i = 0; i < pawnsOnTile.Length; ++i)
                {
                    if (i == slot)
                    {
                        continue;
                    }

                    int pawnCount = pawnsOnTile[i];

                    if (pawnCount == 1)
                    {
                        toEliminate.Add(i);
                    }
                }

                foreach (int slot in toEliminate)
                {
                    foreach (Collider collider in hitColliders)
                    {
                        GameObject     hitGameObject     = collider.transform.parent.gameObject;
                        PawnController hitPawnController = hitGameObject.GetComponent <PawnController>();

                        if (slot == hitPawnController.slot)
                        {
                            hitPawnController.ServerEliminate();
                            bonusEliminationMove = true;
                        }
                    }
                }

                break;
            }
        }

        if (bonusEliminationMove)
        {
            playerController.rollsLeft++;
            RpcBonusRoll(slot);
        }

        if (playerController.rollsLeft > 0)
        {
            RpcBonusRoll(slot);
        }

        playerController.pawnSelected = isSelected = isMoving = false;
        playerController.rolledAmount = 0;
    }