public static bool DetermineTownHasSufficientInputsReplacement(WorkshopType.Production production, Town town, out int inputMaterialCost) { ItemRoster stashRoster = null; for (int i = 0; i < town.Workshops.Length; i++) { if (town.Workshops[i].Owner == Hero.MainHero) { bool didWeFindIt = CampaignChanger.Current.QuickAccess.TryGetValue(town, out var stash); if (didWeFindIt && stash.InputTrue) { stashRoster = stash.Stash; } } } inputMaterialCost = 0; using (IEnumerator <ValueTuple <ItemCategory, int> > enumerator = production.Inputs.GetEnumerator()) { while (enumerator.MoveNext()) { ValueTuple <ItemCategory, int> current = enumerator.Current; ItemCategory item1 = current.Item1; int item2 = current.Item2; ItemRoster itemRoster = town.Owner.ItemRoster; int num1 = 0; if (stashRoster != null) { for (int a = 0; a < stashRoster.Count; a++) { ItemObject itemAtIndex1 = stashRoster.GetItemAtIndex(a); if (itemAtIndex1.ItemCategory == item1) { num1 = stashRoster.GetElementNumber(a); } } } for (int i = 0; i < itemRoster.Count; i++) { ItemObject itemAtIndex = itemRoster.GetItemAtIndex(i); if (itemAtIndex.ItemCategory == item1) { int num = Math.Min(item2, itemRoster.GetElementNumber(i)); item2 = item2 + num1 - num; inputMaterialCost = inputMaterialCost + town.GetItemPrice(itemAtIndex, null, false) * num; } } if (item2 >= 0) { continue; } return(false); } return(true); } }
public static bool DetermineTownHasSufficientInputsReplacement(WorkshopType.Production production, Town town, out int inputMaterialCost, Workshop workshop) { ItemRoster stashRoster = null; if (workshop.Owner == Hero.MainHero) { var stash = MBObjectManager.Instance.GetObject <TownWorkshopStash>(x => x.Town == town); if (stash != null && stash.InputFromStash) { stashRoster = stash.Stash; } } IReadOnlyList <ValueTuple <ItemCategory, int> > inputs = production.Inputs; inputMaterialCost = 0; foreach (ValueTuple <ItemCategory, int> valueTuple in inputs) { ItemCategory itemCategory = valueTuple.Item1; int val1 = valueTuple.Item2; if (stashRoster != null) { for (int index = 0; index < stashRoster.Count; ++index) { ItemObject itemAtIndex = stashRoster.GetItemAtIndex(index); if (itemAtIndex.ItemCategory == itemCategory) { int elementNumber = stashRoster.GetElementNumber(index); int num = Math.Min(val1, elementNumber); val1 -= num; } } } ItemRoster itemRoster = town.Owner.ItemRoster; for (int index = 0; index < itemRoster.Count; ++index) { ItemObject itemAtIndex = itemRoster.GetItemAtIndex(index); if (itemAtIndex.ItemCategory == itemCategory) { int elementNumber = itemRoster.GetElementNumber(index); int num = Math.Min(val1, elementNumber); val1 -= num; inputMaterialCost += town.GetItemPrice(itemAtIndex, null, false) * num; } } if (val1 > 0) { return(false); } } return(true); }