Skip to content

Commit cad996a

Browse files
committed
Finally fixing object orientation issues with constructed map regions
1 parent 7f25e8d commit cad996a

File tree

5 files changed

+94
-64
lines changed

5 files changed

+94
-64
lines changed

src/game-engine/config/index.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ import { Quest } from '@engine/world/actor/player/quest';
1919
import { ItemSpawn, loadItemSpawnConfigurations } from '@engine/config/item-spawn-config';
2020
import { loadSkillGuideConfigurations, SkillGuide } from '@engine/config/skill-guide-config';
2121
import { loadMusicRegionConfigurations, MusicTrack } from '@engine/config/music-regions-config';
22-
import { loadXteaRegionFiles, XteaRegion } from '@runejs/filestore';
22+
import { LandscapeObject, loadXteaRegionFiles, ObjectConfig, XteaRegion } from '@runejs/filestore';
2323

2424
require('json5/lib/register');
2525

2626

2727

2828
export let itemMap: { [key: string]: ItemDetails };
2929
export let itemIdMap: { [key: number]: string };
30+
export let objectMap: { [key: number]: ObjectConfig };
3031
export let itemPresetMap: ItemPresetConfiguration;
3132
export let npcMap: { [key: string]: NpcDetails };
3233
export let npcIdMap: { [key: number]: string };
@@ -65,6 +66,9 @@ export async function loadGameConfigurations(): Promise<void> {
6566

6667
shopMap = await loadShopConfigurations('data/config/shops/');
6768
skillGuides = await loadSkillGuideConfigurations('data/config/skill-guides/');
69+
70+
objectMap = {};
71+
6872
logger.info(`Loaded ${musicRegions.length} music regions, ${Object.keys(itemMap).length} items, ${itemSpawns.length} item spawns, ` +
6973
`${Object.keys(npcMap).length} npcs, ${npcSpawns.length} npc spawns, ${Object.keys(shopMap).length} shops and ${skillGuides.length} skill guides.`);
7074
}
@@ -170,6 +174,21 @@ export const findNpc = (npcKey: number | string): NpcDetails | null => {
170174
};
171175

172176

