Skip to content

Instantly share code, notes, and snippets.

@ultraviolet-jordan
Created November 30, 2023 00:57
Show Gist options
  • Save ultraviolet-jordan/9be633818293e66d0781cee013cf299b to your computer and use it in GitHub Desktop.
Save ultraviolet-jordan/9be633818293e66d0781cee013cf299b to your computer and use it in GitHub Desktop.
[ScriptOpcode.MAP_BLOCKED]: (state) => {
const coord = state.popInt();
if (coord < 0 || coord > Position.max) {
throw new Error(`MAP_BLOCKED attempted to use coord that was out of range: ${coord}. Range should be: 0 to ${Position.max}`);
}
const pos = Position.unpackCoord(coord);
const zone = World.getZone(pos.x, pos.z, pos.level);
const locs = zone.staticLocs.concat(zone.locs);
for (let index = 0; index < locs.length; index++) {
const loc = locs[index];
const type = LocType.get(loc.type);
if (type.active !== 1) {
continue;
}
const layer = LocShapes.layer(loc.shape);
if (loc.respawn !== -1 && layer === LocLayer.WALL) {
continue;
}
if (layer === LocLayer.WALL) {
if (loc.x === pos.x && loc.z === pos.z) {
state.pushInt(1);
return;
}
} else if (layer === LocLayer.GROUND) {
const width = (loc.rotation === LocRotation.NORTH || loc.rotation === LocRotation.SOUTH) ? loc.length : loc.width;
const length = (loc.rotation === LocRotation.NORTH || loc.rotation === LocRotation.SOUTH) ? loc.width : loc.length;
for (let index = 0; index < width * length; index++) {
const deltaX = loc.x + (index % width);
const deltaZ = loc.z + (index / width);
if (deltaX === pos.x && deltaZ === pos.z) {
state.pushInt(1);
return;
}
}
} else if (layer === LocLayer.GROUND_DECOR) {
if (loc.x === pos.x && loc.z === pos.z) {
state.pushInt(1);
return;
}
}
}
state.pushInt(0);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment