add heavy missiles to the printShip
This commit is contained in:
parent
525d223f6b
commit
44fdad6bff
@ -0,0 +1,72 @@
|
||||
<span>heavy missile</span>
|
||||
|
||||
<div class="arcs">
|
||||
<Arcs
|
||||
size={48}
|
||||
selected={arcs}
|
||||
on:clickArc={({ detail }) => setFirstArc(detail)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<label class="switch">
|
||||
<input type="checkbox" bind:checked={extended}/>
|
||||
<span>extended range</span>
|
||||
</label>
|
||||
|
||||
<label class="switch">
|
||||
<input type="checkbox" bind:checked={multiStage}/>
|
||||
<span>multi-stage</span>
|
||||
</label>
|
||||
|
||||
<script lang="ts">
|
||||
import u from "@yanick/updeep-remeda";
|
||||
import { createEventDispatcher } from "svelte";
|
||||
import memoize from "memoize-one";
|
||||
|
||||
import Arcs from "../Arcs.svelte";
|
||||
import {
|
||||
weaponTypes,
|
||||
arcs as allArcs,
|
||||
} from "$lib/store/ship/weaponry/rules.ts";
|
||||
|
||||
export let arcs = ["F", "FS", "FP"];
|
||||
|
||||
export let extended = false;
|
||||
export let multiStage = false;
|
||||
|
||||
|
||||
const nbrArcs = 3;
|
||||
|
||||
let firstArc = allArcs[0];
|
||||
const setFirstArc = (a) => (firstArc = a);
|
||||
|
||||
$: arcs = setArcs(firstArc, nbrArcs);
|
||||
|
||||
function setArcs(firstArc, nbrArcs) {
|
||||
let first_index = allArcs.findIndex((arc) => arc === firstArc);
|
||||
if (first_index === -1) first_index = 0;
|
||||
|
||||
return Array.from({ length: nbrArcs }).map(
|
||||
(_dummy, i) => allArcs[(first_index + i) % allArcs.length]
|
||||
);
|
||||
}
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
const memoChange = memoize((extended,multiStage, ...arcs) =>
|
||||
dispatch("change", {
|
||||
extended,multiStage,
|
||||
arcs,
|
||||
})
|
||||
);
|
||||
|
||||
$: memoChange(extended,multiStage, ...arcs);
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.arcs {
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
label span {
|
||||
padding-left: 1em; }
|
||||
</style>
|
@ -19,6 +19,7 @@
|
||||
import Needle from "./Needle.svelte";
|
||||
import Graser from "./Graser/index.svelte";
|
||||
import Torpedo from "./Torpedo/index.svelte";
|
||||
import Missile from "./HeavyMissile/index.svelte";
|
||||
|
||||
const component = {
|
||||
beam: Beam,
|
||||
@ -28,6 +29,7 @@
|
||||
needle: Needle,
|
||||
graser: Graser,
|
||||
torpedo: Torpedo,
|
||||
heavyMissile: Missile,
|
||||
};
|
||||
|
||||
export let reqs = {};
|
||||
|
@ -35,6 +35,16 @@ export const weaponTypes = [
|
||||
reqs: { mass: 2, cost: 6 },
|
||||
initial: { arc: "F" },
|
||||
},
|
||||
{
|
||||
name: "heavy missile",
|
||||
type: "missile",
|
||||
reqs: missileReqs,
|
||||
initial: {
|
||||
arcs: ["FS", "F", "FP"],
|
||||
extended: false,
|
||||
multiState: false,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const weaponsSlice = createSlice({
|
||||
|
@ -27,6 +27,13 @@ type Scattergun = { type: "scattergun" };
|
||||
|
||||
type Needle = { type: "needle"; arc: Arc };
|
||||
|
||||
type HeavyMissile = {
|
||||
type: "heavyMissile";
|
||||
arcs: Arc[];
|
||||
extended: boolean;
|
||||
multiStage: boolean;
|
||||
};
|
||||
|
||||
type Graser = {
|
||||
type: "graser";
|
||||
weaponClass: 1 | 2 | 3;
|
||||
@ -46,7 +53,8 @@ export type Weapon =
|
||||
| Scattergun
|
||||
| Needle
|
||||
| Graser
|
||||
| Torpedo;
|
||||
| Torpedo
|
||||
| HeavyMissile;
|
||||
|
||||
export const weaponTypes = [
|
||||
{
|
||||
@ -120,6 +128,17 @@ export const weaponTypes = [
|
||||
reqs: { mass: 2, cost: 6 },
|
||||
initial: { arc: "F", type: "needle" },
|
||||
},
|
||||
{
|
||||
name: "heavy missile",
|
||||
type: "heavyMissile",
|
||||
reqs: missileReqs,
|
||||
initial: {
|
||||
arcs: ["FP", "F", "FS"],
|
||||
extended: false,
|
||||
multiStage: false,
|
||||
type: "heavyMissile",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export function weaponReqs(weapon): Reqs {
|
||||
@ -213,6 +232,21 @@ function graserReqs({ weaponClass, arcs }: Graser) {
|
||||
};
|
||||
}
|
||||
|
||||
function missileReqs({ extended, multiStage }: HeavyMissile): Reqs {
|
||||
let mass = 2;
|
||||
let cost = 6;
|
||||
if (extended) {
|
||||
mass += 1;
|
||||
cost += 3;
|
||||
}
|
||||
if (multiStage) {
|
||||
mass += 2;
|
||||
cost *= 2;
|
||||
}
|
||||
|
||||
return { cost, mass };
|
||||
}
|
||||
|
||||
function torpedoReqs({ weaponClass, arcs }: Torpedo): Reqs {
|
||||
let mass: number = 4;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user