Skip to content

Commit

Permalink
Add torpedo launcher debugger.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderson1993 committed Sep 2, 2024
1 parent a70e400 commit d862595
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 39 deletions.
101 changes: 64 additions & 37 deletions client/app/cores/StarmapCore/StarmapCoreContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,31 +99,56 @@ export const StarmapCoreContextMenu = ({
{/* TODO March 11, 2024: Add commands for when right clicking on another object, such as following or attacking the target */}
{selectedShips.length > 0 ? (
!object ? (
<button
className={menuItemClass}
onClick={() => {
if (selectedShips.length > 0) {
const position = useStarmapStore
.getState()
.translate2DTo3D?.(x, y);
if (!position) return;
q.starmapCore.setDestinations.netSend({
ships: selectedShips.map((id: any) => ({
id,
<>
<button
className={menuItemClass}
onClick={() => {
if (selectedShips.length > 0) {
const position = useStarmapStore
.getState()
.translate2DTo3D?.(x, y);
if (!position) return;
q.starmapCore.setDestinations.netSend({
ships: selectedShips.map((id: any) => ({
id,
position: {
x: position.x,
y: useStarmapStore.getState().yDimensionIndex,
z: position.z,
},
systemId: useStarmapStore.getState().currentSystem,
})),
});
setOpen(false);
}
}}
>
Travel To Here
</button>
<button
className={menuItemClass}
onClick={() => {
if (selectedShips.length > 0) {
const position = useStarmapStore
.getState()
.translate2DTo3D?.(x, y);
if (!position) return;
q.starmapCore.fireTorpedo.netSend({
objectId: selectedShips[0] as number,
position: {
x: position.x,
y: useStarmapStore.getState().yDimensionIndex,
z: position.z,
parentId: useStarmapStore.getState().currentSystem!,
},
systemId: useStarmapStore.getState().currentSystem,
})),
});
setOpen(false);
}
}}
>
Travel To Here
</button>
});
setOpen(false);
}
}}
>
Spawn Torpedo (Debug)
</button>
</>
) : object.type === "planet" ? (
<button
className={menuItemClass}
Expand Down Expand Up @@ -157,23 +182,25 @@ export const StarmapCoreContextMenu = ({
Orbit Star
</button>
) : object.type === "ship" ? (
<button
className={menuItemClass}
onClick={() => {
if (selectedShips.length > 0) {
q.starmapCore.setFollowShip.netSend({
ships: useStarmapStore.getState()
.selectedObjectIds as number[],
objectId: object.id,
// TODO: March 15, 2024 - This should change based on the current objective of the ship
objective: "defend",
});
setOpen(false);
}
}}
>
Follow Ship
</button>
<>
<button
className={menuItemClass}
onClick={() => {
if (selectedShips.length > 0) {
q.starmapCore.setFollowShip.netSend({
ships: useStarmapStore.getState()
.selectedObjectIds as number[],
objectId: object.id,
// TODO: March 15, 2024 - This should change based on the current objective of the ship
objective: "defend",
});
setOpen(false);
}
}}
>
Follow Ship
</button>
</>
) : null
) : null}
<button
Expand Down
54 changes: 53 additions & 1 deletion client/app/cores/StarmapCore/data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { t } from "@server/init/t";
import { pubsub } from "@server/init/pubsub";
import { matchSorter } from "match-sorter";
import type ShipPlugin from "@server/classes/Plugins/Ship";
import type { Entity } from "@server/utils/ecs";
import { Entity } from "@server/utils/ecs";
import type { Coordinates } from "@server/utils/unitTypes";
import { z } from "zod";
import {
Expand All @@ -11,6 +11,7 @@ import {
} from "@server/utils/position";
import type { isDestroyed } from "@server/components/isDestroyed";
import type { DataContext } from "@server/utils/types";
import { Vector3 } from "three";

type IsDestroyed = Zod.infer<typeof isDestroyed>;

Expand Down Expand Up @@ -503,6 +504,57 @@ export const starmapCore = t.router({
pubsub.publish.starmapCore.autopilot({ systemId: id });
});
}),
fireTorpedo: t.procedure
.input(
z.object({
objectId: z.number(),
position: z.object({
x: z.number(),
y: z.number(),
z: z.number(),
parentId: z.number(),
}),
}),
)
.send(({ ctx, input }) => {
const torpedoEntity = new Entity();

torpedoEntity.addComponent("position", {
x: input.position.x,
y: input.position.y,
z: input.position.z,
parentId: input.position.parentId,
type: "solar",
});
const directionVector = new Vector3(0, 0, 1)
.normalize()
.multiplyScalar(50);

torpedoEntity.addComponent("velocity", {
x: directionVector.x,
y: directionVector.y,
z: directionVector.z,
});
torpedoEntity.addComponent("isTorpedo", {
launcherId: -1,
targetId: input.objectId,
yield: 1,
damageType: null,
color: "white",
guidanceMode: "visual",
guidanceRange: 5000,
speed: 50,
maxForce: 10,
maxRange: 25000,
});
torpedoEntity.addComponent("mass", { mass: 1500 });

ctx.flight?.ecs.addEntity(torpedoEntity);

pubsub.publish.starmapCore.torpedos({
systemId: torpedoEntity.components.position?.parentId || null,
});
}),
setShipsBehavior: t.procedure
.meta({ action: true })
.input(
Expand Down
1 change: 1 addition & 0 deletions server/src/spawners/ship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export async function spawnShip(
...params.assets,
},
});
entity.addComponent("hull", { hull: 1 });
if (params.position) {
entity.addComponent("position", params.position);
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/systems/ShieldsSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class ShieldsSystem extends System {
if (entity.components.power && entity.components.isShields) {
const { currentPower } = entity.components.power;
const { state, maxStrength, strength } = entity.components.isShields;
let strengthToRecharge = currentPower * elapsedTimeHours * 100;
let strengthToRecharge = currentPower * elapsedTimeHours * 10;
if (state === "down") {
// Quickly drain shields when they are down
strengthToRecharge = (-maxStrength / SHIELD_DISCHARGE_TIME) * elapsed;
Expand Down

0 comments on commit d862595

Please sign in to comment.