BUGFIX: Fix Bladeburner city chaos reaching Infinity/NaN (#1588)

This commit is contained in:
Nicole 2024-08-16 18:28:43 -05:00 committed by GitHub
parent 79bb0d289a
commit 385a9dc11d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 15 deletions

@ -645,8 +645,8 @@ export class Bladeburner {
} }
} else if (chance <= 0.7) { } else if (chance <= 0.7) {
// Synthoid Riots (+chaos), 20% // Synthoid Riots (+chaos), 20%
sourceCity.chaos += 1; sourceCity.changeChaosByCount(1);
sourceCity.chaos *= 1 + getRandomIntInclusive(5, 20) / 100; sourceCity.changeChaosByPercentage(getRandomIntInclusive(5, 20));
if (this.logging.events) { if (this.logging.events) {
this.log("Tensions between Synthoids and humans lead to riots in " + sourceCityName + "! Chaos increased"); 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 { getDiplomacyPercentage(person: Person): number {
// Returns a decimal by which the city's chaos level should be multiplied (e.g. 0.98) // Returns a percentage by which the city's chaos level should be modified (e.g. 2 for 2%)
const CharismaLinearFactor = 1e3; const CharismaLinearFactor = 1e3;
const CharismaExponentialFactor = 0.045; const CharismaExponentialFactor = 0.045;
const charismaEff = const charismaEff =
Math.pow(person.skills.charisma, CharismaExponentialFactor) + person.skills.charisma / CharismaLinearFactor; Math.pow(person.skills.charisma, CharismaExponentialFactor) + person.skills.charisma / CharismaLinearFactor;
return (100 - charismaEff) / 100; return charismaEff;
} }
getRecruitmentSuccessChance(person: Person): number { getRecruitmentSuccessChance(person: Person): number {
@ -1155,15 +1155,12 @@ export class Bladeburner {
break; break;
} }
case BladeGeneralActionName.diplomacy: { case BladeGeneralActionName.diplomacy: {
const eff = this.getDiplomacyEffectiveness(person); const diplomacyPct = this.getDiplomacyPercentage(person);
this.getCurrentCity().chaos *= eff; this.getCurrentCity().changeChaosByPercentage(-diplomacyPct);
if (this.getCurrentCity().chaos < 0) {
this.getCurrentCity().chaos = 0;
}
if (this.logging.general) { if (this.logging.general) {
this.log( this.log(
`${person.whoAmI()}: Diplomacy completed. Chaos levels in the current city fell by ${formatPercent( `${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)) { for (const cityName of Object.values(CityName)) {
const city = this.cities[cityName]; const city = this.cities[cityName];
city.chaos += 10; city.changeChaosByCount(10);
city.chaos += city.chaos / (Math.log(city.chaos) / Math.log(10)); city.changeChaosByCount(city.chaos / Math.log10(city.chaos));
} }
break; break;
} }

@ -50,10 +50,10 @@ export function BladeburnerDev({ bladeburner }: { bladeburner: Bladeburner }): R
const wipeAllChaos = () => Object.values(CityName).forEach((city) => (bladeburner.cities[city].chaos = 0)); const wipeAllChaos = () => Object.values(CityName).forEach((city) => (bladeburner.cities[city].chaos = 0));
const wipeActiveCityChaos = () => (bladeburner.cities[bladeburner.city].chaos = 0); const wipeActiveCityChaos = () => (bladeburner.cities[bladeburner.city].chaos = 0);
const addAllChaos = (modify: number) => (chaos: number) => { 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 = () => { const addTonsAllChaos = () => {
Object.values(CityName).forEach((city) => (bladeburner.cities[city].chaos += bigNumber)); Object.values(CityName).forEach((city) => bladeburner.cities[city].changeChaosByCount(bigNumber));
}; };
// Skill functions // Skill functions