Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public submit(): void {
this.loading = true;
const formRaw = this.configForm.getRawValue();
const configuration: SolverConfiguration = {
populationSize: defaultConfiguration.populationSize,
progressAccuracy: defaultConfiguration.progressAccuracy,
hqTarget: formRaw.hqTarget
};
const gcfParams: any = {
configuration: configuration,
recipe: this.recipe,
stats: { ...this.stats }
};
if (formRaw.seeded && this.seed.length > 0) {
gcfParams.seed = CraftingActionsRegistry.serializeRotation(this.seed);
}
// To debug using local function: http://localhost:5001/ffxivteamcraft/us-central1/solver
// Prod: https://us-central1-ffxivteamcraft.cloudfunctions.net/solver
this.http.post(`https://us-central1-ffxivteamcraft.cloudfunctions.net/solver `, gcfParams).subscribe(res => {
this.ref.close(CraftingActionsRegistry.deserializeRotation(res));
});
}
}
res.set('Access-Control-Max-Age', '3600');
if (req.method === 'OPTIONS') {
// Send response to OPTIONS requests
res.status(204).send('');
} else {
const stats = new CrafterStats(
req.body.stats.jobId,
req.body.stats.craftsmanship,
req.body.stats.control,
req.body.stats.cp,
req.body.stats.specialist,
req.body.stats.level,
req.body.stats.levels
);
const solver = new Solver(req.body.recipe, stats, req.body.configuration);
const seed = req.body.seed ? CraftingActionsRegistry.deserializeRotation(req.body.seed) : undefined;
return res.json(CraftingActionsRegistry.serializeRotation(solver.run(seed)));
}
});
exports.solver = functions.runWith(runtimeOpts).https.onRequest((req, res) => {
res.set('Access-Control-Allow-Methods', 'POST');
res.set('Access-Control-Allow-Origin', '*');
res.set('Access-Control-Allow-Headers', '*');
res.set('Access-Control-Max-Age', '3600');
if (req.method === 'OPTIONS') {
// Send response to OPTIONS requests
res.status(204).send('');
} else {
const stats = new CrafterStats(
req.body.stats.jobId,
req.body.stats.craftsmanship,
req.body.stats.control,
req.body.stats.cp,
req.body.stats.specialist,
req.body.stats.level,
req.body.stats.levels
);
const solver = new Solver(req.body.recipe, stats, req.body.configuration);
const seed = req.body.seed ? CraftingActionsRegistry.deserializeRotation(req.body.seed) : undefined;
return res.json(CraftingActionsRegistry.serializeRotation(solver.run(seed)));
}
});
if (req.method === 'OPTIONS') {
// Send response to OPTIONS requests
res.status(204).send('');
} else {
const stats = new CrafterStats(
req.body.stats.jobId,
req.body.stats.craftsmanship,
req.body.stats.control,
req.body.stats.cp,
req.body.stats.specialist,
req.body.stats.level,
req.body.stats.levels
);
const solver = new Solver(req.body.recipe, stats, req.body.configuration);
const seed = req.body.seed ? CraftingActionsRegistry.deserializeRotation(req.body.seed) : undefined;
return res.json(CraftingActionsRegistry.serializeRotation(solver.run(seed)));
}
});
this.rotation.forEach((action, actionIndex) => {
let macroFragment = this.macro[this.macro.length - 1];
// One macro is 15 lines, if this one is full, create another one.
// Alternatively, if breaking before Byregots Blessing is enabled, split there too.
if ((this.breakBeforeByregotsBlessing && action.is(ByregotsBlessing)) || macroFragment.length >= this.maxMacroLines) {
this.macro.push(this.macroLock ? ['/mlock'] : []);
macroFragment = this.macro[this.macro.length - 1];
}
if (action.getIds()[0] === -1) {
macroFragment.push(`/statusoff "${this.i18n.getName(this.l12n.getAction(new FinalAppraisal().getIds()[0]))}"`);
totalLength++;
} else {
let actionName = this.i18n.getName(this.l12n.getAction(action.getIds()[0]));
if (actionName.indexOf(' ') > -1 || this.translator.currentLang === 'ko') {
actionName = `"${actionName}"`;
}
macroFragment.push(`/ac ${actionName} `);
totalLength++;
}
let doneWithChunk: boolean;
if (this.breakBeforeByregotsBlessing && actionIndex < this.rotation.length - 1 && this.rotation[actionIndex+1].is(ByregotsBlessing)) {
doneWithChunk = true;
} else if (macroFragment.length === 14 && this.addEcho && this.rotation.length > totalLength + 1) {
doneWithChunk = true;
}
matches(simulationResult: SimulationResult): boolean {
const blessingIndex = simulationResult.steps.findIndex(step => step.action.is(ByregotsBrow));
const clone = simulationResult.simulation.clone();
clone.run(true, blessingIndex - 1);
return clone.getBuff(Buff.INNER_QUIET) && clone.getBuff(Buff.INNER_QUIET).stacks > 6 && simulationResult.simulation.quality < simulationResult.simulation.recipe.quality;
}
matches(simulationResult: SimulationResult): boolean {
const blessingIndex = simulationResult.steps.findIndex(step => step.action.is(ByregotsBlessing));
const clone = simulationResult.simulation.clone();
clone.run(true, blessingIndex - 1);
return clone.getBuff(Buff.INNER_QUIET) && clone.getBuff(Buff.INNER_QUIET).stacks === 5;
}
matches(simulationResult: SimulationResult): boolean {
const blessingIndex = simulationResult.steps.findIndex(step => step.action.is(ByregotsBlessing));
const clone = simulationResult.simulation.clone();
clone.run(true, blessingIndex - 1);
return clone.getBuff(Buff.INNER_QUIET) && clone.getBuff(Buff.INNER_QUIET).stacks < 6 && simulationResult.simulation.quality < simulationResult.simulation.recipe.quality;
}
return patientTouchIndexes.some(index => {
const clone = simulationResult.simulation.clone();
clone.run(true, index);
return clone.getBuff(Buff.INNER_QUIET) && clone.getBuff(Buff.INNER_QUIET).stacks > 1;
});
}
openMacroPopup(simulation: Simulation): void {
this.dialog.create({
nzContent: MacroPopupComponent,
nzComponentParams: {
rotation: CraftingActionsRegistry.deserializeRotation(this.rotation.rotation),
job: this.rotation.recipe.job,
simulation: simulation.clone(),
food: this.foods.find(f => this.rotation.food && f.itemId === this.rotation.food.id && f.hq === this.rotation.food.hq),
medicine: this.medicines.find(f => this.rotation.medicine && f.itemId === this.rotation.medicine.id && f.hq === this.rotation.medicine.hq),
freeCompanyActions: this.freeCompanyActions.filter(action => this.rotation.freeCompanyActions.indexOf(action.actionId) > -1)
},
nzTitle: this.translate.instant('SIMULATOR.Generate_ingame_macro'),
nzFooter: null
});
}