private static void Postfix(SmeltingVM __instance, ItemRoster ____playerItemRoster) { // This appears to be how the game works out if an item is locked // From TaleWorlds.CampaignSystem.ViewModelCollection.SPInventoryVM.InitializeInventory() IEnumerable <EquipmentElement> locks = Campaign.Current.GetCampaignBehavior <TaleWorlds.CampaignSystem.SandBox.CampaignBehaviors.IInventoryLockTracker>().GetLocks(); // Updated line 24 to Line 25 which seems to be the updated way game works out item locks in v1.4.3 InitializeInventory() // EquipmentElement[] locked_items = locks?.ToArray<EquipmentElement>(); EquipmentElement[] locked_items = (locks != null) ? locks.ToArray <EquipmentElement>() : null; bool isLocked(EquipmentElement test_item) { return(locked_items != null && locked_items.Any(delegate(EquipmentElement x) { ItemObject lock_item = x.Item; if (lock_item.StringId == test_item.Item.StringId) { ItemModifier itemModifier = x.ItemModifier; string a = itemModifier?.StringId; ItemModifier itemModifier2 = test_item.ItemModifier; return a == (itemModifier2?.StringId); } return false; })); } MBBindingList <SmeltingItemVM> filteredList = new MBBindingList <SmeltingItemVM>(); foreach (SmeltingItemVM sItem in __instance.SmeltableItemList) { if (!____playerItemRoster.Any(rItem => sItem.Item == rItem.EquipmentElement.Item && isLocked(rItem.EquipmentElement) )) { filteredList.Add(sItem); } } __instance.SmeltableItemList = filteredList; if (__instance.SmeltableItemList.Count == 0) { __instance.CurrentSelectedItem = null; } }
private static void Postfix(SmeltingVM __instance, ItemRoster ____playerItemRoster) { if (BannerlordTweaksSettings.Instance is { } settings&& settings.PreventSmeltingLockedItems) { List <string> locked_items = Campaign.Current.GetCampaignBehavior <IInventoryLockTracker>().GetLocks().ToList <string>(); bool isLocked(ItemRosterElement item) { string text = item.EquipmentElement.Item.StringId; if (item.EquipmentElement.ItemModifier != null) { text += item.EquipmentElement.ItemModifier.StringId; } return(locked_items.Contains(text)); } MBBindingList <SmeltingItemVM> filteredList = new MBBindingList <SmeltingItemVM>(); foreach (SmeltingItemVM sItem in __instance.SmeltableItemList) { if (!____playerItemRoster.Any(rItem => sItem.EquipmentElement.Item == rItem.EquipmentElement.Item && isLocked(rItem) )) { filteredList.Add(sItem); } } __instance.SmeltableItemList = filteredList; if (__instance.SmeltableItemList.Count == 0) { __instance.CurrentSelectedItem = null; } } }