Items face: "No buff" toggle on shield rows

Adds a No buff toggle on shield rows in the Items face; it writes the noBuff field RynthAi reads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daniel Wallace 2026-11-04 15:52:33 -08:00
commit 0b94479b62
4 changed files with 147 additions and 7 deletions

View file

@ -5,6 +5,9 @@
// and mana stone tapping (on/off, keep count, min max-mana to tap). A listed
// weapon the character no longer carries (RynthAi's missingIds) shows in amber
// with a warning icon and "(missing)", and says what to do in its tooltip.
// A shield row (Action "Shield") from a RynthAi that sends noBuff shows a
// "No buff" toggle in place of its element column: on = RynthAi never buffs
// that shield. Weapon rows are unchanged.
//
// Edits change a private copy and save the whole payload (ItemsCommands,
// pump thread). A newer snapshot replaces the copy; snapshots from before
@ -91,8 +94,15 @@ internal sealed class ItemsFace : IImGuiPanel
int i = idx[k];
ItemsPanel.WeaponEntry wpn = _data.Weapons[i];
ImGuiNET.ImGui.PushID("w" + i);
int r = Row(wpn.Name, wpn.Element, shown++, bw, _data.MissingIds.Contains(wpn.Id), k > 0, k < idx.Count - 1);
int r = Row(wpn.Name, wpn.Element, shown++, bw, _data.MissingIds.Contains(wpn.Id), k > 0, k < idx.Count - 1,
wpn.ShowsNoBuff ? wpn.NoBuff : null);
ImGuiNET.ImGui.PopID();
if (r == 5)
{
wpn.NoBuff = !(wpn.NoBuff ?? false);
Save();
continue;
}
// Up / down inside its group: the order is RynthAi's preference (the buff wand, the
// first weapon of a kind), and it couldn't be changed but by removing and re-adding.
if (r == 3 || r == 4)
@ -273,13 +283,18 @@ internal sealed class ItemsFace : IImGuiPanel
// The up / down buttons' width in a row (two 20 px buttons and their gaps).
private const float MoveW = 46;
private const string NoBuffTip = "Never buff this shield - for a shield that already carries its buffs.";
/// <summary>
/// Name | up | down | [value picker] | Del. Returns 1 when the picker was clicked, 2 for Del,
/// 3 for up, 4 for down, else 0. Up / down are drawn dim and do nothing at the ends.
/// <paramref name="missing"/>: the item isn't carried any more (amber, a warning icon,
/// "(missing)" and a tooltip saying what to do).
/// 3 for up, 4 for down, 5 for the "No buff" toggle, else 0. Up / down are drawn dim and do
/// nothing at the ends. <paramref name="missing"/>: the item isn't carried any more (amber, a
/// warning icon, "(missing)" and a tooltip saying what to do). <paramref name="noBuff"/>
/// non-null (a shield row, RynthAi sending noBuff): the value column is the "No buff" toggle
/// instead of the picker (a shield has no element; its column only said "Shield").
/// </summary>
private static int Row(string name, string value, int index, float w, bool missing, bool canUp = false, bool canDown = false)
private static int Row(string name, string value, int index, float w, bool missing, bool canUp = false, bool canDown = false,
bool? noBuff = null)
{
Vector2 p = ImGuiNET.ImGui.GetCursorScreenPos();
var dl = ImGuiNET.ImGui.GetWindowDrawList();
@ -311,7 +326,14 @@ internal sealed class ItemsFace : IImGuiPanel
if (IconButton("##down", PhosphorIcons.CaretDown, new Vector2(bx + 22, p.Y + 2), new Vector2(20, 20), canDown ? Teal : Mute, BtnFill) && canDown) result = 4;
ImGuiNET.ImGui.SetItemTooltip("Move down");
bx += MoveW;
if (Button("##pick", value, new Vector2(bx, p.Y + 2), new Vector2(96, 20), Text, BtnFill)) result = 1;
if (noBuff is bool nb)
{
// The tapping toggle's look: lit while the shield is excluded.
if (Button("##nobuff", (nb ? PhosphorIcons.CheckSquare : PhosphorIcons.Square) + " No buff", new Vector2(bx, p.Y + 2), new Vector2(96, 20),
nb ? OnText : Mute, nb ? OnBg : BtnFill)) result = 5;
ImGuiNET.ImGui.SetItemTooltip(NoBuffTip);
}
else if (Button("##pick", value, new Vector2(bx, p.Y + 2), new Vector2(96, 20), Text, BtnFill)) result = 1;
if (IconButton("##del", PhosphorIcons.Trash, new Vector2(bx + 100, p.Y + 2), new Vector2(42, 20), Red, BtnFill)) result = 2;
ImGuiNET.ImGui.SetItemTooltip("Remove");
NextLine(p, 24);

View file

@ -82,8 +82,18 @@ internal static class ItemsPanel
// Melee, Missile, "War Magic", "Void Magic", Shield, Ammo, or "" (not known). Set by RynthAi for
// display (the Items face groups by it); sent back untouched and ignored there.
[JsonPropertyName("kind")] public string Kind { get; set; } = string.Empty;
// True = "Exclude from buffing" (RynthAi ItemRule.KeepBuffed off), sent for every entry by
// RynthAi and applied back by it for shield entries only. Null = the plugin
// predates it: no toggle is drawn, and none is written back (RynthAi keeps its saved value).
[JsonPropertyName("noBuff")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public bool? NoBuff { get; set; }
public bool IsShield => string.Equals(Action, ItemsCommands.ShieldAction, StringComparison.OrdinalIgnoreCase);
/// <summary>The Items face draws its "No buff" toggle: a shield entry (Action "Shield", the
/// only kind RynthAi applies it to) from a plugin that sends the field.</summary>
[JsonIgnore] public bool ShowsNoBuff => IsShield && NoBuff.HasValue;
}
internal sealed class ConsumableEntry
@ -874,7 +884,8 @@ internal static class ItemsPanel
if (a.Count != b.Count) return true;
for (int i = 0; i < a.Count; i++)
if (a[i].Id != b[i].Id || a[i].Name != b[i].Name || a[i].Element != b[i].Element
|| !string.Equals(a[i].Action, b[i].Action, StringComparison.OrdinalIgnoreCase)) return true;
|| !string.Equals(a[i].Action, b[i].Action, StringComparison.OrdinalIgnoreCase)
|| a[i].NoBuff != b[i].NoBuff) return true; // so this panel never saves back a stale noBuff
return false;
}

