Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLADEBURNER: Separate Bladeburner Console Automation from script API (refactor). #1678

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 85 additions & 85 deletions src/Bladeburner/Bladeburner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class Bladeburner implements OperationTeam {

const arrayOfCommands = commands.split(";");
for (let i = 0; i < arrayOfCommands.length; ++i) {
this.executeConsoleCommand(arrayOfCommands[i]);
Bladeburner.executeConsoleCommand(this, arrayOfCommands[i]);
}
} catch (e: unknown) {
exceptionAlert(e);
Expand Down Expand Up @@ -237,21 +237,21 @@ export class Bladeburner implements OperationTeam {
this.storedCycles = clampInteger(this.storedCycles + numCycles, 0);
}

executeStartConsoleCommand(args: string[]): void {
private static executeStartConsoleCommand(blade: Bladeburner, args: string[]): void {
if (args.length !== 3) {
this.postToConsole("Invalid usage of 'start' console command: start [type] [name]");
this.postToConsole("Use 'help start' for more info");
blade.postToConsole("Invalid usage of 'start' console command: start [type] [name]");
blade.postToConsole("Use 'help start' for more info");
return;
}
const type = args[1];
const name = args[2];
const action = this.getActionFromTypeAndName(type, name);
const action = blade.getActionFromTypeAndName(type, name);
if (!action) {
this.postToConsole(`Invalid action type / name specified: type: ${type}, name: ${name}`);
blade.postToConsole(`Invalid action type / name specified: type: ${type}, name: ${name}`);
return;
}
const attempt = this.startAction(action.id);
this.postToConsole(attempt.message);
const attempt = blade.startAction(action.id);
blade.postToConsole(attempt.message);
}

getSkillMultsDisplay(): string[] {
Expand All @@ -262,59 +262,59 @@ export class Bladeburner implements OperationTeam {
return display;
}

executeSkillConsoleCommand(args: string[]): void {
private static executeSkillConsoleCommand(blade: Bladeburner, args: string[]): void {
switch (args.length) {
case 1: {
// Display Skill Help Command
this.postToConsole("Invalid usage of 'skill' console command: skill [action] [name]");
this.postToConsole("Use 'help skill' for more info");
blade.postToConsole("Invalid usage of 'skill' console command: skill [action] [name]");
blade.postToConsole("Use 'help skill' for more info");
break;
}
case 2: {
if (args[1].toLowerCase() === "list") {
// List all skills and their level
this.postToConsole("Skills: ");
blade.postToConsole("Skills: ");
for (const skill of Object.values(Skills)) {
const skillLevel = this.getSkillLevel(skill.name);
this.postToConsole(`${skill.name}: Level ${formatNumberNoSuffix(skillLevel, 0)}\n\nEffects: `);
const skillLevel = blade.getSkillLevel(skill.name);
blade.postToConsole(`${skill.name}: Level ${formatNumberNoSuffix(skillLevel, 0)}\n\nEffects: `);
}
for (const logEntry of this.getSkillMultsDisplay()) this.postToConsole(logEntry);
for (const logEntry of blade.getSkillMultsDisplay()) blade.postToConsole(logEntry);
} else {
this.postToConsole("Invalid usage of 'skill' console command: skill [action] [name]");
this.postToConsole("Use 'help skill' for more info");
blade.postToConsole("Invalid usage of 'skill' console command: skill [action] [name]");
blade.postToConsole("Use 'help skill' for more info");
}
break;
}
case 3: {
const skillName = args[2];
if (!getEnumHelper("BladeburnerSkillName").isMember(skillName)) {
this.postToConsole("Invalid skill name (Note that it is case-sensitive): " + skillName);
blade.postToConsole("Invalid skill name (Note that it is case-sensitive): " + skillName);
return;
}
const level = this.getSkillLevel(skillName);
const level = blade.getSkillLevel(skillName);
if (args[1].toLowerCase() === "list") {
this.postToConsole(skillName + ": Level " + formatNumberNoSuffix(level));
blade.postToConsole(skillName + ": Level " + formatNumberNoSuffix(level));
} else if (args[1].toLowerCase() === "level") {
const attempt = this.upgradeSkill(skillName);
this.postToConsole(attempt.message);
const attempt = blade.upgradeSkill(skillName);
blade.postToConsole(attempt.message);
} else {
this.postToConsole("Invalid usage of 'skill' console command: skill [action] [name]");
this.postToConsole("Use 'help skill' for more info");
blade.postToConsole("Invalid usage of 'skill' console command: skill [action] [name]");
blade.postToConsole("Use 'help skill' for more info");
}
break;
}
default: {
this.postToConsole("Invalid usage of 'skill' console command: skill [action] [name]");
this.postToConsole("Use 'help skill' for more info");
blade.postToConsole("Invalid usage of 'skill' console command: skill [action] [name]");
blade.postToConsole("Use 'help skill' for more info");
break;
}
}
}

executeLogConsoleCommand(args: string[]): void {
private static executeLogConsoleCommand(blade: Bladeburner, args: string[]): void {
if (args.length < 3) {
this.postToConsole("Invalid usage of log command: log [enable/disable] [action/event]");
this.postToConsole("Use 'help log' for more details and examples");
blade.postToConsole("Invalid usage of log command: log [enable/disable] [action/event]");
blade.postToConsole("Use 'help log' for more details and examples");
return;
}

Expand All @@ -326,69 +326,69 @@ export class Bladeburner implements OperationTeam {
switch (args[2].toLowerCase()) {
case "general":
case "gen":
this.logging.general = flag;
this.log("Logging " + (flag ? "enabled" : "disabled") + " for general actions");
blade.logging.general = flag;
blade.log("Logging " + (flag ? "enabled" : "disabled") + " for general actions");
break;
case "contract":
case "contracts":
this.logging.contracts = flag;
this.log("Logging " + (flag ? "enabled" : "disabled") + " for Contracts");
blade.logging.contracts = flag;
blade.log("Logging " + (flag ? "enabled" : "disabled") + " for Contracts");
break;
case "ops":
case "op":
case "operations":
case "operation":
this.logging.ops = flag;
this.log("Logging " + (flag ? "enabled" : "disabled") + " for Operations");
blade.logging.ops = flag;
blade.log("Logging " + (flag ? "enabled" : "disabled") + " for Operations");
break;
case "blackops":
case "blackop":
case "black operations":
case "black operation":
this.logging.blackops = flag;
this.log("Logging " + (flag ? "enabled" : "disabled") + " for BlackOps");
blade.logging.blackops = flag;
blade.log("Logging " + (flag ? "enabled" : "disabled") + " for BlackOps");
break;
case "event":
case "events":
this.logging.events = flag;
this.log("Logging " + (flag ? "enabled" : "disabled") + " for events");
blade.logging.events = flag;
blade.log("Logging " + (flag ? "enabled" : "disabled") + " for events");
break;
case "all":
this.logging.general = flag;
this.logging.contracts = flag;
this.logging.ops = flag;
this.logging.blackops = flag;
this.logging.events = flag;
this.log("Logging " + (flag ? "enabled" : "disabled") + " for everything");
blade.logging.general = flag;
blade.logging.contracts = flag;
blade.logging.ops = flag;
blade.logging.blackops = flag;
blade.logging.events = flag;
blade.log("Logging " + (flag ? "enabled" : "disabled") + " for everything");
break;
default:
this.postToConsole("Invalid action/event type specified: " + args[2]);
this.postToConsole(
blade.postToConsole("Invalid action/event type specified: " + args[2]);
blade.postToConsole(
"Examples of valid action/event identifiers are: [general, contracts, ops, blackops, events]",
);
break;
}
}

executeHelpConsoleCommand(args: string[]): void {
private static executeHelpConsoleCommand(blade: Bladeburner, args: string[]): void {
if (args.length === 1) {
for (const line of ConsoleHelpText.helpList) {
this.postToConsole(line);
blade.postToConsole(line);
}
} else {
for (let i = 1; i < args.length; ++i) {
if (!(args[i] in ConsoleHelpText)) continue;
const helpText = ConsoleHelpText[args[i]];
for (const line of helpText) {
this.postToConsole(line);
blade.postToConsole(line);
}
}
}
}

executeAutomateConsoleCommand(args: string[]): void {
private static executeAutomateConsoleCommand(blade: Bladeburner, args: string[]): void {
if (args.length !== 2 && args.length !== 4) {
this.postToConsole(
blade.postToConsole(
"Invalid use of 'automate' command: automate [var] [val] [hi/low]. Use 'help automate' for more info",
);
return;
Expand All @@ -398,30 +398,30 @@ export class Bladeburner implements OperationTeam {
if (args.length === 2) {
const flag = args[1];
if (flag.toLowerCase() === "status") {
this.postToConsole("Automation: " + (this.automateEnabled ? "enabled" : "disabled"));
this.postToConsole(
blade.postToConsole("Automation: " + (blade.automateEnabled ? "enabled" : "disabled"));
blade.postToConsole(
"When your stamina drops to " +
formatNumberNoSuffix(this.automateThreshLow, 0) +
formatNumberNoSuffix(blade.automateThreshLow, 0) +
", you will automatically switch to " +
(this.automateActionLow?.name ?? "Idle") +
(blade.automateActionLow?.name ?? "Idle") +
". When your stamina recovers to " +
formatNumberNoSuffix(this.automateThreshHigh, 0) +
formatNumberNoSuffix(blade.automateThreshHigh, 0) +
", you will automatically " +
"switch to " +
(this.automateActionHigh?.name ?? "Idle") +
(blade.automateActionHigh?.name ?? "Idle") +
".",
);
} else if (flag.toLowerCase().includes("en")) {
if (!this.automateActionLow || !this.automateActionHigh) {
return this.log("Failed to enable automation. Actions were not set");
if (!blade.automateActionLow || !blade.automateActionHigh) {
return blade.log("Failed to enable automation. Actions were not set");
}
this.automateEnabled = true;
this.log("Bladeburner automation enabled");
blade.automateEnabled = true;
blade.log("Bladeburner automation enabled");
} else if (flag.toLowerCase().includes("d")) {
this.automateEnabled = false;
this.log("Bladeburner automation disabled");
blade.automateEnabled = false;
blade.log("Bladeburner automation disabled");
} else {
this.log("Invalid argument for 'automate' console command: " + args[1]);
blade.log("Invalid argument for 'automate' console command: " + args[1]);
}
return;
}
Expand All @@ -439,14 +439,14 @@ export class Bladeburner implements OperationTeam {
if (type === "stamina") {
// For stamina, the "name" variable is actually the stamina threshold
if (isNaN(parseFloat(name))) {
this.postToConsole("Invalid value specified for stamina threshold (must be numeric): " + name);
blade.postToConsole("Invalid value specified for stamina threshold (must be numeric): " + name);
} else {
if (highLow) {
this.automateThreshHigh = Number(name);
blade.automateThreshHigh = Number(name);
} else {
this.automateThreshLow = Number(name);
blade.automateThreshLow = Number(name);
}
this.log("Automate (" + (highLow ? "HIGH" : "LOW") + ") stamina threshold set to " + name);
blade.log("Automate (" + (highLow ? "HIGH" : "LOW") + ") stamina threshold set to " + name);
}
return;
}
Expand All @@ -457,36 +457,36 @@ export class Bladeburner implements OperationTeam {
switch (type) {
case "general":
case "gen": {
this.postToConsole("Invalid General Action name specified: " + name);
blade.postToConsole("Invalid General Action name specified: " + name);
return;
}
case "contract":
case "contracts": {
this.postToConsole("Invalid Contract name specified: " + name);
blade.postToConsole("Invalid Contract name specified: " + name);
return;
}
case "ops":
case "op":
case "operations":
case "operation":
this.postToConsole("Invalid Operation name specified: " + name);
blade.postToConsole("Invalid Operation name specified: " + name);
return;
default:
this.postToConsole("Invalid use of automate command.");
blade.postToConsole("Invalid use of automate command.");
return;
}
}

if (highLow) {
this.automateActionHigh = actionId;
blade.automateActionHigh = actionId;
} else {
this.automateActionLow = actionId;
blade.automateActionLow = actionId;
}
this.log("Automate (" + (highLow ? "HIGH" : "LOW") + ") action set to " + name);
blade.log("Automate (" + (highLow ? "HIGH" : "LOW") + ") action set to " + name);
}
}

executeConsoleCommand(command: string): void {
private static executeConsoleCommand(blade: Bladeburner, command: string): void {
command = command.trim();
command = command.replace(/\s\s+/g, " "); // Replace all whitespace w/ a single space

Expand All @@ -495,29 +495,29 @@ export class Bladeburner implements OperationTeam {

switch (args[0].toLowerCase()) {
case "automate":
this.executeAutomateConsoleCommand(args);
Bladeburner.executeAutomateConsoleCommand(blade, args);
break;
case "clear":
case "cls":
this.clearConsole();
blade.clearConsole();
break;
case "help":
this.executeHelpConsoleCommand(args);
Bladeburner.executeHelpConsoleCommand(blade, args);
break;
case "log":
this.executeLogConsoleCommand(args);
Bladeburner.executeLogConsoleCommand(blade, args);
break;
case "skill":
this.executeSkillConsoleCommand(args);
Bladeburner.executeSkillConsoleCommand(blade, args);
break;
case "start":
this.executeStartConsoleCommand(args);
Bladeburner.executeStartConsoleCommand(blade, args);
break;
case "stop":
this.resetAction();
blade.resetAction();
break;
default:
this.postToConsole("Invalid console command");
blade.postToConsole("Invalid console command");
break;
}
}
Expand Down