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";
interface IParams {
@ -6,7 +5,7 @@ interface IParams {
type?: number;
}
export class ActionIdentifier implements IActionIdentifier {
export class ActionIdentifier {
name = "";
type = -1;

@ -1,5 +1,4 @@
import { Reviver, Generic_toJSON, Generic_fromJSON, IReviverValue } from "../utils/JSONReviver";
import { IActionIdentifier } from "./IActionIdentifier";
import { ActionIdentifier } from "./ActionIdentifier";
import { ActionTypes } from "./data/ActionTypes";
import { Growths } from "./data/Growths";
@ -66,7 +65,7 @@ export class Bladeburner {
actionTimeCurrent = 0;
actionTimeOverflow = 0;
action: IActionIdentifier = new ActionIdentifier({
action: ActionIdentifier = new ActionIdentifier({
type: ActionTypes["Idle"],
});
@ -88,11 +87,11 @@ export class Bladeburner {
events: true,
};
automateEnabled = false;
automateActionHigh: IActionIdentifier = new ActionIdentifier({
automateActionHigh: ActionIdentifier = new ActionIdentifier({
type: ActionTypes["Idle"],
});
automateThreshHigh = 0;
automateActionLow: IActionIdentifier = new ActionIdentifier({
automateActionLow: ActionIdentifier = new ActionIdentifier({
type: ActionTypes["Idle"],
});
automateThreshLow = 0;
@ -124,7 +123,7 @@ export class Bladeburner {
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
if (this.blackops[actionId.name] != null) {
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. */
startAction(actionId: IActionIdentifier): void {
startAction(actionId: ActionIdentifier): void {
if (actionId == null) return;
this.action = actionId;
this.actionTimeCurrent = 0;
@ -309,7 +308,7 @@ export class Bladeburner {
}
// working on
getActionIdFromTypeAndName(type = "", name = ""): IActionIdentifier | null {
getActionIdFromTypeAndName(type = "", name = ""): ActionIdentifier | null {
if (type === "" || name === "") {
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
* 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) {
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();
switch (actionIdent.type) {
case ActionTypes["Contract"]:
@ -2060,7 +2059,7 @@ export class Bladeburner {
}
}
getTypeAndNameFromActionId(actionId: IActionIdentifier): {
getTypeAndNameFromActionId(actionId: ActionIdentifier): {
type: 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 Button from "@mui/material/Button";
import { AugmentationNames } from "../../Augmentation/data/AugmentationNames";
import { ActionIdentifier } from "../ActionIdentifier";
interface IProps {
bladeburner: Bladeburner;
@ -13,7 +14,7 @@ interface IProps {
rerender: () => void;
}
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) {
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 { BaseGift } from "./BaseGift";
import { IStaneksGift } from "./IStaneksGift";
import { StaneksGift } from "./StaneksGift";
export let staneksGift: IStaneksGift = new StaneksGift();
export let staneksGift = new StaneksGift();
export function loadStaneksGift(saveString: string): void {
if (saveString) {
@ -23,7 +23,7 @@ export function zeros(width: number, height: number): number[][] {
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[][];
for (let i = 0; i < gift.width(); i++) {
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 { ActiveFragment } from "./ActiveFragment";
import { FragmentType } from "./FragmentType";
import { IStaneksGift } from "./IStaneksGift";
import { BaseGift } from "./BaseGift";
import { Factions } from "../Faction/Factions";
import { CalculateEffect } from "./formulas/effect";
import { StaneksGiftEvents } from "./StaneksGiftEvents";
@ -14,9 +14,11 @@ import { Player } from "../Player";
import { AugmentationNames } from "../Augmentation/data/AugmentationNames";
import { defaultMultipliers, mergeMultipliers, Multipliers, scaleMultipliers } from "../PersonObjects/Multipliers";
export class StaneksGift implements IStaneksGift {
export class StaneksGift extends BaseGift {
storedCycles = 0;
fragments: ActiveFragment[] = [];
constructor() {
super();
}
baseSize(): number {
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);
}
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 {
let amt = 0;
for (const aFrag of this.fragments) {

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

@ -1,7 +1,7 @@
import { Box, Table } from "@mui/material";
import * as React from "react";
import { ActiveFragment } from "../ActiveFragment";
import { DummyGift } from "../DummyGift";
import { BaseGift } from "../BaseGift";
import { Grid } from "./Grid";
import { zeros } from "../Helper";
@ -12,7 +12,7 @@ interface IProps {
}
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);
return (
<Box>

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

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

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

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

@ -3,7 +3,7 @@ import { convertTimeMsToTimeElapsedString } from "../../utils/StringHelperFuncti
import { CONSTANTS } from "../../Constants";
import { StaneksGiftEvents } from "../StaneksGiftEvents";
import { MainBoard } from "./MainBoard";
import { IStaneksGift } from "../IStaneksGift";
import { StaneksGift } from "../StaneksGift";
import { Info } from "@mui/icons-material";
import { dialogBoxCreate } from "../../ui/React/DialogBox";
import Typography from "@mui/material/Typography";
@ -13,7 +13,7 @@ import { DummyGrid } from "./DummyGrid";
import Container from "@mui/material/Container";
type IProps = {
staneksGift: IStaneksGift;
staneksGift: StaneksGift;
};
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 { Sleeve } from "../Sleeve/Sleeve";
import { isSleeveCompanyWork } from "../Sleeve/Work/SleeveCompanyWork";
import {
calculateSkillProgress as calculateSkillProgressF,
ISkillProgress,
} from "../formulas/skill";
import { calculateSkillProgress as calculateSkillProgressF, ISkillProgress } from "../formulas/skill";
import { GetServer, AddToAllServers, createUniqueRandomIp } from "../../Server/AllServers";
import { Server } from "../../Server/Server";
import { safetlyCreateUniqueServer } from "../../Server/ServerHelpers";