Skip to content

Commit e3ec1f3

Browse files
committed
Fixing teleporting not re-syncing players correctly in local chunks
1 parent 431e6b5 commit e3ec1f3

File tree

4 files changed

+53
-43
lines changed

4 files changed

+53
-43
lines changed

src/game-engine/world/action/hooks/task.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ export class TaskExecutor<T> {
131131
this.running = false;
132132
this.intervalSubscription?.unsubscribe();
133133

134-
await this.task?.onComplete(this, this.iteration);
134+
if(this.task?.onComplete) {
135+
await this.task.onComplete(this, this.iteration);
136+
}
135137

136138
this.session = null;
137139
}

src/game-engine/world/actor/player/player.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,8 @@ export class Player extends Actor {
642642
this.metadata['teleporting'] = true;
643643

644644
if(!oldChunk.equals(newChunk)) {
645+
oldChunk.removePlayer(this);
646+
newChunk.addPlayer(this);
645647
this.metadata['updateChunk'] = { newChunk, oldChunk };
646648

647649
this.actionPipeline.call('region_change', regionChangeActionFactory(

src/game-engine/world/actor/player/sync/actor-sync.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ export function syncTrackedActors(packet: Packet, playerPosition: Position, appe
9797
}
9898

9999
if(exists && nearbyActors.findIndex(m => m.actor.equals(trackedActor)) !== -1
100-
&& trackedActor.position.withinViewDistance(playerPosition)) {
100+
&& trackedActor.position.withinViewDistance(playerPosition)
101+
&& !trackedActor.metadata['teleporting']) {
101102
appendMovement(trackedActor, packet);
102103
appendUpdateMaskData(trackedActor);
103104
existingTrackedActors.push(trackedActor);
@@ -144,6 +145,6 @@ export function appendMovement(actor: Actor, packet: ByteBuffer): void {
144145

145146
export abstract class SyncTask<T> {
146147

147-
public abstract async execute(): Promise<T>;
148+
public abstract execute(): Promise<T>;
148149

149150
}
Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { buttonActionHandler } from '@engine/world/action/button.action';
1+
import { ButtonAction, buttonActionHandler, ButtonActionHook } from '@engine/world/action/button.action';
22
import { Player } from '@engine/world/actor/player/player';
33
import { Position } from '@engine/world/position';
44
import { animationIds } from '@engine/world/config/animation-ids';
55
import { soundIds } from '@engine/world/config/sound-ids';
66
import { gfxIds } from '@engine/world/config/gfx-ids';
77
import { loopingEvent } from '@engine/game-server';
8+
import { TaskExecutor } from '@engine/world/action';
89

910
enum Teleports {
1011
Home = 591,
@@ -22,57 +23,61 @@ const buttonIds: number[] = [
2223
591, // Home Teleport
2324
];
2425

25-
function homeTeleport(player: Player): void {
26-
let elapsedTicks = 0;
26+
function homeTeleport(player: Player, elapsedTicks: number): boolean {
27+
if (elapsedTicks === 0) {
28+
player.playAnimation(animationIds.homeTeleportDraw);
29+
player.playGraphics({ id: gfxIds.homeTeleportDraw, delay: 0, height: 0 });
30+
player.outgoingPackets.playSound(soundIds.homeTeleportDraw, 10);
31+
} else if (elapsedTicks === 7) {
32+
player.playAnimation(animationIds.homeTeleportSit);
33+
player.playGraphics({ id: gfxIds.homeTeleportFullDrawnCircle, delay: 0, height: 0 });
34+
player.outgoingPackets.playSound(soundIds.homeTeleportSit, 10);
35+
} else if (elapsedTicks === 12) {
36+
player.playAnimation(animationIds.homeTeleportPullOutAndReadBook);
37+
player.playGraphics({ id: gfxIds.homeTeleportPullOutBook, delay: 0, height: 0 });
38+
player.outgoingPackets.playSound(soundIds.homeTeleportPullOutBook, 10);
39+
} else if (elapsedTicks === 16) {
40+
player.playAnimation(animationIds.homeTeleportReadBookAndGlowCircle);
41+
player.playGraphics({ id: gfxIds.homeTeleportCircleGlow, delay: 0, height: 0 });
42+
player.outgoingPackets.playSound(soundIds.homeTeleportCircleGlowAndTeleport, 10);
43+
} else if (elapsedTicks === 20) {
44+
player.playAnimation(animationIds.homeTeleport);
45+
player.playGraphics({ id: gfxIds.homeTeleport, delay: 0, height: 0 });
46+
} else if (elapsedTicks === 22) {
47+
player.teleport(new Position(3218, 3218));
48+
return true;
49+
}
2750

28-
const loop = loopingEvent({ player });
29-
loop.event.subscribe(() => {
30-
if (elapsedTicks === 0) {
31-
player.playAnimation(animationIds.homeTeleportDraw);
32-
player.playGraphics({ id: gfxIds.homeTeleportDraw, delay: 0, height: 0 });
33-
player.outgoingPackets.playSound(soundIds.homeTeleportDraw, 10);
34-
}
35-
if (elapsedTicks === 7) {
36-
player.playAnimation(animationIds.homeTeleportSit);
37-
player.playGraphics({ id: gfxIds.homeTeleportFullDrawnCircle, delay: 0, height: 0 });
38-
player.outgoingPackets.playSound(soundIds.homeTeleportSit, 10);
39-
}
40-
if (elapsedTicks === 12) {
41-
player.playAnimation(animationIds.homeTeleportPullOutAndReadBook);
42-
player.playGraphics({ id: gfxIds.homeTeleportPullOutBook, delay: 0, height: 0 });
43-
player.outgoingPackets.playSound(soundIds.homeTeleportPullOutBook, 10);
44-
}
45-
if (elapsedTicks === 16) {
46-
player.playAnimation(animationIds.homeTeleportReadBookAndGlowCircle);
47-
player.playGraphics({ id: gfxIds.homeTeleportCircleGlow, delay: 0, height: 0 });
48-
player.outgoingPackets.playSound(soundIds.homeTeleportCircleGlowAndTeleport, 10);
49-
}
50-
if (elapsedTicks === 20) {
51-
player.playAnimation(animationIds.homeTeleport);
52-
player.playGraphics({ id: gfxIds.homeTeleport, delay: 0, height: 0 });
53-
}
54-
if (elapsedTicks === 22) {
55-
player.teleport(new Position(3218, 3218));
56-
loop.cancel();
57-
return;
58-
}
59-
elapsedTicks++;
60-
});
51+
return false;
6152
}
6253

63-
export const handler: buttonActionHandler = (details) => {
64-
const { player, buttonId } = details;
54+
export const activate = (task: TaskExecutor<ButtonAction>, elapsedTicks: number = 0) => {
55+
const { player, buttonId } = task.actionData;
56+
57+
let completed: boolean = false;
6558

6659
switch (buttonId) {
6760
case Teleports.Home:
68-
homeTeleport(player);
61+
completed = homeTeleport(player, elapsedTicks);
6962
break;
7063
}
64+
65+
if(completed) {
66+
task.stop();
67+
}
7168
};
7269

7370
export default {
7471
pluginId: 'rs:magic_teleports',
7572
hooks: [
76-
{ type: 'button', widgetId: 192, buttonIds: buttonIds, handler }
73+
{
74+
type: 'button',
75+
widgetId: 192,
76+
buttonIds: buttonIds,
77+
task: {
78+
activate,
79+
interval: 1
80+
}
81+
} as ButtonActionHook
7782
]
7883
};

0 commit comments

Comments
 (0)