fix(movement): invalidate burden on enchantment changes

This commit is contained in:
Erik 2026-07-31 10:16:27 +02:00
parent 2b9dfec9d7
commit d6e8b60303
13 changed files with 231 additions and 25 deletions

View file

@ -3,6 +3,7 @@ using AcDream.App.UI;
using AcDream.App.UI.Layout;
using AcDream.Core.Items;
using AcDream.Core.Selection;
using AcDream.Core.Spells;
using Xunit;
namespace AcDream.App.Tests.UI.Layout;
@ -63,10 +64,12 @@ public class InventoryControllerTests
Action? onClose = null,
SelectionState? selection = null,
StackSplitQuantityState? stackSplitQuantity = null,
ItemInteractionController? itemInteraction = null)
ItemInteractionController? itemInteraction = null,
Func<int?>? strengthProvider = null,
Spellbook? burdenSpellbook = null)
=> InventoryController.Bind(layout, objects, () => Player,
iconIds: (_, _, _, _, _) => 0u,
strength: () => strength, datFont: null,
strength: strengthProvider ?? (() => strength), datFont: null,
ownerName: ownerName is null ? null : () => ownerName,
sendUse: uses is null ? null : g => uses.Add(g),
sendPutItemInContainer: puts is null ? null : (i, c, p) => puts.Add((i, c, p)),
@ -78,7 +81,8 @@ public class InventoryControllerTests
onClose: onClose,
selection: selection ?? new SelectionState(),
stackSplitQuantity: stackSplitQuantity,
itemInteraction: itemInteraction);
itemInteraction: itemInteraction,
burdenSpellbook: burdenSpellbook);
private static UiButton MakeButton(uint id)
{
@ -238,6 +242,37 @@ public class InventoryControllerTests
Assert.Contains("50%", CaptionText(burdenText));
}
[Fact]
public void EnchantmentChange_RefreshesBurdenFromEffectiveStrength()
{
var (layout, _, _, _, meter, burdenText, _, _) = BuildLayout();
var objects = new ClientObjectTable();
var props = new PropertyBundle();
props.Ints[5] = 1600;
objects.UpsertProperties(Player, props);
int effectiveStrength = 10;
var spellbook = new Spellbook();
using InventoryController controller = Bind(
layout,
objects,
strengthProvider: () => effectiveStrength,
burdenSpellbook: spellbook);
Assert.Equal(1600f / 1500f / 3f, meter.Fill() ?? -1f, 3);
Assert.Contains("106%", CaptionText(burdenText));
effectiveStrength = 20;
spellbook.OnEnchantmentAdded(new ActiveEnchantmentRecord(
42u, 1u, 60d, Player, Bucket: 1u));
Assert.Equal(1600f / 3000f / 3f, meter.Fill() ?? -1f, 3);
Assert.Contains("53%", CaptionText(burdenText));
effectiveStrength = 10;
spellbook.OnPurgeAll();
Assert.Equal(1600f / 1500f / 3f, meter.Fill() ?? -1f, 3);
Assert.Contains("106%", CaptionText(burdenText));
}
[Fact]
public void Captions_render_known_strings()
{