mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2025-02-18 10:53:43 +01:00
Added export bonus
This commit is contained in:
@ -12,6 +12,7 @@ import { Player } from "../Player";
|
|||||||
import { prestigeAugmentation } from "../Prestige";
|
import { prestigeAugmentation } from "../Prestige";
|
||||||
import { saveObject } from "../SaveObject";
|
import { saveObject } from "../SaveObject";
|
||||||
import { Page, routing } from "../ui/navigationTracking";
|
import { Page, routing } from "../ui/navigationTracking";
|
||||||
|
import { onExport } from "../ExportBonus";
|
||||||
|
|
||||||
import { dialogBoxCreate } from "../../utils/DialogBox";
|
import { dialogBoxCreate } from "../../utils/DialogBox";
|
||||||
import { clearObject } from "../../utils/helpers/clearObject";
|
import { clearObject } from "../../utils/helpers/clearObject";
|
||||||
@ -2077,9 +2078,14 @@ export function displayAugmentationsContent(contentEl) {
|
|||||||
if (!routing.isOn(Page.Augmentations)) { return; }
|
if (!routing.isOn(Page.Augmentations)) { return; }
|
||||||
if (!(contentEl instanceof HTMLElement)) { return; }
|
if (!(contentEl instanceof HTMLElement)) { return; }
|
||||||
|
|
||||||
|
function backup() {
|
||||||
|
saveObject.exportGame();
|
||||||
|
onExport(Player);
|
||||||
|
}
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<AugmentationsRoot
|
<AugmentationsRoot
|
||||||
exportGameFn={saveObject.exportGame.bind(saveObject)}
|
exportGameFn={backup}
|
||||||
installAugmentationsFn={installAugmentations}
|
installAugmentationsFn={installAugmentations}
|
||||||
/>,
|
/>,
|
||||||
contentEl,
|
contentEl,
|
||||||
|
@ -10,6 +10,8 @@ import { PurchasedAugmentations } from "./PurchasedAugmentations";
|
|||||||
|
|
||||||
import { Player } from "../../Player";
|
import { Player } from "../../Player";
|
||||||
import { StdButton } from "../../ui/React/StdButton";
|
import { StdButton } from "../../ui/React/StdButton";
|
||||||
|
import { LastExportBonus, canGetBonus } from "../../ExportBonus";
|
||||||
|
import { convertTimeMsToTimeElapsedString } from "../../../utils/StringHelperFunctions";
|
||||||
|
|
||||||
type IProps = {
|
type IProps = {
|
||||||
exportGameFn: () => void;
|
exportGameFn: () => void;
|
||||||
@ -17,15 +19,31 @@ type IProps = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type IState = {
|
type IState = {
|
||||||
|
rerender: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AugmentationsRoot extends React.Component<IProps, IState> {
|
export class AugmentationsRoot extends React.Component<IProps, IState> {
|
||||||
constructor(props: IProps) {
|
constructor(props: IProps) {
|
||||||
super(props);
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
rerender: false,
|
||||||
|
};
|
||||||
|
this.export = this.export.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
export() {
|
||||||
|
this.props.exportGameFn();
|
||||||
|
this.setState({
|
||||||
|
rerender: !this.state.rerender,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
render(): React.ReactNode {
|
render(): React.ReactNode {
|
||||||
|
function exportBonusStr(): string {
|
||||||
|
if(canGetBonus()) return "(+1 favor to all factions)";
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id="augmentations-content">
|
<div id="augmentations-content">
|
||||||
<h1>Purchased Augmentations</h1>
|
<h1>Purchased Augmentations</h1>
|
||||||
@ -60,8 +78,8 @@ export class AugmentationsRoot extends React.Component<IProps, IState> {
|
|||||||
|
|
||||||
<StdButton
|
<StdButton
|
||||||
addClasses="flashing-button"
|
addClasses="flashing-button"
|
||||||
onClick={this.props.exportGameFn}
|
onClick={this.export}
|
||||||
text="Backup Save (Export)"
|
text={`Backup Save ${exportBonusStr()}`}
|
||||||
tooltip="It's always a good idea to backup/export your save!"
|
tooltip="It's always a good idea to backup/export your save!"
|
||||||
/>
|
/>
|
||||||
<PurchasedAugmentations />
|
<PurchasedAugmentations />
|
||||||
|
19
src/ExportBonus.tsx
Normal file
19
src/ExportBonus.tsx
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { Factions } from "./Faction/Factions";
|
||||||
|
import { IPlayer } from "./PersonObjects/IPlayer";
|
||||||
|
|
||||||
|
export let LastExportBonus: number = 0;
|
||||||
|
|
||||||
|
const bonusTimer = 24*60*60*1000; // 24h
|
||||||
|
export function canGetBonus(): boolean {
|
||||||
|
const now = (new Date()).getTime()
|
||||||
|
if(now - LastExportBonus > bonusTimer) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function onExport(p: IPlayer): void {
|
||||||
|
if(!canGetBonus()) return;
|
||||||
|
for (const facName of p.factions) {
|
||||||
|
Factions[facName].favor++;
|
||||||
|
}
|
||||||
|
LastExportBonus = (new Date()).getTime();
|
||||||
|
}
|
@ -31,6 +31,7 @@ import { loadStockMarket, StockMarket } from "./StockMarket/StockMarket";
|
|||||||
import { createStatusText } from "./ui/createStatusText";
|
import { createStatusText } from "./ui/createStatusText";
|
||||||
|
|
||||||
import { setTimeoutRef } from "./utils/SetTimeoutRef";
|
import { setTimeoutRef } from "./utils/SetTimeoutRef";
|
||||||
|
import { LastExportBonus } from "./ExportBonus";
|
||||||
|
|
||||||
import { dialogBoxCreate } from "../utils/DialogBox";
|
import { dialogBoxCreate } from "../utils/DialogBox";
|
||||||
import { gameOptionsBoxClose } from "../utils/GameOptions";
|
import { gameOptionsBoxClose } from "../utils/GameOptions";
|
||||||
@ -66,6 +67,7 @@ function BitburnerSaveObject() {
|
|||||||
this.FconfSettingsSave = "";
|
this.FconfSettingsSave = "";
|
||||||
this.VersionSave = "";
|
this.VersionSave = "";
|
||||||
this.AllGangsSave = "";
|
this.AllGangsSave = "";
|
||||||
|
this.LastExportBonus = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
BitburnerSaveObject.prototype.getSaveString = function() {
|
BitburnerSaveObject.prototype.getSaveString = function() {
|
||||||
@ -94,6 +96,7 @@ BitburnerSaveObject.prototype.getSaveString = function() {
|
|||||||
this.SettingsSave = JSON.stringify(Settings);
|
this.SettingsSave = JSON.stringify(Settings);
|
||||||
this.FconfSettingsSave = JSON.stringify(FconfSettings);
|
this.FconfSettingsSave = JSON.stringify(FconfSettings);
|
||||||
this.VersionSave = JSON.stringify(CONSTANTS.Version);
|
this.VersionSave = JSON.stringify(CONSTANTS.Version);
|
||||||
|
this.LastExportBonus = JSON.stringify(LastExportBonus);
|
||||||
if (Player.inGang()) {
|
if (Player.inGang()) {
|
||||||
this.AllGangsSave = JSON.stringify(AllGangs);
|
this.AllGangsSave = JSON.stringify(AllGangs);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user