diff --git a/README.md b/README.md index 0b2bd1f..c9d323e 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ works with. The maintainers publish the releases of the mods in this repository. | [petloot](mods/petloot/) | optional pet pickup with per-character filters, minimum stacks, pause/resume and configurable 2x pet speed | | [zoom](mods/zoom/) | a wider view in normal play: the camera stands further back, the mouse wheel reaches it, `/zoom` sets how far | | [itemquantity](mods/itemquantity/) | 10× as many item drops | +| [mapdrop](mods/mapdrop/) | Configurable bonus map rolls for eligible kills | | [pob](mods/pob/) | preview and import character builds through an external converter; requires LocalExile #639 | | [itemrarity](mods/itemrarity/) | 10× the chance of magic, rare and unique equipment | diff --git a/mods.json b/mods.json index b2360d0..d56616d 100644 --- a/mods.json +++ b/mods.json @@ -8,6 +8,7 @@ { "id": "itemquantity", "name": "Item Quantity", "description": "10 times as many item drops from every kill.", "author": "LocalExile", "version": "1.1.4", "compatibleClientVersions": ["0.4.3-beta", "0.5.0-beta", "0.5.1-beta", "0.5.2-beta"], "kind": "feature", "type": "project", "path": "mods/itemquantity", "depends": [], "settings": true }, { "id": "itemrarity", "name": "Item Rarity", "description": "10 times the chance of magic, rare and unique equipment.", "author": "LocalExile", "version": "1.1.4", "compatibleClientVersions": ["0.4.3-beta", "0.5.0-beta", "0.5.1-beta", "0.5.2-beta"], "kind": "feature", "type": "project", "path": "mods/itemrarity", "depends": [], "settings": true }, { "id": "liveeconomy", "name": "Live Economy", "description": "Faustus's Currency Exchange as a live market: the official Path of Exile leagues' prices, a spread, depth, and orders that fill with time.", "author": "JetStream", "version": "1.1.4", "compatibleClientVersions": ["0.4.3-beta", "0.5.0-beta", "0.5.1-beta", "0.5.2-beta"], "kind": "feature", "type": "project", "path": "mods/liveeconomy", "depends": [], "settings": true }, + { "id": "mapdrop", "name": "Map Drop", "description": "Adds configurable bonus map drops in Atlas maps and optionally in the late campaign.", "author": "zj1022", "version": "1.0.0", "compatibleClientVersions": ["0.5.2-beta"], "kind": "feature", "type": "script", "path": "mods/mapdrop", "depends": [], "settings": true }, { "id": "petloot", "name": "Pet Loot", "description": "Worn pets collect selected currency with per-character filters and an immediate pause switch.", "author": "zj1022", "version": "1.1.0", "compatibleClientVersions": ["0.5.2-beta"], "kind": "feature", "type": "script", "path": "mods/petloot", "depends": ["Game", "Cosmetics"], "settings": true }, { "id": "pob", "name": "POB", "description": "Preview and import a character build through a configured external PoB converter.", "author": "nikolos89", "version": "1.0.3", "compatibleClientVersions": ["0.4.3-beta", "0.5.0-beta", "0.5.1-beta", "0.5.2-beta"], "kind": "feature", "type": "project", "path": "mods/pob", "depends": [], "settings": true }, { "id": "waypoint-tools", "name": "Waypoint Tools", "description": "Lets Waypoint's tools reach the game without the client control bridge: the item crafter gives its items through it.", "author": "Waypoint", "version": "1.0.3", "compatibleClientVersions": ["0.4.3-beta", "0.5.0-beta", "0.5.1-beta", "0.5.2-beta"], "kind": "feature", "type": "project", "path": "mods/waypoint-tools", "depends": ["Game"], "settings": false }, diff --git a/mods/mapdrop/MapDropMod.cs b/mods/mapdrop/MapDropMod.cs new file mode 100644 index 0000000..f9f3593 --- /dev/null +++ b/mods/mapdrop/MapDropMod.cs @@ -0,0 +1,47 @@ +using System.Text.Json.Nodes; +using GameServer.Core.Protocol.Instance; +using GameServer.Modding; + +namespace LocalExile.Mods.MapDrop; + +public sealed class MapDropMod : IMod +{ + public void Load(IModContext mod) + { + var settings = mod.Settings(); + var rates = new Dictionary + { + [MonsterRarity.Normal] = Chance(settings, "normal"), + [MonsterRarity.Magic] = Chance(settings, "magic"), + [MonsterRarity.Rare] = Chance(settings, "rare"), + [MonsterRarity.Unique] = Chance(settings, "unique"), + }; + bool campaign = settings["campaign"]?.GetValue() == true; + var atlas = new AtlasCatalog(Program.Items); + var keys = new string?[17]; + for (int tier = 1; tier < keys.Length; tier++) + if (atlas.KeyOfTier(tier) is uint hash && Program.Items.ByHash(hash) is { Supported: true } type) + keys[tier] = type.Id; + + GameEvents.Drops.Add(mod.Manifest.Id, drops => + { + int tier = drops.Conn.Instance?.Map is { } map && map.Area.Hash16 == drops.Conn.Layout.Hash + ? map.Area.Tier : 0; + if (tier <= 0) + { + if (!campaign || !LateCampaign(drops.Conn.Layout.Id)) return; + tier = 1; + } + if (keys[Math.Clamp(tier, 1, 16)] is { } key + && Random.Shared.NextDouble() < rates.GetValueOrDefault(drops.Monster.Rarity)) + drops.Items.Add(key); + }); + } + + static double Chance(JsonObject settings, string key) => + settings[key] is JsonValue value && value.TryGetValue(out double chance) && double.IsFinite(chance) + ? Math.Clamp(chance, 0, 1) : 0; + + static bool LateCampaign(string area) => area.StartsWith("2_8_", StringComparison.Ordinal) + || area.StartsWith("2_9_", StringComparison.Ordinal) || area.StartsWith("2_10_", StringComparison.Ordinal); +} diff --git a/mods/mapdrop/README.md b/mods/mapdrop/README.md new file mode 100644 index 0000000..f7dea4a --- /dev/null +++ b/mods/mapdrop/README.md @@ -0,0 +1,12 @@ +# Map Drop + +Add one bonus roll for a map of the current Atlas tier when a monster dies. The four chance settings apply by monster +rarity. Turn on **Bonus Tier 1 maps in Acts 8 to 10** to extend the roll to the late campaign. Bonus maps come from the +server's generic map-key catalog and are independent of regular loot and the Atlas drop roll. + +Enable with Waypoint or `/mod_enable mapdrop`. It starts disabled and adds no chat commands. Set the odds in +Waypoint or in `data/mods/mapdrop.json` in the server folder. The JSON values are fractions. For example, `0.05` +is a 5% chance on each eligible kill. + +Inspired by the map-drop settings in [mingyue8621/LocalExile-Mods](https://github.com/mingyue8621/LocalExile-Mods). +Compatible with LocalExile 0.5.2-beta. diff --git a/mods/mapdrop/mod.json b/mods/mapdrop/mod.json new file mode 100644 index 0000000..57f3f78 --- /dev/null +++ b/mods/mapdrop/mod.json @@ -0,0 +1,11 @@ +{ + "id": "mapdrop", + "name": "Map Drop", + "description": "Adds configurable bonus map drops in Atlas maps and optionally in the late campaign.", + "author": "zj1022", + "version": "1.0.0", + "compatibleClientVersions": ["0.5.2-beta"], + "kind": "feature", + "depends": [], + "enabled": false +} diff --git a/mods/mapdrop/settings.json b/mods/mapdrop/settings.json new file mode 100644 index 0000000..6b0c0ed --- /dev/null +++ b/mods/mapdrop/settings.json @@ -0,0 +1,10 @@ +{ + "version": 1, + "settings": { + "normal": { "type": "number", "default": 0.005, "min": 0, "max": 1, "format": "percent", "label": "Normal monster bonus map chance" }, + "magic": { "type": "number", "default": 0.01, "min": 0, "max": 1, "format": "percent", "label": "Magic monster bonus map chance" }, + "rare": { "type": "number", "default": 0.05, "min": 0, "max": 1, "format": "percent", "label": "Rare monster bonus map chance" }, + "unique": { "type": "number", "default": 0.2, "min": 0, "max": 1, "format": "percent", "label": "Unique monster bonus map chance" }, + "campaign": { "type": "bool", "default": false, "label": "Bonus Tier 1 maps in Acts 8 to 10" } + } +}