@rpgjs/server 5.0.0-alpha.30 → 5.0.0-alpha.31
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.
- package/dist/Player/ParameterManager.d.ts +7 -6
- package/dist/Player/Player.d.ts +2 -0
- package/dist/index.js +69 -23
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/Player/MoveManager.ts +11 -7
- package/src/Player/ParameterManager.ts +22 -17
- package/src/Player/Player.ts +33 -16
- package/src/rooms/lobby.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpgjs/server",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.31",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"publishConfig": {
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"description": "",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@rpgjs/common": "5.0.0-alpha.
|
|
15
|
-
"@rpgjs/physic": "5.0.0-alpha.
|
|
16
|
-
"@rpgjs/testing": "5.0.0-alpha.
|
|
14
|
+
"@rpgjs/common": "5.0.0-alpha.31",
|
|
15
|
+
"@rpgjs/physic": "5.0.0-alpha.31",
|
|
16
|
+
"@rpgjs/testing": "5.0.0-alpha.31",
|
|
17
17
|
"@rpgjs/database": "^4.3.0",
|
|
18
18
|
"@signe/di": "^2.8.2",
|
|
19
19
|
"@signe/reactive": "^2.8.2",
|
|
@@ -744,7 +744,8 @@ export function WithMoveManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
744
744
|
* Move toward a target player or position using AI pathfinding
|
|
745
745
|
*
|
|
746
746
|
* Uses the `SeekAvoid` strategy to navigate toward the target while avoiding obstacles.
|
|
747
|
-
* The movement speed is based on the player's current `speed`
|
|
747
|
+
* The movement speed is based on the player's current `speed` and `frequency` settings,
|
|
748
|
+
* scaled appropriately.
|
|
748
749
|
*
|
|
749
750
|
* @param target - Target player or position `{ x, y }` to move toward
|
|
750
751
|
*
|
|
@@ -764,10 +765,14 @@ export function WithMoveManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
764
765
|
const playerId = (this as unknown as PlayerWithMixins).id;
|
|
765
766
|
const engine = map.physic;
|
|
766
767
|
|
|
767
|
-
// Calculate maxSpeed based on player's speed
|
|
768
|
+
// Calculate maxSpeed based on player's speed and frequency
|
|
768
769
|
// Original values: 180 for player target, 80 for position target (with default speed=4)
|
|
769
770
|
// Factor: 45 for player (180/4), 20 for position (80/4)
|
|
770
771
|
const playerSpeed = (this as any).speed();
|
|
772
|
+
const rawFrequency = (this as any).frequency;
|
|
773
|
+
const playerFrequency = typeof rawFrequency === 'function' ? rawFrequency() : rawFrequency;
|
|
774
|
+
const frequencyScale = playerFrequency > 0 ? Frequency.High / playerFrequency : 1;
|
|
775
|
+
const normalizedFrequencyScale = Number.isFinite(frequencyScale) && frequencyScale > 0 ? frequencyScale : 1;
|
|
771
776
|
|
|
772
777
|
// Remove ALL movement strategies that could interfere with SeekAvoid
|
|
773
778
|
// This includes SeekAvoid, Dash, Knockback, and LinearRepulsion
|
|
@@ -789,7 +794,7 @@ export function WithMoveManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
789
794
|
return body;
|
|
790
795
|
};
|
|
791
796
|
// Factor 45: with speed=4 gives 180 (original value)
|
|
792
|
-
const maxSpeed = playerSpeed * 45;
|
|
797
|
+
const maxSpeed = playerSpeed * 45 * normalizedFrequencyScale;
|
|
793
798
|
map.moveManager.add(
|
|
794
799
|
playerId,
|
|
795
800
|
new SeekAvoid(engine, targetProvider, maxSpeed, 140, 80, 48)
|
|
@@ -804,7 +809,7 @@ export function WithMoveManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
804
809
|
staticTarget.freeze();
|
|
805
810
|
|
|
806
811
|
// Factor 20: with speed=4 gives 80 (original value)
|
|
807
|
-
const maxSpeed = playerSpeed * 20;
|
|
812
|
+
const maxSpeed = playerSpeed * 20 * normalizedFrequencyScale;
|
|
808
813
|
map.moveManager.add(
|
|
809
814
|
playerId,
|
|
810
815
|
new SeekAvoid(engine, () => staticTarget, maxSpeed, 140, 80, 48)
|
|
@@ -920,8 +925,8 @@ export function WithMoveManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
920
925
|
this.getActiveMovements().some(s => s instanceof Knockback || s instanceof AdditiveKnockback);
|
|
921
926
|
|
|
922
927
|
const setAnimationName = (name: string): void => {
|
|
923
|
-
if (typeof selfAny.
|
|
924
|
-
selfAny.
|
|
928
|
+
if (typeof selfAny.setGraphicAnimation === 'function') {
|
|
929
|
+
selfAny.setGraphicAnimation(name);
|
|
925
930
|
return;
|
|
926
931
|
}
|
|
927
932
|
const animSignal = selfAny.animationName;
|
|
@@ -1948,4 +1953,3 @@ export interface IMoveManager {
|
|
|
1948
1953
|
*/
|
|
1949
1954
|
replayRoutes(): void;
|
|
1950
1955
|
}
|
|
1951
|
-
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { isString, PlayerCtor } from "@rpgjs/common";
|
|
2
2
|
import { signal, computed, WritableSignal, ComputedSignal } from "@signe/reactive";
|
|
3
3
|
import { MAXHP, MAXSP } from "@rpgjs/common";
|
|
4
|
-
import {
|
|
4
|
+
import { type } from "@signe/sync";
|
|
5
|
+
|
|
6
|
+
export type ExpCurve = {
|
|
7
|
+
basis: number;
|
|
8
|
+
extra: number;
|
|
9
|
+
accelerationA: number;
|
|
10
|
+
accelerationB: number;
|
|
11
|
+
};
|
|
5
12
|
|
|
6
13
|
/**
|
|
7
14
|
* Interface for Parameter Manager functionality
|
|
@@ -53,12 +60,7 @@ export interface IParameterManager {
|
|
|
53
60
|
* ```
|
|
54
61
|
* @memberof ParameterManager
|
|
55
62
|
* */
|
|
56
|
-
expCurve:
|
|
57
|
-
basis: number,
|
|
58
|
-
extra: number,
|
|
59
|
-
accelerationA: number
|
|
60
|
-
accelerationB: number
|
|
61
|
-
};
|
|
63
|
+
expCurve: ExpCurve;
|
|
62
64
|
|
|
63
65
|
/**
|
|
64
66
|
* Changes the health points
|
|
@@ -393,12 +395,12 @@ export function WithParameterManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
393
395
|
* console.log(player.param[MAXHP]); // Updated value
|
|
394
396
|
* ```
|
|
395
397
|
*/
|
|
396
|
-
private _paramsModifierSignal = signal<{
|
|
398
|
+
private _paramsModifierSignal = type(signal<{
|
|
397
399
|
[key: string]: {
|
|
398
400
|
value?: number,
|
|
399
401
|
rate?: number
|
|
400
402
|
}
|
|
401
|
-
}>({})
|
|
403
|
+
}>({}) as any, '_paramsModifierSignal', { persist: true }, this as any)
|
|
402
404
|
|
|
403
405
|
/**
|
|
404
406
|
* Signal for base parameters configuration
|
|
@@ -406,12 +408,12 @@ export function WithParameterManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
406
408
|
* Stores the start and end values for each parameter's level curve.
|
|
407
409
|
* Changes to this signal trigger recalculation of all parameter values.
|
|
408
410
|
*/
|
|
409
|
-
private _parametersSignal = signal<{
|
|
411
|
+
private _parametersSignal = type(signal<{
|
|
410
412
|
[key: string]: {
|
|
411
413
|
start: number,
|
|
412
414
|
end: number
|
|
413
415
|
}
|
|
414
|
-
}>({})
|
|
416
|
+
}>({}) as any, '_parametersSignal', { persist: true }, this as any)
|
|
415
417
|
|
|
416
418
|
/**
|
|
417
419
|
* Computed signal for all parameter values
|
|
@@ -548,11 +550,14 @@ export function WithParameterManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
548
550
|
* ```
|
|
549
551
|
* @memberof ParameterManager
|
|
550
552
|
* */
|
|
551
|
-
public
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
553
|
+
public _expCurveSignal = type(signal<string>('') as any, '_expCurveSignal', { persist: true }, this as any)
|
|
554
|
+
|
|
555
|
+
get expCurve(): ExpCurve {
|
|
556
|
+
return JSON.parse(this._expCurveSignal())
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
set expCurve(val: ExpCurve) {
|
|
560
|
+
this._expCurveSignal.set(JSON.stringify(val))
|
|
556
561
|
}
|
|
557
562
|
|
|
558
563
|
/**
|
|
@@ -903,4 +908,4 @@ export function WithParameterManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
903
908
|
this.recovery({ hp: 1, sp: 1 })
|
|
904
909
|
}
|
|
905
910
|
} as unknown as TBase;
|
|
906
|
-
}
|
|
911
|
+
}
|
package/src/Player/Player.ts
CHANGED
|
@@ -186,21 +186,6 @@ export class RpgPlayer extends BasicPlayerMixins(RpgCommonPlayer) {
|
|
|
186
186
|
|
|
187
187
|
constructor() {
|
|
188
188
|
super();
|
|
189
|
-
// Use type assertion to access mixin properties
|
|
190
|
-
(this as any).expCurve = {
|
|
191
|
-
basis: 30,
|
|
192
|
-
extra: 20,
|
|
193
|
-
accelerationA: 30,
|
|
194
|
-
accelerationB: 30
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
(this as any).addParameter(MAXHP, MAXHP_CURVE);
|
|
198
|
-
(this as any).addParameter(MAXSP, MAXSP_CURVE);
|
|
199
|
-
(this as any).addParameter(STR, STR_CURVE);
|
|
200
|
-
(this as any).addParameter(INT, INT_CURVE);
|
|
201
|
-
(this as any).addParameter(DEX, DEX_CURVE);
|
|
202
|
-
(this as any).addParameter(AGI, AGI_CURVE);
|
|
203
|
-
(this as any).allRecovery();
|
|
204
189
|
|
|
205
190
|
let lastEmitted: { x: number; y: number } | null = null;
|
|
206
191
|
let pendingUpdate: { x: number; y: number } | null = null;
|
|
@@ -238,6 +223,24 @@ export class RpgPlayer extends BasicPlayerMixins(RpgCommonPlayer) {
|
|
|
238
223
|
this.hooks.callHooks("server-playerProps-load", this).subscribe();
|
|
239
224
|
}
|
|
240
225
|
|
|
226
|
+
onGameStart() {
|
|
227
|
+
// Use type assertion to access mixin properties
|
|
228
|
+
(this as any).expCurve = {
|
|
229
|
+
basis: 30,
|
|
230
|
+
extra: 20,
|
|
231
|
+
accelerationA: 30,
|
|
232
|
+
accelerationB: 30
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
;(this as any).addParameter(MAXHP, MAXHP_CURVE);
|
|
236
|
+
(this as any).addParameter(MAXSP, MAXSP_CURVE);
|
|
237
|
+
(this as any).addParameter(STR, STR_CURVE);
|
|
238
|
+
(this as any).addParameter(INT, INT_CURVE);
|
|
239
|
+
(this as any).addParameter(DEX, DEX_CURVE);
|
|
240
|
+
(this as any).addParameter(AGI, AGI_CURVE);
|
|
241
|
+
(this as any).allRecovery();
|
|
242
|
+
}
|
|
243
|
+
|
|
241
244
|
get hooks() {
|
|
242
245
|
return inject<Hooks>(this.context as any, ModulesToken);
|
|
243
246
|
}
|
|
@@ -415,7 +418,12 @@ export class RpgPlayer extends BasicPlayerMixins(RpgCommonPlayer) {
|
|
|
415
418
|
}
|
|
416
419
|
|
|
417
420
|
snapshot() {
|
|
418
|
-
|
|
421
|
+
const snapshot = createStatesSnapshotDeep(this);
|
|
422
|
+
const expCurve = (this as any).expCurve;
|
|
423
|
+
if (expCurve) {
|
|
424
|
+
snapshot.expCurve = { ...expCurve };
|
|
425
|
+
}
|
|
426
|
+
return snapshot;
|
|
419
427
|
}
|
|
420
428
|
|
|
421
429
|
async applySnapshot(snapshot: string | object) {
|
|
@@ -426,6 +434,9 @@ export class RpgPlayer extends BasicPlayerMixins(RpgCommonPlayer) {
|
|
|
426
434
|
const withClass = (this as any).resolveClassSnapshot?.(withStates) ?? withStates;
|
|
427
435
|
const resolvedSnapshot = (this as any).resolveEquipmentsSnapshot?.(withClass) ?? withClass;
|
|
428
436
|
load(this, resolvedSnapshot);
|
|
437
|
+
if (resolvedSnapshot.expCurve) {
|
|
438
|
+
(this as any).expCurve = resolvedSnapshot.expCurve;
|
|
439
|
+
}
|
|
429
440
|
if (Array.isArray(resolvedSnapshot.items)) {
|
|
430
441
|
this.items.set(resolvedSnapshot.items);
|
|
431
442
|
}
|
|
@@ -1258,6 +1269,12 @@ export class RpgPlayer extends BasicPlayerMixins(RpgCommonPlayer) {
|
|
|
1258
1269
|
}
|
|
1259
1270
|
|
|
1260
1271
|
export class RpgEvent extends RpgPlayer {
|
|
1272
|
+
|
|
1273
|
+
constructor() {
|
|
1274
|
+
super();
|
|
1275
|
+
this.onGameStart()
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1261
1278
|
override async execMethod(methodName: string, methodData: any[] = [], instance = this) {
|
|
1262
1279
|
await lastValueFrom(this.hooks
|
|
1263
1280
|
.callHooks(`server-event-${methodName}`, instance, ...methodData));
|
package/src/rooms/lobby.ts
CHANGED
|
@@ -35,6 +35,7 @@ export class LobbyRoom extends BaseRoom {
|
|
|
35
35
|
async guiInteraction(player: RpgPlayer, value: { guiId: string, name: string, data: any }) {
|
|
36
36
|
const id = value.data.id
|
|
37
37
|
if (id === 'start') {
|
|
38
|
+
player.onGameStart();
|
|
38
39
|
this.hooks.callHooks("server-player-onStart", player).subscribe();
|
|
39
40
|
}
|
|
40
41
|
}
|