chore: add sentinel to freestanding inventory
This commit is contained in:
parent
5d8643b187
commit
8c419063bb
@ -295,7 +295,9 @@ export const addItem = async (
|
|||||||
case "Types":
|
case "Types":
|
||||||
switch (typeName.substr(1).split("/")[2]) {
|
switch (typeName.substr(1).split("/")[2]) {
|
||||||
case "Sentinels": {
|
case "Sentinels": {
|
||||||
const inventoryChanges = await addSentinel(typeName, accountId);
|
const inventory = await getInventory(accountId);
|
||||||
|
const inventoryChanges = addSentinel(inventory, typeName);
|
||||||
|
await inventory.save();
|
||||||
await updateSlots(accountId, InventorySlot.SENTINELS, 0, 1);
|
await updateSlots(accountId, InventorySlot.SENTINELS, 0, 1);
|
||||||
return {
|
return {
|
||||||
InventoryChanges: {
|
InventoryChanges: {
|
||||||
@ -368,13 +370,13 @@ export const addItem = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
//TODO: maybe genericMethod for all the add methods, they share a lot of logic
|
//TODO: maybe genericMethod for all the add methods, they share a lot of logic
|
||||||
export const addSentinel = async (sentinelName: string, accountId: string): Promise<IInventoryChanges> => {
|
export const addSentinel = (
|
||||||
const inventoryChanges: IInventoryChanges = {};
|
inventory: TInventoryDatabaseDocument,
|
||||||
|
sentinelName: string,
|
||||||
|
inventoryChanges: IInventoryChanges = {}
|
||||||
|
): IInventoryChanges => {
|
||||||
if (ExportSentinels[sentinelName]?.defaultWeapon) {
|
if (ExportSentinels[sentinelName]?.defaultWeapon) {
|
||||||
inventoryChanges.SentinelWeapons = [
|
addSentinelWeapon(inventory, ExportSentinels[sentinelName].defaultWeapon, inventoryChanges);
|
||||||
await addSentinelWeapon(ExportSentinels[sentinelName].defaultWeapon, accountId)
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const modsToGive: IRawUpgrade[] = [];
|
const modsToGive: IRawUpgrade[] = [];
|
||||||
@ -392,20 +394,26 @@ export const addSentinel = async (sentinelName: string, accountId: string): Prom
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const inventory = await getInventory(accountId);
|
|
||||||
addMods(inventory, modsToGive);
|
addMods(inventory, modsToGive);
|
||||||
const sentinelIndex = inventory.Sentinels.push({ ItemType: sentinelName, Configs: configs, XP: 0 });
|
const sentinelIndex = inventory.Sentinels.push({ ItemType: sentinelName, Configs: configs, XP: 0 }) - 1;
|
||||||
const changedInventory = await inventory.save();
|
inventoryChanges.Sentinels ??= [];
|
||||||
inventoryChanges.Sentinels = [changedInventory.Sentinels[sentinelIndex - 1].toJSON()];
|
(inventoryChanges.Sentinels as IEquipmentClient[]).push(
|
||||||
|
inventory.Sentinels[sentinelIndex].toJSON<IEquipmentClient>()
|
||||||
|
);
|
||||||
|
|
||||||
return inventoryChanges;
|
return inventoryChanges;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addSentinelWeapon = async (typeName: string, accountId: string): Promise<IEquipmentClient> => {
|
export const addSentinelWeapon = (
|
||||||
const inventory = await getInventory(accountId);
|
inventory: TInventoryDatabaseDocument,
|
||||||
const sentinelIndex = inventory.SentinelWeapons.push({ ItemType: typeName });
|
typeName: string,
|
||||||
const changedInventory = await inventory.save();
|
inventoryChanges: IInventoryChanges
|
||||||
return changedInventory.SentinelWeapons[sentinelIndex - 1].toJSON<IEquipmentClient>();
|
): void => {
|
||||||
|
const index = inventory.SentinelWeapons.push({ ItemType: typeName }) - 1;
|
||||||
|
inventoryChanges.SentinelWeapons ??= [];
|
||||||
|
(inventoryChanges.SentinelWeapons as IEquipmentClient[]).push(
|
||||||
|
inventory.SentinelWeapons[index].toJSON<IEquipmentClient>()
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addPowerSuit = (
|
export const addPowerSuit = (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user