2024-05-16 01:34:38 +02:00
|
|
|
import { RequestHandler } from "express";
|
2025-03-14 07:09:28 -07:00
|
|
|
import {
|
2025-03-31 04:14:00 -07:00
|
|
|
addGuildMemberMiscItemContribution,
|
2025-03-14 07:09:28 -07:00
|
|
|
getGuildForRequestEx,
|
|
|
|
getGuildVault,
|
|
|
|
hasAccessToDojo,
|
|
|
|
hasGuildPermission,
|
2025-03-30 09:58:51 -07:00
|
|
|
processFundedGuildTechProject,
|
|
|
|
processGuildTechProjectContributionsUpdate,
|
2025-03-16 04:32:11 -07:00
|
|
|
removePigmentsFromGuildMembers,
|
2025-03-30 09:58:51 -07:00
|
|
|
scaleRequiredCount,
|
|
|
|
setGuildTechLogState
|
2025-03-14 07:09:28 -07:00
|
|
|
} from "@/src/services/guildService";
|
2025-03-30 09:58:51 -07:00
|
|
|
import { ExportDojoRecipes } from "warframe-public-export-plus";
|
2025-01-03 09:06:50 +01:00
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
2025-03-11 07:56:18 -07:00
|
|
|
import {
|
2025-04-16 06:31:00 -07:00
|
|
|
addCrewShipWeaponSkin,
|
2025-04-17 07:59:42 -07:00
|
|
|
addEquipment,
|
2025-03-11 07:56:18 -07:00
|
|
|
addItem,
|
|
|
|
addMiscItems,
|
|
|
|
addRecipes,
|
|
|
|
combineInventoryChanges,
|
|
|
|
getInventory,
|
2025-04-16 06:31:00 -07:00
|
|
|
occupySlot,
|
2025-03-11 07:56:18 -07:00
|
|
|
updateCurrency
|
|
|
|
} from "@/src/services/inventoryService";
|
2025-04-16 06:31:00 -07:00
|
|
|
import { IMiscItem, InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes";
|
2025-01-03 09:06:50 +01:00
|
|
|
import { IInventoryChanges } from "@/src/types/purchaseTypes";
|
2025-02-28 12:35:14 -08:00
|
|
|
import { config } from "@/src/services/configService";
|
2025-03-30 09:58:51 -07:00
|
|
|
import { GuildPermission, ITechProjectClient } from "@/src/types/guildTypes";
|
|
|
|
import { GuildMember } from "@/src/models/guildModel";
|
2025-04-16 10:38:53 -07:00
|
|
|
import { toMongoDate, toOid } from "@/src/helpers/inventoryHelpers";
|
2025-03-20 05:36:09 -07:00
|
|
|
import { logger } from "@/src/utils/logger";
|
2025-04-16 06:31:00 -07:00
|
|
|
import { TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
|
2024-05-16 01:34:38 +02:00
|
|
|
|
2025-01-03 09:06:50 +01:00
|
|
|
export const guildTechController: RequestHandler = async (req, res) => {
|
|
|
|
const accountId = await getAccountIdForRequest(req);
|
|
|
|
const inventory = await getInventory(accountId);
|
|
|
|
const data = JSON.parse(String(req.body)) as TGuildTechRequest;
|
2025-03-16 04:32:11 -07:00
|
|
|
if (data.Action == "Sync") {
|
2025-03-12 07:59:20 -07:00
|
|
|
let needSave = false;
|
|
|
|
const techProjects: ITechProjectClient[] = [];
|
2025-04-13 05:51:15 -07:00
|
|
|
const guild = await getGuildForRequestEx(req, inventory);
|
2025-03-12 07:59:20 -07:00
|
|
|
if (guild.TechProjects) {
|
|
|
|
for (const project of guild.TechProjects) {
|
|
|
|
const techProject: ITechProjectClient = {
|
|
|
|
ItemType: project.ItemType,
|
|
|
|
ReqCredits: project.ReqCredits,
|
|
|
|
ReqItems: project.ReqItems,
|
|
|
|
State: project.State
|
|
|
|
};
|
|
|
|
if (project.CompletionDate) {
|
|
|
|
techProject.CompletionDate = toMongoDate(project.CompletionDate);
|
|
|
|
if (Date.now() >= project.CompletionDate.getTime()) {
|
2025-03-30 09:58:51 -07:00
|
|
|
needSave ||= setGuildTechLogState(guild, project.ItemType, 4, project.CompletionDate);
|
2025-03-12 07:59:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
techProjects.push(techProject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (needSave) {
|
|
|
|
await guild.save();
|
|
|
|
}
|
|
|
|
res.json({ TechProjects: techProjects });
|
2025-03-16 04:32:11 -07:00
|
|
|
} else if (data.Action == "Start") {
|
2025-04-13 05:51:15 -07:00
|
|
|
if (data.Mode == "Guild") {
|
|
|
|
const guild = await getGuildForRequestEx(req, inventory);
|
|
|
|
if (!hasAccessToDojo(inventory) || !(await hasGuildPermission(guild, accountId, GuildPermission.Tech))) {
|
|
|
|
res.status(400).send("-1").end();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const recipe = ExportDojoRecipes.research[data.RecipeType];
|
|
|
|
guild.TechProjects ??= [];
|
|
|
|
if (!guild.TechProjects.find(x => x.ItemType == data.RecipeType)) {
|
|
|
|
const techProject =
|
|
|
|
guild.TechProjects[
|
|
|
|
guild.TechProjects.push({
|
|
|
|
ItemType: data.RecipeType,
|
|
|
|
ReqCredits: config.noDojoResearchCosts ? 0 : scaleRequiredCount(guild.Tier, recipe.price),
|
|
|
|
ReqItems: recipe.ingredients.map(x => ({
|
|
|
|
ItemType: x.ItemType,
|
|
|
|
ItemCount: config.noDojoResearchCosts ? 0 : scaleRequiredCount(guild.Tier, x.ItemCount)
|
|
|
|
})),
|
|
|
|
State: 0
|
|
|
|
}) - 1
|
|
|
|
];
|
|
|
|
setGuildTechLogState(guild, techProject.ItemType, 5);
|
|
|
|
if (config.noDojoResearchCosts) {
|
|
|
|
processFundedGuildTechProject(guild, techProject, recipe);
|
|
|
|
} else {
|
|
|
|
if (data.RecipeType.substring(0, 39) == "/Lotus/Types/Items/Research/DojoColors/") {
|
|
|
|
guild.ActiveDojoColorResearch = data.RecipeType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await guild.save();
|
|
|
|
res.end();
|
|
|
|
} else {
|
|
|
|
const recipe = ExportDojoRecipes.research[data.RecipeType];
|
2025-04-17 10:50:24 -07:00
|
|
|
if (data.TechProductCategory) {
|
|
|
|
if (
|
|
|
|
data.TechProductCategory != "CrewShipWeapons" &&
|
|
|
|
data.TechProductCategory != "CrewShipWeaponSkins"
|
|
|
|
) {
|
|
|
|
throw new Error(`unexpected TechProductCategory: ${data.TechProductCategory}`);
|
|
|
|
}
|
|
|
|
if (!inventory[getSalvageCategory(data.TechProductCategory)].id(data.CategoryItemId)) {
|
|
|
|
throw new Error(
|
|
|
|
`no item with id ${data.CategoryItemId} in ${getSalvageCategory(data.TechProductCategory)} array`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2025-02-28 12:35:14 -08:00
|
|
|
const techProject =
|
2025-04-13 05:51:15 -07:00
|
|
|
inventory.PersonalTechProjects[
|
|
|
|
inventory.PersonalTechProjects.push({
|
|
|
|
State: 0,
|
|
|
|
ReqCredits: recipe.price,
|
2025-03-16 04:32:11 -07:00
|
|
|
ItemType: data.RecipeType,
|
2025-04-16 06:31:00 -07:00
|
|
|
ProductCategory: data.TechProductCategory,
|
|
|
|
CategoryItemId: data.CategoryItemId,
|
2025-04-13 05:51:15 -07:00
|
|
|
ReqItems: recipe.ingredients
|
2025-02-28 12:35:14 -08:00
|
|
|
}) - 1
|
|
|
|
];
|
2025-04-13 05:51:15 -07:00
|
|
|
await inventory.save();
|
|
|
|
res.json({
|
|
|
|
isPersonal: true,
|
|
|
|
action: "Start",
|
|
|
|
personalTech: techProject.toJSON()
|
|
|
|
});
|
2025-01-03 09:06:50 +01:00
|
|
|
}
|
2025-03-16 04:32:11 -07:00
|
|
|
} else if (data.Action == "Contribute") {
|
2025-04-13 05:51:15 -07:00
|
|
|
if ((req.query.guildId as string) == "000000000000000000000000") {
|
|
|
|
const techProject = inventory.PersonalTechProjects.id(data.ResearchId)!;
|
|
|
|
|
|
|
|
techProject.ReqCredits -= data.RegularCredits;
|
|
|
|
const inventoryChanges: IInventoryChanges = updateCurrency(inventory, data.RegularCredits, false);
|
|
|
|
|
|
|
|
const miscItemChanges = [];
|
|
|
|
for (const miscItem of data.MiscItems) {
|
|
|
|
const reqItem = techProject.ReqItems.find(x => x.ItemType == miscItem.ItemType);
|
|
|
|
if (reqItem) {
|
|
|
|
if (miscItem.ItemCount > reqItem.ItemCount) {
|
|
|
|
miscItem.ItemCount = reqItem.ItemCount;
|
|
|
|
}
|
|
|
|
reqItem.ItemCount -= miscItem.ItemCount;
|
|
|
|
miscItemChanges.push({
|
|
|
|
ItemType: miscItem.ItemType,
|
|
|
|
ItemCount: miscItem.ItemCount * -1
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
addMiscItems(inventory, miscItemChanges);
|
|
|
|
inventoryChanges.MiscItems = miscItemChanges;
|
2025-03-27 03:33:08 -07:00
|
|
|
|
2025-04-13 05:51:15 -07:00
|
|
|
techProject.HasContributions = true;
|
2025-03-27 03:33:08 -07:00
|
|
|
|
2025-04-13 05:51:15 -07:00
|
|
|
if (techProject.ReqCredits == 0 && !techProject.ReqItems.find(x => x.ItemCount > 0)) {
|
|
|
|
techProject.State = 1;
|
|
|
|
const recipe = ExportDojoRecipes.research[techProject.ItemType];
|
|
|
|
techProject.CompletionDate = new Date(Date.now() + recipe.time * 1000);
|
|
|
|
}
|
2025-03-06 21:24:25 -08:00
|
|
|
|
2025-04-13 05:51:15 -07:00
|
|
|
await inventory.save();
|
|
|
|
res.json({
|
|
|
|
InventoryChanges: inventoryChanges,
|
|
|
|
PersonalResearch: { $oid: data.ResearchId },
|
|
|
|
PersonalResearchDate: techProject.CompletionDate ? toMongoDate(techProject.CompletionDate) : undefined
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (!hasAccessToDojo(inventory)) {
|
|
|
|
res.status(400).send("-1").end();
|
|
|
|
return;
|
2025-03-06 21:24:25 -08:00
|
|
|
}
|
|
|
|
|
2025-04-13 05:51:15 -07:00
|
|
|
const guild = await getGuildForRequestEx(req, inventory);
|
|
|
|
const guildMember = (await GuildMember.findOne(
|
|
|
|
{ accountId, guildId: guild._id },
|
|
|
|
"RegularCreditsContributed MiscItemsContributed"
|
|
|
|
))!;
|
|
|
|
|
|
|
|
const techProject = guild.TechProjects!.find(x => x.ItemType == data.RecipeType)!;
|
|
|
|
|
|
|
|
if (data.VaultCredits) {
|
|
|
|
if (data.VaultCredits > techProject.ReqCredits) {
|
|
|
|
data.VaultCredits = techProject.ReqCredits;
|
|
|
|
}
|
|
|
|
techProject.ReqCredits -= data.VaultCredits;
|
|
|
|
guild.VaultRegularCredits! -= data.VaultCredits;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.RegularCredits > techProject.ReqCredits) {
|
|
|
|
data.RegularCredits = techProject.ReqCredits;
|
|
|
|
}
|
|
|
|
techProject.ReqCredits -= data.RegularCredits;
|
|
|
|
|
|
|
|
guildMember.RegularCreditsContributed ??= 0;
|
|
|
|
guildMember.RegularCreditsContributed += data.RegularCredits;
|
2025-03-06 21:24:25 -08:00
|
|
|
|
2025-04-13 05:51:15 -07:00
|
|
|
if (data.VaultMiscItems.length) {
|
|
|
|
for (const miscItem of data.VaultMiscItems) {
|
|
|
|
const reqItem = techProject.ReqItems.find(x => x.ItemType == miscItem.ItemType);
|
|
|
|
if (reqItem) {
|
|
|
|
if (miscItem.ItemCount > reqItem.ItemCount) {
|
|
|
|
miscItem.ItemCount = reqItem.ItemCount;
|
|
|
|
}
|
|
|
|
reqItem.ItemCount -= miscItem.ItemCount;
|
2025-03-27 03:33:08 -07:00
|
|
|
|
2025-04-13 05:51:15 -07:00
|
|
|
const vaultMiscItem = guild.VaultMiscItems!.find(x => x.ItemType == miscItem.ItemType)!;
|
|
|
|
vaultMiscItem.ItemCount -= miscItem.ItemCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const miscItemChanges = [];
|
|
|
|
for (const miscItem of data.MiscItems) {
|
2025-03-06 21:24:25 -08:00
|
|
|
const reqItem = techProject.ReqItems.find(x => x.ItemType == miscItem.ItemType);
|
|
|
|
if (reqItem) {
|
|
|
|
if (miscItem.ItemCount > reqItem.ItemCount) {
|
|
|
|
miscItem.ItemCount = reqItem.ItemCount;
|
|
|
|
}
|
|
|
|
reqItem.ItemCount -= miscItem.ItemCount;
|
2025-04-13 05:51:15 -07:00
|
|
|
miscItemChanges.push({
|
|
|
|
ItemType: miscItem.ItemType,
|
|
|
|
ItemCount: miscItem.ItemCount * -1
|
|
|
|
});
|
2025-03-06 21:24:25 -08:00
|
|
|
|
2025-04-13 05:51:15 -07:00
|
|
|
addGuildMemberMiscItemContribution(guildMember, miscItem);
|
2025-03-06 21:24:25 -08:00
|
|
|
}
|
|
|
|
}
|
2025-04-13 05:51:15 -07:00
|
|
|
addMiscItems(inventory, miscItemChanges);
|
|
|
|
const inventoryChanges: IInventoryChanges = updateCurrency(inventory, data.RegularCredits, false);
|
|
|
|
inventoryChanges.MiscItems = miscItemChanges;
|
2025-03-06 21:24:25 -08:00
|
|
|
|
2025-04-13 05:51:15 -07:00
|
|
|
// Check if research is fully funded now.
|
|
|
|
await processGuildTechProjectContributionsUpdate(guild, techProject);
|
2025-03-27 03:33:08 -07:00
|
|
|
|
2025-04-13 05:51:15 -07:00
|
|
|
await Promise.all([guild.save(), inventory.save(), guildMember.save()]);
|
|
|
|
res.json({
|
|
|
|
InventoryChanges: inventoryChanges,
|
|
|
|
Vault: getGuildVault(guild)
|
|
|
|
});
|
2025-01-03 09:06:50 +01:00
|
|
|
}
|
2025-03-16 04:32:11 -07:00
|
|
|
} else if (data.Action.split(",")[0] == "Buy") {
|
|
|
|
const purchase = data as IGuildTechBuyRequest;
|
2025-04-16 06:31:00 -07:00
|
|
|
if (purchase.Mode == "Guild") {
|
|
|
|
const guild = await getGuildForRequestEx(req, inventory);
|
|
|
|
if (
|
|
|
|
!hasAccessToDojo(inventory) ||
|
|
|
|
!(await hasGuildPermission(guild, accountId, GuildPermission.Fabricator))
|
|
|
|
) {
|
|
|
|
res.status(400).send("-1").end();
|
|
|
|
return;
|
2025-01-04 00:25:23 +01:00
|
|
|
}
|
2025-04-16 06:31:00 -07:00
|
|
|
const quantity = parseInt(data.Action.split(",")[1]);
|
|
|
|
const recipeChanges = [
|
|
|
|
{
|
|
|
|
ItemType: purchase.RecipeType,
|
|
|
|
ItemCount: quantity
|
|
|
|
}
|
|
|
|
];
|
|
|
|
addRecipes(inventory, recipeChanges);
|
|
|
|
const currencyChanges = updateCurrency(
|
|
|
|
inventory,
|
|
|
|
ExportDojoRecipes.research[purchase.RecipeType].replicatePrice,
|
|
|
|
false
|
|
|
|
);
|
|
|
|
await inventory.save();
|
|
|
|
// Not a mistake: This response uses `inventoryChanges` instead of `InventoryChanges`.
|
|
|
|
res.json({
|
|
|
|
inventoryChanges: {
|
|
|
|
...currencyChanges,
|
|
|
|
Recipes: recipeChanges
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const inventoryChanges = claimSalvagedComponent(inventory, purchase.CategoryItemId!);
|
|
|
|
await inventory.save();
|
|
|
|
res.json({
|
|
|
|
inventoryChanges: inventoryChanges
|
|
|
|
});
|
|
|
|
}
|
2025-03-16 04:32:11 -07:00
|
|
|
} else if (data.Action == "Fabricate") {
|
2025-04-13 05:51:15 -07:00
|
|
|
const guild = await getGuildForRequestEx(req, inventory);
|
2025-03-14 07:09:28 -07:00
|
|
|
if (!hasAccessToDojo(inventory) || !(await hasGuildPermission(guild, accountId, GuildPermission.Fabricator))) {
|
|
|
|
res.status(400).send("-1").end();
|
|
|
|
return;
|
|
|
|
}
|
2025-03-16 04:32:11 -07:00
|
|
|
const recipe = ExportDojoRecipes.fabrications[data.RecipeType];
|
2025-03-11 07:56:18 -07:00
|
|
|
const inventoryChanges: IInventoryChanges = updateCurrency(inventory, recipe.price, false);
|
|
|
|
inventoryChanges.MiscItems = recipe.ingredients.map(x => ({
|
|
|
|
ItemType: x.ItemType,
|
|
|
|
ItemCount: x.ItemCount * -1
|
|
|
|
}));
|
|
|
|
addMiscItems(inventory, inventoryChanges.MiscItems);
|
2025-03-23 08:26:46 -07:00
|
|
|
combineInventoryChanges(inventoryChanges, await addItem(inventory, recipe.resultType));
|
2025-03-11 07:56:18 -07:00
|
|
|
await inventory.save();
|
|
|
|
// Not a mistake: This response uses `inventoryChanges` instead of `InventoryChanges`.
|
|
|
|
res.json({ inventoryChanges: inventoryChanges });
|
2025-03-16 04:32:11 -07:00
|
|
|
} else if (data.Action == "Pause") {
|
2025-04-13 05:51:15 -07:00
|
|
|
const guild = await getGuildForRequestEx(req, inventory);
|
2025-03-16 04:32:11 -07:00
|
|
|
if (!hasAccessToDojo(inventory) || !(await hasGuildPermission(guild, accountId, GuildPermission.Tech))) {
|
|
|
|
res.status(400).send("-1").end();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const project = guild.TechProjects!.find(x => x.ItemType == data.RecipeType)!;
|
|
|
|
project.State = -2;
|
|
|
|
guild.ActiveDojoColorResearch = "";
|
|
|
|
await guild.save();
|
|
|
|
await removePigmentsFromGuildMembers(guild._id);
|
|
|
|
res.end();
|
|
|
|
} else if (data.Action == "Unpause") {
|
2025-04-13 05:51:15 -07:00
|
|
|
const guild = await getGuildForRequestEx(req, inventory);
|
2025-03-16 04:32:11 -07:00
|
|
|
if (!hasAccessToDojo(inventory) || !(await hasGuildPermission(guild, accountId, GuildPermission.Tech))) {
|
|
|
|
res.status(400).send("-1").end();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const project = guild.TechProjects!.find(x => x.ItemType == data.RecipeType)!;
|
|
|
|
project.State = 0;
|
|
|
|
guild.ActiveDojoColorResearch = data.RecipeType;
|
|
|
|
await guild.save();
|
|
|
|
res.end();
|
2025-04-16 10:38:53 -07:00
|
|
|
} else if (data.Action == "Cancel" && data.CategoryItemId) {
|
|
|
|
const personalTechProjectIndex = inventory.PersonalTechProjects.findIndex(x =>
|
|
|
|
x.CategoryItemId?.equals(data.CategoryItemId)
|
|
|
|
);
|
|
|
|
const personalTechProject = inventory.PersonalTechProjects[personalTechProjectIndex];
|
|
|
|
inventory.PersonalTechProjects.splice(personalTechProjectIndex, 1);
|
|
|
|
|
|
|
|
const meta = ExportDojoRecipes.research[personalTechProject.ItemType];
|
|
|
|
const contributedCredits = meta.price - personalTechProject.ReqCredits;
|
|
|
|
const inventoryChanges = updateCurrency(inventory, contributedCredits * -1, false);
|
|
|
|
inventoryChanges.MiscItems = [];
|
|
|
|
for (const ingredient of meta.ingredients) {
|
|
|
|
const reqItem = personalTechProject.ReqItems.find(x => x.ItemType == ingredient.ItemType);
|
|
|
|
if (reqItem) {
|
|
|
|
const contributedItems = ingredient.ItemCount - reqItem.ItemCount;
|
|
|
|
inventoryChanges.MiscItems.push({
|
|
|
|
ItemType: ingredient.ItemType,
|
|
|
|
ItemCount: contributedItems
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
addMiscItems(inventory, inventoryChanges.MiscItems);
|
|
|
|
|
|
|
|
await inventory.save();
|
|
|
|
res.json({
|
|
|
|
action: "Cancel",
|
|
|
|
isPersonal: true,
|
|
|
|
inventoryChanges: inventoryChanges,
|
|
|
|
personalTech: {
|
|
|
|
ItemId: toOid(personalTechProject._id)
|
|
|
|
}
|
|
|
|
});
|
2025-04-16 06:31:00 -07:00
|
|
|
} else if (data.Action == "Rush" && data.CategoryItemId) {
|
|
|
|
const inventoryChanges: IInventoryChanges = {
|
|
|
|
...updateCurrency(inventory, 20, true),
|
|
|
|
...claimSalvagedComponent(inventory, data.CategoryItemId)
|
|
|
|
};
|
|
|
|
await inventory.save();
|
|
|
|
res.json({
|
|
|
|
inventoryChanges: inventoryChanges
|
|
|
|
});
|
2025-04-19 09:06:07 -07:00
|
|
|
} else if (data.Action == "InstantFinish") {
|
|
|
|
if (data.TechProductCategory != "CrewShipWeapons" && data.TechProductCategory != "CrewShipWeaponSkins") {
|
|
|
|
throw new Error(`unexpected TechProductCategory: ${data.TechProductCategory}`);
|
|
|
|
}
|
|
|
|
const inventoryChanges = finishComponentRepair(inventory, data.TechProductCategory, data.CategoryItemId!);
|
|
|
|
inventoryChanges.MiscItems = [
|
|
|
|
{
|
|
|
|
ItemType: "/Lotus/Types/Items/MiscItems/InstantSalvageRepairItem",
|
|
|
|
ItemCount: -1
|
|
|
|
}
|
|
|
|
];
|
|
|
|
addMiscItems(inventory, inventoryChanges.MiscItems);
|
|
|
|
await inventory.save();
|
|
|
|
res.json({
|
|
|
|
inventoryChanges: inventoryChanges
|
|
|
|
});
|
2025-01-03 09:06:50 +01:00
|
|
|
} else {
|
2025-03-20 05:36:09 -07:00
|
|
|
logger.debug(`data provided to ${req.path}: ${String(req.body)}`);
|
2025-04-16 06:31:00 -07:00
|
|
|
throw new Error(`unhandled guildTech request`);
|
2025-01-03 09:06:50 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2025-03-11 07:56:18 -07:00
|
|
|
type TGuildTechRequest =
|
2025-03-16 04:32:11 -07:00
|
|
|
| { Action: "Sync" | "SomethingElseThatWeMightNotKnowAbout" }
|
|
|
|
| IGuildTechBasicRequest
|
|
|
|
| IGuildTechContributeRequest;
|
2025-01-03 09:06:50 +01:00
|
|
|
|
2025-03-16 04:32:11 -07:00
|
|
|
interface IGuildTechBasicRequest {
|
2025-04-19 09:06:07 -07:00
|
|
|
Action: "Start" | "Fabricate" | "Pause" | "Unpause" | "Cancel" | "Rush" | "InstantFinish";
|
2025-04-13 05:51:15 -07:00
|
|
|
Mode: "Guild" | "Personal";
|
2025-01-03 09:06:50 +01:00
|
|
|
RecipeType: string;
|
2025-04-16 06:31:00 -07:00
|
|
|
TechProductCategory?: string;
|
|
|
|
CategoryItemId?: string;
|
2025-01-03 09:06:50 +01:00
|
|
|
}
|
|
|
|
|
2025-04-16 06:31:00 -07:00
|
|
|
interface IGuildTechBuyRequest extends Omit<IGuildTechBasicRequest, "Action"> {
|
2025-03-16 04:32:11 -07:00
|
|
|
Action: string;
|
|
|
|
}
|
2025-01-04 00:25:23 +01:00
|
|
|
|
2025-03-16 04:32:11 -07:00
|
|
|
interface IGuildTechContributeRequest {
|
|
|
|
Action: "Contribute";
|
2025-04-13 05:51:15 -07:00
|
|
|
ResearchId: string;
|
2025-01-03 09:06:50 +01:00
|
|
|
RecipeType: string;
|
|
|
|
RegularCredits: number;
|
|
|
|
MiscItems: IMiscItem[];
|
|
|
|
VaultCredits: number;
|
|
|
|
VaultMiscItems: IMiscItem[];
|
|
|
|
}
|
2025-04-16 06:31:00 -07:00
|
|
|
|
2025-04-17 10:50:24 -07:00
|
|
|
const getSalvageCategory = (
|
|
|
|
category: "CrewShipWeapons" | "CrewShipWeaponSkins"
|
|
|
|
): "CrewShipSalvagedWeapons" | "CrewShipSalvagedWeaponSkins" => {
|
|
|
|
return category == "CrewShipWeapons" ? "CrewShipSalvagedWeapons" : "CrewShipSalvagedWeaponSkins";
|
|
|
|
};
|
|
|
|
|
2025-04-16 06:31:00 -07:00
|
|
|
const claimSalvagedComponent = (inventory: TInventoryDatabaseDocument, itemId: string): IInventoryChanges => {
|
|
|
|
// delete personal tech project
|
|
|
|
const personalTechProjectIndex = inventory.PersonalTechProjects.findIndex(x => x.CategoryItemId?.equals(itemId));
|
2025-04-17 07:59:42 -07:00
|
|
|
const personalTechProject = inventory.PersonalTechProjects[personalTechProjectIndex];
|
|
|
|
inventory.PersonalTechProjects.splice(personalTechProjectIndex, 1);
|
|
|
|
|
|
|
|
const category = personalTechProject.ProductCategory! as "CrewShipWeapons" | "CrewShipWeaponSkins";
|
2025-04-19 09:06:07 -07:00
|
|
|
return finishComponentRepair(inventory, category, itemId);
|
|
|
|
};
|
|
|
|
|
|
|
|
const finishComponentRepair = (
|
|
|
|
inventory: TInventoryDatabaseDocument,
|
|
|
|
category: "CrewShipWeapons" | "CrewShipWeaponSkins",
|
|
|
|
itemId: string
|
|
|
|
): IInventoryChanges => {
|
2025-04-17 10:50:24 -07:00
|
|
|
const salvageCategory = getSalvageCategory(category);
|
2025-04-16 06:31:00 -07:00
|
|
|
|
|
|
|
// find salved part & delete it
|
2025-04-17 07:59:42 -07:00
|
|
|
const salvageIndex = inventory[salvageCategory].findIndex(x => x._id.equals(itemId));
|
2025-04-19 09:06:07 -07:00
|
|
|
const salvageItem = inventory[salvageCategory][salvageIndex];
|
2025-04-17 07:59:42 -07:00
|
|
|
inventory[salvageCategory].splice(salvageIndex, 1);
|
2025-04-16 06:31:00 -07:00
|
|
|
|
|
|
|
// add final item
|
|
|
|
const inventoryChanges = {
|
2025-04-17 07:59:42 -07:00
|
|
|
...(category == "CrewShipWeaponSkins"
|
|
|
|
? addCrewShipWeaponSkin(inventory, salvageItem.ItemType, salvageItem.UpgradeFingerprint)
|
|
|
|
: addEquipment(
|
|
|
|
inventory,
|
|
|
|
category,
|
|
|
|
salvageItem.ItemType,
|
|
|
|
undefined,
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
UpgradeFingerprint: salvageItem.UpgradeFingerprint
|
|
|
|
}
|
|
|
|
)),
|
2025-04-16 06:31:00 -07:00
|
|
|
...occupySlot(inventory, InventorySlot.RJ_COMPONENT_AND_ARMAMENTS, false)
|
|
|
|
};
|
|
|
|
|
|
|
|
inventoryChanges.RemovedIdItems = [
|
|
|
|
{
|
|
|
|
ItemId: { $oid: itemId }
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
return inventoryChanges;
|
|
|
|
};
|