feat(inventory): port retail weapon switching

Sequence primary weapon replacement through the server-confirmed AutoWield transaction: return the occupied weapon to the player pack, wait for its move event, then wield the requested item. Route authoritative CombatMode property updates so peace stays peace and war adopts the new weapon stance without client-synthesized animation.

Co-Authored-By: Codex <codex@openai.com>
This commit is contained in:
Erik 2026-07-12 23:06:31 +02:00
parent 8e9c538519
commit 17b5712d53
14 changed files with 736 additions and 155 deletions

View file

@ -18,11 +18,13 @@ public sealed class ItemInteractionControllerTests
public readonly List<uint> Examines = new();
public readonly List<(uint Source, uint Target)> UseWithTarget = new();
public readonly List<(uint Item, uint Mask)> Wields = new();
public readonly List<(uint Item, uint Container, int Placement)> Puts = new();
public readonly List<uint> Drops = new();
public readonly List<(uint Item, uint Amount)> SplitDrops = new();
public readonly List<string> Toasts = new();
public readonly StackSplitQuantityState SplitQuantity = new();
public uint SelectedObject;
public bool NonCombatMode;
public long Now = 1_000;
public Harness()
@ -54,7 +56,10 @@ public sealed class ItemInteractionControllerTests
toast: Toasts.Add,
sendSplitToWorld: (item, amount) => SplitDrops.Add((item, amount)),
selectedObjectId: () => SelectedObject,
stackSplitQuantity: SplitQuantity);
stackSplitQuantity: SplitQuantity,
inNonCombatMode: () => NonCombatMode,
sendPutItemInContainer: (item, container, placement) =>
Puts.Add((item, container, placement)));
}
public ItemInteractionController Controller { get; }
@ -412,6 +417,112 @@ public sealed class ItemInteractionControllerTests
Assert.Equal(Pack, h.Objects.Get(0x50000A06u)!.ContainerId);
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void WeaponReplacement_inPeaceOrWar_unwieldsThenWieldsAfterServerConfirm(
bool nonCombatMode)
{
var h = new Harness { NonCombatMode = nonCombatMode };
const uint sword = 0x50000B01u;
const uint bow = 0x50000B02u;
h.Objects.AddOrUpdate(new ClientObject
{
ObjectId = sword,
Name = "Sword",
Type = ItemType.MeleeWeapon,
CombatUse = 1,
ValidLocations = EquipMask.MeleeWeapon,
});
h.Objects.MoveItem(sword, Player, -1, EquipMask.MeleeWeapon);
h.AddContained(bow, item =>
{
item.Name = "Bow";
item.Type = ItemType.MissileWeapon;
item.CombatUse = 1;
item.ValidLocations = EquipMask.MissileWeapon;
});
Assert.True(h.Controller.ActivateItem(bow));
Assert.Equal(new[] { (sword, Player, 0) }, h.Puts);
Assert.Empty(h.Wields);
Assert.Equal(EquipMask.MeleeWeapon,
h.Objects.Get(sword)!.CurrentlyEquippedLocation);
Assert.Equal(Pack, h.Objects.Get(bow)!.ContainerId);
// Authoritative 0x0022: only now does retail retry AutoWield.
h.Objects.MoveItem(sword, Player, 0, EquipMask.None);
Assert.Equal(new[] { (bow, (uint)EquipMask.MissileWeapon) }, h.Wields);
Assert.Equal(EquipMask.None,
h.Objects.Get(sword)!.CurrentlyEquippedLocation);
Assert.Equal(EquipMask.MissileWeapon,
h.Objects.Get(bow)!.CurrentlyEquippedLocation);
Assert.Equal(Player, h.Objects.Get(bow)!.ContainerId);
}
[Fact]
public void WeaponReplacement_doesNotOverlapRequestsWhileAwaitingServer()
{
var h = new Harness();
const uint sword = 0x50000B11u;
const uint bow = 0x50000B12u;
h.Objects.AddOrUpdate(new ClientObject
{
ObjectId = sword,
Type = ItemType.MeleeWeapon,
CombatUse = 1,
ValidLocations = EquipMask.MeleeWeapon,
});
h.Objects.MoveItem(sword, Player, -1, EquipMask.MeleeWeapon);
h.AddContained(bow, item =>
{
item.Type = ItemType.MissileWeapon;
item.CombatUse = 1;
item.ValidLocations = EquipMask.MissileWeapon;
});
Assert.True(h.Controller.ActivateItem(bow));
h.Now += 200;
Assert.True(h.Controller.ActivateItem(bow));
Assert.Single(h.Puts);
Assert.Empty(h.Wields);
}
[Fact]
public void WeaponReplacement_serverReject_clearsPendingTransactionForRetry()
{
var h = new Harness();
const uint sword = 0x50000B21u;
const uint bow = 0x50000B22u;
h.Objects.AddOrUpdate(new ClientObject
{
ObjectId = sword,
Type = ItemType.MeleeWeapon,
CombatUse = 1,
ValidLocations = EquipMask.MeleeWeapon,
});
h.Objects.MoveItem(sword, Player, -1, EquipMask.MeleeWeapon);
h.AddContained(bow, item =>
{
item.Type = ItemType.MissileWeapon;
item.CombatUse = 1;
item.ValidLocations = EquipMask.MissileWeapon;
});
Assert.True(h.Controller.ActivateItem(bow));
Assert.False(h.Objects.RejectMove(sword, 0x04FFu));
h.Now += 200;
Assert.True(h.Controller.ActivateItem(bow));
Assert.Equal(2, h.Puts.Count);
Assert.Empty(h.Wields);
Assert.Equal(EquipMask.MeleeWeapon,
h.Objects.Get(sword)!.CurrentlyEquippedLocation);
}
[Fact]
public void InventoryDragOutsideUi_sendsDropAndMovesToWorldOptimistically()
{