Skip to content

Commit

Permalink
BUGFIX: Fix Bladeburner city chaos reaching Infinity/NaN (bitburner-o…
Browse files Browse the repository at this point in the history
  • Loading branch information
Faenre committed Aug 22, 2024
1 parent 5edc408 commit c759dcf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
23 changes: 10 additions & 13 deletions src/Bladeburner/Bladeburner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
)}.`,
);
}
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/DevMenu/ui/BladeburnerDev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c759dcf

Please sign in to comment.