mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-24 15:12:27 +01:00
GANG: Fix respectGainRate being stored incorrectly (#565)
This commit is contained in:
parent
dd9849f53d
commit
ec9e7ffa3a
@ -14,7 +14,6 @@ import { getRandomInt } from "../utils/helpers/getRandomInt";
|
|||||||
|
|
||||||
import { GangMemberUpgrade } from "./GangMemberUpgrade";
|
import { GangMemberUpgrade } from "./GangMemberUpgrade";
|
||||||
import { GangConstants } from "./data/Constants";
|
import { GangConstants } from "./data/Constants";
|
||||||
import { CONSTANTS } from "../Constants";
|
|
||||||
import { GangMemberTasks } from "./GangMemberTasks";
|
import { GangMemberTasks } from "./GangMemberTasks";
|
||||||
import { IAscensionResult } from "./IAscensionResult";
|
import { IAscensionResult } from "./IAscensionResult";
|
||||||
|
|
||||||
@ -33,8 +32,11 @@ export class Gang {
|
|||||||
|
|
||||||
isHackingGang: boolean;
|
isHackingGang: boolean;
|
||||||
|
|
||||||
|
/** Respect gain rate, per cycle */
|
||||||
respectGainRate: number;
|
respectGainRate: number;
|
||||||
|
/** Wanted level gain rate, per cycle */
|
||||||
wantedGainRate: number;
|
wantedGainRate: number;
|
||||||
|
/** Money gain rate, per cycle */
|
||||||
moneyGainRate: number;
|
moneyGainRate: number;
|
||||||
|
|
||||||
storedCycles: number;
|
storedCycles: number;
|
||||||
@ -80,19 +82,16 @@ export class Gang {
|
|||||||
return AllGangs[this.facName].territory;
|
return AllGangs[this.facName].territory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Main process function called by the engine loop every game cycle */
|
||||||
process(numCycles = 1): void {
|
process(numCycles = 1): void {
|
||||||
// Run every cycle
|
|
||||||
const CyclesPerSecond = 1000 / CONSTANTS.MilliPerCycle;
|
|
||||||
|
|
||||||
if (isNaN(numCycles)) {
|
if (isNaN(numCycles)) {
|
||||||
console.error(`NaN passed into Gang.process(): ${numCycles}`);
|
console.error(`NaN passed into Gang.process(): ${numCycles}`);
|
||||||
}
|
}
|
||||||
this.storedCycles += numCycles;
|
this.storedCycles += numCycles;
|
||||||
|
if (this.storedCycles < GangConstants.minCyclesToProcess) return;
|
||||||
|
|
||||||
// Only process if there are at least 2 seconds, and at most 5 seconds
|
// Calculate how many cycles to actually process.
|
||||||
// works out as 5 * 5 for 25x per cycle during bonus time
|
const cycles = Math.min(this.storedCycles, GangConstants.maxCyclesToProcess);
|
||||||
if (this.storedCycles < 2 * CyclesPerSecond) return;
|
|
||||||
const cycles = Math.min(this.storedCycles, 5 * CyclesPerSecond);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.processGains(cycles);
|
this.processGains(cycles);
|
||||||
@ -104,50 +103,56 @@ export class Gang {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
processGains(numCycles = 1): void {
|
/** Process respect/wanted/money gains
|
||||||
// Get gains per cycle
|
* @param numCycles The number of cycles to process. */
|
||||||
let moneyGains = 0;
|
processGains(numCycles: number): void {
|
||||||
let respectGains = 0;
|
let moneyGainPerCycle = 0;
|
||||||
let wantedLevelGains = 0;
|
let wantedLevelGainPerCycle = 0;
|
||||||
|
let respectGainsTotal = 0;
|
||||||
|
/** Number of members performing actions that lower wanted level */
|
||||||
let justice = 0;
|
let justice = 0;
|
||||||
for (let i = 0; i < this.members.length; ++i) {
|
|
||||||
respectGains += this.members[i].earnRespect(numCycles, this);
|
for (const member of this.members) {
|
||||||
moneyGains += this.members[i].calculateMoneyGain(this);
|
respectGainsTotal += member.earnRespect(numCycles, this);
|
||||||
const wantedLevelGain = this.members[i].calculateWantedLevelGain(this);
|
moneyGainPerCycle += member.calculateMoneyGain(this);
|
||||||
wantedLevelGains += wantedLevelGain;
|
wantedLevelGainPerCycle += member.calculateWantedLevelGain(this);
|
||||||
if (this.members[i].getTask().baseWanted < 0) justice++; // this member is lowering wanted.
|
if (member.getTask().baseWanted < 0) justice++;
|
||||||
}
|
}
|
||||||
this.respectGainRate = respectGains;
|
|
||||||
this.wantedGainRate = wantedLevelGains;
|
this.respectGainRate = respectGainsTotal / numCycles;
|
||||||
this.moneyGainRate = moneyGains;
|
this.wantedGainRate = wantedLevelGainPerCycle;
|
||||||
const gain = respectGains;
|
this.moneyGainRate = moneyGainPerCycle;
|
||||||
this.respect += gain;
|
this.respect += respectGainsTotal;
|
||||||
|
|
||||||
// Faction reputation gains is respect gain divided by some constant
|
// Faction reputation gains is respect gain divided by some constant
|
||||||
const fac = Factions[this.facName];
|
const gangFaction = Factions[this.facName];
|
||||||
if (!fac) {
|
if (!gangFaction) {
|
||||||
dialogBoxCreate(
|
dialogBoxCreate(
|
||||||
"ERROR: Could not get Faction associates with your gang. This is a bug, please report to game dev",
|
"ERROR: Could not get Faction associates with your gang. This is a bug, please report to game dev",
|
||||||
);
|
);
|
||||||
throw new Error("Could not find the faction associated with this gang.");
|
throw new Error("Could not find the faction associated with this gang.");
|
||||||
}
|
}
|
||||||
const favorMult = 1 + fac.favor / 100;
|
const favorMult = 1 + gangFaction.favor / 100;
|
||||||
|
|
||||||
fac.playerReputation += (Player.mults.faction_rep * gain * favorMult) / GangConstants.GangRespectToReputationRatio;
|
gangFaction.playerReputation +=
|
||||||
|
(Player.mults.faction_rep * respectGainsTotal * favorMult) / GangConstants.GangRespectToReputationRatio;
|
||||||
|
|
||||||
if (!(this.wanted === 1 && wantedLevelGains < 0)) {
|
if (!(this.wanted === 1 && wantedLevelGainPerCycle < 0)) {
|
||||||
const oldWanted = this.wanted;
|
const oldWanted = this.wanted;
|
||||||
let newWanted = oldWanted + wantedLevelGains * numCycles;
|
let newWanted = oldWanted + wantedLevelGainPerCycle * numCycles;
|
||||||
newWanted = newWanted * (1 - justice * 0.001); // safeguard
|
newWanted = newWanted * (1 - justice * 0.001); // safeguard
|
||||||
// Prevent overflow
|
// Prevent overflow
|
||||||
if (wantedLevelGains <= 0 && newWanted > oldWanted) newWanted = 1;
|
if (wantedLevelGainPerCycle <= 0 && newWanted > oldWanted) newWanted = 1;
|
||||||
|
|
||||||
this.wanted = newWanted;
|
this.wanted = newWanted;
|
||||||
if (this.wanted < 1) this.wanted = 1;
|
if (this.wanted < 1) this.wanted = 1;
|
||||||
}
|
}
|
||||||
Player.gainMoney(moneyGains * numCycles, "gang");
|
Player.gainMoney(moneyGainPerCycle * numCycles, "gang");
|
||||||
}
|
}
|
||||||
|
|
||||||
processTerritoryAndPowerGains(numCycles = 1): void {
|
/** Process Territory and Power
|
||||||
|
* @param numCycles The number of cycles to process. */
|
||||||
|
processTerritoryAndPowerGains(numCycles: number): void {
|
||||||
function calculateTerritoryGain(winGang: string, loseGang: string): number {
|
function calculateTerritoryGain(winGang: string, loseGang: string): number {
|
||||||
const powerBonus = Math.max(1, 1 + Math.log(AllGangs[winGang].power / AllGangs[loseGang].power) / Math.log(50));
|
const powerBonus = Math.max(1, 1 + Math.log(AllGangs[winGang].power / AllGangs[loseGang].power) / Math.log(50));
|
||||||
const gains = Math.min(AllGangs[loseGang].territory, powerBonus * 0.0001 * (Math.random() + 0.5));
|
const gains = Math.min(AllGangs[loseGang].territory, powerBonus * 0.0001 * (Math.random() + 0.5));
|
||||||
@ -250,10 +255,12 @@ export class Gang {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
processExperienceGains(numCycles = 1): void {
|
/** Process member experience gain
|
||||||
for (let i = 0; i < this.members.length; ++i) {
|
* @param numCycles The number of cycles to process. */
|
||||||
this.members[i].gainExperience(numCycles);
|
processExperienceGains(numCycles: number): void {
|
||||||
this.members[i].updateSkillLevels();
|
for (const member of this.members) {
|
||||||
|
member.gainExperience(numCycles);
|
||||||
|
member.updateSkillLevels();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { CONSTANTS } from "../../Constants";
|
||||||
import { FactionNames } from "../../Faction/data/FactionNames";
|
import { FactionNames } from "../../Faction/data/FactionNames";
|
||||||
|
|
||||||
export const GangConstants = {
|
export const GangConstants = {
|
||||||
@ -18,4 +19,8 @@ export const GangConstants = {
|
|||||||
FactionNames.TheBlackHand,
|
FactionNames.TheBlackHand,
|
||||||
] as string[],
|
] as string[],
|
||||||
GangKarmaRequirement: -54000,
|
GangKarmaRequirement: -54000,
|
||||||
|
/** Normal number of game cycles processed at once (2 seconds) */
|
||||||
|
minCyclesToProcess: 2000 / CONSTANTS.MilliPerCycle,
|
||||||
|
/** Maximum number of cycles to process at once during bonus time (5 seconds) */
|
||||||
|
maxCyclesToProcess: 5000 / CONSTANTS.MilliPerCycle,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user