Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NPC worldIndex to NPC update packets #433

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
29 changes: 29 additions & 0 deletions src/engine/world/actor/player/sync/npc-sync-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ export class NpcSyncTask extends SyncTask<void> {
});
}

/**
* As of 2024-09-03 this has been modified to include an extra `short` if
* any updates are required. This extra `short` includes the `worldIndex`
* for this NPC, which helps the client figure out which NPC to apply the
* updates to.
*
* For the sake of efficiency, this `short` will only be added once, and it
* will always be added after the first updated value's data is processed.
*
* Make sure to keep your client updated so that it can handle it.
*/
private appendUpdateMaskData(npc: Npc, updateMaskData: ByteBuffer): void {
const updateFlags = npc.updateFlags;
if(!updateFlags.updateBlockRequired) {
Expand Down Expand Up @@ -103,12 +114,23 @@ export class NpcSyncTask extends SyncTask<void> {

updateMaskData.put(mask, 'BYTE');

let alreadyPutWorldIndex = false;
const putWorldIndex = () => {
if (alreadyPutWorldIndex) {
return;
}
updateMaskData.put(npc.worldIndex, 'SHORT');
alreadyPutWorldIndex = true;
}

if(updateFlags.damage !== null) {
const damage = updateFlags.damage;
updateMaskData.put(damage.damageDealt);
updateMaskData.put(damage.damageType.valueOf());
updateMaskData.put(damage.remainingHitpoints);
updateMaskData.put(damage.maxHitpoints);

putWorldIndex();
}

if(updateFlags.faceActor !== undefined) {
Expand All @@ -129,6 +151,8 @@ export class NpcSyncTask extends SyncTask<void> {

updateMaskData.put(worldIndex, 'SHORT');
}

putWorldIndex();
}

if(updateFlags.chatMessages.length !== 0) {
Expand All @@ -139,16 +163,20 @@ export class NpcSyncTask extends SyncTask<void> {
} else {
updateMaskData.putString('Undefined Message');
}

putWorldIndex();
}

if(updateFlags.appearanceUpdateRequired) {
updateMaskData.put(npc.id, 'SHORT');
putWorldIndex();
}

if(updateFlags.facePosition) {
const position = updateFlags.facePosition;
updateMaskData.put(position.x * 2 + 1, 'SHORT');
updateMaskData.put(position.y * 2 + 1, 'SHORT', 'LITTLE_ENDIAN');
putWorldIndex();
}

if(updateFlags.animation) {
Expand All @@ -163,6 +191,7 @@ export class NpcSyncTask extends SyncTask<void> {
updateMaskData.put(animation.id, 'SHORT');
updateMaskData.put(delay);
}
putWorldIndex();
}
}

Expand Down
Loading