Ejemplo n.º 1
0
    public void MovePirate()
    {
        int    hexIndex    = gameBoard.tiles.IndexOf(gameObject);
        Player localPlayer = GameObject.Find("Local Player Panel").GetComponent <Player> ();

        localPlayer.CmdMovePirate(hexIndex);
        int numOtherPlayerShips = 0;

        foreach (Edge e in adjacentEdges)
        {
            if (e != null && e.transform.childCount > 2 && (e.transform.GetChild(2).gameObject.GetComponent <EdgeUnit> () != null))
            {
                EdgeUnit ship = e.transform.GetChild(2).gameObject.GetComponent <EdgeUnit> ();
                if (!ship.owner.isLocalPlayer)
                {
                    e.gameObject.GetComponent <BoxCollider> ().enabled = true;
                    e.transform.GetChild(0).gameObject.SetActive(true);
                    e.gameObject.GetComponent <Edge> ().waitingBuildDelegate = e.gameObject.GetComponent <Edge> ().StealResource;
                    numOtherPlayerShips++;
                }
            }
        }
        gameBoard.HexActionRequestEnd();
        gameBoard.EnableAllKnightsAndVillagesSelection(false);
        if (numOtherPlayerShips == 0)
        {
            localPlayer.CmdResponseToServer();
        }
    }
Ejemplo n.º 2
0
    public List <Intersection> getValidIntersectionsForPlayer(Player player, bool isKnight)
    {
        List <Intersection> allIntersections   = GameObject.FindGameObjectWithTag("Board").GetComponent <GameBoard>().Intersections.Values.ToList();
        List <Intersection> validIntersections = new List <Intersection> ();

        if (EventTransferManager.instance.setupPhase)
        {
            for (int i = 0; i < allIntersections.Count; i++)
            {
                List <Intersection> neighborsOfIntersection = allIntersections [i].getNeighborIntersections();
                bool validIntersection = true;

                for (int j = 0; j < neighborsOfIntersection.Count; j++)
                {
                    if (!allIntersections[i].isSettleable() || neighborsOfIntersection [j].occupier != null || !allIntersections[i].isMainIslandIntersection())                      // && neighborsOfIntersection [j].occupier.owner != player) {
                    {
                        validIntersection = false;
                    }
                }

                if (validIntersection)
                {
                    validIntersections.Add(allIntersections [i]);
                }
            }
        }
        else
        {
            allIntersections = new List <Intersection> ();
            List <Unit> ownedUnits = player.getOwnedUnits();

            for (int i = 0; i < ownedUnits.Count; i++)
            {
                if (typeof(EdgeUnit).IsAssignableFrom(ownedUnits [i].GetType()))
                {
                    EdgeUnit tradeUnit   = (EdgeUnit)(ownedUnits [i]);
                    Edge     relatedEdge = tradeUnit.locationEdge;

                    List <Intersection> neighborIntersections = relatedEdge.getLinkedIntersections();

                    for (int j = 0; j < neighborIntersections.Count; j++)
                    {
                        if (neighborIntersections [j].occupier == null && neighborIntersections [j].isSettleable() &&
                            (neighborIntersections [j].isNotNeighboringIntersectionWithUnit() || isKnight))
                        {
                            validIntersections.Add(neighborIntersections [j]);
                        }
                    }
                }
            }
        }

        return(validIntersections);
    }
Ejemplo n.º 3
0
    public static List <Intersection> getValidIntersectionsForPlayer(Player player)
    {
        List <Intersection> allIntersections   = GameBoard.getIntersections();
        List <Intersection> validIntersections = new List <Intersection> ();

        if (setupPhase)
        {
            for (int i = 0; i < allIntersections.Count; i++)
            {
                List <Intersection> neighborsOfIntersection = allIntersections [i].getNeighborIntersections();
                bool validIntersection = true;

                for (int j = 0; j < neighborsOfIntersection.Count; j++)
                {
                    if (!allIntersections[i].isSettleable() || neighborsOfIntersection [j].occupier != null)                      // && neighborsOfIntersection [j].occupier.owner != player) {
                    {
                        validIntersection = false;
                    }
                }

                if (validIntersection)
                {
                    validIntersections.Add(allIntersections [i]);
                }
            }
        }
        else
        {
            allIntersections = new List <Intersection> ();
            List <Unit> ownedUnits = player.getOwnedUnits();

            for (int i = 0; i < ownedUnits.Count; i++)
            {
                if (typeof(EdgeUnit).IsAssignableFrom(ownedUnits [i].GetType()))
                {
                    EdgeUnit edgeUnit    = (EdgeUnit)(ownedUnits [i]);
                    Edge     relatedEdge = edgeUnit.locationEdge;

                    List <Intersection> neighborIntersections = relatedEdge.getLinkedIntersections();

                    for (int j = 0; j < neighborIntersections.Count; j++)
                    {
                        if (neighborIntersections [j].occupier == null && neighborIntersections [j].isSettleable() &&
                            neighborIntersections [j].isNotNeighboringIntersectionWithUnit())
                        {
                            validIntersections.Add(neighborIntersections [j]);
                        }
                    }
                }
            }
        }

        return(validIntersections);
    }
