public void sendResponseCounter()
    {
        //fill 2 new tuples with values from slider for sending
        AssetTuple getAsset  = new AssetTuple();
        AssetTuple giveAsset = new AssetTuple();

        for (int i = 0; i < getAssetSliders.Length; i++)
        {
            getAsset.SetValueAtIndex(i, (int)getAssetSliders [i].value);
            Debug.Log("GetAssetSliders[" + i + "] = " + getAssetSliders [i].value);
        }
        for (int i = 0; i < giveAssetSliders.Length; i++)
        {
            giveAsset.SetValueAtIndex(i, (int)giveAssetSliders [i].value);
            Debug.Log("GiveAssetSliders[" + i + "] = " + giveAssetSliders [i].value);
        }
        if (CatanManager.instance.players [PhotonNetwork.player.ID - 1].hasAvailableAssets(giveAsset))
        {
            Debug.Log("Calling OnTrade counter now");
            //trade call for player responding to trade
            EventTransferManager.instance.OnTradeWithBank(CatanManager.instance.currentPlayerTurn, true, getAsset);
            EventTransferManager.instance.OnTradeWithBank(CatanManager.instance.currentPlayerTurn, false, giveAsset);

            //trade call for sender
            EventTransferManager.instance.OnTradeWithBank(playerSelection, false, getAsset);
            EventTransferManager.instance.OnTradeWithBank(playerSelection, true, giveAsset);
            //cleanup operations
            EventTransferManager.instance.OnTradeEnd(playerSelection, true);
            EventTransferManager.instance.OnOperationFailure();
        }
    }
    public void sendTradeCounter()
    {
        //user cannot do anything after trade is sent
        confirm.onClick.RemoveAllListeners();
        cancel.onClick.RemoveAllListeners();

        confirmtext.gameObject.SetActive(false);
        canceltext.gameObject.SetActive(false);

        //waiting for response visible
        waiting.gameObject.SetActive(true);

        //convert sliders to tuples
        AssetTuple getAsset = new AssetTuple();

        for (int i = 0; i < getAssetSliders.Length; i++)
        {
            getAsset.SetValueAtIndex(i, (int)getAssetSliders [i].value);
        }
        AssetTuple giveAsset = new AssetTuple();

        for (int i = 0; i < giveAssetSliders.Length; i++)
        {
            giveAsset.SetValueAtIndex(i, (int)giveAssetSliders [i].value);
        }

        //rpc for trade sending, redundant check for assets
        if (CatanManager.instance.players [PhotonNetwork.player.ID - 1].hasAvailableAssets(giveAsset))
        {
            waiting.text = "Waiting For Response...";
            EventTransferManager.instance.OnTradeOfferCounter(PhotonNetwork.player.ID - 1, CatanManager.instance.currentPlayerTurn, giveAsset, getAsset);
        }
    }
    private void playIrrigation()
    {
        CatanManager clientCatanManager = GameObject.FindGameObjectWithTag("CatanManager").GetComponent <CatanManager> ();
        int          count     = clientCatanManager.boardManager.getAdjacentTilesOfType(PhotonNetwork.player.ID - 1, TileType.Fields).Count;
        AssetTuple   tempasset = new AssetTuple();

        tempasset.SetValueAtIndex(1, 2 * count);
        if (clientCatanManager.players [PhotonNetwork.player.ID - 1].canPlayIrrigation)
        {
            clientCatanManager.players [PhotonNetwork.player.ID - 1].canPlayIrrigation = false;
            EventTransferManager.instance.OnTradeWithBank(PhotonNetwork.player.ID - 1, true, tempasset);
        }
        returnCardToStack(ProgressCardColor.Green, ProgressCardType.Irrigation);
    }
    public void sendResponse()
    {
        //fill 2 new tuples with values from slider for sending
        AssetTuple getAsset  = new AssetTuple();
        AssetTuple giveAsset = new AssetTuple();

        for (int i = 0; i < getAssetSliders.Length; i++)
        {
            getAsset.SetValueAtIndex(i, (int)getAssetSliders [i].value);
            Debug.Log("GetAssetSliders[" + i + "] = " + getAssetSliders [i].value);
        }
        for (int i = 0; i < giveAssetSliders.Length; i++)
        {
            giveAsset.SetValueAtIndex(i, (int)giveAssetSliders [i].value);
            Debug.Log("GiveAssetSliders[" + i + "] = " + giveAssetSliders [i].value);
        }
        if (CatanManager.instance.players [PhotonNetwork.player.ID - 1].hasAvailableAssets(giveAsset))
        {
            Debug.Log("Calling OnTrades now");

            //incase unity is moody again and tries reverse trades ??????

            /*if(PhotonNetwork.player.ID - 1==CatanManager.instance.currentPlayerTurn+1){
             *      //trade call for player responding to trade
             *      EventTransferManager.instance.OnTradeWithBank (PhotonNetwork.player.ID - 1, false, getAsset);
             *      EventTransferManager.instance.OnTradeWithBank (PhotonNetwork.player.ID - 1, true, giveAsset);
             *
             *      //trade call for sender
             *      EventTransferManager.instance.OnTradeWithBank (CatanManager.instance.currentPlayerTurn, true, getAsset);
             *      EventTransferManager.instance.OnTradeWithBank (CatanManager.instance.currentPlayerTurn, false, giveAsset);
             *
             *      //cleanup operations
             *      EventTransferManager.instance.OnTradeEnd (CatanManager.instance.currentPlayerTurn,true);
             *      EventTransferManager.instance.OnOperationFailure ();
             * }else{*/
            //trade call for player responding to trade
            EventTransferManager.instance.OnTradeWithBank(PhotonNetwork.player.ID - 1, true, getAsset);
            EventTransferManager.instance.OnTradeWithBank(PhotonNetwork.player.ID - 1, false, giveAsset);

            //trade call for sender
            EventTransferManager.instance.OnTradeWithBank(CatanManager.instance.currentPlayerTurn, false, getAsset);
            EventTransferManager.instance.OnTradeWithBank(CatanManager.instance.currentPlayerTurn, true, giveAsset);

            //cleanup operations
            EventTransferManager.instance.OnTradeEnd(CatanManager.instance.currentPlayerTurn, true);
            EventTransferManager.instance.OnOperationFailure();
            //	}
        }
    }
    private IEnumerator playMedicine()
    {
        CatanManager clientCatanManager = GameObject.FindGameObjectWithTag("CatanManager").GetComponent <CatanManager> ();
        AssetTuple   tempasset          = new AssetTuple();

        //set the cost tuple = 2 ore and 1 grain
        tempasset.SetValueAtIndex(1, 1);
        tempasset.SetValueAtIndex(3, 2);
        //check if player has the assets required
        if (clientCatanManager.players [PhotonNetwork.player.ID - 1].hasAvailableAssets(tempasset) && clientCatanManager.players [PhotonNetwork.player.ID - 1].getOwnedUnitsOfType(UnitType.Settlement).Count > 0)
        {
            tempasset.SetValueAtIndex(1, 1);
            tempasset.SetValueAtIndex(3, 1);
            yield return(StartCoroutine(EventTransferManager.instance.ClientUpgradeSettlement(PhotonNetwork.player.ID - 1)));

            EventTransferManager.instance.OnTradeWithBank(PhotonNetwork.player.ID - 1, true, tempasset);
            returnCardToStack(ProgressCardColor.Green, ProgressCardType.Medicine);
        }
        else
        {
            clientCatanManager.uiManager.notificationpanel.gameObject.SetActive(true);
            clientCatanManager.uiManager.notificationtext.text = "Insufficient resources to play this card or no settlements to upgrade";
        }
    }
    private void playMining()
    {
        int          count = 0;
        CatanManager clientCatanManager = GameObject.FindGameObjectWithTag("CatanManager").GetComponent <CatanManager> ();

        count = clientCatanManager.boardManager.getAdjacentTilesOfType(PhotonNetwork.player.ID - 1, TileType.Mountains).Count;
        AssetTuple tempasset = new AssetTuple();

        Debug.Log("Adjacent tiles: " + count);
        tempasset.SetValueAtIndex(3, 2 * count);
        if (clientCatanManager.players [PhotonNetwork.player.ID - 1].canPlayMining)
        {
            clientCatanManager.players [PhotonNetwork.player.ID - 1].canPlayMining = false;
            EventTransferManager.instance.OnTradeWithBank(PhotonNetwork.player.ID - 1, true, tempasset);
        }
        returnCardToStack(ProgressCardColor.Green, ProgressCardType.Mining);
    }
