2022-01-10 17:29:58 +01:00
import React , { useEffect , useState } from "react" ;
2023-06-26 04:53:35 +02:00
import {
Accordion ,
AccordionSummary ,
AccordionDetails ,
Button ,
MenuItem ,
Select ,
SelectChangeEvent ,
TextField ,
2023-10-23 10:01:21 +02:00
Tooltip ,
2023-06-26 04:53:35 +02:00
Typography ,
} from "@mui/material" ;
2021-09-17 01:23:03 +02:00
import ExpandMoreIcon from "@mui/icons-material/ExpandMore" ;
2023-06-26 04:53:35 +02:00
2022-10-10 00:42:14 +02:00
import { Player } from "@player" ;
2023-06-26 04:53:35 +02:00
import { FactionName } from "@enums" ;
import { Money } from "../../ui/React/Money" ;
2022-09-06 15:07:12 +02:00
import { Router } from "../../ui/GameRoot" ;
2023-06-26 10:24:37 +02:00
import { Page } from "../../ui/Router" ;
2022-04-01 14:54:07 +02:00
import { Bladeburner } from "../../Bladeburner/Bladeburner" ;
import { GangConstants } from "../../Gang/data/Constants" ;
2022-04-13 08:53:22 +02:00
import { checkForMessagesToSend } from "../../Message/MessageHelpers" ;
2023-02-02 16:09:38 +01:00
import { ThemeEvents } from "../../Themes/ui/Theme" ;
2023-06-26 04:53:35 +02:00
import { getEnumHelper } from "../../utils/EnumHelper" ;
2021-09-14 02:37:35 +02:00
2022-09-06 15:07:12 +02:00
export function General ( ) : React . ReactElement {
2022-01-10 17:29:58 +01:00
const [ error , setError ] = useState ( false ) ;
2022-04-01 14:54:07 +02:00
const [ corporationName , setCorporationName ] = useState ( "" ) ;
2023-06-26 04:53:35 +02:00
const [ gangFaction , setGangFaction ] = useState ( FactionName . SlumSnakes ) ;
2023-02-02 16:09:38 +01:00
const [ devMoney , setDevMoney ] = useState ( 0 ) ;
2023-10-23 10:01:21 +02:00
const [ hash , setHash ] = useState ( Player . hashManager . hashes ) ;
const [ homeRam , setHomeRam ] = useState ( Player . getHomeComputer ( ) . maxRam ) ;
2021-09-14 02:37:35 +02:00
2023-02-02 16:09:38 +01:00
// Money functions
2023-10-23 10:01:21 +02:00
const moneyValues = [ 1 e6 , 1 e9 , 1 e12 , 1 e15 , Infinity ] ;
2023-02-02 16:09:38 +01:00
const addCustomMoney = ( ) = > ! Number . isNaN ( devMoney ) && Player . gainMoney ( devMoney , "other" ) ;
const addMoney = ( n : number ) = > ( ) = > Player . gainMoney ( n , "other" ) ;
const setMoney = ( n : number ) = > ( ) = > ( Player . money = Number ( n ) ) ;
2023-10-23 10:01:21 +02:00
const addHashes = ( ) = > ( Player . hashManager . hashes += hash ) ;
2021-09-14 02:37:35 +02:00
2023-02-02 16:09:38 +01:00
// Ram functions
2023-10-23 10:01:21 +02:00
const doubleRam = ( ) = > {
Player . getHomeComputer ( ) . maxRam *= 2 ;
setHomeRam ( homeRam * 2 ) ;
} ;
const setRam = ( gb : number ) = > ( ) = > {
Player . getHomeComputer ( ) . maxRam = gb ;
setHomeRam ( gb ) ;
} ;
2021-09-14 02:37:35 +02:00
2023-02-02 16:09:38 +01:00
// Node-clearing functions
2023-06-26 10:24:37 +02:00
const quickB1tFlum3 = ( ) = > Router . toPage ( Page . BitVerse , { flume : true , quick : true } ) ;
const b1tflum3 = ( ) = > Router . toPage ( Page . BitVerse , { flume : true , quick : false } ) ;
const quickHackW0r1dD43m0n = ( ) = > Router . toPage ( Page . BitVerse , { flume : false , quick : true } ) ;
const hackW0r1dD43m0n = ( ) = > Router . toPage ( Page . BitVerse , { flume : false , quick : false } ) ;
2021-09-14 02:37:35 +02:00
2023-02-02 16:09:38 +01:00
// Corp functions
const createCorporation = ( ) = > {
2023-03-18 02:12:43 +01:00
Player . startCorporation ( corporationName , false ) ;
2023-02-02 16:09:38 +01:00
// Rerender so the corp menu option will show up immediately on the devmenu page selection
ThemeEvents . emit ( ) ;
} ;
const destroyCorporation = ( ) = > {
Player . corporation = null ;
// Rerender so the corp menu option will be removed immediately on the devmenu page selection
ThemeEvents . emit ( ) ;
} ;
// Blade functions
const joinBladeburner = ( ) = > {
2022-09-06 15:07:12 +02:00
Player . bladeburner = new Bladeburner ( ) ;
2023-02-02 16:09:38 +01:00
// Rerender so the blade menu option will show up immediately on the devmenu page selection
ThemeEvents . emit ( ) ;
} ;
const leaveBladeburner = ( ) = > {
Player . bladeburner = null ;
// Rerender so the blade menu option will be removed immediately on the devmenu page selection
ThemeEvents . emit ( ) ;
} ;
// Gang functions
const startGang = ( ) = > {
2023-06-12 06:34:20 +02:00
const isHacking = gangFaction === FactionName . NiteSec || gangFaction === FactionName . TheBlackHand ;
2022-09-06 15:07:12 +02:00
Player . startGang ( gangFaction , isHacking ) ;
2023-02-02 16:09:38 +01:00
// Rerender so the gang menu option will show up immediately on the devmenu page selection
ThemeEvents . emit ( ) ;
} ;
const stopGang = ( ) = > {
Player . gang = null ;
// Rerender so the gang menu option will be removed immediately on the devmenu page selection
ThemeEvents . emit ( ) ;
} ;
2023-06-26 04:53:35 +02:00
const setGangFactionDropdown = ( event : SelectChangeEvent ) = > {
// Todo: Make this a more specific check when a GangName enumlike is added
if ( ! getEnumHelper ( "FactionName" ) . isMember ( event . target . value ) ) return ;
setGangFaction ( event . target . value ) ;
} ;
2023-02-02 16:09:38 +01:00
// Misc functions
const checkMessages = ( ) = > checkForMessagesToSend ( ) ;
2022-01-10 17:29:58 +01:00
useEffect ( ( ) = > {
2022-04-01 14:54:07 +02:00
if ( error ) throw new ReferenceError ( "Manually thrown error" ) ;
2022-01-10 17:29:58 +01:00
} , [ error ] ) ;
2023-10-23 10:01:21 +02:00
// Component css
const smallButtonStyle = { width : "12rem" } ;
const largeButtonStyle = { width : "20rem" } ;
const noArrowsNumberField = {
"& input::-webkit-outer-spin-button, & input::-webkit-inner-spin-button" : {
display : "none" ,
} ,
"& input[type=number]" : {
MozAppearance : "textfield" ,
} ,
} ;
2021-09-14 02:37:35 +02:00
return (
2021-09-18 03:30:02 +02:00
< Accordion TransitionProps = { { unmountOnExit : true } } >
2021-09-14 02:37:35 +02:00
< AccordionSummary expandIcon = { < ExpandMoreIcon / > } >
2021-10-01 22:22:33 +02:00
< Typography > General < / Typography >
2021-09-14 02:37:35 +02:00
< / AccordionSummary >
< AccordionDetails >
2023-10-23 10:01:21 +02:00
{ moneyValues . map ( ( value ) = > (
< Button key = { ` add money ${ value } ` } onClick = { addMoney ( value ) } >
< pre >
+ < Money money = { value } / >
< / pre >
< / Button >
) ) }
< br / >
< Typography > Add Money < / Typography >
< TextField
placeholder = { "$$$" }
type = "number"
onChange = { ( x ) = > setDevMoney ( parseFloat ( x . target . value ) ) }
sx = { noArrowsNumberField }
/ >
< Button style = { smallButtonStyle } onClick = { addCustomMoney } >
Give Money
< / Button >
2023-02-02 16:09:38 +01:00
< Button
2023-10-23 10:01:21 +02:00
style = { smallButtonStyle }
2023-02-02 16:09:38 +01:00
onClick = { setMoney ( 0 ) }
title = "This sets your money to $0, this means the money you had will just vanish without being accounted for where it went and may offset some metrics."
>
2023-10-23 10:01:21 +02:00
Clear Money
2021-10-01 19:08:37 +02:00
< / Button >
2023-10-23 10:01:21 +02:00
< br / >
< TextField
disabled = { ! Player . hashManager }
type = "number"
placeholder = { "add Hacknet hashes" }
onChange = { ( x ) = > setHash ( parseFloat ( x . target . value ) ) }
sx = { noArrowsNumberField }
/ >
< Button disabled = { ! Player . hashManager } style = { smallButtonStyle } onClick = { addHashes } >
Give Hashes
2021-10-01 19:08:37 +02:00
< / Button >
2023-10-23 10:01:21 +02:00
< Button disabled = { ! Player . hashManager } style = { smallButtonStyle } onClick = { ( ) = > ( Player . hashManager . hashes = 0 ) } >
Clear Hashes
2021-10-01 19:08:37 +02:00
< / Button >
< br / >
2023-10-23 10:01:21 +02:00
< Tooltip placement = "top-start" title = { ` Current RAM: ${ Player . getHomeComputer ( ) . maxRam } GB ` } >
< Typography > Set Home Server RAM < / Typography >
< / Tooltip >
< Tooltip placement = "top" title = "Starting RAM" >
< Button onClick = { setRam ( 8 ) } > 8 GB < / Button >
< / Tooltip >
< Button onClick = { setRam ( 64 ) } > 64 GB < / Button >
< Button onClick = { setRam ( 1024 ) } > 1 TB < / Button >
< Button onClick = { setRam ( 1048576 ) } > 1.05 PB < / Button >
< Tooltip placement = "top" title = "Max RAM sold by Alpha Ent." >
< Button onClick = { setRam ( 1073741824 ) } > 1.07 EB < / Button >
< / Tooltip >
< Tooltip placement = "top" title = "Double Home server's current RAM" >
< Button onClick = { doubleRam } > RAM *= 2 < / Button >
< / Tooltip >
2022-04-01 14:54:07 +02:00
< br / >
2023-10-23 10:01:21 +02:00
< Typography > Corporation : < / Typography >
2023-02-02 16:09:38 +01:00
{ Player . corporation ? (
2023-10-23 10:01:21 +02:00
< Button style = { smallButtonStyle } onClick = { destroyCorporation } >
Destroy Corporation
< / Button >
2023-02-02 16:09:38 +01:00
) : (
< >
2023-10-23 10:01:21 +02:00
< TextField
placeholder = "Enter Corp Name"
value = { corporationName }
onChange = { ( x ) = > setCorporationName ( x . target . value ) }
/ >
< br / >
< Button style = { smallButtonStyle } onClick = { createCorporation } >
Create Corporation
< / Button >
2023-02-02 16:09:38 +01:00
< / >
) }
2022-04-01 14:54:07 +02:00
< br / >
2023-10-23 10:01:21 +02:00
< Typography > Gang Faction : < / Typography >
2023-02-02 16:09:38 +01:00
{ Player . gang ? (
2023-10-23 10:01:21 +02:00
< Button style = { smallButtonStyle } onClick = { stopGang } >
Leave Gang
< / Button >
2023-02-02 16:09:38 +01:00
) : (
< >
< Select value = { gangFaction } onChange = { setGangFactionDropdown } >
{ GangConstants . Names . map ( ( factionName ) = > (
< MenuItem key = { factionName } value = { factionName } >
{ factionName }
< / MenuItem >
) ) }
< / Select >
2023-10-23 10:01:21 +02:00
< br / >
< Button style = { smallButtonStyle } onClick = { startGang } >
Create Gang
< / Button >
2023-02-02 16:09:38 +01:00
< / >
) }
< br / >
2023-10-23 10:01:21 +02:00
< Typography > Bladeburner : < / Typography >
2023-02-02 16:09:38 +01:00
{ Player . bladeburner ? (
2023-10-23 10:01:21 +02:00
< Button style = { smallButtonStyle } onClick = { leaveBladeburner } >
Leave BladeBurner
< / Button >
2023-02-02 16:09:38 +01:00
) : (
2023-10-23 10:01:21 +02:00
< Button style = { smallButtonStyle } onClick = { joinBladeburner } >
Join BladeBurner
< / Button >
2023-02-02 16:09:38 +01:00
) }
2022-04-01 14:54:07 +02:00
< br / >
2023-10-23 10:01:21 +02:00
< Typography > General : < / Typography >
< Button style = { largeButtonStyle } onClick = { quickB1tFlum3 } >
Quick b1t_flum3 . exe
< / Button >
< Button style = { largeButtonStyle } onClick = { b1tflum3 } >
Run b1t_flum3 . exe
< / Button >
< br / >
< Button style = { largeButtonStyle } onClick = { quickHackW0r1dD43m0n } >
Quick w0rld_d34m0n
< / Button >
< Button style = { largeButtonStyle } onClick = { hackW0r1dD43m0n } >
Hack w0rld_d34m0n
< / Button >
< br / >
< Button style = { largeButtonStyle } onClick = { ( ) = > setError ( true ) } >
Throw Error
< / Button >
< Button style = { largeButtonStyle } onClick = { checkMessages } >
Check Messages
< / Button >
2021-09-14 02:37:35 +02:00
< / AccordionDetails >
< / Accordion >
) ;
}