1
1
import { Position } from '@engine/world/position' ;
2
2
import { Player } from '@engine/world/actor/player/player' ;
3
3
import { PlayerCommandAction } from '@engine/world/action/player-command.action' ;
4
- import { PlayerInitAction , playerInitActionHandler } from '@engine/world/action/player-init.action' ;
5
- import { World } from '@engine/world' ;
6
- import { world } from '@engine/game-server' ;
7
- import { schedule } from '@engine/world/task' ;
4
+ import { PlayerInitAction } from '@engine/world/action/player-init.action' ;
8
5
import { ConstructedMap } from '@engine/world/map/region' ;
9
6
7
+ import { instance1 , instance1Max , instance1PohSpawn , instance2 , instance2Max , MAP_SIZE } from './con-constants' ;
8
+ import { House , Room } from './con-house' ;
10
9
11
- const MAX_HOUSE_SIZE = 13 ;
12
-
13
-
14
- type RoomType = 'empty' | 'empty_grass' | 'garden_1' | 'garden_2' | 'parlor' ;
15
-
16
-
17
- type RoomTemplateMap = {
18
- [ key in RoomType ] : Position ;
19
- }
20
-
21
-
22
- const roomTemplates : RoomTemplateMap = {
23
- empty : new Position ( 1856 , 5056 ) ,
24
- empty_grass : new Position ( 1864 , 5056 ) ,
25
- garden_1 : new Position ( 1856 , 5064 ) ,
26
- garden_2 : new Position ( 1872 , 5064 ) ,
27
- parlor : new Position ( 1856 , 5112 ) ,
28
- } ;
29
-
30
-
31
- class Room {
32
-
33
- public readonly type : RoomType ;
34
-
35
- public orientation : number ;
36
-
37
- public constructor ( type : RoomType , orientation : number = 0 ) {
38
- this . type = type ;
39
- this . orientation = orientation ;
40
- }
41
-
42
- public get roomData ( ) : number {
43
- const { x, y, level } = roomTemplates [ this . type ] ;
44
- return x / 8 << 14 | y / 8 << 3 | level % 4 << 24 | this . orientation % 4 << 1 ;
45
- }
46
-
47
- }
48
-
49
-
50
- class House {
51
-
52
- public readonly rooms : Room [ ] [ ] [ ] ;
53
-
54
- public constructor ( ) {
55
- this . rooms = new Array ( 4 ) ;
56
- for ( let level = 0 ; level < 4 ; level ++ ) {
57
- this . rooms [ level ] = new Array ( MAX_HOUSE_SIZE ) ;
58
- for ( let x = 0 ; x < MAX_HOUSE_SIZE ; x ++ ) {
59
- this . rooms [ level ] [ x ] = new Array ( MAX_HOUSE_SIZE ) . fill ( null ) ;
60
- }
61
- }
62
- }
63
-
64
- public getRoomData ( ) : number [ ] [ ] [ ] {
65
- const roomData = new Array ( 4 ) ;
66
- for ( let level = 0 ; level < 4 ; level ++ ) {
67
- roomData [ level ] = new Array ( MAX_HOUSE_SIZE ) ;
68
- for ( let x = 0 ; x < MAX_HOUSE_SIZE ; x ++ ) {
69
- roomData [ level ] [ x ] = new Array ( MAX_HOUSE_SIZE ) ;
70
- for ( let y = 0 ; y < MAX_HOUSE_SIZE ; y ++ ) {
71
- roomData [ level ] [ x ] [ y ] = this . rooms [ level ] [ x ] [ y ] ?. roomData || null ;
72
- }
73
- }
74
- }
75
-
76
- return roomData ;
77
- }
78
-
79
- public getRoom ( position : Position ) : Room {
80
- return this . rooms [ position . level ] [ position . x ] [ position . y ] ;
81
- }
82
-
83
- }
84
-
85
-
86
- const instance1 = new Position ( 6400 , 6400 ) ;
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 ) ;
93
-
94
-
95
-
96
- const openHouse = async ( player : Player ) : Promise < void > => {
97
- player . sendMessage ( player . position . key ) ;
98
- player . sendMessage ( `${ player . position . chunkLocalX } ,${ player . position . chunkLocalY } ` ) ;
99
10
11
+ const openHouse = ( player : Player ) : void => {
100
12
const house = new House ( ) ;
101
13
102
14
const gardenPortal = new Room ( 'garden_1' ) ;
103
15
const firstParlor = new Room ( 'parlor' ) ;
104
16
const emptySpace = new Room ( 'empty_grass' ) ;
105
17
106
- for ( let x = 0 ; x < MAX_HOUSE_SIZE ; x ++ ) {
107
- for ( let y = 0 ; y < MAX_HOUSE_SIZE ; y ++ ) {
18
+ for ( let x = 0 ; x < MAP_SIZE ; x ++ ) {
19
+ for ( let y = 0 ; y < MAP_SIZE ; y ++ ) {
108
20
if ( x === 6 && y === 6 ) {
109
21
house . rooms [ 0 ] [ x ] [ y ] = gardenPortal ;
110
22
} else if ( ( x === 7 && y === 6 ) || ( x === 6 && y === 7 ) || ( x === 5 && y === 6 ) ) {
@@ -131,40 +43,29 @@ const openHouse = async (player: Player): Promise<void> => {
131
43
tileData : house . getRoomData ( )
132
44
} as ConstructedMap ;
133
45
134
- player . sendMessage ( player . position . key ) ;
135
- player . sendMessage ( `${ player . position . chunkLocalX } ,${ player . position . chunkLocalY } ` ) ;
136
-
137
46
player . sendMessage ( `Welcome home.` ) ;
138
47
} ;
139
48
140
49
141
- const playerInitHomeCheck = async ( player : Player ) : Promise < void > =>
142
- await openHouse ( player ) ;
50
+ const playerInitHomeCheck = ( player : Player ) : void => {
51
+ if ( player . position . within ( instance1 , instance1Max , false ) ||
52
+ player . position . within ( instance2 , instance2Max , false ) ) {
53
+ openHouse ( player ) ;
54
+ }
55
+ } ;
143
56
144
57
145
58
export default {
146
59
pluginId : 'rs:construction' ,
147
60
hooks : [
148
61
{
149
62
type : 'player_command' ,
150
- commands : [ 'con' ] ,
151
- handler : ( { player } : PlayerCommandAction ) : void => {
152
- openHouse ( player ) ;
153
- }
154
- } ,
155
- {
156
- type : 'player_command' ,
157
- commands : [ 'local' ] ,
158
- handler : ( { player } : PlayerCommandAction ) : void => {
159
- player . sendMessage ( player . position . key ) ;
160
- player . sendMessage ( `${ player . position . chunkLocalX } ,${ player . position . chunkLocalY } ` ) ;
161
- }
63
+ commands : [ 'con' , 'poh' , 'house' ] ,
64
+ handler : ( { player } : PlayerCommandAction ) : void => openHouse ( player )
162
65
} ,
163
66
{
164
67
type : 'player_init' ,
165
- handler : ( { player } : PlayerInitAction ) : void => {
166
- playerInitHomeCheck ( player ) ;
167
- }
68
+ handler : ( { player } : PlayerInitAction ) : void => playerInitHomeCheck ( player )
168
69
}
169
70
]
170
71
} ;
0 commit comments