private void HandlePrimaryAction(Item TargetItem) { if (TargetItem is ItemBag TargetBag) { OmniBag.MoveFromBag(TargetBag, true, IBM.InventorySource, IBM.ActualInventoryCapacity, true); } }
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); } } }
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); } }
private static void RegisterAddOmniBagCommand() { List <string> ValidSizes = Enum.GetValues(typeof(ContainerSize)).Cast <ContainerSize>().Select(x => x.ToString()).ToList(); //Possible TODO: Add translation support for this command string CommandName = Constants.TargetPlatform == GamePlatform.Android ? "addomnibag" : "player_addomnibag"; string CommandHelp = string.Format("Adds an empty Omni Bag of the desired size to your inventory.\n" + "Arguments: <BagSize>\n" + "Example: {0} Large\n\n" + "Valid values for <BagSize>: {1}\n\n", CommandName, string.Join(", ", ValidSizes)); 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 { string SizeName = Args[0]; if (!Enum.TryParse(SizeName, out ContainerSize Size) || !ValidSizes.Contains(SizeName)) { Monitor.Log(string.Format("Unable to execute command: <BagSize> \"{0}\" is not valid. Expected valid values: {1}", SizeName, string.Join(", ", ValidSizes)), LogLevel.Alert); } else { try { OmniBag NewBag = new OmniBag(Size); Game1.player.addItemToInventory(NewBag); } catch (Exception ex) { Monitor.Log(string.Format("ItemBags: Unhandled error while executing command: {0}", ex.Message), LogLevel.Error); } } } }); }
public OmniBagMenu(ItemBagMenu IBM, OmniBag Bag, int Columns, int SlotSize, bool ShowLockedSlots, int Padding) { this.IBM = IBM; this.OmniBag = Bag; Bag.OnContentsChanged += Bag_ContentsChanged; this.Padding = Padding; this.ColumnCount = Columns; this.OriginalSlotSize = SlotSize; this.SlotSize = SlotSize; this.ShowLockedSlots = ShowLockedSlots; // Create a placeholder item for every kind of bag the OmniBag can store List <ItemBag> Temp = new List <ItemBag>(); if (BundleBag.ValidSizes.Any(x => x <= this.Bag.Size)) { ContainerSize PlaceholderSize = BundleBag.ValidSizes.OrderByDescending(x => x).First(x => x <= this.Bag.Size); Temp.Add(new BundleBag(PlaceholderSize, false)); } Temp.Add(new Rucksack(Bag.Size, false)); foreach (BagType BagType in ItemBagsMod.BagConfig.BagTypes) { if (BagType.SizeSettings.Any(x => x.Size <= this.Bag.Size)) { ContainerSize PlaceholderSize = BagType.SizeSettings.Select(x => x.Size).OrderByDescending(x => x).First(x => x <= this.Bag.Size); Temp.Add(new BoundedBag(BagType, PlaceholderSize, false)); } } this.Placeholders = new ReadOnlyCollection <ItemBag>(Temp); this.ActualContents = new List <ItemBag>(); for (int i = 0; i < Temp.Count; i++) { ActualContents.Add(null); } UpdateActualContents(); SetTopLeft(Point.Zero, false); InitializeLayout(1); }
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); } }
public override void Action(CommandCaller caller, string input, string[] args) { if (args.Length != 1) { BagsOfHoldingMod.sendChat("Use with \"reloadOrder\" with a held bag to reload its order, \"reloadOmnibag\" to reload omnibag's content list and \"remakeBags\" to remake all bag orders into the configs."); return; } if ((args[0].Equals("reloadOrder") || args[0].Equals("\"reloadOrder\"")) && caller.Player.HeldItem.modItem != null && caller.Player.HeldItem.modItem is GenericHoldingBag) { GenericHoldingBag bag = caller.Player.HeldItem.modItem as GenericHoldingBag; bag.setupItemList(); BagsOfHoldingMod.sendChat("Reloaded bag order"); return; } if (args[0].Equals("reloadOmnibag") || args[0].Equals("\"reloadOmnibag\"")) { TrueOmniBag.contents2 = null; BagPlayer.reloadOmnibag(); BagsOfHoldingMod.sendChat("Recreated Omnibag order."); return; } if (args[0].Equals("remakeBags") || args[0].Equals("\"remakeBags\"")) { GenericHoldingBag bg = new BaitBag(); resetBagConfig(bg); bg.remakeFromConfig(); bg = new ChunkBag(); resetBagConfig(bg); bg.remakeFromConfig(); bg = new CoinBag(); resetBagConfig(bg); bg.remakeFromConfig(); bg = new CrateBag(); resetBagConfig(bg); bg.remakeFromConfig(); bg = new DirtBag(); resetBagConfig(bg); bg.remakeFromConfig(); bg = new DyeMaterialBag(); resetBagConfig(bg); bg.remakeFromConfig(); bg = new FishBag(); resetBagConfig(bg); bg.remakeFromConfig(); bg = new GemBag(); resetBagConfig(bg); bg.remakeFromConfig(); bg = new MushroomBag(); resetBagConfig(bg); bg.remakeFromConfig(); bg = new OreBag(); resetBagConfig(bg); bg.remakeFromConfig(); bg = new PlantBag(); resetBagConfig(bg); bg.remakeFromConfig(); bg = new WoodBag(); resetBagConfig(bg); bg.remakeFromConfig(); FishingBag.resetContents(); NatureBag.resetContents(); OmniBag.resetContents(); BagsOfHoldingMod.sendChat("Reset all bag orders to the original order list."); } }
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); } } } } }