mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-10 01:33:54 +01:00
HASHNET: Company Favor (#469)
This commit is contained in:
parent
ed9e6d5ea3
commit
751fe82f92
@ -21,6 +21,7 @@ import { iTutorialSteps, iTutorialNextStep, ITutorial } from "../InteractiveTuto
|
||||
import { Player } from "@player";
|
||||
import { GetServer } from "../Server/AllServers";
|
||||
import { Server } from "../Server/Server";
|
||||
import { Companies } from "../Company/Companies";
|
||||
|
||||
// Returns a boolean indicating whether the player has Hacknet Servers
|
||||
// (the upgraded form of Hacknet Nodes)
|
||||
@ -562,6 +563,14 @@ export function purchaseHashUpgrade(upgName: string, upgTarget: string, count =
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "Company Favor": {
|
||||
if (!(upgTarget in Companies)) {
|
||||
console.error(`Invalid target specified in purchaseHashUpgrade(): ${upgTarget}`);
|
||||
throw new Error(`'${upgTarget}' is not a company.`);
|
||||
}
|
||||
Companies[upgTarget].favor += 5;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
console.warn(`Unrecognized upgrade name ${upgName}. Upgrade has no effect`);
|
||||
return false;
|
||||
|
@ -4,6 +4,7 @@ export interface IConstructorParams {
|
||||
costPerLevel: number;
|
||||
desc: string;
|
||||
hasTargetServer?: boolean;
|
||||
hasTargetCompany?: boolean;
|
||||
name: string;
|
||||
value: number;
|
||||
effectText?: (level: number) => JSX.Element | null;
|
||||
@ -33,6 +34,12 @@ export class HashUpgrade {
|
||||
*/
|
||||
hasTargetServer = false;
|
||||
|
||||
/**
|
||||
* Boolean indicating that this upgrade's effect affects a single company,
|
||||
* the "target" company
|
||||
*/
|
||||
hasTargetCompany = false;
|
||||
|
||||
/** Name of upgrade */
|
||||
name = "";
|
||||
|
||||
@ -51,6 +58,7 @@ export class HashUpgrade {
|
||||
this.costPerLevel = p.costPerLevel;
|
||||
this.desc = p.desc;
|
||||
this.hasTargetServer = p.hasTargetServer ? p.hasTargetServer : false;
|
||||
this.hasTargetCompany = p.hasTargetCompany ? p.hasTargetCompany : false;
|
||||
this.name = p.name;
|
||||
this.value = p.value;
|
||||
}
|
||||
|
@ -101,4 +101,11 @@ export const HashUpgradesMetadata: IConstructorParams[] = [
|
||||
effectText: (level: number): JSX.Element | null => <>Generated {level} contracts.</>,
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
costPerLevel: 200,
|
||||
desc: "Use hashes to increase the favor with a company by 5. This effect is permanent.",
|
||||
hasTargetCompany: true,
|
||||
name: "Company Favor",
|
||||
value: 5,
|
||||
},
|
||||
];
|
||||
|
@ -5,6 +5,7 @@ import { HashManager } from "../HashManager";
|
||||
import { HashUpgrade } from "../HashUpgrade";
|
||||
|
||||
import { ServerDropdown, ServerType } from "../../ui/React/ServerDropdown";
|
||||
import { CompanyDropdown } from "../../ui/React/CompanyDropdown";
|
||||
|
||||
import { dialogBoxCreate } from "../../ui/React/DialogBox";
|
||||
import { CopyableText } from "../../ui/React/CopyableText";
|
||||
@ -15,6 +16,7 @@ import Paper from "@mui/material/Paper";
|
||||
import Button from "@mui/material/Button";
|
||||
import { SelectChangeEvent } from "@mui/material/Select";
|
||||
import { FactionNames } from "../../Faction/data/FactionNames";
|
||||
import { companiesMetadata } from "../../Company/data/CompaniesMetadata";
|
||||
|
||||
interface IProps {
|
||||
hashManager: HashManager;
|
||||
@ -23,6 +25,7 @@ interface IProps {
|
||||
}
|
||||
|
||||
const serversMap: { [key: string]: string } = {};
|
||||
const companiesMap: { [key: string]: string } = {};
|
||||
|
||||
export function HacknetUpgradeElem(props: IProps): React.ReactElement {
|
||||
const [selectedServer, setSelectedServer] = useState(
|
||||
@ -32,11 +35,20 @@ export function HacknetUpgradeElem(props: IProps): React.ReactElement {
|
||||
setSelectedServer(event.target.value);
|
||||
serversMap[props.upg.name] = event.target.value;
|
||||
}
|
||||
|
||||
const [selectedCompany, setSelectedCompany] = useState(
|
||||
companiesMap[props.upg.name] ? companiesMap[props.upg.name] : companiesMetadata[0].name,
|
||||
);
|
||||
function changeTargetCompany(event: SelectChangeEvent<string>): void {
|
||||
setSelectedCompany(event.target.value);
|
||||
companiesMap[props.upg.name] = event.target.value;
|
||||
}
|
||||
function purchase(): void {
|
||||
const canPurchase = props.hashManager.hashes >= props.hashManager.getUpgradeCost(props.upg.name);
|
||||
if (canPurchase) {
|
||||
const res = purchaseHashUpgrade(props.upg.name, selectedServer);
|
||||
const res = purchaseHashUpgrade(
|
||||
props.upg.name,
|
||||
props.upg.name === "Company Favor" ? selectedCompany : selectedServer,
|
||||
);
|
||||
if (!res) {
|
||||
dialogBoxCreate(
|
||||
"Failed to purchase upgrade. This may be because you do not have enough hashes, " +
|
||||
@ -67,7 +79,7 @@ export function HacknetUpgradeElem(props: IProps): React.ReactElement {
|
||||
</Typography>
|
||||
|
||||
<Typography>{upg.desc}</Typography>
|
||||
{!upg.hasTargetServer && (
|
||||
{!upg.hasTargetServer && !upg.hasTargetCompany && (
|
||||
<Button onClick={purchase} disabled={!canPurchase}>
|
||||
Buy
|
||||
</Button>
|
||||
@ -81,6 +93,14 @@ export function HacknetUpgradeElem(props: IProps): React.ReactElement {
|
||||
onChange={changeTargetServer}
|
||||
/>
|
||||
)}
|
||||
{upg.hasTargetCompany && (
|
||||
<CompanyDropdown
|
||||
purchase={purchase}
|
||||
canPurchase={canPurchase}
|
||||
value={selectedCompany}
|
||||
onChange={changeTargetCompany}
|
||||
/>
|
||||
)}
|
||||
{level > 0 && effect && <Typography>{effect}</Typography>}
|
||||
</Paper>
|
||||
);
|
||||
|
@ -657,6 +657,9 @@ function evaluateVersionCompatibility(ver: string | number): void {
|
||||
// Prior to v2.2.0, sleeve shock was 0 to 100 internally but displayed as 100 to 0. This unifies them as 100 to 0.
|
||||
for (const sleeve of Player.sleeves) sleeve.shock = 100 - sleeve.shock;
|
||||
}
|
||||
if (anyPlayer.hashManager !== undefined) {
|
||||
anyPlayer.hashManager.upgrades["Company Favor"] ??= 0;
|
||||
}
|
||||
}
|
||||
|
||||
function loadGame(saveString: string): boolean {
|
||||
|
44
src/ui/React/CompanyDropdown.tsx
Normal file
44
src/ui/React/CompanyDropdown.tsx
Normal file
@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Creates a dropdown (select HTML element) with company names as options
|
||||
*/
|
||||
import React from "react";
|
||||
import { companiesMetadata } from "../../Company/data/CompaniesMetadata";
|
||||
|
||||
import Select, { SelectChangeEvent } from "@mui/material/Select";
|
||||
import MenuItem from "@mui/material/MenuItem";
|
||||
import Button from "@mui/material/Button";
|
||||
|
||||
interface IProps {
|
||||
purchase: () => void;
|
||||
canPurchase: boolean;
|
||||
onChange: (event: SelectChangeEvent<string>) => void;
|
||||
value: string;
|
||||
}
|
||||
|
||||
const sortedCompanies = companiesMetadata.sort((a, b) => a.name.localeCompare(b.name));
|
||||
|
||||
export function CompanyDropdown(props: IProps): React.ReactElement {
|
||||
const companies = [];
|
||||
for (const company of sortedCompanies) {
|
||||
companies.push(
|
||||
<MenuItem key={company.name} value={company.name}>
|
||||
{company.name}
|
||||
</MenuItem>,
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Select
|
||||
startAdornment={
|
||||
<Button onClick={props.purchase} disabled={!props.canPurchase}>
|
||||
Buy
|
||||
</Button>
|
||||
}
|
||||
sx={{ mx: 1 }}
|
||||
value={props.value}
|
||||
onChange={props.onChange}
|
||||
>
|
||||
{companies}
|
||||
</Select>
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user