Skip to content

Commit 206aa4a

Browse files
committed
Fixing map drawing for construction thanks to Graham once again :)
1 parent 7981822 commit 206aa4a

File tree

3 files changed

+57
-21
lines changed

3 files changed

+57
-21
lines changed

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

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { LandscapeObject } from '@runejs/filestore';
1313
import { xteaRegions } from '@engine/config';
1414
import { world } from '@engine/game-server';
1515
import { ConstructedMap } from '@engine/world/map/region';
16+
import { map } from 'rxjs/operators';
1617

1718
/**
1819
* A helper class for sending various network packets back to the game client.
@@ -576,14 +577,51 @@ export class OutboundPackets {
576577

577578
packet.openBitBuffer();
578579

580+
// @TODO build around the player!
581+
// House room offsets and junk no matter where they are within the instance
582+
583+
const mapWorldX = mapData.position.x;
584+
const mapWorldY = mapData.position.y;
585+
586+
const topCornerMapChunk = world.chunkManager.getChunkForWorldPosition(new Position(mapWorldX, mapWorldY, this.player.position.level));
587+
const playerChunk = world.chunkManager.getChunkForWorldPosition(this.player.position);
588+
589+
const offsetX = playerChunk.position.x - (topCornerMapChunk.position.x - 2);
590+
const offsetY = playerChunk.position.y - (topCornerMapChunk.position.y - 2);
591+
592+
const centerChunkX = 6;
593+
const centerChunkY = 6;
594+
595+
const centerOffsetX = offsetX - centerChunkX;
596+
const centerOffsetY = offsetY - centerChunkY;
597+
598+
console.log(topCornerMapChunk.position.x, topCornerMapChunk.position.y);
599+
console.log(playerChunk.position.x, playerChunk.position.y);
600+
579601
for(let level = 0; level < 4; level++) {
580602
for(let x = 0; x < 13; x++) {
581603
for(let y = 0; y < 13; y++) {
582-
const tileData: number | null = mapData.tileData[level][x][y];
583-
packet.putBits(1, tileData === null ? 0 : 1);
604+
let mapTileOffsetX = x + centerOffsetX;
605+
let mapTileOffsetY = y + centerOffsetY;
606+
if(mapTileOffsetX < 0) {
607+
mapTileOffsetX = 0;
608+
}
609+
if(mapTileOffsetX > 12) {
610+
mapTileOffsetX = 12;
611+
}
612+
if(mapTileOffsetY < 0) {
613+
mapTileOffsetY = 0;
614+
}
615+
if(mapTileOffsetY > 12) {
616+
mapTileOffsetY = 12;
617+
}
618+
const tileData: number | null = mapData.tileData[level][mapTileOffsetX][mapTileOffsetY];
619+
packet.putBits(1, tileData === null && !mapData.emptySpace ? 0 : 1);
584620

585621
if(tileData !== null) {
586622
packet.putBits(26, tileData);
623+
} else if(mapData.emptySpace) {
624+
packet.putBits(26, mapData.emptySpace);
587625
}
588626
}
589627
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ export const regionSizes: RegionSizeMap = {
2525

2626
export interface ConstructedMap {
2727
position: Position;
28+
emptySpace?: number;
2829
tileData: number[][][];
2930
}

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,13 @@ class House {
8484

8585

8686
const instance1 = new Position(6400, 6400);
87-
const instance1PohSpawn = new Position(6432, 6432);
88-
const instance1Max = new Position(6464, 6464);
87+
const instance1PohSpawn = new Position(6400 + 36, 6400 + 36);
88+
const instance1Max = new Position(6400 + 64, 6400 + 64);
89+
90+
const instance2 = new Position(6400, 6464);
91+
const instance2PohSpawn = new Position(6400 + 36, 6464 + 36);
92+
const instance2Max = new Position(6400 + 64, 6464 + 64);
8993

90-
const instance2 = new Position(6464, 6400);
91-
const instance2PohSpawn = new Position(6496, 6432);
92-
const instance2Max = new Position(6528, 6464);
9394

9495

9596
const openHouse = async (player: Player): Promise<void> => {
@@ -104,39 +105,35 @@ const openHouse = async (player: Player): Promise<void> => {
104105

105106
for(let x = 0; x < MAX_HOUSE_SIZE; x++) {
106107
for(let y = 0; y < MAX_HOUSE_SIZE; y++) {
107-
if(x <= 1 || y <= 1 || x >= 11 || y >= 11) {
108-
continue;
109-
}
110-
111108
if(x === 6 && y === 6) {
112109
house.rooms[0][x][y] = gardenPortal;
113110
} else if((x === 7 && y === 6) || (x === 6 && y === 7) || (x === 5 && y === 6)) {
114111
house.rooms[0][x][y] = firstParlor;
115-
} else {
116-
house.rooms[0][x][y] = emptySpace;
117112
}
118113
}
119114
}
120115

121-
let pohPosition: Position = instance1PohSpawn;
116+
let pohPosition: Position = instance1;
117+
let playerSpawn: Position = instance1PohSpawn;
122118

123119
if(player.position.within(instance1, instance1Max, false)) {
124-
player.teleport(player.position.copy().setX(player.position.x + 64));
125-
pohPosition = instance2PohSpawn;
120+
playerSpawn = player.position.copy().setY(player.position.y + 64);
121+
pohPosition = instance2;
126122
} 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);
123+
playerSpawn = player.position.copy().setY(player.position.y - 64);
130124
}
131125

132-
player.sendMessage(player.position.key);
133-
player.sendMessage(`${player.position.chunkLocalX},${player.position.chunkLocalY}`);
126+
player.teleport(playerSpawn);
134127

135128
player.metadata.customMap = {
136129
position: pohPosition,
130+
emptySpace: emptySpace.roomData,
137131
tileData: house.getRoomData()
138132
} as ConstructedMap;
139133

134+
player.sendMessage(player.position.key);
135+
player.sendMessage(`${player.position.chunkLocalX},${player.position.chunkLocalY}`);
136+
140137
player.sendMessage(`Welcome home.`);
141138
};
142139

0 commit comments

Comments
 (0)