2022-07-10 07:37:36 +02:00
|
|
|
import { dialogBoxCreate } from "../ui/React/DialogBox";
|
2023-04-07 06:33:51 +02:00
|
|
|
import { constructorsForReviver, Generic_toJSON, Generic_fromJSON, IReviverValue } from "../utils/JSONReviver";
|
2023-06-12 06:34:20 +02:00
|
|
|
import { AugmentationName, CompletedProgramName } from "@enums";
|
2022-07-10 07:37:36 +02:00
|
|
|
import { CONSTANTS } from "../Constants";
|
2022-10-10 00:42:14 +02:00
|
|
|
import { Player } from "@player";
|
2022-07-10 07:37:36 +02:00
|
|
|
import { Programs } from "../Programs/Programs";
|
|
|
|
import { Work, WorkType } from "./Work";
|
|
|
|
import { Program } from "../Programs/Program";
|
2022-11-09 13:26:26 +01:00
|
|
|
import { calculateIntelligenceBonus } from "../PersonObjects/formulas/intelligence";
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
import { asProgramFilePath } from "../Paths/ProgramFilePath";
|
2022-07-10 07:37:36 +02:00
|
|
|
|
|
|
|
export const isCreateProgramWork = (w: Work | null): w is CreateProgramWork =>
|
|
|
|
w !== null && w.type === WorkType.CREATE_PROGRAM;
|
|
|
|
|
|
|
|
interface CreateProgramWorkParams {
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
programName: CompletedProgramName;
|
2022-07-10 07:37:36 +02:00
|
|
|
singularity: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class CreateProgramWork extends Work {
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
programName: CompletedProgramName;
|
2022-07-10 07:37:36 +02:00
|
|
|
// amount of effective work completed on the program (time boosted by skills).
|
|
|
|
unitCompleted: number;
|
|
|
|
|
|
|
|
constructor(params?: CreateProgramWorkParams) {
|
2022-07-12 07:54:19 +02:00
|
|
|
super(WorkType.CREATE_PROGRAM, params?.singularity ?? true);
|
2022-07-10 07:37:36 +02:00
|
|
|
this.unitCompleted = 0;
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
this.programName = params?.programName ?? CompletedProgramName.bruteSsh;
|
2022-07-10 07:37:36 +02:00
|
|
|
|
2022-09-06 15:07:12 +02:00
|
|
|
if (params) {
|
|
|
|
for (let i = 0; i < Player.getHomeComputer().programs.length; ++i) {
|
|
|
|
const programFile = Player.getHomeComputer().programs[i];
|
2022-07-10 07:37:36 +02:00
|
|
|
if (programFile.startsWith(this.programName) && programFile.endsWith("%-INC")) {
|
|
|
|
const res = programFile.split("-");
|
|
|
|
if (res.length != 3) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const percComplete = Number(res[1].slice(0, -1));
|
|
|
|
if (isNaN(percComplete) || percComplete < 0 || percComplete >= 100) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this.unitCompleted = (percComplete / 100) * this.unitNeeded();
|
2022-09-06 15:07:12 +02:00
|
|
|
Player.getHomeComputer().programs.splice(i, 1);
|
2022-07-10 07:37:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unitNeeded(): number {
|
|
|
|
return this.getProgram().create?.time ?? 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
getProgram(): Program {
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
return Programs[this.programName];
|
2022-07-10 07:37:36 +02:00
|
|
|
}
|
|
|
|
|
2022-09-06 15:07:12 +02:00
|
|
|
process(cycles: number): boolean {
|
2022-07-10 07:37:36 +02:00
|
|
|
let focusBonus = 1;
|
2023-06-12 06:34:20 +02:00
|
|
|
if (!Player.hasAugmentation(AugmentationName.NeuroreceptorManager, true)) {
|
2022-09-06 15:07:12 +02:00
|
|
|
focusBonus = Player.focus ? 1 : CONSTANTS.BaseFocusBonus;
|
2022-07-10 07:37:36 +02:00
|
|
|
}
|
|
|
|
//Higher hacking skill will allow you to create programs faster
|
|
|
|
const reqLvl = this.getProgram().create?.level ?? 0;
|
2022-11-09 13:26:26 +01:00
|
|
|
let skillMult = (Player.skills.hacking / reqLvl) * calculateIntelligenceBonus(Player.skills.intelligence, 3); //This should always be greater than 1;
|
2022-07-10 07:37:36 +02:00
|
|
|
skillMult = 1 + (skillMult - 1) / 5; //The divider constant can be adjusted as necessary
|
|
|
|
skillMult *= focusBonus;
|
|
|
|
//Skill multiplier directly applied to "time worked"
|
|
|
|
this.cyclesWorked += cycles;
|
2023-02-21 15:44:18 +01:00
|
|
|
this.unitCompleted += CONSTANTS.MilliPerCycle * cycles * skillMult;
|
2022-07-10 07:37:36 +02:00
|
|
|
|
|
|
|
if (this.unitCompleted >= this.unitNeeded()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2022-09-06 15:07:12 +02:00
|
|
|
finish(cancelled: boolean): void {
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
const programName = asProgramFilePath(this.programName);
|
2022-07-10 07:37:36 +02:00
|
|
|
if (!cancelled) {
|
|
|
|
//Complete case
|
2022-09-06 15:07:12 +02:00
|
|
|
Player.gainIntelligenceExp(
|
2023-02-21 15:44:18 +01:00
|
|
|
(CONSTANTS.IntelligenceProgramBaseExpGain * this.cyclesWorked * CONSTANTS.MilliPerCycle) / 1000,
|
2022-07-10 07:37:36 +02:00
|
|
|
);
|
|
|
|
if (!this.singularity) {
|
|
|
|
const lines = [
|
|
|
|
`You've finished creating ${programName}!`,
|
|
|
|
"The new program can be found on your home computer.",
|
|
|
|
];
|
2022-11-06 23:27:40 +01:00
|
|
|
dialogBoxCreate(lines.join("\n"));
|
2022-07-10 07:37:36 +02:00
|
|
|
}
|
|
|
|
|
2022-09-06 15:07:12 +02:00
|
|
|
if (!Player.getHomeComputer().programs.includes(programName)) {
|
|
|
|
Player.getHomeComputer().programs.push(programName);
|
2022-07-10 07:37:36 +02:00
|
|
|
}
|
2022-09-06 15:07:12 +02:00
|
|
|
} else if (!Player.getHomeComputer().programs.includes(programName)) {
|
2022-07-10 07:37:36 +02:00
|
|
|
//Incomplete case
|
|
|
|
const perc = ((100 * this.unitCompleted) / this.unitNeeded()).toFixed(2);
|
FILES: Path rework & typesafety (#479)
* Added new types for various file paths, all in the Paths folder.
* TypeSafety and other helper functions related to these types
* Added basic globbing support with * and ?. Currently only implemented for Script/Text, on nano and download terminal commands
* Enforcing the new types throughout the codebase, plus whatever rewrites happened along the way
* Server.textFiles is now a map
* TextFile no longer uses a fn property, now it is filename
* Added a shared ContentFile interface for shared functionality between TextFile and Script.
* related to ContentFile change above, the player is now allowed to move a text file to a script file and vice versa.
* File paths no longer conditionally start with slashes, and all directory names other than root have ending slashes. The player is still able to provide paths starting with / but this now indicates that the player is specifying an absolute path instead of one relative to root.
* Singularized the MessageFilename and LiteratureName enums
* Because they now only accept correct types, server.writeToXFile functions now always succeed (the only reasons they could fail before were invalid filepath).
* Fix several issues with tab completion, which included pretty much a complete rewrite
* Changed the autocomplete display options so there's less chance it clips outside the display area.
* Turned CompletedProgramName into an enum.
* Got rid of programsMetadata, and programs and DarkWebItems are now initialized immediately instead of relying on initializers called from the engine.
* For any executable (program, cct, or script file) pathing can be used directly to execute without using the run command (previously the command had to start with ./ and it wasn't actually using pathing).
2023-04-24 16:26:57 +02:00
|
|
|
const incompleteName = asProgramFilePath(programName + "-" + perc + "%-INC");
|
2022-09-06 15:07:12 +02:00
|
|
|
Player.getHomeComputer().programs.push(incompleteName);
|
2022-07-10 07:37:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-26 21:30:12 +02:00
|
|
|
APICopy(): Record<string, unknown> {
|
|
|
|
return {
|
|
|
|
type: this.type,
|
|
|
|
cyclesWorked: this.cyclesWorked,
|
|
|
|
programName: this.programName,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-10-04 12:40:10 +02:00
|
|
|
/** Serialize the current object to a JSON save state. */
|
2022-07-12 07:54:19 +02:00
|
|
|
toJSON(): IReviverValue {
|
2022-07-10 07:37:36 +02:00
|
|
|
return Generic_toJSON("CreateProgramWork", this);
|
|
|
|
}
|
|
|
|
|
2022-10-09 07:25:31 +02:00
|
|
|
/** Initializes a CreateProgramWork object from a JSON save state. */
|
2022-07-12 07:54:19 +02:00
|
|
|
static fromJSON(value: IReviverValue): CreateProgramWork {
|
2022-07-10 07:37:36 +02:00
|
|
|
return Generic_fromJSON(CreateProgramWork, value.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-07 06:33:51 +02:00
|
|
|
constructorsForReviver.CreateProgramWork = CreateProgramWork;
|