Improvements to handleRecipe()
Cleaner handling of stackable rewards Moved task condition counter lookup to own function
This commit is contained in:
parent
44560991b0
commit
16cb48ad70
@ -8,7 +8,7 @@ import { PaymentHelper } from "@spt-aki/helpers/PaymentHelper";
|
|||||||
import { PresetHelper } from "@spt-aki/helpers/PresetHelper";
|
import { PresetHelper } from "@spt-aki/helpers/PresetHelper";
|
||||||
import { ProfileHelper } from "@spt-aki/helpers/ProfileHelper";
|
import { ProfileHelper } from "@spt-aki/helpers/ProfileHelper";
|
||||||
import { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
|
import { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
|
||||||
import { HideoutArea, Product, Production, ScavCase } from "@spt-aki/models/eft/common/tables/IBotBase";
|
import { HideoutArea, ITaskConditionCounter, Product, Production, ScavCase } from "@spt-aki/models/eft/common/tables/IBotBase";
|
||||||
import { Item } from "@spt-aki/models/eft/common/tables/IItem";
|
import { Item } from "@spt-aki/models/eft/common/tables/IItem";
|
||||||
import { HideoutUpgradeCompleteRequestData } from "@spt-aki/models/eft/hideout/HideoutUpgradeCompleteRequestData";
|
import { HideoutUpgradeCompleteRequestData } from "@spt-aki/models/eft/hideout/HideoutUpgradeCompleteRequestData";
|
||||||
import { IHandleQTEEventRequestData } from "@spt-aki/models/eft/hideout/IHandleQTEEventRequestData";
|
import { IHandleQTEEventRequestData } from "@spt-aki/models/eft/hideout/IHandleQTEEventRequestData";
|
||||||
@ -775,18 +775,7 @@ export class HideoutController
|
|||||||
// Variables for managemnet of skill
|
// Variables for managemnet of skill
|
||||||
let craftingExpAmount = 0;
|
let craftingExpAmount = 0;
|
||||||
|
|
||||||
// ? move the logic of TaskConditionCounters in new method?
|
const counterHoursCrafting = this.getHoursCraftingTaskConditionCounter(pmcData, recipe);
|
||||||
let counterHoursCrafting = pmcData.TaskConditionCounters[HideoutController.nameTaskConditionCountersCrafting];
|
|
||||||
if (!counterHoursCrafting)
|
|
||||||
{
|
|
||||||
pmcData.TaskConditionCounters[HideoutController.nameTaskConditionCountersCrafting] = {
|
|
||||||
id: recipe._id,
|
|
||||||
type: HideoutController.nameTaskConditionCountersCrafting,
|
|
||||||
sourceId: "CounterCrafting",
|
|
||||||
value: 0,
|
|
||||||
};
|
|
||||||
counterHoursCrafting = pmcData.TaskConditionCounters[HideoutController.nameTaskConditionCountersCrafting];
|
|
||||||
}
|
|
||||||
let hoursCrafting = counterHoursCrafting.value;
|
let hoursCrafting = counterHoursCrafting.value;
|
||||||
|
|
||||||
/** Array of arrays of item + children */
|
/** Array of arrays of item + children */
|
||||||
@ -813,15 +802,14 @@ export class HideoutController
|
|||||||
const rewardIsStackable = this.itemHelper.isItemTplStackable(recipe.endProduct);
|
const rewardIsStackable = this.itemHelper.isItemTplStackable(recipe.endProduct);
|
||||||
if (rewardIsStackable)
|
if (rewardIsStackable)
|
||||||
{
|
{
|
||||||
const rewardToAdd: Item[] = [];
|
|
||||||
// Create root item
|
// Create root item
|
||||||
const rootItemToAdd: Item = {
|
const rewardToAdd: Item[] = [{
|
||||||
_id: this.hashUtil.generate(),
|
_id: this.hashUtil.generate(),
|
||||||
_tpl: recipe.endProduct,
|
_tpl: recipe.endProduct,
|
||||||
upd: {
|
upd: {
|
||||||
StackObjectsCount: recipe.count
|
StackObjectsCount: recipe.count
|
||||||
}
|
}
|
||||||
};
|
}];
|
||||||
|
|
||||||
// Split item into separate items with acceptable stack sizes
|
// Split item into separate items with acceptable stack sizes
|
||||||
const splitReward = this.itemHelper.splitStack(rewardToAdd[0]);
|
const splitReward = this.itemHelper.splitStack(rewardToAdd[0]);
|
||||||
@ -829,8 +817,9 @@ export class HideoutController
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Not stackable, send multiple single items
|
// Not stackable, may have to send send multiple of reward
|
||||||
// Add the initial item to array
|
|
||||||
|
// Add the first reward item to array when not a preset (first preset added above earlier)
|
||||||
if (!rewardIsPreset)
|
if (!rewardIsPreset)
|
||||||
{
|
{
|
||||||
itemAndChildrenToSendToPlayer.push([{
|
itemAndChildrenToSendToPlayer.push([{
|
||||||
@ -839,9 +828,10 @@ export class HideoutController
|
|||||||
}]);
|
}]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add multiple of item if recipe requests it
|
||||||
// Start index at one so we ignore first item in array
|
// Start index at one so we ignore first item in array
|
||||||
// (handles preset items already being added)
|
const countOfItemsToReward = recipe.count;
|
||||||
for (let index = 1; index < recipe.count; index++)
|
for (let index = 1; index < countOfItemsToReward; index++)
|
||||||
{
|
{
|
||||||
const itemAndMods: Item[] = this.itemHelper.replaceIDs(
|
const itemAndMods: Item[] = this.itemHelper.replaceIDs(
|
||||||
null,
|
null,
|
||||||
@ -867,22 +857,23 @@ export class HideoutController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loops over all current productions on profile
|
// Loops over all current productions on profile - we want to find a matching production
|
||||||
const entries = Object.entries(pmcData.Hideout.Production);
|
const productionDict = Object.entries(pmcData.Hideout.Production);
|
||||||
let prodId: string;
|
let prodId: string;
|
||||||
for (const entry of entries)
|
for (const production of productionDict)
|
||||||
{
|
{
|
||||||
// Skip null production objects
|
// Skip null production objects
|
||||||
if (!entry[1])
|
if (!production[1])
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.hideoutHelper.isProductionType(entry[1]))
|
if (this.hideoutHelper.isProductionType(production[1]))
|
||||||
{ // Production or ScavCase
|
|
||||||
if ((entry[1] as Production).RecipeId === request.recipeId)
|
|
||||||
{
|
{
|
||||||
prodId = entry[0]; // set to objects key
|
// Production or ScavCase
|
||||||
|
if ((production[1] as Production).RecipeId === request.recipeId)
|
||||||
|
{
|
||||||
|
prodId = production[0]; // Set to objects key
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -901,7 +892,7 @@ export class HideoutController
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the recipe is the same as the last one - get bonus when crafting same thing multiple times
|
// Check if the recipe is the same as the last one - get bonus when crafting same thing multiple times
|
||||||
const area = pmcData.Hideout.Areas.find((x) => x.type === recipe.areaType);
|
const area = pmcData.Hideout.Areas.find((area) => area.type === recipe.areaType);
|
||||||
if (area && request.recipeId !== area.lastRecipe)
|
if (area && request.recipeId !== area.lastRecipe)
|
||||||
{
|
{
|
||||||
// 1 point per craft upon the end of production for alternating between 2 different crafting recipes in the same module
|
// 1 point per craft upon the end of production for alternating between 2 different crafting recipes in the same module
|
||||||
@ -960,6 +951,8 @@ export class HideoutController
|
|||||||
|
|
||||||
}
|
}
|
||||||
area.lastRecipe = request.recipeId;
|
area.lastRecipe = request.recipeId;
|
||||||
|
|
||||||
|
// Update profiles hours crafting value
|
||||||
counterHoursCrafting.value = hoursCrafting;
|
counterHoursCrafting.value = hoursCrafting;
|
||||||
|
|
||||||
// Continuous crafts have special handling in EventOutputHolder.updateOutputProperties()
|
// Continuous crafts have special handling in EventOutputHolder.updateOutputProperties()
|
||||||
@ -975,6 +968,29 @@ export class HideoutController
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the "CounterHoursCrafting" TaskConditionCounter from a profile
|
||||||
|
* @param pmcData Profile to get counter from
|
||||||
|
* @param recipe Recipe being crafted
|
||||||
|
* @returns ITaskConditionCounter
|
||||||
|
*/
|
||||||
|
protected getHoursCraftingTaskConditionCounter(pmcData: IPmcData, recipe: IHideoutProduction): ITaskConditionCounter
|
||||||
|
{
|
||||||
|
let counterHoursCrafting = pmcData.TaskConditionCounters[HideoutController.nameTaskConditionCountersCrafting];
|
||||||
|
if (!counterHoursCrafting)
|
||||||
|
{
|
||||||
|
// Doesn't exist, create
|
||||||
|
pmcData.TaskConditionCounters[HideoutController.nameTaskConditionCountersCrafting] = {
|
||||||
|
id: recipe._id,
|
||||||
|
type: HideoutController.nameTaskConditionCountersCrafting,
|
||||||
|
sourceId: "CounterCrafting",
|
||||||
|
value: 0,
|
||||||
|
};
|
||||||
|
counterHoursCrafting = pmcData.TaskConditionCounters[HideoutController.nameTaskConditionCountersCrafting];
|
||||||
|
}
|
||||||
|
return counterHoursCrafting;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles generating case rewards and sending to player inventory
|
* Handles generating case rewards and sending to player inventory
|
||||||
* @param sessionID Session id
|
* @param sessionID Session id
|
||||||
|
Loading…
Reference in New Issue
Block a user