2021-09-04 08:21:31 +02:00
|
|
|
import React, { useState } from "react";
|
|
|
|
|
|
|
|
import { Location } from "../Location";
|
|
|
|
import { createPurchaseServerPopup,
|
|
|
|
createUpgradeHomeCoresPopup,
|
|
|
|
purchaseTorRouter } from "../LocationsHelpers";
|
|
|
|
|
|
|
|
import { CONSTANTS } from "../../Constants";
|
|
|
|
import { IPlayer } from "../../PersonObjects/IPlayer";
|
|
|
|
import { purchaseRamForHomeComputer } from "../../Server/ServerPurchases";
|
|
|
|
|
|
|
|
import { StdButtonPurchased } from "../../ui/React/StdButtonPurchased";
|
|
|
|
import { StdButton } from "../../ui/React/StdButton";
|
|
|
|
import { Money } from "../../ui/React/Money";
|
2021-09-04 20:03:19 +02:00
|
|
|
import { MathComponent } from 'mathjax-react';
|
2021-09-04 08:21:31 +02:00
|
|
|
|
|
|
|
type IProps = {
|
|
|
|
p: IPlayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function CoresButton(props: IProps): React.ReactElement {
|
|
|
|
const setRerender = useState(false)[1];
|
|
|
|
function rerender(): void {
|
|
|
|
setRerender(old => !old);
|
|
|
|
}
|
|
|
|
|
|
|
|
const btnStyle = { display: "block" };
|
|
|
|
|
|
|
|
const homeComputer = props.p.getHomeComputer();
|
|
|
|
const maxCores = homeComputer.cpuCores >= 8;
|
|
|
|
if(maxCores) {
|
|
|
|
return (<StdButtonPurchased
|
|
|
|
style={btnStyle}
|
|
|
|
text={"Upgrade 'home' cores - MAX"}
|
|
|
|
/>);
|
|
|
|
}
|
|
|
|
|
2021-09-04 20:03:19 +02:00
|
|
|
const cost = 1e9*Math.pow(7.5, homeComputer.cpuCores);
|
2021-09-04 08:21:31 +02:00
|
|
|
|
|
|
|
function buy(): void {
|
|
|
|
if(maxCores) return;
|
|
|
|
if (!props.p.canAfford(cost)) return;
|
|
|
|
props.p.loseMoney(cost);
|
|
|
|
homeComputer.cpuCores++;
|
|
|
|
rerender();
|
|
|
|
}
|
2021-09-04 20:03:19 +02:00
|
|
|
//tooltip={<MathComponent tex={String.raw`cost = `} />}
|
2021-09-04 08:21:31 +02:00
|
|
|
return (<StdButton
|
|
|
|
disabled={!props.p.canAfford(cost)}
|
|
|
|
onClick={buy}
|
|
|
|
style={btnStyle}
|
2021-09-04 09:27:31 +02:00
|
|
|
text={<>Upgrade 'home' cores ({homeComputer.cpuCores} -> {homeComputer.cpuCores+1}) - <Money money={cost} player={props.p} /></>}
|
2021-09-04 20:03:19 +02:00
|
|
|
|
2021-09-04 08:21:31 +02:00
|
|
|
/>);
|
|
|
|
}
|