fix: properly handle ability infusion XP & response
This commit is contained in:
parent
d372141b06
commit
08da860cb0
@ -71,14 +71,14 @@ export const infestedFoundryController: RequestHandler = async (req, res) => {
|
||||
const snack = ExportMisc.helminthSnacks[contribution.ItemType];
|
||||
|
||||
// Note: Currently ignoring loss of apetite
|
||||
totalPercentagePointsGained += snack.gain / 0.01;
|
||||
totalPercentagePointsGained += snack.gain * 100; // 30% would be gain=0.3, so percentage points is equal to gain * 100.
|
||||
const resource = inventory.InfestedFoundry.Resources.find(x => x.ItemType == snack.type);
|
||||
if (resource) {
|
||||
resource.Count += Math.trunc(snack.gain * 1000);
|
||||
} else {
|
||||
inventory.InfestedFoundry.Resources.push({
|
||||
ItemType: snack.type,
|
||||
Count: Math.trunc(snack.gain * 1000)
|
||||
Count: Math.trunc(snack.gain * 1000) // 30% would be gain=0.3 or Count=300, so Count=gain*1000.
|
||||
});
|
||||
}
|
||||
|
||||
@ -261,7 +261,7 @@ const colorToShard: Record<string, string> = {
|
||||
ACC_PURPLE_MYTHIC: "/Lotus/Types/Gameplay/NarmerSorties/ArchonCrystalVioletMythic"
|
||||
};
|
||||
|
||||
const addInfestedFoundryXP = (infestedFoundry: IInfestedFoundry, delta: number): ITypeCount[] => {
|
||||
export const addInfestedFoundryXP = (infestedFoundry: IInfestedFoundry, delta: number): ITypeCount[] => {
|
||||
const recipeChanges: ITypeCount[] = [];
|
||||
infestedFoundry.XP ??= 0;
|
||||
const prevXP = infestedFoundry.XP;
|
||||
|
@ -8,13 +8,16 @@ import {
|
||||
} from "@/src/types/inventoryTypes/commonInventoryTypes";
|
||||
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import { addMiscItems, getInventory, updateCurrency } from "@/src/services/inventoryService";
|
||||
import { addMiscItems, addRecipes, getInventory, updateCurrency } from "@/src/services/inventoryService";
|
||||
import { getRecipeByResult } from "@/src/services/itemDataService";
|
||||
import { IInventoryChanges } from "@/src/types/purchaseTypes";
|
||||
import { addInfestedFoundryXP } from "./infestedFoundryController";
|
||||
|
||||
export const upgradesController: RequestHandler = async (req, res) => {
|
||||
const accountId = await getAccountIdForRequest(req);
|
||||
const payload = JSON.parse(String(req.body)) as IUpgradesRequest;
|
||||
const inventory = await getInventory(accountId);
|
||||
const inventoryChanges: IInventoryChanges = {};
|
||||
for (const operation of payload.Operations) {
|
||||
if (
|
||||
operation.UpgradeRequirement == "/Lotus/Types/Items/MiscItems/ModSlotUnlocker" ||
|
||||
@ -35,6 +38,7 @@ export const upgradesController: RequestHandler = async (req, res) => {
|
||||
const suit = inventory.Suits.find(x => x._id.toString() == payload.ItemId.$oid)!;
|
||||
|
||||
let newAbilityOverride: IAbilityOverride | undefined;
|
||||
let totalPercentagePointsConsumed = 0;
|
||||
if (operation.UpgradeRequirement != "") {
|
||||
newAbilityOverride = {
|
||||
Ability: operation.UpgradeRequirement,
|
||||
@ -43,6 +47,7 @@ export const upgradesController: RequestHandler = async (req, res) => {
|
||||
|
||||
const recipe = getRecipeByResult(operation.UpgradeRequirement)!;
|
||||
for (const ingredient of recipe.ingredients) {
|
||||
totalPercentagePointsConsumed += ingredient.ItemCount / 10;
|
||||
inventory.InfestedFoundry!.Resources!.find(x => x.ItemType == ingredient.ItemType)!.Count -=
|
||||
ingredient.ItemCount;
|
||||
}
|
||||
@ -52,6 +57,12 @@ export const upgradesController: RequestHandler = async (req, res) => {
|
||||
suit.Configs[entry.Slot] ??= {};
|
||||
suit.Configs[entry.Slot].AbilityOverride = newAbilityOverride;
|
||||
}
|
||||
|
||||
const recipeChanges = addInfestedFoundryXP(inventory.InfestedFoundry!, totalPercentagePointsConsumed * 8);
|
||||
addRecipes(inventory, recipeChanges);
|
||||
|
||||
inventoryChanges.Recipes = recipeChanges;
|
||||
inventoryChanges.InfestedFoundry = inventory.toJSON().InfestedFoundry;
|
||||
} else
|
||||
switch (operation.UpgradeRequirement) {
|
||||
case "/Lotus/Types/Items/MiscItems/OrokinReactor":
|
||||
@ -146,7 +157,7 @@ export const upgradesController: RequestHandler = async (req, res) => {
|
||||
}
|
||||
}
|
||||
await inventory.save();
|
||||
res.json({ InventoryChanges: {} });
|
||||
res.json({ InventoryChanges: inventoryChanges });
|
||||
};
|
||||
|
||||
const setSlotPolarity = (item: IEquipmentDatabase, slot: number, polarity: ArtifactPolarity): void => {
|
||||
|
@ -79,8 +79,9 @@ export const combineInventoryChanges = (InventoryChanges: IInventoryChanges, del
|
||||
}
|
||||
} else if (typeof delta[key] == "object") {
|
||||
console.assert(key.substring(-3) == "Bin");
|
||||
console.assert(key != "InfestedFoundry");
|
||||
const left = InventoryChanges[key] as IBinChanges;
|
||||
const right: IBinChanges = delta[key];
|
||||
const right = delta[key] as IBinChanges;
|
||||
left.count += right.count;
|
||||
left.platinum += right.platinum;
|
||||
left.Slots += right.Slots;
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { IInfestedFoundry } from "./inventoryTypes/inventoryTypes";
|
||||
|
||||
export interface IPurchaseRequest {
|
||||
PurchaseParams: IPurchaseParams;
|
||||
buildLabel: string;
|
||||
@ -25,8 +27,10 @@ export interface ICurrencyChanges {
|
||||
|
||||
export type IInventoryChanges = {
|
||||
[_ in SlotNames]?: IBinChanges;
|
||||
} & ICurrencyChanges &
|
||||
Record<string, IBinChanges | number | object[]>;
|
||||
} & ICurrencyChanges & { InfestedFoundry?: IInfestedFoundry } & Record<
|
||||
string,
|
||||
IBinChanges | number | object[] | IInfestedFoundry
|
||||
>;
|
||||
|
||||
export interface IPurchaseResponse {
|
||||
InventoryChanges: IInventoryChanges;
|
||||
|
Loading…
x
Reference in New Issue
Block a user