Skip to content

Commit 4eb453c

Browse files
committed
Merge branch 'develop' into feature/construction
2 parents e049435 + 08e29bf commit 4eb453c

File tree

8 files changed

+79
-53
lines changed

8 files changed

+79
-53
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"bigi": "^1.4.2",
3636
"js-yaml": "^3.13.1",
3737
"json5": "^2.1.3",
38-
"lodash": "^4.17.15",
38+
"lodash": "^4.17.21",
3939
"quadtree-lib": "^1.0.9",
4040
"rxjs": "^7.0.0",
4141
"source-map-support": "^0.5.19",

src/game-engine/net/inbound-packets/character-design-packet.js renamed to src/game-engine/net/inbound-packets/character-design-packet.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
const characterDesignPacket = (player, packet) => {
1+
import { Player } from '@engine/world/actor/player/player';
2+
import { PacketData } from '@engine/net/inbound-packets';
3+
4+
5+
const characterDesignPacket = (player: Player, packet: PacketData) => {
26
const { buffer } = packet;
37

48
// @TODO verify validity of selections
@@ -32,7 +36,7 @@ const characterDesignPacket = (player, packet) => {
3236
};
3337

3438
player.updateFlags.appearanceUpdateRequired = true;
35-
player.player.interfaceState.closeAllSlots();
39+
player.interfaceState.closeAllSlots();
3640
};
3741

3842
export default {

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/actor.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { Player } from '@engine/world/actor/player/player';
1515
import { ActionCancelType, ActionPipeline } from '@engine/world/action';
1616
import { LandscapeObject } from '@runejs/filestore';
1717

18+
1819
/**
1920
* Handles an actor within the game world.
2021
*/
@@ -93,7 +94,6 @@ export abstract class Actor {
9394
*/
9495
public async waitForPathing(target: Position | LandscapeObject): Promise<void>;
9596
public async waitForPathing(target: Position | LandscapeObject): Promise<void> {
96-
console.log(target);
9797
if(this.position.withinInteractionDistance(target)) {
9898
return;
9999
}
@@ -131,6 +131,10 @@ export abstract class Actor {
131131
}
132132

133133
public async moveBehind(target: Actor): Promise<boolean> {
134+
if(this.position.level !== target.position.level) {
135+
return false;
136+
}
137+
134138
const distance = Math.floor(this.position.distanceBetween(target.position));
135139
if(distance > 16) {
136140
this.clearFaceActor();
@@ -153,6 +157,10 @@ export abstract class Actor {
153157
}
154158

155159
public async moveTo(target: Actor): Promise<boolean> {
160+
if(this.position.level !== target.position.level) {
161+
return false;
162+
}
163+
156164
const distance = Math.floor(this.position.distanceBetween(target.position));
157165
if(distance > 16) {
158166
this.clearFaceActor();
@@ -172,7 +180,11 @@ export abstract class Actor {
172180
this.metadata['following'] = target;
173181

174182
this.moveBehind(target);
175-
const subscription = target.walkingQueue.movementEvent.subscribe(async () => this.moveBehind(target));
183+
const subscription = target.walkingQueue.movementEvent.subscribe(() => {
184+
if(!this.moveBehind(target)) {
185+
this.actionsCancelled.next(null);
186+
}
187+
});
176188

177189
this.actionsCancelled.pipe(
178190
filter(type => type !== 'pathing-movement'),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,8 @@ export class Player extends Actor {
654654
const newChunk = world.chunkManager.getChunkForWorldPosition(newPosition);
655655

656656
if(!oldChunk.equals(newChunk)) {
657+
oldChunk.removePlayer(this);
658+
newChunk.addPlayer(this);
657659
this.metadata['updateChunk'] = { newChunk, oldChunk };
658660

659661
if(updateRegion) {

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

Lines changed: 2 additions & 1 deletion
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);
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)