-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathhandleInventory.js
More file actions
47 lines (36 loc) · 1.08 KB
/
handleInventory.js
File metadata and controls
47 lines (36 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const handleInventory = ({ states, data, chIndex, globalData }) => {
const inventory = states.inventories[chIndex];
if (!inventory) {
return;
}
if (data.deleted) {
delete inventory.items[data.elementIndex];
return;
}
if (data.export.ReplayPawn) {
inventory.replayPawn = data.export.ReplayPawn;
}
if (!inventory.playerId) {
const pawnChannel = globalData.actorToChannel[inventory.replayPawn];
const playerChannel = states.pawnChannelToStateChannel[pawnChannel];
const player = states.players[playerChannel];
if (player) {
player.inventory = inventory;
inventory.playerId = player.PlayerId;
}
}
if (!data.export.ItemDefinition) {
return;
}
if (inventory.items[data.elementIndex]) {
inventory.items[data.elementIndex].count = data.export.Count;
inventory.items[data.elementIndex].ammo = data.export.LoadedAmmo;
return;
}
inventory.items[data.elementIndex] = {
count: data.export.Count,
item: data.export.ItemDefinition,
ammo: data.export.LoadedAmmo,
};
};
module.exports = handleInventory;