diff --git a/cache/377/main_file_cache.dat b/cache/377/main_file_cache.dat deleted file mode 100644 index 3ef7685b2..000000000 Binary files a/cache/377/main_file_cache.dat and /dev/null differ diff --git a/cache/377/main_file_cache.idx0 b/cache/377/main_file_cache.idx0 deleted file mode 100644 index 6e4330f76..000000000 Binary files a/cache/377/main_file_cache.idx0 and /dev/null differ diff --git a/cache/377/main_file_cache.idx1 b/cache/377/main_file_cache.idx1 deleted file mode 100644 index 86fc5ac97..000000000 Binary files a/cache/377/main_file_cache.idx1 and /dev/null differ diff --git a/cache/377/main_file_cache.idx2 b/cache/377/main_file_cache.idx2 deleted file mode 100644 index 80b35f75e..000000000 Binary files a/cache/377/main_file_cache.idx2 and /dev/null differ diff --git a/cache/377/main_file_cache.idx3 b/cache/377/main_file_cache.idx3 deleted file mode 100644 index d467e18bb..000000000 Binary files a/cache/377/main_file_cache.idx3 and /dev/null differ diff --git a/cache/377/main_file_cache.idx4 b/cache/377/main_file_cache.idx4 deleted file mode 100644 index a1afef6ab..000000000 Binary files a/cache/377/main_file_cache.idx4 and /dev/null differ diff --git a/cache/435/main_file_cache.dat0 b/cache/main_file_cache.dat0 similarity index 100% rename from cache/435/main_file_cache.dat0 rename to cache/main_file_cache.dat0 diff --git a/cache/435/main_file_cache.dat1 b/cache/main_file_cache.dat1 similarity index 100% rename from cache/435/main_file_cache.dat1 rename to cache/main_file_cache.dat1 diff --git a/cache/435/main_file_cache.dat2 b/cache/main_file_cache.dat2 similarity index 100% rename from cache/435/main_file_cache.dat2 rename to cache/main_file_cache.dat2 diff --git a/cache/435/main_file_cache.idx0 b/cache/main_file_cache.idx0 similarity index 100% rename from cache/435/main_file_cache.idx0 rename to cache/main_file_cache.idx0 diff --git a/cache/435/main_file_cache.idx1 b/cache/main_file_cache.idx1 similarity index 100% rename from cache/435/main_file_cache.idx1 rename to cache/main_file_cache.idx1 diff --git a/cache/435/main_file_cache.idx10 b/cache/main_file_cache.idx10 similarity index 100% rename from cache/435/main_file_cache.idx10 rename to cache/main_file_cache.idx10 diff --git a/cache/435/main_file_cache.idx11 b/cache/main_file_cache.idx11 similarity index 100% rename from cache/435/main_file_cache.idx11 rename to cache/main_file_cache.idx11 diff --git a/cache/435/main_file_cache.idx12 b/cache/main_file_cache.idx12 similarity index 100% rename from cache/435/main_file_cache.idx12 rename to cache/main_file_cache.idx12 diff --git a/cache/435/main_file_cache.idx2 b/cache/main_file_cache.idx2 similarity index 100% rename from cache/435/main_file_cache.idx2 rename to cache/main_file_cache.idx2 diff --git a/cache/435/main_file_cache.idx255 b/cache/main_file_cache.idx255 similarity index 100% rename from cache/435/main_file_cache.idx255 rename to cache/main_file_cache.idx255 diff --git a/cache/435/main_file_cache.idx3 b/cache/main_file_cache.idx3 similarity index 100% rename from cache/435/main_file_cache.idx3 rename to cache/main_file_cache.idx3 diff --git a/cache/435/main_file_cache.idx4 b/cache/main_file_cache.idx4 similarity index 100% rename from cache/435/main_file_cache.idx4 rename to cache/main_file_cache.idx4 diff --git a/cache/435/main_file_cache.idx5 b/cache/main_file_cache.idx5 similarity index 100% rename from cache/435/main_file_cache.idx5 rename to cache/main_file_cache.idx5 diff --git a/cache/435/main_file_cache.idx6 b/cache/main_file_cache.idx6 similarity index 100% rename from cache/435/main_file_cache.idx6 rename to cache/main_file_cache.idx6 diff --git a/cache/435/main_file_cache.idx7 b/cache/main_file_cache.idx7 similarity index 100% rename from cache/435/main_file_cache.idx7 rename to cache/main_file_cache.idx7 diff --git a/cache/435/main_file_cache.idx8 b/cache/main_file_cache.idx8 similarity index 100% rename from cache/435/main_file_cache.idx8 rename to cache/main_file_cache.idx8 diff --git a/cache/435/main_file_cache.idx9 b/cache/main_file_cache.idx9 similarity index 100% rename from cache/435/main_file_cache.idx9 rename to cache/main_file_cache.idx9 diff --git a/package-lock.json b/package-lock.json index ddb9b8cca..72d413db8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -99,9 +99,9 @@ "dev": true }, "@runejs/cache-parser": { - "version": "0.4.5", - "resolved": "https://registry.npmjs.org/@runejs/cache-parser/-/cache-parser-0.4.5.tgz", - "integrity": "sha512-GkJrd35ITUHtc285wEHf61/IPPrd5dfax3NqFLHmPGBhghL2pMguLwL/sBPHLhVzTDRFkzpu0fHAaynHqZNhRw==", + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/@runejs/cache-parser/-/cache-parser-0.5.0.tgz", + "integrity": "sha512-BMGyshWyNDSQewYAzjRrykDrTKb6OqsJ4R6169G8Mhf0I+AN4XdfquV9NnV8HFJAeIpl6dZphjp7eTnMiyIC+w==", "requires": { "@runejs/logger": "^1.0.0", "pngjs": "^3.4.0", diff --git a/package.json b/package.json index 7a9f1148f..77333d412 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "license": "GPL-3.0", "dependencies": { "@hapi/joi": "^16.1.8", - "@runejs/cache-parser": "0.4.5", + "@runejs/cache-parser": "0.5.0", "@runejs/logger": "^1.0.0", "bigi": "^1.4.2", "body-parser": "^1.19.0", diff --git a/src/data-dump.ts b/src/data-dump.ts index 97ed391c5..6ac2e258a 100644 --- a/src/data-dump.ts +++ b/src/data-dump.ts @@ -1,9 +1,8 @@ import { join } from 'path'; import { writeFileSync } from 'fs'; -import { gameCache } from '@server/game-server'; +import { cache } from '@server/game-server'; import { logger } from '@runejs/logger/dist/logger'; -import { ItemDefinition, NpcDefinition } from '@runejs/cache-parser'; -import { WidgetDefinition } from '@runejs/cache-parser/dist/cache-new-format/screen/widgets'; +import { ItemDefinition, NpcDefinition, Widget } from '@runejs/cache-parser'; function dump(fileName: string, definitions: Map): boolean { const filePath = join('data/dump', fileName); @@ -23,13 +22,13 @@ function dump(fileName: string, definitions: Map): boolean { } export function dumpNpcs(): boolean { - return dump('npcs.json', gameCache.npcDefinitions); + return dump('npcs.json', cache.npcDefinitions); } export function dumpItems(): boolean { - return dump('items.json', gameCache.itemDefinitions); + return dump('items.json', cache.itemDefinitions); } export function dumpWidgets(): boolean { - return dump('widgets.json', gameCache.widgetDefinitions); + return dump('widgets.json', cache.widgets); } diff --git a/src/game-server.ts b/src/game-server.ts index 1324c175e..0908fa2a5 100644 --- a/src/game-server.ts +++ b/src/game-server.ts @@ -6,7 +6,7 @@ import { RsBuffer } from './net/rs-buffer'; import { World } from './world/world'; import { ClientConnection } from './net/client-connection'; import { logger } from '@runejs/logger'; -import { EarlyFormatGameCache, NewFormatGameCache } from '@runejs/cache-parser'; +import { Cache } from '@runejs/cache-parser'; import { parseServerConfig, ServerConfig } from '@server/world/config/server-config'; import { loadPlugins } from '@server/plugins/plugin-loader'; @@ -28,8 +28,7 @@ import { setQuestPlugins } from '@server/world/config/quests'; export let serverConfig: ServerConfig; -export let gameCache377: EarlyFormatGameCache; -export let gameCache: NewFormatGameCache; +export let cache: Cache; export let world: World; export let crcTable: Buffer; @@ -63,13 +62,13 @@ export async function injectPlugins(): Promise { } function generateCrcTable(): void { - const index = gameCache.metaChannel; + const index = cache.metaChannel; const indexLength = index.getBuffer().length; const buffer = RsBuffer.create(4048); buffer.writeByte(0); buffer.writeIntBE(indexLength); for(let file = 0; file < (indexLength / 6); file++) { - const crcValue = CRC32.buf(gameCache.getRawCacheFile(255, file).getBuffer()); + const crcValue = CRC32.buf(cache.getRawFile(255, file).getBuffer()); buffer.writeIntBE(crcValue); } @@ -84,9 +83,11 @@ export function runGameServer(): void { return; } - gameCache377 = new EarlyFormatGameCache('cache/377', { loadMaps: true, loadDefinitions: false, loadWidgets: false }); - gameCache = new NewFormatGameCache('cache/435'); + cache = new Cache('cache', { + items: true, npcs: true, locationObjects: true, mapData: true, widgets: true + }); generateCrcTable(); + world = new World(); injectPlugins().then(() => { world.init(); diff --git a/src/net/data-parser/update-server-parser.ts b/src/net/data-parser/update-server-parser.ts index cbd8250ef..3dbcd8329 100644 --- a/src/net/data-parser/update-server-parser.ts +++ b/src/net/data-parser/update-server-parser.ts @@ -1,6 +1,6 @@ import { RsBuffer } from '@server/net/rs-buffer'; import { DataParser } from './data-parser'; -import { crcTable, gameCache } from '@server/game-server'; +import { crcTable, cache } from '@server/game-server'; /** * Handles the cache update server. @@ -49,7 +49,7 @@ export class UpdateServerParser extends DataParser { crcTable.copy(crcBuffer, 0, 0); cacheFile = new RsBuffer(crcBuffer); } else { - cacheFile = gameCache.getRawCacheFile(index, file); + cacheFile = cache.getRawFile(index, file); } if(!cacheFile || cacheFile.getBuffer().length === 0) { diff --git a/src/net/incoming-packets/item-on-npc-packet.ts b/src/net/incoming-packets/item-on-npc-packet.ts index a1d78960d..d1f1acf26 100644 --- a/src/net/incoming-packets/item-on-npc-packet.ts +++ b/src/net/incoming-packets/item-on-npc-packet.ts @@ -3,13 +3,8 @@ import { Player } from '../../world/actor/player/player'; import { RsBuffer } from '@server/net/rs-buffer'; import { widgets } from '@server/world/config/widget'; import { logger } from '@runejs/logger/dist/logger'; -import { itemOnItemAction } from '@server/world/actor/player/action/item-on-item-action'; -import { Position } from '@server/world/position'; -import { gameCache, world } from '@server/game-server'; -import { objectAction } from '@server/world/actor/player/action/object-action'; -import { itemOnObjectAction } from '@server/world/actor/player/action/item-on-object-action'; +import { world } from '@server/game-server'; import { World } from '@server/world/world'; -import { npcAction } from '@server/world/actor/player/action/npc-action'; import { itemOnNpcAction } from '@server/world/actor/player/action/item-on-npc-action'; export const itemOnNpcPacket: incomingPacket = (player: Player, packetId: number, packetSize: number, packet: RsBuffer): void => { @@ -20,30 +15,30 @@ export const itemOnNpcPacket: incomingPacket = (player: Player, packetId: number const itemContainerId = packet.readShortBE(); let usedItem; - if (itemWidgetId === widgets.inventory.widgetId && itemContainerId === widgets.inventory.containerId) { - if (itemSlot < 0 || itemSlot > 27) { + if(itemWidgetId === widgets.inventory.widgetId && itemContainerId === widgets.inventory.containerId) { + if(itemSlot < 0 || itemSlot > 27) { return; } usedItem = player.inventory.items[itemSlot]; - if (!usedItem) { + if(!usedItem) { return; } - if (usedItem.itemId !== itemId) { + if(usedItem.itemId !== itemId) { return; } } else { - logger.warn(`Unhandled item on object case using widget ${itemWidgetId}:${itemContainerId}`); + logger.warn(`Unhandled item on object case using widget ${ itemWidgetId }:${ itemContainerId }`); } - if (npcIndex < 0 || npcIndex > World.MAX_NPCS - 1) { + if(npcIndex < 0 || npcIndex > World.MAX_NPCS - 1) { return; } const npc = world.npcList[npcIndex]; - if (!npc) { + if(!npc) { return; } @@ -51,7 +46,7 @@ export const itemOnNpcPacket: incomingPacket = (player: Player, packetId: number const distance = Math.floor(position.distanceBetween(player.position)); // Too far away - if (distance > 16) { + if(distance > 16) { return; } diff --git a/src/net/incoming-packets/item-on-object-packet.ts b/src/net/incoming-packets/item-on-object-packet.ts index 497882df4..d6ad357e7 100644 --- a/src/net/incoming-packets/item-on-object-packet.ts +++ b/src/net/incoming-packets/item-on-object-packet.ts @@ -3,10 +3,8 @@ import { Player } from '../../world/actor/player/player'; import { RsBuffer } from '@server/net/rs-buffer'; import { widgets } from '@server/world/config/widget'; import { logger } from '@runejs/logger/dist/logger'; -import { itemOnItemAction } from '@server/world/actor/player/action/item-on-item-action'; import { Position } from '@server/world/position'; -import { gameCache, world } from '@server/game-server'; -import { objectAction } from '@server/world/actor/player/action/object-action'; +import { cache, world } from '@server/game-server'; import { itemOnObjectAction } from '@server/world/actor/player/action/item-on-object-action'; export const itemOnObjectPacket: incomingPacket = (player: Player, packetId: number, packetSize: number, packet: RsBuffer): void => { @@ -41,12 +39,12 @@ export const itemOnObjectPacket: incomingPacket = (player: Player, packetId: num const objectChunk = world.chunkManager.getChunkForWorldPosition(objectPosition); let cacheOriginal: boolean = true; - let landscapeObject = objectChunk.getCacheObject(objectId, objectPosition); - if (!landscapeObject) { - landscapeObject = objectChunk.getAddedObject(objectId, objectPosition); + let locationObject = objectChunk.getCacheObject(objectId, objectPosition); + if (!locationObject) { + locationObject = objectChunk.getAddedObject(objectId, objectPosition); cacheOriginal = false; - if (!landscapeObject) { + if (!locationObject) { return; } } @@ -55,9 +53,9 @@ export const itemOnObjectPacket: incomingPacket = (player: Player, packetId: num return; } - const landscapeObjectDefinition = gameCache.landscapeObjectDefinitions.get(objectId); + const locationObjectDefinition = cache.locationObjectDefinitions.get(objectId); - itemOnObjectAction(player, landscapeObject, landscapeObjectDefinition, objectPosition, usedItem, itemWidgetId, itemContainerId, cacheOriginal); + itemOnObjectAction(player, locationObject, locationObjectDefinition, objectPosition, usedItem, itemWidgetId, itemContainerId, cacheOriginal); }; diff --git a/src/net/incoming-packets/object-interaction-packet.ts b/src/net/incoming-packets/object-interaction-packet.ts index d1bf26ff3..28daed58a 100644 --- a/src/net/incoming-packets/object-interaction-packet.ts +++ b/src/net/incoming-packets/object-interaction-packet.ts @@ -2,7 +2,7 @@ import { incomingPacket } from '../incoming-packet'; import { Player } from '../../world/actor/player/player'; import { RsBuffer } from '@server/net/rs-buffer'; import { Position } from '@server/world/position'; -import { gameCache, world } from '@server/game-server'; +import { cache, world } from '@server/game-server'; import { objectAction } from '@server/world/actor/player/action/object-action'; import { logger } from '@runejs/logger/dist/logger'; @@ -63,12 +63,12 @@ export const objectInteractionPacket: incomingPacket = (player: Player, packetId const objectChunk = world.chunkManager.getChunkForWorldPosition(objectPosition); let cacheOriginal: boolean = true; - let landscapeObject = objectChunk.getCacheObject(objectId, objectPosition); - if(!landscapeObject) { - landscapeObject = objectChunk.getAddedObject(objectId, objectPosition); + let locationObject = objectChunk.getCacheObject(objectId, objectPosition); + if(!locationObject) { + locationObject = objectChunk.getAddedObject(objectId, objectPosition); cacheOriginal = false; - if(!landscapeObject) { + if(!locationObject) { return; } } @@ -77,23 +77,23 @@ export const objectInteractionPacket: incomingPacket = (player: Player, packetId return; } - const landscapeObjectDefinition = gameCache.landscapeObjectDefinitions.get(objectId); + const locationObjectDefinition = cache.locationObjectDefinitions.get(objectId); const actionIdx = options[packetId].index; let optionName = `action-${actionIdx + 1}`; - if(landscapeObjectDefinition.options && landscapeObjectDefinition.options.length >= actionIdx) { - if(!landscapeObjectDefinition.options[actionIdx] || landscapeObjectDefinition.options[actionIdx].toLowerCase() === 'hidden') { + if(locationObjectDefinition.options && locationObjectDefinition.options.length >= actionIdx) { + if(!locationObjectDefinition.options[actionIdx] || locationObjectDefinition.options[actionIdx].toLowerCase() === 'hidden') { // Invalid action - logger.error(`1: Invalid object ${objectId} option ${actionIdx + 1}, options: ${JSON.stringify(landscapeObjectDefinition.options)}`); + logger.error(`1: Invalid object ${objectId} option ${actionIdx + 1}, options: ${JSON.stringify(locationObjectDefinition.options)}`); return; } - optionName = landscapeObjectDefinition.options[actionIdx]; + optionName = locationObjectDefinition.options[actionIdx]; } else { // Invalid action - logger.error(`2: Invalid object ${objectId} option ${actionIdx + 1}, options: ${JSON.stringify(landscapeObjectDefinition.options)}`); + logger.error(`2: Invalid object ${objectId} option ${actionIdx + 1}, options: ${JSON.stringify(locationObjectDefinition.options)}`); return; } - objectAction(player, landscapeObject, landscapeObjectDefinition, objectPosition, optionName.toLowerCase(), cacheOriginal); + objectAction(player, locationObject, locationObjectDefinition, objectPosition, optionName.toLowerCase(), cacheOriginal); }; diff --git a/src/net/outgoing-packets.ts b/src/net/outgoing-packets.ts index 2451a76b9..ef7822716 100644 --- a/src/net/outgoing-packets.ts +++ b/src/net/outgoing-packets.ts @@ -4,7 +4,7 @@ import { Packet, PacketType } from '@server/net/packet'; import { ItemContainer } from '@server/world/items/item-container'; import { Item } from '@server/world/items/item'; import { Position } from '@server/world/position'; -import { LandscapeObject } from '@runejs/cache-parser'; +import { LocationObject } from '@runejs/cache-parser'; import { Chunk, ChunkUpdateItem } from '@server/world/map/chunk'; import { WorldItem } from '@server/world/items/world-item'; @@ -87,7 +87,7 @@ export class OutgoingPackets { if(update.object) { const offset = this.getChunkPositionOffset(update.object.x, update.object.y, chunk); packet.writeUnsignedByte(241); - packet.writeByteInverted((update.object.type << 2) + (update.object.rotation & 3)); + packet.writeByteInverted((update.object.type << 2) + (update.object.orientation & 3)); packet.writeUnsignedShortBE(update.object.objectId); packet.writeUnsignedOffsetByte(offset); } else if(update.worldItem) { @@ -101,7 +101,7 @@ export class OutgoingPackets { const offset = this.getChunkPositionOffset(update.object.x, update.object.y, chunk); packet.writeUnsignedByte(143); packet.writeUnsignedOffsetByte(offset); - packet.writeByteInverted((update.object.type << 2) + (update.object.rotation & 3)); + packet.writeByteInverted((update.object.type << 2) + (update.object.orientation & 3)); } }); @@ -139,23 +139,23 @@ export class OutgoingPackets { this.queue(packet); } - public setLandscapeObject(landscapeObject: LandscapeObject, position: Position, offset: number = 0): void { + public setLocationObject(locationObject: LocationObject, position: Position, offset: number = 0): void { this.updateReferencePosition(position); const packet = new Packet(241); - packet.writeByteInverted((landscapeObject.type << 2) + (landscapeObject.rotation & 3)); - packet.writeUnsignedShortBE(landscapeObject.objectId); + packet.writeByteInverted((locationObject.type << 2) + (locationObject.orientation & 3)); + packet.writeUnsignedShortBE(locationObject.objectId); packet.writeUnsignedOffsetByte(offset); this.queue(packet); } - public removeLandscapeObject(landscapeObject: LandscapeObject, position: Position, offset: number = 0): void { + public removeLocationObject(locationObject: LocationObject, position: Position, offset: number = 0): void { this.updateReferencePosition(position); const packet = new Packet(143); packet.writeUnsignedOffsetByte(offset); - packet.writeByteInverted((landscapeObject.type << 2) + (landscapeObject.rotation & 3)); + packet.writeByteInverted((locationObject.type << 2) + (locationObject.orientation & 3)); this.queue(packet); } diff --git a/src/plugins/commands/give-item-command.ts b/src/plugins/commands/give-item-command.ts index 638bfee17..08578a177 100644 --- a/src/plugins/commands/give-item-command.ts +++ b/src/plugins/commands/give-item-command.ts @@ -1,6 +1,6 @@ import { ActionType, RunePlugin } from '@server/plugins/plugin'; import { commandAction } from '@server/world/actor/player/action/input-command-action'; -import { gameCache } from '@server/game-server'; +import { cache } from '@server/game-server'; const action: commandAction = (details) => { const { player, args } = details; @@ -19,7 +19,7 @@ const action: commandAction = (details) => { throw new Error(`Unable to give more than 2,000,000,000.`); } - const itemDefinition = gameCache.itemDefinitions.get(itemId); + const itemDefinition = cache.itemDefinitions.get(itemId); if(!itemDefinition) { throw new Error(`Item ID ${itemId} not found!`); } diff --git a/src/plugins/items/buckets/fill-container-plugin.ts b/src/plugins/items/buckets/fill-container-plugin.ts index e5fbae992..19298358a 100644 --- a/src/plugins/items/buckets/fill-container-plugin.ts +++ b/src/plugins/items/buckets/fill-container-plugin.ts @@ -1,5 +1,5 @@ import { itemOnObjectAction } from '@server/world/actor/player/action/item-on-object-action'; -import { gameCache } from '@server/game-server'; +import { cache } from '@server/game-server'; import { itemIds } from '@server/world/config/item-ids'; import { animationIds } from '@server/world/config/animation-ids'; import { soundIds } from '@server/world/config/sound-ids'; @@ -10,7 +10,7 @@ const SinkIds: number[] = [14878, 873]; const WellIds: number[] = [878]; export const action: itemOnObjectAction = (details) => { const {player, objectDefinition, item} = details; - const itemDef = gameCache.itemDefinitions.get(item.itemId); + const itemDef = cache.itemDefinitions.get(item.itemId); if (item.itemId !== itemIds.bucket && WellIds.indexOf(objectDefinition.id) > -1) { player.sendMessage(`If I drop my ${itemDef.name.toLowerCase()} down there, I don't think I'm likely to get it back.`); return; diff --git a/src/plugins/objects/cows/cow-plugin.ts b/src/plugins/objects/cows/cow-plugin.ts index da5bbdd8c..cfe60fa6a 100644 --- a/src/plugins/objects/cows/cow-plugin.ts +++ b/src/plugins/objects/cows/cow-plugin.ts @@ -1,5 +1,5 @@ import { objectAction } from '@server/world/actor/player/action/object-action'; -import { gameCache } from '@server/game-server'; +import { cache } from '@server/game-server'; import { ActionType, RunePlugin } from '@server/plugins/plugin'; import { dialogueAction, DialogueEmote } from '@server/world/actor/player/action/dialogue-action'; import { npcIds } from '@server/world/config/npc-ids'; @@ -8,12 +8,12 @@ import { soundIds } from '@server/world/config/sound-ids'; import { itemIds } from '@server/world/config/item-ids'; import { objectIds } from '@server/world/config/object-ids'; import { itemOnObjectAction } from '@server/world/actor/player/action/item-on-object-action'; -import { LandscapeObjectDefinition } from '@runejs/cache-parser'; +import { LocationObjectDefinition } from '@runejs/cache-parser'; import { Player } from '@server/world/actor/player/player'; -function milkCow(details: {objectDefinition: LandscapeObjectDefinition, player: Player}): void { +function milkCow(details: { objectDefinition: LocationObjectDefinition, player: Player }): void { const { player, objectDefinition } = details; - const emptyBucketItem = gameCache.itemDefinitions.get(itemIds.bucket); + const emptyBucketItem = cache.itemDefinitions.get(itemIds.bucket); if (player.hasItemInInventory(itemIds.bucket)) { player.playAnimation(animationIds.milkCow); diff --git a/src/plugins/objects/doors/door-plugin.ts b/src/plugins/objects/doors/door-plugin.ts index 41655120b..4eb841f76 100644 --- a/src/plugins/objects/doors/door-plugin.ts +++ b/src/plugins/objects/doors/door-plugin.ts @@ -4,6 +4,7 @@ import { Chunk } from '@server/world/map/chunk'; import { objectAction } from '@server/world/actor/player/action/object-action'; import { ActionType, RunePlugin } from '@server/plugins/plugin'; import { soundIds } from '@server/world/config/sound-ids'; +import { LocationObject } from '@runejs/cache-parser'; // @TODO move to yaml config const doors = [ @@ -73,22 +74,22 @@ export const action: objectAction = (details): void => { } const startDoorChunk: Chunk = world.chunkManager.getChunkForWorldPosition(position); - const startDir = WNES[door.rotation]; + const startDir = WNES[door.orientation]; const endDir = hingeConfig[startDir]; const endPosition = position.step(opening ? 1 : -1, opening ? startDir : endDir); - const replacementDoor = { + const replacementDoor: LocationObject = { objectId: replacementDoorId, x: endPosition.x, y: endPosition.y, level: position.level, type: door.type, - rotation: directionData[endDir].rotation + orientation: directionData[endDir].rotation }; const replacementDoorChunk = world.chunkManager.getChunkForWorldPosition(endPosition); - world.toggleObjects(replacementDoor, door, endPosition, position, replacementDoorChunk, startDoorChunk, !cacheOriginal); + world.toggleLocationObjects(replacementDoor, door, endPosition, position, replacementDoorChunk, startDoorChunk, !cacheOriginal); // 70 = close gate, 71 = open gate, 62 = open door, 60 = close door player.playSound(opening ? soundIds.openDoor : soundIds.closeDoor, 7); }; diff --git a/src/plugins/objects/doors/double-door-plugin.ts b/src/plugins/objects/doors/double-door-plugin.ts index 0e802aae5..39b42c10b 100644 --- a/src/plugins/objects/doors/double-door-plugin.ts +++ b/src/plugins/objects/doors/double-door-plugin.ts @@ -55,7 +55,7 @@ const action: objectAction = (details) => { const leftDoorId = doorIds[0]; const rightDoorId = doorIds[1]; const hinge = leftDoorId === door.objectId ? 'LEFT' : 'RIGHT'; - const direction = WNES[door.rotation]; + const direction = WNES[door.orientation]; let deltaX = 0; let deltaY = 0; const otherDoorId = hinge === 'LEFT' ? rightDoorId : leftDoorId; diff --git a/src/plugins/objects/doors/gate-plugin.ts b/src/plugins/objects/doors/gate-plugin.ts index d1974cd88..8a308a726 100644 --- a/src/plugins/objects/doors/gate-plugin.ts +++ b/src/plugins/objects/doors/gate-plugin.ts @@ -2,7 +2,7 @@ import { Position } from '@server/world/position'; import { directionData, WNES } from '@server/world/direction'; import { logger } from '@runejs/logger/dist/logger'; import { world } from '@server/game-server'; -import { ModifiedLandscapeObject } from '@server/world/map/landscape-object'; +import { ModifiedLocationObject } from '@server/world/map/location-object'; import { objectAction } from '@server/world/actor/player/action/object-action'; import { ActionType, RunePlugin } from '@server/plugins/plugin'; import { soundIds } from '@server/world/config/sound-ids'; @@ -29,18 +29,18 @@ const action: objectAction = (details) => { const { player, cacheOriginal } = details; let { object: gate, position } = details; - if((gate as ModifiedLandscapeObject).metadata) { - const metadata = (gate as ModifiedLandscapeObject).metadata; + if((gate as ModifiedLocationObject).metadata) { + const metadata = (gate as ModifiedLocationObject).metadata; - world.toggleObjects(metadata.originalMain, metadata.main, metadata.originalMainPosition, metadata.mainPosition, metadata.originalMainChunk, metadata.mainChunk, true); - world.toggleObjects(metadata.originalSecond, metadata.second, metadata.originalSecondPosition, metadata.secondPosition, metadata.originalSecondChunk, metadata.secondChunk, true); + world.toggleLocationObjects(metadata.originalMain, metadata.main, metadata.originalMainPosition, metadata.mainPosition, metadata.originalMainChunk, metadata.mainChunk, true); + world.toggleLocationObjects(metadata.originalSecond, metadata.second, metadata.originalSecondPosition, metadata.secondPosition, metadata.originalSecondChunk, metadata.secondChunk, true); player.playSound(soundIds.closeGate, 7); } else { let details = gates.find(g => g.main === gate.objectId); let clickedSecondary = false; let secondGate; let hinge; - let direction = WNES[gate.rotation]; + let direction = WNES[gate.orientation]; let hingeChunk, gateSecondPosition; if(!details) { @@ -88,7 +88,7 @@ const action: objectAction = (details) => { const pos = new Position(gate.x + deltaX, gate.y + deltaY, gate.level); hingeChunk = world.chunkManager.getChunkForWorldPosition(pos); gate = hingeChunk.getCacheObject(details.main, pos); - direction = WNES[gate.rotation]; + direction = WNES[gate.orientation]; position = pos; } else { hinge = details.hinge; @@ -181,16 +181,16 @@ const action: objectAction = (details) => { y: newPosition.y, level: newPosition.level, type: gate.type, - rotation: directionData[newDirection].rotation - } as ModifiedLandscapeObject; + orientation: directionData[newDirection].rotation + } as ModifiedLocationObject; const newSecond = { objectId: details.secondaryOpen, x: newSecondPosition.x, y: newSecondPosition.y, level: newSecondPosition.level, type: gate.type, - rotation: directionData[newDirection].rotation - } as ModifiedLandscapeObject; + orientation: directionData[newDirection].rotation + } as ModifiedLocationObject; const metadata = { second: JSON.parse(JSON.stringify(newSecond)), @@ -210,8 +210,8 @@ const action: objectAction = (details) => { newHinge.metadata = metadata; newSecond.metadata = metadata; - world.toggleObjects(newHinge, gate, newPosition, position, newHingeChunk, hingeChunk, !cacheOriginal); - world.toggleObjects(newSecond, secondGate, newSecondPosition, gateSecondPosition, newSecondChunk, gateSecondChunk, !cacheOriginal); + world.toggleLocationObjects(newHinge, gate, newPosition, position, newHingeChunk, hingeChunk, !cacheOriginal); + world.toggleLocationObjects(newSecond, secondGate, newSecondPosition, gateSecondPosition, newSecondChunk, gateSecondChunk, !cacheOriginal); player.playSound(soundIds.openGate, 7); } }; diff --git a/src/plugins/objects/mill/flour-bin-plugin.ts b/src/plugins/objects/mill/flour-bin-plugin.ts index bfcf70f23..19af4838f 100644 --- a/src/plugins/objects/mill/flour-bin-plugin.ts +++ b/src/plugins/objects/mill/flour-bin-plugin.ts @@ -3,11 +3,11 @@ import { itemIds } from '@server/world/config/item-ids'; import { objectAction } from '@server/world/actor/player/action/object-action'; import { soundIds } from '@server/world/config/sound-ids'; import { itemOnObjectAction } from '@server/world/actor/player/action/item-on-object-action'; -import { LandscapeObjectDefinition } from '@runejs/cache-parser'; +import { LocationObjectDefinition } from '@runejs/cache-parser'; import { Player } from '@server/world/actor/player/player'; -function flourBin(details: {objectDefinition: LandscapeObjectDefinition, player: Player}): void { +function flourBin(details: { objectDefinition: LocationObjectDefinition, player: Player }): void { const { player, objectDefinition } = details; if (!details.player.metadata['flour']) { diff --git a/src/plugins/objects/mill/hopper-controls-plugin.ts b/src/plugins/objects/mill/hopper-controls-plugin.ts index 179a1755b..c8318cfc9 100644 --- a/src/plugins/objects/mill/hopper-controls-plugin.ts +++ b/src/plugins/objects/mill/hopper-controls-plugin.ts @@ -2,7 +2,7 @@ import { objectAction } from '@server/world/actor/player/action/object-action'; import { World } from '@server/world/world'; import { world } from '@server/game-server'; import { Position } from '@server/world/position'; -import { LandscapeObject } from '@runejs/cache-parser'; +import { LocationObject } from '@runejs/cache-parser'; import { ActionType, RunePlugin } from '@server/plugins/plugin'; @@ -10,16 +10,16 @@ export const action: objectAction = (details) => { details.player.busy = true; details.player.playAnimation(3571); details.player.playSound(2400, 5); - const newHopper = { + const newHopper: LocationObject = { objectId: 2722, x: details.object.x, y: details.object.y, level: details.object.level, type: details.object.type, - rotation: details.object.rotation + orientation: details.object.orientation }; - world.replaceObject(2722, details.object, 1); + world.replaceLocationObject(2722, details.object, 1); setTimeout(() => { if (details.player.metadata['grain'] && details.player.metadata['grain'] >= 1) { @@ -30,8 +30,8 @@ export const action: objectAction = (details) => { details.player.metadata['flour'] += details.player.metadata['grain']; details.player.metadata['grain'] = 0; const flourBinPos = new Position(3166, 3306); - const fullFlourBin: LandscapeObject = {objectId: 1782, x: 3166, y: 3306, rotation: 0, level: 0, type: 10}; - world.addLandscapeObject(fullFlourBin, flourBinPos); + const fullFlourBin: LocationObject = {objectId: 1782, x: 3166, y: 3306, orientation: 0, level: 0, type: 10}; + world.addLocationObject(fullFlourBin, flourBinPos); } else { details.player.sendMessage(`You operate the hopper. Nothing interesting happens.`); } diff --git a/src/plugins/objects/pickables/pickables-plugin.ts b/src/plugins/objects/pickables/pickables-plugin.ts index bf25c00a5..8c44364e0 100644 --- a/src/plugins/objects/pickables/pickables-plugin.ts +++ b/src/plugins/objects/pickables/pickables-plugin.ts @@ -1,5 +1,5 @@ import { objectAction } from '@server/world/actor/player/action/object-action'; -import { gameCache, world } from '@server/game-server'; +import { cache, world } from '@server/game-server'; import { World } from '@server/world/world'; import { ActionType, RunePlugin } from '@server/plugins/plugin'; import { itemIds } from '@server/world/config/item-ids'; @@ -30,12 +30,12 @@ export const action: objectAction = (details) => { itemId = itemIds.cabbage; break; } - const pickedItem = gameCache.itemDefinitions.get(itemId); + const pickedItem = cache.itemDefinitions.get(itemId); setTimeout(() => { details.player.sendMessage(`You ${details.option} the ${details.objectDefinition.name.toLowerCase()} and receive ${prefix} ${pickedItem.name.toLowerCase()}.`); details.player.playSound(2581, 7); if (details.objectDefinition.name !== 'Flax' || Math.floor(Math.random() * 10) === 1) { - world.removeLandscapeObjectTemporarily(details.object, details.position, 30); + world.removeLocationObjectTemporarily(details.object, details.position, 30); } details.player.giveItem(pickedItem.id); details.player.busy = false; diff --git a/src/plugins/skills/crafting/spinning-wheel-plugin.ts b/src/plugins/skills/crafting/spinning-wheel-plugin.ts index 1b8cfd81a..2c91394c1 100644 --- a/src/plugins/skills/crafting/spinning-wheel-plugin.ts +++ b/src/plugins/skills/crafting/spinning-wheel-plugin.ts @@ -6,7 +6,7 @@ import { Subscription } from 'rxjs'; import { itemIds } from '@server/world/config/item-ids'; import { loopingAction } from '@server/world/actor/player/action/action'; import { Skill } from '@server/world/actor/skills'; -import { gameCache } from '@server/game-server'; +import { cache } from '@server/game-server'; import { widgets } from '@server/world/config/widget'; import { animationIds } from '@server/world/config/animation-ids'; import { objectIds } from '@server/world/config/object-ids'; @@ -116,7 +116,7 @@ const spinProduct: any = (details: ButtonActionDetails, spinnable: Spinnable, co cancel = true; } if (cancel) { - details.player.sendMessage(`You don't have any ${gameCache.itemDefinitions.get(currentItem).name.toLowerCase()}.`); + details.player.sendMessage(`You don't have any ${cache.itemDefinitions.get(currentItem).name.toLowerCase()}.`); loop.cancel(); return; } @@ -149,7 +149,7 @@ export const buttonClicked: buttonAction = (details) => { details.player.closeActiveWidgets(); if (!details.player.skills.hasSkillLevel(Skill.CRAFTING, product.spinnable.requiredLevel)) { - details.player.sendMessage(`You need a crafting level of ${product.spinnable.requiredLevel} to craft ${gameCache.itemDefinitions.get(product.spinnable.output).name.toLowerCase()}.`, true); + details.player.sendMessage(`You need a crafting level of ${product.spinnable.requiredLevel} to craft ${cache.itemDefinitions.get(product.spinnable.output).name.toLowerCase()}.`, true); return; } diff --git a/src/plugins/skills/firemaking-plugin.ts b/src/plugins/skills/firemaking-plugin.ts index a79d76735..dbb35820c 100644 --- a/src/plugins/skills/firemaking-plugin.ts +++ b/src/plugins/skills/firemaking-plugin.ts @@ -2,7 +2,7 @@ import { itemOnItemAction } from '@server/world/actor/player/action/item-on-item import { world } from '@server/game-server'; import { Skill } from '@server/world/actor/skills'; import { loopingAction } from '@server/world/actor/player/action/action'; -import { LandscapeObject } from '@runejs/cache-parser'; +import { LocationObject } from '@runejs/cache-parser'; import { Player } from '@server/world/actor/player/player'; import { WorldItem } from '@server/world/items/world-item'; import { Position } from '@server/world/position'; @@ -41,13 +41,13 @@ const fireDuration = (): number => { const lightFire = (player: Player, position: Position, worldItemLog: WorldItem, burnExp: number): void => { world.removeWorldItem(worldItemLog); - const fireObject: LandscapeObject = { + const fireObject: LocationObject = { objectId: objectIds.fire, x: position.x, y: position.y, level: position.level, type: 10, - rotation: 0 + orientation: 0 }; player.playAnimation(null); @@ -61,7 +61,7 @@ const lightFire = (player: Player, position: Position, worldItemLog: WorldItem, } } } - world.addTemporaryLandscapeObject(fireObject, position, fireDuration()).then(() => { + world.addTemporaryLocationObject(fireObject, position, fireDuration()).then(() => { world.spawnWorldItem({ itemId: itemIds.ashes, amount: 1 }, position, null, 300); }); diff --git a/src/web-server.ts b/src/web-server.ts index 8065d1bf2..bddbf50d9 100644 --- a/src/web-server.ts +++ b/src/web-server.ts @@ -1,5 +1,5 @@ import express, { Request } from 'express'; -import { gameCache, world } from './game-server'; +import { cache, world } from './game-server'; import { Player } from './world/actor/player/player'; import { constants } from 'http2'; import { logger } from '@runejs/logger'; @@ -153,7 +153,7 @@ export function runWebServer(): void { } const itemData = req.body as ItemData; - const itemDefinition = gameCache.itemDefinitions.get(itemId); + const itemDefinition = cache.itemDefinitions.get(itemId); const itemDetails = { ...itemDefinition, ...itemData } as ItemDetails; world.itemData.set(itemId, itemDetails); saveItemData(world.itemData); diff --git a/src/world/actor/dialogue.ts b/src/world/actor/dialogue.ts index a17c9bbea..74a1b103d 100644 --- a/src/world/actor/dialogue.ts +++ b/src/world/actor/dialogue.ts @@ -1,7 +1,7 @@ import { Npc } from '@server/world/actor/npc/npc'; import { Player } from '@server/world/actor/player/player'; import { Subscription } from 'rxjs'; -import { gameCache } from '@server/game-server'; +import { cache } from '@server/game-server'; import { logger } from '@runejs/logger/dist/logger'; import _ from 'lodash'; import { wrapText } from '@server/util/strings'; @@ -472,7 +472,7 @@ async function runParsedDialogue(player: Player, dialogueTree: ParsedDialogueTre if(dialogueAction.type === 'NPC') { widgetId = npcWidgetIds[lines.length - 1]; player.outgoingPackets.setWidgetNpcHead(widgetId, 0, npcId as number); - player.outgoingPackets.updateWidgetString(widgetId, 1, gameCache.npcDefinitions.get(npcId as number).name); + player.outgoingPackets.updateWidgetString(widgetId, 1, cache.npcDefinitions.get(npcId as number).name); } else { widgetId = playerWidgetIds[lines.length - 1]; player.outgoingPackets.setWidgetPlayerHead(widgetId, 0); diff --git a/src/world/actor/npc/npc.ts b/src/world/actor/npc/npc.ts index 78b61d7d1..daff4bdf0 100644 --- a/src/world/actor/npc/npc.ts +++ b/src/world/actor/npc/npc.ts @@ -70,7 +70,7 @@ export class Npc extends Actor { public init(): void { world.chunkManager.getChunkForWorldPosition(this.position).addNpc(this); - this.initiateRandomMovement(); + // this.initiateRandomMovement(); new Promise(resolve => { npcInitPlugins diff --git a/src/world/actor/player/action/action.ts b/src/world/actor/player/action/action.ts index a9c71b277..6e0ffdf20 100644 --- a/src/world/actor/player/action/action.ts +++ b/src/world/actor/player/action/action.ts @@ -2,14 +2,14 @@ import { Player } from '@server/world/actor/player/player'; import { Position } from '@server/world/position'; import { Subject, timer } from 'rxjs'; import { World } from '@server/world/world'; -import { LandscapeObject } from '@runejs/cache-parser'; +import { LocationObject } from '@runejs/cache-parser'; import { Npc } from '@server/world/actor/npc/npc'; /** * A type of action where something is being interacted with. */ export interface InteractingAction { - interactingObject?: LandscapeObject; + interactingObject?: LocationObject; } /** @@ -89,8 +89,8 @@ export const walkToAction = async (player: Player, position: Position, interacti } } else { if(interactingAction.interactingObject) { - const landscapeObject = interactingAction.interactingObject; - if(player.position.withinInteractionDistance(landscapeObject)) { + const locationObject = interactingAction.interactingObject; + if(player.position.withinInteractionDistance(locationObject)) { resolve(); } else { reject(); diff --git a/src/world/actor/player/action/dialogue-action.ts b/src/world/actor/player/action/dialogue-action.ts index fb1304f51..9da461fd7 100644 --- a/src/world/actor/player/action/dialogue-action.ts +++ b/src/world/actor/player/action/dialogue-action.ts @@ -1,5 +1,5 @@ import { Player } from '@server/world/actor/player/player'; -import { gameCache } from '@server/game-server'; +import { cache } from '@server/game-server'; import { Npc } from '@server/world/actor/npc/npc'; import { WidgetsClosedWarning } from '@server/error-handling'; @@ -115,7 +115,7 @@ export class DialogueAction { if(options.type === 'NPC') { this.p.outgoingPackets.setWidgetNpcHead(widgetId, 0, options.npc); - this.p.outgoingPackets.updateWidgetString(widgetId, 1, gameCache.npcDefinitions.get(options.npc).name); + this.p.outgoingPackets.updateWidgetString(widgetId, 1, cache.npcDefinitions.get(options.npc).name); } else if(options.type === 'PLAYER') { this.p.outgoingPackets.setWidgetPlayerHead(widgetId, 0); this.p.outgoingPackets.updateWidgetString(widgetId, 1, this.p.username); diff --git a/src/world/actor/player/action/item-action.ts b/src/world/actor/player/action/item-action.ts index 6dc18893e..b1738b5ad 100644 --- a/src/world/actor/player/action/item-action.ts +++ b/src/world/actor/player/action/item-action.ts @@ -81,7 +81,7 @@ export const itemAction = (player: Player, itemId: number, slot: number, widgetI let cancelActions = false; - // Find all object action plugins that reference this landscape object + // Find all object action plugins that reference this location object let interactionActions = itemInteractions.filter(plugin => { if(!questFilter(player, plugin)) { return false; diff --git a/src/world/actor/player/action/item-on-object-action.ts b/src/world/actor/player/action/item-on-object-action.ts index 1132e3d9f..d5d05f24a 100644 --- a/src/world/actor/player/action/item-on-object-action.ts +++ b/src/world/actor/player/action/item-on-object-action.ts @@ -1,12 +1,11 @@ import { Player } from '@server/world/actor/player/player'; -import { LandscapeObject, LandscapeObjectDefinition } from '@runejs/cache-parser'; +import { LocationObject, LocationObjectDefinition } from '@runejs/cache-parser'; import { Position } from '@server/world/position'; import { walkToAction } from '@server/world/actor/player/action/action'; import { pluginFilter } from '@server/plugins/plugin-loader'; import { logger } from '@runejs/logger/dist/logger'; import { ActionPlugin, questFilter } from '@server/plugins/plugin'; import { Item } from '@server/world/items/item'; -import { soundIds } from '@server/world/config/sound-ids'; /** * The definition for an item on object action function. @@ -20,9 +19,9 @@ export interface ItemOnObjectActionDetails { // The player performing the action. player: Player; // The object the action is being performed on. - object: LandscapeObject; + object: LocationObject; // Additional details about the object that the action is being performed on. - objectDefinition: LandscapeObjectDefinition; + objectDefinition: LocationObjectDefinition; // The position that the game object was at when the action was initiated. position: Position; // The item being used. @@ -65,14 +64,14 @@ export const setItemOnObjectPlugins = (plugins: ActionPlugin[]): void => { }; // @TODO priority and cancelling other (lower priority) actions -export const itemOnObjectAction = (player: Player, landscapeObject: LandscapeObject, landscapeObjectDefinition: LandscapeObjectDefinition, +export const itemOnObjectAction = (player: Player, locationObject: LocationObject, locationObjectDefinition: LocationObjectDefinition, position: Position, item: Item, itemWidgetId: number, itemContainerId: number, cacheOriginal: boolean): void => { if(player.busy) { return; } - // Find all item on object action plugins that reference this landscape object - let interactionActions = itemOnObjectInteractions.filter(plugin => questFilter(player, plugin) && pluginFilter(plugin.objectIds, landscapeObject.objectId)); + // Find all item on object action plugins that reference this location object + let interactionActions = itemOnObjectInteractions.filter(plugin => questFilter(player, plugin) && pluginFilter(plugin.objectIds, locationObject.objectId)); const questActions = interactionActions.filter(plugin => plugin.questAction !== undefined); if(questActions.length !== 0) { @@ -85,8 +84,8 @@ export const itemOnObjectAction = (player: Player, landscapeObject: LandscapeObj } if(interactionActions.length === 0) { - player.outgoingPackets.chatboxMessage(`Unhandled item on object interaction: ${ item.itemId } on ${ landscapeObjectDefinition.name } ` + - `(id-${ landscapeObject.objectId }) @ ${ position.x },${ position.y },${ position.level }`); + player.outgoingPackets.chatboxMessage(`Unhandled item on object interaction: ${ item.itemId } on ${ locationObjectDefinition.name } ` + + `(id-${ locationObject.objectId }) @ ${ position.x },${ position.y },${ position.level }`); return; } @@ -98,15 +97,15 @@ export const itemOnObjectAction = (player: Player, landscapeObject: LandscapeObj // Make sure we walk to the object before running any of the walk-to plugins if(walkToPlugins.length !== 0) { - walkToAction(player, position, { interactingObject: landscapeObject }) + walkToAction(player, position, { interactingObject: locationObject }) .then(() => { player.face(position); walkToPlugins.forEach(plugin => plugin.action({ player, - object: landscapeObject, - objectDefinition: landscapeObjectDefinition, + object: locationObject, + objectDefinition: locationObjectDefinition, position, item, itemWidgetId, @@ -122,8 +121,8 @@ export const itemOnObjectAction = (player: Player, landscapeObject: LandscapeObj immediatePlugins.forEach(plugin => plugin.action({ player, - object: landscapeObject, - objectDefinition: landscapeObjectDefinition, + object: locationObject, + objectDefinition: locationObjectDefinition, position, item, itemWidgetId, diff --git a/src/world/actor/player/action/object-action.ts b/src/world/actor/player/action/object-action.ts index d88e94be0..f30ddba67 100644 --- a/src/world/actor/player/action/object-action.ts +++ b/src/world/actor/player/action/object-action.ts @@ -1,5 +1,5 @@ import { Player } from '@server/world/actor/player/player'; -import { LandscapeObject, LandscapeObjectDefinition } from '@runejs/cache-parser'; +import { LocationObject, LocationObjectDefinition } from '@runejs/cache-parser'; import { Position } from '@server/world/position'; import { walkToAction } from '@server/world/actor/player/action/action'; import { pluginFilter } from '@server/plugins/plugin-loader'; @@ -18,9 +18,9 @@ export interface ObjectActionDetails { // The player performing the action. player: Player; // The object the action is being performed on. - object: LandscapeObject; + object: LocationObject; // Additional details about the object that the action is being performed on. - objectDefinition: LandscapeObjectDefinition; + objectDefinition: LocationObjectDefinition; // The position that the game object was at when the action was initiated. position: Position; // Whether or not this game object is an original map object or if it has been added/replaced. @@ -59,14 +59,14 @@ export const setObjectPlugins = (plugins: ActionPlugin[]): void => { }; // @TODO priority and cancelling other (lower priority) actions -export const objectAction = (player: Player, landscapeObject: LandscapeObject, landscapeObjectDefinition: LandscapeObjectDefinition, +export const objectAction = (player: Player, locationObject: LocationObject, locationObjectDefinition: LocationObjectDefinition, position: Position, option: string, cacheOriginal: boolean): void => { if(player.busy) { return; } - // Find all object action plugins that reference this landscape object - let interactionActions = objectInteractions.filter(plugin => questFilter(player, plugin) && pluginFilter(plugin.objectIds, landscapeObject.objectId, plugin.options, option)); + // Find all object action plugins that reference this location object + let interactionActions = objectInteractions.filter(plugin => questFilter(player, plugin) && pluginFilter(plugin.objectIds, locationObject.objectId, plugin.options, option)); const questActions = interactionActions.filter(plugin => plugin.questAction !== undefined); if(questActions.length !== 0) { @@ -74,8 +74,8 @@ export const objectAction = (player: Player, landscapeObject: LandscapeObject, l } if(interactionActions.length === 0) { - player.outgoingPackets.chatboxMessage(`Unhandled object interaction: ${option} ${landscapeObjectDefinition.name} ` + - `(id-${landscapeObject.objectId}) @ ${position.x},${position.y},${position.level}`); + player.outgoingPackets.chatboxMessage(`Unhandled object interaction: ${option} ${locationObjectDefinition.name} ` + + `(id-${locationObject.objectId}) @ ${position.x},${position.y},${position.level}`); return; } @@ -87,15 +87,15 @@ export const objectAction = (player: Player, landscapeObject: LandscapeObject, l // Make sure we walk to the object before running any of the walk-to plugins if(walkToPlugins.length !== 0) { - walkToAction(player, position, { interactingObject: landscapeObject }) + walkToAction(player, position, { interactingObject: locationObject }) .then(() => { player.face(position); walkToPlugins.forEach(plugin => plugin.action({ player, - object: landscapeObject, - objectDefinition: landscapeObjectDefinition, + object: locationObject, + objectDefinition: locationObjectDefinition, option, position, cacheOriginal @@ -109,8 +109,8 @@ export const objectAction = (player: Player, landscapeObject: LandscapeObject, l immediatePlugins.forEach(plugin => plugin.action({ player, - object: landscapeObject, - objectDefinition: landscapeObjectDefinition, + object: locationObject, + objectDefinition: locationObjectDefinition, option, position, cacheOriginal diff --git a/src/world/actor/player/player.ts b/src/world/actor/player/player.ts index 3320500e5..ed6c93627 100644 --- a/src/world/actor/player/player.ts +++ b/src/world/actor/player/player.ts @@ -4,7 +4,7 @@ import { Isaac } from '@server/net/isaac'; import { PlayerUpdateTask } from './updating/player-update-task'; import { Actor } from '../actor'; import { Position } from '@server/world/position'; -import { gameCache, serverConfig, world } from '@server/game-server'; +import { cache, serverConfig, world } from '@server/game-server'; import { logger } from '@runejs/logger'; import { Appearance, @@ -295,7 +295,7 @@ export class Player extends Actor { } /** - * Sends chunk updates to notify the client of added & removed landscape objects + * Sends chunk updates to notify the client of added & removed location objects * @param chunks The chunks to update. */ private sendChunkUpdates(chunks: Chunk[]): void { @@ -304,12 +304,12 @@ export class Player extends Actor { const chunkUpdateItems: ChunkUpdateItem[] = []; - if(chunk.removedLandscapeObjects.size !== 0) { - chunk.removedLandscapeObjects.forEach(object => chunkUpdateItems.push({ object, type: 'REMOVE' })); + if(chunk.removedLocationObjects.size !== 0) { + chunk.removedLocationObjects.forEach(object => chunkUpdateItems.push({ object, type: 'REMOVE' })); } - if(chunk.addedLandscapeObjects.size !== 0) { - chunk.addedLandscapeObjects.forEach(object => chunkUpdateItems.push({ object, type: 'ADD' })); + if(chunk.addedLocationObjects.size !== 0) { + chunk.addedLocationObjects.forEach(object => chunkUpdateItems.push({ object, type: 'ADD' })); } if(chunk.worldItems.size !== 0) { @@ -456,7 +456,7 @@ export class Player extends Actor { if(questData.completion.itemId) { this.outgoingPackets.updateWidgetModel1(widgets.questReward, 3, - (gameCache.itemDefinitions.get(questData.completion.itemId) as NewFormatItemDefinition).inventoryModelId); + (cache.itemDefinitions.get(questData.completion.itemId) as NewFormatItemDefinition).inventoryModelId); } else if(questData.completion.modelId) { this.outgoingPackets.updateWidgetModel1(widgets.questReward, 3, questData.completion.modelId); } diff --git a/src/world/actor/walking-queue.ts b/src/world/actor/walking-queue.ts index f333b1f1b..0a84eee08 100644 --- a/src/world/actor/walking-queue.ts +++ b/src/world/actor/walking-queue.ts @@ -3,7 +3,7 @@ import { Position } from '../position'; import { Player } from './player/player'; import { world } from '@server/game-server'; import { Chunk } from '../map/chunk'; -import { MapRegionTile } from '@runejs/cache-parser'; +import { Tile } from '@runejs/cache-parser'; import { Npc } from './npc/npc'; /** @@ -99,7 +99,7 @@ export class WalkingQueue { let destinationChunk: Chunk = world.chunkManager.getChunkForWorldPosition(destination); const positionAbove: Position = new Position(destination.x, destination.y, destination.level + 1); const chunkAbove: Chunk = world.chunkManager.getChunkForWorldPosition(positionAbove); - let tile: MapRegionTile = chunkAbove.getTile(positionAbove); + let tile: Tile = chunkAbove.getTile(positionAbove); if(!tile || !tile.bridge) { tile = destinationChunk.getTile(destination); @@ -212,7 +212,7 @@ export class WalkingQueue { private calculateLocalCornerPosition(cornerX: number, cornerY: number, origin: Position): { localX: number, localY: number, chunk: Chunk } { const cornerPosition: Position = new Position(cornerX, cornerY, origin.level + 1); let cornerChunk: Chunk = world.chunkManager.getChunkForWorldPosition(cornerPosition); - const tileAbove: MapRegionTile = cornerChunk.getTile(cornerPosition); + const tileAbove: Tile = cornerChunk.getTile(cornerPosition); if(!tileAbove || !tileAbove.bridge) { cornerPosition.level = cornerPosition.level - 1; cornerChunk = world.chunkManager.getChunkForWorldPosition(cornerPosition); diff --git a/src/world/items/item.ts b/src/world/items/item.ts index b61063eee..5e52ac301 100644 --- a/src/world/items/item.ts +++ b/src/world/items/item.ts @@ -1,4 +1,4 @@ -import { gameCache } from '@server/game-server'; +import { cache } from '@server/game-server'; export interface Item { itemId: number; @@ -6,7 +6,7 @@ export interface Item { } function itemInventoryOptions(itemId: number): string[] { - const itemDefinition = gameCache.itemDefinitions.get(itemId); + const itemDefinition = cache.itemDefinitions.get(itemId); if(!itemDefinition) { return []; } @@ -15,7 +15,7 @@ function itemInventoryOptions(itemId: number): string[] { } export const getItemOptions = (itemId: number, widget: { widgetId: number, containerId: number }): string[] => { - const widgetDefinition = gameCache.widgetDefinitions.get(widget.widgetId); + const widgetDefinition = cache.widgets.get(widget.widgetId); if(!widgetDefinition || !widgetDefinition.children || widgetDefinition.children.length <= widget.containerId) { return itemInventoryOptions(itemId); } diff --git a/src/world/map/chunk-manager.ts b/src/world/map/chunk-manager.ts index 2cfbf5da9..c9b22e457 100644 --- a/src/world/map/chunk-manager.ts +++ b/src/world/map/chunk-manager.ts @@ -1,12 +1,7 @@ import { Chunk } from './chunk'; import { Position } from '../position'; -import { gameCache377 } from '../../game-server'; import { logger } from '@runejs/logger'; -import { LandscapeObject } from '@runejs/cache-parser'; -import { Item } from '@server/world/items/item'; -import { Player } from '@server/world/actor/player/player'; -import { WorldItem } from '@server/world/items/world-item'; -import { World } from '@server/world/world'; +import { cache } from '@server/game-server'; /** * Controls all of the game world's map chunks. @@ -22,7 +17,7 @@ export class ChunkManager { public generateCollisionMaps(): void { logger.info('Generating game world collision maps...'); - const tileList = gameCache377.mapRegions.mapRegionTileList; + const tileList = cache.mapData.tiles; for(const tile of tileList) { const position = new Position(tile.x, tile.y, tile.level); @@ -30,12 +25,12 @@ export class ChunkManager { chunk.addTile(tile, position); } - const objectList = gameCache377.mapRegions.landscapeObjectList; + const objectList = cache.mapData.locationObjects; - for(const landscapeObject of objectList) { - const position = new Position(landscapeObject.x, landscapeObject.y, landscapeObject.level); + for(const locationObject of objectList) { + const position = new Position(locationObject.x, locationObject.y, locationObject.level); const chunk = this.getChunkForWorldPosition(position); - chunk.setCacheLandscapeObject(landscapeObject, position); + chunk.setCacheLocationObject(locationObject, position); } logger.info('Game world collision maps generated.', true); diff --git a/src/world/map/chunk.ts b/src/world/map/chunk.ts index 17b4b7ef9..1697b2ad2 100644 --- a/src/world/map/chunk.ts +++ b/src/world/map/chunk.ts @@ -1,13 +1,13 @@ import { Position } from '../position'; import { Player } from '../actor/player/player'; import { CollisionMap } from './collision-map'; -import { gameCache } from '../../game-server'; -import { LandscapeObject, LandscapeObjectDefinition, MapRegionTile } from '@runejs/cache-parser'; +import { cache } from '../../game-server'; +import { LocationObject, LocationObjectDefinition, Tile } from '@runejs/cache-parser'; import { Npc } from '../actor/npc/npc'; import { WorldItem } from '@server/world/items/world-item'; export interface ChunkUpdateItem { - object?: LandscapeObject; + object?: LocationObject; worldItem?: WorldItem; type: 'ADD' | 'REMOVE'; } @@ -21,10 +21,10 @@ export class Chunk { private readonly _players: Player[]; private readonly _npcs: Npc[]; private readonly _collisionMap: CollisionMap; - private readonly _tileList: MapRegionTile[]; - private readonly _cacheLandscapeObjects: Map; - private readonly _addedLandscapeObjects: Map; - private readonly _removedLandscapeObjects: Map; + private readonly _tileList: Tile[]; + private readonly _cacheLocationObjects: Map; + private readonly _addedLocationObjects: Map; + private readonly _removedLocationObjects: Map; private readonly _worldItems: Map; public constructor(position: Position) { @@ -33,9 +33,9 @@ export class Chunk { this._npcs = []; this._collisionMap = new CollisionMap(8, 8, (position.x + 6) * 8, (position.y + 6) * 8, this); this._tileList = []; - this._cacheLandscapeObjects = new Map(); - this._addedLandscapeObjects = new Map(); - this._removedLandscapeObjects = new Map(); + this._cacheLocationObjects = new Map(); + this._addedLocationObjects = new Map(); + this._removedLocationObjects = new Map(); this._worldItems = new Map(); } @@ -78,19 +78,20 @@ export class Chunk { } } - public setCacheLandscapeObject(landscapeObject: LandscapeObject, objectPosition: Position): void { + public setCacheLocationObject(locationObject: LocationObject, objectPosition: Position): void { let tile = this.getTile(objectPosition); if(!tile) { - tile = new MapRegionTile(objectPosition.x, objectPosition.y, objectPosition.level, 0); + tile = new Tile(objectPosition.x, objectPosition.y, objectPosition.level); + tile.flags = 0; this.addTile(tile, objectPosition); } - this.markOnCollisionMap(landscapeObject, objectPosition, true); - this._cacheLandscapeObjects.set(`${objectPosition.x},${objectPosition.y},${landscapeObject.objectId}`, landscapeObject); + this.markOnCollisionMap(locationObject, objectPosition, true); + this._cacheLocationObjects.set(`${objectPosition.x},${objectPosition.y},${locationObject.objectId}`, locationObject); } - public addTile(tile: MapRegionTile, tilePosition: Position): void { + public addTile(tile: Tile, tilePosition: Position): void { const existingTile = this.getTile(tilePosition); if(existingTile) { return; @@ -99,7 +100,7 @@ export class Chunk { this._tileList.push(tile); } - public getTile(position: Position): MapRegionTile { + public getTile(position: Position): Tile { for(const tile of this._tileList) { if(position.equalsIgnoreLevel({ x: tile.x, y: tile.y })) { return tile; @@ -135,12 +136,16 @@ export class Chunk { } } - public markOnCollisionMap(landscapeObject: LandscapeObject, position: Position, mark: boolean): void { + public markOnCollisionMap(locationObject: LocationObject, position: Position, mark: boolean): void { const x: number = position.x; const y: number = position.y; - const objectType = landscapeObject.type; - const objectRotation = landscapeObject.rotation; - const objectDetails: LandscapeObjectDefinition = gameCache.landscapeObjectDefinitions.get(landscapeObject.objectId); + const objectType = locationObject.type; + const objectOrientation = locationObject.orientation; + const objectDetails: LocationObjectDefinition = cache.locationObjectDefinitions.get(locationObject.objectId); + + if(x === 3223 && y === 3217) { + console.log(`${x},${y} is type ${objectType} with orientation ${objectOrientation}`); + } if(objectDetails.solid) { if(objectType === 22) { @@ -148,46 +153,46 @@ export class Chunk { this.collisionMap.markBlocked(x, y, mark); } } else if(objectType >= 9) { - this.collisionMap.markSolidOccupant(x, y, objectDetails.sizeX, objectDetails.sizeY, objectRotation, objectDetails.nonWalkable, mark); + this.collisionMap.markSolidOccupant(x, y, objectDetails.sizeX, objectDetails.sizeY, objectOrientation, objectDetails.nonWalkable, mark); } else if(objectType >= 0 && objectType <= 3) { if(mark) { - this.collisionMap.markWall(x, y, objectType, objectRotation, objectDetails.nonWalkable); + this.collisionMap.markWall(x, y, objectType, objectOrientation, objectDetails.nonWalkable); } else { - this.collisionMap.unmarkWall(x, y, objectType, objectRotation, objectDetails.nonWalkable); + this.collisionMap.unmarkWall(x, y, objectType, objectOrientation, objectDetails.nonWalkable); } } } } - public removeObject(object: LandscapeObject, position: Position, markRemoved: boolean = true): void { + public removeObject(object: LocationObject, position: Position, markRemoved: boolean = true): void { if(markRemoved && this.getCacheObject(object.objectId, position)) { // Only add this as an "removed" object if it's from the cache, as that's all we care about - this.removedLandscapeObjects.set(`${position.x},${position.y},${object.objectId}`, object); + this.removedLocationObjects.set(`${position.x},${position.y},${object.objectId}`, object); } this.markOnCollisionMap(object, position, false); } - public addObject(object: LandscapeObject, position: Position): void { + public addObject(object: LocationObject, position: Position): void { if(!this.getCacheObject(object.objectId, position)) { // Only add this as an "added" object if there's not a cache object with the same id and position // This becomes a "custom" added object - this.addedLandscapeObjects.set(`${position.x},${position.y},${object.objectId}`, object); + this.addedLocationObjects.set(`${position.x},${position.y},${object.objectId}`, object); } this.markOnCollisionMap(object, position, true); } - public getCacheObject(objectId: number, position: Position): LandscapeObject { - return this.cacheLandscapeObjects.get(`${position.x},${position.y},${objectId}`); + public getCacheObject(objectId: number, position: Position): LocationObject { + return this.cacheLocationObjects.get(`${position.x},${position.y},${objectId}`); } - public getAddedObject(objectId: number, position: Position): LandscapeObject { - return this.addedLandscapeObjects.get(`${position.x},${position.y},${objectId}`); + public getAddedObject(objectId: number, position: Position): LocationObject { + return this.addedLocationObjects.get(`${position.x},${position.y},${objectId}`); } - public getRemovedObject(objectId: number, position: Position): LandscapeObject { - return this.removedLandscapeObjects.get(`${position.x},${position.y},${objectId}`); + public getRemovedObject(objectId: number, position: Position): LocationObject { + return this.removedLocationObjects.get(`${position.x},${position.y},${objectId}`); } public equals(chunk: Chunk): boolean { @@ -210,20 +215,20 @@ export class Chunk { return this._collisionMap; } - public get tileList(): MapRegionTile[] { + public get tileList(): Tile[] { return this._tileList; } - public get cacheLandscapeObjects(): Map { - return this._cacheLandscapeObjects; + public get cacheLocationObjects(): Map { + return this._cacheLocationObjects; } - public get addedLandscapeObjects(): Map { - return this._addedLandscapeObjects; + public get addedLocationObjects(): Map { + return this._addedLocationObjects; } - public get removedLandscapeObjects(): Map { - return this._removedLandscapeObjects; + public get removedLocationObjects(): Map { + return this._removedLocationObjects; } public get worldItems(): Map { diff --git a/src/world/map/landscape-object.ts b/src/world/map/landscape-object.ts deleted file mode 100644 index 4b39339b0..000000000 --- a/src/world/map/landscape-object.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { LandscapeObject } from '@runejs/cache-parser'; - -export interface ModifiedLandscapeObject extends LandscapeObject { - metadata?: { [key: string]: any }; -} - -export const objectKey = (object: LandscapeObject, level: boolean = false): string => { - return `${object.x},${object.y}${level ? `,${object.level}` : ''},${object.objectId}`; -}; diff --git a/src/world/map/location-object.ts b/src/world/map/location-object.ts new file mode 100644 index 000000000..f63e5ccc8 --- /dev/null +++ b/src/world/map/location-object.ts @@ -0,0 +1,9 @@ +import { LocationObject } from '@runejs/cache-parser'; + +export interface ModifiedLocationObject extends LocationObject { + metadata?: { [key: string]: any }; +} + +export const objectKey = (object: LocationObject, level: boolean = false): string => { + return `${object.x},${object.y}${level ? `,${object.level}` : ''},${object.objectId}`; +}; diff --git a/src/world/position.ts b/src/world/position.ts index d1a373f38..7ef515982 100644 --- a/src/world/position.ts +++ b/src/world/position.ts @@ -1,6 +1,6 @@ import { Direction, directionData } from '@server/world/direction'; -import { LandscapeObject } from '@runejs/cache-parser'; -import { gameCache } from '@server/game-server'; +import { LocationObject } from '@runejs/cache-parser'; +import { cache } from '@server/game-server'; const directionDeltaX = [-1, 0, 1, -1, 1, -1, 0, 1]; const directionDeltaY = [1, 1, 1, 0, 0, -1, -1, -1]; @@ -19,10 +19,10 @@ export class Position { this.move(x, y, level); } - public withinInteractionDistance(landscapeObject: LandscapeObject): boolean { - const definition = gameCache.landscapeObjectDefinitions.get(landscapeObject.objectId); - const occupantX = landscapeObject.x; - const occupantY = landscapeObject.y; + public withinInteractionDistance(locationObject: LocationObject): boolean { + const definition = cache.locationObjectDefinitions.get(locationObject.objectId); + const occupantX = locationObject.x; + const occupantY = locationObject.y; let width = definition.sizeX; let height = definition.sizeY; @@ -34,9 +34,9 @@ export class Position { } if(width === 1 && height === 1) { - return this.distanceBetween(new Position(occupantX, occupantY, landscapeObject.level)) <= 1; + return this.distanceBetween(new Position(occupantX, occupantY, locationObject.level)) <= 1; } else { - if(landscapeObject.rotation == 1 || landscapeObject.rotation == 3) { + if(locationObject.orientation == 1 || locationObject.orientation == 3) { const off = width; width = height; height = off; @@ -44,7 +44,7 @@ export class Position { for(let x = occupantX; x < occupantX + width; x++) { for(let y = occupantY; y < occupantY + height; y++) { - if(this.distanceBetween(new Position(x, y, landscapeObject.level)) <= 1) { + if(this.distanceBetween(new Position(x, y, locationObject.level)) <= 1) { return true; } } diff --git a/src/world/world.ts b/src/world/world.ts index 557f75f89..ed8a1f262 100644 --- a/src/world/world.ts +++ b/src/world/world.ts @@ -2,7 +2,7 @@ import { Player } from './actor/player/player'; import { ChunkManager } from './map/chunk-manager'; import { logger } from '@runejs/logger'; import { ItemDetails, parseItemData } from './config/item-data'; -import { gameCache, world } from '@server/game-server'; +import { cache } from '@server/game-server'; import { Position } from './position'; import { NpcSpawn, parseNpcSpawns } from './config/npc-spawn'; import { Npc } from './actor/npc/npc'; @@ -13,7 +13,7 @@ import { Actor } from '@server/world/actor/actor'; import { WorldItem } from '@server/world/items/world-item'; import { Item } from '@server/world/items/item'; import { Chunk } from '@server/world/map/chunk'; -import { LandscapeObject } from '@runejs/cache-parser'; +import { LocationObject } from '@runejs/cache-parser'; import { schedule } from '@server/task/task'; export interface QuadtreeKey { @@ -42,7 +42,7 @@ export class World { public readonly npcTree: Quadtree; public constructor() { - this.itemData = parseItemData(gameCache.itemDefinitions); + this.itemData = parseItemData(cache.itemDefinitions); this.npcSpawns = parseNpcSpawns(); this.shops = parseShops(); this.playerTree = new Quadtree({ @@ -188,16 +188,16 @@ export class World { } /** - * Replaces a landscape object within the world with a different object of the same object type, orientation, and position. + * Replaces a location object within the world with a different object of the same object type, orientation, and position. * NOT to be confused with `toggleObjects`, which removes one object and adds a different one that may have a differing * type, orientation, or position (such as a door being opened). - * @param newObject The new landscape object to spawn, or the id of the landscape object to spawn. - * @param oldObject The landscape object being replaced. Usually a game-cache-stored object. - * @param respawnTicks [optional] How many ticks it will take before the original landscape object respawns. - * If not provided, the original landscape object will never re-spawn and the new landscape object will forever + * @param newObject The new location object to spawn, or the id of the location object to spawn. + * @param oldObject The location object being replaced. Usually a game-cache-stored object. + * @param respawnTicks [optional] How many ticks it will take before the original location object respawns. + * If not provided, the original location object will never re-spawn and the new location object will forever * remain in it's place. */ - public replaceObject(newObject: LandscapeObject | number, oldObject: LandscapeObject, respawnTicks: number = -1): void { + public replaceLocationObject(newObject: LocationObject | number, oldObject: LocationObject, respawnTicks: number = -1): void { if(typeof newObject === 'number') { newObject = { objectId: newObject, @@ -205,87 +205,87 @@ export class World { y: oldObject.y, level: oldObject.level, type: oldObject.type, - rotation: oldObject.rotation - } as LandscapeObject; + orientation: oldObject.orientation + } as LocationObject; } const position = new Position(newObject.x, newObject.y, newObject.level); - this.addLandscapeObject(newObject, position); + this.addLocationObject(newObject, position); if(respawnTicks !== -1) { - schedule(respawnTicks).then(() => this.addLandscapeObject(oldObject, position)); + schedule(respawnTicks).then(() => this.addLocationObject(oldObject, position)); } } /** - * Removes one landscape object and adds another to the game world. The new object may be completely different from + * Removes one location object and adds another to the game world. The new object may be completely different from * the one being removed, and in different positions. NOT to be confused with `replaceObject`, which will replace * and existing object with another object of the same type, orientation, and position. - * @param newObject The landscape object being spawned. - * @param oldObject The landscape object being removed. - * @param newPosition The position of the landscape object being added. - * @param oldPosition The position of the landscape object being removed. - * @param newChunk The chunk which the landscape object being added resides in. - * @param oldChunk The chunk which the landscape object being removed resides in. + * @param newObject The location object being spawned. + * @param oldObject The location object being removed. + * @param newPosition The position of the location object being added. + * @param oldPosition The position of the location object being removed. + * @param newChunk The chunk which the location object being added resides in. + * @param oldChunk The chunk which the location object being removed resides in. * @param newObjectInCache Whether or not the object being added is the original game-cache object. */ - public toggleObjects(newObject: LandscapeObject, oldObject: LandscapeObject, newPosition: Position, oldPosition: Position, - newChunk: Chunk, oldChunk: Chunk, newObjectInCache: boolean): void { + public toggleLocationObjects(newObject: LocationObject, oldObject: LocationObject, newPosition: Position, oldPosition: Position, + newChunk: Chunk, oldChunk: Chunk, newObjectInCache: boolean): void { if(newObjectInCache) { - this.deleteRemovedObjectMarker(newObject, newPosition, newChunk); - this.deleteAddedObjectMarker(oldObject, oldPosition, oldChunk); + this.deleteRemovedLocationObjectMarker(newObject, newPosition, newChunk); + this.deleteAddedLocationObjectMarker(oldObject, oldPosition, oldChunk); } - this.addLandscapeObject(newObject, newPosition); - this.removeLandscapeObject(oldObject, oldPosition); + this.addLocationObject(newObject, newPosition); + this.removeLocationObject(oldObject, oldPosition); } /** - * Deletes the tracked record of a spawned landscape object within a single game chunk. - * @param object The landscape object to delete the record of. - * @param position The position which the landscape object was spawned. - * @param chunk The map chunk which the landscape object was spawned. + * Deletes the tracked record of a spawned location object within a single game chunk. + * @param object The location object to delete the record of. + * @param position The position which the location object was spawned. + * @param chunk The map chunk which the location object was spawned. */ - public deleteAddedObjectMarker(object: LandscapeObject, position: Position, chunk: Chunk): void { - chunk.addedLandscapeObjects.delete(`${position.x},${position.y},${object.objectId}`); + public deleteAddedLocationObjectMarker(object: LocationObject, position: Position, chunk: Chunk): void { + chunk.addedLocationObjects.delete(`${position.x},${position.y},${object.objectId}`); } /** - * Deletes the tracked record of a removed/de-spawned landscape object within a single game chunk. - * @param object The landscape object to delete the record of. - * @param position The position which the landscape object was removed. - * @param chunk The map chunk which the landscape object was removed. + * Deletes the tracked record of a removed/de-spawned location object within a single game chunk. + * @param object The location object to delete the record of. + * @param position The position which the location object was removed. + * @param chunk The map chunk which the location object was removed. */ - public deleteRemovedObjectMarker(object: LandscapeObject, position: Position, chunk: Chunk): void { - chunk.removedLandscapeObjects.delete(`${position.x},${position.y},${object.objectId}`); + public deleteRemovedLocationObjectMarker(object: LocationObject, position: Position, chunk: Chunk): void { + chunk.removedLocationObjects.delete(`${position.x},${position.y},${object.objectId}`); } /** - * Spawns a temporary landscape object within the game world. - * @param object The landscape object to spawn. + * Spawns a temporary location object within the game world. + * @param object The location object to spawn. * @param position The position to spawn the object at. * @param expireTicks The number of game cycles/ticks before the object will de-spawn. */ - public async addTemporaryLandscapeObject(object: LandscapeObject, position: Position, expireTicks: number): Promise { + public async addTemporaryLocationObject(object: LocationObject, position: Position, expireTicks: number): Promise { return new Promise(resolve => { - this.addLandscapeObject(object, position); + this.addLocationObject(object, position); setTimeout(() => { - this.removeLandscapeObject(object, position, false) - .then(chunk => this.deleteAddedObjectMarker(object, position, chunk)); + this.removeLocationObject(object, position, false) + .then(chunk => this.deleteAddedLocationObjectMarker(object, position, chunk)); resolve(); }, expireTicks * World.TICK_LENGTH); }); } /** - * Temporarily de-spawns a landscape object from the game world. - * @param object The landscape object to de-spawn temporarily. - * @param position The position of the landscape object. + * Temporarily de-spawns a location object from the game world. + * @param object The location object to de-spawn temporarily. + * @param position The position of the location object. * @param expireTicks The number of game cycles/ticks before the object will re-spawn. */ - public async removeLandscapeObjectTemporarily(object: LandscapeObject, position: Position, expireTicks: number): Promise { + public async removeLocationObjectTemporarily(object: LocationObject, position: Position, expireTicks: number): Promise { const chunk = this.chunkManager.getChunkForWorldPosition(position); chunk.removeObject(object, position); @@ -293,25 +293,25 @@ export class World { const nearbyPlayers = this.chunkManager.getSurroundingChunks(chunk).map(chunk => chunk.players).flat(); nearbyPlayers.forEach(player => { - player.outgoingPackets.removeLandscapeObject(object, position); + player.outgoingPackets.removeLocationObject(object, position); }); setTimeout(() => { - this.deleteRemovedObjectMarker(object, position, chunk); - this.addLandscapeObject(object, position); + this.deleteRemovedLocationObjectMarker(object, position, chunk); + this.addLocationObject(object, position); resolve(); }, expireTicks * World.TICK_LENGTH); }); } /** - * Removes/de-spawns a landscape object from the game world. - * @param object The landscape object to de-spawn. - * @param position The position of the landscape object. + * Removes/de-spawns a location object from the game world. + * @param object The location object to de-spawn. + * @param position The position of the location object. * @param markRemoved [optional] Whether or not to mark the object as removed within it's map chunk. If not provided, * the object will be marked as removed. */ - public async removeLandscapeObject(object: LandscapeObject, position: Position, markRemoved: boolean = true): Promise { + public async removeLocationObject(object: LocationObject, position: Position, markRemoved: boolean = true): Promise { const chunk = this.chunkManager.getChunkForWorldPosition(position); chunk.removeObject(object, position, markRemoved); @@ -319,7 +319,7 @@ export class World { const nearbyPlayers = this.chunkManager.getSurroundingChunks(chunk).map(chunk => chunk.players).flat(); nearbyPlayers.forEach(player => { - player.outgoingPackets.removeLandscapeObject(object, position); + player.outgoingPackets.removeLocationObject(object, position); }); resolve(chunk); @@ -327,11 +327,11 @@ export class World { } /** - * Spawns a new landscape object within the game world. - * @param object The landscape object to spawn. + * Spawns a new location object within the game world. + * @param object The location object to spawn. * @param position The position at which to spawn the object. */ - public async addLandscapeObject(object: LandscapeObject, position: Position): Promise { + public async addLocationObject(object: LocationObject, position: Position): Promise { const chunk = this.chunkManager.getChunkForWorldPosition(position); chunk.addObject(object, position); @@ -339,7 +339,7 @@ export class World { const nearbyPlayers = this.chunkManager.getSurroundingChunks(chunk).map(chunk => chunk.players).flat(); nearbyPlayers.forEach(player => { - player.outgoingPackets.setLandscapeObject(object, position); + player.outgoingPackets.setLocationObject(object, position); }); resolve(); @@ -391,7 +391,7 @@ export class World { public spawnNpcs(): void { this.npcSpawns.forEach(npcSpawn => { - const npcDefinition = gameCache.npcDefinitions.get(npcSpawn.npcId); + const npcDefinition = cache.npcDefinitions.get(npcSpawn.npcId); const npc = new Npc(npcSpawn, npcDefinition); this.registerNpc(npc); });