Update Company favor gaining

This commit is contained in:
nickofolas 2022-01-10 14:08:17 -06:00
parent f742782e4a
commit b731b9946e
3 changed files with 22 additions and 30 deletions

@ -1,7 +1,7 @@
import { CompanyPosition } from "./CompanyPosition"; import { CompanyPosition } from "./CompanyPosition";
import * as posNames from "./data/companypositionnames"; import * as posNames from "./data/companypositionnames";
import { favorToRep, repToFavor } from "./formulas/favor";
import { CONSTANTS } from "../Constants";
import { IMap } from "../types"; import { IMap } from "../types";
import { Generic_fromJSON, Generic_toJSON, Reviver } from "../utils/JSONReviver"; import { Generic_fromJSON, Generic_toJSON, Reviver } from "../utils/JSONReviver";
@ -137,39 +137,17 @@ export class Company {
if (this.favor == null) { if (this.favor == null) {
this.favor = 0; this.favor = 0;
} }
if (this.rolloverRep == null) { this.favor += this.getFavorGain();
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];
} }
getFavorGain(): number[] { getFavorGain(): number {
if (this.favor == null) { if (this.favor == null) {
this.favor = 0; this.favor = 0;
} }
if (this.rolloverRep == null) { const storedRep = Math.max(0, favorToRep(this.favor));
this.rolloverRep = 0; const totalRep = storedRep + this.playerReputation;
} const newFavor = repToFavor(totalRep);
let favorGain = 0, return newFavor - this.favor;
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];
} }
/** /**

@ -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.
}

@ -198,7 +198,7 @@ export function CompanyLocation(props: IProps): React.ReactElement {
<Tooltip <Tooltip
title={ title={
<> <>
You will have <Favor favor={company.favor + favorGain[0]} /> company favor upon resetting after You will have <Favor favor={company.favor + favorGain} /> company favor upon resetting after
installing Augmentations installing Augmentations
</> </>
} }