@abextm/cache2
Version:
Utilities for reading OSRS "caches"
270 lines (269 loc) • 8.96 kB
JavaScript
import { PerFileLoadable } from "../Loadable.js";
import { Typed } from "../reflect.js";
import { Params, } from "../types.js";
export class NPC extends PerFileLoadable {
id;
constructor(id) {
super();
this.id = id;
}
static index = 2;
static archive = 9;
static gameval = 1;
models = [];
name = "null";
size = 1;
standingAnimation = -1;
walkingAnimation = -1;
idleRotateLeftAnimation = -1;
idleRotateRightAnimation = -1;
rotate180Animation = -1;
rotateLeftAnimation = -1;
rotateRightAnimation = -1;
category = -1;
actions = [null, null, null, null, null];
recolorFrom = [];
recolorTo = [];
retextureFrom = [];
retextureTo = [];
chatheadModels = [];
isMinimapVisible = true;
combatLevel = -1;
widthScale = 128;
heightScale = 128;
isVisible = false;
ambient = 0;
contrast = 0;
headIconArchive = [];
headIconSpriteIndex = [];
rotationSpeed = 32;
varbit = -1;
varp = -1;
multiChildren = [];
oobChild = -1;
isInteractible = true;
isClickable = true;
isFollower = false;
lowPriorityOps = false;
runAnimation = -1;
runRotate180Animation = -1;
runRotateLeftAnimation = -1;
runRotateRightAnimation = -1;
crawlAnimation = -1;
crawlRotate180Animation = -1;
crawlRotateLeftAnimation = -1;
crawlRotateRightAnimation = -1;
attack = 1;
defence = 1;
strength = 1;
hitpoints = 1;
ranged = 1;
magic = 1;
height = -1;
params = new Params();
static decode(r, id) {
const v = new NPC(id);
for (let opcode; (opcode = r.u8()) != 0;) {
switch (opcode) {
case 1: {
let len = r.u8();
v.models = new Array(len);
for (let i = 0; i < len; i++) {
v.models[i] = r.u16();
}
break;
}
case 2:
v.name = r.string();
break;
case 12:
v.size = r.u8();
break;
case 13:
v.standingAnimation = r.u16();
break;
case 14:
v.walkingAnimation = r.u16();
break;
case 15:
v.idleRotateLeftAnimation = r.u16();
break;
case 16:
v.idleRotateRightAnimation = r.u16();
break;
case 17:
v.walkingAnimation = r.u16();
v.rotate180Animation = r.u16();
v.rotateLeftAnimation = r.u16();
v.rotateRightAnimation = r.u16();
break;
case 18:
v.category = r.u16();
break;
case 30:
case 31:
case 32:
case 33:
case 34:
v.actions[opcode - 30] = r.stringNullHidden();
break;
case 40: {
let len = r.u8();
v.recolorFrom = new Array(len);
v.recolorTo = new Array(len);
for (let i = 0; i < len; i++) {
v.recolorFrom[i] = r.u16();
v.recolorTo[i] = r.u16();
}
break;
}
case 41: {
let len = r.u8();
v.retextureFrom = new Array(len);
v.retextureTo = new Array(len);
for (let i = 0; i < len; i++) {
v.retextureFrom[i] = r.u16();
v.retextureTo[i] = r.u16();
}
break;
}
case 60: {
let len = r.u8();
v.chatheadModels = new Array(len);
for (let i = 0; i < len; i++) {
v.chatheadModels[i] = r.u16();
}
break;
}
case 74:
v.attack = r.u16();
break;
case 75:
v.defence = r.u16();
break;
case 76:
v.strength = r.u16();
break;
case 77:
v.hitpoints = r.u16();
break;
case 78:
v.ranged = r.u16();
break;
case 79:
v.magic = r.u16();
break;
case 93:
v.isMinimapVisible = false;
break;
case 95:
v.combatLevel = r.u16();
break;
case 97:
v.widthScale = r.u16();
break;
case 98:
v.heightScale = r.u16();
break;
case 99:
v.isVisible = true;
break;
case 100:
v.ambient = r.i8();
break;
case 101:
v.contrast = r.i8();
break;
case 102:
if (!r.isAfter({ era: "osrs", indexRevision: 3642 })) {
v.headIconArchive = [-1];
v.headIconSpriteIndex = [r.u16()];
}
else {
let bitfield = r.u8();
v.headIconArchive = [];
v.headIconSpriteIndex = [];
for (let bits = bitfield; bits != 0; bits >>= 1) {
if ((bits & 1) == 0) {
v.headIconArchive.push(-1);
v.headIconSpriteIndex.push(-1);
}
else {
v.headIconArchive.push(r.s2o4n());
v.headIconSpriteIndex.push(r.u8o16m1());
}
}
}
break;
case 103:
v.rotationSpeed = r.u16();
break;
case 106: {
v.varbit = r.u16n();
v.varp = r.u16n();
let len = r.u8p1();
v.multiChildren = new Array(len);
for (let i = 0; i < len; i++) {
v.multiChildren[i] = r.u16n();
}
break;
}
case 107:
v.isInteractible = false;
break;
case 109:
v.isClickable = false;
break;
case 111:
// removed in 220
v.isFollower = true;
v.lowPriorityOps = true;
break;
case 114:
v.runAnimation = r.u16();
break;
case 115:
v.runAnimation = r.u16();
v.runRotate180Animation = r.u16();
v.runRotateLeftAnimation = r.u16();
v.runRotateRightAnimation = r.u16();
break;
case 116:
v.crawlAnimation = r.u16();
break;
case 117:
v.crawlAnimation = r.u16();
v.crawlRotate180Animation = r.u16();
v.crawlRotateLeftAnimation = r.u16();
v.crawlRotateRightAnimation = r.u16();
break;
case 118: {
v.varbit = r.u16n();
v.varp = r.u16n();
v.oobChild = r.u16n();
let len = r.u8p1();
v.multiChildren = new Array(len);
for (let i = 0; i < len; i++) {
v.multiChildren[i] = r.u16n();
}
break;
}
case 122:
v.isFollower = true;
break;
case 123:
v.lowPriorityOps = true;
break;
case 124:
v.height = r.u16();
break;
case 249:
v.params = r.params();
break;
default:
throw new Error(`unknown opcode ${opcode}`);
}
}
return v;
}
}