get rid of rollover rep

This commit is contained in:
Olivier Gagnon
2021-11-05 16:09:19 -04:00
parent ec76c2ecca
commit f8917473f8
4 changed files with 20 additions and 35 deletions
+6 -25
View File
@@ -39,12 +39,6 @@ export class Faction {
*/
playerReputation = 0;
/**
* Reputation from the last "prestige" that was not converted to favor.
* This reputation rolls over and is used for the next favor calculation
*/
rolloverRep = 0;
constructor(name = "") {
this.name = name;
}
@@ -64,31 +58,18 @@ export class Faction {
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();
}
//Returns an array with [How much favor would be gained, how much rep would be left over]
getFavorGain(): number[] {
getFavorGain(): number {
if (this.favor == null) {
this.favor = 0;
}
if (this.rolloverRep == null) {
this.rolloverRep = 0;
}
const storedRep = Math.max(0, favorToRep(this.favor - 1));
const totalRep = storedRep + this.rolloverRep + this.playerReputation;
const newFavor = Math.floor(repToFavor(totalRep));
const newRep = favorToRep(newFavor);
return [newFavor - this.favor + 1, totalRep - newRep];
const storedRep = Math.max(0, favorToRep(this.favor));
const totalRep = storedRep + this.playerReputation;
const newFavor = repToFavor(totalRep);
return newFavor - this.favor;
}
/**