Skip to content

Commit

Permalink
Improved skirmish-mode cheapestfffe
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel Moschkin committed Jan 20, 2024
1 parent 22ad3f1 commit a66b9c3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 22 deletions.
47 changes: 43 additions & 4 deletions src/commands/cheapestfffe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { colorFromRarity, formatCollectionName } from '../utils/crew';
import { getEmoteOrString, sendAndCache } from '../utils/discord';
import CONFIG from '../utils/config';
import { loadFullProfile, toTimestamp, userFromMessage } from '../utils/profile';
import { getNeededItems } from '../utils/equipment';
import { BAD_COST, IDemand, getNeededItems } from '../utils/equipment';

function bonusName(bonus: string) {
let cfg = CONFIG.STATS_CONFIG[Number.parseInt(bonus)];
Expand Down Expand Up @@ -36,14 +36,26 @@ async function asyncHandler(
let crew = DCData.getBotCrew();
let profileCrew = profile.player.character.crew;
let profileItems = profile.player.character.items;
const needs = {} as { [key: string]: { demands: IDemand[], craftCost: number } };
const sources = {} as { [key: string]: Definitions.ItemSource[] };

let candidatesForImmortalisation = profileCrew.filter((c: any) => {
if (c.level >= 90) {
if (c.level >= 90) {
if (c.equipment.length === 4) return false;
let needed = getNeededItems(c.symbol, 90, c.level, skirmish);
if (!needed) {
if (!needed || needed.demands.every(d => d.avgChronCost <= BAD_COST) || needed.craftCost <= BAD_COST) {
return false;
}
needs[c.symbol] = needed;
}
else {
let needed = getNeededItems(c.symbol, c.level, undefined, skirmish);
if (!needed || needed.demands.every(d => d.avgChronCost <= BAD_COST) || needed.craftCost <= BAD_COST) {
return false;
}
needs[c.symbol] = needed;
}

let findcrew = crew.find((d) => d.symbol === c.symbol);

if (!fuse) {
Expand Down Expand Up @@ -72,7 +84,8 @@ async function asyncHandler(
});

candidatesForImmortalisation = candidatesForImmortalisation.map((c: any) => {
let needed = c.level >= 90 ? getNeededItems(c.symbol, 90, c.level, skirmish) : getNeededItems(c.symbol, c.level, undefined, skirmish);
//let needed = c.level >= 90 ? getNeededItems(c.symbol, 90, c.level, skirmish) : getNeededItems(c.symbol, c.level, undefined, skirmish);
let needed = needs[c.symbol];
if (!needed) {
return c;
}
Expand Down Expand Up @@ -106,6 +119,32 @@ async function asyncHandler(
}
}).sort((a: any, b: any) => {
let r = 0;
if (skirmish) {
sources[a.symbol] ??= needs[a.symbol].demands.map(d => d.equipment.item_sources ?? []).flat();
sources[b.symbol] ??= needs[b.symbol].demands.map(d => d.equipment.item_sources ?? []).flat();

let needa = sources[a.symbol];
let ac = needa.length;
let as = needa.filter(f => f.type === 2).length;

let needb = sources[b.symbol];
let bc = needb.length;
let bs = needb.filter(f => f.type === 2).length;

if (ac && bc) {
if (as && bs) {
ac = as / ac;
bc = bs / bc;
r = bc - ac;
}
else if (as) {
r = -1;
}
else if (bs) {
r = 1;
}
}
}
//if (!r) r = (b.rarity/b.max_rarity) - (a.rarity/a.max_rarity);
if (!r) r = a.requiredChronCost - b.requiredChronCost;
return r;
Expand Down
23 changes: 6 additions & 17 deletions src/utils/equipment.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TODO: share this file with \datacore\src\utils\equipment.ts
import { DCData } from '../data/DCData';

const BAD_COST = 999999999;
export const BAD_COST = -1;

export interface IDemand {
count: number;
Expand All @@ -17,7 +17,9 @@ function bestChronCost(item: Definitions.Item, skirmish?: boolean) {
if (!item.factionOnly) {
let bestMissions = item.item_sources.filter((s) => (!skirmish || s.type !== 0) && s.avg_cost && s.avg_cost >= 1).sort((a, b) => (a.avg_cost || 9999) - (b.avg_cost || 9999));
if (bestMissions.length > 0) {
bestCost = bestMissions[0].avg_cost || 0;
if (!skirmish || bestMissions.some(m => m.type === 2)) {
bestCost = bestMissions[0].avg_cost || 0;
}
}
}

Expand All @@ -31,20 +33,13 @@ export function demandsPerSlot(es: any, items: Definitions.Item[], dupeChecker:
if (!equipment) {
return 0;
}

let unskirm = false;

if (!equipment.recipe) {

if (equipment.item_sources.every(f => f.type === 0 || f.type === 1) && skirmish) {
unskirm = true;
}

if (dupeChecker.has(equipment.symbol)) {
demands.find((d) => d.symbol === equipment!.symbol)!.count += 1;
} else {
dupeChecker.add(equipment.symbol);

demands.push({
count: 1,
symbol: equipment.symbol,
Expand All @@ -53,8 +48,7 @@ export function demandsPerSlot(es: any, items: Definitions.Item[], dupeChecker:
avgChronCost: bestChronCost(equipment, skirmish),
});
}

if (unskirm) return BAD_COST;

return 0;
}

Expand All @@ -64,10 +58,6 @@ export function demandsPerSlot(es: any, items: Definitions.Item[], dupeChecker:
continue;
}

if (recipeEquipment.item_sources.every(f => f.type === 0 || f.type === 2) && skirmish) {
unskirm = true;
}

if (dupeChecker.has(iter.symbol)) {
demands.find((d) => d.symbol === iter.symbol)!.count += iter.count;
continue;
Expand All @@ -87,8 +77,7 @@ export function demandsPerSlot(es: any, items: Definitions.Item[], dupeChecker:
avgChronCost: bestChronCost(recipeEquipment, skirmish),
});
}

if (unskirm) return BAD_COST;

return equipment.recipe.craftCost;
}

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "ES2018",
"target": "ES2019",
"module": "commonjs",
"rootDir": "./src/",
"outDir": "./build/",
Expand Down

0 comments on commit a66b9c3

Please sign in to comment.