177+
export const findObject = (objectId: number): ObjectConfig | null => {
178+
if(!objectMap[objectId]) {
179+
const object = filestore.objectStore.getObject(objectId);
180+
if(!object) {
181+
return null;
182+
}
183+
184+
objectMap[objectId] = object;
185+
return object;
186+
} else {
187+
return objectMap[objectId];
188+
}
189+
};
190+
191+
173192
export const findShop = (shopKey: string): Shop | null => {
174193
if(!shopKey) {
175194
return null;

src/game-engine/world/index.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import TravelLocations from '@engine/world/config/travel-locations';
1010
import { Actor } from '@engine/world/actor/actor';
1111
import { schedule } from '@engine/world/task';
1212
import { parseScenerySpawns } from '@engine/world/config/scenery-spawns';
13-
import { findItem, findNpc, itemSpawns, npcSpawns } from '@engine/config';
13+
import { findItem, findNpc, findObject, itemSpawns, npcSpawns } from '@engine/config';
1414
import { NpcDetails } from '@engine/config/npc-config';
1515
import { WorldInstance } from '@engine/world/instances';
1616
import { Direction } from '@engine/world/direction';
@@ -155,6 +155,12 @@ export class World {
155155
return null;
156156
}
157157

158+
const objectConfig = findObject(objectId);
159+
160+
if(!objectConfig) {
161+
return null;
162+
}
163+
158164
const objectChunk = this.chunkManager.getChunkForWorldPosition(objectPosition);
159165
const mapChunk = world.chunkManager.getChunkForWorldPosition(map.renderPosition);
160166

@@ -174,12 +180,10 @@ export class World {
174180
const mapTemplateWorldY = tileY;
175181
const mapTemplateChunk = world.chunkManager.getChunkForWorldPosition(new Position(mapTemplateWorldX, mapTemplateWorldY, objectPosition.level));
176182

177-
const templateLocalX = getTemplateLocalX(tileOrientation, objectLocalX, objectLocalY);
178-
const templateLocalY = getTemplateLocalY(tileOrientation, objectLocalX, objectLocalY);
179-
180-
if(actor instanceof Player) {
181-
actor.sendMessage(`Tile Orientation ${tileOrientation}, Local ${templateLocalX},${templateLocalY}`);
182-
}
183+
const templateLocalX = getTemplateLocalX(tileOrientation, objectLocalX, objectLocalY,
184+
objectConfig?.rendering?.sizeX || 1, objectConfig?.rendering?.sizeY || 1);
185+
const templateLocalY = getTemplateLocalY(tileOrientation, objectLocalX, objectLocalY,
186+
objectConfig?.rendering?.sizeX || 1, objectConfig?.rendering?.sizeY || 1);
183187

184188
const templateObjectPosition = new Position(mapTemplateWorldX + templateLocalX,
185189
mapTemplateWorldY + templateLocalY, objectPosition.level);
@@ -198,8 +202,6 @@ export class World {
198202
rotation -= 4;
199203
}
200204

201-
console.log(realObject.orientation, rotation);
202-
203205
realObject.orientation = rotation;
204206

205207
return realObject || null;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export class CollisionMap {
325325
occupantX -= this._insetX;
326326
occupantY -= this._insetY;
327327

328-
if(rotation == 1 || rotation == 3) {
328+
if(rotation === 1 || rotation === 3) {
329329
const off = width;
330330
width = height;
331331
height = off;

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

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -51,71 +51,87 @@ export interface ConstructedRegion {
5151

5252

5353

54-
export const getTemplateRotatedX = (orientation: number, localX: number, localY: number): number => {
54+
55+
export const getTemplateRotatedX = (orientation: number, localX: number, localY: number,
56+
sizeX: number = 1, sizeY: number = 1): number => {
57+
if(orientation === 1 || orientation === 3) {
58+
const i = sizeX;
59+
sizeX = sizeY;
60+
sizeY = i;
61+
}
62+
5563
if(orientation === 0) {
5664
return localX;
5765
}
5866
if(orientation === 1) {
59-
if(localX === 7) {
60-
return localY;
61-
} else {
62-
return 7 - localY;
63-
}
67+
return 7 - (localY - sizeY + 1);
6468
}
6569
if(orientation === 2) {
66-
if(localY === 0) {
67-
return localX;
68-
} else {
69-
return 7 - localX;
70-
}
70+
return 7 - (localX + sizeX + 1);
7171
}
7272
return localY;
7373
};
7474

75-
export const getTemplateRotatedY = (orientation: number, localX: number, localY: number): number => {
75+
export const getTemplateRotatedY = (orientation: number, localX: number, localY: number,
76+
sizeX: number = 1, sizeY: number = 1): number => {
77+
if(orientation === 1 || orientation === 3) {
78+
const i = sizeX;
79+
sizeX = sizeY;
80+
sizeY = i;
81+
}
82+
7683
if(orientation === 0) {
7784
return localY;
7885
}
7986
if(orientation === 1) {
8087
return localX;
8188
}
8289
if(orientation === 2) {
83-
return 7 - localY;
90+
return 7 - (localY + sizeY + 1);
8491
}
85-
return 7 - localX;
92+
return 7 - (localX - sizeX + 1);
8693
};
8794

8895

89-
export const getTemplateLocalX = (orientation: number, localX: number, localY: number): number => {
96+
97+
98+
99+
100+
101+
export const getTemplateLocalX = (orientation: number, localX: number, localY: number,
102+
sizeX: number = 1, sizeY: number = 1): number => {
103+
if(orientation === 2) {
104+
const i = sizeX;
105+
sizeX = sizeY;
106+
sizeY = i;
107+
}
108+
90109
if(orientation === 0) {
91110
return localX;
111+
} else if(orientation === 1) {
112+
return 7 - (localY + sizeY) + 1;
113+
} else if(orientation === 2) {
114+
return 7 - (localX + sizeX) + 1;
115+
} else { // 3
116+
return localY;
92117
}
93-
if(orientation === 1) {
94-
if(localX === 7) {
95-
return localY;
96-
} else {
97-
return 7 - localY;
98-
}
99-
}
118+
};
119+
120+
export const getTemplateLocalY = (orientation: number, localX: number, localY: number,
121+
sizeX: number = 1, sizeY: number = 1): number => {
100122
if(orientation === 2) {
101-
if(localY === 0) {
102-
return localX;
103-
} else {
104-
return 7 - localX;
105-
}
123+
const i = sizeX;
124+
sizeX = sizeY;
125+
sizeY = i;
106126
}
107-
return localY;
108-
};
109127

110-
export const getTemplateLocalY = (orientation: number, localX: number, localY: number): number => {
111128
if(orientation === 0) {
112129
return localY;
113-
}
114-
if(orientation === 1) {
130+
} else if(orientation === 1) {
115131
return localX;
132+
} else if(orientation === 2) {
133+
return 7 - (localY + sizeY) + 1;
134+
} else { // 3
135+
return 7 - (localX + sizeX) + 1;
116136
}
117-
if(orientation === 2) {
118-
return 7 - localY;
119-
}
120-
return 7 - localX;
121137
};

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

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ const openHouse = (player: Player): void => {
1414
const house = new House();
1515

1616
const gardenPortal = new Room('garden_1');
17-
const firstParlor = new Room('parlor');
18-
const secondParlor = new Room('parlor', 1);
19-
const thirdParlor = new Room('parlor', 2);
20-
const fourthParlor = new Room('parlor', 3);
17+
const parlor0 = new Room('parlor');
18+
const parlor90 = new Room('parlor', 1);
19+
const parlor180 = new Room('parlor', 2);
20+
const parlor270 = new Room('parlor', 3);
2121
const emptySpace = new Room('empty_grass');
2222

2323
for(let x = 0; x < MAP_SIZE; x++) {
2424
for(let y = 0; y < MAP_SIZE; y++) {
2525
if(x === 6 && y === 6) {
2626
house.rooms[0][x][y] = gardenPortal;
2727
} else if(x === 5 && y === 6) {
28-
house.rooms[0][x][y] = firstParlor;
28+
house.rooms[0][x][y] = parlor0;
29+
} else if(x === 6 && y === 7) {
30+
house.rooms[0][x][y] = parlor90;
2931
} else if(x === 7 && y === 6) {
30-
house.rooms[0][x][y] = secondParlor;
32+
house.rooms[0][x][y] = parlor180;
3133
} else if(x === 6 && y === 5) {
32-
house.rooms[0][x][y] = thirdParlor;
33-
} else if(x === 6 && y === 7) {
34-
house.rooms[0][x][y] = fourthParlor;
34+
house.rooms[0][x][y] = parlor270;
3535
} else {
3636
house.rooms[0][x][y] = emptySpace;
3737
}
@@ -82,23 +82,16 @@ const doorHotspot = async (objectInteraction: ObjectInteractionAction): Promise<
8282
return;
8383
}
8484

85-
const objectLocalX = position.x % 8;
86-
const objectLocalY = position.y % 8;
87-
8885
// Standard home outer door ids: closed[13100, 13101], open[13102, 13103]
8986

9087
player.personalInstance.spawnGameObject({
9188
x: position.x,
9289
y: position.y,
9390
level: position.level,
9491
orientation: object.orientation,
95-
objectId: 13103,
92+
objectId: 13100,
9693
type: object.type
9794
});
98-
99-
player.sendMessage(`Template Local = ${getTemplateRotatedX(object.orientation, objectLocalX, objectLocalY)},${getTemplateRotatedY(object.orientation, objectLocalX, objectLocalY)}`);
100-
101-
player.sendMessage(`Object Local ${objectLocalX},${objectLocalY} - rotation ${object.orientation}`);
10295
};
10396

10497

0 commit comments

Comments
 (0)