public void UpdateResourceCount(RollResourcesModel rrModel, LogState logState) { int mult = 1; if (logState == LogState.Undo) { mult = -1; } if (rrModel.BlockedByBaron) { CardsLostToBaron += (rrModel.Value * mult); } else { ResourcesAcquired += (rrModel.Value * mult); PlayerTurnResourceCount.AddResourceCount(rrModel.ResourceType, rrModel.Value * mult); } }
// // given a roll and a multiplier (which should be 1 or -1), do a bunch of calculations. this is the main "worker" function of the class // private static Dictionary <string, PlayerRollData> GetResourceModelForRoll(MainPage mainPage, int roll) { Dictionary <string, PlayerRollData> dict = new Dictionary <string, PlayerRollData>(); // // set up the dictionary and record MaxRollsNoResources foreach (var player in mainPage.MainPageModel.PlayingPlayers) { PlayerRollData rollData = new PlayerRollData() { MaxRollNoResources = player.GameData.MaxNoResourceRolls, }; dict[player.PlayerName] = rollData; } // // get all information about the resources // foreach (TileCtrl tile in mainPage.GameContainer.AllTiles) { if (tile.Number == roll) { tile.HighlightTile(mainPage.CurrentPlayer.GameData.PlayerColor); // shows what was rolled } else { tile.StopHighlightingTile(); } if (tile.Number != roll) { continue; } // // the tile has the right number - see what settlements are on it foreach (BuildingCtrl building in tile.OwnedBuilding) { if (building.Owner == null) { // // not owned -- continue Debug.Assert(false, "Unowned buildings shouldn't be in the Owned Buildings collection!"); continue; } // // owned...it should be a settlement or a city Debug.Assert(building.BuildingState == BuildingState.Settlement || building.BuildingState == BuildingState.City, "Owned buildings should be Settlements or Cities!"); // // get its value and add it to the dictionary that maps players to resources acquired int value = building.BuildingState == BuildingState.Settlement ? 1 : 2; var rrModel = new RollResourcesModel(tile.ResourceType, value, tile.HasBaron); // // we added all the players above, so they need to be here. dict[building.Owner.PlayerName].ResourceList.Add(rrModel); /* * this updates * 1) the per turn resources a player acquired * 2) the toal # of resources a player has acquired (control notified via an event in PlayerResourceModel * 3) the global count for each resource (via an event in PlayerResourceModel) * 4) Cards Lost to Baron */ building.Owner.GameData.UpdateResourceCount(rrModel, LogState.Normal); } } // // go through players and update the good/bad roll count foreach (var player in mainPage.MainPageModel.PlayingPlayers) { if (player.GameData.PlayerTurnResourceCount.Total == 0) { player.GameData.NoResourceCount++; player.GameData.GoodRoll = false; } else { player.GameData.RollsWithResource++; player.GameData.NoResourceCount = 0; player.GameData.GoodRoll = true; } } return(dict); }