feat(combat): port retail held weapon parenting
Select the default combat mode from ordered equipped objects so bows request missile stance. Parse CreateObject parent metadata and ParentEvent, then render held objects as separate children composed from setup holding locations and placement frames each animation tick.
This commit is contained in:
parent
564d39dfea
commit
ab6d96d113
18 changed files with 1152 additions and 17 deletions
|
|
@ -1,9 +1,62 @@
|
|||
using AcDream.Core.Combat;
|
||||
using AcDream.Core.Items;
|
||||
|
||||
namespace AcDream.Core.Tests.Combat;
|
||||
|
||||
public sealed class CombatInputPlannerTests
|
||||
{
|
||||
[Fact]
|
||||
public void GetDefaultCombatMode_MissileCombatUseSelectsMissile()
|
||||
{
|
||||
var bow = Equipped(EquipMask.MissileWeapon, ItemType.MissileWeapon, combatUse: 2);
|
||||
|
||||
Assert.Equal(
|
||||
CombatMode.Missile,
|
||||
CombatInputPlanner.GetDefaultCombatMode([bow]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultCombatMode_PrimaryWeaponOrderMatchesRetailInventoryPlacement()
|
||||
{
|
||||
var bow = Equipped(EquipMask.MissileWeapon, ItemType.MissileWeapon, combatUse: 2);
|
||||
var sword = Equipped(EquipMask.MeleeWeapon, ItemType.MeleeWeapon, combatUse: 1);
|
||||
|
||||
Assert.Equal(
|
||||
CombatMode.Missile,
|
||||
CombatInputPlanner.GetDefaultCombatMode([bow, sword]));
|
||||
Assert.Equal(
|
||||
CombatMode.Melee,
|
||||
CombatInputPlanner.GetDefaultCombatMode([sword, bow]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultCombatMode_HeldCasterSelectsMagic()
|
||||
{
|
||||
var wand = Equipped(EquipMask.Held, ItemType.Caster, combatUse: 0);
|
||||
|
||||
Assert.Equal(
|
||||
CombatMode.Magic,
|
||||
CombatInputPlanner.GetDefaultCombatMode([wand]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultCombatMode_HeldNonCasterCannotEnterCombat()
|
||||
{
|
||||
var held = Equipped(EquipMask.Held, ItemType.Misc, combatUse: 0);
|
||||
|
||||
Assert.Equal(
|
||||
CombatMode.NonCombat,
|
||||
CombatInputPlanner.GetDefaultCombatMode([held]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultCombatMode_NoWeaponDefaultsToUnarmedMelee()
|
||||
{
|
||||
Assert.Equal(
|
||||
CombatMode.Melee,
|
||||
CombatInputPlanner.GetDefaultCombatMode([]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToggleMode_FromNonCombat_UsesDefaultCombatMode()
|
||||
{
|
||||
|
|
@ -40,4 +93,15 @@ public sealed class CombatInputPlannerTests
|
|||
{
|
||||
Assert.Equal(expected, CombatInputPlanner.SupportsTargetedAttack(mode));
|
||||
}
|
||||
|
||||
private static ClientObject Equipped(
|
||||
EquipMask location,
|
||||
ItemType type,
|
||||
byte combatUse) => new()
|
||||
{
|
||||
ObjectId = 1,
|
||||
CurrentlyEquippedLocation = location,
|
||||
Type = type,
|
||||
CombatUse = combatUse,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -678,12 +678,15 @@ public sealed class ClientObjectTableTests
|
|||
{
|
||||
var table = new ClientObjectTable();
|
||||
const uint player = 0x50000001u;
|
||||
ClientObject? rolledBack = null;
|
||||
table.MoveRolledBack += item => rolledBack = item;
|
||||
table.AddOrUpdate(new ClientObject { ObjectId = 0x942u });
|
||||
table.MoveItem(0x942u, player, newSlot: -1, newEquipLocation: EquipMask.Shield); // equipped
|
||||
table.MoveItemOptimistic(0x942u, player, 0); // optimistic UNWIELD into the pack (clears equip)
|
||||
Assert.Equal(EquipMask.None, table.Get(0x942u)!.CurrentlyEquippedLocation);
|
||||
Assert.True(table.RollbackMove(0x942u)); // server rejected the unwield
|
||||
Assert.Equal(EquipMask.Shield, table.Get(0x942u)!.CurrentlyEquippedLocation); // restored to equipped
|
||||
Assert.Same(table.Get(0x942u), rolledBack);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
108
tests/AcDream.Core.Tests/Meshing/EquippedChildAttachmentTests.cs
Normal file
108
tests/AcDream.Core.Tests/Meshing/EquippedChildAttachmentTests.cs
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
using System.Numerics;
|
||||
using AcDream.Core.Meshing;
|
||||
using AcDream.Core.World;
|
||||
using DatReaderWriter.DBObjs;
|
||||
using DatReaderWriter.Enums;
|
||||
using DatReaderWriter.Types;
|
||||
|
||||
namespace AcDream.Core.Tests.Meshing;
|
||||
|
||||
public sealed class EquippedChildAttachmentTests
|
||||
{
|
||||
[Fact]
|
||||
public void TryCompose_CombinesChildPlacementHoldingFrameAndAnimatedHandPart()
|
||||
{
|
||||
var parent = new Setup
|
||||
{
|
||||
HoldingLocations =
|
||||
{
|
||||
[ParentLocation.LeftHand] = new LocationType
|
||||
{
|
||||
PartId = 1,
|
||||
Frame = FrameAt(2, 0, 0),
|
||||
},
|
||||
},
|
||||
};
|
||||
var parentPose = new[]
|
||||
{
|
||||
new MeshRef(1, Matrix4x4.Identity),
|
||||
new MeshRef(2, Matrix4x4.CreateTranslation(10, 0, 0)),
|
||||
};
|
||||
var child = new Setup
|
||||
{
|
||||
Parts = { 0x01000001u },
|
||||
DefaultScale = { Vector3.One },
|
||||
PlacementFrames =
|
||||
{
|
||||
[Placement.LeftHand] = new AnimationFrame(1)
|
||||
{
|
||||
Frames = { FrameAt(3, 0, 0) },
|
||||
},
|
||||
},
|
||||
};
|
||||
var template = new[] { new MeshRef(0x01000001u, Matrix4x4.Identity) };
|
||||
|
||||
bool ok = EquippedChildAttachment.TryCompose(
|
||||
parent, parentPose, child, ParentLocation.LeftHand,
|
||||
Placement.LeftHand, template, 1.0f, out var result);
|
||||
|
||||
Assert.True(ok);
|
||||
Assert.Equal(15f, Assert.Single(result).PartTransform.Translation.X);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryCompose_MissingRequestedPlacementFallsBackToDefault()
|
||||
{
|
||||
var parent = ParentWithRightHand(partId: -1, FrameAt(4, 0, 0));
|
||||
var child = new Setup
|
||||
{
|
||||
Parts = { 0x01000001u },
|
||||
PlacementFrames =
|
||||
{
|
||||
[Placement.Default] = new AnimationFrame(1)
|
||||
{
|
||||
Frames = { FrameAt(6, 0, 0) },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
bool ok = EquippedChildAttachment.TryCompose(
|
||||
parent, [], child, ParentLocation.RightHand,
|
||||
Placement.RightHandCombat,
|
||||
[new MeshRef(0x01000001u, Matrix4x4.Identity)],
|
||||
1.0f,
|
||||
out var result);
|
||||
|
||||
Assert.True(ok);
|
||||
Assert.Equal(10f, Assert.Single(result).PartTransform.Translation.X);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryCompose_MissingHoldingLocationRejectsAttachment()
|
||||
{
|
||||
bool ok = EquippedChildAttachment.TryCompose(
|
||||
new Setup(), [], new Setup(), ParentLocation.RightHand,
|
||||
Placement.RightHandCombat, [], 1.0f, out var result);
|
||||
|
||||
Assert.False(ok);
|
||||
Assert.Empty(result);
|
||||
}
|
||||
|
||||
private static Setup ParentWithRightHand(int partId, Frame frame) => new()
|
||||
{
|
||||
HoldingLocations =
|
||||
{
|
||||
[ParentLocation.RightHand] = new LocationType
|
||||
{
|
||||
PartId = partId,
|
||||
Frame = frame,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
private static Frame FrameAt(float x, float y, float z) => new()
|
||||
{
|
||||
Origin = new Vector3(x, y, z),
|
||||
Orientation = Quaternion.Identity,
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue