Skip to content

Commit 66225ab

Browse files
authored
Merge pull request #314 from runejs/feature/construction
Construction: Adding new rooms + house saving/loading
2 parents 8d4fce9 + 50ade19 commit 66225ab

File tree

16 files changed

+551
-197
lines changed

16 files changed

+551
-197
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ node_modules
22
.DS_Store
33
/dist
44
/data/dump
5+
/data/houses
56
/data/saves/*.json
67
/data/config/server-config.yaml
78

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
"main": "dist/index.js",
66
"scripts": {
77
"start": "npm run build && concurrently \"npm run build:watch\" \"npm run start:infra\" \"npm run start:game\"",
8-
"start:game": "nodemon --delay 5000ms --max-old-space-size=2048 dist/index.js",
8+
"start:game": "nodemon --delay 5000ms --max-old-space-size=2048 dist/main.js",
99
"start:game:dev": "npm run build && concurrently \"npm run build:watch\" \"npm run start:game\"",
1010
"start:login": "node --max-old-space-size=1024 dist/game-engine/login-server.js",
1111
"start:update": "node --max-old-space-size=1024 dist/game-engine/update-server.js",
1212
"start:infra": "concurrently \"npm run start:update\" \"npm run start:login\"",
1313
"start:standalone": "concurrently \"npm run start:infra\" \"npm run start:game\"",
1414
"lint": "eslint -c .eslintrc.js --ext .ts src",
15-
"lint-fix": "eslint -c .eslintrc.js --ext .ts src --fix",
16-
"fake-players": "concurrently \"npm run build:watch\" \"node --max-old-space-size=4096 dist/index.js -fakePlayers\"",
17-
"fake-players-tick": "concurrently \"npm run build:watch\" \"node --max-old-space-size=4096 dist/index.js -fakePlayers -tickTime\"",
15+
"lint:fix": "eslint -c .eslintrc.js --ext .ts src --fix",
1816
"build:watch": "babel ./src --out-dir dist --extensions \".ts,.tsx,.js\" --source-maps --watch",
1917
"build": "rimraf dist && babel ./src --out-dir dist --extensions \".ts,.tsx,.js\" --source-maps"
2018
},

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,22 @@ export class OutboundPackets {
7171
//packet - 129 - freezes client?
7272
//packet - 202 - directly to login screen
7373

74-
public sendProjectile(position: Position, offsetX: number, offsetY: number, id: number, startHeight: number, endHeight: number, speed: number, lockon: number, delay: number) {
75-
this.updateReferencePosition(position);
76-
77-
const packet = new Packet(1);
78-
packet.put(0);
79-
packet.put(offsetY, 'byte');
80-
packet.put(offsetX, 'byte');
81-
packet.put(lockon, 'SHORT', 'BIG_ENDIAN');
82-
packet.put(id, 'SHORT', 'BIG_ENDIAN');
83-
packet.put(startHeight);
84-
packet.put(endHeight);
85-
packet.put(delay, 'SHORT', 'BIG_ENDIAN');
86-
packet.put(speed, 'SHORT', 'BIG_ENDIAN');
87-
packet.put(16);
88-
packet.put(64);
89-
this.queue(packet);
74+
public sendProjectile(position: Position, offsetX: number, offsetY: number, id: number, startHeight: number, endHeight: number, speed: number, lockon: number, delay: number) {
75+
this.updateReferencePosition(position);
76+
77+
const packet = new Packet(1);
78+
packet.put(0);
79+
packet.put(offsetY, 'byte');
80+
packet.put(offsetX, 'byte');
81+
packet.put(lockon, 'SHORT', 'BIG_ENDIAN');
82+
packet.put(id, 'SHORT', 'BIG_ENDIAN');
83+
packet.put(startHeight);
84+
packet.put(endHeight);
85+
packet.put(delay, 'SHORT', 'BIG_ENDIAN');
86+
packet.put(speed, 'SHORT', 'BIG_ENDIAN');
87+
packet.put(16);
88+
packet.put(64);
89+
this.queue(packet);
9090
}
9191
public updateFriendStatus(friendName: string, worldId: number): void {
9292
const packet = new Packet(156);
@@ -630,11 +630,11 @@ export class OutboundPackets {
630630
const constructedChunk: ConstructedChunk | null = mapData.chunks[level][mapTileOffsetX][mapTileOffsetY];
631631
packet.putBits(1, constructedChunk === null ? 0 : 1)
632632
if (constructedChunk !== null) {
633-
const { templatePosition, rotation } = constructedChunk;
633+
const { templatePosition, orientation } = constructedChunk;
634634
packet.putBits(2, templatePosition?.level & 0x3);
635635
packet.putBits(10, templatePosition?.x / 8);
636636
packet.putBits(11, templatePosition?.y / 8);
637-
packet.putBits(2, rotation || 0);
637+
packet.putBits(2, orientation || 0);
638638
packet.putBits(1, 0); // unused
639639
}
640640
}

src/game-engine/plugins/content-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export async function loadPluginFiles(): Promise<ContentPlugin[]> {
2424
const relativeDir = join('..', '..', 'plugins');
2525
const plugins: ContentPlugin[] = [];
2626

27-
for await(const path of getFiles(pluginDir, { type: 'whitelist', list: ['.plugin.js'] })) {
27+
for await(const path of getFiles(pluginDir, { type: 'whitelist', list: ['.plugin.js', 'index.js'] })) {
2828
const location = join(relativeDir, path.substring(pluginDir.length).replace('.js', ''));
2929

3030
try {

src/game-engine/world/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export class World {
171171

172172
const tileX = objectTile.templatePosition.x;
173173
const tileY = objectTile.templatePosition.y;
174-
const tileOrientation = objectTile.rotation;
174+
const tileOrientation = objectTile.orientation;
175175

176176
const objectLocalX = objectPosition.x - (objectChunk.position.x + 6) * 8;
177177
const objectLocalY = objectPosition.y - (objectChunk.position.y + 6) * 8;
@@ -197,7 +197,7 @@ export class World {
197197
realObject.y = objectPosition.y;
198198
realObject.level = objectPosition.level;
199199

200-
let rotation = realObject.orientation + objectTile.rotation;
200+
let rotation = realObject.orientation + objectTile.orientation;
201201
if(rotation > 3) {
202202
rotation -= 4;
203203
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* chunk: 8x8 tile chunk within a map.
55
*/
66
import { Position } from '@engine/world/position';
7-
import { Room } from '@plugins/skills/construction/con-house';
7+
import { Room } from '@plugins/skills/construction/house';
88

