From 385a9dc11d5ac3916eb470aab096e8ef8f5467ad Mon Sep 17 00:00:00 2001 From: Nicole Date: Fri, 16 Aug 2024 18:28:43 -0500 Subject: [PATCH] BUGFIX: Fix Bladeburner city chaos reaching Infinity/NaN (#1588) --- src/Bladeburner/Bladeburner.ts | 23 ++++++++++------------- src/DevMenu/ui/BladeburnerDev.tsx | 4 ++-- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/Bladeburner/Bladeburner.ts b/src/Bladeburner/Bladeburner.ts index 7ddd73f68..6ce16ac8f 100644 --- a/src/Bladeburner/Bladeburner.ts +++ b/src/Bladeburner/Bladeburner.ts @@ -645,8 +645,8 @@ export class Bladeburner { } } else if (chance <= 0.7) { // Synthoid Riots (+chaos), 20% - sourceCity.chaos += 1; - sourceCity.chaos *= 1 + getRandomIntInclusive(5, 20) / 100; + sourceCity.changeChaosByCount(1); + sourceCity.changeChaosByPercentage(getRandomIntInclusive(5, 20)); if (this.logging.events) { this.log("Tensions between Synthoids and humans lead to riots in " + sourceCityName + "! Chaos increased"); } @@ -700,14 +700,14 @@ export class Bladeburner { }; } - getDiplomacyEffectiveness(person: Person): number { - // Returns a decimal by which the city's chaos level should be multiplied (e.g. 0.98) + getDiplomacyPercentage(person: Person): number { + // Returns a percentage by which the city's chaos level should be modified (e.g. 2 for 2%) const CharismaLinearFactor = 1e3; const CharismaExponentialFactor = 0.045; const charismaEff = Math.pow(person.skills.charisma, CharismaExponentialFactor) + person.skills.charisma / CharismaLinearFactor; - return (100 - charismaEff) / 100; + return charismaEff; } getRecruitmentSuccessChance(person: Person): number { @@ -1155,15 +1155,12 @@ export class Bladeburner { break; } case BladeGeneralActionName.diplomacy: { - const eff = this.getDiplomacyEffectiveness(person); - this.getCurrentCity().chaos *= eff; - if (this.getCurrentCity().chaos < 0) { - this.getCurrentCity().chaos = 0; - } + const diplomacyPct = this.getDiplomacyPercentage(person); + this.getCurrentCity().changeChaosByPercentage(-diplomacyPct); if (this.logging.general) { this.log( `${person.whoAmI()}: Diplomacy completed. Chaos levels in the current city fell by ${formatPercent( - 1 - eff, + diplomacyPct / 100, )}.`, ); } @@ -1203,8 +1200,8 @@ export class Bladeburner { } for (const cityName of Object.values(CityName)) { const city = this.cities[cityName]; - city.chaos += 10; - city.chaos += city.chaos / (Math.log(city.chaos) / Math.log(10)); + city.changeChaosByCount(10); + city.changeChaosByCount(city.chaos / Math.log10(city.chaos)); } break; } diff --git a/src/DevMenu/ui/BladeburnerDev.tsx b/src/DevMenu/ui/BladeburnerDev.tsx index 7a6cde535..1d5e0264e 100644 --- a/src/DevMenu/ui/BladeburnerDev.tsx +++ b/src/DevMenu/ui/BladeburnerDev.tsx @@ -50,10 +50,10 @@ export function BladeburnerDev({ bladeburner }: { bladeburner: Bladeburner }): R const wipeAllChaos = () => Object.values(CityName).forEach((city) => (bladeburner.cities[city].chaos = 0)); const wipeActiveCityChaos = () => (bladeburner.cities[bladeburner.city].chaos = 0); const addAllChaos = (modify: number) => (chaos: number) => { - Object.values(CityName).forEach((city) => (bladeburner.cities[city].chaos += chaos * modify)); + Object.values(CityName).forEach((city) => bladeburner.cities[city].changeChaosByCount(chaos * modify)); }; const addTonsAllChaos = () => { - Object.values(CityName).forEach((city) => (bladeburner.cities[city].chaos += bigNumber)); + Object.values(CityName).forEach((city) => bladeburner.cities[city].changeChaosByCount(bigNumber)); }; // Skill functions