diff --git a/StackSizeController.cs b/StackSizeController.cs index 2bfd0ab..7cedc1d 100644 --- a/StackSizeController.cs +++ b/StackSizeController.cs @@ -10,17 +10,18 @@ namespace Oxide.Plugins { - [Info("Stack Size Controller", "AnExiledDev", "4.1.1")] + [Info("Stack Size Controller", "AnExiledDev/optimized by WouayNote", "4.1.3")] [Description("Allows configuration of most items max stack size.")] class StackSizeController : CovalencePlugin { [PluginReference] Plugin AirFuel, GetToDaChoppa, VehicleVendorOptions; - private const string _vanillaDefaultsUri = "https://raw.githubusercontent.com/AnExiledDev/StackSizeController/master/vanilla-defaults.json"; + private const string _vanillaDefaultsUri = "https://raw.githubusercontent.com/WouayNote/StackSizeController/master/vanilla-defaults.json"; private Configuration _config; private Dictionary _vanillaDefaults; + private Dictionary _computedStackSizesByItemId = new Dictionary(); private readonly List _ignoreList = new List { @@ -266,7 +267,7 @@ private string GetMessage(string key, string playerId) // Credit to WhiteThunder- https://github.com/AnExiledDev/StackSizeController/pull/7 // Fix initial fuel amount for vendor-spawned helis since they use 20% of max stack size of low grade. - private void OnEntitySpawned(MiniCopter heli) + private void OnEntitySpawned(Minicopter heli) { // Ignore if a known plugin is loaded that adjusts heli fuel. if (AirFuel != null || GetToDaChoppa != null || VehicleVendorOptions != null) @@ -391,8 +392,7 @@ private void ItemSearchCommand(IPlayer player, string command, string[] args) { if (args.Length != 1) { - player.Reply( - string.Format(GetMessage("NotEnoughArguments", player.Id), 1)); + player.Reply(string.Format(GetMessage("NotEnoughArguments", player.Id), 1)); } List itemDefinitions = ItemManager.itemList.Where(itemDefinition => @@ -407,8 +407,9 @@ private void ItemSearchCommand(IPlayer player, string command, string[] args) foreach (ItemDefinition itemDefinition in itemDefinitions) { + int vanillaStackSize = _vanillaDefaults.TryGetValue(itemDefinition.shortname, out vanillaStackSize) ? vanillaStackSize : itemDefinition.stackable; output.AddRow(itemDefinition.itemid.ToString(), itemDefinition.shortname, - itemDefinition.category.ToString(), _vanillaDefaults[itemDefinition.shortname].ToString("N0"), + itemDefinition.category.ToString(), vanillaStackSize.ToString("N0"), Mathf.Clamp(GetStackSize(itemDefinition), 0, int.MaxValue).ToString("N0")); } @@ -443,8 +444,9 @@ private void ListCategoryItemsCommand(IPlayer player, string command, string[] a foreach (ItemDefinition itemDefinition in ItemManager.GetItemDefinitions() .Where(itemDefinition => itemDefinition.category == itemCategory)) { + int vanillaStackSize = _vanillaDefaults.TryGetValue(itemDefinition.shortname, out vanillaStackSize) ? vanillaStackSize : itemDefinition.stackable; output.AddRow(itemDefinition.itemid.ToString(), itemDefinition.shortname, - itemDefinition.category.ToString(), _vanillaDefaults[itemDefinition.shortname].ToString("N0"), + itemDefinition.category.ToString(), vanillaStackSize.ToString("N0"), Mathf.Clamp(GetStackSize(itemDefinition), 0, int.MaxValue).ToString("N0"), _config.CategoryStackMultipliers[itemDefinition.category.ToString()].ToString()); } @@ -521,8 +523,8 @@ private void SetVanillaDefaults(int code, string response) private int GetVanillaStackSize(ItemDefinition itemDefinition) { - return _vanillaDefaults.ContainsKey(itemDefinition.shortname) - ? _vanillaDefaults[itemDefinition.shortname] + return _vanillaDefaults.TryGetValue(itemDefinition.shortname, out int vanillaStackSize) + ? vanillaStackSize : itemDefinition.stackable; } @@ -535,45 +537,51 @@ private int GetStackSize(ItemDefinition itemDefinition) { try { - if (_ignoreList.Contains(itemDefinition.shortname)) + // Cached Stack Size + if (this._computedStackSizesByItemId.TryGetValue(itemDefinition.itemid, out int stackSize)) { - return GetVanillaStackSize(itemDefinition); + return stackSize; } - - int stackable = GetVanillaStackSize(itemDefinition); - - // Individual Limit set by shortname - if (_config.IndividualItemStackSize.ContainsKey(itemDefinition.shortname)) - { - stackable = _config.IndividualItemStackSize[itemDefinition.shortname]; - } - - // Individual Multiplier set by shortname - if (_config.IndividualItemStackMultipliers.ContainsKey(itemDefinition.shortname)) - { - return Mathf.RoundToInt(stackable * _config.IndividualItemStackMultipliers[itemDefinition.shortname]); - } - - // Individual Multiplier set by item id - if (_config.IndividualItemStackMultipliers.ContainsKey(itemDefinition.itemid.ToString())) + // Ignored Items + if (_ignoreList.Contains(itemDefinition.shortname)) { - return Mathf.RoundToInt(stackable * _config.IndividualItemStackMultipliers[itemDefinition.itemid.ToString()]); + stackSize = GetVanillaStackSize(itemDefinition); } - - // Category stack multiplier defined - if (_config.CategoryStackMultipliers.ContainsKey(itemDefinition.category.ToString()) && - _config.CategoryStackMultipliers[itemDefinition.category.ToString()] > 1.0f) + else { - return Mathf.RoundToInt( - stackable * _config.CategoryStackMultipliers[itemDefinition.category.ToString()]); + // Individual Limit + if (!_config.IndividualItemStackSize.TryGetValue(itemDefinition.shortname, out int stackable)) + { + stackable = GetVanillaStackSize(itemDefinition); + } + // Individual Multiplier set by shortname + if (_config.IndividualItemStackMultipliers.TryGetValue(itemDefinition.shortname, out float stackMultiplierOfShortName)) + { + stackSize = Mathf.RoundToInt(stackable * stackMultiplierOfShortName); + } + // Individual Multiplier set by item id + else if (_config.IndividualItemStackMultipliers.TryGetValue(itemDefinition.itemid.ToString(), out float stackMultiplierOfId)) + { + stackSize = Mathf.RoundToInt(stackable * stackMultiplierOfId); + } + // Category stack multiplier defined + else if (_config.CategoryStackMultipliers.TryGetValue(itemDefinition.category.ToString(), out float stackMultiplierOfCategory) && stackMultiplierOfCategory > 1.0f) + { + stackSize = Mathf.RoundToInt(stackable * stackMultiplierOfCategory); + } + // Global stack multiplier + else + { + stackSize = Mathf.RoundToInt(stackable * _config.GlobalStackMultiplier); + } } - - return Mathf.RoundToInt(stackable * _config.GlobalStackMultiplier); + // Cache Computed Stack Size + this._computedStackSizesByItemId.Add(itemDefinition.itemid, stackSize); + return stackSize; } catch (Exception ex) { LogError("Exception encountered during GetStackSize. Item: " + itemDefinition.shortname + " Ex:" + ex.ToString()); - return GetVanillaStackSize(itemDefinition); } } @@ -596,6 +604,8 @@ private void SetStackSizes() itemDefinition.stackable = Mathf.Clamp(GetStackSize(itemDefinition), 1, int.MaxValue); } + // Invalidate Stack Size Cache + _computedStackSizesByItemId.Clear(); } private void RevertStackSizes() @@ -616,6 +626,8 @@ private void RevertStackSizes() itemDefinition.stackable = Mathf.Clamp(GetVanillaStackSize(itemDefinition), 1, int.MaxValue); } + // Invalidate Stack Size Cache + _computedStackSizesByItemId.Clear(); } #endregion diff --git a/vanilla-defaults.json b/vanilla-defaults.json index 202ce86..7f8c465 100644 --- a/vanilla-defaults.json +++ b/vanilla-defaults.json @@ -18,6 +18,7 @@ "ammo.rocket.hv": 3, "ammo.rocket.mlrs": 6, "ammo.rocket.sam": 1000, + "ammo.rocket.seeker": 4, "ammo.rocket.smoke": 3, "ammo.shotgun": 64, "ammo.shotgun.fire": 64, @@ -31,9 +32,11 @@ "arrow.fire": 64, "arrow.hv": 64, "arrow.wooden": 64, + "attackhelicopter": 1, "attire.banditguard": 1, "attire.bunny.onesie": 1, "attire.bunnyears": 1, + "attire.egg.suit": 1, "attire.hide.boots": 1, "attire.hide.helterneck": 1, "attire.hide.pants": 1, @@ -71,6 +74,8 @@ "blood": 1000, "blue.berry": 20, "blueberries": 20, + "bluedogtags": 5000, + "blueidtag": 5000, "blueprintbase": 1000, "bone.armor.suit": 1, "bone.club": 1, @@ -117,13 +122,15 @@ "ceilinglight": 10, "chainsaw": 1, "chair": 5, + "chair.icethrone": 5, "charcoal": 1000, "chicken.burned": 20, "chicken.cooked": 20, "chicken.raw": 20, "chicken.spoiled": 20, "chineselantern": 1, - "chocholate": 10, + "chocolate": 10, + "clantable": 1, "clatter.helmet": 1, "clone.black.berry": 50, "clone.blue.berry": 50, @@ -141,6 +148,8 @@ "coffin.storage": 1, "composter": 1, "computerstation": 1, + "concretehatchet": 1, + "concretepickaxe": 1, "connected.speaker": 5, "corn": 20, "crankshaft1": 5, @@ -159,10 +168,14 @@ "discoball": 5, "discofloor": 5, "discofloor.largetiles": 5, + "diverhatchet": 1, + "diverpickaxe": 1, + "divertorch": 1, "diving.fins": 1, "diving.mask": 1, "diving.tank": 1, "diving.wetsuit": 1, + "dogtagneutral": 5000, "door.closer": 1, "door.double.hinged.metal": 1, "door.double.hinged.toptier": 1, @@ -172,6 +185,8 @@ "door.hinged.toptier": 1, "door.hinged.wood": 1, "door.key": 1, + "draculacape": 1, + "draculamask": 1, "dragondoorknocker": 1, "drone": 1, "dropbox": 5, @@ -195,6 +210,7 @@ "electric.doorcontroller": 5, "electric.flasherlight": 5, "electric.fuelgenerator.small": 1, + "electric.furnace": 1, "electric.generator.small": 1, "electric.hbhfsensor": 1, "electric.heater": 5, @@ -264,7 +280,7 @@ "floor.triangle.ladder.hatch": 1, "fluid.combiner": 5, "fluid.splitter": 5, - "fluid.switch": 1, + "fluid.switch": 5, "fogmachine": 1, "frankensteins.monster.01.head": 1, "frankensteins.monster.01.legs": 1, @@ -298,18 +314,28 @@ "ghostsheet": 1, "giantcandycanedecor": 1, "giantlollipops": 1, + "gingerbreadsuit": 1, "gloweyes": 1, "glue": 10, "granolabar": 10, "gravestone": 1, + "grayidtag": 5000, "green.berry": 20, + "greenidtag": 5000, "grenade.beancan": 5, "grenade.f1": 5, + "grenade.flashbang": 5, + "grenade.molotov": 5, "grenade.smoke": 3, "grub": 20, "gun.water": 1, "gunpowder": 1000, + "gunrack.horizontal": 10, + "gunrack_stand": 10, + "gunrack_tall.horizontal": 10, + "gunrack_wide.horizontal": 10, "guntrap": 1, + "hab.armor": 1, "habrepair": 1, "halloween.candy": 1000, "halloween.lootbag.large": 10, @@ -328,13 +354,20 @@ "hat.gas.mask": 1, "hat.miner": 1, "hat.oxmask": 1, + "hat.rabbitmask": 1, "hat.ratmask": 1, + "hat.tigermask": 1, "hat.wolf": 1, "hatchet": 1, "hazmatsuit": 1, + "hazmatsuit.arcticsuit": 1, + "hazmatsuit.diver": 1, + "hazmatsuit.lumberjack": 1, "hazmatsuit.nomadsuit": 1, "hazmatsuit.spacesuit": 1, "hazmatsuit_scientist": 1, + "hazmatsuit_scientist_arctic": 1, + "hazmatsuit_scientist_nvgm": 1, "hazmatsuit_scientist_peacekeeper": 1, "healingtea": 10, "healingtea.advanced": 10, @@ -343,11 +376,15 @@ "heavy.plate.jacket": 1, "heavy.plate.pants": 1, "hitchtroughcombo": 1, + "hmlmg": 1, "hobobarrel": 1, + "homingmissile.launcher": 1, "hoodie": 1, "horse.armor.roadsign": 1, "horse.armor.wood": 1, "horse.saddle": 1, + "horse.saddle.double": 1, + "horse.saddle.single": 1, "horse.saddlebag": 1, "horse.shoes.advanced": 1, "horse.shoes.basic": 1, @@ -356,12 +393,16 @@ "horsemeat.cooked": 20, "horsemeat.raw": 20, "hosetool": 1, - "hq.metal.ore": 1000, + "hq.metal.ore": 100, "humanmeat.burned": 20, "humanmeat.cooked": 20, "humanmeat.raw": 20, "humanmeat.spoiled": 20, "icepick.salvaged": 1, + "industrial.combiner": 5, + "industrial.conveyor": 5, + "industrial.crafter": 5, + "industrial.splitter": 5, "industrial.wall.light": 10, "industrial.wall.light.green": 10, "industrial.wall.light.red": 10, @@ -393,11 +434,15 @@ "lock.code": 10, "lock.key": 10, "locker": 1, + "locomotive": 1, "longsword": 1, "lowgradefuel": 500, "lumberjack hoodie": 1, + "lumberjack.hatchet": 1, + "lumberjack.pickaxe": 1, "lunar.firecrackers": 5, "mace": 1, + "mace.baseballbat": 1, "machete": 1, "mailbox": 1, "map": 1, @@ -411,9 +456,12 @@ "meat.pork.cooked": 20, "megaphone": 1, "metal.facemask": 1, + "metal.facemask.hockey": 1, + "metal.facemask.icemask": 1, "metal.fragments": 1000, "metal.ore": 1000, "metal.plate.torso": 1, + "metal.plate.torso.icevest": 1, "metal.refined": 100, "metalblade": 20, "metalpipe": 20, @@ -433,6 +481,7 @@ "newyeargong": 1, "nightvisiongoggles": 1, "note": 1, + "orangeidtag": 5000, "oretea": 10, "oretea.advanced": 10, "oretea.pure": 10, @@ -441,6 +490,8 @@ "pants": 1, "pants.shorts": 1, "paper": 1000, + "parachute": 1, + "parachute.deployed": 1, "partyhat": 1, "photo": 1, "photoframe.landscape": 1, @@ -448,9 +499,12 @@ "photoframe.portrait": 1, "piano": 1, "pickaxe": 1, + "pinkidtag": 5000, + "pipetool": 1, "pistol.eoka": 1, "pistol.m92": 1, "pistol.nailgun": 1, + "pistol.prototype17": 1, "pistol.python": 1, "pistol.revolver": 1, "pistol.semiauto": 1, @@ -464,10 +518,12 @@ "plantfiber": 1000, "pookie.bear": 1, "potato": 20, - "powered.water.purifier": 1, + "powered.water.purifier": 3, "propanetank": 5, + "ptz.cctv.camera": 5, "pumpkin": 20, "pumpkinbasket": 1, + "purpleidtag": 5000, "radiationremovetea": 10, "radiationremovetea.advanced": 10, "radiationremovetea.pure": 10, @@ -475,11 +531,16 @@ "radiationresisttea.advanced": 10, "radiationresisttea.pure": 10, "red.berry": 20, + "reddogtags": 5000, + "redidtag": 5000, "research.table": 1, "researchpaper": 1000, "rf.detonator": 1, "rf_pager": 1, + "rhib": 1, "rifle.ak": 1, + "rifle.ak.diver": 1, + "rifle.ak.ice": 1, "rifle.bolt": 1, "rifle.l96": 1, "rifle.lr300": 1, @@ -494,6 +555,7 @@ "rock": 1, "rocket.launcher": 1, "rope": 50, + "rowboat": 1, "rug": 1, "rug.bear": 1, "rustige_egg_a": 1, @@ -501,6 +563,7 @@ "rustige_egg_c": 1, "rustige_egg_d": 1, "rustige_egg_e": 1, + "rustige_egg_f": 1, "salvaged.cleaver": 1, "salvaged.sword": 1, "samsite": 1, @@ -542,6 +605,7 @@ "shutter.metal.embrasure.b": 20, "shutter.wood.a": 20, "sickle": 1, + "sign.egg.suit": 5, "sign.hanging": 5, "sign.hanging.banner.large": 5, "sign.hanging.ornate": 5, @@ -560,10 +624,10 @@ "sign.post.single": 5, "sign.post.town": 5, "sign.post.town.roof": 5, - "sign.wooden.huge": 5, - "sign.wooden.large": 5, - "sign.wooden.medium": 5, - "sign.wooden.small": 5, + "sign.wooden.huge": 1, + "sign.wooden.large": 1, + "sign.wooden.medium": 1, + "sign.wooden.small": 1, "skull": 1, "skull.human": 1, "skull.trophy": 1, @@ -576,6 +640,11 @@ "skullspikes": 1, "skullspikes.candles": 1, "skullspikes.pumpkin": 1, + "skylantern": 20, + "skylantern.skylantern.green": 20, + "skylantern.skylantern.orange": 20, + "skylantern.skylantern.purple": 20, + "skylantern.skylantern.red": 20, "sled": 1, "sled.xmas": 1, "sleepingbag": 1, @@ -592,6 +661,8 @@ "snowballgun": 1, "snowmachine": 1, "snowman": 5, + "snowmobile": 1, + "snowmobiletomaha": 1, "sofa": 2, "sofa.pattern": 2, "soundlight": 5, @@ -606,6 +677,8 @@ "spikes.floor": 10, "spinner.wheel": 1, "spookyspeaker": 1, + "spraycan": 1, + "spraycandecal": 10, "stash.small": 5, "sticks": 100, "stocking.large": 1, @@ -614,7 +687,9 @@ "stonehatchet": 1, "stones": 1000, "storage.monitor": 1, + "storageadaptor": 5, "strobelight": 1, + "submarine.torpedo.rising": 100, "submarine.torpedo.straight": 100, "submarineduo": 1, "submarinesolo": 1, @@ -627,6 +702,7 @@ "sunglasses03black": 1, "sunglasses03chrome": 1, "sunglasses03gold": 1, + "supertea": 1, "supply.signal": 1, "surveycharge": 10, "syringe.medical": 2, @@ -642,16 +718,20 @@ "tool.instant_camera": 1, "toolgun": 1, "torch": 1, + "torch.torch.skull": 1, "trap.bear": 3, "trap.landmine": 5, + "trophy": 1, "tshirt": 1, "tshirt.long": 1, + "tugboat": 1, "tunalight": 1, "twitch.headset": 1, "twitchsunglasses": 1, "valve1": 15, "valve2": 15, "valve3": 15, + "vampire.stake": 1, "vehicle.1mod.cockpit": 1, "vehicle.1mod.cockpit.armored": 1, "vehicle.1mod.cockpit.with.engine": 1, @@ -671,6 +751,7 @@ "vehicle.chassis.4mod": 1, "vehicle.module": 1, "vending.machine": 1, + "wagon": 1, "wall.external.high": 10, "wall.external.high.ice": 10, "wall.external.high.stone": 10, @@ -684,6 +765,7 @@ "wall.frame.shopfront.metal": 1, "wall.graveyard.fence": 10, "wall.ice.wall": 10, + "wall.window.bars.brickskin": 10, "wall.window.bars.metal": 10, "wall.window.bars.toptier": 10, "wall.window.bars.wood": 10, @@ -696,8 +778,10 @@ "water.purifier": 1, "water.salt": 2147483647, "waterjug": 1, - "waterpump": 1, + "waterpump": 3, "weapon.mod.8x.scope": 1, + "weapon.mod.burstmodule": 1, + "weapon.mod.extendedmags": 1, "weapon.mod.flashlight": 1, "weapon.mod.holosight": 1, "weapon.mod.lasersight": 1, @@ -706,7 +790,10 @@ "weapon.mod.silencer": 1, "weapon.mod.simplesight": 1, "weapon.mod.small.scope": 1, + "weaponrack.doublelight": 1, + "weaponrack.light": 1, "white.berry": 20, + "whiteidtag": 5000, "wiretool": 1, "wolfmeat.burned": 20, "wolfmeat.cooked": 20, @@ -746,5 +833,6 @@ "xmas.window.garland": 10, "xmasdoorwreath": 1, "xylophone": 1, - "yellow.berry": 20 + "yellow.berry": 20, + "yellowidtag": 5000 } \ No newline at end of file