1. Welcome to the official Starbound Mod repository, Guest! Not sure how to install your mods? Check out the installation guide or check out the modding help thread for more guides.
    Outdated Mods have been moved to their own category! If you update your mod please let a moderator know so we can move it back to the active section.
    Dismiss Notice

Adventure Shop Inventory 1.0.1

Make Marlon sell what you want, when you want, for how much you want.

  1. v1.0.1

    Hammurabi
    Fixed a potential NullReferenceException bug.

    Code:
    using System;
    using System.Collections.Generic;
    using StardewModdingAPI;
    using StardewModdingAPI.Events;
    using StardewValley;
    using StardewValley.Locations;
    using StardewValley.Menus;
    using StardewValley.Objects;
    using StardewValley.Tools;
    
    namespace Adventure_Shop_Inventory {
       public class AdventureShopMod : Mod {
         public bool shopReplaced;
         public Config config;
    
         public override void Entry(IModHelper helper) {
           MenuEvents.MenuChanged += OnMenuChanged;
           MenuEvents.MenuClosed += OnMenuClosed;
           config = helper.ReadConfig<Config>();
           if (config == null) {
             config = new Config();
             helper.WriteConfig<Config>(config);
           }
         }
    
         public void OnMenuChanged(object sender, EventArgs e) {
           if (Game1.activeClickableMenu != null && Game1.activeClickableMenu is ShopMenu && !shopReplaced) {
             ShopMenu shop = (ShopMenu) Game1.activeClickableMenu;
             if (shop.portraitPerson != null && shop.portraitPerson.name.Equals("Marlon")) {
               Dictionary<Item, int[]> shopList = new Dictionary<Item, int[]>();
    
               AddWeapons(shopList);
               AddBoots(shopList);
               AddRings(shopList);
               AddHats(shopList);
    
               shopReplaced = true;
               Game1.activeClickableMenu = new ShopMenu(shopList, 0, "Marlon");
             }
           }
         }
    
         public void OnMenuClosed(object sender, EventArgs e) {
           shopReplaced = false;
         }
    
         public void AddWeapons(Dictionary<Item, int[]> shopList) {
           bool sellsWoodenBlade = false;
           bool sellsIronDirk = false;
           bool sellsSilverSaber = false;
           bool sellsPiratesSword = false;
           bool sellsCutlass = false;
           bool sellsWoodMallet = false;
           bool sellsClaymore = false;
           bool sellsTemplarsBlade = false;
           bool sellsBoneSword = false;
           bool sellsSteelFalchion = false;
           bool sellsLavaKatana = false;
           bool sellsGalaxySword = false;
           bool sellsGalaxyDagger = false;
           bool sellsGalaxyHammer = false;
           bool sellsInsectHead = false;
    
           foreach (ItemForSale entry in config.weaponList) {
             if (entry.itemID >= 0) {
               switch (entry.itemID) {
                 case 1: sellsSilverSaber = true;
                   break;
                 case 4: sellsGalaxySword = true;
                   break;
                 case 5: sellsBoneSword = true;
                   break;
                 case 7: sellsTemplarsBlade = true;
                   break;
                 case 9: sellsLavaKatana = true;
                   break;
                 case 10: sellsClaymore = true;
                   break;
                 case 12: sellsWoodenBlade = true;
                   break;
                 case 13: sellsInsectHead = true;
                   break;
                 case 17: sellsIronDirk = true;
                   break;
                 case 23: sellsGalaxyDagger = true;
                   break;
                 case 27: sellsWoodMallet = true;
                   break;
                 case 29: sellsGalaxyHammer = true;
                   break;
                 case 43: sellsPiratesSword = true;
                   break;
                 case 44: sellsCutlass = true;
                   break;
                 case 50: sellsSteelFalchion = true;
                   break;
                 default: break;
               }
    
               bool killRequirementMet = false;
               if (entry.requiredKillCount == 0 || entry.requiredKillTypes == null || entry.requiredKillTypes.Length == 0 || (entry.requiredKillTypes.Length == 1 && string.IsNullOrWhiteSpace(entry.requiredKillTypes[0]))) { killRequirementMet = true; }
               else {
                 int kills = 0;
                 foreach (string type in entry.requiredKillTypes) {
                   kills += Game1.stats.getMonstersKilled(type);
                 }
                 killRequirementMet = kills >= entry.requiredKillCount;
               }
    
               bool donationRequirementMet = entry.requiresAllDonations;
               if (entry.requiresAllDonations) {
                 if (entry.donatedItems != null && entry.donatedItems.Length > 0 && (entry.donatedItems.Length != 1 || entry.donatedItems[0] != -1)) {
                   foreach (int donationID in entry.donatedItems) {
                     if (!((LibraryMuseum) Game1.getLocationFromName("ArchaeologyHouse")).museumPieces.ContainsValue(donationID)) {
                       donationRequirementMet = false;
                       break;
                     }
                   }
                 }
               }
               else {
                 if (entry.donatedItems == null || entry.donatedItems.Length == 0 || (entry.donatedItems.Length == 1 && entry.donatedItems[0] == -1)) { donationRequirementMet = true; }
                 else {
                   foreach (int donationID in entry.donatedItems) {
                     if (((LibraryMuseum) Game1.getLocationFromName("ArchaeologyHouse")).museumPieces.ContainsValue(donationID)) {
                       donationRequirementMet = true;
                       break;
                     }
                   }
                 }
               }
    
               if (killRequirementMet && donationRequirementMet && Game1.mine.lowestLevelReached >= entry.mineLevelReached && (string.IsNullOrWhiteSpace(entry.mailReceived) || Game1.player.mailReceived.Contains(entry.mailReceived))) {
                 MeleeWeapon item = new MeleeWeapon(entry.itemID);
                 if (!entry.isUnique || !PlayerHasItem(item.name)) {
                   shopList.Add(item, new int[] {
                   entry.salePrice <= 0 ? item.getItemLevel() * item.getItemLevel() * 50 : entry.salePrice,
                   entry.isUnique ? 1 : int.MaxValue
                 });
                 }
               }
             }
           }
    
           if (config.keepDefaultsIfNotOverwritten) {
             if (!sellsWoodenBlade) { shopList.Add(new MeleeWeapon(12), new int[] { 250, int.MaxValue }); }
             if (!sellsIronDirk && Game1.mine.lowestLevelReached >= 15) { shopList.Add(new MeleeWeapon(17), new int[] { 500, int.MaxValue }); }
             if (!sellsSilverSaber && Game1.mine.lowestLevelReached >= 20) { shopList.Add(new MeleeWeapon(1), new int[] { 750, int.MaxValue }); }
             if (!sellsPiratesSword && Game1.mine.lowestLevelReached >= 25) { shopList.Add(new MeleeWeapon(43), new int[] { 850, int.MaxValue }); }
             if (!sellsCutlass && Game1.mine.lowestLevelReached >= 25) { shopList.Add(new MeleeWeapon(44), new int[] { 1500, int.MaxValue }); }
             if (!sellsWoodMallet && Game1.mine.lowestLevelReached >= 40) { shopList.Add(new MeleeWeapon(27), new int[] { 2000, int.MaxValue }); }
             if (!sellsClaymore && Game1.mine.lowestLevelReached >= 45) { shopList.Add(new MeleeWeapon(10), new int[] { 2000, int.MaxValue }); }
             if (!sellsTemplarsBlade && Game1.mine.lowestLevelReached >= 55) { shopList.Add(new MeleeWeapon(7), new int[] { 4000, int.MaxValue }); }
             if (!sellsBoneSword && Game1.mine.lowestLevelReached >= 75) { shopList.Add(new MeleeWeapon(5), new int[] { 6000, int.MaxValue }); }
             if (!sellsSteelFalchion && Game1.mine.lowestLevelReached >= 90) { shopList.Add(new MeleeWeapon(50), new int[] { 9000, int.MaxValue }); }
             if (!sellsLavaKatana && Game1.mine.lowestLevelReached >= 120) { shopList.Add(new MeleeWeapon(9), new int[] { 25000, int.MaxValue }); }
             if (!sellsInsectHead && Game1.player.mailReceived.Contains("Gil_Insect Head")) { shopList.Add(new MeleeWeapon(13), new int[] { 10000, int.MaxValue }); }
             if (Game1.player.mailReceived.Contains("galaxySword")) {
               if (!sellsGalaxySword) { shopList.Add(new MeleeWeapon(4), new int[] { 50000, int.MaxValue }); }
               if (!sellsGalaxyDagger) { shopList.Add(new MeleeWeapon(23), new int[] { 35000, int.MaxValue }); }
               if (!sellsGalaxyHammer) { shopList.Add(new MeleeWeapon(29), new int[] { 75000, int.MaxValue }); }
             }
    
             
           }
         }
    
         public void AddBoots(Dictionary<Item, int[]> shopList) {
           bool sellsSneakers = false;
           bool sellsCombatBoots = false;
           bool sellsDarkBoots = false;
    
           foreach (ItemForSale entry in config.bootList) {
             if (entry.itemID >= 0) {
               switch (entry.itemID) {
                 case 504: sellsSneakers = true;
                   break;
                 case 508: sellsCombatBoots = true;
                   break;
                 case 511: sellsDarkBoots = true;
                   break;
                 default: break;
               }
    
               bool killRequirementMet = false;
               if (entry.requiredKillCount == 0 || entry.requiredKillTypes == null || entry.requiredKillTypes.Length == 0 || (entry.requiredKillTypes.Length == 1 && string.IsNullOrWhiteSpace(entry.requiredKillTypes[0]))) { killRequirementMet = true; }
               else {
                 int kills = 0;
                 foreach (string type in entry.requiredKillTypes) {
                   kills += Game1.stats.getMonstersKilled(type);
                 }
                 killRequirementMet = kills >= entry.requiredKillCount;
               }
    
               bool donationRequirementMet = entry.requiresAllDonations;
               if (entry.requiresAllDonations) {
                 if (entry.donatedItems != null && entry.donatedItems.Length > 0 && (entry.donatedItems.Length != 1 || entry.donatedItems[0] != -1)) {
                   foreach (int donationID in entry.donatedItems) {
                     if (!((LibraryMuseum) Game1.getLocationFromName("ArchaeologyHouse")).museumPieces.ContainsValue(donationID)) {
                       donationRequirementMet = false;
                       break;
                     }
                   }
                 }
               }
               else {
                 if (entry.donatedItems == null || entry.donatedItems.Length == 0 || (entry.donatedItems.Length == 1 && entry.donatedItems[0] == -1)) { donationRequirementMet = true; }
                 else {
                   foreach (int donationID in entry.donatedItems) {
                     if (((LibraryMuseum) Game1.getLocationFromName("ArchaeologyHouse")).museumPieces.ContainsValue(donationID)) {
                       donationRequirementMet = true;
                       break;
                     }
                   }
                 }
               }
    
               if (killRequirementMet && donationRequirementMet && entry.mineLevelReached <= Game1.mine.lowestLevelReached && (string.IsNullOrWhiteSpace(entry.mailReceived) || Game1.player.mailReceived.Contains(entry.mailReceived))) {
                 Boots item = new Boots(entry.itemID);
                 if (!entry.isUnique || !PlayerHasItem(item.name)) {
                   shopList.Add(item, new int[] {
                     entry.salePrice <= 0 ? item.salePrice() * 8 : entry.salePrice,
                     entry.isUnique ? 1 : int.MaxValue
                   });
                 }
               }
             }
           }
    
           if (config.keepDefaultsIfNotOverwritten) {
             if (!sellsSneakers) { shopList.Add(new Boots(504), new int[] { 500, int.MaxValue }); }
             if (!sellsCombatBoots && Game1.mine.lowestLevelReached >= 40) { shopList.Add(new Boots(508), new int[] { 1250, int.MaxValue }); }
             if (!sellsDarkBoots && Game1.mine.lowestLevelReached >= 80) { shopList.Add(new Boots(511), new int[] { 2500, int.MaxValue }); }
           }
         }
    
         public void AddRings(Dictionary<Item, int[]> shopList) {
           bool sellsSlimeCharmerRing = false;
           bool sellsVampireRing = false;
           bool sellsSavageRing = false;
           bool sellsBurglarsRing = false;
           bool sellsAmethystRing = false;
           bool sellsTopazRing = false;
           bool sellsAquamarineRing = false;
           bool sellsJadeRing = false;
           bool sellsEmeraldRing = false;
           bool sellsRubyRing = false;
    
           foreach (ItemForSale entry in config.ringList) {
             if (entry.itemID > 515 && entry.itemID < 535 && (entry.itemID != 530 || !config.removeTopazRing)) {
               switch (entry.itemID) {
                 case 520: sellsSlimeCharmerRing = true;
                   break;
                 case 522: sellsVampireRing = true;
                   break;
                 case 523: sellsSavageRing = true;
                   break;
                 case 526: sellsBurglarsRing = true;
                   break;
                 case 529: sellsAmethystRing = true;
                   break;
                 case 530: sellsTopazRing = true;
                   break;
                 case 531: sellsAquamarineRing = true;
                   break;
                 case 532: sellsJadeRing = true;
                   break;
                 case 533: sellsEmeraldRing = true;
                   break;
                 case 534: sellsRubyRing = true;
                   break;
                 default: break;
               }
    
               bool killRequirementMet = false;
               if (entry.requiredKillCount == 0 || entry.requiredKillTypes == null || entry.requiredKillTypes.Length == 0 || (entry.requiredKillTypes.Length == 1 && string.IsNullOrWhiteSpace(entry.requiredKillTypes[0]))) { killRequirementMet = true; }
               else {
                 int kills = 0;
                 foreach (string type in entry.requiredKillTypes) {
                   kills += Game1.stats.getMonstersKilled(type);
                 }
                 killRequirementMet = kills >= entry.requiredKillCount;
               }
    
               bool donationRequirementMet = entry.requiresAllDonations;
               if (entry.requiresAllDonations) {
                 if (entry.donatedItems != null && entry.donatedItems.Length > 0 && (entry.donatedItems.Length != 1 || entry.donatedItems[0] != -1)) {
                   foreach (int donationID in entry.donatedItems) {
                     if (!((LibraryMuseum) Game1.getLocationFromName("ArchaeologyHouse")).museumPieces.ContainsValue(donationID)) {
                       donationRequirementMet = false;
                       break;
                     }
                   }
                 }
               }
               else {
                 if (entry.donatedItems == null || entry.donatedItems.Length == 0 || (entry.donatedItems.Length == 1 && entry.donatedItems[0] == -1)) { donationRequirementMet = true; }
                 else {
                   foreach (int donationID in entry.donatedItems) {
                     if (((LibraryMuseum) Game1.getLocationFromName("ArchaeologyHouse")).museumPieces.ContainsValue(donationID)) {
                       donationRequirementMet = true;
                       break;
                     }
                   }
                 }
               }
    
               if (killRequirementMet && donationRequirementMet && entry.mineLevelReached <= Game1.mine.lowestLevelReached && (string.IsNullOrWhiteSpace(entry.mailReceived) || Game1.player.mailReceived.Contains(entry.mailReceived))) {
                 Ring item = new Ring(entry.itemID);
                 if (!entry.isUnique || !PlayerHasItem(item.name)) {
                   shopList.Add(item, new int[] {
                     entry.salePrice < 1 ? item.salePrice() * 12 : entry.salePrice,
                     entry.isUnique ? 1 : int.MaxValue
                   });
                 }
               }
             }
           }
    
           if (config.keepDefaultsIfNotOverwritten) {
             if (!sellsAmethystRing) { shopList.Add(new Ring(529), new int[] { 1000, int.MaxValue }); }
             if (!sellsTopazRing && !config.removeTopazRing) { shopList.Add(new Ring(530), new int[] { 1000, int.MaxValue }); }
             if (!sellsAquamarineRing && Game1.mine.lowestLevelReached >= 40) { shopList.Add(new Ring(531), new int[] { 2500, int.MaxValue });  }
             if (!sellsJadeRing && Game1.mine.lowestLevelReached >= 40) { shopList.Add(new Ring(532), new int[] { 2500, int.MaxValue }); }
             if (!sellsEmeraldRing && Game1.mine.lowestLevelReached >= 80) { shopList.Add(new Ring(533), new int[] { 5000, int.MaxValue }); }
             if (!sellsRubyRing && Game1.mine.lowestLevelReached >= 80) { shopList.Add(new Ring(534), new int[] { 5000, int.MaxValue }); }
    
             if (!sellsVampireRing && Game1.player.mailReceived.Contains("Gil_Vampire Ring")) { shopList.Add(new Ring(522), new int[] { 15000, int.MaxValue }); }
             if (!sellsBurglarsRing && Game1.player.mailReceived.Contains("Gil_Burglar's Ring")) { shopList.Add(new Ring(526), new int[] { 20000, int.MaxValue }); }
             if (!sellsSavageRing && Game1.player.mailReceived.Contains("Gil_Savage Ring")) { shopList.Add(new Ring(523), new int[] { 25000, int.MaxValue }); }
             if (!sellsSlimeCharmerRing && Game1.player.mailReceived.Contains("Gil_Slime Charmer Ring")) { shopList.Add(new Ring(520), new int[] { 25000, int.MaxValue }); }
           }
         }
    
         public void AddHats(Dictionary<Item, int[]> shopList) {
           bool sellsSkeletonMask = false;
           bool sellsHardHat = false;
    
           foreach (ItemForSale entry in config.hatList) {
             if (entry.itemID >= 0) {
               switch (entry.itemID) {
                 case 8: sellsSkeletonMask = true;
                   break;
                 case 27: sellsHardHat = true;
                   break;
                 default: break;
               }
    
               bool killRequirementMet = false;
               if (entry.requiredKillCount == 0 || entry.requiredKillTypes == null || entry.requiredKillTypes.Length == 0 || (entry.requiredKillTypes.Length == 1 && string.IsNullOrWhiteSpace(entry.requiredKillTypes[0]))) { killRequirementMet = true; }
               else {
                 int kills = 0;
                 foreach (string type in entry.requiredKillTypes) {
                   kills += Game1.stats.getMonstersKilled(type);
                 }
                 killRequirementMet = kills >= entry.requiredKillCount;
               }
    
               bool donationRequirementMet = entry.requiresAllDonations;
               if (entry.requiresAllDonations) {
                 if (entry.donatedItems != null && entry.donatedItems.Length > 0 && (entry.donatedItems.Length != 1 || entry.donatedItems[0] != -1)) {
                   foreach (int donationID in entry.donatedItems) {
                     if (!((LibraryMuseum) Game1.getLocationFromName("ArchaeologyHouse")).museumPieces.ContainsValue(donationID)) {
                       donationRequirementMet = false;
                       break;
                     }
                   }
                 }
               }
               else {
                 if (entry.donatedItems == null || entry.donatedItems.Length == 0 || (entry.donatedItems.Length == 1 && entry.donatedItems[0] == -1)) { donationRequirementMet = true; }
                 else {
                   foreach (int donationID in entry.donatedItems) {
                     if (((LibraryMuseum) Game1.getLocationFromName("ArchaeologyHouse")).museumPieces.ContainsValue(donationID)) {
                       donationRequirementMet = true;
                       break;
                     }
                   }
                 }
               }
    
               if (killRequirementMet && donationRequirementMet && entry.mineLevelReached <= Game1.mine.lowestLevelReached && (string.IsNullOrWhiteSpace(entry.mailReceived) || Game1.player.mailReceived.Contains(entry.mailReceived))) {
                 Hat item = new Hat(entry.itemID);
                 if (!entry.isUnique || !PlayerHasItem(item.name)) {
                   shopList.Add(item, new int[] {
                     entry.salePrice < 1 ? 20000 : entry.salePrice,
                     entry.isUnique ? 1 : int.MaxValue
                   });
                 }
               }
             }
           }
    
           if (config.keepDefaultsIfNotOverwritten) {
             if (!sellsSkeletonMask && Game1.player.mailReceived.Contains("Gil_Skeleton Mask")) { shopList.Add(new Hat(8), new int[] { 20000, int.MaxValue }); }
             if (!sellsHardHat && Game1.player.mailReceived.Contains("Gil_Hard Hat")) { shopList.Add(new Hat(27), new int[] { 20000, int.MaxValue }); }
           }
         }
    
         public bool PlayerHasItem(string itemName) {
           if (Game1.player.hasItemWithNameThatContains(itemName) != null) { return true; }
           if (Game1.player.boots != null && Game1.player.boots.name.Equals(itemName)) { return true; }
           if (Game1.player.leftRing != null && Game1.player.leftRing.name.Equals(itemName)) { return true; }
           if (Game1.player.rightRing != null && Game1.player.rightRing.name.Equals(itemName)) { return true; }
           if (Game1.player.hat != null && Game1.player.hat.name.Equals(itemName)) { return true; }
           foreach (GameLocation loc in Game1.locations) {
             foreach (StardewValley.Object obj in loc.objects.Values) {
               if (obj is Chest && ((Chest) obj).playerChest) {
                 Chest chest = (Chest) obj;
                 foreach (Item i in chest.items) {
                   if (i.Name.Equals(itemName)) { return true; }
                 }
               }
             }
           }
    
           return false;
         }
       }
    
       public class Config {
         public bool keepDefaultsIfNotOverwritten { get; set; }
         public bool removeTopazRing { get; set; }
         public ItemForSale[] weaponList { get; set; }
         public ItemForSale[] bootList { get; set; }
         public ItemForSale[] ringList { get; set; }
         public ItemForSale[] hatList { get; set; }
    
         public Config() {
           keepDefaultsIfNotOverwritten = true;
           removeTopazRing = true;
           weaponList = new ItemForSale[] { new ItemForSale() };
           bootList = new ItemForSale[] { new ItemForSale() };
           ringList = new ItemForSale[] { new ItemForSale() };
           hatList = new ItemForSale[] { new ItemForSale() };
         }
       }
    
       public class ItemForSale {
         public int itemID { get; set; } = -1;
         public bool isUnique { get; set; } = false;
         public int salePrice { get; set; } = -1;
         public int mineLevelReached { get; set; } = -1;
         public string mailReceived { get; set; } = "";
         public int requiredKillCount { get; set; } = 0;
         public string[] requiredKillTypes { get; set; } = new string[] { "" };
         public bool requiresAllDonations { get; set; } = false;
         public int[] donatedItems { get; set; } = new int[] { -1 };
       }
    }
    
Return to update list...