Skip to content

Commit

Permalink
Merge pull request #2933 from Thorium-Sim/tractor-beams
Browse files Browse the repository at this point in the history
Tractor beams
  • Loading branch information
alexanderson1993 authored May 9, 2020
2 parents 9676e9d + 97be7ad commit e1b2691
Show file tree
Hide file tree
Showing 35 changed files with 1,690 additions and 930 deletions.
57 changes: 0 additions & 57 deletions server/classes/tractorBeam.js

This file was deleted.

112 changes: 112 additions & 0 deletions server/classes/tractorBeam.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import {System} from "./generic";
import uuid from "uuid";

class Beam {
id: string;
state: boolean;
target: boolean;
targetLabel: string;
strength: number;
stress: number;
scanning: boolean;
constructor(params: Partial<Beam> = {}) {
this.id = params.id || uuid.v4();
this.state = params.state || false;
this.target = params.target || false;
this.targetLabel = params.targetLabel || "";
this.strength = params.strength || 0.0;
this.stress = params.stress || 0.15;
this.scanning = params.scanning || false;
}
setState(tf: boolean) {
this.state = tf;
}
setTarget(tf: boolean) {
this.target = tf;
}
setTargetLabel(label: string) {
this.targetLabel = label;
}
setStrength(percent: number) {
this.strength = Math.min(1, Math.max(0, percent));
}
setStress(percent: number) {
this.stress = Math.min(1, Math.max(0, percent));
}
setScanning(scanning: boolean) {
this.scanning = scanning;
}
}
export default class TractorBeam extends System {
class: "TractorBeam" = "TractorBeam";
type: "TractorBeam" = "TractorBeam";
beams: Beam[];

constructor(params: Partial<TractorBeam & Beam> = {}) {
super(params);
this.class = "TractorBeam";
this.type = "TractorBeam";
this.wing = params.wing || "right";

this.name = params.name || "Tractor Beam";
this.beams = params.beams
? params.beams.map(b => new Beam(b))
: [new Beam({...params, id: null})];
}
get stealthFactor() {
const beamsRunning = this.beams.find(b => b.state);
const strength = this.beams.reduce(
(prev, next) => Math.max(prev, next.strength),
0,
);
return beamsRunning ? strength / 5 + 0.8 : 0;
}
trainingMode() {
this.beams?.[0].setTarget(true);
this.beams?.[0].setTargetLabel("Training Target");
}

break(report, destroyed, which) {
this.beams.forEach(b => b.setState(false));
super.break(report, destroyed, which);
}
setPower(powerLevel) {
if (
this.power.powerLevels.length &&
powerLevel < this.power.powerLevels[0]
) {
this.beams.forEach(b => b.setState(false));
}
super.setPower(powerLevel);
}
setBeamCount(count: number) {
if (count > 4 || count <= 0 || count === 3) return;
if (this.beams.length < count) {
const needed = count - this.beams.length;
for (let i = 0; i < needed; i++) {
this.beams.push(new Beam({}));
}
} else if (this.beams.length > count) {
this.beams = this.beams.slice(0, count);
}
}
setState(beam: string, tf: boolean) {
this.beams.find(b => b.id === beam).setState(tf);
}
setTarget(beam: string, tf: boolean) {
console.log(beam, this.beams);
this.beams.find(b => b.id === beam).setTarget(tf);
}
setTargetLabel(beam: string, label: string) {
this.beams.find(b => b.id === beam).setTargetLabel(label);
}
setStrength(beam: string, percent: number) {
this.beams.find(b => b.id === beam).setStrength(percent);
}
setStress(beam: string, percent: number) {
this.beams.find(b => b.id === beam).setStress(percent);
}
setScanning(beam: string, scanning: boolean) {
this.beams.find(b => b.id === beam).setScanning(scanning);
}
}
1 change: 0 additions & 1 deletion server/events/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import "./probes";
import "./stealthField";
import "./thrusters";
import "./coolant";
import "./tractorBeam";
import "./crew";
import "./teams";
import "./viewscreen";
Expand Down
110 changes: 0 additions & 110 deletions server/events/tractorBeam.js

This file was deleted.

Loading

0 comments on commit e1b2691

Please sign in to comment.