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

168 lines
4.8 KiB
TypeScript
Raw Normal View History

/**
* React Subcomponent for displaying a location's UI, when that location has special
* actions/options/properties
*
* Examples:
* - Bladeburner @ NSA
* - Re-sleeving @ VitaLife
* - Create Corporation @ City Hall
*
* This subcomponent creates all of the buttons for interacting with those special
* properties
*/
import * as React from "react";
2021-09-05 01:09:30 +02:00
import { Location } from "../Location";
2021-09-11 09:19:52 +02:00
import { CreateCorporationPopup } from "../../Corporation/ui/CreateCorporationPopup";
import { createPopup } from "../../ui/React/createPopup";
2021-09-05 01:09:30 +02:00
import { LocationName } from "../data/LocationNames";
2021-09-05 01:09:30 +02:00
import { IEngine } from "../../IEngine";
import { IPlayer } from "../../PersonObjects/IPlayer";
2021-09-05 01:09:30 +02:00
import { AutoupdatingStdButton } from "../../ui/React/AutoupdatingStdButton";
import { StdButton } from "../../ui/React/StdButton";
2021-09-05 01:09:30 +02:00
import { dialogBoxCreate } from "../../../utils/DialogBox";
type IProps = {
2021-09-05 01:09:30 +02:00
engine: IEngine;
loc: Location;
p: IPlayer;
};
type IState = {
2021-09-05 01:09:30 +02:00
inBladeburner: boolean;
};
export class SpecialLocation extends React.Component<IProps, IState> {
2021-09-05 01:09:30 +02:00
/**
* Stores button styling that sets them all to block display
*/
btnStyle: any;
constructor(props: IProps) {
super(props);
this.btnStyle = { display: "block" };
this.renderNoodleBar = this.renderNoodleBar.bind(this);
this.createCorporationPopup = this.createCorporationPopup.bind(this);
this.handleBladeburner = this.handleBladeburner.bind(this);
this.handleResleeving = this.handleResleeving.bind(this);
this.state = {
inBladeburner: this.props.p.inBladeburner(),
};
}
/**
* Click handler for "Create Corporation" button at Sector-12 City Hall
*/
createCorporationPopup(): void {
2021-09-11 09:19:52 +02:00
const popupId = `create-start-corporation-popup`;
createPopup(popupId, CreateCorporationPopup, {
player: this.props.p,
popupId: popupId,
});
2021-09-05 01:09:30 +02:00
}
/**
* Click handler for Bladeburner button at Sector-12 NSA
*/
handleBladeburner(): void {
const p = this.props.p;
if (p.inBladeburner()) {
// Enter Bladeburner division
this.props.engine.loadBladeburnerContent();
} else {
// Apply for Bladeburner division
2021-09-09 05:47:34 +02:00
if (p.strength >= 100 && p.defense >= 100 && p.dexterity >= 100 && p.agility >= 100) {
2021-09-05 01:09:30 +02:00
p.startBladeburner({ new: true });
2021-09-09 05:47:34 +02:00
dialogBoxCreate("You have been accepted into the Bladeburner division!");
2021-09-05 01:09:30 +02:00
this.setState({
inBladeburner: true,
});
const worldHeader = document.getElementById("world-menu-header");
if (worldHeader instanceof HTMLElement) {
worldHeader.click();
worldHeader.click();
}
2021-09-05 01:09:30 +02:00
} else {
2021-09-09 05:47:34 +02:00
dialogBoxCreate("Rejected! Please apply again when you have 100 of each combat stat (str, def, dex, agi)");
2021-09-05 01:09:30 +02:00
}
}
2021-09-05 01:09:30 +02:00
}
/**
* Click handler for Resleeving button at New Tokyo VitaLife
*/
handleResleeving(): void {
this.props.engine.loadResleevingContent();
}
renderBladeburner(): React.ReactNode {
if (!this.props.p.canAccessBladeburner()) {
return null;
}
2021-09-09 05:47:34 +02:00
const text = this.state.inBladeburner ? "Enter Bladeburner Headquarters" : "Apply to Bladeburner Division";
return <StdButton onClick={this.handleBladeburner} style={this.btnStyle} text={text} />;
2021-09-05 01:09:30 +02:00
}
renderNoodleBar(): React.ReactNode {
function EatNoodles(): void {
dialogBoxCreate(<>You ate some delicious noodles and feel refreshed.</>);
}
2021-09-09 05:47:34 +02:00
return <StdButton onClick={EatNoodles} style={this.btnStyle} text={"Eat noodles"} />;
2021-09-05 01:09:30 +02:00
}
renderCreateCorporation(): React.ReactNode {
if (!this.props.p.canAccessCorporation()) {
return (
<>
<p>
2021-09-09 05:47:34 +02:00
<i>A business man is yelling at a clerk. You should come back later.</i>
2021-09-05 01:09:30 +02:00
</p>
</>
);
2021-08-19 22:37:59 +02:00
}
2021-09-05 01:09:30 +02:00
return (
<AutoupdatingStdButton
2021-09-09 05:47:34 +02:00
disabled={!this.props.p.canAccessCorporation() || this.props.p.hasCorporation()}
2021-09-05 01:09:30 +02:00
onClick={this.createCorporationPopup}
style={this.btnStyle}
text={"Create a Corporation"}
/>
);
}
renderResleeving(): React.ReactNode {
if (!this.props.p.canAccessResleeving()) {
return null;
}
2021-09-09 05:47:34 +02:00
return <StdButton onClick={this.handleResleeving} style={this.btnStyle} text={"Re-Sleeve"} />;
2021-09-05 01:09:30 +02:00
}
render(): React.ReactNode {
switch (this.props.loc.name) {
case LocationName.NewTokyoVitaLife: {
return this.renderResleeving();
}
case LocationName.Sector12CityHall: {
return this.renderCreateCorporation();
}
case LocationName.Sector12NSA: {
return this.renderBladeburner();
}
case LocationName.NewTokyoNoodleBar: {
return this.renderNoodleBar();
}
default:
2021-09-09 05:47:34 +02:00
console.error(`Location ${this.props.loc.name} doesn't have any special properties`);
2021-09-05 01:09:30 +02:00
break;
}
2021-09-05 01:09:30 +02:00
}
}