From 0f2b7517b43fb2ab4c76eedcac9bef694540869d Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Mon, 10 May 2021 18:26:50 -0400 Subject: [PATCH] Added export bonus --- src/Augmentation/AugmentationHelpers.jsx | 8 +++++++- src/Augmentation/ui/Root.tsx | 24 +++++++++++++++++++++--- src/ExportBonus.tsx | 19 +++++++++++++++++++ src/SaveObject.jsx | 3 +++ 4 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 src/ExportBonus.tsx diff --git a/src/Augmentation/AugmentationHelpers.jsx b/src/Augmentation/AugmentationHelpers.jsx index 30cf40e00..21268f8e1 100644 --- a/src/Augmentation/AugmentationHelpers.jsx +++ b/src/Augmentation/AugmentationHelpers.jsx @@ -12,6 +12,7 @@ import { Player } from "../Player"; import { prestigeAugmentation } from "../Prestige"; import { saveObject } from "../SaveObject"; import { Page, routing } from "../ui/navigationTracking"; +import { onExport } from "../ExportBonus"; import { dialogBoxCreate } from "../../utils/DialogBox"; import { clearObject } from "../../utils/helpers/clearObject"; @@ -2077,9 +2078,14 @@ export function displayAugmentationsContent(contentEl) { if (!routing.isOn(Page.Augmentations)) { return; } if (!(contentEl instanceof HTMLElement)) { return; } + function backup() { + saveObject.exportGame(); + onExport(Player); + } + ReactDOM.render( , contentEl, diff --git a/src/Augmentation/ui/Root.tsx b/src/Augmentation/ui/Root.tsx index d9350836c..f5315ed24 100644 --- a/src/Augmentation/ui/Root.tsx +++ b/src/Augmentation/ui/Root.tsx @@ -10,6 +10,8 @@ import { PurchasedAugmentations } from "./PurchasedAugmentations"; import { Player } from "../../Player"; import { StdButton } from "../../ui/React/StdButton"; +import { LastExportBonus, canGetBonus } from "../../ExportBonus"; +import { convertTimeMsToTimeElapsedString } from "../../../utils/StringHelperFunctions"; type IProps = { exportGameFn: () => void; @@ -17,15 +19,31 @@ type IProps = { } type IState = { - + rerender: boolean; } export class AugmentationsRoot extends React.Component { constructor(props: IProps) { 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 { + function exportBonusStr(): string { + if(canGetBonus()) return "(+1 favor to all factions)"; + return ""; + } + return (

Purchased Augmentations

@@ -60,8 +78,8 @@ export class AugmentationsRoot extends React.Component { diff --git a/src/ExportBonus.tsx b/src/ExportBonus.tsx new file mode 100644 index 000000000..ed33b6d24 --- /dev/null +++ b/src/ExportBonus.tsx @@ -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(); +} \ No newline at end of file diff --git a/src/SaveObject.jsx b/src/SaveObject.jsx index 5ffbb156d..884d47d02 100755 --- a/src/SaveObject.jsx +++ b/src/SaveObject.jsx @@ -31,6 +31,7 @@ import { loadStockMarket, StockMarket } from "./StockMarket/StockMarket"; import { createStatusText } from "./ui/createStatusText"; import { setTimeoutRef } from "./utils/SetTimeoutRef"; +import { LastExportBonus } from "./ExportBonus"; import { dialogBoxCreate } from "../utils/DialogBox"; import { gameOptionsBoxClose } from "../utils/GameOptions"; @@ -66,6 +67,7 @@ function BitburnerSaveObject() { this.FconfSettingsSave = ""; this.VersionSave = ""; this.AllGangsSave = ""; + this.LastExportBonus = ""; } BitburnerSaveObject.prototype.getSaveString = function() { @@ -94,6 +96,7 @@ BitburnerSaveObject.prototype.getSaveString = function() { this.SettingsSave = JSON.stringify(Settings); this.FconfSettingsSave = JSON.stringify(FconfSettings); this.VersionSave = JSON.stringify(CONSTANTS.Version); + this.LastExportBonus = JSON.stringify(LastExportBonus); if (Player.inGang()) { this.AllGangsSave = JSON.stringify(AllGangs); }