Esempio n. 7
0
    public void submitSelection()
    {
        if (leftDiscards == 0)
        {
            selectionMade = true;

            AssetTuple assetsToDiscard = new AssetTuple(0, 0, 0, 0, 0, 0, 0, 0);
            for (int i = 0; i < assetSliders.Length; i++)
            {
                assetsToDiscard.SetValueAtIndex(i, (int)assetSliders [i].value);
            }

            discardTuple = assetsToDiscard;
        }
        else
        {
            Debug.Log("Need to select the correct amount!");
        }
    }
    public void upgradeScience()
    {
        CityImprovementType science = CityImprovementType.Science;

        if (CatanManager.instance.currentPlayerTurn == PhotonNetwork.player.ID - 1 && CatanManager.instance.players [CatanManager.instance.currentPlayerTurn].canUpgrade(science))
        {
            AssetTuple upgradeCost = CatanManager.instance.players [CatanManager.instance.currentPlayerTurn].cityImprovements.nextImprovementCost(science);
            if (CatanManager.instance.players [CatanManager.instance.currentPlayerTurn].playedCrane)
            {
                upgradeCost.SetValueAtIndex(5, upgradeCost.GetValueAtIndex(5) - 1);
                CatanManager.instance.players [CatanManager.instance.currentPlayerTurn].playedCrane = false;
            }

            EventTransferManager.instance.OnTradeWithBank(CatanManager.instance.currentPlayerTurn, false, upgradeCost);
            EventTransferManager.instance.OnUpgradeCity(CatanManager.instance.currentPlayerTurn, (int)science);

            int scienceLevel  = CatanManager.instance.players [CatanManager.instance.currentPlayerTurn].cityImprovements.cityImprovements [CityImprovementType.Science];
            int politicsLevel = CatanManager.instance.players [CatanManager.instance.currentPlayerTurn].cityImprovements.cityImprovements [CityImprovementType.Politics];
            int tradeLevel    = CatanManager.instance.players [CatanManager.instance.currentPlayerTurn].cityImprovements.cityImprovements [CityImprovementType.Trade];

            openPanel(tradeLevel, politicsLevel, scienceLevel);
        }
    }
