Compare commits

..

3 Commits

Author SHA1 Message Date
9de57668ab fix: ensure quest progress exists (#1000)
All checks were successful
Build Docker image / docker (push) Successful in 38s
Build / build (20) (push) Successful in 37s
Build / build (22) (push) Successful in 1m2s
Build / build (18) (push) Successful in 1m4s
Reviewed-on: #1000
Co-authored-by: OrdisPrime <134585663+OrdisPrime@users.noreply.github.com>
Co-committed-by: OrdisPrime <134585663+OrdisPrime@users.noreply.github.com>
2025-02-24 06:14:47 -08:00
ebb28d56d5 feat: acquisition of resource extractor drones (#998)
All checks were successful
Build / build (18) (push) Successful in 1m5s
Build / build (20) (push) Successful in 1m3s
Build / build (22) (push) Successful in 37s
Build Docker image / docker (push) Successful in 51s
Related to #793

Reviewed-on: #998
Co-authored-by: Sainan <sainan@calamity.inc>
Co-committed-by: Sainan <sainan@calamity.inc>
2025-02-24 05:28:43 -08:00
d69cba6bef chore: reuse inventory in claimCompletedRecipeController (#999)
Some checks failed
Build / build (20) (push) Successful in 41s
Build / build (18) (push) Has been cancelled
Build / build (22) (push) Has been cancelled
Build Docker image / docker (push) Has been cancelled
Reviewed-on: #999
Co-authored-by: Sainan <sainan@calamity.inc>
Co-committed-by: Sainan <sainan@calamity.inc>
2025-02-24 05:27:50 -08:00
6 changed files with 94 additions and 55 deletions

View File

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

View File

@ -68,7 +68,9 @@ import {
ICalendarProgress,
IPendingCouponDatabase,
IPendingCouponClient,
ILibraryAvailableDailyTaskInfo
ILibraryAvailableDailyTaskInfo,
IDroneDatabase,
IDroneClient
} from "../../types/inventoryTypes/inventoryTypes";
import { IOid } from "../../types/commonTypes";
import {
@ -349,6 +351,27 @@ const TypeXPItemSchema = new Schema<ITypeXPItem>(
{ _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>(
{
Progress: Number,
@ -509,7 +532,7 @@ const questProgressSchema = new Schema<IQuestStage>(
const questKeysSchema = new Schema<IQuestKeyDatabase>(
{
Progress: { type: [questProgressSchema], default: undefined },
Progress: { type: [questProgressSchema], default: [] },
unlock: Boolean,
Completed: Boolean,
CustomData: String,
@ -1148,8 +1171,8 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
CompletedSorties: [String],
LastSortieReward: [Schema.Types.Mixed],
//Resource_Drone[Uselees stuff]
Drones: [Schema.Types.Mixed],
// Resource Extractor Drones
Drones: [droneSchema],
//Active profile ico
ActiveAvatarImageType: String,
@ -1299,6 +1322,7 @@ export type InventoryDocumentProps = {
PendingRecipes: Types.DocumentArray<IPendingRecipeDatabase>;
WeaponSkins: Types.DocumentArray<IWeaponSkinDatabase>;
QuestKeys: Types.DocumentArray<IQuestKeyDatabase>;
Drones: Types.DocumentArray<IDroneDatabase>;
} & { [K in TEquipmentKey]: Types.DocumentArray<IEquipmentDatabase> };
// eslint-disable-next-line @typescript-eslint/ban-types

View File

@ -24,7 +24,8 @@ import {
IKubrowPetEggDatabase,
IKubrowPetEggClient,
ILibraryAvailableDailyTaskInfo,
ICalendarProgress
ICalendarProgress,
IDroneClient
} from "@/src/types/inventoryTypes/inventoryTypes";
import { IGenericUpdate } from "../types/genericUpdate";
import {
@ -38,6 +39,7 @@ import { IEquipmentClient, IEquipmentDatabase, IItemConfig } from "../types/inve
import {
ExportArcanes,
ExportCustoms,
ExportDrones,
ExportFlavour,
ExportFusionBundles,
ExportGear,
@ -56,7 +58,7 @@ import { IKeyChainRequest } from "@/src/controllers/api/giveKeyChainTriggeredIte
import { toOid } from "../helpers/inventoryHelpers";
import { generateRewardSeed } from "@/src/controllers/api/getNewRewardSeedController";
import { addStartingGear } from "@/src/controllers/api/giveStartingGearController";
import { completeQuest } from "@/src/services/questService";
import { addQuestKey, completeQuest } from "@/src/services/questService";
export const createInventory = async (
accountOwnerId: Types.ObjectId,
@ -325,15 +327,29 @@ export const addItem = async (
}
if (typeName in ExportKeys) {
// Note: "/Lotus/Types/Keys/" contains some EmailItems
inventory.QuestKeys.push({ ItemType: typeName });
return {
InventoryChanges: {
QuestKeys: [
{
ItemType: typeName
}
]
const key = ExportKeys[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 {
InventoryChanges: inventoryChanges
};
}
@ -650,20 +666,6 @@ export const updateCurrency = (
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<
Exclude<TStandingLimitBin, "STANDING_LIMIT_BIN_NONE">,
keyof IDailyAffiliations
@ -823,6 +825,17 @@ const addMotorcycle = (
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
export const addGearExpByCategory = (
inventory: TInventoryDatabaseDocument,

View File

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

View File

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

View File

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