improve IInventoryChanges typings
All checks were successful
Build / build (18) (push) Successful in 41s
Build / build (20) (push) Successful in 49s
Build / build (18) (pull_request) Successful in 39s
Build / build (22) (push) Successful in 56s
Build / build (20) (pull_request) Successful in 49s
Build / build (22) (pull_request) Successful in 37s
All checks were successful
Build / build (18) (push) Successful in 41s
Build / build (20) (push) Successful in 49s
Build / build (18) (pull_request) Successful in 39s
Build / build (22) (push) Successful in 56s
Build / build (20) (pull_request) Successful in 49s
Build / build (22) (pull_request) Successful in 37s
This commit is contained in:
parent
7f6bb5f6cc
commit
ce79b2240a
@ -54,10 +54,8 @@ export const guildTechController: RequestHandler = async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
addMiscItems(inventory, miscItemChanges);
|
addMiscItems(inventory, miscItemChanges);
|
||||||
const inventoryChanges: IInventoryChanges = {
|
const inventoryChanges: IInventoryChanges = updateCurrency(inventory, contributions.RegularCredits, false);
|
||||||
...updateCurrency(inventory, contributions.RegularCredits, false),
|
inventoryChanges.MiscItems = miscItemChanges;
|
||||||
MiscItems: miscItemChanges
|
|
||||||
};
|
|
||||||
|
|
||||||
if (techProject.ReqCredits == 0 && !techProject.ReqItems.find(x => x.ItemCount > 0)) {
|
if (techProject.ReqCredits == 0 && !techProject.ReqItems.find(x => x.ItemCount > 0)) {
|
||||||
// This research is now fully funded.
|
// This research is now fully funded.
|
||||||
|
@ -5,7 +5,7 @@ import {
|
|||||||
} from "@/src/models/inventoryModels/inventoryModel";
|
} from "@/src/models/inventoryModels/inventoryModel";
|
||||||
import { config } from "@/src/services/configService";
|
import { config } from "@/src/services/configService";
|
||||||
import { HydratedDocument, Types } from "mongoose";
|
import { HydratedDocument, Types } from "mongoose";
|
||||||
import { SlotNames, IInventoryChanges, IBinChanges, ICurrencyChanges } from "@/src/types/purchaseTypes";
|
import { SlotNames, IInventoryChanges, IBinChanges, slotNames } from "@/src/types/purchaseTypes";
|
||||||
import {
|
import {
|
||||||
IChallengeProgress,
|
IChallengeProgress,
|
||||||
IConsumable,
|
IConsumable,
|
||||||
@ -26,8 +26,7 @@ import {
|
|||||||
ILibraryDailyTaskInfo,
|
ILibraryDailyTaskInfo,
|
||||||
ICalendarProgress,
|
ICalendarProgress,
|
||||||
IDroneClient,
|
IDroneClient,
|
||||||
IUpgradeClient,
|
IUpgradeClient
|
||||||
ISlots
|
|
||||||
} from "@/src/types/inventoryTypes/inventoryTypes";
|
} from "@/src/types/inventoryTypes/inventoryTypes";
|
||||||
import { IGenericUpdate } from "../types/genericUpdate";
|
import { IGenericUpdate } from "../types/genericUpdate";
|
||||||
import {
|
import {
|
||||||
@ -127,13 +126,17 @@ export const combineInventoryChanges = (InventoryChanges: IInventoryChanges, del
|
|||||||
for (const item of right) {
|
for (const item of right) {
|
||||||
left.push(item);
|
left.push(item);
|
||||||
}
|
}
|
||||||
} else if (typeof delta[key] == "object") {
|
} else if (slotNames.indexOf(key as SlotNames) != -1) {
|
||||||
console.assert(key.substring(-3) == "Bin");
|
const left = InventoryChanges[key as SlotNames]!;
|
||||||
console.assert(key != "InfestedFoundry");
|
const right = delta[key as SlotNames]!;
|
||||||
const left = InventoryChanges[key] as IBinChanges;
|
if (right.count) {
|
||||||
const right = delta[key] as IBinChanges;
|
left.count ??= 0;
|
||||||
left.count += right.count;
|
left.count += right.count;
|
||||||
left.platinum += right.platinum;
|
}
|
||||||
|
if (right.platinum) {
|
||||||
|
left.platinum ??= 0;
|
||||||
|
left.platinum += right.platinum;
|
||||||
|
}
|
||||||
left.Slots += right.Slots;
|
left.Slots += right.Slots;
|
||||||
if (right.Extra) {
|
if (right.Extra) {
|
||||||
left.Extra ??= 0;
|
left.Extra ??= 0;
|
||||||
@ -176,9 +179,9 @@ const occupySlot = (
|
|||||||
slotChanges.Slots -= 1;
|
slotChanges.Slots -= 1;
|
||||||
}
|
}
|
||||||
updateSlots(inventory, bin, slotChanges.Slots, slotChanges.Extra);
|
updateSlots(inventory, bin, slotChanges.Slots, slotChanges.Extra);
|
||||||
return {
|
const inventoryChanges: IInventoryChanges = {};
|
||||||
[bin]: slotChanges satisfies ISlots
|
inventoryChanges[bin] = slotChanges satisfies IBinChanges;
|
||||||
};
|
return inventoryChanges;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addItem = async (
|
export const addItem = async (
|
||||||
@ -325,7 +328,7 @@ export const addItem = async (
|
|||||||
const inventoryChanges = addEquipment(inventory, weapon.productCategory, typeName);
|
const inventoryChanges = addEquipment(inventory, weapon.productCategory, typeName);
|
||||||
if (weapon.additionalItems) {
|
if (weapon.additionalItems) {
|
||||||
for (const item of weapon.additionalItems) {
|
for (const item of weapon.additionalItems) {
|
||||||
combineInventoryChanges(inventoryChanges, await addItem(inventory, item, 1));
|
combineInventoryChanges(inventoryChanges, (await addItem(inventory, item, 1)).InventoryChanges);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
@ -684,8 +687,8 @@ export const updateCurrency = (
|
|||||||
inventory: TInventoryDatabaseDocument,
|
inventory: TInventoryDatabaseDocument,
|
||||||
price: number,
|
price: number,
|
||||||
usePremium: boolean
|
usePremium: boolean
|
||||||
): ICurrencyChanges => {
|
): IInventoryChanges => {
|
||||||
const currencyChanges: ICurrencyChanges = {};
|
const currencyChanges: IInventoryChanges = {};
|
||||||
if (price != 0 && isCurrencyTracked(usePremium)) {
|
if (price != 0 && isCurrencyTracked(usePremium)) {
|
||||||
if (usePremium) {
|
if (usePremium) {
|
||||||
if (inventory.PremiumCreditsFree > 0) {
|
if (inventory.PremiumCreditsFree > 0) {
|
||||||
|
@ -164,7 +164,7 @@ export const handlePurchase = async (
|
|||||||
addMiscItems(inventory, [invItem]);
|
addMiscItems(inventory, [invItem]);
|
||||||
|
|
||||||
purchaseResponse.InventoryChanges.MiscItems ??= [];
|
purchaseResponse.InventoryChanges.MiscItems ??= [];
|
||||||
(purchaseResponse.InventoryChanges.MiscItems as IMiscItem[]).push(invItem);
|
purchaseResponse.InventoryChanges.MiscItems.push(invItem);
|
||||||
} else if (!config.infiniteRegalAya) {
|
} else if (!config.infiniteRegalAya) {
|
||||||
inventory.PrimeTokens -= offer.PrimePrice! * purchaseRequest.PurchaseParams.Quantity;
|
inventory.PrimeTokens -= offer.PrimePrice! * purchaseRequest.PurchaseParams.Quantity;
|
||||||
}
|
}
|
||||||
@ -191,11 +191,11 @@ const handleItemPrices = (
|
|||||||
addMiscItems(inventory, [invItem]);
|
addMiscItems(inventory, [invItem]);
|
||||||
|
|
||||||
inventoryChanges.MiscItems ??= [];
|
inventoryChanges.MiscItems ??= [];
|
||||||
const change = (inventoryChanges.MiscItems as IMiscItem[]).find(x => x.ItemType == item.ItemType);
|
const change = inventoryChanges.MiscItems.find(x => x.ItemType == item.ItemType);
|
||||||
if (change) {
|
if (change) {
|
||||||
change.ItemCount += invItem.ItemCount;
|
change.ItemCount += invItem.ItemCount;
|
||||||
} else {
|
} else {
|
||||||
(inventoryChanges.MiscItems as IMiscItem[]).push(invItem);
|
inventoryChanges.MiscItems.push(invItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -300,16 +300,14 @@ const handleSlotPurchase = (
|
|||||||
|
|
||||||
logger.debug(`added ${slotsPurchased} slot ${slotName}`);
|
logger.debug(`added ${slotsPurchased} slot ${slotName}`);
|
||||||
|
|
||||||
return {
|
const inventoryChanges: IInventoryChanges = {};
|
||||||
InventoryChanges: {
|
inventoryChanges[slotName] = {
|
||||||
[slotName]: {
|
count: 0,
|
||||||
count: 0,
|
platinum: 1,
|
||||||
platinum: 1,
|
Slots: slotsPurchased,
|
||||||
Slots: slotsPurchased,
|
Extra: slotsPurchased
|
||||||
Extra: slotsPurchased
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
return { InventoryChanges: inventoryChanges };
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleBoosterPackPurchase = async (
|
const handleBoosterPackPurchase = async (
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { IEquipmentClient } from "./inventoryTypes/commonInventoryTypes";
|
import { IEquipmentClient } from "./inventoryTypes/commonInventoryTypes";
|
||||||
import { IDroneClient, IInfestedFoundryClient, TEquipmentKey } from "./inventoryTypes/inventoryTypes";
|
import { IDroneClient, IInfestedFoundryClient, IMiscItem, TEquipmentKey } from "./inventoryTypes/inventoryTypes";
|
||||||
|
|
||||||
export interface IPurchaseRequest {
|
export interface IPurchaseRequest {
|
||||||
PurchaseParams: IPurchaseParams;
|
PurchaseParams: IPurchaseParams;
|
||||||
@ -22,20 +22,31 @@ export interface IPurchaseParams {
|
|||||||
IsWeekly?: boolean; // for Source 7
|
IsWeekly?: boolean; // for Source 7
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ICurrencyChanges {
|
|
||||||
RegularCredits?: number;
|
|
||||||
PremiumCredits?: number;
|
|
||||||
PremiumCreditsFree?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type IInventoryChanges = {
|
export type IInventoryChanges = {
|
||||||
[_ in SlotNames]?: IBinChanges;
|
[_ in SlotNames]?: IBinChanges;
|
||||||
} & {
|
} & {
|
||||||
[_ in TEquipmentKey]?: IEquipmentClient[];
|
[_ in TEquipmentKey]?: IEquipmentClient[];
|
||||||
} & ICurrencyChanges & {
|
} & {
|
||||||
InfestedFoundry?: IInfestedFoundryClient;
|
RegularCredits?: number;
|
||||||
Drones?: IDroneClient[];
|
PremiumCredits?: number;
|
||||||
} & Record<string, IBinChanges | number | object[] | IInfestedFoundryClient>;
|
PremiumCreditsFree?: number;
|
||||||
|
InfestedFoundry?: IInfestedFoundryClient;
|
||||||
|
Drones?: IDroneClient[];
|
||||||
|
MiscItems?: IMiscItem[];
|
||||||
|
} & Record<
|
||||||
|
Exclude<
|
||||||
|
string,
|
||||||
|
| SlotNames
|
||||||
|
| TEquipmentKey
|
||||||
|
| "RegularCredits"
|
||||||
|
| "PremiumCredits"
|
||||||
|
| "PremiumCreditsFree"
|
||||||
|
| "InfestedFoundry"
|
||||||
|
| "Drones"
|
||||||
|
| "MiscItems"
|
||||||
|
>,
|
||||||
|
number | object[]
|
||||||
|
>;
|
||||||
|
|
||||||
export interface IAffiliationMods {
|
export interface IAffiliationMods {
|
||||||
Tag: string;
|
Tag: string;
|
||||||
@ -51,8 +62,8 @@ export interface IPurchaseResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type IBinChanges = {
|
export type IBinChanges = {
|
||||||
count: number;
|
count?: number;
|
||||||
platinum: number;
|
platinum?: number;
|
||||||
Slots: number;
|
Slots: number;
|
||||||
Extra?: number;
|
Extra?: number;
|
||||||
};
|
};
|
||||||
@ -69,18 +80,21 @@ export type SlotPurchaseName =
|
|||||||
| "TwoCrewShipSalvageSlotItem"
|
| "TwoCrewShipSalvageSlotItem"
|
||||||
| "CrewMemberSlotItem";
|
| "CrewMemberSlotItem";
|
||||||
|
|
||||||
export type SlotNames =
|
export const slotNames = [
|
||||||
| "SuitBin"
|
"SuitBin",
|
||||||
| "WeaponBin"
|
"WeaponBin",
|
||||||
| "MechBin"
|
"MechBin",
|
||||||
| "PveBonusLoadoutBin"
|
"PveBonusLoadoutBin",
|
||||||
| "SentinelBin"
|
"SentinelBin",
|
||||||
| "SpaceSuitBin"
|
"SpaceSuitBin",
|
||||||
| "SpaceWeaponBin"
|
"SpaceWeaponBin",
|
||||||
| "OperatorAmpBin"
|
"OperatorAmpBin",
|
||||||
| "RandomModBin"
|
"RandomModBin",
|
||||||
| "CrewShipSalvageBin"
|
"CrewShipSalvageBin",
|
||||||
| "CrewMemberBin";
|
"CrewMemberBin"
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export type SlotNames = (typeof slotNames)[number];
|
||||||
|
|
||||||
export type SlotPurchase = {
|
export type SlotPurchase = {
|
||||||
[P in SlotPurchaseName]: { name: SlotNames; slotsPerPurchase: number };
|
[P in SlotPurchaseName]: { name: SlotNames; slotsPerPurchase: number };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user