Skip to content

Commit

Permalink
Merge branch 'develop' into feature/rotten-potato
Browse files Browse the repository at this point in the history
  • Loading branch information
Promises authored Apr 7, 2021
2 parents 34428df + afae3de commit d6b654e
Show file tree
Hide file tree
Showing 51 changed files with 2,181 additions and 379 deletions.
1,406 changes: 1,406 additions & 0 deletions cache/file-names.properties

Large diffs are not rendered by default.

491 changes: 413 additions & 78 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
},
"repository": {
"type": "git",
"url": "git+ssh://[email protected]/rune-js/server.git"
"url": "git+ssh://[email protected]/runejs/server.git"
},
"bugs": {
"url": "https://github.com/rune-js/server/issues"
"url": "https://github.com/runejs/server/issues"
},
"homepage": "https://github.com/rune-js/server#readme",
"homepage": "https://github.com/runejs/server#readme",
"author": "Tynarus",
"license": "GPL-3.0",
"dependencies": {
"@hapi/joi": "^16.1.8",
"@runejs/cache-parser": "0.7.0",
"@runejs/core": "^1.0.0-beta.0",
"@runejs/core": "^1.2.0",
"@runejs/filestore": "^0.10.2",
"@runejs/login-server": "^1.0.0-beta.2",
"@runejs/update-server": "^1.0.0-beta.0",
"bcrypt": "^5.0.0",
Expand All @@ -44,9 +44,9 @@
"quadtree-lib": "^1.0.9",
"rxjs": "^7.0.0-beta.8",
"source-map-support": "^0.5.16",
"ts-node": "^8.4.1",
"tslib": "^1.10.0",
"typescript": "^3.7.2",
"ts-node": "^9.1.1",
"tslib": "^2.1.0",
"typescript": "^4.2.3",
"uuid": "^3.3.3",
"yargs": "^15.3.1"
},
Expand All @@ -64,7 +64,7 @@
"@types/js-yaml": "^3.12.1",
"@types/json5": "0.0.30",
"@types/lodash": "^4.14.149",
"@types/node": "^12.12.6",
"@types/node": "^14.14.37",
"@types/uuid": "^3.4.6",
"@types/yargs": "^13.0.4",
"@typescript-eslint/eslint-plugin": "^4.6.0",
Expand Down
19 changes: 10 additions & 9 deletions src/game-engine/config/data-dump.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { join } from 'path';
import { writeFileSync } from 'fs';
import { cache } from '@engine/game-server';
import { filestore } from '@engine/game-server';
import { logger } from '@runejs/core';
import { ItemDefinition, NpcDefinition, Widget } from '@runejs/cache-parser';
import { ItemConfig, NpcConfig, ObjectConfig } from '@runejs/filestore';

