graser rules
This commit is contained in:
parent
8a2b1cd306
commit
6ab2de80fa
@ -7,120 +7,182 @@ export type Arc = (typeof arcs)[number];
|
||||
export type WeaponType = "beam";
|
||||
|
||||
type Beam = {
|
||||
type: "beam";
|
||||
weaponClass: 1 | 2 | 3 | 4;
|
||||
arcs: Arc[];
|
||||
type: "beam";
|
||||
weaponClass: 1 | 2 | 3 | 4;
|
||||
arcs: Arc[];
|
||||
};
|
||||
|
||||
type Submunition = {
|
||||
type: "submunition";
|
||||
arc: Arc;
|
||||
type: "submunition";
|
||||
arc: Arc;
|
||||
};
|
||||
|
||||
type PDS = {
|
||||
type: "pds";
|
||||
type: "pds";
|
||||
};
|
||||
|
||||
type Scattergun = { type: "scattergun" };
|
||||
|
||||
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 = [
|
||||
{
|
||||
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",
|
||||
{
|
||||
type: "graser",
|
||||
name: "graser",
|
||||
reqs: graserReqs,
|
||||
initial: {
|
||||
type: "graser",
|
||||
weaponClass: 1,
|
||||
arcs: ["F"],
|
||||
} as any as Graser,
|
||||
options: {
|
||||
1: {
|
||||
nbrArcs: [1, 3, 6],
|
||||
broadside: true,
|
||||
},
|
||||
2: {
|
||||
nbrArcs: [1, 2, 3, 4, 5, 6],
|
||||
broadside: true,
|
||||
},
|
||||
3: {
|
||||
nbrArcs: [1, 2, 3, 4, 5, 6],
|
||||
broadside: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
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 {
|
||||
const { reqs } = weaponTypes.find((wt) => wt.type === weapon.type) || {};
|
||||
const { reqs } = weaponTypes.find((wt) => wt.type === weapon.type) || {};
|
||||
|
||||
if (!reqs)
|
||||
return {
|
||||
cost: 0,
|
||||
mass: 0,
|
||||
};
|
||||
if (!reqs)
|
||||
return {
|
||||
cost: 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[]) => {
|
||||
if (arcs.length !== 4) return false;
|
||||
if (arcs.length !== 4) return false;
|
||||
|
||||
// that'd be A or F
|
||||
return !arcs.some((a) => a.length === 1);
|
||||
// that'd be A or F
|
||||
return !arcs.some((a) => a.length === 1);
|
||||
};
|
||||
|
||||
function beamReqs({ weaponClass, arcs }: Beam) {
|
||||
console.log(weaponClass, arcs);
|
||||
let mass;
|
||||
let mass;
|
||||
|
||||
if (weaponClass === 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 === 1) {
|
||||
mass = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (weaponClass == 4) {
|
||||
mass = 8;
|
||||
|
||||
if (isBroadside(arcs)) {
|
||||
mass += 4;
|
||||
} else {
|
||||
mass += 2 * (arcs.length - 1);
|
||||
if (weaponClass === 2) {
|
||||
mass = 2 + (arcs.length > 3 ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
mass,
|
||||
cost: 3 * mass,
|
||||
};
|
||||
if (weaponClass == 3) {
|
||||
mass = 4;
|
||||
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user