Click-to-interact wire layer. Adds the three most common "do a thing to an object" GameActions that the UI triggers on left-click / use-item contexts. Wire layer: - InteractRequests.BuildUse (0x0036): single target guid — click a door, loot a corpse, talk to an NPC, activate a lifestone, step on a portal. - InteractRequests.BuildUseWithTarget (0x0035): source + target — key on locked door, scroll on self, salvage tool on item. - InteractRequests.BuildTeleToLifestone (0x0063): no-arg recall. Fails server-side if not tied; reply comes back as GameEvent WeenieError. Server reply for Use + UseWithTarget is GameEventType.UseDone (0x01C7) carrying a WeenieError code (0 = success). Already parsed; wiring into a "UseDone" event on CombatState-style holder can be a follow-up. Tests (3 new): byte-exact encoding of all three builders. Build green, 616 tests pass (up from 613). Ref: r08 §3 rows 0x0035/0x0036/0x0063. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
76 lines
2.9 KiB
C#
76 lines
2.9 KiB
C#
using System.Buffers.Binary;
|
|
|
|
namespace AcDream.Core.Net.Messages;
|
|
|
|
/// <summary>
|
|
/// Outbound interaction GameActions. Each carries a single uint32
|
|
/// target guid (plus a second guid for <c>UseWithTarget</c>) inside the
|
|
/// standard <c>0xF7B1</c> GameAction envelope.
|
|
///
|
|
/// <para>
|
|
/// Wire layout (r08 §3 rows 0x0035/0x0036):
|
|
/// <code>
|
|
/// u32 0xF7B1
|
|
/// u32 gameActionSequence
|
|
/// u32 subOpcode
|
|
/// u32 targetGuid // e.g. door, NPC, lifestone, corpse, item
|
|
/// u32 sourceGuid // only for UseWithTarget (the item you're using)
|
|
/// </code>
|
|
/// </para>
|
|
///
|
|
/// <para>
|
|
/// Server reply is <c>GameEventType.UseDone</c> (0x01C7) carrying a
|
|
/// <c>WeenieError</c>; 0 = success.
|
|
/// </para>
|
|
/// </summary>
|
|
public static class InteractRequests
|
|
{
|
|
public const uint GameActionEnvelope = 0xF7B1u;
|
|
public const uint UseOpcode = 0x0036u;
|
|
public const uint UseWithTargetOpcode = 0x0035u;
|
|
public const uint TeleToLifestoneOpcode = 0x0063u;
|
|
|
|
/// <summary>
|
|
/// Use an object: click a door, loot a corpse, talk to an NPC,
|
|
/// activate a lifestone, step onto a portal.
|
|
/// </summary>
|
|
public static byte[] BuildUse(uint gameActionSequence, uint targetGuid)
|
|
{
|
|
byte[] body = new byte[16];
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body, GameActionEnvelope);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(4), gameActionSequence);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(8), UseOpcode);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(12), targetGuid);
|
|
return body;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Use source item on target: e.g. key on locked door, key on
|
|
/// chest, scroll on yourself, salvage tool on an item.
|
|
/// </summary>
|
|
public static byte[] BuildUseWithTarget(
|
|
uint gameActionSequence, uint sourceGuid, uint targetGuid)
|
|
{
|
|
byte[] body = new byte[20];
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body, GameActionEnvelope);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(4), gameActionSequence);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(8), UseWithTargetOpcode);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(12), sourceGuid);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(16), targetGuid);
|
|
return body;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Teleport to your lifestone. No target guid — just tells the
|
|
/// server "recall me." Fails if you haven't tied to a lifestone
|
|
/// (server responds with a WeenieError).
|
|
/// </summary>
|
|
public static byte[] BuildTeleToLifestone(uint gameActionSequence)
|
|
{
|
|
byte[] body = new byte[12];
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body, GameActionEnvelope);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(4), gameActionSequence);
|
|
BinaryPrimitives.WriteUInt32LittleEndian(body.AsSpan(8), TeleToLifestoneOpcode);
|
|
return body;
|
|
}
|
|
}
|