From 765618d450aae6ca3cebdbac5f0e8c297673fb0d Mon Sep 17 00:00:00 2001 From: Bandit-HaxUnit <100861363+Bandit-HaxUnit@users.noreply.github.com> Date: Mon, 23 Nov 2026 11:17:11 +0100 Subject: [PATCH 1/4] Hueycoatl #3558: hold the tail at its side's angle, hide it while sunk; per-target head attacks The tail never turns, so live holds it with npc face_angle (instant): 512 out of the east cave, 1536 out of the west. It is added drawn as nothing (body customisation model -1), shown with a reset, and hidden again 2 ticks after a sink, so a late viewer sees no tail. Adds the NPC face angle update (mask 0x80000) to the protocol and client, and makes the client draw an NPC with a -1 model as nothing (no model, no clickbox). Rain Fire is huey_attack_melee for everyone; each target gets its own style sequence (shielded variants while shielded) and charge spotanim as npc_anim_specific / npc_spotanim_specific. Refs #3558 (rsprox recordings 4052, 4054, 3399). Co-Authored-By: Claude Opus 5.5 --- client/game/OsrsClient.ts | 5 + client/game/scene/SceneRaycaster.ts | 6 +- client/game/sync/NpcUpdateDecoder.ts | 14 +- client/render/render/overlays.ts | 1 + client/rs/config/npctype/NpcModelLoader.ts | 6 +- client/rs/config/npctype/NpcType.ts | 9 + .../npc-face-angle-hidden-models.test.ts | 65 +++++++ docs/hueycoatl.md | 6 +- .../bosses/hueycoatl/Attacks.Hueycoatl.js | 13 +- .../bosses/hueycoatl/Fight.Hueycoatl.js | 37 +++- .../bosses/hueycoatl/Shared.Hueycoatl.js | 9 +- .../elvarg/game/entity/impl/npc/NPC.ts | 19 ++ .../typescript/elvarg/net/PlayerSession.ts | 1 + .../elvarg/net/protocol/ClientProtocol.ts | 10 +- server/tests/hueycoatl-tail-head.test.cjs | 162 ++++++++++++++++++ 15 files changed, 344 insertions(+), 19 deletions(-) create mode 100644 client/tests/npc-face-angle-hidden-models.test.ts create mode 100644 server/tests/hueycoatl-tail-head.test.cjs diff --git a/client/game/OsrsClient.ts b/client/game/OsrsClient.ts index b87456e9e0..fb54195834 100644 --- a/client/game/OsrsClient.ts +++ b/client/game/OsrsClient.ts @@ -8325,6 +8325,11 @@ export class OsrsClient { if (block.faceTile) { applyNpcFaceTile(this.npcEcs, ecsId, block.faceTile); } + if (block.faceAngle) { + // Instant sets the drawn angle too: the only way to turn an NPC whose turn speed is 0. + this.npcEcs.setTargetRot(ecsId, block.faceAngle.angle); + if (block.faceAngle.instant) this.npcEcs.setRotation(ecsId, block.faceAngle.angle); + } if (typeof block.faceEntity === "number") { this.npcEcs.setInteractionIndex(ecsId, block.faceEntity | 0); } diff --git a/client/game/scene/SceneRaycaster.ts b/client/game/scene/SceneRaycaster.ts index df8da35956..2fb543fd69 100644 --- a/client/game/scene/SceneRaycaster.ts +++ b/client/game/scene/SceneRaycaster.ts @@ -2,7 +2,7 @@ import { mat4, vec3 } from "gl-matrix"; import { LocModelLoader } from "../../rs/config/loctype/LocModelLoader"; import { LocModelType } from "../../rs/config/loctype/LocModelType"; -import type { NpcType } from "../../rs/config/npctype/NpcType"; +import { type NpcType, npcTypeHasModel } from "../../rs/config/npctype/NpcType"; import type { LocType } from "../../rs/config/loctype/LocType"; import type { Model } from "../../rs/model/Model"; import { Scene } from "../../rs/scene/Scene"; @@ -730,7 +730,7 @@ export class SceneRaycaster { npcType = npcType.transform(this.osrsClient.varManager, this.osrsClient.npcTypeLoader); } // Model-less NPC spawns must not intercept objects behind their bounding box. - if (!npcType?.modelIds?.length) continue; + if (!npcTypeHasModel(npcType)) continue; isFishingSpot = String(npcType.name ?? "").toLowerCase().includes("fishing spot"); // The scaled model's height; size is already the scaled footprint in tiles. heightTiles = (this.npcHeightProvider?.(npcType.id) ?? 200) / 128; @@ -849,7 +849,7 @@ export class SceneRaycaster { while (npcType?.transforms) { npcType = npcType.transform(this.osrsClient.varManager, this.osrsClient.npcTypeLoader); } - if (!npcType?.modelIds?.length) return; + if (!npcTypeHasModel(npcType)) return; heightTiles = (this.npcHeightProvider?.(npcType.id) ?? 200) / 128; } catch { return; diff --git a/client/game/sync/NpcUpdateDecoder.ts b/client/game/sync/NpcUpdateDecoder.ts index 7090549faf..0a07382b18 100644 --- a/client/game/sync/NpcUpdateDecoder.ts +++ b/client/game/sync/NpcUpdateDecoder.ts @@ -46,6 +46,8 @@ export type NpcUpdateBlock = { exactMove?: ForcedMovementUpdate; /** A world tile to turn to once (OSRS npc face coord). */ faceTile?: { x: number; y: number }; + /** A held facing (OSRS npc face angle); instant snaps to it, even an NPC that never turns. */ + faceAngle?: { angle: number; instant: boolean }; /** Body-model slot overrides (OSRS npc model customisation); an empty list resets them. */ modelCustomisation?: Array<{ slot: number; modelId: number }>; /** @@ -465,7 +467,11 @@ export class NpcUpdateDecoder { if ((flags & TYPE_MODELS) !== 0) { const count = stream.readUnsignedByte() | 0; custom.models = []; - for (let i = 0; i < count; i++) custom.models.push(stream.readUnsignedShortBE() | 0); + for (let i = 0; i < count; i++) { + // 0xffff is -1: no model, so the NPC is drawn as nothing (the Hueycoatl's sunk tail). + const model = stream.readUnsignedShortBE() | 0; + custom.models.push(model === 0xffff ? -1 : model); + } } if ((flags & TYPE_RECOLOURS) !== 0) { const count = stream.readUnsignedByte() | 0; @@ -481,6 +487,12 @@ export class NpcUpdateDecoder { block.typeCustomisation = custom; } + // FACE_ANGLE (0x80000): an angle (0 south, 512 west, 1024 north, 1536 east) and whether to snap to it. + if ((mask & 0x80000) !== 0) { + const angle = stream.readUnsignedShortBE() & 2047; + block.faceAngle = { angle, instant: (stream.readUnsignedByte() | 0) !== 0 }; + } + if (Object.keys(block).length > 0) { updateBlocks.set(npcId | 0, block); } diff --git a/client/render/render/overlays.ts b/client/render/render/overlays.ts index a79f72b251..827297e36e 100644 --- a/client/render/render/overlays.ts +++ b/client/render/render/overlays.ts @@ -330,6 +330,7 @@ export function getNpcDefaultHeight(host: WebGLOsrsRendererHost, npcTypeId: numb // Load and merge model data const models: ModelData[] = []; for (const modelId of npcType.modelIds) { + if (modelId < 0) continue; const modelData = host.osrsClient.modelLoader.getModel(modelId); if (modelData) { models.push(modelData); diff --git a/client/rs/config/npctype/NpcModelLoader.ts b/client/rs/config/npctype/NpcModelLoader.ts index 4090313e3e..2588ec69d6 100644 --- a/client/rs/config/npctype/NpcModelLoader.ts +++ b/client/rs/config/npctype/NpcModelLoader.ts @@ -8,7 +8,7 @@ import { TextureLoader } from "../../texture/TextureLoader"; import { SeqType } from "../seqtype/SeqType"; import { SeqTypeLoader } from "../seqtype/SeqTypeLoader"; import { VarManager } from "../vartype/VarManager"; -import { NpcType } from "./NpcType"; +import { NpcType, npcTypeHasModel } from "./NpcType"; import { NpcTypeLoader } from "./NpcTypeLoader"; export class NpcModelLoader { @@ -49,8 +49,8 @@ export class NpcModelLoader { ); } - // NPC has no model IDs defined (opcode 1 was never decoded) - if (!npcType.modelIds || npcType.modelIds.length === 0) { + // NPC has no model IDs defined (opcode 1 was never decoded), or one of them is -1 + if (!npcTypeHasModel(npcType)) { return undefined; } diff --git a/client/rs/config/npctype/NpcType.ts b/client/rs/config/npctype/NpcType.ts index 03c9fce53f..103e029f85 100644 --- a/client/rs/config/npctype/NpcType.ts +++ b/client/rs/config/npctype/NpcType.ts @@ -23,6 +23,15 @@ export enum NpcDrawPriority { DRAW_PRIORITY_LAST = 2, } +/** + * Whether the type has a model to draw. A model id of -1 (the server's body customisation, e.g. + * the Hueycoatl's sunk tail) loads nothing, so the whole NPC is drawn as nothing and can't be clicked. + */ +export function npcTypeHasModel(type: T | undefined): type is T { + const ids = type?.modelIds; + return !!ids && ids.length > 0 && ids.every((id) => id >= 0); +} + export class NpcType extends Type { name: string; desc?: string; diff --git a/client/tests/npc-face-angle-hidden-models.test.ts b/client/tests/npc-face-angle-hidden-models.test.ts new file mode 100644 index 0000000000..d64d405b86 --- /dev/null +++ b/client/tests/npc-face-angle-hidden-models.test.ts @@ -0,0 +1,65 @@ +import assert from "node:assert/strict"; + +import { NpcUpdateDecoder } from "../game/sync/NpcUpdateDecoder"; +import { npcTypeHasModel } from "../rs/config/npctype/NpcType"; +import { + createNpcSyncState, + encodeNpcSync, +} from "../../server/src/main/typescript/elvarg/net/protocol/ClientProtocol"; + +/** + * The Hueycoatl's tail (rsprox.net 4052, 4054): it never turns, so live holds it with npc + * face_angle (instant) at 512 out of the east cave and 1536 out of the west one, and while it is + * sunk its body customisation replaces every model with -1, so it is drawn as nothing. + */ +function decodeNpcs(packet: Buffer, decoder: NpcUpdateDecoder) { + const body = packet.subarray(3); + const length = body.readUInt16BE(9); + return decoder.decode(body.subarray(11, 11 + length), { + large: body[4] === 1, + loopCycle: 0, + clientCycle: 100, + localTileX: 3200, + localTileY: 3200, + level: 0, + }); +} + +function roundTrip(): void { + const state = createNpcSyncState(); + const decoder = new NpcUpdateDecoder(); + const local = { x: 3200, y: 3200, level: 0 }; + const view = (extra: object) => ({ + index: 9, typeId: 14014, x: 3204, y: 3204, level: 0, + rotation: 0, walkDirection: -1, runDirection: -1, forcedChat: "before", ...extra, + }); + let decoded = decodeNpcs(encodeNpcSync(1, local, [view({}) as any], state), decoder); + assert.equal(decoded.updateBlocks.get(9)?.faceAngle, undefined, "none unless sent"); + + decoded = decodeNpcs(encodeNpcSync(2, local, [view({ + faceAngle: { angle: 512, instant: true }, + typeCustomisation: { models: [-1] }, + }) as any], state), decoder); + const block = decoded.updateBlocks.get(9); + assert.deepEqual(block?.faceAngle, { angle: 512, instant: true }); + assert.deepEqual(block?.typeCustomisation, { models: [-1] }, "-1 survives the wire"); + assert.equal(block?.say, "before", "the blocks before it stay aligned"); + + decoded = decodeNpcs(encodeNpcSync(3, local, [view({ faceAngle: { angle: 1536, instant: false } }) as any], state), decoder); + assert.deepEqual(decoded.updateBlocks.get(9)?.faceAngle, { angle: 1536, instant: false }); + + decoded = decodeNpcs(encodeNpcSync(4, local, [view({ typeCustomisation: { models: [-1, -1, -1] } }) as any], state), decoder); + assert.deepEqual(decoded.updateBlocks.get(9)?.typeCustomisation, { models: [-1, -1, -1] }, "the broken tail's three models"); +} + +function hiddenModelsDrawNothing(): void { + assert.equal(npcTypeHasModel({ modelIds: [50311] }), true); + assert.equal(npcTypeHasModel({ modelIds: [-1] }), false, "a -1 model is drawn as nothing"); + assert.equal(npcTypeHasModel({ modelIds: [50311, -1, 50312] }), false, "one -1 hides the whole NPC"); + assert.equal(npcTypeHasModel({ modelIds: [] }), false); + assert.equal(npcTypeHasModel(undefined), false); +} + +roundTrip(); +hiddenModelsDrawNothing(); +console.log("NPC face angle and hidden model tests passed"); diff --git a/docs/hueycoatl.md b/docs/hueycoatl.md index 201df2474c..e0a127825c 100644 --- a/docs/hueycoatl.md +++ b/docs/hueycoatl.md @@ -58,6 +58,7 @@ All ticks below are from rsprox 3399 (a solo fight, two kills) and agree with 32 ### Phase 3: the tail - The tail plays `npc_huey_tail_appear_01` (11720) and slams 2 ticks later; it stays 36 ticks, plays `npc_huey_tail_disappear_01` (11721) and shows on the other side 2 ticks later. While it rises and sinks it takes no damage (Wiki). +- The tail never turns (turn speed 0), so every show sets npc `face_angle` (instant) for its side: 512 (facing west) in the east cave, 1536 (facing east) in the west one; it is added with 512. It is added drawn as nothing (body customisation model -1) and the customisation is reset as it shows. 2 ticks after a sink that is not followed by a show on that tick, it is hidden again: model -1 for the whole tail, three -1s for the broken one (14015 has three models). A player who comes into view while it is sunk gets the hidden state with the add, so sees no tail (rsprox recording 4052: added at tick 80, shows at 81, 119; broken sinks at 159 and 189, hidden at 161 and 191). - Its hits are capped at 4, or 9 when the attacker's crush attack bonus is their highest; a miss still deals 1 (Wiki; the captured hits were 1, 4, 5 and 9). - The shielded head attacks every 15 ticks (`huey_shield_attack_*`, 11673-11675). - The tail broken: `npc_huey_tail_break_01` (11723) and the change to 14015 (`huey_tail_broken`), sound 9678, the head's `huey_screech` (11677). A tick later "The Hueycoatl's shield falls!"; 3 ticks after the break `huey_screech_reset` (11678) and the head is 14009 again. The broken tail sinks 4 ticks after it broke. @@ -75,7 +76,7 @@ All ticks below are from rsprox 3399 (a solo fight, two kills) and agree with 32 ## Attacks -- **Rain Fire:** the head rears with `huey_attack_