graser rules

This commit is contained in:
Yanick Champoux 2023-05-02 11:52:00 -04:00
parent 8a2b1cd306
commit 6ab2de80fa

View File

@ -7,120 +7,182 @@ export type Arc = (typeof arcs)[number];
export type WeaponType = "beam"; export type WeaponType = "beam";
type Beam = { type Beam = {
type: "beam"; type: "beam";
weaponClass: 1 | 2 | 3 | 4; weaponClass: 1 | 2 | 3 | 4;
arcs: Arc[]; arcs: Arc[];
}; };
type Submunition = { type Submunition = {
type: "submunition"; type: "submunition";
arc: Arc; arc: Arc;
}; };
type PDS = { type PDS = {
type: "pds"; type: "pds";
}; };
type Scattergun = { type: "scattergun" }; type Scattergun = { type: "scattergun" };
type Needle = { type: "needle"; arc: Arc }; type Needle = { type: "needle"; arc: Arc };
export type Weapon = Beam | Submunition | PDS | Scattergun | Needle; type Graser = {
type: "graser";
weaponClass: 1 | 2 | 3;
arcs: Arc[];
};
export type Weapon = Beam | Submunition | PDS | Scattergun | Needle | Graser;
export const weaponTypes = [ export const weaponTypes = [
{ {
type: "beam", type: "graser",
name: "beam", name: "graser",
reqs: beamReqs, reqs: graserReqs,
initial: { initial: {
type: "beam", type: "graser",
weaponClass: 1, weaponClass: 1,
arcs, arcs: ["F"],
} as any as Beam, } as any as Graser,
}, options: {
{ 1: {
type: "submunition", nbrArcs: [1, 3, 6],
name: "submunition pack", broadside: true,
reqs: { mass: 1, cost: 3 }, },
initial: { type: "submunition", arc: "F" } as Submunition, 2: {
}, nbrArcs: [1, 2, 3, 4, 5, 6],
{ broadside: true,
name: "point defence system", },
type: "pds", 3: {
reqs: { mass: 1, cost: 3 }, nbrArcs: [1, 2, 3, 4, 5, 6],
initial: { broadside: true,
type: "pds", },
},
},
{
type: "beam",
name: "beam",
reqs: beamReqs,
initial: {
type: "beam",
weaponClass: 1,
arcs,
} as any as Beam,
},
{
type: "submunition",
name: "submunition pack",
reqs: { mass: 1, cost: 3 },
initial: { type: "submunition", arc: "F" } as Submunition,
},
{
name: "point defence system",
type: "pds",
reqs: { mass: 1, cost: 3 },
initial: {
type: "pds",
},
},
{
name: "scattergun",
type: "scattergun",
reqs: { mass: 1, cost: 4 },
initial: { type: "scattergun" },
},
{
name: "needle beam",
type: "needle",
reqs: { mass: 2, cost: 6 },
initial: { arc: "F", type: "needle" },
}, },
},
{
name: "scattergun",
type: "scattergun",
reqs: { mass: 1, cost: 4 },
initial: { type: "scattergun" },
},
{
name: "needle beam",
type: "needle",
reqs: { mass: 2, cost: 6 },
initial: { arc: "F", type: "needle" },
},
]; ];
export function weaponReqs(weapon): Reqs { export function weaponReqs(weapon): Reqs {
const { reqs } = weaponTypes.find((wt) => wt.type === weapon.type) || {}; const { reqs } = weaponTypes.find((wt) => wt.type === weapon.type) || {};
if (!reqs) if (!reqs)
return { return {
cost: 0, cost: 0,
mass: 0, mass: 0,
}; };
if (typeof reqs === "function") return reqs(weapon); if (typeof reqs === "function") return reqs(weapon);
return reqs; return reqs;
} }
const isBroadside = (arcs: Arc[]) => { const isBroadside = (arcs: Arc[]) => {
if (arcs.length !== 4) return false; if (arcs.length !== 4) return false;
// that'd be A or F // that'd be A or F
return !arcs.some((a) => a.length === 1); return !arcs.some((a) => a.length === 1);
}; };
function beamReqs({ weaponClass, arcs }: Beam) { function beamReqs({ weaponClass, arcs }: Beam) {
console.log(weaponClass, arcs); let mass;
let mass;
if (weaponClass === 1) { if (weaponClass === 1) {
mass = 1; mass = 1;
}
if (weaponClass === 2) {
mass = 2 + (arcs.length > 3 ? 1 : 0);
}
if (weaponClass == 3) {
mass = 4;
if (isBroadside(arcs)) {
mass += 2;
} else {
mass += arcs.length - 1;
} }
}
if (weaponClass == 4) { if (weaponClass === 2) {
mass = 8; mass = 2 + (arcs.length > 3 ? 1 : 0);
if (isBroadside(arcs)) {
mass += 4;
} else {
mass += 2 * (arcs.length - 1);
} }
}
return { if (weaponClass == 3) {
mass, mass = 4;
cost: 3 * mass,
}; if (isBroadside(arcs)) {
mass += 2;
} else {
mass += arcs.length - 1;
}
}
if (weaponClass == 4) {
mass = 8;
if (isBroadside(arcs)) {
mass += 4;
} else {
mass += 2 * (arcs.length - 1);
}
}
return {
mass,
cost: 3 * mass,
};
}
function graserReqs({ weaponClass, arcs }: Beam) {
let mass: number;
if (weaponClass === 1) {
if (arcs.length === 1) {
mass = 2;
} else if (arcs.length === 3) {
mass = 3;
} else {
mass = 4;
}
} else if (weaponClass === 2) {
mass = 9;
if (isBroadside(arcs)) {
mass += 6;
} else {
mass += 3 * (arcs.length - 1);
}
} else if (weaponClass === 3) {
mass = 24;
if (isBroadside(arcs)) {
mass += 12;
} else {
mass += 6 * (arcs.length - 1);
}
}
return {
mass,
cost: 4 * mass,
};
} }