@rpgjs/common 5.0.0-alpha.32 → 5.0.0-alpha.35

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.
@@ -7,6 +7,7 @@ interface ItemData {
7
7
  atk: number;
8
8
  pdef: number;
9
9
  sdef: number;
10
+ icon: string;
10
11
  onAdd: (player: RpgCommonPlayer) => void;
11
12
  }
12
13
  export declare class Item {
@@ -17,6 +18,7 @@ export declare class Item {
17
18
  atk: import('@signe/reactive').WritableSignal<number>;
18
19
  pdef: import('@signe/reactive').WritableSignal<number>;
19
20
  sdef: import('@signe/reactive').WritableSignal<number>;
21
+ icon: import('@signe/reactive').WritableSignal<string>;
20
22
  quantity: import('@signe/reactive').WritableSignal<number>;
21
23
  onAdd: (player: RpgCommonPlayer) => void;
22
24
  constructor(data?: ItemData);
@@ -6,12 +6,14 @@ export interface SkillData {
6
6
  hitRate: number;
7
7
  power: number;
8
8
  coefficient: Record<string, number>;
9
+ icon: string;
9
10
  }
10
11
  export declare class Skill {
11
12
  id: import('@signe/reactive').WritableSignal<string>;
12
13
  name: import('@signe/reactive').WritableSignal<string>;
13
14
  description: import('@signe/reactive').WritableSignal<string>;
14
15
  spCost: import('@signe/reactive').WritableSignal<number>;
16
+ icon: import('@signe/reactive').WritableSignal<string>;
15
17
  hitRate: import('@signe/reactive').WritableSignal<number>;
16
18
  power: import('@signe/reactive').WritableSignal<number>;
17
19
  coefficient: import('@signe/reactive').WritableObjectSignal<{}>;
package/dist/index.d.ts CHANGED
@@ -11,3 +11,4 @@ export * from './database';
11
11
  export * from './PerlinNoise';
12
12
  export * from '@rpgjs/physic';
13
13
  export * from './Presets';
14
+ export * from './weather';
package/dist/index.js CHANGED
@@ -2506,6 +2506,7 @@ class Item {
2506
2506
  this.atk = signal(0);
2507
2507
  this.pdef = signal(0);
2508
2508
  this.sdef = signal(0);
2509
+ this.icon = signal("");
2509
2510
  this.quantity = signal(1);
2510
2511
  this.onAdd = () => {
2511
2512
  };
@@ -2515,6 +2516,7 @@ class Item {
2515
2516
  this.atk.set(data?.atk ?? 0);
2516
2517
  this.pdef.set(data?.pdef ?? 0);
2517
2518
  this.sdef.set(data?.sdef ?? 0);
2519
+ this.icon.set(data?.icon ?? "");
2518
2520
  this.onAdd = data?.onAdd?.bind(this) ?? (() => {
2519
2521
  });
2520
2522
  }
@@ -2522,6 +2524,12 @@ class Item {
2522
2524
  __decorateClass$2([
2523
2525
  id()
2524
2526
  ], Item.prototype, "id");
2527
+ __decorateClass$2([
2528
+ sync()
2529
+ ], Item.prototype, "name");
2530
+ __decorateClass$2([
2531
+ sync()
2532
+ ], Item.prototype, "icon");
2525
2533
  __decorateClass$2([
2526
2534
  sync()
2527
2535
  ], Item.prototype, "quantity");
@@ -2541,6 +2549,7 @@ class Skill {
2541
2549
  this.name = signal("");
2542
2550
  this.description = signal("");
2543
2551
  this.spCost = signal(0);
2552
+ this.icon = signal("");
2544
2553
  this.hitRate = signal(0);
2545
2554
  this.power = signal(0);
2546
2555
  this.coefficient = signal({});
@@ -2551,11 +2560,21 @@ class Skill {
2551
2560
  this.hitRate.set(data?.hitRate ?? 0);
2552
2561
  this.power.set(data?.power ?? 0);
2553
2562
  this.coefficient.set(data?.coefficient ?? {});
2563
+ this.icon.set(data?.icon ?? "");
2554
2564
  }
2555
2565
  }
2556
2566
  __decorateClass$1([
2557
2567
  id()
2558
2568
  ], Skill.prototype, "id");
2569
+ __decorateClass$1([
2570
+ sync()
2571
+ ], Skill.prototype, "name");
2572
+ __decorateClass$1([
2573
+ sync()
2574
+ ], Skill.prototype, "spCost");
2575
+ __decorateClass$1([
2576
+ sync()
2577
+ ], Skill.prototype, "icon");
2559
2578
 
2560
2579
  var __defProp = Object.defineProperty;
2561
2580
  var __decorateClass = (decorators, target, key, kind) => {
@@ -9686,8 +9705,8 @@ class PredictionController {
9686
9705
  this.lastAckFrame = 0;
9687
9706
  this.lastAckTick = 0;
9688
9707
  this.correctionThreshold = config.correctionThreshold ?? 5;
9689
- this.historyTtlMs = config.historyTtlMs ?? 2e3;
9690
- this.maxHistoryEntries = config.maxHistoryEntries ?? 200;
9708
+ this.historyTtlMs = config.historyTtlMs ?? 1e4;
9709
+ this.maxHistoryEntries = config.maxHistoryEntries ?? 1200;
9691
9710
  }
9692
9711
  recordInput(direction, timestamp) {
9693
9712
  const frame = ++this.frameCounter;
@@ -9705,6 +9724,9 @@ class PredictionController {
9705
9724
  hasPendingInputs() {
9706
9725
  return this.history.length > 0;
9707
9726
  }
9727
+ getPendingInputs() {
9728
+ return [...this.history];
9729
+ }
9708
9730
  queueServerSnapshot(snapshot) {
9709
9731
  if (this.hasPendingInputs()) {
9710
9732
  this.pendingSnapshot = snapshot;
@@ -9721,22 +9743,59 @@ class PredictionController {
9721
9743
  }
9722
9744
  applyServerAck(ack) {
9723
9745
  if (typeof ack.frame !== "number") {
9724
- return;
9746
+ const result2 = {
9747
+ acknowledgedFrame: this.lastAckFrame,
9748
+ acknowledgedTick: this.lastAckTick,
9749
+ pendingInputs: [...this.history],
9750
+ needsReconciliation: false
9751
+ };
9752
+ if (ack.state) {
9753
+ result2.state = ack.state;
9754
+ }
9755
+ return result2;
9725
9756
  }
9726
- this.lastAckFrame = Math.max(this.lastAckFrame, ack.frame);
9727
- if (typeof ack.serverTick === "number") {
9728
- this.lastAckTick = Math.max(this.lastAckTick, ack.serverTick);
9757
+ if (ack.frame < this.lastAckFrame) {
9758
+ const result2 = {
9759
+ acknowledgedFrame: this.lastAckFrame,
9760
+ acknowledgedTick: this.lastAckTick,
9761
+ pendingInputs: [...this.history],
9762
+ needsReconciliation: false
9763
+ };
9764
+ if (ack.state) {
9765
+ result2.state = ack.state;
9766
+ }
9767
+ return result2;
9729
9768
  }
9769
+ const nextAckFrame = Math.max(this.lastAckFrame, ack.frame);
9770
+ const nextAckTick = typeof ack.serverTick === "number" ? Math.max(this.lastAckTick, ack.serverTick) : this.lastAckTick;
9771
+ let needsReconciliation = false;
9772
+ if (ack.state) {
9773
+ const acknowledgedEntry = this.history.find(
9774
+ (entry) => entry.frame === nextAckFrame && !!entry.state
9775
+ );
9776
+ const comparisonState = acknowledgedEntry?.state ?? this.config.getCurrentState();
9777
+ const dx = comparisonState.x - ack.state.x;
9778
+ const dy = comparisonState.y - ack.state.y;
9779
+ const distance = Math.hypot(dx, dy);
9780
+ needsReconciliation = distance > this.correctionThreshold;
9781
+ }
9782
+ this.lastAckFrame = nextAckFrame;
9783
+ this.lastAckTick = nextAckTick;
9730
9784
  this.history = this.history.filter((entry) => entry.frame > this.lastAckFrame);
9731
- if (ack.state && !this.hasPendingInputs()) {
9732
- this.applySnapshot(ack.state);
9733
- this.pendingSnapshot = null;
9734
- return;
9735
- }
9736
- if (this.pendingSnapshot && !this.hasPendingInputs()) {
9785
+ if (!needsReconciliation && this.pendingSnapshot && !this.hasPendingInputs()) {
9737
9786
  this.applySnapshot(this.pendingSnapshot);
9738
9787
  this.pendingSnapshot = null;
9739
9788
  }
9789
+ const result = {
9790
+ acknowledgedFrame: this.lastAckFrame,
9791
+ acknowledgedTick: this.lastAckTick,
9792
+ pendingInputs: [...this.history],
9793
+ needsReconciliation
9794
+ };
9795
+ if (ack.state) {
9796
+ result.state = ack.state;
9797
+ }
9798
+ return result;
9740
9799
  }
9741
9800
  cleanup(now) {
9742
9801
  this.trimHistory(now);
@@ -10043,12 +10102,17 @@ class RpgCommonMap {
10043
10102
  }
10044
10103
  loadPhysic() {
10045
10104
  this.clearPhysic();
10046
- const hitboxes = this.data()?.hitboxes ?? [];
10047
- const gap = 100;
10048
- this.addStaticHitbox("map-width-left", -gap, 0, gap, this.data().height);
10049
- this.addStaticHitbox("map-width-right", this.data().width, 0, gap, this.data().height);
10050
- this.addStaticHitbox("map-height-top", 0, -gap, this.data().width, gap);
10051
- this.addStaticHitbox("map-height-bottom", 0, this.data().height, this.data().width, gap);
10105
+ const mapData = this.data?.();
10106
+ const mapWidth = typeof mapData?.width === "number" ? mapData.width : 0;
10107
+ const mapHeight = typeof mapData?.height === "number" ? mapData.height : 0;
10108
+ const hitboxes = Array.isArray(mapData?.hitboxes) ? mapData.hitboxes : [];
10109
+ if (mapWidth > 0 && mapHeight > 0) {
10110
+ const gap = 100;
10111
+ this.addStaticHitbox("map-width-left", -gap, 0, gap, mapHeight);
10112
+ this.addStaticHitbox("map-width-right", mapWidth, 0, gap, mapHeight);
10113
+ this.addStaticHitbox("map-height-top", 0, -gap, mapWidth, gap);
10114
+ this.addStaticHitbox("map-height-bottom", 0, mapHeight, mapWidth, gap);
10115
+ }
10052
10116
  for (let staticHitbox of hitboxes) {
10053
10117
  if ("x" in staticHitbox) {
10054
10118
  this.addStaticHitbox(staticHitbox.id ?? generateShortUUID(), staticHitbox.x, staticHitbox.y, staticHitbox.width, staticHitbox.height);
@@ -10058,13 +10122,29 @@ class RpgCommonMap {
10058
10122
  }
10059
10123
  this.playersSubscription = this.players.observable.subscribe(
10060
10124
  ({ value: player, type, key }) => {
10125
+ if (type === "remove") {
10126
+ this.removeHitbox(key);
10127
+ return;
10128
+ }
10129
+ if (type == "reset") {
10130
+ if (!player) return;
10131
+ for (let id in player) {
10132
+ const _player = player[id];
10133
+ _player.id = _player.id ?? id;
10134
+ this.createCharacterHitbox(_player, "hero");
10135
+ }
10136
+ return;
10137
+ }
10061
10138
  if (!player) return;
10062
10139
  if (type === "add") {
10063
10140
  player.id = key;
10064
10141
  this.createCharacterHitbox(player, "hero");
10065
- } else if (type === "remove") {
10066
- this.removeHitbox(key);
10067
10142
  } else if (type === "update") {
10143
+ player.id = player.id ?? key;
10144
+ if (!this.getBody(key)) {
10145
+ this.createCharacterHitbox(player, "hero");
10146
+ return;
10147
+ }
10068
10148
  if (this.isPhysicsSyncingSignals) {
10069
10149
  return;
10070
10150
  }
@@ -10085,9 +10165,41 @@ class RpgCommonMap {
10085
10165
  }
10086
10166
  this.removeHitbox(key);
10087
10167
  } else if (type === "update") {
10168
+ event.id = event.id ?? key;
10169
+ if (!this.getBody(key)) {
10170
+ this.createCharacterHitbox(event, "npc", {
10171
+ mass: 100
10172
+ });
10173
+ return;
10174
+ }
10088
10175
  this.updateCharacterHitbox(event);
10176
+ } else if (type === "reset") {
10177
+ for (const id in event) {
10178
+ const _event = event[id];
10179
+ if (!_event) continue;
10180
+ _event.id = _event.id ?? id;
10181
+ this.createCharacterHitbox(_event, "npc", {
10182
+ mass: 100
10183
+ });
10184
+ }
10089
10185
  }
10090
10186
  });
10187
+ const players = this.players();
10188
+ for (const id in players) {
10189
+ const player = players[id];
10190
+ if (!player) continue;
10191
+ player.id = player.id ?? id;
10192
+ this.createCharacterHitbox(player, "hero");
10193
+ }
10194
+ const events = this.events();
10195
+ for (const id in events) {
10196
+ const event = events[id];
10197
+ if (!event) continue;
10198
+ event.id = event.id ?? id;
10199
+ this.createCharacterHitbox(event, "npc", {
10200
+ mass: 100
10201
+ });
10202
+ }
10091
10203
  if (this.autoTickEnabled) {
10092
10204
  this.tickSubscription = this.tick$.subscribe(({ delta }) => {
10093
10205
  this.runFixedTicks(delta);
@@ -10285,6 +10397,12 @@ class RpgCommonMap {
10285
10397
  if (!owner?.id) {
10286
10398
  return;
10287
10399
  }
10400
+ const existingEntity = this.physic.getEntityByUUID(owner.id);
10401
+ if (existingEntity) {
10402
+ existingEntity.owner = owner;
10403
+ this.updateCharacterHitbox(owner);
10404
+ return;
10405
+ }
10288
10406
  const hitbox = typeof owner.hitbox === "function" ? owner.hitbox() : owner.hitbox;
10289
10407
  const width = hitbox?.w ?? 32;
10290
10408
  const height = hitbox?.h ?? 32;
@@ -10301,6 +10419,9 @@ class RpgCommonMap {
10301
10419
  }
10302
10420
  updateCharacterHitbox(owner) {
10303
10421
  if (!owner?.id) return;
10422
+ const entity = this.physic.getEntityByUUID(owner.id);
10423
+ if (!entity) return;
10424
+ entity.owner = owner;
10304
10425
  const hitbox = typeof owner.hitbox === "function" ? owner.hitbox() : owner.hitbox;
10305
10426
  const width = hitbox?.w ?? 32;
10306
10427
  const height = hitbox?.h ?? 32;
@@ -10688,22 +10809,26 @@ class RpgCommonMap {
10688
10809
  }
10689
10810
  }
10690
10811
  });
10691
- const entityWidth = width;
10692
- const entityHeight = height;
10693
10812
  entity.onPositionChange(({ x, y }) => {
10813
+ const currentOwner = entity.owner;
10814
+ if (!currentOwner) {
10815
+ return;
10816
+ }
10817
+ const entityWidth = entity.width || width;
10818
+ const entityHeight = entity.height || height;
10694
10819
  const topLeftX2 = x - entityWidth / 2;
10695
10820
  const topLeftY2 = y - entityHeight / 2;
10696
10821
  let changed = false;
10697
- if (typeof owner.x === "function" && typeof owner.x.set === "function") {
10698
- owner.x.set(Math.round(topLeftX2));
10822
+ if (typeof currentOwner.x === "function" && typeof currentOwner.x.set === "function") {
10823
+ currentOwner.x.set(Math.round(topLeftX2));
10699
10824
  changed = true;
10700
10825
  }
10701
- if (typeof owner.y === "function" && typeof owner.y.set === "function") {
10702
- owner.y.set(Math.round(topLeftY2));
10826
+ if (typeof currentOwner.y === "function" && typeof currentOwner.y.set === "function") {
10827
+ currentOwner.y.set(Math.round(topLeftY2));
10703
10828
  changed = true;
10704
10829
  }
10705
10830
  if (changed) {
10706
- owner.applyFrames?.();
10831
+ currentOwner.applyFrames?.();
10707
10832
  }
10708
10833
  });
10709
10834
  entity.addResolutionFilter((self, other) => {