Hi,
I am trying to auto craft Vaccinators on start and when a new trade offer is accepted.
// craftVaccinators.ts
import Bot from '../../Bot';
export default function craftVaccinators(bot: Bot): Promise<void> {
return new Promise(resolve => {
if (!bot.options.crafting.weapons.enable) {
return resolve();
}
const inventory = bot.inventoryManager.getInventory;
const quickFix = inventory.currenciesFindBySKU('411;6');
const reclaimed = inventory.currenciesFindBySKU('5001;6');
const amountToCraft = Math.min(Math.trunc(quickFix.length / 3), reclaimed.length);
for (let i = 0; i < amountToCraft; i++) {
bot.tf2gc.craftVaccinators();
}
return resolve();
});
}
I am calling craftVaccinators at onReady and onTradeOfferChanged
// MyHandler.ts
if (this.isCraftingManual === false) {
// Smelt / combine metal
keepMetalSupply(this.bot, this.minimumScrap, this.minimumReclaimed, this.combineThreshold);
// Craft duplicate weapons
craftDuplicateWeapons(this.bot)
.then(() => {
return craftClassWeapons(this.bot).then(() => {
return craftVaccinators(this.bot);
});
})
.catch(err => {
log.warn('Failed to craft duplicated craft/class weapons', err);
});
}
Which create jobs handled by handleCraftVaccinators
// TF2GC.ts
private handleCraftVaccinators(job: Job): void {
const inventory = this.bot.inventoryManager.getInventory;
const assetids1 = inventory.findBySKU('411;6', true).filter(assetid => !this.bot.trades.isInTrade(assetid));
const assetids2 = inventory.findBySKU('5001;6', true).filter(assetid => !this.bot.trades.isInTrade(assetid));
if (assetids1.length < 3 || assetids2.length < 1) {
return this.finishedProcessingJob(new Error("Can't process job"));
}
const ids = [...assetids1.splice(0, 3), ...assetids2.splice(0, 1)];
log.debug('Sending vaccinator craft request');
this.bot.tf2.craft(ids);
const gainSKU = '998;6';
this.listenForEvent(
'craftingComplete',
(recipe: number, itemsGained: string[]) => {
log.debug('itemsGained', itemsGained);
if (itemsGained.length > 0) {
// Remove items used for recipe
ids.forEach(assetid => inventory.removeItem(assetid));
// Add items gained
itemsGained.forEach(assetid => inventory.addItem(gainSKU, assetid));
}
this.finishedProcessingJob();
},
err => {
this.finishedProcessingJob(err);
}
);
}
My issue is that most of the time, craftingComplete is emitted but the Vaccinator has not been crafted and itemsGained is empty.
Any idea what I am doing wrong ?
Thanks.