mission inventory update - exp

This commit is contained in:
holmityd 2023-08-30 07:51:56 +04:00
parent b66fdc17ba
commit 15ab3f76b1
2 changed files with 42 additions and 36 deletions

View File

@ -1,14 +1,14 @@
import { RequestHandler } from "express"; import { RequestHandler } from "express";
import { addRawUpgrades, addMiscItems } from "@/src/services/inventoryService"; import { missionInventoryUpdate } from "@/src/services/inventoryService";
import fs from 'fs'; import fs from 'fs';
/* /*
- [ ] crossPlaySetting - [ ] crossPlaySetting
- [ ] rewardsMultiplier - [ ] rewardsMultiplier
- [ ] ActiveBoosters - [ ] ActiveBoosters
- [ ] LongGuns - [x] LongGuns
- [ ] Pistols - [x] Pistols
- [ ] Suits - [x] Suits
- [ ] Melee - [x] Melee
- [x] RawUpgrades - [x] RawUpgrades
- [x] MiscItems - [x] MiscItems
- [ ] RegularCredits - [ ] RegularCredits
@ -47,10 +47,9 @@ const missionInventoryUpdateController: RequestHandler = async (req, res) => {
}); });
const [data, _secondIGuessIsSalt] = String(req.body).split("\n"); const [data, _secondIGuessIsSalt] = String(req.body).split("\n");
const {RawUpgrades, MiscItems} = JSON.parse(data);
const id = req.query.accountId as string; const id = req.query.accountId as string;
addRawUpgrades(RawUpgrades, id);
addMiscItems(MiscItems, id); await missionInventoryUpdate(JSON.parse(data), id);
res.json({}); res.json({});
}; };

View File

@ -2,10 +2,11 @@ import { Inventory } from "@/src/models/inventoryModel";
import new_inventory from "@/static/fixed_responses/postTutorialInventory.json"; import new_inventory from "@/static/fixed_responses/postTutorialInventory.json";
import config from "@/config.json"; import config from "@/config.json";
import { Types } from "mongoose"; import { Types } from "mongoose";
import { ISuitResponse } from "@/src/types/inventoryTypes/SuitTypes"; import { ISuitDatabase, ISuitResponse } from "@/src/types/inventoryTypes/SuitTypes";
import { SlotType } from "@/src/types/purchaseTypes"; import { SlotType } from "@/src/types/purchaseTypes";
import { IWeaponResponse } from "@/src/types/inventoryTypes/weaponTypes"; import { IWeaponDatabase, IWeaponResponse } from "@/src/types/inventoryTypes/weaponTypes";
import { FlavourItem, RawUpgrade, MiscItem } from "@/src/types/inventoryTypes/inventoryTypes"; import { FlavourItem, RawUpgrade, MiscItem, IInventoryDatabase } from "@/src/types/inventoryTypes/inventoryTypes";
import { items } from "@/static/data/items";
const createInventory = async (accountOwnerId: Types.ObjectId) => { const createInventory = async (accountOwnerId: Types.ObjectId) => {
try { try {
@ -106,35 +107,41 @@ export const addCustomization = async (customizatonName: string, accountId: stri
return changedInventory.FlavourItems[flavourItemIndex].toJSON(); //mongoose bug forces as FlavourItem return changedInventory.FlavourItems[flavourItemIndex].toJSON(); //mongoose bug forces as FlavourItem
}; };
export const addRawUpgrades = async (rawUpgrades: RawUpgrade[], accountId: string): Promise<void> => { export const missionInventoryUpdate = async (data: any, accountId: string): Promise<void> => {
const { RawUpgrades, MiscItems, Suits, Pistols, LongGuns, Melee } = data;
const inventory = await getInventory(accountId); const inventory = await getInventory(accountId);
rawUpgrades?.forEach(item => {
const { ItemCount, ItemType } = item;
const existingItemIndex = inventory.RawUpgrades.findIndex(i => i.ItemType === ItemType);
if (existingItemIndex !== -1) { const addGearExpByCategory = (gearArray: (ISuitDatabase|IWeaponDatabase)[], category: 'Pistols'|'LongGuns'|'Melee'|'Suits') => {
inventory.RawUpgrades[existingItemIndex].ItemCount += ItemCount; gearArray.forEach(({ ItemId, XP }: any) => {
inventory.markModified('RawUpgrades.' + existingItemIndex + '.ItemCount'); const itemIndex = inventory[category].findIndex(i => i._id?.equals(ItemId.$oid));
} else { if (itemIndex !== -1) {
inventory.RawUpgrades.push({ ItemCount, ItemType }); inventory[category][itemIndex].XP += XP;
} inventory.markModified(`${category}.${itemIndex}.XP`);
}); }
await inventory.save(); });
}; };
export const addMiscItems = async (miscItems: MiscItem[], accountId: string): Promise<void> => { const addItemsByCategory = (itemsArray: (RawUpgrade | MiscItem)[], category: 'RawUpgrades'|'MiscItems') => {
const inventory = await getInventory(accountId); itemsArray?.forEach(item => {
miscItems?.forEach(item => { const { ItemCount, ItemType } = item;
const { ItemCount, ItemType } = item; const existingItemIndex = inventory[category].findIndex(i => i.ItemType === ItemType);
const existingItemIndex = inventory.MiscItems.findIndex(i => i.ItemType === ItemType);
if (existingItemIndex !== -1) {
inventory[category][existingItemIndex].ItemCount += ItemCount;
inventory.markModified(category + '.' + existingItemIndex + '.ItemCount');
} else {
inventory[category].push({ ItemCount, ItemType });
}
});
};
addGearExpByCategory(Pistols, 'Pistols');
addGearExpByCategory(LongGuns, 'LongGuns');
addGearExpByCategory(Melee, 'Melee');
addGearExpByCategory(Suits, 'Suits');
addItemsByCategory(RawUpgrades, 'RawUpgrades'); // TODO - check mods fusion level
addItemsByCategory(MiscItems, 'MiscItems');
if (existingItemIndex !== -1) {
inventory.MiscItems[existingItemIndex].ItemCount += ItemCount;
inventory.markModified('MiscItems.' + existingItemIndex + '.ItemCount');
} else {
inventory.MiscItems.push({ ItemCount, ItemType });
}
});
await inventory.save(); await inventory.save();
}; };