@pma-network/redm-types 0.0.13 → 0.0.15
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/BaseInventory.d.ts +26 -0
- package/BaseInventory.js +10 -0
- package/Inventory.d.ts +39 -18
- package/Inventory.js +86 -4
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { InventoryAddItemFailReason, InventoryRemoveItemFailReason, ItemName, OptionalItem } from "./Inventory";
|
|
2
|
+
export declare abstract class BaseInventory {
|
|
3
|
+
/**
|
|
4
|
+
* Gets the item with {@link item_name}
|
|
5
|
+
* @returns the {@link InventoryItem} or undefined if the player doesn't have that item in their inventory.
|
|
6
|
+
*/
|
|
7
|
+
abstract get_item(item_name: ItemName): OptionalItem;
|
|
8
|
+
/**
|
|
9
|
+
* Adds the item with {@link item_name} to the players next free slot
|
|
10
|
+
* @throws This will throw an error if {@link item_name} is invalid, or if {@link quantity} is negative
|
|
11
|
+
* @returns the {@link InventoryItem} that was created, or undefined if there wasn't a free slot to put the item into.
|
|
12
|
+
*/
|
|
13
|
+
abstract add_item(item_name: ItemName, quantity: number): InventoryAddItemFailReason;
|
|
14
|
+
/**
|
|
15
|
+
* Removes the item with {@link item_name} from the players inventory
|
|
16
|
+
* @throws This will throw an error if there wasn't enough {@link quantity} in the players inventory, you should use use {@link has_enough_of_item} to check before calling
|
|
17
|
+
* @param item_name the item to remove
|
|
18
|
+
* @param quantity the amount of the item to remove
|
|
19
|
+
*/
|
|
20
|
+
abstract remove_item(item_name: ItemName, quantity: number): InventoryRemoveItemFailReason;
|
|
21
|
+
/**
|
|
22
|
+
* Checks if the player has enough of {@link item_name}
|
|
23
|
+
* @returns `true` if they had enough {@link quantity}, `false` otherwise
|
|
24
|
+
*/
|
|
25
|
+
abstract has_enough_of_item(item_name: ItemName, quantity: number): boolean;
|
|
26
|
+
}
|
package/BaseInventory.js
ADDED
package/Inventory.d.ts
CHANGED
|
@@ -8,8 +8,12 @@ export declare enum ItemFlags {
|
|
|
8
8
|
IsAmmo = 8,
|
|
9
9
|
Stackable = 32
|
|
10
10
|
}
|
|
11
|
+
export type InventoryEntityTypes = "localHorse" | "localVehicle" | "horse" | "player" | "vehicle" | "chest" | "shop" | "invalid";
|
|
12
|
+
export type InventoryId = `${InventoryEntityTypes}:${number}`;
|
|
11
13
|
export type ItemName = string;
|
|
14
|
+
export type SlotId = number;
|
|
12
15
|
export type ItemId = number;
|
|
16
|
+
export type SlotAndItemId = [SlotId] | [SlotId, ItemId | undefined];
|
|
13
17
|
export interface ItemData {
|
|
14
18
|
item_id: ItemId;
|
|
15
19
|
name: ItemName;
|
|
@@ -24,28 +28,45 @@ export interface InventoryItem {
|
|
|
24
28
|
quantity: number;
|
|
25
29
|
}
|
|
26
30
|
export type OptionalItem = InventoryItem | null | undefined;
|
|
27
|
-
export declare
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
export declare enum InventoryAddItemFailReason {
|
|
32
|
+
SUCCESS = 0,
|
|
33
|
+
TooHeavy = 1,
|
|
34
|
+
NoFreeSlot = 2
|
|
35
|
+
}
|
|
36
|
+
export declare enum InventoryRemoveItemFailReason {
|
|
37
|
+
SUCCESS = 0,
|
|
38
|
+
NotEnoughOfItem = 1,
|
|
39
|
+
NoItem = 2
|
|
40
|
+
}
|
|
41
|
+
export declare class ItemWrapper {
|
|
42
|
+
#private;
|
|
43
|
+
private static item_data_ref;
|
|
33
44
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @throws This will throw an error if {@link item_name} is invalid, or if {@link quantity} is negative
|
|
36
|
-
* @returns the {@link InventoryItem} that was created, or undefined if there wasn't a free slot to put the item into.
|
|
45
|
+
*
|
|
37
46
|
*/
|
|
38
|
-
|
|
47
|
+
static get UnsafeRef(): ItemWrapper;
|
|
48
|
+
constructor(item_data: ItemData);
|
|
49
|
+
replace_ref(ref: ItemData): this;
|
|
50
|
+
clone(): ItemWrapper;
|
|
51
|
+
get ItemData(): ItemData;
|
|
52
|
+
get ItemId(): number;
|
|
53
|
+
get Name(): ItemName;
|
|
54
|
+
get Weight(): number;
|
|
55
|
+
get Flags(): Bitwise<ItemFlags>;
|
|
39
56
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* @param item_name the item to remove
|
|
43
|
-
* @param quantity the amount of the item to remove
|
|
57
|
+
* If the item is a weapon it will just return the weapons weight, as ammo has
|
|
58
|
+
* no actual weight, otherwise it will return the weight of the item * quantity
|
|
44
59
|
*/
|
|
45
|
-
|
|
60
|
+
calculate_weight(quantity: number): number;
|
|
61
|
+
private can_item_stack;
|
|
62
|
+
private is_item_stackable;
|
|
63
|
+
get IsWeapon(): boolean;
|
|
64
|
+
get IsStackable(): boolean;
|
|
46
65
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
66
|
+
* Returns the amount of items that can be stacked into this item, by default
|
|
67
|
+
* this is 100
|
|
49
68
|
*/
|
|
50
|
-
|
|
69
|
+
get StackLimit(): number;
|
|
70
|
+
get Label(): string;
|
|
71
|
+
get Description(): string;
|
|
51
72
|
}
|
package/Inventory.js
CHANGED
|
@@ -9,12 +9,94 @@ var ItemFlags = /* @__PURE__ */ ((ItemFlags2) => {
|
|
|
9
9
|
ItemFlags2[ItemFlags2["Stackable"] = 32] = "Stackable";
|
|
10
10
|
return ItemFlags2;
|
|
11
11
|
})(ItemFlags || {});
|
|
12
|
-
|
|
12
|
+
var InventoryAddItemFailReason = /* @__PURE__ */ ((InventoryAddItemFailReason2) => {
|
|
13
|
+
InventoryAddItemFailReason2[InventoryAddItemFailReason2["SUCCESS"] = 0] = "SUCCESS";
|
|
14
|
+
InventoryAddItemFailReason2[InventoryAddItemFailReason2["TooHeavy"] = 1] = "TooHeavy";
|
|
15
|
+
InventoryAddItemFailReason2[InventoryAddItemFailReason2["NoFreeSlot"] = 2] = "NoFreeSlot";
|
|
16
|
+
return InventoryAddItemFailReason2;
|
|
17
|
+
})(InventoryAddItemFailReason || {});
|
|
18
|
+
var InventoryRemoveItemFailReason = /* @__PURE__ */ ((InventoryRemoveItemFailReason2) => {
|
|
19
|
+
InventoryRemoveItemFailReason2[InventoryRemoveItemFailReason2["SUCCESS"] = 0] = "SUCCESS";
|
|
20
|
+
InventoryRemoveItemFailReason2[InventoryRemoveItemFailReason2["NotEnoughOfItem"] = 1] = "NotEnoughOfItem";
|
|
21
|
+
InventoryRemoveItemFailReason2[InventoryRemoveItemFailReason2["NoItem"] = 2] = "NoItem";
|
|
22
|
+
return InventoryRemoveItemFailReason2;
|
|
23
|
+
})(InventoryRemoveItemFailReason || {});
|
|
24
|
+
class ItemWrapper {
|
|
13
25
|
static {
|
|
14
|
-
__name(this, "
|
|
26
|
+
__name(this, "ItemWrapper");
|
|
27
|
+
}
|
|
28
|
+
#ref;
|
|
29
|
+
static item_data_ref = new ItemWrapper(void 0);
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
static get UnsafeRef() {
|
|
34
|
+
return ItemWrapper.item_data_ref;
|
|
35
|
+
}
|
|
36
|
+
constructor(item_data) {
|
|
37
|
+
this.#ref = item_data;
|
|
38
|
+
}
|
|
39
|
+
replace_ref(ref) {
|
|
40
|
+
this.#ref = ref;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
clone() {
|
|
44
|
+
return new ItemWrapper(this.#ref);
|
|
45
|
+
}
|
|
46
|
+
get ItemData() {
|
|
47
|
+
return this.#ref;
|
|
48
|
+
}
|
|
49
|
+
get ItemId() {
|
|
50
|
+
return this.#ref.item_id;
|
|
51
|
+
}
|
|
52
|
+
get Name() {
|
|
53
|
+
return this.#ref.name;
|
|
54
|
+
}
|
|
55
|
+
get Weight() {
|
|
56
|
+
return this.#ref.weight;
|
|
57
|
+
}
|
|
58
|
+
get Flags() {
|
|
59
|
+
return this.#ref.flags;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* If the item is a weapon it will just return the weapons weight, as ammo has
|
|
63
|
+
* no actual weight, otherwise it will return the weight of the item * quantity
|
|
64
|
+
*/
|
|
65
|
+
calculate_weight(quantity) {
|
|
66
|
+
if (this.IsWeapon) {
|
|
67
|
+
return this.Weight;
|
|
68
|
+
}
|
|
69
|
+
return this.#ref.weight * quantity;
|
|
70
|
+
}
|
|
71
|
+
can_item_stack() {
|
|
72
|
+
return this.is_item_stackable() || this.IsWeapon;
|
|
73
|
+
}
|
|
74
|
+
is_item_stackable() {
|
|
75
|
+
return (this.#ref.flags & 32 /* Stackable */) !== 0;
|
|
76
|
+
}
|
|
77
|
+
get IsWeapon() {
|
|
78
|
+
return (this.#ref.flags & 8 /* IsWeapon */) !== 0;
|
|
79
|
+
}
|
|
80
|
+
get IsStackable() {
|
|
81
|
+
return this.can_item_stack();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns the amount of items that can be stacked into this item, by default
|
|
85
|
+
* this is 100
|
|
86
|
+
*/
|
|
87
|
+
get StackLimit() {
|
|
88
|
+
return this.#ref.stack_limit;
|
|
89
|
+
}
|
|
90
|
+
get Label() {
|
|
91
|
+
return this.#ref.label;
|
|
92
|
+
}
|
|
93
|
+
get Description() {
|
|
94
|
+
return this.#ref.description;
|
|
15
95
|
}
|
|
16
96
|
}
|
|
17
97
|
export {
|
|
18
|
-
|
|
19
|
-
|
|
98
|
+
InventoryAddItemFailReason,
|
|
99
|
+
InventoryRemoveItemFailReason,
|
|
100
|
+
ItemFlags,
|
|
101
|
+
ItemWrapper
|
|
20
102
|
};
|
package/index.d.ts
CHANGED
package/index.js
CHANGED