mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-23 01:32:55 +02:00
fix sleeve memory bug
This commit is contained in:
+37
-189
@@ -17,11 +17,7 @@ import { HashManager } from "./HashManager";
|
||||
import { HashUpgrades } from "./HashUpgrades";
|
||||
|
||||
import { generateRandomContract } from "../CodingContractGenerator";
|
||||
import {
|
||||
iTutorialSteps,
|
||||
iTutorialNextStep,
|
||||
ITutorial,
|
||||
} from "../InteractiveTutorial";
|
||||
import { iTutorialSteps, iTutorialNextStep, ITutorial } from "../InteractiveTutorial";
|
||||
import { Player } from "../Player";
|
||||
import { AllServers } from "../Server/AllServers";
|
||||
import { GetServerByHostname } from "../Server/ServerHelpers";
|
||||
@@ -94,24 +90,15 @@ export function purchaseHacknet() {
|
||||
}
|
||||
|
||||
export function hasMaxNumberHacknetServers() {
|
||||
return (
|
||||
hasHacknetServers() &&
|
||||
Player.hacknetNodes.length >= HacknetServerConstants.MaxServers
|
||||
);
|
||||
return hasHacknetServers() && Player.hacknetNodes.length >= HacknetServerConstants.MaxServers;
|
||||
}
|
||||
|
||||
export function getCostOfNextHacknetNode() {
|
||||
return calculateNodeCost(
|
||||
Player.hacknetNodes.length + 1,
|
||||
Player.hacknet_node_purchase_cost_mult,
|
||||
);
|
||||
return calculateNodeCost(Player.hacknetNodes.length + 1, Player.hacknet_node_purchase_cost_mult);
|
||||
}
|
||||
|
||||
export function getCostOfNextHacknetServer() {
|
||||
return calculateServerCost(
|
||||
Player.hacknetNodes.length + 1,
|
||||
Player.hacknet_node_purchase_cost_mult,
|
||||
);
|
||||
return calculateServerCost(Player.hacknetNodes.length + 1, Player.hacknet_node_purchase_cost_mult);
|
||||
}
|
||||
|
||||
// Calculate the maximum number of times the Player can afford to upgrade a Hacknet Node's level
|
||||
@@ -120,25 +107,14 @@ export function getMaxNumberLevelUpgrades(nodeObj, maxLevel) {
|
||||
throw new Error(`getMaxNumberLevelUpgrades() called without maxLevel arg`);
|
||||
}
|
||||
|
||||
if (
|
||||
Player.money.lt(
|
||||
nodeObj.calculateLevelUpgradeCost(1, Player.hacknet_node_level_cost_mult),
|
||||
)
|
||||
) {
|
||||
if (Player.money.lt(nodeObj.calculateLevelUpgradeCost(1, Player.hacknet_node_level_cost_mult))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let min = 1;
|
||||
let max = maxLevel - 1;
|
||||
let levelsToMax = maxLevel - nodeObj.level;
|
||||
if (
|
||||
Player.money.gt(
|
||||
nodeObj.calculateLevelUpgradeCost(
|
||||
levelsToMax,
|
||||
Player.hacknet_node_level_cost_mult,
|
||||
),
|
||||
)
|
||||
) {
|
||||
if (Player.money.gt(nodeObj.calculateLevelUpgradeCost(levelsToMax, Player.hacknet_node_level_cost_mult))) {
|
||||
return levelsToMax;
|
||||
}
|
||||
|
||||
@@ -146,37 +122,13 @@ export function getMaxNumberLevelUpgrades(nodeObj, maxLevel) {
|
||||
var curr = ((min + max) / 2) | 0;
|
||||
if (
|
||||
curr !== maxLevel &&
|
||||
Player.money.gt(
|
||||
nodeObj.calculateLevelUpgradeCost(
|
||||
curr,
|
||||
Player.hacknet_node_level_cost_mult,
|
||||
),
|
||||
) &&
|
||||
Player.money.lt(
|
||||
nodeObj.calculateLevelUpgradeCost(
|
||||
curr + 1,
|
||||
Player.hacknet_node_level_cost_mult,
|
||||
),
|
||||
)
|
||||
Player.money.gt(nodeObj.calculateLevelUpgradeCost(curr, Player.hacknet_node_level_cost_mult)) &&
|
||||
Player.money.lt(nodeObj.calculateLevelUpgradeCost(curr + 1, Player.hacknet_node_level_cost_mult))
|
||||
) {
|
||||
return Math.min(levelsToMax, curr);
|
||||
} else if (
|
||||
Player.money.lt(
|
||||
nodeObj.calculateLevelUpgradeCost(
|
||||
curr,
|
||||
Player.hacknet_node_level_cost_mult,
|
||||
),
|
||||
)
|
||||
) {
|
||||
} else if (Player.money.lt(nodeObj.calculateLevelUpgradeCost(curr, Player.hacknet_node_level_cost_mult))) {
|
||||
max = curr - 1;
|
||||
} else if (
|
||||
Player.money.gt(
|
||||
nodeObj.calculateLevelUpgradeCost(
|
||||
curr,
|
||||
Player.hacknet_node_level_cost_mult,
|
||||
),
|
||||
)
|
||||
) {
|
||||
} else if (Player.money.gt(nodeObj.calculateLevelUpgradeCost(curr, Player.hacknet_node_level_cost_mult))) {
|
||||
min = curr + 1;
|
||||
} else {
|
||||
return Math.min(levelsToMax, curr);
|
||||
@@ -191,11 +143,7 @@ export function getMaxNumberRamUpgrades(nodeObj, maxLevel) {
|
||||
throw new Error(`getMaxNumberRamUpgrades() called without maxLevel arg`);
|
||||
}
|
||||
|
||||
if (
|
||||
Player.money.lt(
|
||||
nodeObj.calculateRamUpgradeCost(1, Player.hacknet_node_ram_cost_mult),
|
||||
)
|
||||
) {
|
||||
if (Player.money.lt(nodeObj.calculateRamUpgradeCost(1, Player.hacknet_node_ram_cost_mult))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -205,24 +153,13 @@ export function getMaxNumberRamUpgrades(nodeObj, maxLevel) {
|
||||
} else {
|
||||
levelsToMax = Math.round(Math.log2(maxLevel / nodeObj.ram));
|
||||
}
|
||||
if (
|
||||
Player.money.gt(
|
||||
nodeObj.calculateRamUpgradeCost(
|
||||
levelsToMax,
|
||||
Player.hacknet_node_ram_cost_mult,
|
||||
),
|
||||
)
|
||||
) {
|
||||
if (Player.money.gt(nodeObj.calculateRamUpgradeCost(levelsToMax, Player.hacknet_node_ram_cost_mult))) {
|
||||
return levelsToMax;
|
||||
}
|
||||
|
||||
//We'll just loop until we find the max
|
||||
for (let i = levelsToMax - 1; i >= 0; --i) {
|
||||
if (
|
||||
Player.money.gt(
|
||||
nodeObj.calculateRamUpgradeCost(i, Player.hacknet_node_ram_cost_mult),
|
||||
)
|
||||
) {
|
||||
if (Player.money.gt(nodeObj.calculateRamUpgradeCost(i, Player.hacknet_node_ram_cost_mult))) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -235,25 +172,14 @@ export function getMaxNumberCoreUpgrades(nodeObj, maxLevel) {
|
||||
throw new Error(`getMaxNumberCoreUpgrades() called without maxLevel arg`);
|
||||
}
|
||||
|
||||
if (
|
||||
Player.money.lt(
|
||||
nodeObj.calculateCoreUpgradeCost(1, Player.hacknet_node_core_cost_mult),
|
||||
)
|
||||
) {
|
||||
if (Player.money.lt(nodeObj.calculateCoreUpgradeCost(1, Player.hacknet_node_core_cost_mult))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let min = 1;
|
||||
let max = maxLevel - 1;
|
||||
const levelsToMax = maxLevel - nodeObj.cores;
|
||||
if (
|
||||
Player.money.gt(
|
||||
nodeObj.calculateCoreUpgradeCost(
|
||||
levelsToMax,
|
||||
Player.hacknet_node_core_cost_mult,
|
||||
),
|
||||
)
|
||||
) {
|
||||
if (Player.money.gt(nodeObj.calculateCoreUpgradeCost(levelsToMax, Player.hacknet_node_core_cost_mult))) {
|
||||
return levelsToMax;
|
||||
}
|
||||
|
||||
@@ -262,37 +188,13 @@ export function getMaxNumberCoreUpgrades(nodeObj, maxLevel) {
|
||||
let curr = ((min + max) / 2) | 0;
|
||||
if (
|
||||
curr != maxLevel &&
|
||||
Player.money.gt(
|
||||
nodeObj.calculateCoreUpgradeCost(
|
||||
curr,
|
||||
Player.hacknet_node_core_cost_mult,
|
||||
),
|
||||
) &&
|
||||
Player.money.lt(
|
||||
nodeObj.calculateCoreUpgradeCost(
|
||||
curr + 1,
|
||||
Player.hacknet_node_core_cost_mult,
|
||||
),
|
||||
)
|
||||
Player.money.gt(nodeObj.calculateCoreUpgradeCost(curr, Player.hacknet_node_core_cost_mult)) &&
|
||||
Player.money.lt(nodeObj.calculateCoreUpgradeCost(curr + 1, Player.hacknet_node_core_cost_mult))
|
||||
) {
|
||||
return Math.min(levelsToMax, curr);
|
||||
} else if (
|
||||
Player.money.lt(
|
||||
nodeObj.calculateCoreUpgradeCost(
|
||||
curr,
|
||||
Player.hacknet_node_core_cost_mult,
|
||||
),
|
||||
)
|
||||
) {
|
||||
} else if (Player.money.lt(nodeObj.calculateCoreUpgradeCost(curr, Player.hacknet_node_core_cost_mult))) {
|
||||
max = curr - 1;
|
||||
} else if (
|
||||
Player.money.gt(
|
||||
nodeObj.calculateCoreUpgradeCost(
|
||||
curr,
|
||||
Player.hacknet_node_core_cost_mult,
|
||||
),
|
||||
)
|
||||
) {
|
||||
} else if (Player.money.gt(nodeObj.calculateCoreUpgradeCost(curr, Player.hacknet_node_core_cost_mult))) {
|
||||
min = curr + 1;
|
||||
} else {
|
||||
return Math.min(levelsToMax, curr);
|
||||
@@ -342,10 +244,7 @@ export function getMaxNumberCacheUpgrades(nodeObj, maxLevel) {
|
||||
|
||||
export function purchaseLevelUpgrade(node, levels = 1) {
|
||||
const sanitizedLevels = Math.round(levels);
|
||||
const cost = node.calculateLevelUpgradeCost(
|
||||
sanitizedLevels,
|
||||
Player.hacknet_node_level_cost_mult,
|
||||
);
|
||||
const cost = node.calculateLevelUpgradeCost(sanitizedLevels, Player.hacknet_node_level_cost_mult);
|
||||
if (isNaN(cost) || cost <= 0 || sanitizedLevels < 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -353,25 +252,14 @@ export function purchaseLevelUpgrade(node, levels = 1) {
|
||||
const isServer = node instanceof HacknetServer;
|
||||
|
||||
// If we're at max level, return false
|
||||
if (
|
||||
node.level >=
|
||||
(isServer ? HacknetServerConstants.MaxLevel : HacknetNodeConstants.MaxLevel)
|
||||
) {
|
||||
if (node.level >= (isServer ? HacknetServerConstants.MaxLevel : HacknetNodeConstants.MaxLevel)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the number of specified upgrades would exceed the max level, calculate
|
||||
// the maximum number of upgrades and use that
|
||||
if (
|
||||
node.level + sanitizedLevels >
|
||||
(isServer ? HacknetServerConstants.MaxLevel : HacknetNodeConstants.MaxLevel)
|
||||
) {
|
||||
const diff = Math.max(
|
||||
0,
|
||||
(isServer
|
||||
? HacknetServerConstants.MaxLevel
|
||||
: HacknetNodeConstants.MaxLevel) - node.level,
|
||||
);
|
||||
if (node.level + sanitizedLevels > (isServer ? HacknetServerConstants.MaxLevel : HacknetNodeConstants.MaxLevel)) {
|
||||
const diff = Math.max(0, (isServer ? HacknetServerConstants.MaxLevel : HacknetNodeConstants.MaxLevel) - node.level);
|
||||
return purchaseLevelUpgrade(node, diff);
|
||||
}
|
||||
|
||||
@@ -387,10 +275,7 @@ export function purchaseLevelUpgrade(node, levels = 1) {
|
||||
|
||||
export function purchaseRamUpgrade(node, levels = 1) {
|
||||
const sanitizedLevels = Math.round(levels);
|
||||
const cost = node.calculateRamUpgradeCost(
|
||||
sanitizedLevels,
|
||||
Player.hacknet_node_ram_cost_mult,
|
||||
);
|
||||
const cost = node.calculateRamUpgradeCost(sanitizedLevels, Player.hacknet_node_ram_cost_mult);
|
||||
if (isNaN(cost) || cost <= 0 || sanitizedLevels < 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -398,32 +283,20 @@ export function purchaseRamUpgrade(node, levels = 1) {
|
||||
const isServer = node instanceof HacknetServer;
|
||||
|
||||
// Fail if we're already at max
|
||||
if (
|
||||
node.ram >=
|
||||
(isServer ? HacknetServerConstants.MaxRam : HacknetNodeConstants.MaxRam)
|
||||
) {
|
||||
if (node.ram >= (isServer ? HacknetServerConstants.MaxRam : HacknetNodeConstants.MaxRam)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the number of specified upgrades would exceed the max RAM, calculate the
|
||||
// max possible number of upgrades and use that
|
||||
if (isServer) {
|
||||
if (
|
||||
node.maxRam * Math.pow(2, sanitizedLevels) >
|
||||
HacknetServerConstants.MaxRam
|
||||
) {
|
||||
const diff = Math.max(
|
||||
0,
|
||||
Math.log2(Math.round(HacknetServerConstants.MaxRam / node.maxRam)),
|
||||
);
|
||||
if (node.maxRam * Math.pow(2, sanitizedLevels) > HacknetServerConstants.MaxRam) {
|
||||
const diff = Math.max(0, Math.log2(Math.round(HacknetServerConstants.MaxRam / node.maxRam)));
|
||||
return purchaseRamUpgrade(node, diff);
|
||||
}
|
||||
} else {
|
||||
if (node.ram * Math.pow(2, sanitizedLevels) > HacknetNodeConstants.MaxRam) {
|
||||
const diff = Math.max(
|
||||
0,
|
||||
Math.log2(Math.round(HacknetNodeConstants.MaxRam / node.ram)),
|
||||
);
|
||||
const diff = Math.max(0, Math.log2(Math.round(HacknetNodeConstants.MaxRam / node.ram)));
|
||||
return purchaseRamUpgrade(node, diff);
|
||||
}
|
||||
}
|
||||
@@ -440,10 +313,7 @@ export function purchaseRamUpgrade(node, levels = 1) {
|
||||
|
||||
export function purchaseCoreUpgrade(node, levels = 1) {
|
||||
const sanitizedLevels = Math.round(levels);
|
||||
const cost = node.calculateCoreUpgradeCost(
|
||||
sanitizedLevels,
|
||||
Player.hacknet_node_core_cost_mult,
|
||||
);
|
||||
const cost = node.calculateCoreUpgradeCost(sanitizedLevels, Player.hacknet_node_core_cost_mult);
|
||||
if (isNaN(cost) || cost <= 0 || sanitizedLevels < 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -451,25 +321,14 @@ export function purchaseCoreUpgrade(node, levels = 1) {
|
||||
const isServer = node instanceof HacknetServer;
|
||||
|
||||
// Fail if we're already at max
|
||||
if (
|
||||
node.cores >=
|
||||
(isServer ? HacknetServerConstants.MaxCores : HacknetNodeConstants.MaxCores)
|
||||
) {
|
||||
if (node.cores >= (isServer ? HacknetServerConstants.MaxCores : HacknetNodeConstants.MaxCores)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the specified number of upgrades would exceed the max Cores, calculate
|
||||
// the max possible number of upgrades and use that
|
||||
if (
|
||||
node.cores + sanitizedLevels >
|
||||
(isServer ? HacknetServerConstants.MaxCores : HacknetNodeConstants.MaxCores)
|
||||
) {
|
||||
const diff = Math.max(
|
||||
0,
|
||||
(isServer
|
||||
? HacknetServerConstants.MaxCores
|
||||
: HacknetNodeConstants.MaxCores) - node.cores,
|
||||
);
|
||||
if (node.cores + sanitizedLevels > (isServer ? HacknetServerConstants.MaxCores : HacknetNodeConstants.MaxCores)) {
|
||||
const diff = Math.max(0, (isServer ? HacknetServerConstants.MaxCores : HacknetNodeConstants.MaxCores) - node.cores);
|
||||
return purchaseCoreUpgrade(node, diff);
|
||||
}
|
||||
|
||||
@@ -546,10 +405,7 @@ export function processHacknetEarnings(numCycles) {
|
||||
function processAllHacknetNodeEarnings(numCycles) {
|
||||
let total = 0;
|
||||
for (let i = 0; i < Player.hacknetNodes.length; ++i) {
|
||||
total += processSingleHacknetNodeEarnings(
|
||||
numCycles,
|
||||
Player.hacknetNodes[i],
|
||||
);
|
||||
total += processSingleHacknetNodeEarnings(numCycles, Player.hacknetNodes[i]);
|
||||
}
|
||||
|
||||
return total;
|
||||
@@ -565,9 +421,7 @@ function processSingleHacknetNodeEarnings(numCycles, nodeObj) {
|
||||
|
||||
function processAllHacknetServerEarnings(numCycles) {
|
||||
if (!(Player.hashManager instanceof HashManager)) {
|
||||
throw new Error(
|
||||
`Player does not have a HashManager (should be in 'hashManager' prop)`,
|
||||
);
|
||||
throw new Error(`Player does not have a HashManager (should be in 'hashManager' prop)`);
|
||||
}
|
||||
|
||||
let hashes = 0;
|
||||
@@ -648,9 +502,7 @@ export function purchaseHashUpgrade(upgName, upgTarget) {
|
||||
try {
|
||||
const target = GetServerByHostname(upgTarget);
|
||||
if (target == null) {
|
||||
console.error(
|
||||
`Invalid target specified in purchaseHashUpgrade(): ${upgTarget}`,
|
||||
);
|
||||
console.error(`Invalid target specified in purchaseHashUpgrade(): ${upgTarget}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -665,9 +517,7 @@ export function purchaseHashUpgrade(upgName, upgTarget) {
|
||||
try {
|
||||
const target = GetServerByHostname(upgTarget);
|
||||
if (target == null) {
|
||||
console.error(
|
||||
`Invalid target specified in purchaseHashUpgrade(): ${upgTarget}`,
|
||||
);
|
||||
console.error(`Invalid target specified in purchaseHashUpgrade(): ${upgTarget}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -725,9 +575,7 @@ export function purchaseHashUpgrade(upgName, upgTarget) {
|
||||
break;
|
||||
}
|
||||
default:
|
||||
console.warn(
|
||||
`Unrecognized upgrade name ${upgName}. Upgrade has no effect`,
|
||||
);
|
||||
console.warn(`Unrecognized upgrade name ${upgName}. Upgrade has no effect`);
|
||||
Player.hashManager.refundUpgrade(upgName);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -17,11 +17,7 @@ import {
|
||||
import { HacknetNodeConstants } from "./data/Constants";
|
||||
|
||||
import { dialogBoxCreate } from "../../utils/DialogBox";
|
||||
import {
|
||||
Generic_fromJSON,
|
||||
Generic_toJSON,
|
||||
Reviver,
|
||||
} from "../../utils/JSONReviver";
|
||||
import { Generic_fromJSON, Generic_toJSON, Reviver } from "../../utils/JSONReviver";
|
||||
|
||||
export class HacknetNode implements IHacknetNode {
|
||||
// Node's number of cores
|
||||
@@ -85,20 +81,14 @@ export class HacknetNode implements IHacknetNode {
|
||||
// Upgrade this Node's number of cores, if possible
|
||||
// Returns a boolean indicating whether new cores were successfully bought
|
||||
upgradeCore(levels = 1, prodMult: number): void {
|
||||
this.cores = Math.min(
|
||||
HacknetNodeConstants.MaxCores,
|
||||
Math.round(this.cores + levels),
|
||||
);
|
||||
this.cores = Math.min(HacknetNodeConstants.MaxCores, Math.round(this.cores + levels));
|
||||
this.updateMoneyGainRate(prodMult);
|
||||
}
|
||||
|
||||
// Upgrade this Node's level, if possible
|
||||
// Returns a boolean indicating whether the level was successfully updated
|
||||
upgradeLevel(levels = 1, prodMult: number): void {
|
||||
this.level = Math.min(
|
||||
HacknetNodeConstants.MaxLevel,
|
||||
Math.round(this.level + levels),
|
||||
);
|
||||
this.level = Math.min(HacknetNodeConstants.MaxLevel, Math.round(this.level + levels));
|
||||
this.updateMoneyGainRate(prodMult);
|
||||
}
|
||||
|
||||
@@ -114,18 +104,10 @@ export class HacknetNode implements IHacknetNode {
|
||||
|
||||
// Re-calculate this Node's production and update the moneyGainRatePerSecond prop
|
||||
updateMoneyGainRate(prodMult: number): void {
|
||||
this.moneyGainRatePerSecond = calculateMoneyGainRate(
|
||||
this.level,
|
||||
this.ram,
|
||||
this.cores,
|
||||
prodMult,
|
||||
);
|
||||
this.moneyGainRatePerSecond = calculateMoneyGainRate(this.level, this.ram, this.cores, prodMult);
|
||||
if (isNaN(this.moneyGainRatePerSecond)) {
|
||||
this.moneyGainRatePerSecond = 0;
|
||||
dialogBoxCreate(
|
||||
"Error in calculating Hacknet Node production. Please report to game developer",
|
||||
false,
|
||||
);
|
||||
dialogBoxCreate("Error in calculating Hacknet Node production. Please report to game developer", false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,11 +18,7 @@ import {
|
||||
|
||||
import { createRandomIp } from "../../utils/IPAddress";
|
||||
|
||||
import {
|
||||
Generic_fromJSON,
|
||||
Generic_toJSON,
|
||||
Reviver,
|
||||
} from "../../utils/JSONReviver";
|
||||
import { Generic_fromJSON, Generic_toJSON, Reviver } from "../../utils/JSONReviver";
|
||||
|
||||
interface IConstructorParams {
|
||||
adminRights?: boolean;
|
||||
@@ -55,9 +51,7 @@ export class HacknetServer extends BaseServer implements IHacknetNode {
|
||||
// Total number of hashes earned by this server
|
||||
totalHashesGenerated = 0;
|
||||
|
||||
constructor(
|
||||
params: IConstructorParams = { hostname: "", ip: createRandomIp() },
|
||||
) {
|
||||
constructor(params: IConstructorParams = { hostname: "", ip: createRandomIp() }) {
|
||||
super(params);
|
||||
|
||||
this.maxRam = 1;
|
||||
@@ -88,26 +82,17 @@ export class HacknetServer extends BaseServer implements IHacknetNode {
|
||||
}
|
||||
|
||||
upgradeCache(levels: number): void {
|
||||
this.cache = Math.min(
|
||||
HacknetServerConstants.MaxCache,
|
||||
Math.round(this.cache + levels),
|
||||
);
|
||||
this.cache = Math.min(HacknetServerConstants.MaxCache, Math.round(this.cache + levels));
|
||||
this.updateHashCapacity();
|
||||
}
|
||||
|
||||
upgradeCore(levels: number, prodMult: number): void {
|
||||
this.cores = Math.min(
|
||||
HacknetServerConstants.MaxCores,
|
||||
Math.round(this.cores + levels),
|
||||
);
|
||||
this.cores = Math.min(HacknetServerConstants.MaxCores, Math.round(this.cores + levels));
|
||||
this.updateHashRate(prodMult);
|
||||
}
|
||||
|
||||
upgradeLevel(levels: number, prodMult: number): void {
|
||||
this.level = Math.min(
|
||||
HacknetServerConstants.MaxLevel,
|
||||
Math.round(this.level + levels),
|
||||
);
|
||||
this.level = Math.min(HacknetServerConstants.MaxLevel, Math.round(this.level + levels));
|
||||
this.updateHashRate(prodMult);
|
||||
}
|
||||
|
||||
@@ -115,10 +100,7 @@ export class HacknetServer extends BaseServer implements IHacknetNode {
|
||||
for (let i = 0; i < levels; ++i) {
|
||||
this.maxRam *= 2;
|
||||
}
|
||||
this.maxRam = Math.min(
|
||||
HacknetServerConstants.MaxRam,
|
||||
Math.round(this.maxRam),
|
||||
);
|
||||
this.maxRam = Math.min(HacknetServerConstants.MaxRam, Math.round(this.maxRam));
|
||||
this.updateHashRate(prodMult);
|
||||
|
||||
return true;
|
||||
@@ -137,13 +119,7 @@ export class HacknetServer extends BaseServer implements IHacknetNode {
|
||||
}
|
||||
|
||||
updateHashRate(prodMult: number): void {
|
||||
this.hashRate = calculateHashGainRate(
|
||||
this.level,
|
||||
this.ramUsed,
|
||||
this.maxRam,
|
||||
this.cores,
|
||||
prodMult,
|
||||
);
|
||||
this.hashRate = calculateHashGainRate(this.level, this.ramUsed, this.maxRam, this.cores, prodMult);
|
||||
|
||||
if (isNaN(this.hashRate)) {
|
||||
this.hashRate = 0;
|
||||
|
||||
@@ -10,11 +10,7 @@ import { HashUpgrades } from "./HashUpgrades";
|
||||
import { HashUpgrade } from "./HashUpgrade";
|
||||
|
||||
import { IMap } from "../types";
|
||||
import {
|
||||
Generic_fromJSON,
|
||||
Generic_toJSON,
|
||||
Reviver,
|
||||
} from "../../utils/JSONReviver";
|
||||
import { Generic_fromJSON, Generic_toJSON, Reviver } from "../../utils/JSONReviver";
|
||||
|
||||
export class HashManager {
|
||||
// Max number of hashes this can hold. Equal to the sum of capacities of
|
||||
@@ -68,9 +64,7 @@ export class HashManager {
|
||||
getUpgrade(upgName: string): HashUpgrade | null {
|
||||
const upg = HashUpgrades[upgName];
|
||||
if (!upg) {
|
||||
console.error(
|
||||
`Invalid Upgrade Name given to HashManager.getUpgrade(): ${upgName}`,
|
||||
);
|
||||
console.error(`Invalid Upgrade Name given to HashManager.getUpgrade(): ${upgName}`);
|
||||
return null;
|
||||
}
|
||||
return upg;
|
||||
@@ -83,9 +77,7 @@ export class HashManager {
|
||||
const upg = this.getUpgrade(upgName);
|
||||
const currLevel = this.upgrades[upgName];
|
||||
if (upg == null || currLevel == null) {
|
||||
console.error(
|
||||
`Invalid Upgrade Name given to HashManager.getUpgradeCost(): ${upgName}`,
|
||||
);
|
||||
console.error(`Invalid Upgrade Name given to HashManager.getUpgradeCost(): ${upgName}`);
|
||||
return Infinity;
|
||||
}
|
||||
|
||||
@@ -113,9 +105,7 @@ export class HashManager {
|
||||
|
||||
const currLevel = this.upgrades[upgName];
|
||||
if (upg == null || currLevel == null || currLevel < 0) {
|
||||
console.error(
|
||||
`Invalid Upgrade Name given to HashManager.upgrade(): ${upgName}`,
|
||||
);
|
||||
console.error(`Invalid Upgrade Name given to HashManager.upgrade(): ${upgName}`);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -142,9 +132,7 @@ export class HashManager {
|
||||
upgrade(upgName: string): boolean {
|
||||
const upg = HashUpgrades[upgName];
|
||||
if (upg == null) {
|
||||
console.error(
|
||||
`Invalid Upgrade Name given to HashManager.upgrade(): ${upgName}`,
|
||||
);
|
||||
console.error(`Invalid Upgrade Name given to HashManager.upgrade(): ${upgName}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,9 +63,7 @@ export const HashUpgradesMetadata: IConstructorParams[] = [
|
||||
"Use hashes to improve the experience earned when training at the gym by 20%. This effect " +
|
||||
"persists until you install Augmentations",
|
||||
name: "Improve Gym Training",
|
||||
effectText: (level: number): JSX.Element | null => (
|
||||
<>Improves training by ${level * 20}%</>
|
||||
),
|
||||
effectText: (level: number): JSX.Element | null => <>Improves training by ${level * 20}%</>,
|
||||
value: 20, // Improves training by value%
|
||||
},
|
||||
{
|
||||
@@ -82,10 +80,7 @@ export const HashUpgradesMetadata: IConstructorParams[] = [
|
||||
desc: "Exchange hashes for 100 Bladeburner Rank",
|
||||
name: "Exchange for Bladeburner Rank",
|
||||
effectText: (level: number): JSX.Element | null => (
|
||||
<>
|
||||
Acquired a total of {numeralWrapper.format(100 * level, "0a")}{" "}
|
||||
Bladeburner rank
|
||||
</>
|
||||
<>Acquired a total of {numeralWrapper.format(100 * level, "0a")} Bladeburner rank</>
|
||||
),
|
||||
value: 100,
|
||||
},
|
||||
@@ -94,10 +89,7 @@ export const HashUpgradesMetadata: IConstructorParams[] = [
|
||||
desc: "Exchanges hashes for 10 Bladeburner Skill Points",
|
||||
name: "Exchange for Bladeburner SP",
|
||||
effectText: (level: number): JSX.Element | null => (
|
||||
<>
|
||||
Acquired a total of {numeralWrapper.format(10 * level, "0a")}{" "}
|
||||
Bladeburner Skill Points
|
||||
</>
|
||||
<>Acquired a total of {numeralWrapper.format(10 * level, "0a")} Bladeburner Skill Points</>
|
||||
),
|
||||
value: 10,
|
||||
},
|
||||
@@ -105,9 +97,7 @@ export const HashUpgradesMetadata: IConstructorParams[] = [
|
||||
costPerLevel: 200,
|
||||
desc: "Generate a random Coding Contract somewhere on the network",
|
||||
name: "Generate Coding Contract",
|
||||
effectText: (level: number): JSX.Element | null => (
|
||||
<>Generated {level} contracts.</>
|
||||
),
|
||||
effectText: (level: number): JSX.Element | null => <>Generated {level} contracts.</>,
|
||||
value: 1,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -1,27 +1,16 @@
|
||||
import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
|
||||
import { HacknetNodeConstants } from "../data/Constants";
|
||||
|
||||
export function calculateMoneyGainRate(
|
||||
level: number,
|
||||
ram: number,
|
||||
cores: number,
|
||||
mult: number,
|
||||
): number {
|
||||
export function calculateMoneyGainRate(level: number, ram: number, cores: number, mult: number): number {
|
||||
const gainPerLevel = HacknetNodeConstants.MoneyGainPerLevel;
|
||||
|
||||
const levelMult = level * gainPerLevel;
|
||||
const ramMult = Math.pow(1.035, ram - 1);
|
||||
const coresMult = (cores + 5) / 6;
|
||||
return (
|
||||
levelMult * ramMult * coresMult * mult * BitNodeMultipliers.HacknetNodeMoney
|
||||
);
|
||||
return levelMult * ramMult * coresMult * mult * BitNodeMultipliers.HacknetNodeMoney;
|
||||
}
|
||||
|
||||
export function calculateLevelUpgradeCost(
|
||||
startingLevel: number,
|
||||
extraLevels = 1,
|
||||
costMult = 1,
|
||||
): number {
|
||||
export function calculateLevelUpgradeCost(startingLevel: number, extraLevels = 1, costMult = 1): number {
|
||||
const sanitizedLevels = Math.round(extraLevels);
|
||||
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
|
||||
return 0;
|
||||
@@ -35,19 +24,14 @@ export function calculateLevelUpgradeCost(
|
||||
let totalMultiplier = 0;
|
||||
let currLevel = startingLevel;
|
||||
for (let i = 0; i < sanitizedLevels; ++i) {
|
||||
totalMultiplier +=
|
||||
HacknetNodeConstants.LevelBaseCost * Math.pow(mult, currLevel);
|
||||
totalMultiplier += HacknetNodeConstants.LevelBaseCost * Math.pow(mult, currLevel);
|
||||
++currLevel;
|
||||
}
|
||||
|
||||
return (HacknetNodeConstants.BaseCost / 2) * totalMultiplier * costMult;
|
||||
}
|
||||
|
||||
export function calculateRamUpgradeCost(
|
||||
startingRam: number,
|
||||
extraLevels = 1,
|
||||
costMult = 1,
|
||||
): number {
|
||||
export function calculateRamUpgradeCost(startingRam: number, extraLevels = 1, costMult = 1): number {
|
||||
const sanitizedLevels = Math.round(extraLevels);
|
||||
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
|
||||
return 0;
|
||||
@@ -76,11 +60,7 @@ export function calculateRamUpgradeCost(
|
||||
return totalCost;
|
||||
}
|
||||
|
||||
export function calculateCoreUpgradeCost(
|
||||
startingCore: number,
|
||||
extraLevels = 1,
|
||||
costMult = 1,
|
||||
): number {
|
||||
export function calculateCoreUpgradeCost(startingCore: number, extraLevels = 1, costMult = 1): number {
|
||||
const sanitizedCores = Math.round(extraLevels);
|
||||
if (isNaN(sanitizedCores) || sanitizedCores < 1) {
|
||||
return 0;
|
||||
@@ -108,9 +88,5 @@ export function calculateNodeCost(n: number, mult = 1): number {
|
||||
if (n <= 0) {
|
||||
return 0;
|
||||
}
|
||||
return (
|
||||
HacknetNodeConstants.BaseCost *
|
||||
Math.pow(HacknetNodeConstants.PurchaseNextMult, n - 1) *
|
||||
mult
|
||||
);
|
||||
return HacknetNodeConstants.BaseCost * Math.pow(HacknetNodeConstants.PurchaseNextMult, n - 1) * mult;
|
||||
}
|
||||
|
||||
@@ -13,21 +13,10 @@ export function calculateHashGainRate(
|
||||
const coreMultiplier = 1 + (cores - 1) / 5;
|
||||
const ramRatio = 1 - ramUsed / maxRam;
|
||||
|
||||
return (
|
||||
baseGain *
|
||||
ramMultiplier *
|
||||
coreMultiplier *
|
||||
ramRatio *
|
||||
mult *
|
||||
BitNodeMultipliers.HacknetNodeMoney
|
||||
);
|
||||
return baseGain * ramMultiplier * coreMultiplier * ramRatio * mult * BitNodeMultipliers.HacknetNodeMoney;
|
||||
}
|
||||
|
||||
export function calculateLevelUpgradeCost(
|
||||
startingLevel: number,
|
||||
extraLevels = 1,
|
||||
costMult = 1,
|
||||
): number {
|
||||
export function calculateLevelUpgradeCost(startingLevel: number, extraLevels = 1, costMult = 1): number {
|
||||
const sanitizedLevels = Math.round(extraLevels);
|
||||
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
|
||||
return 0;
|
||||
@@ -48,11 +37,7 @@ export function calculateLevelUpgradeCost(
|
||||
return 10 * HacknetServerConstants.BaseCost * totalMultiplier * costMult;
|
||||
}
|
||||
|
||||
export function calculateRamUpgradeCost(
|
||||
startingRam: number,
|
||||
extraLevels = 1,
|
||||
costMult = 1,
|
||||
): number {
|
||||
export function calculateRamUpgradeCost(startingRam: number, extraLevels = 1, costMult = 1): number {
|
||||
const sanitizedLevels = Math.round(extraLevels);
|
||||
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
|
||||
return 0;
|
||||
@@ -79,11 +64,7 @@ export function calculateRamUpgradeCost(
|
||||
return totalCost;
|
||||
}
|
||||
|
||||
export function calculateCoreUpgradeCost(
|
||||
startingCores: number,
|
||||
extraLevels = 1,
|
||||
costMult = 1,
|
||||
): number {
|
||||
export function calculateCoreUpgradeCost(startingCores: number, extraLevels = 1, costMult = 1): number {
|
||||
const sanitizedLevels = Math.round(extraLevels);
|
||||
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
|
||||
return 0;
|
||||
@@ -106,10 +87,7 @@ export function calculateCoreUpgradeCost(
|
||||
return totalCost;
|
||||
}
|
||||
|
||||
export function calculateCacheUpgradeCost(
|
||||
startingCache: number,
|
||||
extraLevels = 1,
|
||||
): number {
|
||||
export function calculateCacheUpgradeCost(startingCache: number, extraLevels = 1): number {
|
||||
const sanitizedLevels = Math.round(extraLevels);
|
||||
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
|
||||
return 0;
|
||||
@@ -136,9 +114,5 @@ export function calculateServerCost(n: number, mult = 1): number {
|
||||
return Infinity;
|
||||
}
|
||||
|
||||
return (
|
||||
HacknetServerConstants.BaseCost *
|
||||
Math.pow(HacknetServerConstants.PurchaseMult, n - 1) *
|
||||
mult
|
||||
);
|
||||
return HacknetServerConstants.BaseCost * Math.pow(HacknetServerConstants.PurchaseMult, n - 1) * mult;
|
||||
}
|
||||
|
||||
@@ -46,9 +46,8 @@ export class GeneralInfo extends React.Component {
|
||||
return (
|
||||
<div>
|
||||
<p className={"hacknet-general-info"}>
|
||||
The Hacknet is a global, decentralized network of machines. It is used
|
||||
by hackers all around the world to anonymously share computing power
|
||||
and perform distributed cyberattacks without the fear of being traced.
|
||||
The Hacknet is a global, decentralized network of machines. It is used by hackers all around the world to
|
||||
anonymously share computing power and perform distributed cyberattacks without the fear of being traced.
|
||||
</p>
|
||||
<p className={"hacknet-general-info"}>{this.getSecondParagraph()}</p>
|
||||
<p className={"hacknet-general-info"}>{this.getThirdParagraph()}</p>
|
||||
|
||||
@@ -33,23 +33,16 @@ export class HacknetNode extends React.Component {
|
||||
} else {
|
||||
let multiplier = 0;
|
||||
if (purchaseMult === "MAX") {
|
||||
multiplier = getMaxNumberLevelUpgrades(
|
||||
node,
|
||||
HacknetNodeConstants.MaxLevel,
|
||||
);
|
||||
multiplier = getMaxNumberLevelUpgrades(node, HacknetNodeConstants.MaxLevel);
|
||||
} else {
|
||||
const levelsToMax = HacknetNodeConstants.MaxLevel - node.level;
|
||||
multiplier = Math.min(levelsToMax, purchaseMult);
|
||||
}
|
||||
|
||||
const upgradeLevelCost = node.calculateLevelUpgradeCost(
|
||||
multiplier,
|
||||
Player.hacknet_node_level_cost_mult,
|
||||
);
|
||||
const upgradeLevelCost = node.calculateLevelUpgradeCost(multiplier, Player.hacknet_node_level_cost_mult);
|
||||
upgradeLevelContent = (
|
||||
<>
|
||||
Upgrade x{multiplier} -{" "}
|
||||
<Money money={upgradeLevelCost} player={Player} />
|
||||
Upgrade x{multiplier} - <Money money={upgradeLevelCost} player={Player} />
|
||||
</>
|
||||
);
|
||||
if (Player.money.lt(upgradeLevelCost)) {
|
||||
@@ -61,10 +54,7 @@ export class HacknetNode extends React.Component {
|
||||
const upgradeLevelOnClick = () => {
|
||||
let numUpgrades = purchaseMult;
|
||||
if (purchaseMult === "MAX") {
|
||||
numUpgrades = getMaxNumberLevelUpgrades(
|
||||
node,
|
||||
HacknetNodeConstants.MaxLevel,
|
||||
);
|
||||
numUpgrades = getMaxNumberLevelUpgrades(node, HacknetNodeConstants.MaxLevel);
|
||||
}
|
||||
purchaseLevelUpgrade(node, numUpgrades);
|
||||
recalculate();
|
||||
@@ -80,20 +70,14 @@ export class HacknetNode extends React.Component {
|
||||
if (purchaseMult === "MAX") {
|
||||
multiplier = getMaxNumberRamUpgrades(node, HacknetNodeConstants.MaxRam);
|
||||
} 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);
|
||||
}
|
||||
|
||||
const upgradeRamCost = node.calculateRamUpgradeCost(
|
||||
multiplier,
|
||||
Player.hacknet_node_ram_cost_mult,
|
||||
);
|
||||
const upgradeRamCost = node.calculateRamUpgradeCost(multiplier, Player.hacknet_node_ram_cost_mult);
|
||||
upgradeRamContent = (
|
||||
<>
|
||||
Upgrade x{multiplier} -{" "}
|
||||
<Money money={upgradeRamCost} player={Player} />
|
||||
Upgrade x{multiplier} - <Money money={upgradeRamCost} player={Player} />
|
||||
</>
|
||||
);
|
||||
if (Player.money.lt(upgradeRamCost)) {
|
||||
@@ -105,10 +89,7 @@ export class HacknetNode extends React.Component {
|
||||
const upgradeRamOnClick = () => {
|
||||
let numUpgrades = purchaseMult;
|
||||
if (purchaseMult === "MAX") {
|
||||
numUpgrades = getMaxNumberRamUpgrades(
|
||||
node,
|
||||
HacknetNodeConstants.MaxRam,
|
||||
);
|
||||
numUpgrades = getMaxNumberRamUpgrades(node, HacknetNodeConstants.MaxRam);
|
||||
}
|
||||
purchaseRamUpgrade(node, numUpgrades);
|
||||
recalculate();
|
||||
@@ -122,23 +103,16 @@ export class HacknetNode extends React.Component {
|
||||
} else {
|
||||
let multiplier = 0;
|
||||
if (purchaseMult === "MAX") {
|
||||
multiplier = getMaxNumberCoreUpgrades(
|
||||
node,
|
||||
HacknetNodeConstants.MaxCores,
|
||||
);
|
||||
multiplier = getMaxNumberCoreUpgrades(node, HacknetNodeConstants.MaxCores);
|
||||
} else {
|
||||
const levelsToMax = HacknetNodeConstants.MaxCores - node.cores;
|
||||
multiplier = Math.min(levelsToMax, purchaseMult);
|
||||
}
|
||||
|
||||
const upgradeCoreCost = node.calculateCoreUpgradeCost(
|
||||
multiplier,
|
||||
Player.hacknet_node_core_cost_mult,
|
||||
);
|
||||
const upgradeCoreCost = node.calculateCoreUpgradeCost(multiplier, Player.hacknet_node_core_cost_mult);
|
||||
upgradeCoresContent = (
|
||||
<>
|
||||
Upgrade x{multiplier} -{" "}
|
||||
<Money money={upgradeCoreCost} player={Player} />
|
||||
Upgrade x{multiplier} - <Money money={upgradeCoreCost} player={Player} />
|
||||
</>
|
||||
);
|
||||
if (Player.money.lt(upgradeCoreCost)) {
|
||||
@@ -150,10 +124,7 @@ export class HacknetNode extends React.Component {
|
||||
const upgradeCoresOnClick = () => {
|
||||
let numUpgrades = purchaseMult;
|
||||
if (purchaseMult === "MAX") {
|
||||
numUpgrades = getMaxNumberCoreUpgrades(
|
||||
node,
|
||||
HacknetNodeConstants.MaxCores,
|
||||
);
|
||||
numUpgrades = getMaxNumberCoreUpgrades(node, HacknetNodeConstants.MaxCores);
|
||||
}
|
||||
purchaseCoreUpgrade(node, numUpgrades);
|
||||
recalculate();
|
||||
@@ -169,8 +140,7 @@ export class HacknetNode extends React.Component {
|
||||
<div className={"row"}>
|
||||
<p>Production:</p>
|
||||
<span className={"text money-gold"}>
|
||||
<Money money={node.totalMoneyGenerated} player={Player} /> (
|
||||
{MoneyRate(node.moneyGainRatePerSecond)})
|
||||
<Money money={node.totalMoneyGenerated} player={Player} /> ({MoneyRate(node.moneyGainRatePerSecond)})
|
||||
</span>
|
||||
</div>
|
||||
<div className={"row"}>
|
||||
|
||||
@@ -37,23 +37,16 @@ export class HacknetServer extends React.Component {
|
||||
} else {
|
||||
let multiplier = 0;
|
||||
if (purchaseMult === "MAX") {
|
||||
multiplier = getMaxNumberLevelUpgrades(
|
||||
node,
|
||||
HacknetServerConstants.MaxLevel,
|
||||
);
|
||||
multiplier = getMaxNumberLevelUpgrades(node, HacknetServerConstants.MaxLevel);
|
||||
} else {
|
||||
const levelsToMax = HacknetServerConstants.MaxLevel - node.level;
|
||||
multiplier = Math.min(levelsToMax, purchaseMult);
|
||||
}
|
||||
|
||||
const upgradeLevelCost = node.calculateLevelUpgradeCost(
|
||||
multiplier,
|
||||
Player.hacknet_node_level_cost_mult,
|
||||
);
|
||||
const upgradeLevelCost = node.calculateLevelUpgradeCost(multiplier, Player.hacknet_node_level_cost_mult);
|
||||
upgradeLevelContent = (
|
||||
<>
|
||||
Upgrade x{multiplier} -{" "}
|
||||
<Money money={upgradeLevelCost} player={Player} />
|
||||
Upgrade x{multiplier} - <Money money={upgradeLevelCost} player={Player} />
|
||||
</>
|
||||
);
|
||||
if (Player.money.lt(upgradeLevelCost)) {
|
||||
@@ -65,10 +58,7 @@ export class HacknetServer extends React.Component {
|
||||
const upgradeLevelOnClick = () => {
|
||||
let numUpgrades = purchaseMult;
|
||||
if (purchaseMult === "MAX") {
|
||||
numUpgrades = getMaxNumberLevelUpgrades(
|
||||
node,
|
||||
HacknetServerConstants.MaxLevel,
|
||||
);
|
||||
numUpgrades = getMaxNumberLevelUpgrades(node, HacknetServerConstants.MaxLevel);
|
||||
}
|
||||
purchaseLevelUpgrade(node, numUpgrades);
|
||||
recalculate();
|
||||
@@ -83,25 +73,16 @@ export class HacknetServer extends React.Component {
|
||||
} else {
|
||||
let multiplier = 0;
|
||||
if (purchaseMult === "MAX") {
|
||||
multiplier = getMaxNumberRamUpgrades(
|
||||
node,
|
||||
HacknetServerConstants.MaxRam,
|
||||
);
|
||||
multiplier = getMaxNumberRamUpgrades(node, HacknetServerConstants.MaxRam);
|
||||
} else {
|
||||
const levelsToMax = Math.round(
|
||||
Math.log2(HacknetServerConstants.MaxRam / node.maxRam),
|
||||
);
|
||||
const levelsToMax = Math.round(Math.log2(HacknetServerConstants.MaxRam / node.maxRam));
|
||||
multiplier = Math.min(levelsToMax, purchaseMult);
|
||||
}
|
||||
|
||||
const upgradeRamCost = node.calculateRamUpgradeCost(
|
||||
multiplier,
|
||||
Player.hacknet_node_ram_cost_mult,
|
||||
);
|
||||
const upgradeRamCost = node.calculateRamUpgradeCost(multiplier, Player.hacknet_node_ram_cost_mult);
|
||||
upgradeRamContent = (
|
||||
<>
|
||||
Upgrade x{multiplier} -{" "}
|
||||
<Money money={upgradeRamCost} player={Player} />
|
||||
Upgrade x{multiplier} - <Money money={upgradeRamCost} player={Player} />
|
||||
</>
|
||||
);
|
||||
if (Player.money.lt(upgradeRamCost)) {
|
||||
@@ -113,10 +94,7 @@ export class HacknetServer extends React.Component {
|
||||
const upgradeRamOnClick = () => {
|
||||
let numUpgrades = purchaseMult;
|
||||
if (purchaseMult === "MAX") {
|
||||
numUpgrades = getMaxNumberRamUpgrades(
|
||||
node,
|
||||
HacknetServerConstants.MaxRam,
|
||||
);
|
||||
numUpgrades = getMaxNumberRamUpgrades(node, HacknetServerConstants.MaxRam);
|
||||
}
|
||||
purchaseRamUpgrade(node, numUpgrades);
|
||||
recalculate();
|
||||
@@ -131,23 +109,16 @@ export class HacknetServer extends React.Component {
|
||||
} else {
|
||||
let multiplier = 0;
|
||||
if (purchaseMult === "MAX") {
|
||||
multiplier = getMaxNumberCoreUpgrades(
|
||||
node,
|
||||
HacknetServerConstants.MaxCores,
|
||||
);
|
||||
multiplier = getMaxNumberCoreUpgrades(node, HacknetServerConstants.MaxCores);
|
||||
} else {
|
||||
const levelsToMax = HacknetServerConstants.MaxCores - node.cores;
|
||||
multiplier = Math.min(levelsToMax, purchaseMult);
|
||||
}
|
||||
|
||||
const upgradeCoreCost = node.calculateCoreUpgradeCost(
|
||||
multiplier,
|
||||
Player.hacknet_node_core_cost_mult,
|
||||
);
|
||||
const upgradeCoreCost = node.calculateCoreUpgradeCost(multiplier, Player.hacknet_node_core_cost_mult);
|
||||
upgradeCoresContent = (
|
||||
<>
|
||||
Upgrade x{multiplier} -{" "}
|
||||
<Money money={upgradeCoreCost} player={Player} />
|
||||
Upgrade x{multiplier} - <Money money={upgradeCoreCost} player={Player} />
|
||||
</>
|
||||
);
|
||||
if (Player.money.lt(upgradeCoreCost)) {
|
||||
@@ -159,10 +130,7 @@ export class HacknetServer extends React.Component {
|
||||
const upgradeCoresOnClick = () => {
|
||||
let numUpgrades = purchaseMult;
|
||||
if (purchaseMult === "MAX") {
|
||||
numUpgrades = getMaxNumberCoreUpgrades(
|
||||
node,
|
||||
HacknetServerConstants.MaxCores,
|
||||
);
|
||||
numUpgrades = getMaxNumberCoreUpgrades(node, HacknetServerConstants.MaxCores);
|
||||
}
|
||||
purchaseCoreUpgrade(node, numUpgrades);
|
||||
recalculate();
|
||||
@@ -177,10 +145,7 @@ export class HacknetServer extends React.Component {
|
||||
} else {
|
||||
let multiplier = 0;
|
||||
if (purchaseMult === "MAX") {
|
||||
multiplier = getMaxNumberCacheUpgrades(
|
||||
node,
|
||||
HacknetServerConstants.MaxCache,
|
||||
);
|
||||
multiplier = getMaxNumberCacheUpgrades(node, HacknetServerConstants.MaxCache);
|
||||
} else {
|
||||
const levelsToMax = HacknetServerConstants.MaxCache - node.cache;
|
||||
multiplier = Math.min(levelsToMax, purchaseMult);
|
||||
@@ -189,8 +154,7 @@ export class HacknetServer extends React.Component {
|
||||
const upgradeCacheCost = node.calculateCacheUpgradeCost(multiplier);
|
||||
upgradeCacheContent = (
|
||||
<>
|
||||
Upgrade x{multiplier} -{" "}
|
||||
<Money money={upgradeCacheCost} player={Player} />
|
||||
Upgrade x{multiplier} - <Money money={upgradeCacheCost} player={Player} />
|
||||
</>
|
||||
);
|
||||
if (Player.money.lt(upgradeCacheCost)) {
|
||||
@@ -202,10 +166,7 @@ export class HacknetServer extends React.Component {
|
||||
const upgradeCacheOnClick = () => {
|
||||
let numUpgrades = purchaseMult;
|
||||
if (purchaseMult === "MAX") {
|
||||
numUpgrades = getMaxNumberCacheUpgrades(
|
||||
node,
|
||||
HacknetServerConstants.MaxCache,
|
||||
);
|
||||
numUpgrades = getMaxNumberCacheUpgrades(node, HacknetServerConstants.MaxCache);
|
||||
}
|
||||
purchaseCacheUpgrade(node, numUpgrades);
|
||||
recalculate();
|
||||
|
||||
@@ -26,11 +26,7 @@ class HashUpgrade extends React.Component {
|
||||
};
|
||||
|
||||
this.changeTargetServer = this.changeTargetServer.bind(this);
|
||||
this.purchase = this.purchase.bind(
|
||||
this,
|
||||
this.props.hashManager,
|
||||
this.props.upg,
|
||||
);
|
||||
this.purchase = this.purchase.bind(this, this.props.hashManager, this.props.upg);
|
||||
}
|
||||
|
||||
changeTargetServer(e) {
|
||||
@@ -40,8 +36,7 @@ class HashUpgrade extends React.Component {
|
||||
}
|
||||
|
||||
purchase(hashManager, upg) {
|
||||
const canPurchase =
|
||||
hashManager.hashes >= hashManager.getUpgradeCost(upg.name);
|
||||
const canPurchase = hashManager.hashes >= hashManager.getUpgradeCost(upg.name);
|
||||
if (canPurchase) {
|
||||
const res = purchaseHashUpgrade(upg.name, this.state.selectedServer);
|
||||
if (res) {
|
||||
@@ -124,14 +119,7 @@ export class HashUpgradePopup extends React.Component {
|
||||
|
||||
const upgradeElems = Object.keys(HashUpgrades).map((upgName) => {
|
||||
const upg = HashUpgrades[upgName];
|
||||
return (
|
||||
<HashUpgrade
|
||||
upg={upg}
|
||||
hashManager={hashManager}
|
||||
key={upg.name}
|
||||
rerender={rerender}
|
||||
/>
|
||||
);
|
||||
return <HashUpgrade upg={upg} hashManager={hashManager} key={upg.name} rerender={rerender} />;
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@@ -26,10 +26,7 @@ export function MultiplierButtons(props) {
|
||||
for (let i = 0; i < mults.length; ++i) {
|
||||
const mult = mults[i];
|
||||
const btnProps = {
|
||||
className:
|
||||
props.purchaseMultiplier === PurchaseMultipliers[mult]
|
||||
? "std-button-disabled"
|
||||
: "std-button",
|
||||
className: props.purchaseMultiplier === PurchaseMultipliers[mult] ? "std-button-disabled" : "std-button",
|
||||
key: mult,
|
||||
onClick: onClicks[i],
|
||||
text: mult,
|
||||
|
||||
@@ -32,8 +32,7 @@ export function PlayerInfo(props) {
|
||||
{hasServers && (
|
||||
<>
|
||||
<span>
|
||||
Hashes: {Hashes(Player.hashManager.hashes)} /{" "}
|
||||
{Hashes(Player.hashManager.capacity)}
|
||||
Hashes: {Hashes(Player.hashManager.hashes)} / {Hashes(Player.hashManager.capacity)}
|
||||
</span>
|
||||
<br />
|
||||
</>
|
||||
|
||||
@@ -3,10 +3,7 @@
|
||||
*/
|
||||
import React from "react";
|
||||
|
||||
import {
|
||||
hasHacknetServers,
|
||||
hasMaxNumberHacknetServers,
|
||||
} from "../HacknetHelpers";
|
||||
import { hasHacknetServers, hasMaxNumberHacknetServers } from "../HacknetHelpers";
|
||||
import { Player } from "../../Player";
|
||||
import { Money } from "../../ui/React/Money";
|
||||
|
||||
|
||||
+5
-17
@@ -41,8 +41,7 @@ export class HacknetRoot extends React.Component {
|
||||
|
||||
this.createHashUpgradesPopup = this.createHashUpgradesPopup.bind(this);
|
||||
this.handlePurchaseButtonClick = this.handlePurchaseButtonClick.bind(this);
|
||||
this.recalculateTotalProduction =
|
||||
this.recalculateTotalProduction.bind(this);
|
||||
this.recalculateTotalProduction = this.recalculateTotalProduction.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
@@ -71,9 +70,7 @@ export class HacknetRoot extends React.Component {
|
||||
if (hserver) {
|
||||
total += hserver.hashRate;
|
||||
} else {
|
||||
console.warn(
|
||||
`Could not find Hacknet Server object in AllServers map (i=${i})`,
|
||||
);
|
||||
console.warn(`Could not find Hacknet Server object in AllServers map (i=${i})`);
|
||||
}
|
||||
} else {
|
||||
total += Player.hacknetNodes[i].moneyGainRatePerSecond;
|
||||
@@ -113,9 +110,7 @@ export class HacknetRoot extends React.Component {
|
||||
if (hasHacknetServers()) {
|
||||
const hserver = AllServers[node];
|
||||
if (hserver == null) {
|
||||
throw new Error(
|
||||
`Could not find Hacknet Server object in AllServers map for IP: ${node}`,
|
||||
);
|
||||
throw new Error(`Could not find Hacknet Server object in AllServers map for IP: ${node}`);
|
||||
}
|
||||
return (
|
||||
<HacknetServer
|
||||
@@ -151,18 +146,11 @@ export class HacknetRoot extends React.Component {
|
||||
<br />
|
||||
<div id={"hacknet-nodes-money-multipliers-div"}>
|
||||
<PlayerInfo totalProduction={this.state.totalProduction} />
|
||||
<MultiplierButtons
|
||||
onClicks={purchaseMultiplierOnClicks}
|
||||
purchaseMultiplier={this.state.purchaseMultiplier}
|
||||
/>
|
||||
<MultiplierButtons onClicks={purchaseMultiplierOnClicks} purchaseMultiplier={this.state.purchaseMultiplier} />
|
||||
</div>
|
||||
|
||||
{hasHacknetServers() && (
|
||||
<button
|
||||
className={"std-button"}
|
||||
onClick={this.createHashUpgradesPopup}
|
||||
style={{ display: "block" }}
|
||||
>
|
||||
<button className={"std-button"} onClick={this.createHashUpgradesPopup} style={{ display: "block" }}>
|
||||
{"Spend Hashes on Upgrades"}
|
||||
</button>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user