Ejemplo n.º 4
0
    IEnumerator buildTradeUnit2(EdgeUnit edgeUnit, System.Type unitType)
    {
        waitingForPlayer = true;
        List <Edge>   validEdgesToBuild = getValidEdgesForPlayer(players[currentPlayerTurn], true);
        ResourceTuple costOfUnit        = resourceManager.getCostOfUnit(unitType);

        if (costOfUnit == null)
        {
            print("costofunit is null, returning.");
            waitingForPlayer = false;
            yield break;
        }

        if (!setupPhase)
        {
            if (!players [currentPlayerTurn].hasAvailableResources(costOfUnit))                // (Road.ResourceValue);//ResourceCost.getResourceValueOf(Road.ResourceValue);
            {
                print("Insufficient Resources to build a road!");
                waitingForPlayer = false;
                yield break;
            }
        }

        if (validEdgesToBuild.Count == 0)
        {
            print("No possible location to build a road!");
            Destroy(edgeUnit);
            waitingForPlayer = false;
            yield break;
        }

        highlightEdgesWithColor(validEdgesToBuild, true, players [currentPlayerTurn].playerColor);

        edgeUnit.id = unitID++;
        edgeUnit.gameObject.SetActive(false);

        yield return(StartCoroutine(players [currentPlayerTurn].makeEdgeSelection(validEdgesToBuild)));         //, edgeUnit));//new Road(unitID++)));

        edgeUnit.GetComponentInChildren <Renderer> ().material.color = players[currentPlayerTurn].playerColor;
        edgeUnit.gameObject.SetActive(true);

        if (!setupPhase)
        {
            players [currentPlayerTurn].spendResources(costOfUnit);

            uiButtons [2].GetComponentInChildren <Text> ().text = "Build Road";
        }
        highlightAllEdges(false);

        waitingForPlayer = false;
    }
