bitburner-src/src/Locations/ui/CompanyLocation.tsx

350 lines
10 KiB
TypeScript
Raw Normal View History

/**
* React Subcomponent for displaying a location's UI, when that location is a company
*
* This subcomponent renders all of the buttons for applying to jobs at a company
*/
2021-09-18 01:43:08 +02:00
import React, { useState } from "react";
2021-09-05 01:09:30 +02:00
import { ApplyToJobButton } from "./ApplyToJobButton";
2021-09-05 01:09:30 +02:00
import { Locations } from "../Locations";
import { LocationName } from "../data/LocationNames";
2021-09-05 01:09:30 +02:00
import { Companies } from "../../Company/Companies";
import { CompanyPosition } from "../../Company/CompanyPosition";
import { CompanyPositions } from "../../Company/CompanyPositions";
import * as posNames from "../../Company/data/companypositionnames";
2021-09-05 01:09:30 +02:00
import { StdButton } from "../../ui/React/StdButton";
import { Reputation } from "../../ui/React/Reputation";
import { Favor } from "../../ui/React/Favor";
2021-09-13 00:03:07 +02:00
import { createPopup } from "../../ui/React/createPopup";
2021-09-18 01:43:08 +02:00
import { use } from "../../ui/Context";
2021-09-13 00:03:07 +02:00
import { QuitJobPopup } from "../../Company/ui/QuitJobPopup";
v0.51.6 (#905) * Make command `cd` without arguments an alias for `cd /` (#853) In most shells `cd` without arguments takes you to the home directory of the current user. I keep trying to do this due to muscle memory from working in terminals, so I figured I'd make it do something useful. There is no home directory in the game, but going to / is the closest thing we have, since that is the starting point for the user in the game. * Add new `backdoor` terminal command (#852) * Add the backdoor command to the terminal This command will perform a manual hack without rewarding money. It will be used for the story, mainly for faction hacking tests * Add tab completion for backdoor command * Add help text for backdoor command * Change condition syntax to be more consistent with others * Extract reused code block so it is always called after actions * Update documentation for new backdoor command Modified references to manual hack as it isn't for factions anymore * Remove extra parenthesis * Rename manuallyHacked to backdoorInstalled * Fix typo * Change faction test messages to use backdoor instad of hack * Rename more instances of manuallyHacked * fixed typo in helptext of darkweb buy (#858) * Fix typos and unify descriptions of augmentations (#859) Made an attempt to... - give all "+rep% company/faction" the same text - make all augmentations with a single effect use a single line to describe the effect - make all effects end with a period * Made Cashroot starter kit display its tooltip with the money formatted properly and in gold * fix typo in docs (#860) * Initial code for Casino Card Deck implementation * Casino Blackjack Implementation * Update some tools (eslint, typescript) * Blackjack code cleanup * Update README_contribution * Update ScriptHelpers.js (#861) expand error message * More augmentation typo fixes (#862) * Add Netscript function getCurrentScript (#856) Add netscript function that returns the current script. * Added milestones menu to guide new players. (#865) Milestone menu * fix typos in milestones (#866) Co-authored-by: sschmidTU <s.schmid@phonicscore.com> * Corrupt location title when backdoor is installed (#864) * Add corruptableText component * Corrupt location title if backdoor is installed * Formatting * Add helper to check value of backdoorInstalled Helper could be oneline but it would make it less readable * Fix some formatting * Add settings option to disable text effects * Import useState * getRunningScript (#867) * Replaced getCurrentScript with getRunningScript * Bunch of smaller fixes (#904) Fix #884 Fix #879 Fix #878 Fix #876 Fix #874 Fix #873 Fix #887 Fix #891 Fix #895 * rework the early servers to be more noob friendly (#903) * v0.51.6 Co-authored-by: Andreas Eriksson <2691182+AndreasTPC@users.noreply.github.com> Co-authored-by: Jack <jackdewinter1@gmail.com> Co-authored-by: Teun Pronk <5228255+Crownie88@users.noreply.github.com> Co-authored-by: Pimvgd <Pimvgd@gmail.com> Co-authored-by: Daniel Xie <daniel.xie@flockfreight.com> Co-authored-by: Simon <33069673+sschmidTU@users.noreply.github.com> Co-authored-by: sschmidTU <s.schmid@phonicscore.com>
2021-04-29 02:07:26 +02:00
type IProps = {
2021-09-05 01:09:30 +02:00
locName: LocationName;
};
2021-09-18 01:43:08 +02:00
export function CompanyLocation(props: IProps): React.ReactElement {
const p = use.Player();
const router = use.Router();
const setRerender = useState(false)[1];
function rerender(): void {
setRerender((old) => !old);
}
2021-09-05 01:09:30 +02:00
/**
* We'll keep a reference to the Company that this component is being rendered for,
* so we don't have to look it up every time
*/
2021-09-18 01:43:08 +02:00
const company = Companies[props.locName];
if (company == null) throw new Error(`CompanyLocation component constructed with invalid company: ${props.locName}`);
2021-09-05 01:09:30 +02:00
/**
* Reference to the Location that this component is being rendered for
*/
2021-09-18 01:43:08 +02:00
const location = Locations[props.locName];
if (location == null) {
throw new Error(`CompanyLocation component constructed with invalid location: ${props.locName}`);
}
2021-09-05 01:09:30 +02:00
/**
* Name of company position that player holds, if applicable
*/
2021-09-18 01:43:08 +02:00
const jobTitle = p.jobs[props.locName] ? p.jobs[props.locName] : null;
2021-09-05 01:09:30 +02:00
2021-09-18 01:43:08 +02:00
/**
* CompanyPosition object for the job that the player holds at this company
* (if he has one)
*/
const companyPosition = jobTitle ? CompanyPositions[jobTitle] : null;
2021-09-05 01:09:30 +02:00
2021-09-18 01:43:08 +02:00
p.location = props.locName;
2021-09-05 01:09:30 +02:00
2021-09-18 01:43:08 +02:00
function applyForAgentJob(e: React.MouseEvent<HTMLElement>): void {
2021-09-05 01:09:30 +02:00
if (!e.isTrusted) {
return;
}
2021-09-18 01:43:08 +02:00
p.applyForAgentJob();
rerender();
2021-09-05 01:09:30 +02:00
}
2021-09-18 01:43:08 +02:00
function applyForBusinessConsultantJob(e: React.MouseEvent<HTMLElement>): void {
2021-09-05 01:09:30 +02:00
if (!e.isTrusted) {
return;
}
2021-09-18 01:43:08 +02:00
p.applyForBusinessConsultantJob();
rerender();
2021-09-05 01:09:30 +02:00
}
2021-09-18 01:43:08 +02:00
function applyForBusinessJob(e: React.MouseEvent<HTMLElement>): void {
2021-09-05 01:09:30 +02:00
if (!e.isTrusted) {
return;
}
2021-09-18 01:43:08 +02:00
p.applyForBusinessJob();
rerender();
2021-09-05 01:09:30 +02:00
}
2021-09-18 01:43:08 +02:00
function applyForEmployeeJob(e: React.MouseEvent<HTMLElement>): void {
2021-09-05 01:09:30 +02:00
if (!e.isTrusted) {
return;
}
2021-09-18 01:43:08 +02:00
p.applyForEmployeeJob();
rerender();
2021-09-05 01:09:30 +02:00
}
2021-09-18 01:43:08 +02:00
function applyForItJob(e: React.MouseEvent<HTMLElement>): void {
2021-09-05 01:09:30 +02:00
if (!e.isTrusted) {
return;
}
2021-09-18 01:43:08 +02:00
p.applyForItJob();
rerender();
2021-09-05 01:09:30 +02:00
}
2021-09-18 01:43:08 +02:00
function applyForPartTimeEmployeeJob(e: React.MouseEvent<HTMLElement>): void {
2021-09-05 01:09:30 +02:00
if (!e.isTrusted) {
return;
}
2021-09-18 01:43:08 +02:00
p.applyForPartTimeEmployeeJob();
rerender();
2021-09-05 01:09:30 +02:00
}
2021-09-18 01:43:08 +02:00
function applyForPartTimeWaiterJob(e: React.MouseEvent<HTMLElement>): void {
2021-09-05 01:09:30 +02:00
if (!e.isTrusted) {
return;
}
2021-09-18 01:43:08 +02:00
p.applyForPartTimeWaiterJob();
rerender();
2021-09-05 01:09:30 +02:00
}
2021-09-18 01:43:08 +02:00
function applyForSecurityJob(e: React.MouseEvent<HTMLElement>): void {
2021-09-05 01:09:30 +02:00
if (!e.isTrusted) {
return;
}
2021-09-18 01:43:08 +02:00
p.applyForSecurityJob();
rerender();
2021-09-05 01:09:30 +02:00
}
2021-09-18 01:43:08 +02:00
function applyForSoftwareConsultantJob(e: React.MouseEvent<HTMLElement>): void {
2021-09-05 01:09:30 +02:00
if (!e.isTrusted) {
return;
}
2021-09-18 01:43:08 +02:00
p.applyForSoftwareConsultantJob();
rerender();
2021-09-05 01:09:30 +02:00
}
2021-09-18 01:43:08 +02:00
function applyForSoftwareJob(e: React.MouseEvent<HTMLElement>): void {
2021-09-05 01:09:30 +02:00
if (!e.isTrusted) {
return;
}
2021-09-18 01:43:08 +02:00
p.applyForSoftwareJob();
rerender();
2021-09-05 01:09:30 +02:00
}
2021-09-18 01:43:08 +02:00
function applyForWaiterJob(e: React.MouseEvent<HTMLElement>): void {
2021-09-05 01:09:30 +02:00
if (!e.isTrusted) {
return;
}
2021-09-18 01:43:08 +02:00
p.applyForWaiterJob();
rerender();
2021-09-05 01:09:30 +02:00
}
2021-09-18 01:43:08 +02:00
function startInfiltration(e: React.MouseEvent<HTMLElement>): void {
2021-09-05 01:09:30 +02:00
if (!e.isTrusted) {
return;
}
2021-09-18 01:43:08 +02:00
const loc = location;
if (!loc.infiltrationData)
throw new Error(`trying to start infiltration at ${props.locName} but the infiltrationData is null`);
2021-09-18 01:43:08 +02:00
router.toInfiltration(props.locName);
2021-09-05 01:09:30 +02:00
}
2021-09-18 01:43:08 +02:00
function work(e: React.MouseEvent<HTMLElement>): void {
2021-09-05 01:09:30 +02:00
if (!e.isTrusted) {
return;
}
2019-04-04 02:08:11 +02:00
2021-09-18 01:43:08 +02:00
const pos = companyPosition;
2021-09-05 01:09:30 +02:00
if (pos instanceof CompanyPosition) {
2021-09-09 05:47:34 +02:00
if (pos.isPartTimeJob() || pos.isSoftwareConsultantJob() || pos.isBusinessConsultantJob()) {
2021-09-18 01:43:08 +02:00
p.startWorkPartTime(props.locName);
2021-09-05 01:09:30 +02:00
} else {
2021-09-18 01:43:08 +02:00
p.startWork(props.locName);
2021-09-05 01:09:30 +02:00
}
2021-09-18 01:43:08 +02:00
router.toWork();
2019-04-04 02:08:11 +02:00
}
2021-09-05 01:09:30 +02:00
}
2019-04-04 02:08:11 +02:00
2021-09-18 01:43:08 +02:00
function quit(e: React.MouseEvent<HTMLElement>): void {
2021-09-13 00:03:07 +02:00
if (!e.isTrusted) return;
const popupId = `quit-job-popup`;
createPopup(popupId, QuitJobPopup, {
2021-09-18 01:43:08 +02:00
locName: props.locName,
company: company,
player: p,
onQuit: rerender,
2021-09-13 00:03:07 +02:00
popupId: popupId,
2021-09-05 01:09:30 +02:00
});
}
2021-09-18 01:43:08 +02:00
const isEmployedHere = jobTitle != null;
const favorGain = company.getFavorGain();
return (
<div>
{isEmployedHere && (
<div>
<p>Job Title: {jobTitle}</p>
<br />
<p style={{ display: "block" }}>-------------------------</p>
<br />
<p className={"tooltip"}>
Company reputation: {Reputation(company.playerReputation)}
<span className={"tooltiptext"}>
You will earn {Favor(favorGain[0])} company favor upon resetting after installing Augmentations
</span>
</p>
<br />
<br />
<p style={{ display: "block" }}>-------------------------</p>
<br />
<p className={"tooltip"}>
Company Favor: {Favor(company.favor)}
<span className={"tooltiptext"}>
Company favor increases the rate at which you earn reputation for this company by 1% per favor. Company
favor is gained whenever you reset after installing Augmentations. The amount of favor you gain depends on
how much reputation you have with the comapny.
</span>
</p>
<br />
<br />
<p style={{ display: "block" }}>-------------------------</p>
<br />
<StdButton onClick={work} text={"Work"} />
&nbsp;&nbsp;&nbsp;&nbsp;
<StdButton onClick={quit} text={"Quit"} />
</div>
)}
{company.hasAgentPositions() && (
<ApplyToJobButton
company={company}
entryPosType={CompanyPositions[posNames.AgentCompanyPositions[0]]}
onClick={applyForAgentJob}
p={p}
style={{ display: "block" }}
text={"Apply for Agent Job"}
/>
)}
{company.hasBusinessConsultantPositions() && (
<ApplyToJobButton
company={company}
entryPosType={CompanyPositions[posNames.BusinessConsultantCompanyPositions[0]]}
onClick={applyForBusinessConsultantJob}
p={p}
style={{ display: "block" }}
text={"Apply for Business Consultant Job"}
/>
)}
{company.hasBusinessPositions() && (
<ApplyToJobButton
company={company}
entryPosType={CompanyPositions[posNames.BusinessCompanyPositions[0]]}
onClick={applyForBusinessJob}
p={p}
style={{ display: "block" }}
text={"Apply for Business Job"}
/>
)}
{company.hasEmployeePositions() && (
<ApplyToJobButton
company={company}
entryPosType={CompanyPositions[posNames.MiscCompanyPositions[1]]}
onClick={applyForEmployeeJob}
p={p}
style={{ display: "block" }}
text={"Apply to be an Employee"}
/>
)}
{company.hasEmployeePositions() && (
<ApplyToJobButton
company={company}
entryPosType={CompanyPositions[posNames.PartTimeCompanyPositions[1]]}
onClick={applyForPartTimeEmployeeJob}
p={p}
style={{ display: "block" }}
text={"Apply to be a part-time Employee"}
/>
)}
{company.hasITPositions() && (
<ApplyToJobButton
company={company}
entryPosType={CompanyPositions[posNames.ITCompanyPositions[0]]}
onClick={applyForItJob}
p={p}
style={{ display: "block" }}
text={"Apply for IT Job"}
/>
)}
{company.hasSecurityPositions() && (
<ApplyToJobButton
company={company}
entryPosType={CompanyPositions[posNames.SecurityCompanyPositions[2]]}
onClick={applyForSecurityJob}
p={p}
style={{ display: "block" }}
text={"Apply for Security Job"}
/>
)}
{company.hasSoftwareConsultantPositions() && (
<ApplyToJobButton
company={company}
entryPosType={CompanyPositions[posNames.SoftwareConsultantCompanyPositions[0]]}
onClick={applyForSoftwareConsultantJob}
p={p}
style={{ display: "block" }}
text={"Apply for Software Consultant Job"}
/>
)}
{company.hasSoftwarePositions() && (
<ApplyToJobButton
company={company}
entryPosType={CompanyPositions[posNames.SoftwareCompanyPositions[0]]}
onClick={applyForSoftwareJob}
p={p}
style={{ display: "block" }}
text={"Apply for Software Job"}
/>
)}
{company.hasWaiterPositions() && (
<ApplyToJobButton
company={company}
entryPosType={CompanyPositions[posNames.MiscCompanyPositions[0]]}
onClick={applyForWaiterJob}
p={p}
style={{ display: "block" }}
text={"Apply to be a Waiter"}
/>
)}
{company.hasWaiterPositions() && (
<ApplyToJobButton
company={company}
entryPosType={CompanyPositions[posNames.PartTimeCompanyPositions[0]]}
onClick={applyForPartTimeWaiterJob}
p={p}
style={{ display: "block" }}
text={"Apply to be a part-time Waiter"}
/>
)}
{location.infiltrationData != null && (
<StdButton onClick={startInfiltration} style={{ display: "block" }} text={"Infiltrate Company"} />
)}
<br />
<br />
<br />
<br />
<br />
</div>
);
}