2023-07-07 17:40:59 -06:00

68 lines
2.3 KiB
TypeScript

import { attackRanges } from "./attackDefs.ts";
import { move, moves } from "./moveDefs.ts";
import { penaltyDefs } from "./penaltyDefs.ts";
import { card } from "./types.ts";
const series = Deno.args.find(a => a.includes('series'))?.split('=')[1];
console.log(`Generating cards for series ${series}`);
const cardCount = 60;
const cards: card[] = [];
while (cards.length < cardCount) {
const maneuvers: move[] = [];
const maneuverCount = Math.floor(Math.random() * 3);
while (maneuvers.length < maneuverCount) {
const move = moves[Math.floor(Math.random() * moves.length)];
if (!maneuvers.includes(move)) maneuvers.push(move);
}
const attacks: string[] = [];
for (const [name, attack] of Object.entries(attackRanges)) {
const rand = Math.random() * 10;
if (rand < attack.max) attacks.push(name);
}
const penalties = penaltyDefs.map(value => ({ value, sort: Math.random() }))
.sort((a, b) => a.sort - b.sort)
.map(({ value }) => value).splice(0, Math.min(3, Math.floor(Math.random() * (penaltyDefs.length + 1))))
.sort((a,b) => {
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
});
const card: card = {
maneuvers,
attacks,
penalties,
type: 'action'
};
if (card.penalties.length === 0 && card.attacks.includes('groundToAir')) card.penalties.push('Land Battle');
// TODO: optimize this. Cards should be stored in a map with the key being the stringification of a normalized concatenation of all properties
for (const existing of cards) {
const everyAttack = existing.attacks.every(a => card.attacks.includes(a)) && card.attacks.every(a => existing.attacks.includes(a))
const everyManeuver = existing.maneuvers.every(a => card.maneuvers.find(e => e.name === a.name)) && card.maneuvers.every(a => existing.maneuvers.find(e => e.name === a.name));
const everyPenalty = existing.penalties.every(a => card.penalties.includes(a)) && card.penalties.every(a => existing.penalties.includes(a))
if (everyAttack && everyManeuver && everyPenalty) {
card.needsEffect = true;
break;
}
}
(card.maneuvers.length || card.attacks.length || card.penalties.length) && cards.push(card);
}
const encoder = new TextEncoder();
Deno.writeFile(`./series${series}.json`, encoder.encode(JSON.stringify(cards, null, 2)));
console.log('Done');