Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions src/engine/World.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,11 +619,6 @@ class World {
continue;
}

if ((!player.target || player.target instanceof Loc || player.target instanceof Obj) && player.faceEntity !== -1) {
player.faceEntity = -1;
player.masks |= player.entitymask;
}

if (!player.busy() && player.opcalled) {
player.moveClickRequest = false;
} else {
Expand Down Expand Up @@ -723,6 +718,8 @@ class World {
}
// - engine queue
player.processEngineQueue();
// Update target facing
player.setFaceEntity();
// - interactions
// - movement
player.processInteraction();
Expand Down Expand Up @@ -908,11 +905,13 @@ class World {

player.client.state = 1;

player.client.send(Uint8Array.from([
2,
Math.min(player.staffModLevel, 2),
1 // mouse tracking can only be enabled on login
]));
player.client.send(
Uint8Array.from([
2,
Math.min(player.staffModLevel, 2),
1 // mouse tracking can only be enabled on login
])
);

const remote = player.client.remoteAddress;
if (remote.indexOf('.') !== -1) {
Expand Down Expand Up @@ -1877,10 +1876,7 @@ class World {
} else if (reply === 10) {
// hop timer
const { remaining } = msg;
client.send(Uint8Array.from([
21,
Math.min(255, remaining! / 1000)
]));
client.send(Uint8Array.from([21, Math.min(255, remaining! / 1000)]));
client.close();
return;
}
Expand Down
6 changes: 2 additions & 4 deletions src/engine/entity/Npc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ export default class Npc extends PathingEntity {
this.processQueue();
// Movement-Interactions
this.processMovementInteraction();
// Update target facing
this.setFaceEntity();
// Dev note: Is this necessary?
this.validateDistanceWalked();
}
Expand Down Expand Up @@ -404,16 +406,12 @@ export default class Npc extends PathingEntity {
clearInteraction(): void {
super.clearInteraction();
this.targetOp = NpcMode.NONE;
this.faceEntity = -1;
this.masks |= NpcInfoProt.FACE_ENTITY;
}

resetDefaults(): void {
this.clearInteraction();
const type: NpcType = NpcType.get(this.type);
this.targetOp = type.defaultmode;
this.faceEntity = -1;
this.masks |= this.entitymask;

const npcType: NpcType = NpcType.get(this.type);
this.huntMode = npcType.huntmode;
Expand Down
39 changes: 22 additions & 17 deletions src/engine/entity/PathingEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,26 @@ export default abstract class PathingEntity extends Entity {
}
}

setFaceEntity(): void {
const oldEntity = this.faceEntity;
if (this.target instanceof Player) {
const playerSlot: number = this.target.slot + 32768;
if (this.faceEntity !== playerSlot) {
this.faceEntity = playerSlot;
}
} else if (this.target instanceof Npc) {
const nid: number = this.target.nid;
if (this.faceEntity !== nid) {
this.faceEntity = nid;
}
} else {
this.faceEntity = -1;
}
if (this.faceEntity !== oldEntity) {
this.masks |= this.entitymask;
}
}

setInteraction(interaction: Interaction, target: Entity, op: TargetOp, com?: number): boolean {
if (!target.isValid(this instanceof Player ? this.hash64 : undefined)) {
return false;
Expand All @@ -530,19 +550,7 @@ export default abstract class PathingEntity extends Entity {

this.focus(CoordGrid.fine(target.x, target.width), CoordGrid.fine(target.z, target.length), target instanceof NonPathingEntity && interaction === Interaction.ENGINE);

if (target instanceof Player) {
const playerSlot: number = target.slot + 32768;
if (this.faceEntity !== playerSlot) {
this.faceEntity = playerSlot;
this.masks |= this.entitymask;
}
} else if (target instanceof Npc) {
const nid: number = target.nid;
if (this.faceEntity !== nid) {
this.faceEntity = nid;
this.masks |= this.entitymask;
}
} else {
if (target instanceof NonPathingEntity) {
this.targetX = CoordGrid.fine(target.x, target.width);
this.targetZ = CoordGrid.fine(target.z, target.length);
}
Expand Down Expand Up @@ -614,10 +622,7 @@ export default abstract class PathingEntity extends Entity {
this.faceSquareX = -1;
this.faceSquareZ = -1;

if (!this.target && this.faceEntity !== -1) {
this.masks |= this.entitymask;
this.faceEntity = -1;
}
this.setFaceEntity();
}

private takeStep(): number | null {
Expand Down
18 changes: 13 additions & 5 deletions src/engine/entity/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,17 @@ export default class Player extends PathingEntity {

constructor(username: string, username37: bigint, hash64: bigint) {
super(
0, 3094, 3106, // tutorial island
1, 1,
EntityLifeCycle.FOREVER, MoveRestrict.NORMAL, BlockWalk.NPC, MoveStrategy.SMART, PlayerInfoProt.FACE_COORD, PlayerInfoProt.FACE_ENTITY
0,
3094,
3106, // tutorial island
1,
1,
EntityLifeCycle.FOREVER,
MoveRestrict.NORMAL,
BlockWalk.NPC,
MoveStrategy.SMART,
PlayerInfoProt.FACE_COORD,
PlayerInfoProt.FACE_ENTITY
);

this.username = username;
Expand Down Expand Up @@ -1755,7 +1763,7 @@ export default class Player extends PathingEntity {
const { basevar, startbit, endbit } = varbit;
const mask = Packet.bitmask[endbit - startbit + 1];

return this.vars[basevar] >> startbit & mask;
return (this.vars[basevar] >> startbit) & mask;
}

setVarBit(id: number, value: number) {
Expand All @@ -1772,7 +1780,7 @@ export default class Player extends PathingEntity {
}

mask <<= startbit;
this.setVar(basevar, mask & value << startbit | this.vars[basevar] & ~mask);
this.setVar(basevar, (mask & (value << startbit)) | (this.vars[basevar] & ~mask));
}

private writeVarp(id: number, value: number): void {
Expand Down
2 changes: 0 additions & 2 deletions src/network/game/client/handler/OpHeldHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ export default class OpHeldHandler extends ClientGameMessageHandler<OpHeld> {
}

player.moveClickRequest = false; // uses the dueling ring op to move whilst busy & queue pending: https://youtu.be/GPfN3Isl2rM
player.faceEntity = -1;
player.masks |= player.entitymask;

// opheld5 gets wealth logged in content
if (message.op !== 5) {
Expand Down
2 changes: 0 additions & 2 deletions src/network/game/client/handler/OpHeldTHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ export default class OpHeldTHandler extends ClientGameMessageHandler<OpHeldT> {
player.lastSlot = slot;

player.clearPendingAction();
player.faceEntity = -1;
player.masks |= player.entitymask;

player.addSessionLog(LoggerEventType.MODERATOR, `Cast ${spellCom.comName} on ${ObjType.get(obj).debugname}`);

Expand Down
2 changes: 0 additions & 2 deletions src/network/game/client/handler/OpHeldUHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ export default class OpHeldUHandler extends ClientGameMessageHandler<OpHeldU> {
const useObjType = ObjType.get(player.lastUseItem);

player.clearPendingAction();
player.faceEntity = -1;
player.masks |= player.entitymask;

if ((objType.members || useObjType.members) && !Environment.NODE_MEMBERS) {
player.messageGame("To use this item please login to a members' server.");
Expand Down
Loading