public void isEmptyTest2() { BoundedBag <string> b = new BoundedBag <string>("bag", 3); b.insert("one"); Assert.IsFalse(b.isEmpty()); }
public void isFullTest2() { BoundedBag <string> b = new BoundedBag <string>("bag", 1); b.insert("one"); Assert.IsTrue(b.isFull()); }
private bool TryHandlePrimaryAction(bool IsMouseInput) { if (BoundedBag.Autofill && !IBM.IsTransferMultipleModifierHeld && !IBM.IsTransferHalfModifierHeld) { if (!GroupedOptions.IsEmptyMenu && GroupedOptions.HoveredSlot.HasValue) { if (!IsMouseInput || GetAutofillToggleClickableRegion(GroupedOptions.HoveredSlot.Value).Contains(CurrentMousePosition)) { BoundedBag.ToggleItemAutofill(GroupedOptions.GetHoveredItem()); return(true); } } if (!UngroupedOptions.IsEmptyMenu && UngroupedOptions.HoveredSlot.HasValue) { if (!IsMouseInput || GetAutofillToggleClickableRegion(UngroupedOptions.HoveredSlot.Value).Contains(CurrentMousePosition)) { BoundedBag.ToggleItemAutofill(UngroupedOptions.GetHoveredItem()); return(true); } } } return(false); }
public void isFullTest3() { BoundedBag <string> b = new BoundedBag <string>("bag", 2); b.insert("one"); Assert.IsFalse(b.isFull()); }
static void Main(string[] args) { try { BoundedBag <string> b = new BoundedBag <string>("ShoppingList", 10); b.insert("apple"); b.insert("eggs"); b.insert("milk"); b.saveBag("C:/test/mybag.txt"); BoundedBag <string> c = new BoundedBag <string>("ShoppingList", 10); c.loadBag("C:/test/mybag.txt"); Console.WriteLine(c.remove()); Console.WriteLine(c.remove()); Console.WriteLine(c.remove()); } catch (BagEmptyException) { Console.WriteLine("No more items remain in the bag, unable to remove."); } catch (BagFullExcepion) { Console.WriteLine("No more room in the bag, The bag is full!"); } Console.ReadKey(); }
private void HandlePrimaryAction() { if ((IsLeftSidebarVisible || IsRightSidebarVisible) && HoveredButton.HasValue) { if (IsLeftSidebarVisible && HoveredButton.Value == SidebarButton.DepositAll) { List <Object> ToDeposit = InventorySource.Where(x => x != null && x is Object Obj && Bag.IsValidBagObject(Obj)).Cast <Object>().ToList(); Bag.MoveToBag(ToDeposit, ToDeposit.Select(x => x.Stack).ToList(), out int TotalMovedQty, true, InventorySource); } else if (IsLeftSidebarVisible && HoveredButton.Value == SidebarButton.WithdrawAll) { List <Object> ToWithdraw = Bag.Contents.Where(x => x != null).ToList(); Bag.MoveFromBag(ToWithdraw, ToWithdraw.Select(x => x.Stack).ToList(), out int TotalMovedQty, true, InventorySource, ActualInventoryCapacity); } else if (IsLeftSidebarVisible && HoveredButton.Value == SidebarButton.Autoloot) { if (Bag is BoundedBag BB) { BB.Autofill = !BB.Autofill; } else if (Bag is Rucksack RS) { RS.CycleAutofill(); } } else if (IsRightSidebarVisible && HoveredButton.Value == SidebarButton.HelpInfo) { } else if (IsRightSidebarVisible && HoveredButton.Value == SidebarButton.CustomizeIcon && Bag.CanCustomizeIcon()) { ItemBag Copy; if (Bag is BoundedBag BB) { if (BB is BundleBag) { Copy = new BundleBag(Bag.Size, false); } else { Copy = new BoundedBag(BB.TypeInfo, Bag.Size, false); } } else if (Bag is Rucksack RS) { Copy = new Rucksack(Bag.Size, false); } else if (Bag is OmniBag OB) { Copy = new OmniBag(Bag.Size); } else { throw new NotImplementedException(string.Format("Unexpected Bag Type while creating CustomizeIconMenu: {0}", Bag.GetType().ToString())); } CustomizeIconMenu = new CustomizeIconMenu(this, this.Bag, Copy, 24); } } }
public void isEmptyTest3() { BoundedBag <string> b = new BoundedBag <string>("bag", 3); b.insert("one"); b.remove(); Assert.IsTrue(b.isEmpty()); }
public void removeTest1() { BoundedBag <string> b = new BoundedBag <string>("bag", 3); b.insert("one"); string s = b.remove(); Assert.IsTrue(s.Equals("one")); }
public void insertTest1() { BoundedBag <string> b = new BoundedBag <string>("bag", 3); b.insert("one"); b.insert("two"); b.insert("one"); Assert.IsTrue(b.isFull()); }
public void removeTest2() { BoundedBag <string> b = new BoundedBag <string>("bag", 0); try { b.remove(); } catch (BagEmptyException e) { } finally { Assert.AreEqual("bag", b.getName()); } }
public void loadsaveTest() { BoundedBag <string> b = new BoundedBag <string>("bag", 3); b.insert("one"); b.insert("two"); b.insert("three"); b.saveBag("C:\\temp\\a1.txt"); BoundedBag <string> newb = new BoundedBag <string>("new", 3); newb.loadBag("C:\\temp\\a1.txt"); newb.remove(); Assert.IsFalse(newb.isFull()); }
public void loadsaveTest() { BoundedBag <string> b = new BoundedBag <string>("bag", 3); b.insert("one"); b.insert("two"); b.insert("three"); b.saveBag("C:/Users/Goragottsen/Desktop/gbc/COMP2129/assignment/A101095885/A101095885/mybag.txt"); BoundedBag <string> newb = new BoundedBag <string>("new", 3); newb.loadBag("C:/Users/Goragottsen/Desktop/gbc/COMP2129/assignment/A101095885/A101095885/mybag.txt"); newb.remove(); Assert.IsFalse(newb.isFull()); }
internal bool TryDecode(out ItemBag Decoded) { // Handle BundleBags if (this.TypeId == BundleBag.BundleBagTypeId) { Decoded = new BundleBag(this); return(true); } // Handle Rucksacks else if (this.TypeId == Rucksack.RucksackTypeId) { Decoded = new Rucksack(this); return(true); } // Handle OmniBags else if (this.TypeId == OmniBag.OmniBagTypeId) { Decoded = new OmniBag(this); return(true); } // Handle all other types of Bags else if (ItemBagsMod.BagConfig.IndexedBagTypes.TryGetValue(this.TypeId, out BagType BagType)) { BagSizeConfig SizeConfig = BagType.SizeSettings.FirstOrDefault(x => x.Size == this.Size); if (SizeConfig != null) { Decoded = new BoundedBag(BagType, this); return(true); } else { string Warning = string.Format("Warning - BagType with Id = {0} was found, but it does not contain any settings for Size={1}. Did you manually edit your {2} json file? The saved bag cannot be loaded without the corresponding settings for this size!", this.TypeId, this.Size.ToString(), ItemBagsMod.BagConfigDataKey); ItemBagsMod.ModInstance.Monitor.Log(Warning, LogLevel.Warn); Decoded = null; return(false); } } else { string Warning = string.Format("Warning - no BagType with Id = {0} was found. Did you manually edit your {1} json file or delete a .json file from 'Modded Bags' folder? The saved bag cannot be loaded without a corresponding type!", this.TypeId, ItemBagsMod.BagConfigDataKey); ItemBagsMod.ModInstance.Monitor.Log(Warning, LogLevel.Warn); Decoded = null; return(false); } }
public void insertTest2() { BoundedBag <string> b = new BoundedBag <string>("bag", 3); b.insert("one"); b.insert("two"); b.insert("one"); try { b.insert("four"); } catch (BagFullException e) { } finally { Assert.AreEqual("bag", b.getName()); } }
public void removeTest3() { BoundedBag <string> b = new BoundedBag <string>("bag", 3); b.insert("one"); b.insert("two"); b.insert("two"); try { b.remove(); b.remove(); } catch (BagEmptyException e) { } finally { Assert.IsFalse(b.isFull()); } }
public BoundedBagMenu(ItemBagMenu IBM, BoundedBag Bag, bool GroupContentsByQuality, GroupedLayoutOptions GroupedLayout, UngroupedLayoutOptions UngroupedLayout, int Padding) { this.IBM = IBM; this.BoundedBag = Bag; this.Padding = Padding; this.GroupByQuality = GroupContentsByQuality; this.GroupedOptions = GroupedLayout; this.GroupedOptions.SetParent(this); this.GroupedOptions.OnItemSlotRendered += OnItemSlotRendered; this.UngroupedOptions = UngroupedLayout; this.UngroupedOptions.SetParent(this); this.UngroupedOptions.OnItemSlotRendered += OnItemSlotRendered; if (!GroupedOptions.IsEmptyMenu && !UngroupedOptions.IsEmptyMenu) { GroupedOptions.MenuNeighbors[NavigationDirection.Down] = UngroupedOptions; UngroupedOptions.MenuNeighbors[NavigationDirection.Up] = GroupedOptions; } SetTopLeft(Point.Zero, false); InitializeLayout(1); }
private void OnItemSlotRendered(object sender, ItemSlotRenderedEventArgs e) { // Draw a toggle to enable/disable autofilling this item if (BoundedBag.Autofill && (e.IsHovered || IBM.IsHoveringAutofillButton)) { Rectangle AutofillDestination; float Transparency; if (IBM.IsHoveringAutofillButton) { double PercentSize = 0.75; int Width = (int)(e.Slot.Width * PercentSize); int Height = (int)(e.Slot.Height * PercentSize); AutofillDestination = new Rectangle(e.Slot.Center.X - Width / 2, e.Slot.Center.Y - Height / 2, Width, Height); Transparency = 1.0f; } else { AutofillDestination = GetAutofillToggleDrawPosition(e.Slot); Transparency = GetAutofillToggleClickableRegion(e.Slot).Contains(CurrentMousePosition) ? 1.0f : 0.75f; } Rectangle HandIconSourceRect = new Rectangle(32, 0, 10, 10); int HandIconSize = (int)(HandIconSourceRect.Width * 2.0 / 32.0 * AutofillDestination.Width); //b.Draw(Game1.menuTexture, AutofillDestination, new Rectangle(128, 128, 64, 64), Color.White); e.SB.Draw(Game1.mouseCursors, new Rectangle(AutofillDestination.X + (AutofillDestination.Width - HandIconSize) / 2, AutofillDestination.Y + (AutofillDestination.Height - HandIconSize) / 2, HandIconSize, HandIconSize), HandIconSourceRect, Color.White * Transparency); if (!BoundedBag.CanAutofillWithItem(e.Item)) { Rectangle DisabledIconSourceRect = new Rectangle(322, 498, 12, 12); int DisabledIconSize = (int)(DisabledIconSourceRect.Width * 1.5 / 32.0 * AutofillDestination.Width); Rectangle DisabledIconDestination = new Rectangle(AutofillDestination.Right - DisabledIconSize - 2, AutofillDestination.Bottom - DisabledIconSize - 2, DisabledIconSize, DisabledIconSize); e.SB.Draw(Game1.mouseCursors, DisabledIconDestination, DisabledIconSourceRect, Color.White * Transparency); } } }
private void Display_MenuChanged(object sender, MenuChangedEventArgs e) { // Refresh completed Bundles in the community center if (e.OldMenu != null && e.OldMenu is JunimoNoteMenu) { CommunityCenterBundles.Instance = new CommunityCenterBundles(); } if (e.NewMenu is ShopMenu SM) { // Determine if the shop menu belongs to one of our managed shops bool IsModifiableShop = false; BagShop BagShop = BagShop.Pierre; if (SM.portraitPerson?.Name != null) { //TODO test if the Stardew Valley Expanded shops like Isaac/Sophia/Alesia have non-null values for ShopMenu.portraitPerson.Name if (Enum.TryParse(SM.portraitPerson.Name, out BagShop)) { IsModifiableShop = true; } } else if (SM.storeContext != null) { if (SM.storeContext.Equals("Forest", StringComparison.CurrentCultureIgnoreCase)) { if (SM.onPurchase?.GetMethodInfo().Name == "onTravelingMerchantShopPurchase") // nameof(Utility.onTravelingMerchantShopPurchase) { BagShop = BagShop.TravellingCart; } else { BagShop = BagShop.HatMouse; } IsModifiableShop = true; } else if (SM.storeContext.Equals("Town", StringComparison.CurrentCultureIgnoreCase) && SM.potraitPersonDialogue != null && SM.potraitPersonDialogue.Contains("Khadija")) { BagShop = BagShop.Khadija; IsModifiableShop = true; } } // Add Bag items to the shop's stock if (IsModifiableShop) { Dictionary <ISalable, int[]> Stock = SM.itemPriceAndStock; bool ShouldModifyStock = true; if (BagShop == BagShop.Clint) { // Assume user is viewing Clint tool upgrades if the stock doesn't contain Coal if (!Stock.Any(x => x.Key is Object Obj && Obj.Name.Equals("Coal", StringComparison.CurrentCultureIgnoreCase))) { ShouldModifyStock = false; } } if (ShouldModifyStock) { bool HasChangedStock = false; List <ItemBag> OwnedBags = UserConfig.HideObsoleteBagsFromShops ? ItemBag.GetAllBags(true) : new List <ItemBag>(); // Add Bounded Bags to stock foreach (BagType Type in BagConfig.BagTypes) { foreach (BagSizeConfig SizeCfg in Type.SizeSettings) { bool IsSoldByShop = UserConfig.IsSizeVisibleInShops(SizeCfg.Size) && SizeCfg.Sellers.Contains(BagShop); #if DEBUG //IsSoldByShop = true; #endif if (IsSoldByShop) { bool IsObsolete = false; if (UserConfig.HideObsoleteBagsFromShops) { IsObsolete = OwnedBags.Any(x => x is BoundedBag BB && BB.TypeInfo == Type && (int)BB.Size > (int)SizeCfg.Size); } if (!IsObsolete) { BoundedBag SellableInstance = new BoundedBag(Type, SizeCfg.Size, false); int Price = SellableInstance.GetPurchasePrice(); #if DEBUG //Price = 1 + (int)SizeCfg.Size; #endif Stock.Add(SellableInstance, new int[] { Price, ShopMenu.infiniteStock }); HasChangedStock = true; } } } } // Add Bundle Bags to stock foreach (BundleBagSizeConfig SizeCfg in UserConfig.BundleBagSettings) { ContainerSize Size = SizeCfg.Size; if (BundleBag.ValidSizes.Contains(Size) && SizeCfg.Sellers.Contains(BagShop) && UserConfig.IsSizeVisibleInShops(Size)) { bool IsObsolete = false; if (UserConfig.HideObsoleteBagsFromShops) { IsObsolete = OwnedBags.Any(x => x is BundleBag BB && (int)BB.Size > (int)Size); } if (!IsObsolete) { BundleBag BundleBag = new BundleBag(Size, true); int Price = BundleBag.GetPurchasePrice(); Stock.Add(BundleBag, new int[] { Price, ShopMenu.infiniteStock }); HasChangedStock = true; } } } // Add Rucksacks to stock foreach (RucksackSizeConfig SizeCfg in UserConfig.RucksackSettings) { ContainerSize Size = SizeCfg.Size; if (SizeCfg.Sellers.Contains(BagShop) && UserConfig.IsSizeVisibleInShops(Size)) { bool IsObsolete = false; if (UserConfig.HideObsoleteBagsFromShops) { IsObsolete = OwnedBags.Any(x => x is Rucksack RS && (int)RS.Size > (int)Size); } if (!IsObsolete) { Rucksack Rucksack = new Rucksack(Size, false, AutofillPriority.Low); int Price = Rucksack.GetPurchasePrice(); Stock.Add(Rucksack, new int[] { Price, ShopMenu.infiniteStock }); HasChangedStock = true; } } } // Add Omni Bags to stock foreach (OmniBagSizeConfig SizeCfg in UserConfig.OmniBagSettings) { ContainerSize Size = SizeCfg.Size; if (SizeCfg.Sellers.Contains(BagShop) && UserConfig.IsSizeVisibleInShops(Size)) { bool IsObsolete = false; if (UserConfig.HideObsoleteBagsFromShops) { IsObsolete = OwnedBags.Any(x => x is OmniBag OB && (int)OB.Size > (int)Size); } if (!IsObsolete) { OmniBag OmniBag = new OmniBag(Size); int Price = OmniBag.GetPurchasePrice(); Stock.Add(OmniBag, new int[] { Price, ShopMenu.infiniteStock }); HasChangedStock = true; } } } if (HasChangedStock) { SM.setItemPriceAndStock(Stock); } } } } }
public void isFullTest1() { BoundedBag <string> b = new BoundedBag <string>("bag", 0); Assert.IsTrue(b.isFull()); }
public BoundedBagMenu(ItemBagMenu IBM, BoundedBag Bag, BagMenuOptions Opts, int Padding) : this(IBM, Bag, Opts.GroupByQuality, new GroupedLayoutOptions(Opts.GroupedLayoutOptions), new UngroupedLayoutOptions(Opts.UngroupedLayoutOptions), Padding) { }
public void isEmptyTest1() { BoundedBag <string> b = new BoundedBag <string>("bag", 3); Assert.IsTrue(b.isEmpty()); }
public void getNameTest() { BoundedBag <string> b = new BoundedBag <string>("bag", 3); Assert.AreEqual("bag", b.getName()); }
private static void RegisterAddItemBagCommand() { List <string> ValidSizes = Enum.GetValues(typeof(ContainerSize)).Cast <ContainerSize>().Select(x => x.ToString()).ToList(); List <string> ValidTypes = BagConfig.BagTypes.Select(x => x.Name).ToList(); //Possible TODO: Add translation support for this command string CommandName = Constants.TargetPlatform == GamePlatform.Android ? "addbag" : "player_additembag"; string CommandHelp = string.Format("Adds an empty Bag of the desired size and type to your inventory.\n" + "Arguments: <BagSize> <BagType>\n" + "Example: {0} Massive River Fish Bag\n\n" + "Valid values for <BagSize>: {1}\n\n" + "Valid values for <BagType>: {2}", CommandName, string.Join(", ", ValidSizes), string.Join(", ", ValidTypes)); Helper.ConsoleCommands.Add(CommandName, CommandHelp, (string Name, string[] Args) => { if (Game1.player.isInventoryFull()) { Monitor.Log("Unable to execute command: Inventory is full!", LogLevel.Alert); } else if (Args.Length < 1) { Monitor.Log("Unable to execute command: Required arguments missing!", LogLevel.Alert); } else { // If user didn't specify a size, give them 1 of every available size for thes BagType bool AllSizes = Args.Length < 2; if (AllSizes) { string TypeName = string.Join(" ", Args[0]); BagType BagType = BagConfig.BagTypes.FirstOrDefault(x => x.Name.Equals(TypeName, StringComparison.CurrentCultureIgnoreCase)); if (BagType == null) { Monitor.Log(string.Format("Unable to execute command: <BagType> \"{0}\" is not valid. Expected valid values: {1}", TypeName, string.Join(", ", ValidTypes)), LogLevel.Alert); } else { foreach (ContainerSize Size in Enum.GetValues(typeof(ContainerSize)).Cast <ContainerSize>()) { if (BagType.SizeSettings.Any(x => x.Size == Size)) { try { if (!Game1.player.isInventoryFull()) { BoundedBag NewBag = new BoundedBag(BagType, Size, false); Game1.player.addItemToInventory(NewBag); } } catch (Exception ex) { Monitor.Log(string.Format("ItemBags: Unhandled error while executing command: {0}", ex.Message), LogLevel.Error); } } } } } else { string SizeName = Args[0]; if (!Enum.TryParse(SizeName, out ContainerSize Size)) { Monitor.Log(string.Format("Unable to execute command: <BagSize> \"{0}\" is not valid. Expected valid values: {1}", SizeName, string.Join(", ", ValidSizes)), LogLevel.Alert); } else { string TypeName = string.Join(" ", Args.Skip(1)); //Possible TODO: If you add translation support to this command, then find the BagType where BagType.GetTranslatedName().Equals(TypeName, StringComparison.CurrentCultureIgnoreCase)); BagType BagType = BagConfig.BagTypes.FirstOrDefault(x => x.Name.Equals(TypeName, StringComparison.CurrentCultureIgnoreCase)); if (BagType == null) { Monitor.Log(string.Format("Unable to execute command: <BagType> \"{0}\" is not valid. Expected valid values: {1}", TypeName, string.Join(", ", ValidTypes)), LogLevel.Alert); } else { if (!BagType.SizeSettings.Any(x => x.Size == Size)) { Monitor.Log(string.Format("Unable to execute command: Type='{0}' does not contain a configuration for Size='{1}'", TypeName, SizeName), LogLevel.Alert); } else { try { BoundedBag NewBag = new BoundedBag(BagType, Size, false); Game1.player.addItemToInventory(NewBag); } catch (Exception ex) { Monitor.Log(string.Format("ItemBags: Unhandled error while executing command: {0}", ex.Message), LogLevel.Error); } } } } } } }); }
public static void MonsterDrop_Postfix(GameLocation __instance, Monster monster, int x, int y, Farmer who) { try { MonsterLootSettings LootSettings = MonsterLootSettings; if (who.UniqueMultiplayerID == Game1.player.UniqueMultiplayerID && LootSettings.CanReceiveBagsAsDrops) { // Roll chance at receiving an ItemBag double Chance = LootSettings.GetItemBagDropChance(__instance, monster, out double BaseChance, out double LocationMultiplier, out double ExpMultiplier, out double HPMultiplier); bool Success = Randomizer.NextDouble() <= Chance; string LogMessage; if (Success) { if (MonsterLootSettings.LogDropChancesToConsole) { LogMessage = string.Format("Succeeded drop chance: Location = {0}, monster.ExperienceGained = {1}, monster.MaxHealth = {2}\n" + "BaseChance = {3} ({4}%), LocationMultiplier = {5} (+{6}%), ExpMultiplier = {7}, HPMultiplier = {8} (+{9}%), TotalChance = {10} ({11}%)", __instance.Name, monster.ExperienceGained, monster.MaxHealth, BaseChance, (BaseChance * 100.0).ToString("0.##"), LocationMultiplier, ((LocationMultiplier - 1.0) * 100.0).ToString("0.##"), ExpMultiplier.ToString("#.####"), HPMultiplier, ((HPMultiplier - 1.0) * 100.0).ToString("0.##"), Chance, (Chance * 100.0).ToString("0.###")); Monitor.Log(LogMessage, LogLevel.Info); } int SpawnDirection = Randomizer.Next(4); List <ItemBag> OwnedBags = ItemBag.GetAllBags(true); // Compute the odds of receiving each type of bag bool CanReceiveRucksack = LootSettings.RucksackDropSettings.SizeWeights.Any(size => size.Value > 0); int RucksackWeight = CanReceiveRucksack ? LootSettings.RucksackDropSettings.TypeWeight : 0; bool CanReceiveOmniBag = LootSettings.OmniBagDropSettings.SizeWeights.Any(size => size.Value > 0); int OmniBagWeight = CanReceiveOmniBag ? LootSettings.OmniBagDropSettings.TypeWeight : 0; bool CanReceiveBundleBag = LootSettings.BundleBagDropSettings.SizeWeights.Any(size => BundleBag.ValidSizes.Contains(size.Key) && size.Value > 0 && !IsSizeObsolete(OwnedBags, BundleBag.BundleBagTypeId, size.Key)); int BundleBagWeight = CanReceiveBundleBag ? LootSettings.BundleBagDropSettings.TypeWeight : 0; bool CanReceiveStandardBag = LootSettings.StandardBagDropSettings.SizeWeights.Any(size => size.Value > 0); int StandardBagWeight = CanReceiveStandardBag ? LootSettings.StandardBagDropSettings.TypeWeight : 0; int TotalTypeWeight = RucksackWeight + OmniBagWeight + BundleBagWeight + StandardBagWeight; if (TotalTypeWeight > 0) { ItemBag ChosenBag; // Pick the type of bag to spawn (Rucksack, OmniBag, BundleBag or a standard BoundedBag) int ChosenTypeWeight = Randomizer.Next(0, TotalTypeWeight); if (ChosenTypeWeight < RucksackWeight) { ContainerSize CurrentSize = GetWeightedRandomSize(LootSettings.RucksackDropSettings.SizeWeights); // Try to force a non-obsolete bag to spawn if (RollDice(LootSettings.ForceNewBagTypeChance)) { List <ContainerSize> ValidSizes = LootSettings.RucksackDropSettings.SizeWeights.Where(size => size.Value > 0).Select(size => size.Key).ToList(); ContainerSize MaxSize = ValidSizes.DefaultIfEmpty(ContainerSize.Small).Max(); while (CurrentSize < MaxSize && IsSizeObsolete(OwnedBags, Rucksack.RucksackTypeId, CurrentSize)) { CurrentSize = ValidSizes.Where(size => size > CurrentSize).OrderBy(size => size).First(); } } // Spawn a Rucksack ChosenBag = new Rucksack(CurrentSize, false); } else if (ChosenTypeWeight < RucksackWeight + OmniBagWeight) { ContainerSize CurrentSize = GetWeightedRandomSize(LootSettings.OmniBagDropSettings.SizeWeights); // Try to force a non-obsolete bag to spawn if (RollDice(LootSettings.ForceNewBagTypeChance)) { List <ContainerSize> ValidSizes = LootSettings.OmniBagDropSettings.SizeWeights.Where(size => size.Value > 0).Select(size => size.Key).ToList(); ContainerSize MaxSize = ValidSizes.DefaultIfEmpty(ContainerSize.Small).Max(); while (CurrentSize < MaxSize && IsSizeObsolete(OwnedBags, OmniBag.OmniBagTypeId, CurrentSize)) { CurrentSize = ValidSizes.Where(size => size > CurrentSize).OrderBy(size => size).First(); } } // Spawn an OmniBag ChosenBag = new OmniBag(CurrentSize); } else if (ChosenTypeWeight < RucksackWeight + OmniBagWeight + BundleBagWeight) { // Spawn a BundleBag ContainerSize Size = GetWeightedRandomSize(LootSettings.BundleBagDropSettings.SizeWeights.Where(size => BundleBag.ValidSizes.Contains(size.Key) && !IsSizeObsolete(OwnedBags, BundleBag.BundleBagTypeId, size.Key))); ChosenBag = new BundleBag(Size, true); } else { ContainerSize CurrentSize = GetWeightedRandomSize(LootSettings.StandardBagDropSettings.SizeWeights); // Get all standard BagTypes that are available in the chosen size List <BagType> StandardTypes = ItemBagsMod.BagConfig.BagTypes.Where(type => type.SizeSettings.Any(sizeCfg => sizeCfg.Size == CurrentSize)).ToList(); // Try to force a non-obsolete bag to spawn if (RollDice(LootSettings.ForceNewBagTypeChance)) { StandardTypes.RemoveAll(type => IsSizeObsolete(OwnedBags, type.Id, CurrentSize)); // If all bag types were obsolete, then keep incrementing the size until we find a non-obsolete bag to spawn if (!StandardTypes.Any()) { List <ContainerSize> ValidSizes = LootSettings.StandardBagDropSettings.SizeWeights.Where(size => size.Value > 0).Select(size => size.Key).ToList(); ContainerSize MaxSize = ValidSizes.DefaultIfEmpty(ContainerSize.Small).Max(); while (CurrentSize < MaxSize && !StandardTypes.Any()) { CurrentSize = ValidSizes.Where(size => size > CurrentSize).OrderBy(size => size).First(); StandardTypes = ItemBagsMod.BagConfig.BagTypes.Where(type => type.SizeSettings.Any(sizeCfg => sizeCfg.Size == CurrentSize) && !IsSizeObsolete(OwnedBags, type.Id, CurrentSize)).ToList(); } } } if (StandardTypes.Any()) { // Spawn a standard BoundedBag int ChosenTypeIndex = Randomizer.Next(StandardTypes.Count); ChosenBag = new BoundedBag(StandardTypes[ChosenTypeIndex], CurrentSize, false); } else { ChosenBag = null; } } if (ChosenBag != null) { Game1.createItemDebris(ChosenBag, Game1.player.getStandingPosition(), SpawnDirection, null, -1); } } } else if (MonsterLootSettings.LogDropChancesToConsole) { LogMessage = string.Format("Failed drop chance: Location = {0}, monster.ExperienceGained = {1}, monster.MaxHealth = {2}\n" + "BaseChance = {3} ({4}%), LocationMultiplier = {5} (+{6}%), ExpMultiplier = {7}, HPMultiplier = {8} (+{9}%), TotalChance = {10} ({11}%)", __instance.Name, monster.ExperienceGained, monster.MaxHealth, BaseChance, (BaseChance * 100.0).ToString("0.##"), LocationMultiplier, ((LocationMultiplier - 1.0) * 100.0).ToString("0.##"), ExpMultiplier.ToString("#.####"), HPMultiplier, ((HPMultiplier - 1.0) * 100.0).ToString("0.##"), Chance, (Chance * 100.0).ToString("0.###")); Monitor.Log(LogMessage, LogLevel.Info); } } } catch (Exception ex) { Monitor.Log(string.Format("Unhandled Error in {0}:\n{1}", nameof(MonsterDrop_Postfix), ex), LogLevel.Error); } }