@rpgjs/common 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,318 @@
1
+ import { RpgShape } from './Shape';
2
+ import SAT from 'sat';
3
+ import { TileInfo } from './Map';
4
+ import { RpgCommonGame } from './Game';
5
+ import { Vector2d } from './Vector2d';
6
+ import { Box } from './VirtualGrid';
7
+ import { Behavior, ClientMode, Direction, MoveTo, Position, PositionXY, Tick } from '@rpgjs/types';
8
+ import { Observable } from 'rxjs';
9
+ declare type CollisionOptions = {
10
+ collision?: (event: AbstractObject) => void;
11
+ near?: (event: AbstractObject) => void;
12
+ allSearch?: boolean;
13
+ };
14
+ export declare class AbstractObject {
15
+ private gameEngine;
16
+ playerId: string;
17
+ map: string;
18
+ height: number;
19
+ width: number;
20
+ speed: number;
21
+ direction: number;
22
+ checkCollision: boolean;
23
+ clientModeMove: ClientMode;
24
+ behavior: Behavior;
25
+ hitbox: SAT.Box;
26
+ inShapes: {
27
+ [shapeId: string]: RpgShape;
28
+ };
29
+ disableVirtualGrid: boolean;
30
+ private shapes;
31
+ private _position;
32
+ private _hitboxPos;
33
+ private collisionWith;
34
+ private _collisionWithTiles;
35
+ private _collisionWithShapes;
36
+ private destroyMove$;
37
+ static get ACTIONS(): {
38
+ IDLE: number;
39
+ RUN: number;
40
+ ACTION: number;
41
+ };
42
+ constructor(gameEngine: RpgCommonGame, playerId: string);
43
+ get id(): string;
44
+ set id(str: string);
45
+ updateInVirtualGrid(): void;
46
+ get canMove(): boolean;
47
+ set canMove(val: boolean);
48
+ /**
49
+ * Get/Set position x, y and z of player
50
+ *
51
+ * z is the depth layer. By default, its value is 0. Collisions and overlays will be performed with other objects on the same z-position.
52
+ *
53
+ * @title Get/Set position
54
+ * @prop { { x: number, y: number, z: number } } position
55
+ * @memberof Player
56
+ */
57
+ set position(val: Position | Vector2d);
58
+ get position(): Vector2d;
59
+ get worldPositionX(): number;
60
+ get worldPositionY(): number;
61
+ set posX(val: any);
62
+ set posY(val: any);
63
+ set posZ(val: any);
64
+ /**
65
+ *
66
+ * Recovers all the colliding shapes of the current player
67
+ *
68
+ * @title Get Collision of shapes
69
+ * @since 3.2.0
70
+ * @readonly
71
+ * @prop { RpgShape[] } shapes
72
+ * @memberof Player
73
+ * @memberof RpgSpriteLogic
74
+ */
75
+ get shapesCollision(): RpgShape[];
76
+ /**
77
+ *
78
+ * Recovers all the colliding tiles of the current player
79
+ *
80
+ * @title Get Collision of tiles
81
+ * @since 3.0.0-beta.4
82
+ * @readonly
83
+ * @prop { TileInfo[] } tiles
84
+ * @memberof Player
85
+ * @memberof RpgSpriteLogic
86
+ */
87
+ get tilesCollision(): TileInfo[];
88
+ /**
89
+ *
90
+ * Recovers all other players and events colliding with the current player's hitbox
91
+ *
92
+ * @title Get Collision of other players/events
93
+ * @since 3.0.0-beta.4
94
+ * @readonly
95
+ * @prop { (RpgPlayer | RpgEvent)[] } otherPlayersCollision
96
+ * @memberof Player
97
+ * @memberof RpgSpriteLogic
98
+ */
99
+ get otherPlayersCollision(): AbstractObject[];
100
+ /**
101
+ * Define the size of the player. You can set the hitbox for collisions
102
+ *
103
+ * ```ts
104
+ * player.setSizes({
105
+ * width: 32,
106
+ * height: 32
107
+ * })
108
+ * ```
109
+ *
110
+ * and with hitbox:
111
+ *
112
+ * ```ts
113
+ * player.setSizes({
114
+ * width: 32,
115
+ * height: 32,
116
+ * hitbox: {
117
+ * width: 20,
118
+ * height: 20
119
+ * }
120
+ * })
121
+ * ```
122
+ *
123
+ * @title Set Sizes
124
+ * @method player.setSizes(key,value)
125
+ * @param { { width: number, height: number, hitbox?: { width: number, height: number } } } obj
126
+ * @deprecated
127
+ * @returns {void}
128
+ * @memberof Player
129
+ */
130
+ setSizes(obj: {
131
+ width: number;
132
+ height: number;
133
+ hitbox?: {
134
+ width: number;
135
+ height: number;
136
+ };
137
+ }): void;
138
+ /**
139
+ * Define the hitbox of the player.
140
+ *
141
+ * ```ts
142
+ * player.setHitbox(20, 20)
143
+ * ```
144
+ *
145
+ * @title Set Hitbox
146
+ * @method player.setHitbox(width,height)
147
+ * @param {number} width
148
+ * @param {number} height
149
+ * @returns {void}
150
+ * @memberof Player
151
+ */
152
+ setHitbox(width: number, height: number): void;
153
+ set wHitbox(val: any);
154
+ set hHitbox(val: any);
155
+ get wHitbox(): any;
156
+ get hHitbox(): any;
157
+ private directionToAngle;
158
+ /**
159
+ * Retrieves a tile and checks if the player has a collision
160
+ *
161
+ * ```ts
162
+ * const tileInfo = player.getTile(20, 30)
163
+ * console.log(tileInfo)
164
+ * ```
165
+ *
166
+ * Example of returns:
167
+ *
168
+ ```ts
169
+ {
170
+ tiles: [
171
+ {
172
+ id: 0,
173
+ terrain: [],
174
+ probability: null,
175
+ properties: [Object],
176
+ animations: [],
177
+ objectGroups: [],
178
+ image: null,
179
+ gid: 1
180
+ }
181
+ ],
182
+ hasCollision: false,
183
+ isOverlay: undefined,
184
+ objectGroups: [],
185
+ isClimbable: undefined,
186
+ tileIndex: 93
187
+ }
188
+ ```
189
+ *
190
+ * @title Get Tile
191
+ * @since 3.0.0-beta.4
192
+ * @method player.getTile(x,y,z?)
193
+ * @param {number} x
194
+ * @param {number} y
195
+ * @param {number} [z]
196
+ * @returns {object}
197
+ * @memberof Player
198
+ * @memberof RpgSpriteLogic
199
+ */
200
+ getTile(x: number, y: number, z?: number, hitbox?: SAT.Box): TileInfo;
201
+ private collisionObjects;
202
+ private collisionShapes;
203
+ computeNextPositionByTarget(nextPosition: Vector2d, target: Vector2d): Promise<Vector2d>;
204
+ isCollided(nextPosition: Vector2d, options?: CollisionOptions): Promise<boolean>;
205
+ /**
206
+ * Attach a shape to the player (and allow interaction with it)
207
+ *
208
+ * ```ts
209
+ * import { ShapePositioning } from '@rpgjs/server'
210
+ *
211
+ * player.attachShape({
212
+ * width: 100,
213
+ * height: 100,
214
+ * positioning: ShapePositioning.Center
215
+ * })
216
+ * ```
217
+ *
218
+ * @title Attach Shape
219
+ * @method player.attachShape(parameters)
220
+ * @param { { width: number, height: number, positioning?, name?, properties?: object } } obj
221
+ * - positioning: Indicate where the shape is placed.
222
+ * - properties: An object in order to retrieve information when interacting with the shape
223
+ * - name: The name of the shape
224
+ * @since 3.0.0-beta.3
225
+ * @returns {RpgShape}
226
+ * @memberof Player
227
+ */
228
+ attachShape(obj: {
229
+ width: number;
230
+ height: number;
231
+ positioning?: string;
232
+ name?: string;
233
+ properties?: object;
234
+ }): RpgShape;
235
+ /**
236
+ * Returns all shapes assigned to this player
237
+ *
238
+ * @title Get Shapes
239
+ * @method player.getShapes()
240
+ * @returns {RpgShape[]}
241
+ * @since 3.0.0-beta.3
242
+ * @memberof Player
243
+ * @memberof RpgSpriteLogic
244
+ */
245
+ getShapes(): RpgShape[];
246
+ private autoChangeDirection;
247
+ /**
248
+ * Stops the movement of the player who moves towards his target
249
+ *
250
+ * @title Stop Move To
251
+ * @method player.stopMoveTo()
252
+ * @returns {void}
253
+ * @since 3.2.0
254
+ * @memberof MoveManager
255
+ */
256
+ stopMoveTo(): void;
257
+ _moveTo(tick$: Observable<Tick>, positionTarget: AbstractObject | RpgShape | PositionXY, options?: MoveTo): Observable<Vector2d>;
258
+ /**
259
+ * Retrieves all shapes where the player is located
260
+ *
261
+ * @title Get In-Shapes
262
+ * @method player.getInShapes()
263
+ * @returns {RpgShape[]}
264
+ * @since 3.0.0-beta.3
265
+ * @memberof Player
266
+ */
267
+ getInShapes(): RpgShape[];
268
+ /**
269
+ * Get the current direction.
270
+ *
271
+ * ```ts
272
+ * player.getDirection()
273
+ * ```
274
+ *
275
+ * @title Get Direction
276
+ * @method player.getDirection()
277
+ * @returns {Direction | number} direction
278
+ * @memberof Player
279
+ */
280
+ getDirection(direction?: Direction | number): string | number;
281
+ /**
282
+ * Changes the player's direction
283
+ *
284
+ * ```ts
285
+ * import { Direction } from '@rpgjs/server'
286
+ *
287
+ * player.changeDirection(Direction.Left)
288
+ * ```
289
+ *
290
+ * @title Change direction
291
+ * @method player.changeDirection(direction)
292
+ * @param {Direction} direction
293
+ * @enum {string}
294
+ *
295
+ * Direction.Left | left
296
+ * Direction.Right | right
297
+ * Direction.Up | up
298
+ * Direction.Down | down
299
+ * @returns {boolean} the direction has changed
300
+ * @memberof Player
301
+ */
302
+ changeDirection(direction: Direction): boolean;
303
+ /**
304
+ * Gets the necessary number of pixels to allow the player to cross a tile.
305
+ * This is the ratio between the height or width of the tile and the speed of the player.
306
+ */
307
+ get nbPixelInTile(): any;
308
+ getSizeMaxShape(x?: number, y?: number): Box;
309
+ }
310
+ export interface AbstractObject {
311
+ readonly type: string;
312
+ through: boolean;
313
+ throughOtherPlayer: boolean;
314
+ autoChangeMap?(nextPosition: Position): Promise<boolean>;
315
+ execMethod(methodName: string, methodData?: any, instance?: any): any;
316
+ changeMap(mapName: string): any;
317
+ }
318
+ export {};