From b731b9946e4f34512949cec490a40023aadf7b77 Mon Sep 17 00:00:00 2001 From: nickofolas Date: Mon, 10 Jan 2022 14:08:17 -0600 Subject: [PATCH 1/3] Update Company favor gaining --- src/Company/Company.ts | 36 ++++++---------------------- src/Company/formulas/favor.ts | 14 +++++++++++ src/Locations/ui/CompanyLocation.tsx | 2 +- 3 files changed, 22 insertions(+), 30 deletions(-) create mode 100644 src/Company/formulas/favor.ts diff --git a/src/Company/Company.ts b/src/Company/Company.ts index 3a1e65c2a..d6b51a9c0 100644 --- a/src/Company/Company.ts +++ b/src/Company/Company.ts @@ -1,7 +1,7 @@ import { CompanyPosition } from "./CompanyPosition"; import * as posNames from "./data/companypositionnames"; +import { favorToRep, repToFavor } from "./formulas/favor"; -import { CONSTANTS } from "../Constants"; import { IMap } from "../types"; import { Generic_fromJSON, Generic_toJSON, Reviver } from "../utils/JSONReviver"; @@ -137,39 +137,17 @@ export class Company { if (this.favor == null) { this.favor = 0; } - if (this.rolloverRep == null) { - this.rolloverRep = 0; - } - const res = this.getFavorGain(); - if (res.length != 2) { - console.error("Invalid result from getFavorGain() function"); - return; - } - - this.favor += res[0]; - this.rolloverRep = res[1]; + this.favor += this.getFavorGain(); } - getFavorGain(): number[] { + getFavorGain(): number { if (this.favor == null) { this.favor = 0; } - if (this.rolloverRep == null) { - this.rolloverRep = 0; - } - let favorGain = 0, - rep = this.playerReputation + this.rolloverRep; - let reqdRep = CONSTANTS.CompanyReputationToFavorBase * Math.pow(CONSTANTS.CompanyReputationToFavorMult, this.favor); - while (rep > 0) { - if (rep >= reqdRep) { - ++favorGain; - rep -= reqdRep; - } else { - break; - } - reqdRep *= CONSTANTS.FactionReputationToFavorMult; - } - return [favorGain, rep]; + const storedRep = Math.max(0, favorToRep(this.favor)); + const totalRep = storedRep + this.playerReputation; + const newFavor = repToFavor(totalRep); + return newFavor - this.favor; } /** diff --git a/src/Company/formulas/favor.ts b/src/Company/formulas/favor.ts new file mode 100644 index 000000000..09edd1ca5 --- /dev/null +++ b/src/Company/formulas/favor.ts @@ -0,0 +1,14 @@ +// The initial formulas was sum 0 to f of 500*1.02^f. +// see https://en.wikipedia.org/wiki/Geometric_series#Closed-form_formula +// for information on how to calculate this + +export function favorToRep(f: number): number { + const raw = 25000 * (Math.pow(1.02, f) - 1); + return Math.round(raw * 10000) / 10000; // round to make things easier. + } + + export function repToFavor(r: number): number { + const raw = Math.log(r / 25000 + 1) / Math.log(1.02); + return Math.round(raw * 10000) / 10000; // round to make things easier. + } + \ No newline at end of file diff --git a/src/Locations/ui/CompanyLocation.tsx b/src/Locations/ui/CompanyLocation.tsx index 04fee9754..d38c04e71 100644 --- a/src/Locations/ui/CompanyLocation.tsx +++ b/src/Locations/ui/CompanyLocation.tsx @@ -198,7 +198,7 @@ export function CompanyLocation(props: IProps): React.ReactElement { - You will have company favor upon resetting after + You will have company favor upon resetting after installing Augmentations } From 30f6d157d9698a59d705c8a4644cde4c3d7aae40 Mon Sep 17 00:00:00 2001 From: nickofolas Date: Mon, 10 Jan 2022 14:15:32 -0600 Subject: [PATCH 2/3] Fix indentation --- src/Company/formulas/favor.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Company/formulas/favor.ts b/src/Company/formulas/favor.ts index 09edd1ca5..73790544b 100644 --- a/src/Company/formulas/favor.ts +++ b/src/Company/formulas/favor.ts @@ -3,12 +3,11 @@ // for information on how to calculate this export function favorToRep(f: number): number { - const raw = 25000 * (Math.pow(1.02, f) - 1); - return Math.round(raw * 10000) / 10000; // round to make things easier. - } - - export function repToFavor(r: number): number { - const raw = Math.log(r / 25000 + 1) / Math.log(1.02); - return Math.round(raw * 10000) / 10000; // round to make things easier. - } - \ No newline at end of file + const raw = 25000 * (Math.pow(1.02, f) - 1); + return Math.round(raw * 10000) / 10000; // round to make things easier. +} + +export function repToFavor(r: number): number { + const raw = Math.log(r / 25000 + 1) / Math.log(1.02); + return Math.round(raw * 10000) / 10000; // round to make things easier. +} From 4e94b3db4ef0e67f00d1d79604b41f379e0340c6 Mon Sep 17 00:00:00 2001 From: nickofolas Date: Mon, 10 Jan 2022 14:19:25 -0600 Subject: [PATCH 3/3] Remove unneeded rolloverRep attribute --- src/Company/Company.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Company/Company.ts b/src/Company/Company.ts index d6b51a9c0..43f6fa855 100644 --- a/src/Company/Company.ts +++ b/src/Company/Company.ts @@ -71,7 +71,6 @@ export class Company { isPlayerEmployed: boolean; playerReputation: number; favor: number; - rolloverRep: number; constructor(p: IConstructorParams = DefaultConstructorParams) { this.name = p.name; @@ -84,7 +83,6 @@ export class Company { this.isPlayerEmployed = false; this.playerReputation = 1; this.favor = 0; - this.rolloverRep = 0; this.isMegacorp = false; if (p.isMegacorp) this.isMegacorp = true; }