More classes as types

This commit is contained in:
Snarling 2022-09-20 03:15:00 -04:00
parent 2213d06159
commit 557bc12562
18 changed files with 67 additions and 143 deletions

@ -1,4 +1,3 @@
import { IActionIdentifier } from "./IActionIdentifier";
import { Generic_fromJSON, Generic_toJSON, IReviverValue, Reviver } from "../utils/JSONReviver"; import { Generic_fromJSON, Generic_toJSON, IReviverValue, Reviver } from "../utils/JSONReviver";
interface IParams { interface IParams {
@ -6,7 +5,7 @@ interface IParams {
type?: number; type?: number;
} }
export class ActionIdentifier implements IActionIdentifier { export class ActionIdentifier {
name = ""; name = "";
type = -1; type = -1;

@ -1,5 +1,4 @@
import { Reviver, Generic_toJSON, Generic_fromJSON, IReviverValue } from "../utils/JSONReviver"; import { Reviver, Generic_toJSON, Generic_fromJSON, IReviverValue } from "../utils/JSONReviver";
import { IActionIdentifier } from "./IActionIdentifier";
import { ActionIdentifier } from "./ActionIdentifier"; import { ActionIdentifier } from "./ActionIdentifier";
import { ActionTypes } from "./data/ActionTypes"; import { ActionTypes } from "./data/ActionTypes";
import { Growths } from "./data/Growths"; import { Growths } from "./data/Growths";
@ -66,7 +65,7 @@ export class Bladeburner {
actionTimeCurrent = 0; actionTimeCurrent = 0;
actionTimeOverflow = 0; actionTimeOverflow = 0;
action: IActionIdentifier = new ActionIdentifier({ action: ActionIdentifier = new ActionIdentifier({
type: ActionTypes["Idle"], type: ActionTypes["Idle"],
}); });
@ -88,11 +87,11 @@ export class Bladeburner {
events: true, events: true,
}; };
automateEnabled = false; automateEnabled = false;
automateActionHigh: IActionIdentifier = new ActionIdentifier({ automateActionHigh: ActionIdentifier = new ActionIdentifier({
type: ActionTypes["Idle"], type: ActionTypes["Idle"],
}); });
automateThreshHigh = 0; automateThreshHigh = 0;
automateActionLow: IActionIdentifier = new ActionIdentifier({ automateActionLow: ActionIdentifier = new ActionIdentifier({
type: ActionTypes["Idle"], type: ActionTypes["Idle"],
}); });
automateThreshLow = 0; automateThreshLow = 0;
@ -124,7 +123,7 @@ export class Bladeburner {
return Math.min(1, this.stamina / (0.5 * this.maxStamina)); return Math.min(1, this.stamina / (0.5 * this.maxStamina));
} }
canAttemptBlackOp(actionId: IActionIdentifier): BlackOpsAttempt { canAttemptBlackOp(actionId: ActionIdentifier): BlackOpsAttempt {
// Safety measure - don't repeat BlackOps that are already done // Safety measure - don't repeat BlackOps that are already done
if (this.blackops[actionId.name] != null) { if (this.blackops[actionId.name] != null) {
return { error: "Tried to start a Black Operation that had already been completed" }; return { error: "Tried to start a Black Operation that had already been completed" };
@ -162,7 +161,7 @@ export class Bladeburner {
} }
/** This function is only for the player. Sleeves use their own functions to perform blade work. */ /** This function is only for the player. Sleeves use their own functions to perform blade work. */
startAction(actionId: IActionIdentifier): void { startAction(actionId: ActionIdentifier): void {
if (actionId == null) return; if (actionId == null) return;
this.action = actionId; this.action = actionId;
this.actionTimeCurrent = 0; this.actionTimeCurrent = 0;
@ -309,7 +308,7 @@ export class Bladeburner {
} }
// working on // working on
getActionIdFromTypeAndName(type = "", name = ""): IActionIdentifier | null { getActionIdFromTypeAndName(type = "", name = ""): ActionIdentifier | null {
if (type === "" || name === "") { if (type === "" || name === "") {
return null; return null;
} }
@ -1201,7 +1200,7 @@ export class Bladeburner {
} }
} }
getActionObject(actionId: IActionIdentifier): Action | null { getActionObject(actionId: ActionIdentifier): Action | null {
/** /**
* Given an ActionIdentifier object, returns the corresponding * Given an ActionIdentifier object, returns the corresponding
* GeneralAction, Contract, Operation, or BlackOperation object * GeneralAction, Contract, Operation, or BlackOperation object
@ -1231,7 +1230,7 @@ export class Bladeburner {
} }
} }
completeContract(success: boolean, actionIdent: IActionIdentifier): void { completeContract(success: boolean, actionIdent: ActionIdentifier): void {
if (actionIdent.type !== ActionTypes.Contract) { if (actionIdent.type !== ActionTypes.Contract) {
throw new Error("completeContract() called even though current action is not a Contract"); throw new Error("completeContract() called even though current action is not a Contract");
} }
@ -1256,7 +1255,7 @@ export class Bladeburner {
} }
} }
completeAction(person: Person, actionIdent: IActionIdentifier, isPlayer = true): ITaskTracker { completeAction(person: Person, actionIdent: ActionIdentifier, isPlayer = true): ITaskTracker {
let retValue = createTaskTracker(); let retValue = createTaskTracker();
switch (actionIdent.type) { switch (actionIdent.type) {
case ActionTypes["Contract"]: case ActionTypes["Contract"]:
@ -2060,7 +2059,7 @@ export class Bladeburner {
} }
} }
getTypeAndNameFromActionId(actionId: IActionIdentifier): { getTypeAndNameFromActionId(actionId: ActionIdentifier): {
type: string; type: string;
name: string; name: string;
} { } {

@ -1,4 +0,0 @@
export interface IActionIdentifier {
name: string;
type: number;
}

@ -5,6 +5,7 @@ import { BlackOperation } from "../BlackOperation";
import { Player } from "../../Player"; import { Player } from "../../Player";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import { AugmentationNames } from "../../Augmentation/data/AugmentationNames"; import { AugmentationNames } from "../../Augmentation/data/AugmentationNames";
import { ActionIdentifier } from "../ActionIdentifier";
interface IProps { interface IProps {
bladeburner: Bladeburner; bladeburner: Bladeburner;
@ -13,7 +14,7 @@ interface IProps {
rerender: () => void; rerender: () => void;
} }
export function StartButton(props: IProps): React.ReactElement { export function StartButton(props: IProps): React.ReactElement {
const action = props.bladeburner.getActionObject({ name: props.name, type: props.type }); const action = props.bladeburner.getActionObject(new ActionIdentifier({ name: props.name, type: props.type }));
if (action == null) { if (action == null) {
throw new Error("Failed to get Operation Object for: " + props.name); throw new Error("Failed to get Operation Object for: " + props.name);
} }

29
src/CotMG/BaseGift.ts Normal file

@ -0,0 +1,29 @@
import { ActiveFragment } from "./ActiveFragment";
export class BaseGift {
fragments: ActiveFragment[];
_width?: number;
_height?: number;
constructor(width?: number, height?: number, fragments: ActiveFragment[] = []) {
this.fragments = fragments;
this._width = width;
this._height = height;
}
width(): number {
return this._width || 4;
}
height(): number {
return this._height || 4;
}
fragmentAt(worldX: number, worldY: number): ActiveFragment | undefined {
for (const aFrag of this.fragments) {
if (aFrag.fullAt(worldX, worldY)) {
return aFrag;
}
}
return undefined;
}
}

@ -1,67 +0,0 @@
import { ActiveFragment } from "./ActiveFragment";
import { IStaneksGift } from "./IStaneksGift";
export class DummyGift implements IStaneksGift {
storedCycles = 0;
fragments: ActiveFragment[] = [];
_width: number;
_height: number;
constructor(width: number, height: number, fragments: ActiveFragment[]) {
this.fragments = fragments;
this._width = width;
this._height = height;
}
width(): number {
return this._width;
}
height(): number {
return this._height;
}
charge(): void {
throw new Error("unimplemented for dummy gift");
}
process(): void {
throw new Error("unimplemented for dummy gift");
}
effect(): number {
throw new Error("unimplemented for dummy gift");
}
canPlace(): boolean {
throw new Error("unimplemented for dummy gift");
}
place(): boolean {
throw new Error("unimplemented for dummy gift");
}
findFragment(): ActiveFragment | undefined {
throw new Error("unimplemented for dummy gift");
}
fragmentAt(worldX: number, worldY: number): ActiveFragment | undefined {
for (const aFrag of this.fragments) {
if (aFrag.fullAt(worldX, worldY)) {
return aFrag;
}
}
return undefined;
}
delete(): boolean {
throw new Error("unimplemented for dummy gift");
}
clear(): void {
throw new Error("unimplemented for dummy gift");
}
count(): number {
throw new Error("unimplemented for dummy gift");
}
inBonus(): boolean {
throw new Error("unimplemented for dummy gift");
}
prestigeAugmentation(): void {
throw new Error("unimplemented for dummy gift");
}
prestigeSourceFile(): void {
throw new Error("unimplemented for dummy gift");
}
}

@ -1,9 +1,9 @@
import { Reviver } from "../utils/JSONReviver"; import { Reviver } from "../utils/JSONReviver";
import { BaseGift } from "./BaseGift";
import { IStaneksGift } from "./IStaneksGift";
import { StaneksGift } from "./StaneksGift"; import { StaneksGift } from "./StaneksGift";
export let staneksGift: IStaneksGift = new StaneksGift(); export let staneksGift = new StaneksGift();
export function loadStaneksGift(saveString: string): void { export function loadStaneksGift(saveString: string): void {
if (saveString) { if (saveString) {
@ -23,7 +23,7 @@ export function zeros(width: number, height: number): number[][] {
return array; return array;
} }
export function calculateGrid(gift: IStaneksGift): number[][] { export function calculateGrid(gift: BaseGift): number[][] {
const newgrid = zeros(gift.width(), gift.height()) as unknown as number[][]; const newgrid = zeros(gift.width(), gift.height()) as unknown as number[][];
for (let i = 0; i < gift.width(); i++) { for (let i = 0; i < gift.width(); i++) {
for (let j = 0; j < gift.height(); j++) { for (let j = 0; j < gift.height(); j++) {

@ -1,22 +0,0 @@
import { ActiveFragment } from "./ActiveFragment";
import { Fragment } from "./Fragment";
export interface IStaneksGift {
storedCycles: number;
fragments: ActiveFragment[];
width(): number;
height(): number;
charge(fragment: ActiveFragment, threads: number): void;
process(n: number): void;
effect(fragment: ActiveFragment): number;
canPlace(x: number, y: number, rotation: number, fragment: Fragment): boolean;
place(x: number, y: number, rotation: number, fragment: Fragment): boolean;
findFragment(rootX: number, rootY: number): ActiveFragment | undefined;
fragmentAt(rootX: number, rootY: number): ActiveFragment | undefined;
delete(rootX: number, rootY: number): boolean;
clear(): void;
count(fragment: Fragment): number;
inBonus(): boolean;
prestigeAugmentation(): void;
prestigeSourceFile(): void;
}

@ -2,7 +2,7 @@ import { FactionNames } from "../Faction/data/FactionNames";
import { Fragment } from "./Fragment"; import { Fragment } from "./Fragment";
import { ActiveFragment } from "./ActiveFragment"; import { ActiveFragment } from "./ActiveFragment";
import { FragmentType } from "./FragmentType"; import { FragmentType } from "./FragmentType";
import { IStaneksGift } from "./IStaneksGift"; import { BaseGift } from "./BaseGift";
import { Factions } from "../Faction/Factions"; import { Factions } from "../Faction/Factions";
import { CalculateEffect } from "./formulas/effect"; import { CalculateEffect } from "./formulas/effect";
import { StaneksGiftEvents } from "./StaneksGiftEvents"; import { StaneksGiftEvents } from "./StaneksGiftEvents";
@ -14,9 +14,11 @@ import { Player } from "../Player";
import { AugmentationNames } from "../Augmentation/data/AugmentationNames"; import { AugmentationNames } from "../Augmentation/data/AugmentationNames";
import { defaultMultipliers, mergeMultipliers, Multipliers, scaleMultipliers } from "../PersonObjects/Multipliers"; import { defaultMultipliers, mergeMultipliers, Multipliers, scaleMultipliers } from "../PersonObjects/Multipliers";
export class StaneksGift implements IStaneksGift { export class StaneksGift extends BaseGift {
storedCycles = 0; storedCycles = 0;
fragments: ActiveFragment[] = []; constructor() {
super();
}
baseSize(): number { baseSize(): number {
return StanekConstants.BaseSize + BitNodeMultipliers.StaneksGiftExtraSize + Player.sourceFileLvl(13); return StanekConstants.BaseSize + BitNodeMultipliers.StaneksGiftExtraSize + Player.sourceFileLvl(13);
@ -95,16 +97,6 @@ export class StaneksGift implements IStaneksGift {
return this.fragments.find((f) => f.x === rootX && f.y === rootY); return this.fragments.find((f) => f.x === rootX && f.y === rootY);
} }
fragmentAt(worldX: number, worldY: number): ActiveFragment | undefined {
for (const aFrag of this.fragments) {
if (aFrag.fullAt(worldX, worldY)) {
return aFrag;
}
}
return undefined;
}
count(fragment: Fragment): number { count(fragment: Fragment): number {
let amt = 0; let amt = 0;
for (const aFrag of this.fragments) { for (const aFrag of this.fragments) {

@ -1,6 +1,6 @@
import React from "react"; import React from "react";
import { ActiveFragment } from "../ActiveFragment"; import { ActiveFragment } from "../ActiveFragment";
import { IStaneksGift } from "../IStaneksGift"; import { StaneksGift } from "../StaneksGift";
import { FragmentType, Effect } from "../FragmentType"; import { FragmentType, Effect } from "../FragmentType";
import { numeralWrapper } from "../../ui/numeralFormat"; import { numeralWrapper } from "../../ui/numeralFormat";
@ -10,7 +10,7 @@ import Table from "@mui/material/Table";
import { TableBody, TableCell, TableRow } from "@mui/material"; import { TableBody, TableCell, TableRow } from "@mui/material";
type IProps = { type IProps = {
gift: IStaneksGift; gift: StaneksGift;
}; };
function formatEffect(effect: number, type: FragmentType): string { function formatEffect(effect: number, type: FragmentType): string {

@ -1,7 +1,7 @@
import { Box, Table } from "@mui/material"; import { Box, Table } from "@mui/material";
import * as React from "react"; import * as React from "react";
import { ActiveFragment } from "../ActiveFragment"; import { ActiveFragment } from "../ActiveFragment";
import { DummyGift } from "../DummyGift"; import { BaseGift } from "../BaseGift";
import { Grid } from "./Grid"; import { Grid } from "./Grid";
import { zeros } from "../Helper"; import { zeros } from "../Helper";
@ -12,7 +12,7 @@ interface IProps {
} }
export function DummyGrid(props: IProps): React.ReactElement { export function DummyGrid(props: IProps): React.ReactElement {
const gift = new DummyGift(props.width, props.height, props.fragments); const gift = new BaseGift(props.width, props.height, props.fragments);
const ghostGrid = zeros(props.width, props.height); const ghostGrid = zeros(props.width, props.height);
return ( return (
<Box> <Box>

@ -1,6 +1,6 @@
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import { ActiveFragment } from "../ActiveFragment"; import { ActiveFragment } from "../ActiveFragment";
import { IStaneksGift } from "../IStaneksGift"; import { StaneksGift } from "../StaneksGift";
import { FragmentType, Effect } from "../FragmentType"; import { FragmentType, Effect } from "../FragmentType";
import { numeralWrapper } from "../../ui/numeralFormat"; import { numeralWrapper } from "../../ui/numeralFormat";
@ -8,7 +8,7 @@ import Paper from "@mui/material/Paper";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
type IProps = { type IProps = {
gift: IStaneksGift; gift: StaneksGift;
fragment: ActiveFragment | undefined; fragment: ActiveFragment | undefined;
x: number; x: number;
y: number; y: number;

@ -1,7 +1,7 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { Fragments, Fragment, NoneFragment, DeleteFragment } from "../Fragment"; import { Fragments, Fragment, NoneFragment, DeleteFragment } from "../Fragment";
import { FragmentType, Effect } from "../FragmentType"; import { FragmentType, Effect } from "../FragmentType";
import { IStaneksGift } from "../IStaneksGift"; import { StaneksGift } from "../StaneksGift";
import { FragmentPreview } from "./FragmentPreview"; import { FragmentPreview } from "./FragmentPreview";
import { numeralWrapper } from "../../ui/numeralFormat"; import { numeralWrapper } from "../../ui/numeralFormat";
@ -11,7 +11,7 @@ import Typography from "@mui/material/Typography";
import Box from "@mui/material/Box"; import Box from "@mui/material/Box";
type IOptionProps = { type IOptionProps = {
gift: IStaneksGift; gift: StaneksGift;
fragment: Fragment; fragment: Fragment;
selectFragment: (fragment: Fragment) => void; selectFragment: (fragment: Fragment) => void;
}; };
@ -46,7 +46,7 @@ function FragmentOption(props: IOptionProps): React.ReactElement {
} }
type IProps = { type IProps = {
gift: IStaneksGift; gift: StaneksGift;
selectFragment: (fragment: Fragment) => void; selectFragment: (fragment: Fragment) => void;
}; };

@ -2,14 +2,14 @@ import { TableBody, TableRow } from "@mui/material";
import * as React from "react"; import * as React from "react";
import { ActiveFragment } from "../ActiveFragment"; import { ActiveFragment } from "../ActiveFragment";
import { calculateGrid } from "../Helper"; import { calculateGrid } from "../Helper";
import { IStaneksGift } from "../IStaneksGift"; import { BaseGift } from "../BaseGift";
import { Cell } from "./Cell"; import { Cell } from "./Cell";
interface IProps { interface IProps {
width: number; width: number;
height: number; height: number;
ghostGrid: number[][]; ghostGrid: number[][];
gift: IStaneksGift; gift: BaseGift;
enter(i: number, j: number): void; enter(i: number, j: number): void;
click(i: number, j: number): void; click(i: number, j: number): void;
} }

@ -1,7 +1,7 @@
import * as React from "react"; import * as React from "react";
import { Fragment, NoneFragment } from "../Fragment"; import { Fragment, NoneFragment } from "../Fragment";
import { FragmentType } from "../FragmentType"; import { FragmentType } from "../FragmentType";
import { IStaneksGift } from "../IStaneksGift"; import { StaneksGift } from "../StaneksGift";
import { FragmentInspector } from "./FragmentInspector"; import { FragmentInspector } from "./FragmentInspector";
import { FragmentSelector } from "./FragmentSelector"; import { FragmentSelector } from "./FragmentSelector";
import Box from "@mui/material/Box"; import Box from "@mui/material/Box";
@ -14,7 +14,7 @@ import Tooltip from "@mui/material/Tooltip";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
interface IProps { interface IProps {
gift: IStaneksGift; gift: StaneksGift;
} }
export function MainBoard(props: IProps): React.ReactElement { export function MainBoard(props: IProps): React.ReactElement {

@ -3,7 +3,7 @@ import { convertTimeMsToTimeElapsedString } from "../../utils/StringHelperFuncti
import { CONSTANTS } from "../../Constants"; import { CONSTANTS } from "../../Constants";
import { StaneksGiftEvents } from "../StaneksGiftEvents"; import { StaneksGiftEvents } from "../StaneksGiftEvents";
import { MainBoard } from "./MainBoard"; import { MainBoard } from "./MainBoard";
import { IStaneksGift } from "../IStaneksGift"; import { StaneksGift } from "../StaneksGift";
import { Info } from "@mui/icons-material"; import { Info } from "@mui/icons-material";
import { dialogBoxCreate } from "../../ui/React/DialogBox"; import { dialogBoxCreate } from "../../ui/React/DialogBox";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
@ -13,7 +13,7 @@ import { DummyGrid } from "./DummyGrid";
import Container from "@mui/material/Container"; import Container from "@mui/material/Container";
type IProps = { type IProps = {
staneksGift: IStaneksGift; staneksGift: StaneksGift;
}; };
export function StaneksGiftRoot({ staneksGift }: IProps): React.ReactElement { export function StaneksGiftRoot({ staneksGift }: IProps): React.ReactElement {

@ -178,4 +178,4 @@ export class PlayerObject extends Person {
} }
} }
Reviver.constructors.PlayerObject = PlayerObject; Reviver.constructors.PlayerObject = PlayerObject;

@ -23,10 +23,7 @@ import { CityName } from "../../Locations/data/CityNames";
import { LocationName } from "../../Locations/data/LocationNames"; import { LocationName } from "../../Locations/data/LocationNames";
import { Sleeve } from "../Sleeve/Sleeve"; import { Sleeve } from "../Sleeve/Sleeve";
import { isSleeveCompanyWork } from "../Sleeve/Work/SleeveCompanyWork"; import { isSleeveCompanyWork } from "../Sleeve/Work/SleeveCompanyWork";
import { import { calculateSkillProgress as calculateSkillProgressF, ISkillProgress } from "../formulas/skill";
calculateSkillProgress as calculateSkillProgressF,
ISkillProgress,
} from "../formulas/skill";
import { GetServer, AddToAllServers, createUniqueRandomIp } from "../../Server/AllServers"; import { GetServer, AddToAllServers, createUniqueRandomIp } from "../../Server/AllServers";
import { Server } from "../../Server/Server"; import { Server } from "../../Server/Server";
import { safetlyCreateUniqueServer } from "../../Server/ServerHelpers"; import { safetlyCreateUniqueServer } from "../../Server/ServerHelpers";