Compare commits

..

No commits in common. "9de57668ab961eb2c0646b1a44ff6cba731487dd" and "50d687e59a229eac4a5ecad2e8b9134de17b4a5d" have entirely different histories.

6 changed files with 55 additions and 94 deletions

View File

@ -7,7 +7,14 @@ import { getRecipe } from "@/src/services/itemDataService";
import { IOid } from "@/src/types/commonTypes"; import { IOid } from "@/src/types/commonTypes";
import { getJSONfromString } from "@/src/helpers/stringHelpers"; import { getJSONfromString } from "@/src/helpers/stringHelpers";
import { getAccountIdForRequest } from "@/src/services/loginService"; import { getAccountIdForRequest } from "@/src/services/loginService";
import { getInventory, updateCurrency, addItem, addMiscItems, addRecipes } from "@/src/services/inventoryService"; import {
getInventory,
updateCurrency,
addItem,
addMiscItems,
addRecipes,
updateCurrencyByAccountId
} from "@/src/services/inventoryService";
export interface IClaimCompletedRecipeRequest { export interface IClaimCompletedRecipeRequest {
RecipeIds: IOid[]; RecipeIds: IOid[];
@ -30,6 +37,7 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
// } // }
inventory.PendingRecipes.pull(pendingRecipe._id); inventory.PendingRecipes.pull(pendingRecipe._id);
await inventory.save();
const recipe = getRecipe(pendingRecipe.ItemType); const recipe = getRecipe(pendingRecipe.ItemType);
if (!recipe) { if (!recipe) {
@ -37,10 +45,11 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
} }
if (req.query.cancel) { if (req.query.cancel) {
const inventory = await getInventory(accountId);
const currencyChanges = updateCurrency(inventory, recipe.buildPrice * -1, false); const currencyChanges = updateCurrency(inventory, recipe.buildPrice * -1, false);
addMiscItems(inventory, recipe.ingredients); addMiscItems(inventory, recipe.ingredients);
await inventory.save(); await inventory.save();
// Not a bug: In the specific case of cancelling a recipe, InventoryChanges are expected to be the root. // Not a bug: In the specific case of cancelling a recipe, InventoryChanges are expected to be the root.
res.json({ res.json({
...currencyChanges, ...currencyChanges,
@ -50,6 +59,7 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
logger.debug("Claiming Recipe", { recipe, pendingRecipe }); logger.debug("Claiming Recipe", { recipe, pendingRecipe });
if (recipe.secretIngredientAction == "SIA_SPECTRE_LOADOUT_COPY") { if (recipe.secretIngredientAction == "SIA_SPECTRE_LOADOUT_COPY") {
const inventory = await getInventory(accountId);
inventory.PendingSpectreLoadouts ??= []; inventory.PendingSpectreLoadouts ??= [];
inventory.SpectreLoadouts ??= []; inventory.SpectreLoadouts ??= [];
@ -67,6 +77,7 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
); );
inventory.SpectreLoadouts.push(inventory.PendingSpectreLoadouts[pendingLoadoutIndex]); inventory.SpectreLoadouts.push(inventory.PendingSpectreLoadouts[pendingLoadoutIndex]);
inventory.PendingSpectreLoadouts.splice(pendingLoadoutIndex, 1); inventory.PendingSpectreLoadouts.splice(pendingLoadoutIndex, 1);
await inventory.save();
} }
} }
@ -81,14 +92,17 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
InventoryChanges = { ...InventoryChanges, Recipes: recipeChanges }; InventoryChanges = { ...InventoryChanges, Recipes: recipeChanges };
const inventory = await getInventory(accountId);
addRecipes(inventory, recipeChanges); addRecipes(inventory, recipeChanges);
await inventory.save();
} }
if (req.query.rush) { if (req.query.rush) {
InventoryChanges = { InventoryChanges = {
...InventoryChanges, ...InventoryChanges,
...updateCurrency(inventory, recipe.skipBuildTimePrice, true) ...(await updateCurrencyByAccountId(recipe.skipBuildTimePrice, true, accountId))
}; };
} }
const inventory = await getInventory(accountId);
InventoryChanges = { InventoryChanges = {
...InventoryChanges, ...InventoryChanges,
...(await addItem(inventory, recipe.resultType, recipe.num)).InventoryChanges ...(await addItem(inventory, recipe.resultType, recipe.num)).InventoryChanges

View File

@ -68,9 +68,7 @@ import {
ICalendarProgress, ICalendarProgress,
IPendingCouponDatabase, IPendingCouponDatabase,
IPendingCouponClient, IPendingCouponClient,
ILibraryAvailableDailyTaskInfo, ILibraryAvailableDailyTaskInfo
IDroneDatabase,
IDroneClient
} from "../../types/inventoryTypes/inventoryTypes"; } from "../../types/inventoryTypes/inventoryTypes";
import { IOid } from "../../types/commonTypes"; import { IOid } from "../../types/commonTypes";
import { import {
@ -351,27 +349,6 @@ const TypeXPItemSchema = new Schema<ITypeXPItem>(
{ _id: false } { _id: false }
); );
const droneSchema = new Schema<IDroneDatabase>(
{
ItemType: String,
CurrentHP: Number,
RepairStart: { type: Date, default: undefined }
},
{ id: false }
);
droneSchema.set("toJSON", {
virtuals: true,
transform(_document, obj) {
const client = obj as IDroneClient;
const db = obj as IDroneDatabase;
client.ItemId = toOid(db._id);
delete obj._id;
delete obj.__v;
}
});
const challengeProgressSchema = new Schema<IChallengeProgress>( const challengeProgressSchema = new Schema<IChallengeProgress>(
{ {
Progress: Number, Progress: Number,
@ -532,7 +509,7 @@ const questProgressSchema = new Schema<IQuestStage>(
const questKeysSchema = new Schema<IQuestKeyDatabase>( const questKeysSchema = new Schema<IQuestKeyDatabase>(
{ {
Progress: { type: [questProgressSchema], default: [] }, Progress: { type: [questProgressSchema], default: undefined },
unlock: Boolean, unlock: Boolean,
Completed: Boolean, Completed: Boolean,
CustomData: String, CustomData: String,
@ -1171,8 +1148,8 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
CompletedSorties: [String], CompletedSorties: [String],
LastSortieReward: [Schema.Types.Mixed], LastSortieReward: [Schema.Types.Mixed],
// Resource Extractor Drones //Resource_Drone[Uselees stuff]
Drones: [droneSchema], Drones: [Schema.Types.Mixed],
//Active profile ico //Active profile ico
ActiveAvatarImageType: String, ActiveAvatarImageType: String,
@ -1322,7 +1299,6 @@ export type InventoryDocumentProps = {
PendingRecipes: Types.DocumentArray<IPendingRecipeDatabase>; PendingRecipes: Types.DocumentArray<IPendingRecipeDatabase>;
WeaponSkins: Types.DocumentArray<IWeaponSkinDatabase>; WeaponSkins: Types.DocumentArray<IWeaponSkinDatabase>;
QuestKeys: Types.DocumentArray<IQuestKeyDatabase>; QuestKeys: Types.DocumentArray<IQuestKeyDatabase>;
Drones: Types.DocumentArray<IDroneDatabase>;
} & { [K in TEquipmentKey]: Types.DocumentArray<IEquipmentDatabase> }; } & { [K in TEquipmentKey]: Types.DocumentArray<IEquipmentDatabase> };
// eslint-disable-next-line @typescript-eslint/ban-types // eslint-disable-next-line @typescript-eslint/ban-types

View File

@ -24,8 +24,7 @@ import {
IKubrowPetEggDatabase, IKubrowPetEggDatabase,
IKubrowPetEggClient, IKubrowPetEggClient,
ILibraryAvailableDailyTaskInfo, ILibraryAvailableDailyTaskInfo,
ICalendarProgress, ICalendarProgress
IDroneClient
} from "@/src/types/inventoryTypes/inventoryTypes"; } from "@/src/types/inventoryTypes/inventoryTypes";
import { IGenericUpdate } from "../types/genericUpdate"; import { IGenericUpdate } from "../types/genericUpdate";
import { import {
@ -39,7 +38,6 @@ import { IEquipmentClient, IEquipmentDatabase, IItemConfig } from "../types/inve
import { import {
ExportArcanes, ExportArcanes,
ExportCustoms, ExportCustoms,
ExportDrones,
ExportFlavour, ExportFlavour,
ExportFusionBundles, ExportFusionBundles,
ExportGear, ExportGear,
@ -58,7 +56,7 @@ import { IKeyChainRequest } from "@/src/controllers/api/giveKeyChainTriggeredIte
import { toOid } from "../helpers/inventoryHelpers"; import { toOid } from "../helpers/inventoryHelpers";
import { generateRewardSeed } from "@/src/controllers/api/getNewRewardSeedController"; import { generateRewardSeed } from "@/src/controllers/api/getNewRewardSeedController";
import { addStartingGear } from "@/src/controllers/api/giveStartingGearController"; import { addStartingGear } from "@/src/controllers/api/giveStartingGearController";
import { addQuestKey, completeQuest } from "@/src/services/questService"; import { completeQuest } from "@/src/services/questService";
export const createInventory = async ( export const createInventory = async (
accountOwnerId: Types.ObjectId, accountOwnerId: Types.ObjectId,
@ -327,29 +325,15 @@ export const addItem = async (
} }
if (typeName in ExportKeys) { if (typeName in ExportKeys) {
// Note: "/Lotus/Types/Keys/" contains some EmailItems // Note: "/Lotus/Types/Keys/" contains some EmailItems
const key = ExportKeys[typeName]; inventory.QuestKeys.push({ ItemType: typeName });
if (key.chainStages) {
const key = addQuestKey(inventory, { ItemType: typeName });
if (key) {
return { InventoryChanges: { QuestKeys: [key] } };
}
} else {
const key = { ItemType: typeName, ItemCount: quantity };
const index = inventory.LevelKeys.findIndex(levelKey => levelKey.ItemType == typeName);
if (index) {
inventory.LevelKeys[index].ItemCount += quantity;
} else {
inventory.LevelKeys.push(key);
}
return { InventoryChanges: { LevelKeys: [key] } };
}
}
if (typeName in ExportDrones) {
const inventoryChanges = addDrone(inventory, typeName);
return { return {
InventoryChanges: inventoryChanges InventoryChanges: {
QuestKeys: [
{
ItemType: typeName
}
]
}
}; };
} }
@ -666,6 +650,20 @@ export const updateCurrency = (
return currencyChanges; return currencyChanges;
}; };
export const updateCurrencyByAccountId = async (
price: number,
usePremium: boolean,
accountId: string
): Promise<ICurrencyChanges> => {
if (!isCurrencyTracked(usePremium)) {
return {};
}
const inventory = await getInventory(accountId);
const currencyChanges = updateCurrency(inventory, price, usePremium);
await inventory.save();
return currencyChanges;
};
const standingLimitBinToInventoryKey: Record< const standingLimitBinToInventoryKey: Record<
Exclude<TStandingLimitBin, "STANDING_LIMIT_BIN_NONE">, Exclude<TStandingLimitBin, "STANDING_LIMIT_BIN_NONE">,
keyof IDailyAffiliations keyof IDailyAffiliations
@ -825,17 +823,6 @@ const addMotorcycle = (
return inventoryChanges; return inventoryChanges;
}; };
const addDrone = (
inventory: TInventoryDatabaseDocument,
typeName: string,
inventoryChanges: IInventoryChanges = {}
): IInventoryChanges => {
const index = inventory.Drones.push({ ItemType: typeName, CurrentHP: ExportDrones[typeName].durability }) - 1;
inventoryChanges.Drones ??= [];
inventoryChanges.Drones.push(inventory.Drones[index].toJSON<IDroneClient>());
return inventoryChanges;
};
//TODO: wrong id is not erroring //TODO: wrong id is not erroring
export const addGearExpByCategory = ( export const addGearExpByCategory = (
inventory: TInventoryDatabaseDocument, inventory: TInventoryDatabaseDocument,

View File

@ -5,12 +5,7 @@ import { TInventoryDatabaseDocument } from "@/src/models/inventoryModels/invento
import { createMessage } from "@/src/services/inboxService"; import { createMessage } from "@/src/services/inboxService";
import { addItem, addKeyChainItems } from "@/src/services/inventoryService"; import { addItem, addKeyChainItems } from "@/src/services/inventoryService";
import { getKeyChainMessage, getLevelKeyRewards } from "@/src/services/itemDataService"; import { getKeyChainMessage, getLevelKeyRewards } from "@/src/services/itemDataService";
import { import { IInventoryDatabase, IQuestKeyDatabase, IQuestStage } from "@/src/types/inventoryTypes/inventoryTypes";
IInventoryDatabase,
IQuestKeyClient,
IQuestKeyDatabase,
IQuestStage
} from "@/src/types/inventoryTypes/inventoryTypes";
import { logger } from "@/src/utils/logger"; import { logger } from "@/src/utils/logger";
import { HydratedDocument } from "mongoose"; import { HydratedDocument } from "mongoose";
import { ExportKeys } from "warframe-public-export-plus"; import { ExportKeys } from "warframe-public-export-plus";
@ -74,14 +69,12 @@ export const updateQuestStage = (
Object.assign(questStage, questStageUpdate); Object.assign(questStage, questStageUpdate);
}; };
export const addQuestKey = (inventory: TInventoryDatabaseDocument, questKey: IQuestKeyDatabase) => { export const addQuestKey = (inventory: TInventoryDatabaseDocument, questKey: IQuestKeyDatabase): void => {
if (inventory.QuestKeys.some(q => q.ItemType === questKey.ItemType)) { if (inventory.QuestKeys.some(q => q.ItemType === questKey.ItemType)) {
logger.error(`quest key ${questKey.ItemType} already exists`); logger.error(`quest key ${questKey.ItemType} already exists`);
return; return;
} }
const index = inventory.QuestKeys.push(questKey); inventory.QuestKeys.push(questKey);
return inventory.QuestKeys[index - 1].toJSON<IQuestKeyClient>();
}; };
export const completeQuest = async (inventory: TInventoryDatabaseDocument, questKey: string) => { export const completeQuest = async (inventory: TInventoryDatabaseDocument, questKey: string) => {

View File

@ -39,7 +39,6 @@ export interface IInventoryDatabase
| "DialogueHistory" | "DialogueHistory"
| "KubrowPetEggs" | "KubrowPetEggs"
| "PendingCoupon" | "PendingCoupon"
| "Drones"
| TEquipmentKey | TEquipmentKey
>, >,
InventoryDatabaseEquipment { InventoryDatabaseEquipment {
@ -64,7 +63,6 @@ export interface IInventoryDatabase
DialogueHistory?: IDialogueHistoryDatabase; DialogueHistory?: IDialogueHistoryDatabase;
KubrowPetEggs?: IKubrowPetEggDatabase[]; KubrowPetEggs?: IKubrowPetEggDatabase[];
PendingCoupon?: IPendingCouponDatabase; PendingCoupon?: IPendingCouponDatabase;
Drones: IDroneDatabase[];
} }
export interface IQuestKeyDatabase { export interface IQuestKeyDatabase {
@ -260,7 +258,7 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu
Alignment: IAlignment; Alignment: IAlignment;
CompletedSorties: string[]; CompletedSorties: string[];
LastSortieReward: ILastSortieReward[]; LastSortieReward: ILastSortieReward[];
Drones: IDroneClient[]; Drones: IDrone[];
StepSequencers: IStepSequencer[]; StepSequencers: IStepSequencer[];
ActiveAvatarImageType: string; ActiveAvatarImageType: string;
ShipDecorations: IConsumable[]; ShipDecorations: IConsumable[];
@ -510,20 +508,13 @@ export interface IDiscoveredMarker {
discoveryState: number[]; discoveryState: number[];
} }
export interface IDroneClient { export interface IDrone {
ItemType: string; ItemType: string;
CurrentHP: number; CurrentHP: number;
ItemId: IOid; ItemId: IOid;
RepairStart?: IMongoDate; RepairStart?: IMongoDate;
} }
export interface IDroneDatabase {
ItemType: string;
CurrentHP: number;
_id: Types.ObjectId;
RepairStart?: Date;
}
export interface ITypeXPItem { export interface ITypeXPItem {
ItemType: string; ItemType: string;
XP: number; XP: number;

View File

@ -1,5 +1,5 @@
import { IEquipmentClient } from "./inventoryTypes/commonInventoryTypes"; import { IEquipmentClient } from "./inventoryTypes/commonInventoryTypes";
import { IDroneClient, IInfestedFoundryClient, TEquipmentKey } from "./inventoryTypes/inventoryTypes"; import { IInfestedFoundryClient, TEquipmentKey } from "./inventoryTypes/inventoryTypes";
export interface IPurchaseRequest { export interface IPurchaseRequest {
PurchaseParams: IPurchaseParams; PurchaseParams: IPurchaseParams;
@ -32,10 +32,10 @@ export type IInventoryChanges = {
[_ in SlotNames]?: IBinChanges; [_ in SlotNames]?: IBinChanges;
} & { } & {
[_ in TEquipmentKey]?: IEquipmentClient[]; [_ in TEquipmentKey]?: IEquipmentClient[];
} & ICurrencyChanges & { } & ICurrencyChanges & { InfestedFoundry?: IInfestedFoundryClient } & Record<
InfestedFoundry?: IInfestedFoundryClient; string,
Drones?: IDroneClient[]; IBinChanges | number | object[] | IInfestedFoundryClient
} & Record<string, IBinChanges | number | object[] | IInfestedFoundryClient>; >;
export interface IAffiliationMods { export interface IAffiliationMods {
Tag: string; Tag: string;