public void DoMaterialConversion(SourceKind from, SourceKind to, Player p, int fromAmount, int toAmount) { if (from == SourceKind.Null || to == SourceKind.Null) return; int rate = p.GetConversionRate(from); if (!this.IsMaterialAvailable(from,rate)) { return; } //remove material from player SourceAll cost = CreateSourceAllCost(from, -fromAmount); p.AddSources(cost,TransactionState.TransactionStart); //add new material SourceAll get = CreateSourceAllCost(to, toAmount); p.AddSources(get, TransactionState.TransactionEnd); }
internal void PrepareCampaignMap() { if (mapSource == null) // neni kampan return; XmlDocument xDoc = new XmlDocument(); xDoc.Load("Content/Maps/" + mapSource); XmlNodeList playersNodes = xDoc.GetElementsByTagName("players")[0].ChildNodes; for(int loop1 = 0; loop1 < playersNodes.Count; loop1++) { XmlNode playerNode = playersNodes[loop1]; activePlayer = players[loop1]; for (int loop2 = 0; loop2 < playerNode.ChildNodes.Count; loop2++) { XmlNode info = playerNode.ChildNodes[loop2]; switch (info.Name) { case "towns": foreach (XmlNode townNode in info.ChildNodes) { int ID = Convert.ToInt16(townNode.Attributes[0].Value); map.GetMapController().BuildTown(ID); foreach (XmlNode buildingNode in townNode.ChildNodes) { int pos = Convert.ToInt16(buildingNode.InnerText); switch (buildingNode.Name) { case "source-building" : map.GetTownByID(ID).BuildSourceBuilding((byte) pos); break; case "fort": map.GetTownByID(ID).BuildFort((byte)pos); break; case "market": map.GetTownByID(ID).BuildMarket((byte)pos); break; case "monastery": map.GetTownByID(ID).BuildMonastery((byte)pos); break; } } } break; case "roads": foreach (XmlNode roadID in info.ChildNodes) { int ID = Convert.ToInt16(roadID.InnerText); map.GetMapController().BuildRoad(ID); } break; case "source": //activePlayer.AddSources(new SourceAll(0), TransactionState.TransactionStart); foreach (XmlNode kind in info.ChildNodes) { int amount = Convert.ToInt16(kind.InnerText); switch (kind.Name) { case "wood" : activePlayer.AddSources(new SourceAll(0, 0, 0, amount, 0), TransactionState.TransactionMiddle); break; case "ore": activePlayer.AddSources(new SourceAll(0, 0, 0, 0, amount), TransactionState.TransactionMiddle); break; case "corn": activePlayer.AddSources(new SourceAll(amount, 0, 0, 0, 0), TransactionState.TransactionMiddle); break; case "stone": activePlayer.AddSources(new SourceAll(0, 0, amount, 0, 0), TransactionState.TransactionMiddle); break; case "meat": activePlayer.AddSources(new SourceAll(0, amount, 0, 0, 0), TransactionState.TransactionMiddle); break; } } //activePlayer.AddSources(new SourceAll(0), TransactionState.TransactionEnd); break; } } } }
public void CollectSources(Player player) { SourceAll sourceNow = new SourceAll(0); SourceAll sourceNormal = new SourceAll(0); int amountNow; int amountNormal; for(int loop1 = 0; loop1 < 3; loop1++) { if (hexaNeighbour[loop1] != null && buildingKind[loop1] == BuildingKind.SourceBuilding) { SourceBuildingModel tempBuilding = (SourceBuildingModel) building[loop1]; float multiply = (tempBuilding.GetUpgrade() == UpgradeKind.SecondUpgrade) ? 2.0f : (tempBuilding.GetUpgrade() == UpgradeKind.FirstUpgrade) ? 1.5f : 1.0f; amountNormal = (int) (hexaNeighbour[loop1].GetStartSource() * multiply); amountNow = (int)(hexaNeighbour[loop1].GetCurrentSource() * multiply); if (player == hexaNeighbour[loop1].GetCapturedPlayer() || (player == playerOwner && !hexaNeighbour[loop1].GetCaptured())) { switch (hexaNeighbour[loop1].GetKind()) { case HexaKind.Forest: sourceNow += new SourceAll(0, 0, 0, amountNow, 0); sourceNormal += new SourceAll(0, 0, 0, amountNormal, 0); break; case HexaKind.Stone: sourceNow += new SourceAll(0, 0, amountNow, 0, 0); sourceNormal += new SourceAll(0, 0, amountNormal, 0, 0); break; case HexaKind.Cornfield: sourceNow += new SourceAll(amountNow, 0, 0, 0, 0); sourceNormal += new SourceAll(amountNormal, 0, 0, 0, 0); break; case HexaKind.Pasture: sourceNow += new SourceAll(0, amountNow, 0, 0, 0); sourceNormal += new SourceAll(0, amountNormal, 0, 0, 0); break; case HexaKind.Mountains: sourceNow += new SourceAll(0, 0, 0, 0, amountNow); sourceNormal += new SourceAll(0, 0, 0, 0, amountNormal); break; } } } } player.AddSources(sourceNow, TransactionState.TransactionMiddle); player.AddCollectSources(sourceNormal, sourceNow); }