function dump<T>(fileName: string, definitions: Map<number, T>): boolean {

function dump<T>(fileName: string, definitions: T[]): boolean {
const filePath = join('data/dump', fileName);

const arr = [];
for(let i = 0; i < definitions.size; i++) {
arr.push(definitions.get(i));
for(let i = 0; i < definitions.length; i++) {
arr.push(definitions[i]);
}

try {
Expand All @@ -22,13 +23,13 @@ function dump<T>(fileName: string, definitions: Map<number, T>): boolean {
}

export function dumpNpcs(): boolean {
return dump<NpcDefinition>('npcs.json', cache.npcDefinitions);
return dump<NpcConfig>('npcs.json', filestore.configStore.npcStore.decodeNpcStore());
}

export function dumpItems(): boolean {
return dump<ItemDefinition>('items.json', cache.itemDefinitions);
return dump<ItemConfig>('items.json', filestore.configStore.itemStore.decodeItemStore());
}

export function dumpWidgets(): boolean {
return dump<Widget>('widgets.json', cache.widgets);
export function dumpObjects(): boolean {
return dump<ObjectConfig>('objects.json', filestore.configStore.objectStore.decodeObjectStore());
}
11 changes: 6 additions & 5 deletions src/game-engine/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import {
loadItemConfigurations,
translateItemConfig
} from '@engine/config/item-config';
import { cache, questMap } from '@engine/game-server';
import { filestore, questMap } from '@engine/game-server';
import {
loadNpcConfigurations,
NpcDetails,
NpcPresetConfiguration,
translateNpcConfig
translateNpcServerConfig
} from '@engine/config/npc-config';
import { loadNpcSpawnConfigurations, NpcSpawn } from '@engine/config/npc-spawn-config';
import { loadShopConfigurations, Shop } from '@engine/config/shop-config';
Expand All @@ -23,6 +23,7 @@ import { loadSkillGuideConfigurations, SkillGuide } from '@engine/config/skill-g
import { loadMusicRegionConfigurations, MusicTrack } from '@engine/config/music-regions-config';
require('json5/lib/register');


export async function loadConfigurationFiles(configurationDir: string): Promise<any[]> {
const files = [];

Expand Down Expand Up @@ -128,7 +129,7 @@ export const findItem = (itemKey: number | string): ItemDetails | null => {
}

if(gameId) {
const cacheItem = cache.itemDefinitions.get(gameId);
const cacheItem = filestore.configStore.itemStore.getItem(gameId);
item = _.merge(item, cacheItem);
}

Expand All @@ -146,7 +147,7 @@ export const findNpc = (npcKey: number | string): NpcDetails | null => {
npcKey = npcIdMap[gameId];

if(!npcKey) {
const cacheNpc = cache.npcDefinitions.get(gameId);
const cacheNpc = filestore.configStore.npcStore.getNpc(gameId);
if(cacheNpc) {
return cacheNpc as any;
} else {
Expand Down Expand Up @@ -176,7 +177,7 @@ export const findNpc = (npcKey: number | string): NpcDetails | null => {
extensions.forEach(extKey => {
const extensionNpc = npcPresetMap[extKey];
if(extensionNpc) {
npc = _.merge(npc, translateNpcConfig(undefined, extensionNpc));
npc = _.merge(npc, translateNpcServerConfig(undefined, extensionNpc));
}
});
}
Expand Down
88 changes: 43 additions & 45 deletions src/game-engine/config/npc-config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { DefensiveBonuses, translateItemConfig } from '@engine/config/item-config';
import { DefensiveBonuses } from '@engine/config/item-config';
import { loadConfigurationFiles } from '@engine/config/index';
import { cache } from '@engine/game-server';
import { filestore } from '@engine/game-server';
import _ from 'lodash';
import { NpcConfig } from '@runejs/filestore';
import { logger } from '@runejs/core';


export interface NpcSkills {
[key: string]: number;
Expand All @@ -17,24 +20,19 @@ export interface OffensiveStats {
rangedStrength?: number;
}

export interface NpcAnimations {
export interface NpcCombatAnimations {
attack?: number | number[];
defend?: number;
death?: number;
stand?: number;
walk?: number;
turnAround?: number;
turnRight?: number;
turnLeft?: number;
}

export type DropTable = [ [ string, string, number, number? ] ];

export interface NpcPresetConfiguration {
[key: string]: NpcConfiguration;
[key: string]: NpcServerConfig;
}

export interface NpcConfiguration {
export interface NpcServerConfig {
extends?: string | string[];
game_id: number;
skills?: NpcSkills;
Expand All @@ -52,47 +50,39 @@ export interface NpcConfiguration {
defensive_stats?: DefensiveBonuses;
variations?: [{
suffix: string;
} & NpcConfiguration];
animations?: NpcAnimations;
} & NpcServerConfig];
animations?: NpcCombatAnimations;
drop_table?: DropTable;
metadata: { [key: string]: unknown };
}

/**
* Full server + cache details about a specific game NPC.
*/
export class NpcDetails {
export class NpcDetails extends NpcConfig {

extends?: string | string[];
key: string;
gameId: number;
name?: string;
skills?: NpcSkills;
killable?: boolean;
respawnTime?: number;
offensiveStats?: OffensiveStats;
defensiveStats?: DefensiveBonuses;
animations?: NpcAnimations;
combatAnimations?: NpcCombatAnimations;
dropTable?: DropTable;
metadata: { [key: string]: unknown } = {};
options?: string[];
models?: number[];
headModels?: number[];
minimapVisible?: boolean;
combatLevel?: number;
boundary?: number;
sizeX?: number;
sizeY?: number;
renderPriority?: boolean;
headIcon?: number;
clickable?: boolean;
turnDegrees?: number;

public constructor(defaultValues: { [key: string]: any }) {
super();
Object.keys(defaultValues).forEach(key => this[key] = defaultValues[key]);
}

}

export function translateNpcConfig(npcKey: string, config: NpcConfiguration): NpcDetails {
return {
export function translateNpcServerConfig(npcKey: string, config: NpcServerConfig): NpcDetails {
return new NpcDetails({
key: npcKey,
extends: config.extends || undefined,
gameId: config.game_id,
skills: config.skills || {},
killable: config.killable || false,
respawnTime: config.respawn_time || 1,
Expand All @@ -106,10 +96,10 @@ export function translateNpcConfig(npcKey: string, config: NpcConfiguration): Np
rangedStrength: config.offensive_stats.ranged_strength || undefined
} : undefined,
defensiveStats: config.defensive_stats || undefined,
animations: config.animations || {},
combatAnimations: config.animations || {},
dropTable: config.drop_table || undefined,
metadata: config.metadata || {}
};
});
}

export async function loadNpcConfigurations(path: string): Promise<{ npcs: { [key: string]: NpcDetails };
Expand All @@ -126,25 +116,33 @@ export async function loadNpcConfigurations(path: string): Promise<{ npcs: { [ke
if(key === 'presets') {
npcPresets = { ...npcPresets, ...npcConfigs[key] };
} else {
const npcConfig = npcConfigs[key] as NpcConfiguration;
const npcConfig = npcConfigs[key] as NpcServerConfig;
if(!isNaN(npcConfig.game_id)) {
npcIds[npcConfig.game_id] = key;
npcs[key] = {
...translateNpcConfig(key, npcConfig),
...cache.npcDefinitions.get(npcConfig.game_id)
...translateNpcServerConfig(key, npcConfig),
...filestore.configStore.npcStore.getNpc(npcConfig.game_id)
};
}
if(npcConfig.variations) {

for(const variation of npcConfig.variations) {
const subKey = key+':'+variation.suffix;
const baseItem = JSON.parse(JSON.stringify({ ...translateNpcConfig(key, npcConfig),
...cache.npcDefinitions.get(npcConfig.game_id) }));

const subBaseItem = JSON.parse(JSON.stringify({ ...translateNpcConfig(subKey, variation),
...cache.npcDefinitions.get(variation.game_id) }));
npcIds[variation.game_id] = subKey;
npcs[subKey] = _.merge(baseItem,subBaseItem);
try {
const subKey = key + ':' + variation.suffix;
const baseItem = JSON.parse(JSON.stringify({
...translateNpcServerConfig(key, npcConfig),
...filestore.configStore.npcStore.getNpc(npcConfig.game_id)
}));

const subBaseItem = JSON.parse(JSON.stringify({
...translateNpcServerConfig(subKey, variation),
...filestore.configStore.npcStore.getNpc(variation.game_id)
}));
npcIds[variation.game_id] = subKey;
npcs[subKey] = _.merge(baseItem, subBaseItem);
} catch(error) {
logger.error(`Error registering npc variant ${key}_${variation.suffix}`);
logger.error(error);
}
}
}
}
Expand Down
13 changes: 4 additions & 9 deletions src/game-engine/game-server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { World } from './world';
import { logger, parseServerConfig } from '@runejs/core';
import { Cache, LocationObject } from '@runejs/cache-parser';
import { ServerConfig } from '@engine/config/server-config';

import { loadPluginFiles } from '@engine/plugins/content-plugin';
Expand All @@ -16,6 +15,7 @@ import { Subject, timer } from 'rxjs';
import { Position } from '@engine/world/position';
import { ActionHook, sortActionHooks } from '@engine/world/action/hooks';
import { ActionType } from '@engine/world/action';
import { Filestore, LandscapeObject } from '@runejs/filestore';


/**
Expand All @@ -27,7 +27,7 @@ export let serverConfig: ServerConfig;
/**
* The singleton instance referencing the game's asset filestore.
*/
export let cache: Cache;
export let filestore: Filestore;


/**
Expand Down Expand Up @@ -122,12 +122,7 @@ export async function runGameServer(): Promise<void> {
return;
}

cache = new Cache('cache', {
items: true,
npcs: true,
locationObjects: true,
widgets: true
});
filestore = new Filestore('cache');

await loadConfigurations();
await loadPackets();
Expand Down Expand Up @@ -218,7 +213,7 @@ export const loopingEvent = (options?: {
* @deprecated - use methods provided within the Actor API to force or await movement
*/
export const playerWalkTo = async (player: Player, position: Position, interactingAction?: {
interactingObject?: LocationObject;
interactingObject?: LandscapeObject;
}): Promise<void> => {
return new Promise<void>((resolve, reject) => {
player.walkingTo = position;
Expand Down
2 changes: 1 addition & 1 deletion src/game-engine/net/inbound-packets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function handlePacket(player: Player, packetId: number, packetSize: numbe
return;
}

new Promise(resolve => {
new Promise<void>(resolve => {
incomingPacket.handler(player, { packetId, packetSize, buffer });
resolve();
}).catch(error => logger.error(`Error handling inbound packet ${packetId} with size ${packetSize}: ${error}`));
Expand Down
6 changes: 3 additions & 3 deletions src/game-engine/net/inbound-packets/item-on-object-packet.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { logger } from '@runejs/core';
import { Position } from '../../world/position';
import { cache, world } from '../../game-server';
import { filestore, world } from '../../game-server';
import { widgets } from '../../config';

const itemOnObjectPacket = (player, packet) => {
Expand Down Expand Up @@ -39,9 +39,9 @@ const itemOnObjectPacket = (player, packet) => {
return;
}

const locationObjectDefinition = cache.locationObjectDefinitions.get(objectId);
const objectConfig = filestore.configStore.objectStore.getObject(objectId);

player.actionPipeline.call('item_on_object', player, locationObject, locationObjectDefinition, objectPosition, usedItem, itemWidgetId, itemContainerId, cacheOriginal);
player.actionPipeline.call('item_on_object', player, locationObject, objectConfig, objectPosition, usedItem, itemWidgetId, itemContainerId, cacheOriginal);
};

export default {
Expand Down
Loading

0 comments on commit d6b654e

Please sign in to comment.