@pma-network/redm-server 0.0.14 → 0.0.16

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/PMA.d.ts CHANGED
@@ -32,6 +32,10 @@ export declare class PMA {
32
32
  * Gets all of the players that habe the specified job(s), and the specified {@param job_rank} if specified.
33
33
  */
34
34
  static get_players_with_job(job_names: string | string[], job_rank?: number): PMAPlayerWrapper[];
35
+ /**
36
+ * Returns all of the players currently registered in the core.
37
+ */
38
+ static get_players(): PMAPlayerWrapper[];
35
39
  /**
36
40
  * Generic logging
37
41
  * TODO: Setup a clickhouse wrapper
package/PMA.js CHANGED
@@ -10,7 +10,7 @@ class PMA {
10
10
  * @returns the item data for {@param item_name}, or `null` if the item doesn't exist
11
11
  */
12
12
  static get_item(item_name) {
13
- return exports["pma"].get_item(item_name);
13
+ return exports["pma-inventory"].get_item(item_name);
14
14
  }
15
15
  /**
16
16
  * Registers the {@param item_name} to be used as a usable item
@@ -23,7 +23,7 @@ class PMA {
23
23
  }, "usable_item_wrapper");
24
24
  const resource_wrapper = GetResourceWrapper();
25
25
  resource_wrapper.add_to_resource_start("pma", () => {
26
- exports["pma"].register_usable_item(item_name, usable_item_wrapper);
26
+ exports["pma-inventory"].register_usable_item(item_name, usable_item_wrapper);
27
27
  });
28
28
  }
29
29
  /**
@@ -51,6 +51,13 @@ class PMA {
51
51
  const players = exports["pma"].get_players_with_job(job_names, job_rank);
52
52
  return players.map((v) => PMAPlayerWrapper.from_raw(v));
53
53
  }
54
+ /**
55
+ * Returns all of the players currently registered in the core.
56
+ */
57
+ static get_players() {
58
+ const players = exports["pma"].get_players();
59
+ return players.map((v) => PMAPlayerWrapper.from_raw(v));
60
+ }
54
61
  /**
55
62
  * Generic logging
56
63
  * TODO: Setup a clickhouse wrapper
@@ -0,0 +1,18 @@
1
+ import type { BaseInventory } from "@pma-network/redm-types/BaseInventory";
2
+ import type { InventoryId, ItemName } from "@pma-network/redm-types/Inventory";
3
+ import type { PlayerUID, Source } from "@pma-network/redm-types/PMAPlayer";
4
+ export declare class PMAInventory {
5
+ #private;
6
+ static HaveItemsLoaded: Promise<boolean>;
7
+ private static init_has_loaded;
8
+ protected static _resolve(): void;
9
+ static on_resource_stop(): void;
10
+ static on_resource_start(): Promise<void>;
11
+ /**
12
+ * Initializes the player, this will internally await for items to be loaded
13
+ */
14
+ static init_player(source: Source, inventory_id: InventoryId, uid: PlayerUID): Promise<BaseInventory>;
15
+ protected static get_inventory_internal(inventory_id: InventoryId): any;
16
+ static get_inventory(inventory_id: InventoryId): BaseInventory;
17
+ static does_item_exist(item_name: ItemName): boolean;
18
+ }
@@ -0,0 +1,49 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { Delay, OnResourceStart, OnResourceStop } from "@nativewrappers/common";
4
+ class PMAInventory {
5
+ static {
6
+ __name(this, "PMAInventory");
7
+ }
8
+ static #has_loaded_resolve;
9
+ static HaveItemsLoaded;
10
+ static async init_has_loaded() {
11
+ PMAInventory.HaveItemsLoaded = new Promise((res) => {
12
+ PMAInventory.#has_loaded_resolve = res;
13
+ });
14
+ }
15
+ static _resolve() {
16
+ PMAInventory.#has_loaded_resolve(true);
17
+ }
18
+ static {
19
+ PMAInventory.init_has_loaded();
20
+ }
21
+ @OnResourceStop("pma-inventory")
22
+ static on_resource_stop() {
23
+ PMAInventory.init_has_loaded();
24
+ }
25
+ @OnResourceStart("pma-inventory")
26
+ static async on_resource_start() {
27
+ await Delay(0);
28
+ await exports["pma-inventory"].wait_for_item_manager_init();
29
+ PMAInventory._resolve();
30
+ }
31
+ /**
32
+ * Initializes the player, this will internally await for items to be loaded
33
+ */
34
+ static async init_player(source, inventory_id, uid) {
35
+ return exports["pma-inventory"].init_player(source, inventory_id, uid);
36
+ }
37
+ static get_inventory_internal(inventory_id) {
38
+ return exports["pma-inventory"].get_inventory(inventory_id);
39
+ }
40
+ static get_inventory(inventory_id) {
41
+ return PMAInventory.get_inventory_internal(inventory_id);
42
+ }
43
+ static does_item_exist(item_name) {
44
+ return exports["pma-inventory"].does_item_exist(item_name);
45
+ }
46
+ }
47
+ export {
48
+ PMAInventory
49
+ };
@@ -1,4 +1,4 @@
1
- import type { ItemName, OptionalItem } from "@pma-network/redm-types/Inventory";
1
+ import type { InventoryAddItemFailReason, InventoryRemoveItemFailReason, ItemName, OptionalItem } from "@pma-network/redm-types/Inventory";
2
2
  import type { NotificationVariant, PMAPartialNotification } from "@pma-network/redm-types/Notifications";