99

1010
export type RegionType = 'mapfile' | 'region' | 'chunk';
@@ -28,10 +28,10 @@ export const regionSizes: RegionSizeMap = {
2828

2929
export abstract class ConstructedChunk {
3030

31-
public rotation: number;
31+
public orientation: number;
3232

3333
protected constructor(rotation: number = 0) {
34-
this.rotation = rotation;
34+
this.orientation = rotation;
3535
}
3636

3737
public abstract getTemplatePosition(): Position;

src/game-engine/world/position.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,14 @@ export class Position {
222222
return this._y - 8 * this.chunkY;
223223
}
224224

225+
public get localX(): number {
226+
return this._x - 8 * (this.chunkX + 6);
227+
}
228+
229+
public get localY(): number {
230+
return this._y - 8 * (this.chunkY + 6);
231+
}
232+
225233
public get x(): number {
226234
return this._x;
227235
}
File renamed without changes.

src/plugins/skills/construction/con-constants.ts

Lines changed: 84 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,99 @@ import { Position } from '@engine/world/position';
44
export const MAP_SIZE = 13;
55

66

7-
export type RoomType = 'empty' | 'empty_grass' | 'garden_1' | 'garden_2' | 'parlor';
7+
export type RoomType =
8+
'empty'
9+
| 'empty_grass'
10+
| 'garden'
11+
| 'formal_garden'
12+
| 'parlor'
13+
| 'kitchen'
14+
| 'dining_room'
15+
| 'bedroom'
16+
| 'skill_hall'
17+
| 'quest_hall'
18+
| 'portal_chamber'
19+
| 'combat_room'
20+
| 'games_room'
21+
| 'treasure_room'
22+
| 'chapel'
23+
| 'study'
24+
| 'throne_room'
25+
| 'workshop'
26+
| 'oubliette'
27+
| 'costume_room';
828

929

10-
export type RoomTemplateMap = {
11-
[key in RoomType]: Position;
30+
export const RoomStyle = {
31+
basic_wood: 0,
32+
basic_stone: 1,
33+
whitewashed_stone: 2,
34+
fremennik_wood: 3,
35+
tropical_wood: 4,
36+
fancy_stone: 5
1237
};
1338

14-
export const roomTemplates: RoomTemplateMap = {
15-
empty: new Position(1856, 5056),
16-
empty_grass: new Position(1864, 5056),
17-
garden_1: new Position(1856, 5064),
18-
garden_2: new Position(1872, 5064),
19-
parlor: new Position(1856, 5112),
39+
40+
/**
41+
* A map of room types to their respective world map template positions within the game.
42+
*/
43+
export const roomTemplates: { [key in RoomType]: Position } = {
44+
empty: new Position(1856, 5056),
45+
empty_grass: new Position(1864, 5056),
46+
garden: new Position(1856, 5064),
47+
formal_garden: new Position(1872, 5064),
48+
parlor: new Position(1856, 5112),
49+
kitchen: new Position(1872, 5112),
50+
dining_room: new Position(1888, 5112),
51+
bedroom: new Position(1904, 5112),
52+
skill_hall: new Position(1864, 5104),
53+
quest_hall: new Position(1912, 5104),
54+
portal_chamber: new Position(1864, 5088),
55+
combat_room: new Position(1880, 5088),
56+
games_room: new Position(1896, 5088),
57+
treasure_room: new Position(1912, 5088),
58+
chapel: new Position(1872, 5096),
59+
study: new Position(1888, 5096),
60+
throne_room: new Position(1904, 5096),
61+
workshop: new Position(1856, 5096),
62+
oubliette: new Position(1904, 5080),
63+
costume_room: new Position(1904, 5064, 0)
64+
};
65+
66+
67+
/**
68+
* A map of room builder widget button ids to their respective room types.
69+
*/
70+
export const roomBuilderButtonMap: { [key: number]: RoomType } = {
71+
160: 'parlor',
72+
161: 'garden',
73+
162: 'kitchen',
74+
163: 'dining_room',
75+
164: 'workshop',
76+
165: 'bedroom',
77+
166: 'skill_hall',
78+
167: 'games_room',
79+
168: 'combat_room',
80+
169: 'quest_hall',
81+
170: 'study',
82+
171: 'costume_room',
83+
172: 'chapel',
84+
173: 'portal_chamber',
85+
174: 'formal_garden',
86+
175: 'throne_room',
87+
176: 'oubliette',
88+
177: 'treasure_room', // @TODO dungeon corridor
89+
178: 'treasure_room', // @TODO dungeon junction
90+
179: 'treasure_room', // @TODO dungeon stair
91+
180: 'treasure_room'
2092
};
2193

2294

2395
export const instance1 = new Position(6400, 6400);
2496
export const instance1PohSpawn = new Position(6400 + 36, 6400 + 36);
2597
export const instance1Max = new Position(6400 + 64, 6400 + 64);
2698
export const instance2 = new Position(6400, 6464);
27-
export const instance2PohSpawn = new Position(6400 + 36, 6464 + 36);
99+
export const instance2PohSpawn = new Position(6400 + 36, 6464 + 36); // for reference
28100
export const instance2Max = new Position(6400 + 64, 6464 + 64);
101+
102+
// Standard home outer door ids: closed[13100, 13101], open[13102, 13103]

src/plugins/skills/construction/con-house.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)