View file

@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<!--
Offline checks for the Items face's "No buff" shield toggle: ItemsPanel.WeaponEntry
must read RynthAi's "noBuff" (sent for every entry; null from an older RynthAi), show the toggle
on shield entries only, and write the field back only when it holds a value. Reaches the
internal types by reflection (the engine has no test seam). x86, like the engine: needs the
x86 .NET runtime.
Run: dotnet run -c Release (exit 0 = pass, 1 = fail)
-->
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0-windows</TargetFramework>
<PlatformTarget>x86</PlatformTarget>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<SelfContained>false</SelfContained>
<Platforms>x86</Platforms>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
<RootNamespace>ItemsNoBuffTests</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\RynthCore.Engine\RynthCore.Engine.csproj" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,79 @@
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization.Metadata;
using System.Text.RegularExpressions;
namespace ItemsNoBuffTests
{
// The engine half of the shield "No buff" toggle, against what RynthAi's Items bridge writes
// (ItemsBridgePayload: PascalCase names, indented, "noBuff" on every weapon entry) and reads
// (case-insensitive; noBuff applied for Action "Shield" entries only, absent = unchanged).
internal static class Program
{
private static int _fails, _asserts;
private static void Check(bool cond, string msg)
{
_asserts++;
if (!cond) { _fails++; Console.WriteLine($" [FAIL] {msg}"); }
}
private const string Ns = "RynthCore.Engine.UI.Panels.";
private const BindingFlags All = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;
private static int Main()
{
Assembly engine = Assembly.Load("RynthCore.Engine");
Type ctxType = engine.GetType(Ns + "ItemsPanelJsonContext", throwOnError: true)!;
object ctx = ctxType.GetProperty("Default", All)!.GetValue(null)!;
var info = (JsonTypeInfo)ctxType.GetProperty("Payload", All)!.GetValue(ctx)!;
Type payloadType = engine.GetType(Ns + "ItemsPanel+Payload", throwOnError: true)!;
Type entryType = engine.GetType(Ns + "ItemsPanel+WeaponEntry", throwOnError: true)!;
List<object> Weapons(object payload) =>
((System.Collections.IEnumerable)payloadType.GetProperty("Weapons", All)!.GetValue(payload)!).Cast<object>().ToList();
bool? NoBuff(object e) => (bool?)entryType.GetProperty("NoBuff", All)!.GetValue(e);
bool Shows(object e) => (bool)entryType.GetProperty("ShowsNoBuff", All)!.GetValue(e)!;
string Name(object e) => (string)entryType.GetProperty("Name", All)!.GetValue(e)!;
// --- RynthAi -> engine (the shape RynthAi's BuildItemsJson writes)
const string fromPlugin = "{\n \"Weapons\": [\n" +
" { \"Id\": 1, \"Name\": \"Sword\", \"Action\": \"Weapon\", \"Element\": \"Slash\", \"Kind\": \"Melee\", \"KeepBuffed\": false, \"noBuff\": true },\n" +
" { \"Id\": 2, \"Name\": \"Kite Shield\", \"Action\": \"Shield\", \"Element\": \"Shield\", \"Kind\": \"Shield\", \"KeepBuffed\": true, \"noBuff\": false },\n" +
" { \"Id\": 3, \"Name\": \"Rose Shield\", \"Action\": \"Shield\", \"Element\": \"Shield\", \"Kind\": \"Shield\", \"KeepBuffed\": false, \"noBuff\": true },\n" +
" { \"Id\": 4, \"Name\": \"Buckler\", \"Action\": \"Weapon\", \"Element\": \"Shield\", \"Kind\": \"Shield\", \"noBuff\": true }\n" +
" ],\n \"MissingIds\": []\n}";
object p = JsonSerializer.Deserialize(fromPlugin, info)!;
var w = Weapons(p);
Check(w.Count == 4, "four entries read");
Check(NoBuff(w[0]) == true && NoBuff(w[1]) == false && NoBuff(w[2]) == true, "noBuff is read per entry");
Check(!Shows(w[0]), "a weapon row: no toggle (RynthAi ignores noBuff on weapons)");
Check(Shows(w[1]) && Shows(w[2]), "a shield row (Action Shield): the toggle");
Check(!Shows(w[3]), "a shield filed as a Weapon (Kind Shield, Action Weapon): no toggle (RynthAi ignores it there)");
// --- An older RynthAi: no field -> no toggle, nothing written back
object old = JsonSerializer.Deserialize("{\"Weapons\":[{\"Id\":2,\"Name\":\"Kite Shield\",\"Action\":\"Shield\",\"Element\":\"Shield\"}]}", info)!;
object oldShield = Weapons(old)[0];
Check(NoBuff(oldShield) == null, "an older RynthAi: noBuff is null");
Check(!Shows(oldShield), "and the shield row has no toggle");
string oldBack = JsonSerializer.Serialize(old, info);
Check(!oldBack.Contains("noBuff"), "and the save carries no noBuff (RynthAi keeps its saved value): " + oldBack);
Check(!oldBack.Contains("ShowsNoBuff"), "the face-only ShowsNoBuff is not on the wire");
// --- Engine -> RynthAi: the toggle flipped and saved
entryType.GetProperty("NoBuff", All)!.SetValue(w[1], true); // what the face's click does
entryType.GetProperty("NoBuff", All)!.SetValue(w[2], false);
string back = JsonSerializer.Serialize(p, info);
Check(Regex.IsMatch(back, "\"id\":2,[^}]*\"noBuff\":true"), "the Kite Shield goes back noBuff true: " + back);
Check(Regex.IsMatch(back, "\"id\":3,[^}]*\"noBuff\":false"), "the Rose Shield goes back noBuff false");
Check(Regex.IsMatch(back, "\"id\":1,[^}]*\"noBuff\":true"), "a weapon's value is round-tripped untouched (RynthAi ignores it)");
Check(Regex.Matches(back, "\"action\":\"Shield\"").Count == 2 && Name(w[1]) == "Kite Shield", "names and actions round-trip");
// The field name is exactly what RynthAi's ItemRule.NoBuff ([JsonPropertyName("noBuff")]) reads.
var attr = entryType.GetProperty("NoBuff", All)!.GetCustomAttribute<System.Text.Json.Serialization.JsonPropertyNameAttribute>();
Check(attr?.Name == "noBuff", "the wire name is noBuff");
Console.WriteLine(_fails == 0 ? $"All {_asserts} checks passed." : $"{_fails} of {_asserts} checks FAILED.");
return _fails == 0 ? 0 : 1;
}
}
}