public static int GetVillagePlayerRevenue(string villageID) { EntrepreneurCampaignBehaviour entrepreneur = Campaign.Current.GetCampaignBehavior <EntrepreneurCampaignBehaviour>(); VillageData settlementAcreProperties; entrepreneur.VillageData.TryGetValue(villageID, out settlementAcreProperties); return(settlementAcreProperties.VillagePlayerRevenue); }
public static void BuyPlot(VillageData villageData) { EntrepreneurCampaignBehaviour entrepreneur = Campaign.Current.GetCampaignBehavior <EntrepreneurCampaignBehaviour>(); Dictionary <string, int> itemRequirements = new Dictionary <string, int>(); itemRequirements.Add("tools", 5); itemRequirements.Add("hardwood", 5); Dictionary <string, int> missingRequirements = new Dictionary <string, int>(); missingRequirements.Add("tools", 5); missingRequirements.Add("hardwood", 5); Dictionary <ItemRosterElement, int> itemsToRemove = new Dictionary <ItemRosterElement, int>(); foreach (KeyValuePair <string, int> requirement in itemRequirements) { IEnumerable <ItemRosterElement> items = Hero.MainHero.PartyBelongedTo.ItemRoster.AsQueryable().Where(item => item.Amount >= requirement.Value && item.EquipmentElement.Item.StringId.Equals(requirement.Key)); if (items.Count() != 0) { int currentAmount = items.First().Amount; itemsToRemove.Add(items.First(), currentAmount - requirement.Value); missingRequirements.Remove(requirement.Key); } } if (missingRequirements.Count == 0) { int buyPrice = villageData.AcreSellPrice; if (villageData.AvailableAcres > 0) { if (Hero.MainHero.Gold >= buyPrice) { villageData.buyAcre(); foreach (var item in itemsToRemove) { // Remove whole stack. Hero.MainHero.PartyBelongedTo.ItemRoster.Remove(item.Key); // Add the difference. Hero.MainHero.PartyBelongedTo.ItemRoster.AddToCounts(item.Key.EquipmentElement.Item, item.Value); } GiveGoldAction.ApplyForCharacterToSettlement(Hero.MainHero, Settlement.CurrentSettlement, buyPrice); } else { InformationManager.DisplayMessage(new InformationMessage("You dont have enouph gold to buy this plot.")); } } else { InformationManager.DisplayMessage(new InformationMessage("There are no plots acres to buy.")); } } else { foreach (KeyValuePair <string, int> requirement in missingRequirements) { InformationManager.DisplayMessage(new InformationMessage(($"You are missing {requirement.Value} items of {requirement.Key}."))); } } }