Merge pull request #3912 from danielyxie/dev

Add blade bulk purchase
This commit is contained in:
hydroflame 2022-07-15 23:46:17 -04:00 committed by GitHub
commit 91d9ebbedc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 84 additions and 50 deletions

4
dist/main.bundle.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -17,7 +17,7 @@ import { IAction } from "./IAction";
import { IPlayer } from "../PersonObjects/IPlayer"; import { IPlayer } from "../PersonObjects/IPlayer";
import { createTaskTracker, ITaskTracker } from "../PersonObjects/ITaskTracker"; import { createTaskTracker, ITaskTracker } from "../PersonObjects/ITaskTracker";
import { IPerson } from "../PersonObjects/IPerson"; import { IPerson } from "../PersonObjects/IPerson";
import { IRouter, Page } from "../ui/Router"; import { IRouter } from "../ui/Router";
import { ConsoleHelpText } from "./data/Help"; import { ConsoleHelpText } from "./data/Help";
import { exceptionAlert } from "../utils/helpers/exceptionAlert"; import { exceptionAlert } from "../utils/helpers/exceptionAlert";
import { getRandomInt } from "../utils/helpers/getRandomInt"; import { getRandomInt } from "../utils/helpers/getRandomInt";
@ -35,7 +35,6 @@ import { getTimestamp } from "../utils/helpers/getTimestamp";
import { joinFaction } from "../Faction/FactionHelpers"; import { joinFaction } from "../Faction/FactionHelpers";
import { WorkerScript } from "../Netscript/WorkerScript"; import { WorkerScript } from "../Netscript/WorkerScript";
import { FactionNames } from "../Faction/data/FactionNames"; import { FactionNames } from "../Faction/data/FactionNames";
import { BlackOperationNames } from "./data/BlackOperationNames";
import { KEY } from "../utils/helpers/keyCodes"; import { KEY } from "../utils/helpers/keyCodes";
interface BlackOpsAttempt { interface BlackOpsAttempt {
@ -237,13 +236,13 @@ export class Bladeburner implements IBladeburner {
} }
} }
upgradeSkill(skill: Skill): void { upgradeSkill(skill: Skill, count = 1): void {
// This does NOT handle deduction of skill points // This does NOT handle deduction of skill points
const skillName = skill.name; const skillName = skill.name;
if (this.skills[skillName]) { if (this.skills[skillName]) {
++this.skills[skillName]; this.skills[skillName] += count;
} else { } else {
this.skills[skillName] = 1; this.skills[skillName] = count;
} }
if (isNaN(this.skills[skillName]) || this.skills[skillName] < 0) { if (isNaN(this.skills[skillName]) || this.skills[skillName] < 0) {
throw new Error("Level of Skill " + skillName + " is invalid: " + this.skills[skillName]); throw new Error("Level of Skill " + skillName + " is invalid: " + this.skills[skillName]);
@ -2277,7 +2276,7 @@ export class Bladeburner implements IBladeburner {
} }
} }
getSkillUpgradeCostNetscriptFn(skillName: string, workerScript: WorkerScript): number { getSkillUpgradeCostNetscriptFn(skillName: string, count: number, workerScript: WorkerScript): number {
if (skillName === "" || !Skills.hasOwnProperty(skillName)) { if (skillName === "" || !Skills.hasOwnProperty(skillName)) {
workerScript.log("bladeburner.getSkillUpgradeCost", () => `Invalid skill: '${skillName}'`); workerScript.log("bladeburner.getSkillUpgradeCost", () => `Invalid skill: '${skillName}'`);
return -1; return -1;
@ -2285,13 +2284,13 @@ export class Bladeburner implements IBladeburner {
const skill = Skills[skillName]; const skill = Skills[skillName];
if (this.skills[skillName] == null) { if (this.skills[skillName] == null) {
return skill.calculateCost(0); return skill.calculateCost(0, count);
} else { } else {
return skill.calculateCost(this.skills[skillName]); return skill.calculateCost(this.skills[skillName], count);
} }
} }
upgradeSkillNetscriptFn(skillName: string, workerScript: WorkerScript): boolean { upgradeSkillNetscriptFn(skillName: string, count: number, workerScript: WorkerScript): boolean {
const errorLogText = `Invalid skill: '${skillName}'`; const errorLogText = `Invalid skill: '${skillName}'`;
if (!Skills.hasOwnProperty(skillName)) { if (!Skills.hasOwnProperty(skillName)) {
workerScript.log("bladeburner.upgradeSkill", () => errorLogText); workerScript.log("bladeburner.upgradeSkill", () => errorLogText);
@ -2303,10 +2302,10 @@ export class Bladeburner implements IBladeburner {
if (this.skills[skillName] && !isNaN(this.skills[skillName])) { if (this.skills[skillName] && !isNaN(this.skills[skillName])) {
currentLevel = this.skills[skillName]; currentLevel = this.skills[skillName];
} }
const cost = skill.calculateCost(currentLevel); const cost = skill.calculateCost(currentLevel, count);
if (skill.maxLvl && currentLevel >= skill.maxLvl) { if (skill.maxLvl && currentLevel + count > skill.maxLvl) {
workerScript.log("bladeburner.upgradeSkill", () => `Skill '${skillName}' is already maxed.`); workerScript.log("bladeburner.upgradeSkill", () => `Skill '${skillName}' cannot be upgraded ${count} time(s).`);
return false; return false;
} }
@ -2314,13 +2313,13 @@ export class Bladeburner implements IBladeburner {
workerScript.log( workerScript.log(
"bladeburner.upgradeSkill", "bladeburner.upgradeSkill",
() => () =>
`You do not have enough skill points to upgrade ${skillName} (You have ${this.skillPoints}, you need ${cost})`, `You do not have enough skill points to upgrade ${skillName} ${count} time(s). (You have ${this.skillPoints}, you need ${cost})`,
); );
return false; return false;
} }
this.skillPoints -= cost; this.skillPoints -= cost;
this.upgradeSkill(skill); this.upgradeSkill(skill, count);
workerScript.log("bladeburner.upgradeSkill", () => `'${skillName}' upgraded to level ${this.skills[skillName]}`); workerScript.log("bladeburner.upgradeSkill", () => `'${skillName}' upgraded to level ${this.skills[skillName]}`);
return true; return true;
} }

@ -76,8 +76,8 @@ export interface IBladeburner {
getActionEstimatedSuccessChanceNetscriptFn(person: IPerson, type: string, name: string): [number, number] | string; getActionEstimatedSuccessChanceNetscriptFn(person: IPerson, type: string, name: string): [number, number] | string;
getActionCountRemainingNetscriptFn(type: string, name: string, workerScript: WorkerScript): number; getActionCountRemainingNetscriptFn(type: string, name: string, workerScript: WorkerScript): number;
getSkillLevelNetscriptFn(skillName: string, workerScript: WorkerScript): number; getSkillLevelNetscriptFn(skillName: string, workerScript: WorkerScript): number;
getSkillUpgradeCostNetscriptFn(skillName: string, workerScript: WorkerScript): number; getSkillUpgradeCostNetscriptFn(skillName: string, count: number, workerScript: WorkerScript): number;
upgradeSkillNetscriptFn(skillName: string, workerScript: WorkerScript): boolean; upgradeSkillNetscriptFn(skillName: string, count: number, workerScript: WorkerScript): boolean;
getTeamSizeNetscriptFn(type: string, name: string, workerScript: WorkerScript): number; getTeamSizeNetscriptFn(type: string, name: string, workerScript: WorkerScript): number;
setTeamSizeNetscriptFn(type: string, name: string, size: number, workerScript: WorkerScript): number; setTeamSizeNetscriptFn(type: string, name: string, size: number, workerScript: WorkerScript): number;
joinBladeburnerFactionNetscriptFn(workerScript: WorkerScript): boolean; joinBladeburnerFactionNetscriptFn(workerScript: WorkerScript): boolean;

@ -133,8 +133,37 @@ export class Skill {
} }
} }
calculateCost(currentLevel: number): number { calculateCost(currentLevel: number, count = 1): number {
//Recursive mode does not handle invalid inputs properly, but it should never
//be possible for it to run with them. For the sake of not crashing the game,
const recursiveMode = (currentLevel: number, count: number): number => {
if (count <= 1) {
return Math.floor((this.baseCost + currentLevel * this.costInc) * BitNodeMultipliers.BladeburnerSkillCost); return Math.floor((this.baseCost + currentLevel * this.costInc) * BitNodeMultipliers.BladeburnerSkillCost);
} else {
const thisUpgrade = Math.floor(
(this.baseCost + currentLevel * this.costInc) * BitNodeMultipliers.BladeburnerSkillCost,
);
return this.calculateCost(currentLevel + 1, count - 1) + thisUpgrade;
}
};
//Count must be a positive integer.
if (count < 0 || count % 1 != 0) {
throw new Error(`${count} is an invalid number of upgrades`);
}
//Use recursive mode if count is small
if (count <= 100) {
return recursiveMode(currentLevel, count);
}
//Use optimized mode if count is large
else {
//unFloored is roughly equivalent to
//(this.baseCost + currentLevel * this.costInc) * BitNodeMultipliers.BladeburnerSkillCost
//being repeated for increasing currentLevel
const preMult = (count * (2 * this.baseCost + this.costInc * (2 * currentLevel + count + 1))) / 2;
const unFloored = preMult * BitNodeMultipliers.BladeburnerSkillCost - count / 2;
return Math.floor(unFloored);
}
} }
getMultiplier(name: string): number { getMultiplier(name: string): number {

@ -74,7 +74,7 @@ export function GeneralActionElem(props: IProps): React.ReactElement {
<CopyableText value={props.action.name} /> <CopyableText value={props.action.name} />
<StartButton <StartButton
bladeburner={props.bladeburner} bladeburner={props.bladeburner}
type={ActionTypes[props.action.name ]} type={ActionTypes[props.action.name]}
name={props.action.name} name={props.action.name}
rerender={rerender} rerender={rerender}
/> />

@ -22,7 +22,7 @@ export function Augmentations(props: IProps): React.ReactElement {
const [augmentation, setAugmentation] = useState("Augmented Targeting I"); const [augmentation, setAugmentation] = useState("Augmented Targeting I");
function setAugmentationDropdown(event: SelectChangeEvent<string>): void { function setAugmentationDropdown(event: SelectChangeEvent<string>): void {
setAugmentation(event.target.value ); setAugmentation(event.target.value);
} }
function queueAug(): void { function queueAug(): void {
props.player.queueAugmentation(augmentation); props.player.queueAugmentation(augmentation);

@ -15,7 +15,7 @@ import { CodingContractTypes } from "../../CodingContracts";
export function CodingContracts(): React.ReactElement { export function CodingContracts(): React.ReactElement {
const [codingcontract, setCodingcontract] = useState("Find Largest Prime Factor"); const [codingcontract, setCodingcontract] = useState("Find Largest Prime Factor");
function setCodingcontractDropdown(event: SelectChangeEvent<string>): void { function setCodingcontractDropdown(event: SelectChangeEvent<string>): void {
setCodingcontract(event.target.value ); setCodingcontract(event.target.value);
} }
function specificContract(): void { function specificContract(): void {

@ -18,7 +18,7 @@ const bigNumber = 1e12;
export function Companies(): React.ReactElement { export function Companies(): React.ReactElement {
const [company, setCompany] = useState(FactionNames.ECorp as string); const [company, setCompany] = useState(FactionNames.ECorp as string);
function setCompanyDropdown(event: SelectChangeEvent<string>): void { function setCompanyDropdown(event: SelectChangeEvent<string>): void {
setCompany(event.target.value ); setCompany(event.target.value);
} }
function resetCompanyRep(): void { function resetCompanyRep(): void {
AllCompanies[company].playerReputation = 0; AllCompanies[company].playerReputation = 0;

@ -29,7 +29,7 @@ export function Factions(props: IProps): React.ReactElement {
const [faction, setFaction] = useState(FactionNames.Illuminati as string); const [faction, setFaction] = useState(FactionNames.Illuminati as string);
function setFactionDropdown(event: SelectChangeEvent<string>): void { function setFactionDropdown(event: SelectChangeEvent<string>): void {
setFaction(event.target.value ); setFaction(event.target.value);
} }
function receiveInvite(): void { function receiveInvite(): void {

@ -19,7 +19,7 @@ interface IProps {
export function Programs(props: IProps): React.ReactElement { export function Programs(props: IProps): React.ReactElement {
const [program, setProgram] = useState("NUKE.exe"); const [program, setProgram] = useState("NUKE.exe");
function setProgramDropdown(event: SelectChangeEvent<string>): void { function setProgramDropdown(event: SelectChangeEvent<string>): void {
setProgram(event.target.value ); setProgram(event.target.value);
} }
function addProgram(): void { function addProgram(): void {
if (!props.player.hasProgram(program)) { if (!props.player.hasProgram(program)) {

@ -15,7 +15,7 @@ import MenuItem from "@mui/material/MenuItem";
export function Servers(): React.ReactElement { export function Servers(): React.ReactElement {
const [server, setServer] = useState("home"); const [server, setServer] = useState("home");
function setServerDropdown(event: SelectChangeEvent<string>): void { function setServerDropdown(event: SelectChangeEvent<string>): void {
setServer(event.target.value ); setServer(event.target.value);
} }
function rootServer(): void { function rootServer(): void {
const s = GetServer(server); const s = GetServer(server);

@ -8,8 +8,8 @@ export function Unclickable(): React.ReactElement {
function unclickable(event: React.MouseEvent<HTMLDivElement>): void { function unclickable(event: React.MouseEvent<HTMLDivElement>): void {
if (!event.target || !(event.target instanceof Element)) return; if (!event.target || !(event.target instanceof Element)) return;
const display = getComputedStyle(event.target ).display; const display = getComputedStyle(event.target).display;
const visibility = getComputedStyle(event.target ).visibility; const visibility = getComputedStyle(event.target).visibility;
if (display === "none" && visibility === "hidden" && event.isTrusted) player.giveExploit(Exploit.Unclickable); if (display === "none" && visibility === "hidden" && event.isTrusted) player.giveExploit(Exploit.Unclickable);
} }

@ -54,7 +54,7 @@ export function HacknetNodeElem(props: IProps): React.ReactElement {
multiplier = getMaxNumberLevelUpgrades(props.player, node, HacknetNodeConstants.MaxLevel); multiplier = getMaxNumberLevelUpgrades(props.player, node, HacknetNodeConstants.MaxLevel);
} else { } else {
const levelsToMax = HacknetNodeConstants.MaxLevel - node.level; const levelsToMax = HacknetNodeConstants.MaxLevel - node.level;
multiplier = Math.min(levelsToMax, purchaseMult ); multiplier = Math.min(levelsToMax, purchaseMult);
} }
const increase = const increase =
@ -94,7 +94,7 @@ export function HacknetNodeElem(props: IProps): React.ReactElement {
multiplier = getMaxNumberRamUpgrades(props.player, node, HacknetNodeConstants.MaxRam); multiplier = getMaxNumberRamUpgrades(props.player, node, HacknetNodeConstants.MaxRam);
} else { } else {
const levelsToMax = Math.round(Math.log2(HacknetNodeConstants.MaxRam / node.ram)); const levelsToMax = Math.round(Math.log2(HacknetNodeConstants.MaxRam / node.ram));
multiplier = Math.min(levelsToMax, purchaseMult ); multiplier = Math.min(levelsToMax, purchaseMult);
} }
const increase = const increase =
@ -144,7 +144,7 @@ export function HacknetNodeElem(props: IProps): React.ReactElement {
multiplier = getMaxNumberCoreUpgrades(props.player, node, HacknetNodeConstants.MaxCores); multiplier = getMaxNumberCoreUpgrades(props.player, node, HacknetNodeConstants.MaxCores);
} else { } else {
const levelsToMax = HacknetNodeConstants.MaxCores - node.cores; const levelsToMax = HacknetNodeConstants.MaxCores - node.cores;
multiplier = Math.min(levelsToMax, purchaseMult ); multiplier = Math.min(levelsToMax, purchaseMult);
} }
const increase = const increase =

@ -279,26 +279,28 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
}, },
getSkillUpgradeCost: getSkillUpgradeCost:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_skillName: unknown): number => { (_skillName: unknown, _count: unknown = 1): number => {
const skillName = ctx.helper.string("skillName", _skillName); const skillName = ctx.helper.string("skillName", _skillName);
const count = ctx.helper.number("count", _count);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner; const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
try { try {
return bladeburner.getSkillUpgradeCostNetscriptFn(skillName, workerScript); return bladeburner.getSkillUpgradeCostNetscriptFn(skillName, count, workerScript);
} catch (e: any) { } catch (e: any) {
throw ctx.makeRuntimeErrorMsg(e); throw ctx.makeRuntimeErrorMsg(e);
} }
}, },
upgradeSkill: upgradeSkill:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>
(_skillName: unknown): boolean => { (_skillName: unknown, _count: unknown = 1): boolean => {
const skillName = ctx.helper.string("skillName", _skillName); const skillName = ctx.helper.string("skillName", _skillName);
const count = ctx.helper.number("count", _count);
checkBladeburnerAccess(ctx); checkBladeburnerAccess(ctx);
const bladeburner = player.bladeburner; const bladeburner = player.bladeburner;
if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
try { try {
return bladeburner.upgradeSkillNetscriptFn(skillName, workerScript); return bladeburner.upgradeSkillNetscriptFn(skillName, count, workerScript);
} catch (e: any) { } catch (e: any) {
throw ctx.makeRuntimeErrorMsg(e); throw ctx.makeRuntimeErrorMsg(e);
} }

@ -257,7 +257,7 @@ export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript
function getMaterial(divisionName: string, cityName: string, materialName: string): Material { function getMaterial(divisionName: string, cityName: string, materialName: string): Material {
const warehouse = getWarehouse(divisionName, cityName); const warehouse = getWarehouse(divisionName, cityName);
const matName = (materialName ).replace(/ /g, ""); const matName = materialName.replace(/ /g, "");
const material = warehouse.materials[matName]; const material = warehouse.materials[matName];
if (material === undefined) throw new Error(`Invalid material name: '${materialName}'`); if (material === undefined) throw new Error(`Invalid material name: '${materialName}'`);
return material; return material;
@ -725,9 +725,11 @@ export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript
const employeeName = ctx.helper.string("employeeName", _employeeName); const employeeName = ctx.helper.string("employeeName", _employeeName);
const job = ctx.helper.string("job", _job); const job = ctx.helper.string("job", _job);
const employee = getEmployee(divisionName, cityName, employeeName); const employee = getEmployee(divisionName, cityName, employeeName);
return netscriptDelay(["Training", "Unassigned"].includes(employee.pos) ? 0 : 1000, workerScript).then(function () { return netscriptDelay(["Training", "Unassigned"].includes(employee.pos) ? 0 : 1000, workerScript).then(
function () {
return Promise.resolve(AssignJob(employee, job)); return Promise.resolve(AssignJob(employee, job));
}); },
);
}, },
hireEmployee: hireEmployee:
(ctx: NetscriptContext) => (ctx: NetscriptContext) =>

@ -3080,28 +3080,30 @@ export interface Bladeburner {
* @remarks * @remarks
* RAM cost: 4 GB * RAM cost: 4 GB
* *
* This function returns the number of skill points needed to upgrade the specified skill. * This function returns the number of skill points needed to upgrade the specified skill the specified number of times.
* *
* The function returns -1 if an invalid skill name is passed in. * The function returns -1 if an invalid skill name is passed in.
* *
* @param skillName - Name of skill. Case-sensitive and must be an exact match * @param skillName - Name of skill. Case-sensitive and must be an exact match
* @param count - Number of times to upgrade the skill. Defaults to 1 if not specified.
* @returns Number of skill points needed to upgrade the specified skill. * @returns Number of skill points needed to upgrade the specified skill.
*/ */
getSkillUpgradeCost(name: string): number; getSkillUpgradeCost(name: string, count?: number): number;
/** /**
* Upgrade skill. * Upgrade skill.
* @remarks * @remarks
* RAM cost: 4 GB * RAM cost: 4 GB
* *
* Attempts to upgrade the specified Bladeburner skill. * Attempts to upgrade the specified Bladeburner skill the specified number of times.
* *
* Returns true if the skill is successfully upgraded, and false otherwise. * Returns true if the skill is successfully upgraded, and false otherwise.
* *
* @param skillName - Name of skill to be upgraded. Case-sensitive and must be an exact match * @param skillName - Name of skill to be upgraded. Case-sensitive and must be an exact match
* @param count - Number of times to upgrade the skill. Defaults to 1 if not specified.
* @returns true if the skill is successfully upgraded, and false otherwise. * @returns true if the skill is successfully upgraded, and false otherwise.
*/ */
upgradeSkill(name: string): boolean; upgradeSkill(name: string, count?: number): boolean;
/** /**
* Get team size. * Get team size.

@ -693,7 +693,7 @@ export function Root(props: IProps): React.ReactElement {
if (server === null) throw new Error(`Server '${closingScript.hostname}' should not be null, but it is.`); if (server === null) throw new Error(`Server '${closingScript.hostname}' should not be null, but it is.`);
const serverScriptIndex = server.scripts.findIndex((script) => script.filename === closingScript.fileName); const serverScriptIndex = server.scripts.findIndex((script) => script.filename === closingScript.fileName);
if (serverScriptIndex === -1 || savedScriptCode !== server.scripts[serverScriptIndex ].code) { if (serverScriptIndex === -1 || savedScriptCode !== server.scripts[serverScriptIndex].code) {
PromptEvent.emit({ PromptEvent.emit({
txt: `Do you want to save changes to ${closingScript.fileName} on ${closingScript.hostname}?`, txt: `Do you want to save changes to ${closingScript.fileName} on ${closingScript.hostname}?`,
resolve: (result: boolean | string) => { resolve: (result: boolean | string) => {

@ -36,7 +36,7 @@ function toNumber(n: number | IMinMaxRange): number {
return n; return n;
} }
case "object": { case "object": {
const range = n ; const range = n;
value = getRandomInt(range.min, range.max); value = getRandomInt(range.min, range.max);
break; break;
} }

@ -68,7 +68,7 @@ export function placeOrder(
// Process to see if it should be executed immediately // Process to see if it should be executed immediately
const processOrderRefs = { const processOrderRefs = {
stockMarket: StockMarket , stockMarket: StockMarket,
symbolToStockMap: SymbolToStockMap, symbolToStockMap: SymbolToStockMap,
}; };
processOrders(stock, order.type, order.pos, processOrderRefs); processOrders(stock, order.type, order.pos, processOrderRefs);

@ -84,7 +84,7 @@ export function mv(
script.filename = destPath; script.filename = destPath;
} else if (srcFile instanceof TextFile) { } else if (srcFile instanceof TextFile) {
const textFile = srcFile ; const textFile = srcFile;
if (!dest.endsWith(".txt")) { if (!dest.endsWith(".txt")) {
terminal.error(`Source and destination files must have the same type`); terminal.error(`Source and destination files must have the same type`);
return; return;

@ -121,7 +121,7 @@ export function getTextFile(fn: string, server: BaseServer): TextFile | null {
filename = removeLeadingSlash(filename); filename = removeLeadingSlash(filename);
} }
for (const file of server.textFiles ) { for (const file of server.textFiles) {
if (file.fn === filename) { if (file.fn === filename) {
return file; return file;
} }