示例#1
0
    /*public void tradeGoldDone(){
     *      Debug.Log ("trade ini");
     *      Debug.Log ("gold cnt: " + CatanManager.instance.players [CatanManager.instance.currentPlayerTurn].getGoldCoinsCnt ());
     *      AssetTuple assetsToReceive = GameAsset.getAssetOfIndex (tradePanel.getGoldChoiceInt(), 1);
     *      if (CatanManager.instance.players [CatanManager.instance.currentPlayerTurn].getGoldCoinsCnt() >= 2) {
     *              EventTransferManager.instance.GoldTrade (PhotonNetwork.player.ID - 1);
     *              EventTransferManager.instance.OnTradeWithBank(CatanManager.instance.currentPlayerTurn, true, assetsToReceive);
     *              tradePanel.hideErrorText ();
     *              tradePanel.gameObject.SetActive (false);
     *              EventTransferManager.instance.OnOperationFailure ();
     *      }
     * }*/
    public void tradeDone()
    {
        int tradeRatio = CatanManager.instance.players [CatanManager.instance.currentPlayerTurn].getMinimumTradeValue(tradePanel.getTradeChoiceInt());

        if (tradePanel.getTradeChoiceInt() >= 5 && CatanManager.instance.players [CatanManager.instance.currentPlayerTurn].unlockedTradingHouse())
        {
            tradeRatio = 2;
        }
        if (CatanManager.instance.players [PhotonNetwork.player.ID - 1].playedMerchantFleet && tradePanel.getTradeChoiceInt() == CatanManager.instance.players [PhotonNetwork.player.ID - 1].merchantFleetSelection)
        {
            tradeRatio = 2;
        }
        if (CatanManager.instance.merchantController == PhotonNetwork.player.ID - 1)
        {
            ResourceType typeOfResource = GameAsset.getResourceOfHex(GameObject.FindGameObjectWithTag("Merchant").GetComponent <Merchant> ().occupyingTile.tileType);
            if ((int)typeOfResource == tradePanel.getTradeChoiceInt())
            {
                tradeRatio = 2;
            }
        }
        AssetTuple assetsToSpend   = GameAsset.getAssetOfIndex(tradePanel.getTradeChoiceInt(), tradeRatio);
        AssetTuple assetsToReceive = GameAsset.getAssetOfIndex(tradePanel.getReceiveChoiceInt(), 1);

        if (CatanManager.instance.players [CatanManager.instance.currentPlayerTurn].hasAvailableAssets(assetsToSpend))
        {
            //CatanManager.instance.players [CatanManager.instance.currentPlayerTurn].spendAssets (assetsToSpend);
            //CatanManager.instance.players [CatanManager.instance.currentPlayerTurn].receiveAssets (assetsToReceive);
            EventTransferManager.instance.OnTradeWithBank(CatanManager.instance.currentPlayerTurn, false, assetsToSpend);
            EventTransferManager.instance.OnTradeWithBank(CatanManager.instance.currentPlayerTurn, true, assetsToReceive);

            //print (players [currentPlayerTurn].playerName + " gives 4 " + tradePanel.getTradeChoiceInt ().ToString () + " to the bank and receives 1 " + assetsToReceive.ToString());
            tradePanel.hideErrorText();
            tradePanel.gameObject.SetActive(false);

            EventTransferManager.instance.OnOperationFailure();
        }
        else
        {
            print("Insufficient resources! Please try again...");
            tradePanel.showNotEnoughError(tradePanel.getTradeChoiceInt());
        }
    }
    /*void tradeDone() {
     *      bool successful = false;
     *      //int choice = tradePanel.getTradeChoiceInt ();
     *      ResourceTuple resourcesToGiveToBank = new ResourceTuple ();
     *      CommodityTuple commoditiesToGiveToBank = new CommodityTuple ();
     *
     *      Tuple<ResourceType, CommodityType> spending = GameAsset.getProductionAssetsOfIndex (tradePanel.getTradeChoiceInt ());
     *      Tuple<ResourceType, CommodityType> receiving = GameAsset.getProductionAssetsOfIndex (tradePanel.getReceiveChoiceInt ());
     *
     *      if (tradePanel.getTradeChoiceInt() < 5) {
     *              resourcesToGiveToBank.addResourceWithType (spending.first, 4);
     *      } else {
     *              commoditiesToGiveToBank.addCommodityWithType(spending.second, 4);
     *      }
     *
     *      if (players [currentPlayerTurn].hasAvailableResources (resourcesToGiveToBank) && players [currentPlayerTurn].hasAvailableCommodities (commoditiesToGiveToBank)) {
     *              players [currentPlayerTurn].spendResources (resourcesToGiveToBank);
     *              players [currentPlayerTurn].spendCommodities (commoditiesToGiveToBank);
     *
     *              ResourceTuple resourceToReceive = new ResourceTuple ();
     *              CommodityTuple commodityToReceive = new CommodityTuple ();
     *
     *              if (tradePanel.getReceiveChoiceInt () < 5) {
     *                      resourceToReceive.addResourceWithType (receiving.first, 1);
     *              } else {
     *                      commodityToReceive.addCommodityWithType (receiving.second, 1);
     *              }
     *
     *              players [currentPlayerTurn].receiveResources (resourceToReceive);
     *              players [currentPlayerTurn].receiveCommodities (commodityToReceive);
     *
     *              //print (players [currentPlayerTurn].playerName + " gives 4 " + tradePanel.getTradeChoice ().ToString () + " to the bank and receives 1 " + tradePanel.getReceiveChoice ());
     *              print (players [currentPlayerTurn].playerName + " gives 4 " + spending.ToString () + " to the bank and receives 1 " + receiving.ToString());
     *
     *              currentActiveButton = -1;
     *              tradePanel.hideErrorText ();
     *              tradePanel.gameObject.SetActive (false);
     *              waitingForPlayer = false;
     *      } else {
     *              print ("Insufficient resources! Please try again...");
     *              tradePanel.showNotEnoughError (tradePanel.getTradeChoiceInt ());
     *      }
     * }*/

    void tradeDone()
    {
        AssetTuple assetsToSpend   = GameAsset.getAssetOfIndex(tradePanel.getTradeChoiceInt(), 4);
        AssetTuple assetsToReceive = GameAsset.getAssetOfIndex(tradePanel.getReceiveChoiceInt(), 1);

        if (players [currentPlayerTurn].hasAvailableAssets(assetsToSpend))
        {
            players [currentPlayerTurn].spendAssets(assetsToSpend);
            players [currentPlayerTurn].receiveAssets(assetsToReceive);
            //print (players [currentPlayerTurn].playerName + " gives 4 " + tradePanel.getTradeChoiceInt ().ToString () + " to the bank and receives 1 " + assetsToReceive.ToString());

            currentActiveButton = -1;
            tradePanel.hideErrorText();
            tradePanel.gameObject.SetActive(false);
            waitingForPlayer = false;
        }
        else
        {
            print("Insufficient resources! Please try again...");
            tradePanel.showNotEnoughError(tradePanel.getTradeChoiceInt());
        }
    }