mission inventoryupdate - credits

This commit is contained in:
holmityd 2023-08-30 08:14:59 +04:00
parent 15ab3f76b1
commit b583e7173a
2 changed files with 8 additions and 8 deletions

View File

@ -11,7 +11,7 @@ import fs from 'fs';
- [x] Melee - [x] Melee
- [x] RawUpgrades - [x] RawUpgrades
- [x] MiscItems - [x] MiscItems
- [ ] RegularCredits - [x] RegularCredits
- [ ] RandomUpgradesIdentified - [ ] RandomUpgradesIdentified
- [ ] MissionFailed - [ ] MissionFailed
- [ ] MissionStatus - [ ] MissionStatus
@ -23,7 +23,7 @@ import fs from 'fs';
- [ ] LastRegionPlayed - [ ] LastRegionPlayed
- [ ] GameModeId - [ ] GameModeId
- [ ] hosts - [ ] hosts
- [ ] ChallengeProgress - [+] ChallengeProgress
- [ ] SeasonChallengeHistory - [ ] SeasonChallengeHistory
- [ ] PS - [ ] PS
- [ ] ActiveDojoColorResearch - [ ] ActiveDojoColorResearch

View File

@ -5,8 +5,7 @@ import { Types } from "mongoose";
import { ISuitDatabase, 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 { IWeaponDatabase, IWeaponResponse } from "@/src/types/inventoryTypes/weaponTypes"; import { IWeaponDatabase, IWeaponResponse } from "@/src/types/inventoryTypes/weaponTypes";
import { FlavourItem, RawUpgrade, MiscItem, IInventoryDatabase } from "@/src/types/inventoryTypes/inventoryTypes"; import { FlavourItem, RawUpgrade, MiscItem } 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 {
@ -107,12 +106,12 @@ 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 missionInventoryUpdate = async (data: any, accountId: string): Promise<void> => { export const missionInventoryUpdate = async (data: any, accountId: string): Promise<void> => { // TODO - add data type
const { RawUpgrades, MiscItems, Suits, Pistols, LongGuns, Melee } = data; const { RawUpgrades, MiscItems, Suits, Pistols, LongGuns, Melee, RegularCredits } = data;
const inventory = await getInventory(accountId); const inventory = await getInventory(accountId);
const addGearExpByCategory = (gearArray: (ISuitDatabase|IWeaponDatabase)[], category: 'Pistols'|'LongGuns'|'Melee'|'Suits') => { const addGearExpByCategory = (gearArray: (ISuitDatabase|IWeaponDatabase)[], category: 'Pistols'|'LongGuns'|'Melee'|'Suits') => {
gearArray.forEach(({ ItemId, XP }: any) => { gearArray?.forEach(({ ItemId, XP }: any) => {
const itemIndex = inventory[category].findIndex(i => i._id?.equals(ItemId.$oid)); const itemIndex = inventory[category].findIndex(i => i._id?.equals(ItemId.$oid));
if (itemIndex !== -1) { if (itemIndex !== -1) {
inventory[category][itemIndex].XP += XP; inventory[category][itemIndex].XP += XP;
@ -134,7 +133,8 @@ export const missionInventoryUpdate = async (data: any, accountId: string): Prom
} }
}); });
}; };
inventory.RegularCredits += RegularCredits||0;
addGearExpByCategory(Pistols, 'Pistols'); addGearExpByCategory(Pistols, 'Pistols');
addGearExpByCategory(LongGuns, 'LongGuns'); addGearExpByCategory(LongGuns, 'LongGuns');
addGearExpByCategory(Melee, 'Melee'); addGearExpByCategory(Melee, 'Melee');