diff --git a/Changelog/2026-10-08-fix-loot-keep-count-zero.md b/Changelog/2026-10-08-fix-loot-keep-count-zero.md new file mode 100644 index 0000000..ba6acd8 --- /dev/null +++ b/Changelog/2026-10-08-fix-loot-keep-count-zero.md @@ -0,0 +1,23 @@ +# Loot profiles - "Keep # 0" and salvage combine off survive a save - 2026-10-08 + +## Fixed + +- **"Keep #" with a count of 0 loads back as 0.** `LootJsonContext` skips values equal to the + type default when writing (`WhenWritingDefault`), so `"KeepCount": 0` was left out of the + `.json` profile and loaded back as the initializer's 1: a "keep none" rule kept one. +- **Salvage combine turned off stays off.** `SalvageCombineSettings.Enabled = false` was left + out the same way and loaded back as `true`. +- Both properties are now always written (`JsonIgnore(Condition = Never)`, as `LootRule.Enabled` + already was). Profiles saved before this still have the value missing and load as before + (1 / on) until they are saved again with the intended value. + +## Files + +- `Shared/RynthCore.LootSdk/LootModel.cs`: `LootRule.KeepCount` always written. +- `Shared/RynthCore.LootSdk/SalvageCombineSettings.cs`: `Enabled` always written. +- `Tools/RynthCore.RynthAiHostTests/Tests/NativeLootTests.cs`: the Keep # 0 round trip is a + normal test now (was a known failure); new salvage-combine-off round trip. + +## Checks + +- `loot native` host tests: 24 passed, 0 known failures. diff --git a/Shared/RynthCore.LootSdk/LootModel.cs b/Shared/RynthCore.LootSdk/LootModel.cs index 95311c8..c8a89ea 100644 --- a/Shared/RynthCore.LootSdk/LootModel.cs +++ b/Shared/RynthCore.LootSdk/LootModel.cs @@ -95,6 +95,8 @@ public sealed class LootRule : System.ComponentModel.INotifyPropertyChanged [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] public bool Enabled { get; set; } = true; public LootAction Action { get; set; } = LootAction.Keep; + // Always written: the context skips default values, and a skipped "Keep # 0" would load back as 1. + [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] public int KeepCount { get; set; } = 1; public List Conditions { get; set; } = new(); diff --git a/Shared/RynthCore.LootSdk/SalvageCombineSettings.cs b/Shared/RynthCore.LootSdk/SalvageCombineSettings.cs index d5e5ef6..5f7ec5b 100644 --- a/Shared/RynthCore.LootSdk/SalvageCombineSettings.cs +++ b/Shared/RynthCore.LootSdk/SalvageCombineSettings.cs @@ -12,6 +12,8 @@ namespace RynthCore.Loot; /// public sealed class SalvageCombineSettings { + // Always written: LootJsonContext skips default values, and a skipped false would load back as true. + [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] public bool Enabled { get; set; } = true; /// Default bands applied to materials with no per-material override. diff --git a/Tools/RynthCore.RynthAiHostTests/Tests/NativeLootTests.cs b/Tools/RynthCore.RynthAiHostTests/Tests/NativeLootTests.cs index 96b858b..f6e3a04 100644 --- a/Tools/RynthCore.RynthAiHostTests/Tests/NativeLootTests.cs +++ b/Tools/RynthCore.RynthAiHostTests/Tests/NativeLootTests.cs @@ -42,9 +42,8 @@ internal static class NativeLootTests r.Add("loot native: profile JSON round trip keeps rules and order", JsonRoundTrip); r.Add("loot native: malformed or missing JSON profile", MalformedJson); r.Add("loot native: an invalid regex in a String rule does not match", InvalidRegexDoesNotThrow); // was a known failure; fixed by a2902c3 - r.KnownFailure("loot native: Keep # with a count of 0 survives a save and load", - "LootJsonContext skips default values when writing, so KeepCount 0 is left out and loads back as the initializer's 1", - KeepCountZeroRoundTrip); + r.Add("loot native: Keep # with a count of 0 survives a save and load", KeepCountZeroRoundTrip); // was a known failure + r.Add("loot native: salvage combine turned off survives a save and load", SalvageCombineOffRoundTrip); } private static LootRule Rule(string name, LootAction action, params LootCondition[] conds) @@ -366,4 +365,16 @@ internal static class NativeLootTests Profile(rule).Save(path); Check.Eq(LootProfile.Load(path).Rules[0].KeepCount, 0, "KeepCount after reload"); } + + /// LootJsonContext skips default values: SalvageCombine.Enabled = false was left out and loaded back as true. + private static void SalvageCombineOffRoundTrip() + { + var p = Profile(Rule("any", LootAction.Salvage)); + p.SalvageCombine = new SalvageCombineSettings { Enabled = false }; + string path = TempFile("combine-off.json"); + p.Save(path); + var loaded = LootProfile.Load(path); + Check.NotNull(loaded.SalvageCombine, "SalvageCombine after reload"); + Check.False(loaded.SalvageCombine?.Enabled ?? true, "SalvageCombine.Enabled stays off"); + } }