bitburner-src/src/ui/CharacterInfo.tsx

468 lines
14 KiB
TypeScript
Raw Normal View History

2021-09-10 21:08:51 +02:00
import React, { useState, useEffect } from "react";
import { numeralWrapper } from "../ui/numeralFormat";
import { BitNodes } from "../BitNode/BitNode";
import { IPlayer } from "../PersonObjects/IPlayer";
import { MoneySourceTracker } from "../utils/MoneySourceTracker";
import { dialogBoxCreate } from "../../utils/DialogBox";
import { convertTimeMsToTimeElapsedString } from "../../utils/StringHelperFunctions";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
import { SourceFileFlags } from "../SourceFile/SourceFileFlags";
import { getPurchaseServerLimit } from "../Server/ServerPurchases";
import { HacknetServerConstants } from "../Hacknet/data/Constants";
import { StatsTable } from "./React/StatsTable";
import { Money } from "./React/Money";
2021-09-18 09:00:07 +02:00
import { use } from "./Context";
2021-09-18 09:00:07 +02:00
function LastEmployer(): React.ReactElement {
const player = use.Player();
if (player.companyName) {
return (
<>
<span>Employer at which you last worked: {player.companyName}</span>
<br />
</>
);
}
return <></>;
2021-09-10 21:08:51 +02:00
}
2021-09-18 09:00:07 +02:00
function LastJob(): React.ReactElement {
const player = use.Player();
if (player.companyName !== "") {
return (
<>
<span>Job you last worked: {player.jobs[player.companyName]}</span>
<br />
</>
);
2021-09-10 21:08:51 +02:00
}
2021-09-18 09:00:07 +02:00
return <></>;
}
2021-09-10 21:08:51 +02:00
2021-09-18 09:00:07 +02:00
function Employers(): React.ReactElement {
const player = use.Player();
if (player.jobs && Object.keys(player.jobs).length !== 0)
return (
<>
<span>All Employers:</span>
<br />
<ul>
{Object.keys(player.jobs).map((j) => (
<li key={j}> * {j}</li>
))}
</ul>
<br />
<br />
</>
);
return <></>;
}
2021-09-10 21:08:51 +02:00
2021-09-18 09:00:07 +02:00
function Hacknet(): React.ReactElement {
const player = use.Player();
// Can't import HacknetHelpers for some reason.
if (!(player.bitNodeN === 9 || SourceFileFlags[9] > 0)) {
return (
<>
<span>{`Hacknet Nodes owned: ${player.hacknetNodes.length}`}</span>
<br />
</>
);
} else {
return (
<>
<span>{`Hacknet Servers owned: ${player.hacknetNodes.length} / ${HacknetServerConstants.MaxServers}`}</span>
<br />
</>
);
}
}
function Intelligence(): React.ReactElement {
const player = use.Player();
if (player.intelligence > 0 && (player.bitNodeN === 5 || SourceFileFlags[5] > 0)) {
return (
<tr key="5">
<td>Intelligence:</td>
<td style={{ textAlign: "right" }}>{numeralWrapper.formatSkill(player.intelligence)}</td>
</tr>
);
2021-09-05 01:09:30 +02:00
}
2021-09-18 09:00:07 +02:00
return <></>;
}
function MultiplierTable(props: any): React.ReactElement {
function bn5Stat(r: any): JSX.Element {
if (SourceFileFlags[5] > 0 && r.length > 2 && r[1] != r[2]) {
2021-09-05 01:09:30 +02:00
return (
2021-09-18 09:00:07 +02:00
<td key="2" style={{ textAlign: "right" }}>
{" "}
({numeralWrapper.formatPercentage(r[2])})
</td>
2021-09-05 01:09:30 +02:00
);
}
2021-09-05 01:09:30 +02:00
return <></>;
}
2021-09-18 09:00:07 +02:00
return (
<>
<table>
<tbody>
{props.rows.map((r: any) => (
<tr key={r[0]}>
<td key="0">{`${r[0]} multiplier:`}</td>
<td key="1" style={{ textAlign: "right", paddingLeft: "5px" }}>
{numeralWrapper.formatPercentage(r[1])}
</td>
{bn5Stat(r)}
</tr>
))}
</tbody>
</table>
</>
);
}
function BladeburnerMults(): React.ReactElement {
const player = use.Player();
if (!player.canAccessBladeburner()) return <></>;
return (
<>
<MultiplierTable
rows={[
["Bladeburner Success Chance", player.bladeburner_max_stamina_mult],
["Bladeburner Max Stamina", player.bladeburner_stamina_gain_mult],
["Bladeburner Stamina Gain", player.bladeburner_analysis_mult],
["Bladeburner Field Analysis", player.bladeburner_success_chance_mult],
]}
/>
<br />
</>
);
}
function CurrentBitNode(): React.ReactElement {
const player = use.Player();
if (player.sourceFiles.length > 0) {
const index = "BitNode" + player.bitNodeN;
return (
<>
<span>
Current BitNode: {player.bitNodeN} ({BitNodes[index].name})
</span>
<br />
<br />
<div style={{ width: "60%", fontSize: "13px", marginLeft: "2%" }}>
<span style={{ whiteSpace: "pre-wrap", overflowWrap: "break-word" }}>{BitNodes[index].info}</span>
</div>
</>
);
2021-09-05 01:09:30 +02:00
}
2021-09-18 09:00:07 +02:00
return <></>;
}
export function CharacterInfo(): React.ReactElement {
const player = use.Player();
const setRerender = useState(false)[1];
function rerender(): void {
setRerender((old) => !old);
2021-09-05 01:09:30 +02:00
}
2021-09-18 09:00:07 +02:00
useEffect(() => {
const id = setInterval(rerender, 20);
return () => clearInterval(id);
}, []);
2021-09-09 05:47:34 +02:00
function convertMoneySourceTrackerToString(src: MoneySourceTracker): React.ReactElement {
2021-09-05 01:09:30 +02:00
const parts: any[][] = [[`Total:`, <Money money={src.total} />]];
if (src.bladeburner) {
parts.push([`Bladeburner:`, <Money money={src.bladeburner} />]);
}
2021-09-05 01:09:30 +02:00
if (src.codingcontract) {
parts.push([`Coding Contracts:`, <Money money={src.codingcontract} />]);
}
2021-09-05 01:09:30 +02:00
if (src.work) {
parts.push([`Company Work:`, <Money money={src.work} />]);
}
if (src.class) {
parts.push([`Class:`, <Money money={src.class} />]);
}
if (src.corporation) {
parts.push([`Corporation:`, <Money money={src.corporation} />]);
}
if (src.crime) {
parts.push([`Crimes:`, <Money money={src.crime} />]);
}
if (src.gang) {
parts.push([`Gang:`, <Money money={src.gang} />]);
}
if (src.hacking) {
parts.push([`Hacking:`, <Money money={src.hacking} />]);
}
if (src.hacknetnode) {
parts.push([`Hacknet Nodes:`, <Money money={src.hacknetnode} />]);
}
if (src.hospitalization) {
parts.push([`Hospitalization:`, <Money money={src.hospitalization} />]);
}
if (src.infiltration) {
parts.push([`Infiltration:`, <Money money={src.infiltration} />]);
}
if (src.stock) {
parts.push([`Stock Market:`, <Money money={src.stock} />]);
}
if (src.casino) {
parts.push([`Casino:`, <Money money={src.casino} />]);
}
if (src.sleeves) {
parts.push([`Sleeves:`, <Money money={src.sleeves} />]);
}
2021-09-05 01:09:30 +02:00
return StatsTable(parts);
}
function openMoneyModal(): void {
let content = (
<>
<u>Money earned since you last installed Augmentations:</u>
<br />
2021-09-18 09:00:07 +02:00
{convertMoneySourceTrackerToString(player.moneySourceA)}
2021-09-05 01:09:30 +02:00
</>
);
2021-09-18 09:00:07 +02:00
if (player.sourceFiles.length !== 0) {
2021-09-05 01:09:30 +02:00
content = (
<>
{content}
<br />
<br />
<u>Money earned in this BitNode:</u>
<br />
2021-09-18 09:00:07 +02:00
{convertMoneySourceTrackerToString(player.moneySourceB)}
</>
2021-09-05 01:09:30 +02:00
);
}
2021-09-05 01:09:30 +02:00
dialogBoxCreate(content, false);
}
2021-09-10 21:08:51 +02:00
const timeRows = [
2021-09-18 09:00:07 +02:00
["Time played since last Augmentation:", convertTimeMsToTimeElapsedString(player.playtimeSinceLastAug)],
2021-09-10 21:08:51 +02:00
];
2021-09-18 09:00:07 +02:00
if (player.sourceFiles.length > 0) {
2021-09-05 01:09:30 +02:00
timeRows.push([
"Time played since last Bitnode destroyed:",
2021-09-18 09:00:07 +02:00
convertTimeMsToTimeElapsedString(player.playtimeSinceLastBitnode),
2021-09-05 01:09:30 +02:00
]);
}
2021-09-18 09:00:07 +02:00
timeRows.push(["Total Time played:", convertTimeMsToTimeElapsedString(player.totalPlaytime)]);
2021-09-05 01:09:30 +02:00
return (
2021-09-11 18:24:09 +02:00
<>
<pre>
<b>General</b>
<br />
<br />
2021-09-18 09:00:07 +02:00
<span>Current City: {player.city}</span>
<br />
<LastEmployer />
<LastJob />
<Employers />
<span>
2021-09-18 09:00:07 +02:00
Money: <Money money={player.money.toNumber()} />
</span>
<button
className="popup-box-button"
style={{ display: "inline-block", float: "none" }}
onClick={openMoneyModal}
>
Money Statistics & Breakdown
</button>
<br />
<br />
<b>Stats</b>
<table>
<tbody>
<tr key="0">
<td key="0">Hacking:</td>
<td key="1" style={{ textAlign: "right" }}>
2021-09-18 09:00:07 +02:00
{numeralWrapper.formatSkill(player.hacking_skill)}
</td>
<td key="2" style={{ textAlign: "right" }}>
2021-09-18 09:00:07 +02:00
({numeralWrapper.formatExp(player.hacking_exp)} exp)
</td>
</tr>
<tr key="1">
<td key="0">Strength:</td>
<td key="1" style={{ textAlign: "right" }}>
2021-09-18 09:00:07 +02:00
{numeralWrapper.formatSkill(player.strength)}
</td>
<td key="2" style={{ textAlign: "right" }}>
2021-09-18 09:00:07 +02:00
({numeralWrapper.formatExp(player.strength_exp)} exp)
</td>
</tr>
<tr key="2">
<td key="0">Defense:</td>
<td key="1" style={{ textAlign: "right" }}>
2021-09-18 09:00:07 +02:00
{numeralWrapper.formatSkill(player.defense)}
</td>
<td key="2" style={{ textAlign: "right" }}>
2021-09-18 09:00:07 +02:00
({numeralWrapper.formatExp(player.defense_exp)} exp)
</td>
</tr>
<tr key="3">
<td key="0">Dexterity:</td>
<td key="1" style={{ textAlign: "right" }}>
2021-09-18 09:00:07 +02:00
{numeralWrapper.formatSkill(player.dexterity)}
</td>
<td key="2" style={{ textAlign: "right" }}>
2021-09-18 09:00:07 +02:00
({numeralWrapper.formatExp(player.dexterity_exp)} exp)
</td>
</tr>
<tr key="4">
<td key="0">Agility:</td>
<td key="1" style={{ textAlign: "right" }}>
2021-09-18 09:00:07 +02:00
{numeralWrapper.formatSkill(player.agility)}
</td>
<td key="2" style={{ textAlign: "right" }}>
2021-09-18 09:00:07 +02:00
({numeralWrapper.formatExp(player.agility_exp)} exp)
</td>
</tr>
<tr key="5">
<td key="0">Charisma:</td>
<td key="1" style={{ textAlign: "right" }}>
2021-09-18 09:00:07 +02:00
{numeralWrapper.formatSkill(player.charisma)}
</td>
<td key="2" style={{ textAlign: "right" }}>
2021-09-18 09:00:07 +02:00
({numeralWrapper.formatExp(player.charisma_exp)} exp)
</td>
</tr>
<Intelligence />
</tbody>
</table>
<br />
<MultiplierTable
rows={[
2021-09-18 09:00:07 +02:00
["Hacking Chance", player.hacking_chance_mult],
["Hacking Speed", player.hacking_speed_mult],
[
"Hacking Money",
2021-09-18 09:00:07 +02:00
player.hacking_money_mult,
player.hacking_money_mult * BitNodeMultipliers.ScriptHackMoney,
],
[
"Hacking Growth",
2021-09-18 09:00:07 +02:00
player.hacking_grow_mult,
player.hacking_grow_mult * BitNodeMultipliers.ServerGrowthRate,
],
]}
/>
<br />
<MultiplierTable
rows={[
2021-09-18 09:00:07 +02:00
["Hacking Level", player.hacking_mult, player.hacking_mult * BitNodeMultipliers.HackingLevelMultiplier],
["Hacking Experience", player.hacking_exp_mult, player.hacking_exp_mult * BitNodeMultipliers.HackExpGain],
]}
/>
<br />
<MultiplierTable
rows={[
2021-09-18 09:00:07 +02:00
["Strength Level", player.strength_mult, player.strength_mult * BitNodeMultipliers.StrengthLevelMultiplier],
["Strength Experience", player.strength_exp_mult],
]}
/>
<br />
<MultiplierTable
rows={[
2021-09-18 09:00:07 +02:00
["Defense Level", player.defense_mult, player.defense_mult * BitNodeMultipliers.DefenseLevelMultiplier],
["Defense Experience", player.defense_exp_mult],
]}
/>
<br />
<MultiplierTable
rows={[
[
"Dexterity Level",
2021-09-18 09:00:07 +02:00
player.dexterity_mult,
player.dexterity_mult * BitNodeMultipliers.DexterityLevelMultiplier,
],
2021-09-18 09:00:07 +02:00
["Dexterity Experience", player.dexterity_exp_mult],
]}
/>
<br />
<MultiplierTable
rows={[
2021-09-18 09:00:07 +02:00
["Agility Level", player.agility_mult, player.agility_mult * BitNodeMultipliers.AgilityLevelMultiplier],
["Agility Experience", player.agility_exp_mult],
]}
/>
<br />
<MultiplierTable
rows={[
2021-09-18 09:00:07 +02:00
["Charisma Level", player.charisma_mult, player.charisma_mult * BitNodeMultipliers.CharismaLevelMultiplier],
["Charisma Experience", player.charisma_exp_mult],
]}
/>
<br />
<MultiplierTable
rows={[
[
"Hacknet Node production",
2021-09-18 09:00:07 +02:00
player.hacknet_node_money_mult,
player.hacknet_node_money_mult * BitNodeMultipliers.HacknetNodeMoney,
],
2021-09-18 09:00:07 +02:00
["Hacknet Node purchase cost", player.hacknet_node_purchase_cost_mult],
["Hacknet Node RAM upgrade cost", player.hacknet_node_ram_cost_mult],
["Hacknet Node Core purchase cost", player.hacknet_node_core_cost_mult],
["Hacknet Node level upgrade cost", player.hacknet_node_level_cost_mult],
]}
/>
<br />
<MultiplierTable
rows={[
2021-09-18 09:00:07 +02:00
["Company reputation gain", player.company_rep_mult],
[
"Faction reputation gain",
2021-09-18 09:00:07 +02:00
player.faction_rep_mult,
player.faction_rep_mult * BitNodeMultipliers.FactionWorkRepGain,
],
2021-09-18 09:00:07 +02:00
["Salary", player.work_money_mult, player.work_money_mult * BitNodeMultipliers.CompanyWorkMoney],
]}
/>
<br />
<MultiplierTable
rows={[
2021-09-18 09:00:07 +02:00
["Crime success", player.crime_success_mult],
["Crime money", player.crime_money_mult, player.crime_money_mult * BitNodeMultipliers.CrimeMoney],
]}
/>
<br />
2021-05-08 03:24:16 +02:00
<BladeburnerMults />
<br />
<b>Misc.</b>
<br />
<br />
2021-09-18 09:00:07 +02:00
<span>{`Servers owned: ${player.purchasedServers.length} / ${getPurchaseServerLimit()}`}</span>
<br />
<Hacknet />
2021-09-18 09:00:07 +02:00
<span>{`Augmentations installed: ${player.augmentations.length}`}</span>
<br />
<br />
{StatsTable(timeRows)}
<br />
<CurrentBitNode />
</pre>
2021-09-11 18:24:09 +02:00
</>
2021-09-05 01:09:30 +02:00
);
}