From 050841b8f9e65c77f67490628c20d774aa75e9f3 Mon Sep 17 00:00:00 2001 From: Wolfgang von Caron Date: Sat, 11 Dec 2021 03:52:15 +0000 Subject: [PATCH] movement sit/stand --- lib/classes/Agent.ts | 10 +++++ lib/classes/ClientCommands.ts | 3 ++ lib/classes/commands/MovementCommands.ts | 56 ++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 lib/classes/commands/MovementCommands.ts diff --git a/lib/classes/Agent.ts b/lib/classes/Agent.ts index 704a6c9..75d355b 100644 --- a/lib/classes/Agent.ts +++ b/lib/classes/Agent.ts @@ -422,4 +422,14 @@ export class Agent this.appearanceComplete = true; this.appearanceCompleteEvent.next(); } + + setControlFlag(flag: ControlFlags): void + { + this.controlFlags = this.controlFlags | flag; + } + + clearControlFlag(flag: ControlFlags): void + { + this.controlFlags = this.controlFlags & ~flag; + } } diff --git a/lib/classes/ClientCommands.ts b/lib/classes/ClientCommands.ts index 845bd17..f71a7cb 100644 --- a/lib/classes/ClientCommands.ts +++ b/lib/classes/ClientCommands.ts @@ -12,6 +12,7 @@ import { GroupCommands } from './commands/GroupCommands'; import { InventoryCommands } from './commands/InventoryCommands'; import { ParcelCommands } from './commands/ParcelCommands'; import { FriendCommands } from './commands/FriendCommands'; +import { MovementCommands } from './commands/MovementCommands'; export class ClientCommands { @@ -26,6 +27,7 @@ export class ClientCommands public agent: AgentCommands; public group: GroupCommands; public inventory: InventoryCommands; + public movement: MovementCommands; constructor(region: Region, agent: Agent, bot: Bot) { @@ -40,6 +42,7 @@ export class ClientCommands this.agent = new AgentCommands(region, agent, bot); this.group = new GroupCommands(region, agent, bot); this.inventory = new InventoryCommands(region, agent, bot); + this.movement = new MovementCommands(region, agent, bot); } shutdown(): void diff --git a/lib/classes/commands/MovementCommands.ts b/lib/classes/commands/MovementCommands.ts new file mode 100644 index 0000000..b3dccc3 --- /dev/null +++ b/lib/classes/commands/MovementCommands.ts @@ -0,0 +1,56 @@ +import { ControlFlags, PacketFlags } from "../.."; +import { AgentRequestSitMessage, AgentSitMessage } from "../MessageClasses"; +import { UUID } from "../UUID"; +import { Vector3 } from "../Vector3"; +import { CommandsBase } from "./CommandsBase"; + +export class MovementCommands extends CommandsBase { + + async sitOnObject(targetID: UUID, offset: Vector3): Promise + { + await this.requestSitOnObject(targetID, offset); + await this.sitOn(); + } + + sitOnGround(): void + { + this.agent.setControlFlag(ControlFlags.AGENT_CONTROL_SIT_ON_GROUND); + this.agent.sendAgentUpdate(); + } + + stand(): void + { + this.agent.clearControlFlag(ControlFlags.AGENT_CONTROL_SIT_ON_GROUND); + this.agent.setControlFlag(ControlFlags.AGENT_CONTROL_STAND_UP); + this.agent.sendAgentUpdate(); + this.agent.clearControlFlag(ControlFlags.AGENT_CONTROL_STAND_UP); + this.agent.sendAgentUpdate(); + } + + private async requestSitOnObject(targetID: UUID, offset: Vector3): Promise + { + const msg = new AgentRequestSitMessage(); + msg.AgentData = { + AgentID: this.agent.agentID, + SessionID: this.circuit.sessionID, + }; + msg.TargetObject = { + TargetID: targetID, + Offset: offset, + }; + + const seqID = this.circuit.sendMessage(msg, PacketFlags.Reliable); + return this.circuit.waitForAck(seqID, 10000); + } + + private async sitOn(): Promise + { + const msg = new AgentSitMessage(); + msg.AgentData = { + AgentID: this.agent.agentID, + SessionID: this.circuit.sessionID, + }; + const seqID = this.circuit.sendMessage(msg, PacketFlags.Reliable); + return this.circuit.waitForAck(seqID, 10000); + } +}