Esempio n. 9
0
    IEnumerator spendFishTokenResults()
    {
        int        numTokensNeeded = 0;
        bool       success         = false;
        AssetTuple assetsToRemove  = new AssetTuple();

        switch (rewardSelection)
        {
        case 0:
            //move robber
            numTokensNeeded = 2;

            Robber robber = GameObject.FindObjectOfType <Robber> ();
            Pirate pirate = GameObject.FindObjectOfType <Pirate> ();
            if (robber != null && pirate != null)
            {
                CatanManager.instance.uiManager.robberPiratePanel.gameObject.SetActive(true);
                bool selected = false;

                while (!selected)
                {
                    if (!CatanManager.instance.uiManager.robberPiratePanel.selectionMade)
                    {
                        yield return(StartCoroutine(CatanManager.instance.uiManager.robberPiratePanel.waitUntilButtonDown()));
                    }

                    if (CatanManager.instance.uiManager.robberPiratePanel.selectionMade)
                    {
                        selected = true;
                    }
                }

                CatanManager.instance.uiManager.robberPiratePanel.gameObject.SetActive(false);
                CatanManager.instance.uiManager.robberPiratePanel.selectionMade = false;

                StartCoroutine(CatanManager.instance.moveGamePieceForCurrentPlayer(CatanManager.instance.uiManager.robberPiratePanel.selection, true, false));
            }
            else if (robber != null)
            {
                StartCoroutine(CatanManager.instance.moveGamePieceForCurrentPlayer(0, true, false));
            }
            else if (pirate != null)
            {
                StartCoroutine(CatanManager.instance.moveGamePieceForCurrentPlayer(1, true, false));
            }
            for (int i = 0; i < FishTokens.Length; i++)
            {
                Debug.Log("Set index " + (i + 8) + " of assetToRemove to = " + (int)FishTokens [i].value);
                assetsToRemove.SetValueAtIndex(i + 8, (int)FishTokens [i].value);
            }
            success = true;
            break;

        case 1:
            //steal random resource
            numTokensNeeded = 3;

            List <Player> stealableOpponents = new List <Player> ();
            for (int i = 0; i < PhotonNetwork.playerList.Length; i++)
            {
                stealableOpponents.Add(CatanManager.instance.players[i]);
            }
            stealableOpponents.Remove(CatanManager.instance.players [CatanManager.instance.currentPlayerTurn]);

            if (stealableOpponents.Count != 0)
            {
                yield return(StartCoroutine(CatanManager.instance.stealRandomResource(stealableOpponents)));

                this.gameObject.SetActive(false);

                for (int i = 0; i < FishTokens.Length; i++)
                {
                    Debug.Log("Set index " + (i + 8) + " of assetToRemove to = " + (int)FishTokens [i].value);
                    assetsToRemove.SetValueAtIndex(i + 8, (int)FishTokens [i].value);
                }
                success = true;
            }
            break;

        case 2:
            //take resource of choice
            numTokensNeeded = 4;

            CatanManager.instance.uiManager.fishResourceSelection();
            bool selectionMade = false;
            this.transform.localScale = Vector3.zero;
            CatanManager.instance.uiManager.fishresourcepanel.gameObject.SetActive(true);

            while (!selectionMade)
            {
                if (!CatanManager.instance.uiManager.fishresourcepanel.selectionMade)
                {
                    yield return(StartCoroutine(CatanManager.instance.uiManager.fishresourcepanel.waitUntilButtonDown()));
                }
                if (CatanManager.instance.uiManager.fishresourcepanel.selectionMade)
                {
                    selectionMade = true;
                }
            }

            CatanManager.instance.uiManager.fishresourcepanel.gameObject.SetActive(false);
            CatanManager.instance.uiManager.fishresourcepanel.selectionMade = false;
            this.transform.localScale = scale;
            this.gameObject.SetActive(false);

            AssetTuple assetsToGain = GameAsset.getAssetOfIndex(CatanManager.instance.uiManager.fishresourcepanel.getSelection(), 1);
            EventTransferManager.instance.OnTradeWithBank(CatanManager.instance.currentPlayerTurn, true, assetsToGain);

            for (int i = 0; i < FishTokens.Length; i++)
            {
                Debug.Log("Set index " + (i + 8) + " of assetToRemove to = " + (int)FishTokens [i].value);
                assetsToRemove.SetValueAtIndex(i + 8, (int)FishTokens [i].value);
            }
            success = true;
            break;

        case 3:
            //build road
            numTokensNeeded = 5;

            int numRoadsInitial = CatanManager.instance.players [CatanManager.instance.currentPlayerTurn].getOwnedUnitsOfType(UnitType.Road).Count;
            this.transform.localScale = Vector3.zero;

            yield return(StartCoroutine(CatanManager.instance.unitManager.buildRoad(false)));

            int numRoadsFinal = CatanManager.instance.players [CatanManager.instance.currentPlayerTurn].getOwnedUnitsOfType(UnitType.Road).Count;

            this.transform.localScale = scale;
            this.gameObject.SetActive(false);

            if (numRoadsInitial + 1 != numRoadsFinal)
            {
                this.gameObject.SetActive(true);
            }
            else
            {
                for (int i = 0; i < FishTokens.Length; i++)
                {
                    Debug.Log("Set index " + (i + 8) + " of assetToRemove to = " + (int)FishTokens [i].value);
                    assetsToRemove.SetValueAtIndex(i + 8, (int)FishTokens [i].value);
                }
                success = true;
            }
            break;

        case 4:
            numTokensNeeded = 7;
            CatanManager.instance.uiManager.cardSelectPanel.gameObject.SetActive(true);
            for (int i = 0; i < FishTokens.Length; i++)
            {
                Debug.Log("Set index " + (i + 8) + " of assetToRemove to = " + (int)FishTokens [i].value);
                assetsToRemove.SetValueAtIndex(i + 8, (int)FishTokens [i].value);
            }
            success = true;
            break;
        }

        if (assetsToRemove.fishTokens.numTotalTokens() == 0)
        {
            success = false;
        }

        if (success)
        {
            int numTokens    = assetsToRemove.fishTokens.numTotalTokens();
            int indexRemoved = 0;

            while (numTokens >= numTokensNeeded)
            {
                int nextLargestIndex = assetsToRemove.fishTokens.nextAvailableLargestIndex();

                if (assetsToRemove.fishTokens.fishTuple.ContainsKey((FishTokenType)nextLargestIndex))
                {
                    assetsToRemove.fishTokens.fishTuple [(FishTokenType)nextLargestIndex]--;
                    indexRemoved = nextLargestIndex;
                }
                else
                {
                    break;
                }

                numTokens = assetsToRemove.fishTokens.numTotalTokens();
            }

            assetsToRemove.fishTokens.fishTuple [(FishTokenType)indexRemoved]++;

            //CatanManager.instance.players [CatanManager.instance.currentPlayerTurn].spendAssets (assetsToRemove);
            EventTransferManager.instance.OnTradeWithBank(CatanManager.instance.currentPlayerTurn, false, assetsToRemove);
            rewardSelection = -1;
            selectionGlow.gameObject.SetActive(false);
            this.gameObject.SetActive(false);
            StopAllCoroutines();
            EventTransferManager.instance.OnOperationFailure();
        }
    }