Skip to content

Feat/tick queue #440

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

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions data/config/item-spawns/test-area.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"item": "rs:bronze_axe",
"amount": 1,
"spawn_x": 2713,
"spawn_y": 9807,
"instance": "global",
"respawn": 25
}
]
4 changes: 0 additions & 4 deletions data/config/items/logs.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@
"extends": "rs:log",
"game_id": 1513
},
"rs:magic_pyre_logs": {
"extends": "rs:log",
"game_id": 1513
},
"rs:bark": {
"game_id": 3239,
"examine": "Bark from a hollow tree.",
Expand Down
9 changes: 9 additions & 0 deletions data/config/npc-spawns/test-area/test-shops.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{
"npc": "rs:dromunds_cat",
"spawn_x": 2712,
"spawn_y": 9806,
"movement_radius": 0,
"face": "SOUTH"
}
]
3 changes: 3 additions & 0 deletions data/config/npcs/general.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@
"skills": {
"hitpoints": 1
}
},
"rs:dromunds_cat": {
"game_id": 2140
}
}
44 changes: 44 additions & 0 deletions data/config/scenery-spawns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,47 @@
type: 10
orientation: 1
# End lumby castle roof bank construction objects
# Test area objects
- objectId: 1276
x: 2711
y: 9807
level: 0
type: 10
orientation: 1
- objectId: 1281
x: 2710
y: 9809
level: 0
type: 10
orientation: 1
- objectId: 1308
x: 2711
y: 9812
level: 0
type: 10
orientation: 1
- objectId: 1307
x: 2711
y: 9814
level: 0
type: 10
orientation: 1
- objectId: 1309
x: 2710
y: 9816
level: 0
type: 10
orientation: 1
- objectId: 1306
x: 2711
y: 9819
level: 0
type: 10
orientation: 1
- objectId: 4483
x: 2713
y: 9805
level: 0
type: 10
orientation: 4
# End test area
40 changes: 40 additions & 0 deletions data/config/shops/test-area/test-shop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"rs:test_shop": {
"name": "Testing Shop",
"shop_sell_rate": 1.0,
"shop_buy_rate": 1.0,
"rate_modifier": 0.03,
"stock": [
{
"itemKey": "rs:logs",
"amount": 100,
"restock": 25000
},
{
"itemKey": "rs:oak_logs",
"amount": 100,
"restock": 25000
},
{
"itemKey": "rs:willow_logs",
"amount": 100,
"restock": 25000
},
{
"itemKey": "rs:maple_logs",
"amount": 100,
"restock": 25000
},
{
"itemKey": "rs:yew_logs",
"amount": 100,
"restock": 25000
},
{
"itemKey": "rs:magic_logs",
"amount": 100,
"restock": 25000
}
]
}
}
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@
"type": "git",
"url": "git+ssh://[email protected]/runejs/server.git"
},
"keywords": ["runejs", "runescape", "typescript", "game server", "game engine"],
"keywords": [
"runejs",
"runescape",
"typescript",
"game server",
"game engine"
],
"author": "Tynarus",
"license": "GPL-3.0",
"bugs": {
Expand Down Expand Up @@ -73,5 +79,6 @@
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.7.3"
}
},
"packageManager": "[email protected]+sha256.e4fc5f94867cd0b492fb0a644f14e7b47c4387bc75d46b56e86db6d0f1a6cb97"
}
4 changes: 2 additions & 2 deletions src/engine/action/pipe/task/walk-to-actor-plugin-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export class WalkToActorPluginTask<
/**
* Executed every tick to check if the player has arrived yet and calls the plugins if so.
*/
public execute(): void {
public async execute(): Promise<void> {
// call super to manage waiting for the movement to complete
super.execute();
await super.execute();

// check if the player has arrived yet
const other = this.other;
Expand Down
42 changes: 27 additions & 15 deletions src/engine/action/pipe/task/walk-to-object-plugin-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { ItemOnObjectAction } from '@engine/action/pipe/item-on-object.acti
import type { ObjectInteractionAction } from '@engine/action/pipe/object-interaction.action';
import { ActorLandscapeObjectInteractionTask } from '@engine/task/impl/actor-landscape-object-interaction-task';
import type { Player } from '@engine/world/actor/player/player';
import { Position } from '@engine/world/position';
import type { LandscapeObject } from '@runejs/filestore';

/**
Expand Down Expand Up @@ -35,38 +36,49 @@ export class WalkToObjectPluginTask<TAction extends ObjectAction> extends ActorL
private data: ObjectActionData<TAction>;

constructor(plugins: ObjectActionHook<TAction>[], player: Player, landscapeObject: LandscapeObject, data: ObjectActionData<TAction>) {
const rendering = data.objectConfig?.rendering;
let sizeX = rendering?.sizeX || 1;
let sizeY = rendering?.sizeY || 1;

// Get the object's facing direction (0-3 maps to WNES array) TODO: verify
const face = rendering?.face || 0;

// If facing East or West, swap X and Y dimensions
if (face === 0 || face === 2) {
// WEST or EAST
[sizeX, sizeY] = [sizeY, sizeX];
}
super(
player,
landscapeObject,
// TODO (jkm) handle object size
// TODO (jkm) pass orientation instead of size
1,
1,
sizeX,
sizeY,
);

this.plugins = plugins;
this.data = data;
}

/**
* Executed every tick to check if the player has arrived yet and calls the plugins if so.
*/
public execute(): void {
// call super to manage waiting for the movement to complete
super.execute();

// check if the player has arrived yet
protected onObjectReached(): void {
const landscapeObject = this.landscapeObject;
const landscapeObjectPosition = this.landscapeObjectPosition;

if (!landscapeObject || !landscapeObjectPosition) {
this.stop();
return;
}

// call the relevant plugins
// Make the actor face the center of the object
const objectCenter = new Position(
landscapeObjectPosition.x + Math.floor((this.data.objectConfig?.rendering?.sizeX || 1) / 2),
landscapeObjectPosition.y + Math.floor((this.data.objectConfig?.rendering?.sizeY || 1) / 2),
landscapeObjectPosition.level,
);
this.actor.face(objectCenter);

this.plugins.forEach(plugin => {
if (!plugin || !plugin.handler) {
return;
}
if (!plugin?.handler) return;

const action = {
player: this.actor,
Expand Down
7 changes: 4 additions & 3 deletions src/engine/net/inbound-packets/walk.packet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ const walkPacket = (player: Player, packet: PacketData) => {
size -= 14;
}

if (!player.canMove()) {
// Check if player can move and isn't delayed
if (!player.canMove() || player.delayManager.isDelayed()) {
return;
}

const totalSteps = Math.floor((size - 5) / 2);

const firstY = buffer.get('short', 'u', 'le');
const runSteps = buffer.get('byte') === 1; // @TODO forced running
const runSteps = buffer.get('byte') === 1;
const firstX = buffer.get('short', 'u', 'le');

const walkingQueue = player.walkingQueue;

// Cancel any weak tasks since movement interrupts them
player.actionsCancelled.next('manual-movement');

walkingQueue.clear();
Expand Down
Loading