Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
Hideout production:
Browse files Browse the repository at this point in the history
- fixed item not being added to inventory after production completed,
- refactored singleProductionStart()
  • Loading branch information
Nehaxfr committed Jan 10, 2023
1 parent b3c7d27 commit 18de7d0
Showing 1 changed file with 35 additions and 41 deletions.
76 changes: 35 additions & 41 deletions lib/controllers/HideoutController.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,55 +309,49 @@ class HideoutController {
let allItemsTaken = true;
for (const itemToTake of moveAction.items) {
const itemTaken = await playerProfile.character.removeItem(itemToTake.id, itemToTake.count);
if (itemTaken) {
if (typeof itemTaken.changed !== "undefined") {
output.items.change = output.items.change.concat(itemTaken.changed);
}
if (!itemTaken) {
await logger.error(`[singleProductionStart] Starting hideout production for recepie with Id ${moveAction.recipeId} failed. Unable to take required items.`);
return false;
}
if (typeof itemTaken.changed !== "undefined") {
output.items.change = output.items.change.concat(itemTaken.changed);
}

if (typeof itemTaken.removed !== "undefined") {
output.items.del = output.items.del.concat(itemTaken.removed);
}
} else {
allItemsTaken = false;
if (typeof itemTaken.removed !== "undefined") {
output.items.del = output.items.del.concat(itemTaken.removed);
}
}

if (allItemsTaken) {
let productionTime = 0;
let productionTime = 0;

if (typeof hideoutProductionTemplate.ProductionTime !== "undefined") {
productionTime = hideoutProductionTemplate.ProductionTime;
} else if (typeof hideoutProductionTemplate.productionTime !== "undefined") {
productionTime = hideoutProductionTemplate.productionTime;
}
if (typeof hideoutProductionTemplate.ProductionTime !== "undefined") {
productionTime = hideoutProductionTemplate.ProductionTime;
} else if (typeof hideoutProductionTemplate.productionTime !== "undefined") {
productionTime = hideoutProductionTemplate.productionTime;
}

if (!hideoutProductionTemplate.count) {
hideoutProductionTemplate.count = 1;
}
if (!hideoutProductionTemplate.count) {
hideoutProductionTemplate.count = 1;
}

const productId = await generateMongoID();
const products = [{
_id: productId,
_tpl: hideoutProductionTemplate.endProduct,
count: hideoutProductionTemplate.count
}];
const productId = await generateMongoID();
const products = [{
_id: productId,
_tpl: hideoutProductionTemplate.endProduct,
count: hideoutProductionTemplate.count
}];

playerProfile.character.Hideout.Production[hideoutProductionTemplate._id] = {
Progress: 0,
inProgress: true,
Products: products,
RecipeId: moveAction.recepieId,
SkipTime: 0,
ProductionTime: Number(productionTime),
StartTimestamp: await getCurrentTimestamp()
};
playerProfile.character.Hideout.Production[hideoutProductionTemplate._id] = {
Progress: 0,
inProgress: true,
Products: products,
RecipeId: moveAction.recepieId,
SkipTime: 0,
ProductionTime: Number(productionTime),
StartTimestamp: await getCurrentTimestamp()
};

return output;
} else {
// How do return custom error to client!!1!1!!!111!elf?
await logger.error(`[singleProductionStart] Starting hideout production for recepie with Id ${moveAction.recipeId} failed. Unable to take required items.`);
return false;
}
return output;
}

static async continuousProductionStart(moveAction = null, playerProfile = null) {
Expand Down Expand Up @@ -443,7 +437,7 @@ class HideoutController {
product.count = 1;
}
const itemTemplate = await Item.get(product._tpl);
const container = playerProfile.character.getInventoryItemByID(await playerProfile.character.getStashContainer());
const container = await playerProfile.character.getInventoryItemByID(await playerProfile.character.getStashContainer());
if (await Preset.itemHasPreset(itemTemplate._id)) {
const itemPresets = await Preset.getPresetsForItem(itemTemplate._id);
const itemPreset = Object.values(itemPresets).find(preset => preset._encyclopedia);
Expand Down

0 comments on commit 18de7d0

Please sign in to comment.