Ejemplo n.º 5
0
    public List <Edge> getValidEdgesForPlayer(Player player, bool roadBuilt)
    {
        //print ("roadBuilt == " + roadBuilt.ToString ());
        List <Edge> validEdges = new List <Edge> ();
        List <Unit> ownedUnits = player.getOwnedUnits();

        if (EventTransferManager.instance.setupPhase)
        {
            for (int i = 0; i < ownedUnits.Count; i++)
            {
                if (typeof(IntersectionUnit).IsAssignableFrom(ownedUnits [i].GetType()))
                {
                    bool             validSet            = true;
                    IntersectionUnit intersectionUnit    = (IntersectionUnit)(ownedUnits [i]);
                    Intersection     relatedIntersection = intersectionUnit.locationIntersection;
                    List <Edge>      connectedEdges      = relatedIntersection.getLinkedEdges();

                    for (int j = 0; j < connectedEdges.Count; j++)
                    {
                        if (connectedEdges [j].occupier != null)
                        {
                            validSet = false;
                        }
                    }
                    if (validSet)
                    {
                        for (int j = 0; j < connectedEdges.Count; j++)
                        {
                            if (connectedEdges [j].occupier == null)
                            {
                                validEdges.Add(connectedEdges [j]);
                            }
                        }
                    }
                }
            }
        }
        else
        {
            for (int i = 0; i < ownedUnits.Count; i++)
            {
                if (typeof(EdgeUnit).IsAssignableFrom(ownedUnits [i].GetType()))
                {
                    EdgeUnit tradeUnit   = (EdgeUnit)(ownedUnits [i]);
                    Edge     relatedEdge = tradeUnit.locationEdge;

                    List <Intersection> connectedIntersections = relatedEdge.getLinkedIntersections();
                    for (int j = 0; j < connectedIntersections.Count; j++)
                    {
                        if (connectedIntersections [j].occupier == null || connectedIntersections [j].occupier.owner == player)
                        {
                            List <Edge> connectedEdges = connectedIntersections [j].getLinkedEdges();

                            for (int k = 0; k < connectedEdges.Count; k++)
                            {
                                if (connectedEdges [k].occupier == null && (roadBuilt == connectedEdges [k].isLandEdge() || connectedEdges [k].isShoreEdge()))
                                {
                                    if (relatedEdge.occupier.isRoad() == roadBuilt || (connectedIntersections [j].occupier != null && connectedIntersections [j].occupier.owner == player))
                                    {
                                        validEdges.Add(connectedEdges [k]);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        if (!roadBuilt)
        {
            List <Edge> pirateEdges = getRobberPirateEdges(1);
            foreach (var edge in pirateEdges)
            {
                if (validEdges.Contains(edge))
                {
                    validEdges.Remove(edge);
                }
            }
        }

        return(validEdges);
    }
Ejemplo n.º 6
0
    IEnumerator buildTradeUnit(EdgeUnit edgeUnit, System.Type unitType)
    {
        waitingForPlayer = true;
        List <Edge>   validEdgesToBuild = getValidEdgesForPlayer(players[currentPlayerTurn], unitType == typeof(Road));
        ResourceTuple costOfUnit        = resourceManager.getCostOfUnit(unitType);

        System.Type newType = unitType;

        if (costOfUnit == null)
        {
            print("costofunit is null, returning.");
            waitingForPlayer = false;
            uiButtons [2].GetComponentInChildren <Text> ().text = "Build Road";
            uiButtons [5].GetComponentInChildren <Text> ().text = "Build Ship";
            currentActiveButton = -1;
            Destroy(edgeUnit.gameObject);
            removeUnitFromGame(edgeUnit);
            yield break;
        }

        if (!setupPhase)
        {
            if (!players [currentPlayerTurn].hasAvailableResources(costOfUnit))                // (Road.ResourceValue);//ResourceCost.getResourceValueOf(Road.ResourceValue);
            {
                print("Insufficient Resources to build this trade unit!");
                waitingForPlayer = false;
                uiButtons [2].GetComponentInChildren <Text> ().text = "Build Road";
                uiButtons [5].GetComponentInChildren <Text> ().text = "Build Ship";
                currentActiveButton = -1;
                Destroy(edgeUnit.gameObject);
                removeUnitFromGame(edgeUnit);
                yield break;
            }
        }

        if (validEdgesToBuild.Count == 0)
        {
            print("No possible location to build this trade unit!");
            Destroy(edgeUnit.gameObject);
            waitingForPlayer = false;
            uiButtons [2].GetComponentInChildren <Text> ().text = "Build Road";
            uiButtons [5].GetComponentInChildren <Text> ().text = "Build Ship";
            currentActiveButton = -1;
            removeUnitFromGame(edgeUnit);
            yield break;
        }

        highlightEdgesWithColor(validEdgesToBuild, true, players [currentPlayerTurn].playerColor);
        //highlightEdges (validEdgesToBuild, true);

        yield return(StartCoroutine(players [currentPlayerTurn].makeEdgeSelection(validEdgesToBuild)));         //, edgeUnit));//new Road(unitID++)));

        print(players [currentPlayerTurn].playerName + " builds a " + unitType.ToString() + " on edge #" + players [currentPlayerTurn].lastEdgeSelection.id);

        if (setupPhase && !(players [currentPlayerTurn].lastEdgeSelection.isLandEdge() || players [currentPlayerTurn].lastEdgeSelection.isShoreEdge()))
        {
            GameObject edgeUnitGameObject = (GameObject)Instantiate(prefabManager.shipPrefab);
            Ship       replacedShip       = edgeUnitGameObject.GetComponent <Ship> ();
            replacedShip.id = edgeUnit.id;
            removeUnitFromGame(edgeUnit);
            edgeUnit = replacedShip;
            unitsInPlay.Add(edgeUnit.id, edgeUnit);
            newType = typeof(Ship);
        }

        players [currentPlayerTurn].lastEdgeSelection.occupier = edgeUnit;
        edgeUnit.locationEdge = players [currentPlayerTurn].lastEdgeSelection;
        players [currentPlayerTurn].addOwnedUnit(edgeUnit, newType);
        edgeUnit.owner = players [currentPlayerTurn];

        edgeUnit.transform.position   = players [currentPlayerTurn].lastEdgeSelection.transform.position;
        edgeUnit.transform.rotation   = players [currentPlayerTurn].lastEdgeSelection.transform.rotation;
        edgeUnit.transform.localScale = players [currentPlayerTurn].lastEdgeSelection.transform.localScale;
        edgeUnit.transform.parent     = players [currentPlayerTurn].lastEdgeSelection.transform;

        edgeUnit.GetComponentInChildren <Renderer> ().material.color = players[currentPlayerTurn].playerColor;
        edgeUnit.gameObject.SetActive(true);

        if (!setupPhase)
        {
            players [currentPlayerTurn].spendResources(costOfUnit);

            uiButtons [2].GetComponentInChildren <Text> ().text = "Build Road";
            uiButtons [5].GetComponentInChildren <Text> ().text = "Build Ship";
        }
        highlightAllEdges(false);
        currentActiveButton = -1;

        waitingForPlayer = false;
    }