public AssetTuple getRandomSufficientAsset(int number) { AssetTuple randomAsset = new AssetTuple(); if (Random.Range(0.0f, 1.0f) <= 0.5f) { int randomResourceIndex; do { randomResourceIndex = Random.Range(0, Enum.GetNames(typeof(ResourceType)).Length - 1); randomAsset = GameAsset.getAssetOfIndex(randomResourceIndex, number); } while(!hasAvailableAssets(randomAsset)); } else { int randomCommodityIndex; do { randomCommodityIndex = Random.Range(0, Enum.GetNames(typeof(CommodityType)).Length - 1) + 5; randomAsset = GameAsset.getAssetOfIndex(randomCommodityIndex, number); } while(!hasAvailableAssets(randomAsset)); } return(randomAsset); }
/*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()); } }
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(); } }