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];
|
const snack = ExportMisc.helminthSnacks[contribution.ItemType];
|
||||||
|
|
||||||
// Note: Currently ignoring loss of apetite
|
// 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);
|
const resource = inventory.InfestedFoundry.Resources.find(x => x.ItemType == snack.type);
|
||||||
if (resource) {
|
if (resource) {
|
||||||
resource.Count += Math.trunc(snack.gain * 1000);
|
resource.Count += Math.trunc(snack.gain * 1000);
|
||||||
} else {
|
} else {
|
||||||
inventory.InfestedFoundry.Resources.push({
|
inventory.InfestedFoundry.Resources.push({
|
||||||
ItemType: snack.type,
|
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"
|
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[] = [];
|
const recipeChanges: ITypeCount[] = [];
|
||||||
infestedFoundry.XP ??= 0;
|
infestedFoundry.XP ??= 0;
|
||||||
const prevXP = infestedFoundry.XP;
|
const prevXP = infestedFoundry.XP;
|
||||||
|
@ -8,13 +8,16 @@ import {
|
|||||||
} from "@/src/types/inventoryTypes/commonInventoryTypes";
|
} from "@/src/types/inventoryTypes/commonInventoryTypes";
|
||||||
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
|
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
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 { getRecipeByResult } from "@/src/services/itemDataService";
|
||||||
|
import { IInventoryChanges } from "@/src/types/purchaseTypes";
|
||||||
|
import { addInfestedFoundryXP } from "./infestedFoundryController";
|
||||||
|
|
||||||
export const upgradesController: RequestHandler = async (req, res) => {
|
export const upgradesController: RequestHandler = async (req, res) => {
|
||||||
const accountId = await getAccountIdForRequest(req);
|
const accountId = await getAccountIdForRequest(req);
|
||||||
const payload = JSON.parse(String(req.body)) as IUpgradesRequest;
|
const payload = JSON.parse(String(req.body)) as IUpgradesRequest;
|
||||||
const inventory = await getInventory(accountId);
|
const inventory = await getInventory(accountId);
|
||||||
|
const inventoryChanges: IInventoryChanges = {};
|
||||||
for (const operation of payload.Operations) {
|
for (const operation of payload.Operations) {
|
||||||
if (
|
if (
|
||||||
operation.UpgradeRequirement == "/Lotus/Types/Items/MiscItems/ModSlotUnlocker" ||
|
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)!;
|
const suit = inventory.Suits.find(x => x._id.toString() == payload.ItemId.$oid)!;
|
||||||
|
|
||||||
let newAbilityOverride: IAbilityOverride | undefined;
|
let newAbilityOverride: IAbilityOverride | undefined;
|
||||||
|
let totalPercentagePointsConsumed = 0;
|
||||||
if (operation.UpgradeRequirement != "") {
|
if (operation.UpgradeRequirement != "") {
|
||||||
newAbilityOverride = {
|
newAbilityOverride = {
|
||||||
Ability: operation.UpgradeRequirement,
|
Ability: operation.UpgradeRequirement,
|
||||||
@ -43,6 +47,7 @@ export const upgradesController: RequestHandler = async (req, res) => {
|
|||||||
|
|
||||||
const recipe = getRecipeByResult(operation.UpgradeRequirement)!;
|
const recipe = getRecipeByResult(operation.UpgradeRequirement)!;
|
||||||
for (const ingredient of recipe.ingredients) {
|
for (const ingredient of recipe.ingredients) {
|
||||||
|
totalPercentagePointsConsumed += ingredient.ItemCount / 10;
|
||||||
inventory.InfestedFoundry!.Resources!.find(x => x.ItemType == ingredient.ItemType)!.Count -=
|
inventory.InfestedFoundry!.Resources!.find(x => x.ItemType == ingredient.ItemType)!.Count -=
|
||||||
ingredient.ItemCount;
|
ingredient.ItemCount;
|
||||||
}
|
}
|
||||||
@ -52,6 +57,12 @@ export const upgradesController: RequestHandler = async (req, res) => {
|
|||||||
suit.Configs[entry.Slot] ??= {};
|
suit.Configs[entry.Slot] ??= {};
|
||||||
suit.Configs[entry.Slot].AbilityOverride = newAbilityOverride;
|
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
|
} else
|
||||||
switch (operation.UpgradeRequirement) {
|
switch (operation.UpgradeRequirement) {
|
||||||
case "/Lotus/Types/Items/MiscItems/OrokinReactor":
|
case "/Lotus/Types/Items/MiscItems/OrokinReactor":
|
||||||
@ -146,7 +157,7 @@ export const upgradesController: RequestHandler = async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
await inventory.save();
|
await inventory.save();
|
||||||
res.json({ InventoryChanges: {} });
|
res.json({ InventoryChanges: inventoryChanges });
|
||||||
};
|
};
|
||||||
|
|
||||||
const setSlotPolarity = (item: IEquipmentDatabase, slot: number, polarity: ArtifactPolarity): void => {
|
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") {
|
} else if (typeof delta[key] == "object") {
|
||||||
console.assert(key.substring(-3) == "Bin");
|
console.assert(key.substring(-3) == "Bin");
|
||||||
|
console.assert(key != "InfestedFoundry");
|
||||||
const left = InventoryChanges[key] as IBinChanges;
|
const left = InventoryChanges[key] as IBinChanges;
|
||||||
const right: IBinChanges = delta[key];
|
const right = delta[key] as IBinChanges;
|
||||||
left.count += right.count;
|
left.count += right.count;
|
||||||
left.platinum += right.platinum;
|
left.platinum += right.platinum;
|
||||||
left.Slots += right.Slots;
|
left.Slots += right.Slots;
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { IInfestedFoundry } from "./inventoryTypes/inventoryTypes";
|
||||||
|
|
||||||
export interface IPurchaseRequest {
|
export interface IPurchaseRequest {
|
||||||
PurchaseParams: IPurchaseParams;
|
PurchaseParams: IPurchaseParams;
|
||||||
buildLabel: string;
|
buildLabel: string;
|
||||||
@ -25,8 +27,10 @@ export interface ICurrencyChanges {
|
|||||||
|
|
||||||
export type IInventoryChanges = {
|
export type IInventoryChanges = {
|
||||||
[_ in SlotNames]?: IBinChanges;
|
[_ in SlotNames]?: IBinChanges;
|
||||||
} & ICurrencyChanges &
|
} & ICurrencyChanges & { InfestedFoundry?: IInfestedFoundry } & Record<
|
||||||
Record<string, IBinChanges | number | object[]>;
|
string,
|
||||||
|
IBinChanges | number | object[] | IInfestedFoundry
|
||||||
|
>;
|
||||||
|
|
||||||
export interface IPurchaseResponse {
|
export interface IPurchaseResponse {
|
||||||
InventoryChanges: IInventoryChanges;
|
InventoryChanges: IInventoryChanges;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user