IEnumerator tradeXForOne(int resourceToGiveForOne) { waitingForPlayer = true; ResourceTuple currentResources = players [currentPlayerTurn].getCurrentResources(); bool canTrade = false; foreach (var pair in currentResources.resourceTuple) { if (pair.Value >= resourceToGiveForOne) { canTrade = true; } } if (!canTrade) { print(players [currentPlayerTurn].playerName + " can not trade with bank for " + resourceToGiveForOne + ":1! Insufficient resources!"); waitingForPlayer = false; currentActiveButton = -1; yield break; } tradePanel.gameObject.SetActive(true); //TODO: // Set which type is possible to be selected, map slider value to text, etc. (must also do this in update) // Then in done, can check if it works for player's current number of resources. or can check this here too... }
public AssetTuple(ResourceTuple resourceTuple, CommodityTuple commodityTuple, FishTuple fishTuple, int gold) { this.resources = resourceTuple; this.commodities = commodityTuple; this.fishTokens = fishTuple; this.gold = gold; }
public AssetTuple getAssetTupleForTile(GameTile tile, int numCollected) { ResourceTuple resources = getResourceForTile(tile, numCollected); CommodityTuple commodities = getCommodityForTile(tile, numCollected); return(new AssetTuple(resources, commodities)); }
public AssetTuple(int brick, int grain, int lumber, int ore, int wool, int paper, int coin, int cloth, int oneTokens, int twoTokens, int threeTokens, int oldBoot, int gold) { resources = new ResourceTuple(brick, grain, lumber, ore, wool); commodities = new CommodityTuple(paper, coin, cloth); fishTokens = new FishTuple(oneTokens, twoTokens, threeTokens, oldBoot); this.gold = gold; }
public AssetTuple(ResourceTuple resourceTuple, CommodityTuple commodityTuple) { this.resources = resourceTuple; this.commodities = commodityTuple; this.fishTokens = new FishTuple(); this.gold = 0; }
public AssetTuple(int brick, int grain, int lumber, int ore, int wool, int paper, int coin, int cloth) { resources = new ResourceTuple(brick, grain, lumber, ore, wool); commodities = new CommodityTuple(paper, coin, cloth); fishTokens = new FishTuple(0, 0, 0); this.gold = 0; }
public AssetTuple() { resources = new ResourceTuple(); commodities = new CommodityTuple(); fishTokens = new FishTuple(); this.gold = 0; }
ResourceTuple getResourceForTile(GameTile tile, int numCollected) { ResourceTuple resourceCollected = new ResourceTuple(); ResourceType typeOfResource = GameAsset.getResourceOfHex(tile.tileType); if (typeOfResource != ResourceType.Null) { resourceCollected.resourceTuple [typeOfResource] = numCollected; } return(resourceCollected); }
IEnumerator buildIntersectionUnit2(IntersectionUnit intersectionUnit, System.Type unitType) { waitingForPlayer = true; List <Intersection> validIntersectionsToBuild = getValidIntersectionsForPlayer(players[currentPlayerTurn]); ResourceTuple costOfUnit = resourceManager.getCostOfUnit(unitType); if (costOfUnit == null) { print("Cost of unit 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 (validIntersectionsToBuild.Count == 0) { print("No possible location to build a settlement!"); Destroy(intersectionUnit); waitingForPlayer = false; yield break; } highlightIntersectionsWithColor(validIntersectionsToBuild, true, players [currentPlayerTurn].playerColor); intersectionUnit.id = unitID++; intersectionUnit.gameObject.SetActive(false); yield return(StartCoroutine(players [currentPlayerTurn].makeIntersectionSelection(validIntersectionsToBuild))); //, intersectionUnit)); intersectionUnit.GetComponentInChildren <Renderer> ().material.color = players[currentPlayerTurn].playerColor; intersectionUnit.gameObject.SetActive(true); if (!setupPhase) { players [currentPlayerTurn].spendResources(costOfUnit); uiButtons [1].GetComponentInChildren <Text> ().text = "Build Settlement"; } highlightAllIntersections(false); waitingForPlayer = false; }
public void spendResources(ResourceTuple resourceToSpend) { List <ResourceType> resourceKeys = new List <ResourceType>(assets.resources.resourceTuple.Keys); for (int i = 0; i < resourceKeys.Count; i++) { if (assets.resources.resourceTuple [resourceKeys [i]] >= resourceToSpend.resourceTuple [resourceKeys [i]]) { print("Subtracted " + resourceToSpend.resourceTuple [resourceKeys [i]].ToString() + " " + resourceKeys [i].ToString() + " from " + this.playerName); assets.resources.resourceTuple [resourceKeys [i]] -= resourceToSpend.resourceTuple [resourceKeys [i]]; } } }
public void receiveResources(ResourceTuple resourceToAdd) { List <ResourceType> resourceKeys = new List <ResourceType>(assets.resources.resourceTuple.Keys); for (int i = 0; i < resourceKeys.Count; i++) { if (resourceToAdd.resourceTuple [resourceKeys [i]] >= 0) { print("Added " + resourceToAdd.resourceTuple [resourceKeys [i]].ToString() + " " + resourceKeys [i].ToString() + " to " + this.playerName); assets.resources.resourceTuple [resourceKeys [i]] += resourceToAdd.resourceTuple [resourceKeys [i]]; } } }
public bool hasAvailableResources(ResourceTuple resourcesNeeded) { List <ResourceType> resourceKeys = new List <ResourceType>(assets.resources.resourceTuple.Keys); for (int i = 0; i < resourceKeys.Count; i++) { if (assets.resources.resourceTuple [resourceKeys [i]] < resourcesNeeded.resourceTuple [resourceKeys [i]]) { return(false); } } return(true); }
void giveResourcesToPlayer(Player player, ResourceTuple resourceObtained) { player.receiveResources(resourceObtained); }
IEnumerator buildIntersectionUnit(IntersectionUnit intersectionUnit, System.Type unitType) { waitingForPlayer = true; List <Intersection> validIntersectionsToBuild = getValidIntersectionsForPlayer(players[currentPlayerTurn]); ResourceTuple costOfUnit = resourceManager.getCostOfUnit(unitType); if (!setupPhase && costOfUnit == null) { print("costofunit is null, returning."); Destroy(intersectionUnit.gameObject); waitingForPlayer = false; uiButtons [1].GetComponentInChildren <Text> ().text = "Build Settlement"; currentActiveButton = -1; removeUnitFromGame(intersectionUnit); yield break; } if (!setupPhase) { if (!players [currentPlayerTurn].hasAvailableResources(costOfUnit)) // (Road.ResourceValue);//ResourceCost.getResourceValueOf(Road.ResourceValue); { print("Insufficient Resources to build this intersection unit!"); Destroy(intersectionUnit.gameObject); waitingForPlayer = false; uiButtons [1].GetComponentInChildren <Text> ().text = "Build Settlement"; currentActiveButton = -1; removeUnitFromGame(intersectionUnit); yield break; } } if (validIntersectionsToBuild.Count == 0) { print("No possible location to build this intersection unit!"); Destroy(intersectionUnit.gameObject); waitingForPlayer = false; uiButtons [1].GetComponentInChildren <Text> ().text = "Build Settlement"; currentActiveButton = -1; removeUnitFromGame(intersectionUnit); yield break; } highlightIntersectionsWithColor(validIntersectionsToBuild, true, players [currentPlayerTurn].playerColor); yield return(StartCoroutine(players [currentPlayerTurn].makeIntersectionSelection(validIntersectionsToBuild))); //, intersectionUnit)); print(players [currentPlayerTurn].playerName + " builds a " + unitType.ToString() + " on intersection #" + players [currentPlayerTurn].lastIntersectionSelection.id); players [currentPlayerTurn].lastIntersectionSelection.occupier = intersectionUnit; intersectionUnit.locationIntersection = players [currentPlayerTurn].lastIntersectionSelection; players [currentPlayerTurn].addOwnedUnit(intersectionUnit, unitType); intersectionUnit.owner = players [currentPlayerTurn]; intersectionUnit.transform.position = players [currentPlayerTurn].lastIntersectionSelection.transform.position; intersectionUnit.transform.parent = players [currentPlayerTurn].lastIntersectionSelection.transform; intersectionUnit.transform.localScale = intersectionUnit.transform.localScale * GameObject.FindGameObjectWithTag("Board").GetComponent <GameBoard> ().hexRadius; intersectionUnit.GetComponentInChildren <Renderer> ().material.color = players[currentPlayerTurn].playerColor; intersectionUnit.gameObject.SetActive(true); //unitsInPlay.Add (intersectionUnit.id, intersectionUnit); if (!setupPhase) { players [currentPlayerTurn].spendResources(costOfUnit); uiButtons [1].GetComponentInChildren <Text> ().text = "Build Settlement"; } highlightAllIntersections(false); currentActiveButton = -1; waitingForPlayer = false; }
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; }
IEnumerator upgradeSettlement() { waitingForPlayer = true; List <Settlement> ownedSettlements = players [currentPlayerTurn].getOwnedUnitsOfType(typeof(Settlement)).Cast <Settlement> ().ToList(); //List<Unit> ownedSettlements = players [currentPlayerTurn].getOwnedUnitsOfType (typeof(Settlement)); ResourceTuple costOfUnit = resourceManager.getCostOfUnit(typeof(City)); if (ownedSettlements.Count == 0) { print("No settlements owned!"); uiButtons [4].GetComponentInChildren <Text> ().text = "Upgrade Settlement"; currentActiveButton = -1; waitingForPlayer = false; yield break; } if (!players [currentPlayerTurn].hasAvailableResources(costOfUnit)) // (Road.ResourceValue);//ResourceCost.getResourceValueOf(Road.ResourceValue); { print("Insufficient Resources to upgrade a settlement to a city!"); uiButtons [4].GetComponentInChildren <Text> ().text = "Upgrade Settlement"; currentActiveButton = -1; waitingForPlayer = false; yield break; } highlightUnitsWithColor(ownedSettlements.Cast <Unit> ().ToList(), true, Color.black); yield return(StartCoroutine(players [currentPlayerTurn].makeUnitSelection(ownedSettlements.Cast <Unit> ().ToList()))); //new Road(unitID++))); Settlement settlementToUpgrade = (Settlement)unitsInPlay [players [currentPlayerTurn].lastUnitSelection.id]; //print ("Selected settlement has id#: " + selection.id + " and is owned by " + selection); print("Found settlement with id#: " + settlementToUpgrade.id + ". Residing on intersection id#: " + settlementToUpgrade.locationIntersection.id); GameObject cityGameObject = (GameObject)Instantiate(prefabManager.cityPrefab); City newCity = cityGameObject.GetComponent <City> (); newCity.id = settlementToUpgrade.id; unitsInPlay [settlementToUpgrade.id] = newCity; settlementToUpgrade.locationIntersection.occupier = newCity; newCity.locationIntersection = settlementToUpgrade.locationIntersection; players [currentPlayerTurn].removeOwnedUnit(settlementToUpgrade, typeof(Settlement)); players [currentPlayerTurn].addOwnedUnit(newCity, typeof(City)); newCity.owner = players [currentPlayerTurn]; newCity.transform.position = settlementToUpgrade.transform.position; newCity.transform.parent = settlementToUpgrade.transform.parent; newCity.transform.localScale = settlementToUpgrade.transform.localScale; newCity.GetComponentInChildren <Renderer> ().material.color = players[currentPlayerTurn].playerColor; Destroy(settlementToUpgrade.gameObject); players [currentPlayerTurn].spendResources(costOfUnit); highlightUnitsWithColor(ownedSettlements.Cast <Unit>().ToList(), true, players[currentPlayerTurn].playerColor); uiButtons [4].GetComponentInChildren <Text> ().text = "Upgrade Settlement"; currentActiveButton = -1; waitingForPlayer = false; }