3
3
  import { CommonPMAPlayer } from "../shared-server/class/CommonPMAPlayer";
4
4
  import type { CommonAbstractPMAPlayer } from "../shared-server/types/CommonAbstractPMAPlayer";
@@ -18,8 +18,10 @@ export declare class PMAPlayerWrapper extends CommonPMAPlayer {
18
18
  static from_source_unchecked(source: number): CommonPMAPlayer;
19
19
  constructor(source: number);
20
20
  constructor(pma_player: CommonAbstractPMAPlayer);
21
+ ensure_inventory_init(): void;
21
22
  send_notification(title?: string, description?: string, variant?: NotificationVariant, duration?: number): void;
22
23
  send_notification_object(partial: PMAPartialNotification): void;
23
24
  get_item(item_name: ItemName): OptionalItem;
24
- add_item(item_name: ItemName, quantity: number): OptionalItem;
25
+ add_item(item_name: ItemName, quantity: number): InventoryAddItemFailReason;
26
+ remove_item(item_name: ItemName, quantity: number): InventoryRemoveItemFailReason;
25
27
  }
@@ -1,14 +1,12 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
  import { CommonPMAPlayer } from "../shared-server/class/CommonPMAPlayer";
4
+ import { pma_get_inventory_from_id } from "../shared-server/utils/GlobalOverrides";
4
5
  class PMAPlayerWrapper extends CommonPMAPlayer {
5
6
  static {
6
7
  __name(this, "PMAPlayerWrapper");
7
8
  }
8
- // This will get lazy-initialized whenever we actually call a function that needs it,
9
- // this will make sure we don't pay the un-needed serialize cost if we're only using this for
10
- // basic nativewrappers types
11
- #pma_player;
9
+ #inventory;
12
10
  /**
13
11
  * Creates the player from the ScRT msgpack'd class
14
12
  */
@@ -34,11 +32,22 @@ class PMAPlayerWrapper extends CommonPMAPlayer {
34
32
  if (typeof source !== "number") {
35
33
  const ply = source;
36
34
  super(ply.source);
37
- this.#pma_player = ply;
35
+ this.pma_player = ply;
38
36
  } else {
39
37
  super(source);
40
38
  }
41
39
  }
40
+ ensure_inventory_init() {
41
+ this.ensure_init();
42
+ const fn = (
43
+ // @ts-ignore
44
+ typeof globalThis.pma_get_inventory_from_id === "function" ? (
45
+ // @ts-ignore
46
+ globalThis.pma_get_inventory_from_id
47
+ ) : pma_get_inventory_from_id
48
+ );
49
+ this.#inventory ??= fn(`player:${this.get_unique_id()}`);
50
+ }
42
51
  send_notification(title, description, variant = "default", duration = 5e3) {
43
52
  const noti = {
44
53
  body: description,
@@ -51,12 +60,16 @@ class PMAPlayerWrapper extends CommonPMAPlayer {
51
60
  this.emit("pma:add_notification", partial);
52
61
  }
53
62
  get_item(item_name) {
54
- this.ensure_init();
55
- return this.#pma_player.get_item(item_name);
63
+ this.ensure_inventory_init();
64
+ return this.#inventory.get_item(item_name);
56
65
  }
57
66
  add_item(item_name, quantity) {
58
- this.ensure_init();
59
- return this.#pma_player.add_item(item_name, quantity);
67
+ this.ensure_inventory_init();
68
+ return this.#inventory.add_item(item_name, quantity);
69
+ }
70
+ remove_item(item_name, quantity) {
71
+ this.ensure_inventory_init();
72
+ return this.#inventory.remove_item(item_name, quantity);
60
73
  }
61
74
  }
62
75
  export {
package/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./PMA";
2
+ export * from "./PMAInventory";
2
3
  export * from "./types/Inventory";
3
4
  export * from "./shared-server/CommonPMA";
4
5
  export * from "./shared-server/utils/CooldownTracker";
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./PMA";
2
+ export * from "./PMAInventory";
2
3
  export * from "./types/Inventory";
3
4
  export * from "./shared-server/CommonPMA";
4
5
  export * from "./shared-server/utils/CooldownTracker";
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "Dillon Skaggs <AvarianKnight>"
6
6
  ],
7
7
  "type": "module",
8
- "version": "0.0.14",
8
+ "version": "0.0.16",
9
9
  "files": [
10
10
  "./**/*.js",
11
11
  "./**/*.d.ts"
@@ -3,7 +3,7 @@ import type { CommonAbstractPMAPlayer } from "../types/CommonAbstractPMAPlayer";
3
3
  import type { CommonNotificationVariant, CommonPMAPartialNotification } from "../types/CommonNotifications";
4
4
  import type { CallSign, ItemName, PlayerJob, PlayerUID } from "../types/SharedTypes";
5
5
  export declare class CommonPMAPlayer extends Player implements CommonAbstractPMAPlayer {
6
- #private;
6
+ protected pma_player: CommonAbstractPMAPlayer | null;
7
7
  /**
8
8
  * Creates the player from the ScRT msgpack'd class
9
9
  */
@@ -31,7 +31,7 @@ export declare class CommonPMAPlayer extends Player implements CommonAbstractPMA
31
31
  get_log_name(): string;
32
32
  get_item(item_name: ItemName): unknown;
33
33
  add_item(item_name: ItemName, quantity: number): unknown;
34
- remove_item(item_name: ItemName, quantity: number): void;
34
+ remove_item(item_name: ItemName, quantity: number): unknown;
35
35
  has_enough_of_item(item_name: ItemName, quantity: number): boolean;
36
36
  get_job(): PlayerJob;
37
37
  set_job(job_name: string, rank: number): void;
@@ -1,7 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
  import { Player } from "@nativewrappers/server";
4
- import { framework_name } from "../utils/FrameworkName";
5
4
  import { pma_get_player_from_id } from "../utils/GlobalOverrides";
6
5
  class CommonPMAPlayer extends Player {
7
6
  static {
@@ -10,7 +9,7 @@ class CommonPMAPlayer extends Player {
10
9
  // This will get lazy-initialized whenever we actually call a function that needs it,
11
10
  // this will make sure we don't pay the un-needed serialize cost if we're only using this for
12
11
  // basic nativewrappers types
13
- #pma_player = null;
12
+ pma_player = null;
14
13
  /**
15
14
  * Creates the player from the ScRT msgpack'd class
16
15
  */
@@ -36,15 +35,15 @@ class CommonPMAPlayer extends Player {
36
35
  if (typeof source !== "number") {
37
36
  const ply = source;
38
37
  super(ply.source);
39
- this.#pma_player = ply;
38
+ this.pma_player = ply;
40
39
  } else {
41
40
  super(source);
42
41
  }
43
42
  }
44
43
  // Ensure we initialize the player whenever we're doing something that needs it.
45
44
  ensure_init() {
46
- if (!this.#pma_player) {
47
- this.#pma_player = globalThis.pma_get_player_from_id ? (
45
+ if (!this.pma_player) {
46
+ this.pma_player = globalThis.pma_get_player_from_id ? (
48
47
  // @ts-ignore: we override this in GlobalOverrides
49
48
  globalThis.pma_get_player_from_id(this.Source)
50
49
  ) : pma_get_player_from_id(this.Source);
@@ -56,7 +55,7 @@ class CommonPMAPlayer extends Player {
56
55
  */
57
56
  is_player_valid() {
58
57
  this.ensure_init();
59
- return this.#pma_player !== null;
58
+ return this.pma_player !== null;
60
59
  }
61
60
  send_notification(title, description, variant = "default", duration = 5e3) {
62
61
  const noti = {
@@ -71,71 +70,71 @@ class CommonPMAPlayer extends Player {
71
70
  }
72
71
  get_sex() {
73
72
  this.ensure_init();
74
- return this.#pma_player.get_sex();
73
+ return this.pma_player.get_sex();
75
74
  }
76
75
  get_height() {
77
76
  this.ensure_init();
78
- return this.#pma_player.get_height();
77
+ return this.pma_player.get_height();
79
78
  }
80
79
  get_dob() {
81
80
  this.ensure_init();
82
- return this.#pma_player.get_dob();
81
+ return this.pma_player.get_dob();
83
82
  }
84
83
  get_unique_id() {
85
84
  this.ensure_init();
86
- return this.#pma_player.get_unique_id();
85
+ return this.pma_player.get_unique_id();
87
86
  }
88
87
  get_call_sign() {
89
88
  this.ensure_init();
90
- return this.#pma_player.get_call_sign();
89
+ return this.pma_player.get_call_sign();
91
90
  }
92
91
  get_character_name() {
93
92
  this.ensure_init();
94
- return this.#pma_player.get_character_name();
93
+ return this.pma_player.get_character_name();
95
94
  }
96
95
  get_log_name() {
97
96
  this.ensure_init();
98
- return this.#pma_player.get_character_name();
97
+ return this.pma_player.get_character_name();
99
98
  }
100
99
  get_item(item_name) {
101
100
  this.ensure_init();
102
- return this.#pma_player.get_item(item_name);
101
+ return this.pma_player.get_item(item_name);
103
102
  }
104
103
  add_item(item_name, quantity) {
105
104
  this.ensure_init();
106
- return this.#pma_player.add_item(item_name, quantity);
105
+ return this.pma_player.add_item(item_name, quantity);
107
106
  }
108
107
  remove_item(item_name, quantity) {
109
108
  this.ensure_init();
110
- return this.#pma_player.remove_item(item_name, quantity);
109
+ return this.pma_player.remove_item(item_name, quantity);
111
110
  }
112
111
  has_enough_of_item(item_name, quantity) {
113
112
  this.ensure_init();
114
- return this.#pma_player.has_enough_of_item(item_name, quantity);
113
+ return this.pma_player.has_enough_of_item(item_name, quantity);
115
114
  }
116
115
  get_job() {
117
116
  this.ensure_init();
118
- return this.#pma_player.get_job();
117
+ return this.pma_player.get_job();
119
118
  }
120
119
  set_job(job_name, rank) {
121
120
  this.ensure_init();
122
- return this.#pma_player.set_job(job_name, rank);
121
+ return this.pma_player.set_job(job_name, rank);
123
122
  }
124
123
  get_bank() {
125
124
  this.ensure_init();
126
- return this.#pma_player.get_bank();
125
+ return this.pma_player.get_bank();
127
126
  }
128
127
  add_to_bank(positive_amount) {
129
128
  this.ensure_init();
130
- return this.#pma_player.add_to_bank(positive_amount);
129
+ return this.pma_player.add_to_bank(positive_amount);
131
130
  }
132
131
  remove_from_bank(negative_amount) {
133
132
  this.ensure_init();
134
- return this.#pma_player.remove_from_bank(negative_amount);
133
+ return this.pma_player.remove_from_bank(negative_amount);
135
134
  }
136
135
  save() {
137
136
  this.ensure_init();
138
- return this.#pma_player.save();
137
+ return this.pma_player.save();
139
138
  }
140
139
  }
141
140
  export {
@@ -21,7 +21,7 @@ export declare abstract class CommonAbstractPMAPlayer {
21
21
  * Removes the item with {@param item_name} from the players inventory
22
22
  * @throws This will throw an error if there wasn't enough {@param quantity} in the players inventory, you should use use has_enough_of_item to check before calling
23
23
  */
24
- abstract remove_item(item_name: ItemName, quantity: number): void;
24
+ abstract remove_item(item_name: ItemName, quantity: number): unknown;
25
25
  /**
26
26
  * Checks if the player has enough of {@param item_name}
27
27
  * @returns `true` if they had enough {@param quantity}, `false` otherwise
@@ -1,3 +1,4 @@
1
1
  import type { CommonPMAPlayer } from "../class/CommonPMAPlayer";
2
2
  import type { Source } from "../types/SharedTypes";
3
3
  export declare function pma_get_player_from_id(source: Source): CommonPMAPlayer;
4
+ export declare function pma_get_inventory_from_id(source: Source): CommonPMAPlayer;
@@ -6,6 +6,12 @@ function pma_get_player_from_id(source) {
6
6
  }
7
7
  __name(pma_get_player_from_id, "pma_get_player_from_id");
8
8
  globalThis.pma_get_player_from_id = pma_get_player_from_id;
9
+ function pma_get_inventory_from_id(source) {
10
+ return exports[framework_name].get_inventory(source);
11
+ }
12
+ __name(pma_get_inventory_from_id, "pma_get_inventory_from_id");
13
+ globalThis.pma_get_inventory_from_id = pma_get_inventory_from_id;
9
14
  export {
15
+ pma_get_inventory_from_id,
10
16
  pma_get_player_from_id
11
17
  };
@@ -1,4 +1,5 @@
1
- import type { BaseInventory, InventoryItem } from "@pma-network/redm-types/Inventory";
1
+ import type { BaseInventory } from "@pma-network/redm-types/BaseInventory";
2
+ import type { InventoryItem } from "@pma-network/redm-types/Inventory";
2
3
  import type { AbstractPMAPlayer } from "../class/AbstractPMAPlayer";
3
4
  import type { PMAPlayerWrapper } from "../class/PMAPlayer";
4
5
  export type UsableItemCall = (ply: PMAPlayerWrapper, inventory: BaseInventory, item: InventoryItem) => void;