Skip to content

Commit 7981822

Browse files
committed
Modifying how POH instances are handled
1 parent 14797ef commit 7981822

File tree

4 files changed

+74
-53
lines changed

4 files changed

+74
-53
lines changed

src/game-engine/net/outbound-packets.ts

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { stringToLong } from '@engine/util/strings';
1212
import { LandscapeObject } from '@runejs/filestore';
1313
import { xteaRegions } from '@engine/config';
1414
import { world } from '@engine/game-server';
15+
import { ConstructedMap } from '@engine/world/map/region';
1516

1617
/**
1718
* A helper class for sending various network packets back to the game client.
@@ -564,36 +565,25 @@ export class OutboundPackets {
564565
this.queue(packet);
565566
}
566567

567-
public constructHouseMaps(rooms: number[][][]): void {
568+
public constructMapRegion(mapData: ConstructedMap): void {
568569
const packet = new Packet(23, PacketType.DYNAMIC_LARGE);
569570

570-
const chunk = world.chunkManager.getChunkForWorldPosition(this.player.position);
571-
572-
const chunkX = this.player.position.chunkX + 6;
573-
const chunkY = this.player.position.chunkY + 6;
574-
const regionX = Math.floor(chunkX / 8);
575-
const regionY = Math.floor(chunkY / 8);
576-
577-
const localX = this.player.position.x - (regionX * 64);
578-
const localY = this.player.position.y - (regionY * 64);
579-
const mapPlane = this.player.position.level;
580-
581-
packet.put(localY, 'short');
582-
packet.put(localX, 'short', 'le');
583-
packet.put(chunkX, 'short');
584-
packet.put(mapPlane);
585-
packet.put(chunkY, 'short');
571+
packet.put(this.player.position.chunkLocalY, 'short');
572+
packet.put(this.player.position.chunkLocalX, 'short', 'le');
573+
packet.put(this.player.position.chunkX + 6, 'short');
574+
packet.put(this.player.position.level);
575+
packet.put(this.player.position.chunkY + 6, 'short');
586576

587577
packet.openBitBuffer();
588578

589579
for(let level = 0; level < 4; level++) {
590580
for(let x = 0; x < 13; x++) {
591581
for(let y = 0; y < 13; y++) {
592-
const roomData: number | null = rooms[level][x][y];
593-
packet.putBits(1, roomData === null ? 0 : 1);
582+
const tileData: number | null = mapData.tileData[level][x][y];
583+
packet.putBits(1, tileData === null ? 0 : 1);
594584

595-
if(roomData !== null) {
596-
packet.putBits(26, roomData);
585+
if(tileData !== null) {
586+
packet.putBits(26, tileData);
597587
}
598588
}
599589
}

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,10 @@ export class Player extends Actor {
266266
await this.actionPipeline.call('player_init', { player: this });
267267

268268
world.spawnWorldItems(this);
269-
this.chunkChanged(playerChunk);
269+
270+
if(!this.metadata.customMap) {
271+
this.chunkChanged(playerChunk);
272+
}
270273

271274
this.outgoingPackets.flushQueue();
272275
logger.info(`${this.username}:${this.worldIndex} has logged in.`);
@@ -391,10 +394,12 @@ export class Player extends Actor {
391394
return new Promise<void>(resolve => {
392395
this.walkingQueue.process();
393396

394-
if(this.metadata.customMap) {
395-
this.outgoingPackets.constructHouseMaps(this.metadata.customMap);
396-
} else if(this.updateFlags.mapRegionUpdateRequired) {
397-
this.outgoingPackets.updateCurrentMapChunk();
397+
if(this.updateFlags.mapRegionUpdateRequired) {
398+
if(this.metadata.customMap) {
399+
this.outgoingPackets.constructMapRegion(this.metadata.customMap);
400+
} else {
401+
this.outgoingPackets.updateCurrentMapChunk();
402+
}
398403
}
399404

400405
resolve();
@@ -637,25 +642,25 @@ export class Player extends Actor {
637642
/**
638643
* Instantly teleports the player to the specified location.
639644
* @param newPosition The player's new position.
640-
* @param updateRegion Whether or not to update the player's map region in the game client.
645+
* @param updateRegion Whether or not to sync the player's map region with their client. Defaults to true.
641646
*/
642647
public teleport(newPosition: Position, updateRegion: boolean = true): void {
643648
this.walkingQueue.clear();
644-
this.metadata['lastPosition'] = this.position;
649+
const originalPosition = this.position.copy();
650+
this.metadata['lastPosition'] = originalPosition;
645651
this.position = newPosition;
646652
this.metadata['teleporting'] = true;
647653

648-
if(updateRegion) {
649-
this.updateFlags.mapRegionUpdateRequired = true;
650-
this.lastMapRegionUpdatePosition = newPosition;
654+
this.updateFlags.mapRegionUpdateRequired = updateRegion;
655+
this.lastMapRegionUpdatePosition = newPosition;
651656

652-
const originalPosition = this.position;
653-
const oldChunk = world.chunkManager.getChunkForWorldPosition(originalPosition);
654-
const newChunk = world.chunkManager.getChunkForWorldPosition(newPosition);
657+
const oldChunk = world.chunkManager.getChunkForWorldPosition(originalPosition);
658+
const newChunk = world.chunkManager.getChunkForWorldPosition(newPosition);
655659

656-
if(!oldChunk.equals(newChunk)) {
657-
this.metadata['updateChunk'] = { newChunk, oldChunk };
660+
if(!oldChunk.equals(newChunk)) {
661+
this.metadata['updateChunk'] = { newChunk, oldChunk };
658662

663+
if(updateRegion) {
659664
this.actionPipeline.call('region_change', regionChangeActionFactory(
660665
this, originalPosition, newPosition, true));
661666
}

src/game-engine/world/map/region.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* map: 64x64 tile (13x13 tile chunks) full map region file.
44
* chunk: 8x8 tile chunk within a map.
55
*/
6+
import { Position } from '@engine/world/position';
7+
68
export type RegionType = 'map' | 'chunk';
79

810
/**
@@ -19,3 +21,9 @@ export const regionSizes: RegionSizeMap = {
1921
'map': 64,
2022
'chunk': 8
2123
};
24+
25+
26+
export interface ConstructedMap {
27+
position: Position;
28+
tileData: number[][][];
29+
}

src/plugins/skills/construction/construction.plugin.ts

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { PlayerInitAction, playerInitActionHandler } from '@engine/world/action/
55
import { World } from '@engine/world';
66
import { world } from '@engine/game-server';
77
import { schedule } from '@engine/world/task';
8+
import { ConstructedMap } from '@engine/world/map/region';
89

910

1011
const MAX_HOUSE_SIZE = 13;
@@ -82,26 +83,18 @@ class House {
8283
}
8384

8485

85-
const instance1 = new Position(6296, 6296);
86-
const instance1PohSpawn = new Position(6296 + 52, 6296 + 52);
87-
const instance1Max = new Position(6296 + 104, 6296 + 104);
86+
const instance1 = new Position(6400, 6400);
87+
const instance1PohSpawn = new Position(6432, 6432);
88+
const instance1Max = new Position(6464, 6464);
8889

89-
const instance2 = new Position(6192, 6296);
90-
const instance2PohSpawn = new Position(6192 + 52, 6296 + 52);
91-
const instance2Max = new Position(6192 + 104, 6296 + 104);
90+
const instance2 = new Position(6464, 6400);
91+
const instance2PohSpawn = new Position(6496, 6432);
92+
const instance2Max = new Position(6528, 6464);
9293

9394

9495
const openHouse = async (player: Player): Promise<void> => {
95-
if(player.position.within(instance1, instance1Max, false)) {
96-
player.teleport(instance1PohSpawn);
97-
} else if(player.position.within(instance2, instance2Max, false)) {
98-
player.teleport(instance2PohSpawn);
99-
} else {
100-
player.teleport(instance1PohSpawn);
101-
}
102-
103-
10496
player.sendMessage(player.position.key);
97+
player.sendMessage(`${player.position.chunkLocalX},${player.position.chunkLocalY}`);
10598

10699
const house = new House();
107100

@@ -111,7 +104,7 @@ const openHouse = async (player: Player): Promise<void> => {
111104

112105
for(let x = 0; x < MAX_HOUSE_SIZE; x++) {
113106
for(let y = 0; y < MAX_HOUSE_SIZE; y++) {
114-
if(x <= 1 || y <= 1 || x >= 10 || y >= 10) {
107+
if(x <= 1 || y <= 1 || x >= 11 || y >= 11) {
115108
continue;
116109
}
117110

@@ -125,7 +118,24 @@ const openHouse = async (player: Player): Promise<void> => {
125118
}
126119
}
127120

128-
player.metadata.customMap = house.getRoomData();
121+
let pohPosition: Position = instance1PohSpawn;
122+
123+
if(player.position.within(instance1, instance1Max, false)) {
124+
player.teleport(player.position.copy().setX(player.position.x + 64));
125+
pohPosition = instance2PohSpawn;
126+
} else if(player.position.within(instance2, instance2Max, false)) {
127+
player.teleport(player.position.copy().setX(player.position.x - 64));
128+
} else {
129+
player.teleport(instance1PohSpawn);
130+
}
131+
132+
player.sendMessage(player.position.key);
133+
player.sendMessage(`${player.position.chunkLocalX},${player.position.chunkLocalY}`);
134+
135+
player.metadata.customMap = {
136+
position: pohPosition,
137+
tileData: house.getRoomData()
138+
} as ConstructedMap;
129139

130140
player.sendMessage(`Welcome home.`);
131141
};
@@ -145,6 +155,14 @@ export default {
145155
openHouse(player);
146156
}
147157
},
158+
{
159+
type: 'player_command',
160+
commands: [ 'local' ],
161+
handler: ({ player }: PlayerCommandAction): void => {
162+
player.sendMessage(player.position.key);
163+
player.sendMessage(`${player.position.chunkLocalX},${player.position.chunkLocalY}`);
164+
}
165+
},
148166
{
149167
type: 'player_init',
150168
handler: ({ player }: PlayerInitAction): void => {

0 commit comments

Comments
 (0)