Skip to content

Commit

Permalink
Merge pull request #150 from clementop/travel-to
Browse files Browse the repository at this point in the history
add travel command
  • Loading branch information
TheBlackParade authored Jun 3, 2020
2 parents 7843dd7 + 0c59b1b commit acfb399
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 0 deletions.
102 changes: 102 additions & 0 deletions data/config/travel-locations-data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
- name: Lumbridge
x: 3221
y: 3219
- name: Al Kharid
x: 3293
y: 3184
- name: Varrock
x: 3213
y: 3425
- name: Barbarian Village
x: 3082
y: 3416
- name: Edgeville
x: 3089
y: 3487
- name: Draynor Village
x: 3083
y: 3249
- name: Wizard's Tower
x: 3113
y: 3169
- name: Port Sarim
x: 3019
y: 3244
- name: Rimmington
x: 2956
y: 3209
- name: Falador
x: 2965
y: 3383
- name: Taverly
x: 2895
y: 3436
- name: Burthorpe
x: 2898
y: 3544
- name: Catherby
x: 2805
y: 3435
- name: Seer's Village
x: 2730
y: 3485
- name: Rellekka
x: 2659
y: 3657
- name: Entrana
x: 2827
y: 3343
- name: Karamja
x: 2917
y: 3175
- name: Brimhaven
x: 2795
y: 3177
- name: Shilo Village
x: 2849
y: 2961
- name: Marim
x: 2758
y: 2781
- name: Yanille
x: 2605
y: 3093
- name: Port Khazard
x: 2655
y: 3157
- name: Ardougne
x: 2663
y: 3305
- name: West Ardougne
x: 2533
y: 3306
- name: Tree Gnome Stronghold
x: 2450
y: 3422
- name: Digsite
x: 3359
y: 3416
- name: Canifis
x: 3494
y: 3483
- name: Mort'ton
x: 3488
y: 3288
- name: Port Phasmatys
x: 3666
y: 3486
- name: Ruins of Uzer
x: 3482
y: 3090
- name: Nardah
x: 3419
y: 2917
- name: Sophanem
x: 3305
y: 2788
- name: Pollnivneach
x: 3358
y: 2970
- name: Bedabin Camp
x: 3169
y: 3034
30 changes: 30 additions & 0 deletions src/plugins/commands/travel-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ActionType, RunePlugin } from '@server/plugins/plugin';
import { commandAction } from '@server/world/actor/player/action/input-command-action';
import { world } from '@server/game-server';
import { TravelLocation } from '@server/world/config/travel-locations';

const action: commandAction = (details) => {
const { player, args } = details;

const search: string = args.search as string;
const location = world.travelLocations.find(search) as TravelLocation;

if (location) {
player.teleport(location.position);
player.sendLogMessage(`Welcome to ${location.name}`, details.isConsole);
} else {
player.sendLogMessage(`Unknown location ${search}`, details.isConsole);
}
};

export default new RunePlugin({
type: ActionType.COMMAND,
commands: [ 'travel' ],
args: [
{
name: 'search',
type: 'string'
}
],
action
});
46 changes: 46 additions & 0 deletions src/world/config/travel-locations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { readFileSync } from 'fs';
import { JSON_SCHEMA, safeLoad } from 'js-yaml';
import { Position } from '@server/world/position';

interface RawTravelLocation {
name: string;
x: number;
y: number;
}

export interface TravelLocation {
name: string;
key: string;
position: Position;
}

const readLocations = (): TravelLocation[] => {
const locationData = safeLoad(
readFileSync('data/config/travel-locations-data.yaml', 'utf8'),
{ schema: JSON_SCHEMA }) as RawTravelLocation[];
return locationData.map((location) => {
return {
name: location.name,
key: location.name.toLowerCase(),
position: new Position(location.x, location.y, 0),
};
}) as TravelLocation[];
};

export default class TravelLocations {
private readonly locations: TravelLocation[];

public constructor () {
this.locations = readLocations();
}

public find (search: string): TravelLocation {
search = search.toLowerCase().trim();
for (const location of this.locations) {
if (location.key.indexOf(search) >= 0) {
return location;
}
}
return null;
}
}
2 changes: 2 additions & 0 deletions src/world/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Position } from './position';
import { NpcSpawn, parseNpcSpawns } from './config/npc-spawn';
import { Npc } from './actor/npc/npc';
import { parseShops, Shop } from '@server/world/config/shops';
import TravelLocations from '@server/world/config/travel-locations';
import Quadtree from 'quadtree-lib';
import { timer } from 'rxjs';
import { Actor } from '@server/world/actor/actor';
Expand Down Expand Up @@ -40,6 +41,7 @@ export class World {
public readonly examine: ExamineCache = new ExamineCache();
public readonly npcSpawns: NpcSpawn[];
public readonly shops: Shop[];
public readonly travelLocations: TravelLocations = new TravelLocations();
public readonly playerTree: Quadtree<any>;
public readonly npcTree: Quadtree<any>;

Expand Down

0 comments on commit acfb399

Please sign in to comment.