Ejemplo n.º 1
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.º 2
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;
    }