mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-21 23:23:51 +01:00
MISC: Refactor favor code (#1321)
This commit is contained in:
parent
b8d3109158
commit
c2a56a6150
@ -6,6 +6,7 @@ import { assertLoadingType } from "../utils/TypeAssertion";
|
|||||||
import { CompanyName } from "./Enums";
|
import { CompanyName } from "./Enums";
|
||||||
import { PartialRecord, createEnumKeyedRecord } from "../Types/Record";
|
import { PartialRecord, createEnumKeyedRecord } from "../Types/Record";
|
||||||
import { getEnumHelper } from "../utils/EnumHelper";
|
import { getEnumHelper } from "../utils/EnumHelper";
|
||||||
|
import { clampNumber } from "../utils/helpers/clampNumber";
|
||||||
|
|
||||||
export const Companies: Record<CompanyName, Company> = (() => {
|
export const Companies: Record<CompanyName, Company> = (() => {
|
||||||
const metadata = getCompaniesMetadata();
|
const metadata = getCompaniesMetadata();
|
||||||
@ -27,8 +28,14 @@ export function loadCompanies(saveString: string): void {
|
|||||||
const company = Companies[loadedCompanyName];
|
const company = Companies[loadedCompanyName];
|
||||||
assertLoadingType<SavegameCompany>(loadedCompany);
|
assertLoadingType<SavegameCompany>(loadedCompany);
|
||||||
const { playerReputation: loadedRep, favor: loadedFavor } = loadedCompany;
|
const { playerReputation: loadedRep, favor: loadedFavor } = loadedCompany;
|
||||||
if (typeof loadedRep === "number" && loadedRep > 0) company.playerReputation = loadedRep;
|
if (typeof loadedRep === "number" && loadedRep >= 0) {
|
||||||
if (typeof loadedFavor === "number" && loadedFavor > 0) company.favor = loadedFavor;
|
// `playerReputation` must be in [0, Number.MAX_VALUE].
|
||||||
|
company.playerReputation = clampNumber(loadedRep, 0);
|
||||||
|
}
|
||||||
|
if (typeof loadedFavor === "number" && loadedFavor >= 0) {
|
||||||
|
// `favor` must be in [0, MaxFavor]. This rule will be enforced in the `setFavor` function.
|
||||||
|
company.setFavor(loadedFavor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import type { CompanyPosition } from "./CompanyPosition";
|
import type { CompanyPosition } from "./CompanyPosition";
|
||||||
|
|
||||||
import { CompanyName, JobName, FactionName } from "@enums";
|
import { CompanyName, JobName, FactionName } from "@enums";
|
||||||
import { favorToRep, repToFavor } from "../Faction/formulas/favor";
|
import { MaxFavor, calculateFavorAfterResetting } from "../Faction/formulas/favor";
|
||||||
|
import { clampNumber } from "../utils/helpers/clampNumber";
|
||||||
|
|
||||||
export interface CompanyCtorParams {
|
export interface CompanyCtorParams {
|
||||||
name: CompanyName;
|
name: CompanyName;
|
||||||
@ -37,7 +38,8 @@ export class Company {
|
|||||||
|
|
||||||
// Dynamic info, loaded from save and updated during game.
|
// Dynamic info, loaded from save and updated during game.
|
||||||
playerReputation = 0;
|
playerReputation = 0;
|
||||||
favor = 0;
|
|
||||||
|
#favor = 0;
|
||||||
|
|
||||||
constructor(p: CompanyCtorParams) {
|
constructor(p: CompanyCtorParams) {
|
||||||
this.name = p.name;
|
this.name = p.name;
|
||||||
@ -49,26 +51,36 @@ export class Company {
|
|||||||
if (p.relatedFaction) this.relatedFaction = p.relatedFaction;
|
if (p.relatedFaction) this.relatedFaction = p.relatedFaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get favor() {
|
||||||
|
return this.#favor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* There is no setter for this.#favor. This is intentional. Performing arithmetic operations on `favor` may lead to
|
||||||
|
* the overflow error of `playerReputation`, so anything that wants to change `favor` must explicitly do that through
|
||||||
|
* `setFavor`.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
setFavor(value: number) {
|
||||||
|
if (Number.isNaN(value)) {
|
||||||
|
this.#favor = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.#favor = clampNumber(value, 0, MaxFavor);
|
||||||
|
}
|
||||||
|
|
||||||
hasPosition(pos: CompanyPosition | JobName): boolean {
|
hasPosition(pos: CompanyPosition | JobName): boolean {
|
||||||
return this.companyPositions.has(typeof pos === "string" ? pos : pos.name);
|
return this.companyPositions.has(typeof pos === "string" ? pos : pos.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
prestigeAugmentation(): void {
|
prestigeAugmentation(): void {
|
||||||
if (this.favor == null) this.favor = 0;
|
this.setFavor(calculateFavorAfterResetting(this.favor, this.playerReputation));
|
||||||
this.favor += this.getFavorGain();
|
|
||||||
this.playerReputation = 0;
|
this.playerReputation = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
prestigeSourceFile() {
|
prestigeSourceFile() {
|
||||||
this.favor = 0;
|
this.setFavor(0);
|
||||||
this.playerReputation = 0;
|
this.playerReputation = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
getFavorGain(): number {
|
|
||||||
if (this.favor == null) this.favor = 0;
|
|
||||||
const storedRep = Math.max(0, favorToRep(this.favor));
|
|
||||||
const totalRep = storedRep + this.playerReputation;
|
|
||||||
const newFavor = repToFavor(totalRep);
|
|
||||||
return newFavor - this.favor;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,9 @@ import { Companies } from "../../Company/Companies";
|
|||||||
import { Adjuster } from "./Adjuster";
|
import { Adjuster } from "./Adjuster";
|
||||||
import { isMember } from "../../utils/EnumHelper";
|
import { isMember } from "../../utils/EnumHelper";
|
||||||
import { getRecordValues } from "../../Types/Record";
|
import { getRecordValues } from "../../Types/Record";
|
||||||
|
import { MaxFavor } from "../../Faction/formulas/favor";
|
||||||
|
|
||||||
const bigNumber = 1e12;
|
const largeAmountOfReputation = 1e12;
|
||||||
|
|
||||||
export function CompaniesDev(): React.ReactElement {
|
export function CompaniesDev(): React.ReactElement {
|
||||||
const [companyName, setCompanyName] = useState(CompanyName.ECorp);
|
const [companyName, setCompanyName] = useState(CompanyName.ECorp);
|
||||||
@ -40,18 +41,18 @@ export function CompaniesDev(): React.ReactElement {
|
|||||||
return function (favor: number): void {
|
return function (favor: number): void {
|
||||||
const company = Companies[companyName];
|
const company = Companies[companyName];
|
||||||
if (!isNaN(favor)) {
|
if (!isNaN(favor)) {
|
||||||
company.favor += favor * modifier;
|
company.setFavor(company.favor + favor * modifier);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetCompanyFavor(): void {
|
function resetCompanyFavor(): void {
|
||||||
Companies[companyName].favor = 0;
|
Companies[companyName].setFavor(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function tonsOfRepCompanies(): void {
|
function tonsOfRepCompanies(): void {
|
||||||
for (const company of getRecordValues(Companies)) {
|
for (const company of getRecordValues(Companies)) {
|
||||||
company.playerReputation = bigNumber;
|
company.playerReputation = largeAmountOfReputation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,13 +64,13 @@ export function CompaniesDev(): React.ReactElement {
|
|||||||
|
|
||||||
function tonsOfFavorCompanies(): void {
|
function tonsOfFavorCompanies(): void {
|
||||||
for (const company of getRecordValues(Companies)) {
|
for (const company of getRecordValues(Companies)) {
|
||||||
company.favor = bigNumber;
|
company.setFavor(MaxFavor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetAllFavorCompanies(): void {
|
function resetAllFavorCompanies(): void {
|
||||||
for (const company of getRecordValues(Companies)) {
|
for (const company of getRecordValues(Companies)) {
|
||||||
company.favor = 0;
|
company.setFavor(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +104,7 @@ export function CompaniesDev(): React.ReactElement {
|
|||||||
<Adjuster
|
<Adjuster
|
||||||
label="reputation"
|
label="reputation"
|
||||||
placeholder="amt"
|
placeholder="amt"
|
||||||
tons={() => modifyCompanyRep(1)(bigNumber)}
|
tons={() => modifyCompanyRep(1)(largeAmountOfReputation)}
|
||||||
add={modifyCompanyRep(1)}
|
add={modifyCompanyRep(1)}
|
||||||
subtract={modifyCompanyRep(-1)}
|
subtract={modifyCompanyRep(-1)}
|
||||||
reset={resetCompanyRep}
|
reset={resetCompanyRep}
|
||||||
|
@ -29,8 +29,9 @@ import { Factions } from "../../Faction/Factions";
|
|||||||
import { getRecordValues } from "../../Types/Record";
|
import { getRecordValues } from "../../Types/Record";
|
||||||
import { getEnumHelper } from "../../utils/EnumHelper";
|
import { getEnumHelper } from "../../utils/EnumHelper";
|
||||||
import { useRerender } from "../../ui/React/hooks";
|
import { useRerender } from "../../ui/React/hooks";
|
||||||
|
import { MaxFavor } from "../../Faction/formulas/favor";
|
||||||
|
|
||||||
const bigNumber = 1e12;
|
const largeAmountOfReputation = 1e12;
|
||||||
|
|
||||||
export function FactionsDev(): React.ReactElement {
|
export function FactionsDev(): React.ReactElement {
|
||||||
const [selectedFaction, setSelectedFaction] = useState(Factions[FactionName.Illuminati]);
|
const [selectedFaction, setSelectedFaction] = useState(Factions[FactionName.Illuminati]);
|
||||||
@ -73,7 +74,9 @@ export function FactionsDev(): React.ReactElement {
|
|||||||
|
|
||||||
function modifyFactionRep(modifier: number): (x: number) => void {
|
function modifyFactionRep(modifier: number): (x: number) => void {
|
||||||
return function (reputation: number): void {
|
return function (reputation: number): void {
|
||||||
if (!isNaN(reputation)) selectedFaction.playerReputation += reputation * modifier;
|
if (!isNaN(reputation)) {
|
||||||
|
selectedFaction.playerReputation += reputation * modifier;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,17 +86,19 @@ export function FactionsDev(): React.ReactElement {
|
|||||||
|
|
||||||
function modifyFactionFavor(modifier: number): (x: number) => void {
|
function modifyFactionFavor(modifier: number): (x: number) => void {
|
||||||
return function (favor: number): void {
|
return function (favor: number): void {
|
||||||
if (!isNaN(favor)) selectedFaction.favor += favor * modifier;
|
if (!isNaN(favor)) {
|
||||||
|
selectedFaction.setFavor(selectedFaction.favor + favor * modifier);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetFactionFavor(): void {
|
function resetFactionFavor(): void {
|
||||||
selectedFaction.favor = 0;
|
selectedFaction.setFavor(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function tonsOfRep(): void {
|
function tonsOfRep(): void {
|
||||||
for (const faction of getRecordValues(Factions)) {
|
for (const faction of getRecordValues(Factions)) {
|
||||||
faction.playerReputation = bigNumber;
|
faction.playerReputation = largeAmountOfReputation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,17 +110,17 @@ export function FactionsDev(): React.ReactElement {
|
|||||||
|
|
||||||
function tonsOfFactionFavor(): void {
|
function tonsOfFactionFavor(): void {
|
||||||
for (const faction of getRecordValues(Factions)) {
|
for (const faction of getRecordValues(Factions)) {
|
||||||
faction.favor = bigNumber;
|
faction.setFavor(MaxFavor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetAllFactionFavor(): void {
|
function resetAllFactionFavor(): void {
|
||||||
for (const faction of getRecordValues(Factions)) {
|
for (const faction of getRecordValues(Factions)) {
|
||||||
faction.favor = 0;
|
faction.setFavor(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setDiscovery(event: React.ChangeEvent<HTMLInputElement>, value: string): void {
|
function setDiscovery(_: React.ChangeEvent<HTMLInputElement>, value: string): void {
|
||||||
if (!getEnumHelper("FactionDiscovery").isMember(value)) return;
|
if (!getEnumHelper("FactionDiscovery").isMember(value)) return;
|
||||||
selectedFaction.discovery = value;
|
selectedFaction.discovery = value;
|
||||||
rerender();
|
rerender();
|
||||||
@ -187,7 +192,7 @@ export function FactionsDev(): React.ReactElement {
|
|||||||
<Adjuster
|
<Adjuster
|
||||||
label="reputation"
|
label="reputation"
|
||||||
placeholder="amt"
|
placeholder="amt"
|
||||||
tons={() => modifyFactionRep(1)(bigNumber)}
|
tons={() => modifyFactionRep(1)(largeAmountOfReputation)}
|
||||||
add={modifyFactionRep(1)}
|
add={modifyFactionRep(1)}
|
||||||
subtract={modifyFactionRep(-1)}
|
subtract={modifyFactionRep(-1)}
|
||||||
reset={resetFactionRep}
|
reset={resetFactionRep}
|
||||||
@ -202,7 +207,7 @@ export function FactionsDev(): React.ReactElement {
|
|||||||
<Adjuster
|
<Adjuster
|
||||||
label="favor"
|
label="favor"
|
||||||
placeholder="amt"
|
placeholder="amt"
|
||||||
tons={() => modifyFactionFavor(1)(2000)}
|
tons={() => modifyFactionFavor(1)(MaxFavor)}
|
||||||
add={modifyFactionFavor(1)}
|
add={modifyFactionFavor(1)}
|
||||||
subtract={modifyFactionFavor(-1)}
|
subtract={modifyFactionFavor(-1)}
|
||||||
reset={resetFactionFavor}
|
reset={resetFactionFavor}
|
||||||
|
@ -12,7 +12,7 @@ export function canGetBonus(): boolean {
|
|||||||
export function onExport(): void {
|
export function onExport(): void {
|
||||||
if (!canGetBonus()) return;
|
if (!canGetBonus()) return;
|
||||||
for (const facName of Player.factions) {
|
for (const facName of Player.factions) {
|
||||||
Factions[facName].favor++;
|
Factions[facName].setFavor(Factions[facName].favor + 1);
|
||||||
}
|
}
|
||||||
LastExportBonus = new Date().getTime();
|
LastExportBonus = new Date().getTime();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { AugmentationName, FactionName, FactionDiscovery } from "@enums";
|
import { AugmentationName, FactionName, FactionDiscovery } from "@enums";
|
||||||
import { FactionInfo, FactionInfos } from "./FactionInfo";
|
import { FactionInfo, FactionInfos } from "./FactionInfo";
|
||||||
import { favorToRep, repToFavor } from "./formulas/favor";
|
import { MaxFavor, calculateFavorAfterResetting } from "./formulas/favor";
|
||||||
|
import { clampNumber } from "../utils/helpers/clampNumber";
|
||||||
|
|
||||||
export class Faction {
|
export class Faction {
|
||||||
/**
|
/**
|
||||||
@ -13,7 +14,7 @@ export class Faction {
|
|||||||
augmentations: AugmentationName[] = [];
|
augmentations: AugmentationName[] = [];
|
||||||
|
|
||||||
/** Amount of favor the player has with this faction. */
|
/** Amount of favor the player has with this faction. */
|
||||||
favor = 0;
|
#favor = 0;
|
||||||
|
|
||||||
/** Flag signalling whether player has been banned from this faction */
|
/** Flag signalling whether player has been banned from this faction */
|
||||||
isBanned = false;
|
isBanned = false;
|
||||||
@ -34,6 +35,25 @@ export class Faction {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get favor() {
|
||||||
|
return this.#favor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* There is no setter for this.#favor. This is intentional. Performing arithmetic operations on `favor` may lead to
|
||||||
|
* the overflow error of `playerReputation`, so anything that wants to change `favor` must explicitly do that through
|
||||||
|
* `setFavor`.
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
setFavor(value: number) {
|
||||||
|
if (Number.isNaN(value)) {
|
||||||
|
this.#favor = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.#favor = clampNumber(value, 0, MaxFavor);
|
||||||
|
}
|
||||||
|
|
||||||
getInfo(): FactionInfo {
|
getInfo(): FactionInfo {
|
||||||
const info = FactionInfos[this.name];
|
const info = FactionInfos[this.name];
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
@ -47,7 +67,7 @@ export class Faction {
|
|||||||
|
|
||||||
prestigeSourceFile() {
|
prestigeSourceFile() {
|
||||||
// Reset favor, reputation, and flags
|
// Reset favor, reputation, and flags
|
||||||
this.favor = 0;
|
this.setFavor(0);
|
||||||
this.playerReputation = 0;
|
this.playerReputation = 0;
|
||||||
this.alreadyInvited = false;
|
this.alreadyInvited = false;
|
||||||
this.isMember = false;
|
this.isMember = false;
|
||||||
@ -56,23 +76,11 @@ export class Faction {
|
|||||||
|
|
||||||
prestigeAugmentation(): void {
|
prestigeAugmentation(): void {
|
||||||
// Gain favor
|
// Gain favor
|
||||||
if (this.favor == null) this.favor = 0;
|
this.setFavor(calculateFavorAfterResetting(this.favor, this.playerReputation));
|
||||||
this.favor += this.getFavorGain();
|
|
||||||
// Reset reputation and flags
|
// Reset reputation and flags
|
||||||
this.playerReputation = 0;
|
this.playerReputation = 0;
|
||||||
this.alreadyInvited = false;
|
this.alreadyInvited = false;
|
||||||
this.isMember = false;
|
this.isMember = false;
|
||||||
this.isBanned = false;
|
this.isBanned = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Returns an array with [How much favor would be gained, how much rep would be left over]
|
|
||||||
getFavorGain(): number {
|
|
||||||
if (this.favor == null) {
|
|
||||||
this.favor = 0;
|
|
||||||
}
|
|
||||||
const storedRep = Math.max(0, favorToRep(this.favor));
|
|
||||||
const totalRep = storedRep + this.playerReputation;
|
|
||||||
const newFavor = repToFavor(totalRep);
|
|
||||||
return newFavor - this.favor;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import { assertLoadingType } from "../utils/TypeAssertion";
|
|||||||
import { PartialRecord, createEnumKeyedRecord, getRecordValues } from "../Types/Record";
|
import { PartialRecord, createEnumKeyedRecord, getRecordValues } from "../Types/Record";
|
||||||
import { Augmentations } from "../Augmentation/Augmentations";
|
import { Augmentations } from "../Augmentation/Augmentations";
|
||||||
import { getEnumHelper } from "../utils/EnumHelper";
|
import { getEnumHelper } from "../utils/EnumHelper";
|
||||||
|
import { clampNumber } from "../utils/helpers/clampNumber";
|
||||||
|
|
||||||
/** The static list of all factions. Initialized once and never modified. */
|
/** The static list of all factions. Initialized once and never modified. */
|
||||||
export const Factions = createEnumKeyedRecord(FactionName, (name) => new Faction(name));
|
export const Factions = createEnumKeyedRecord(FactionName, (name) => new Faction(name));
|
||||||
@ -33,8 +34,14 @@ export function loadFactions(saveString: string, player: PlayerObject): void {
|
|||||||
if (typeof loadedFaction !== "object") continue;
|
if (typeof loadedFaction !== "object") continue;
|
||||||
assertLoadingType<SavegameFaction>(loadedFaction);
|
assertLoadingType<SavegameFaction>(loadedFaction);
|
||||||
const { playerReputation: loadedRep, favor: loadedFavor, discovery: loadedDiscovery } = loadedFaction;
|
const { playerReputation: loadedRep, favor: loadedFavor, discovery: loadedDiscovery } = loadedFaction;
|
||||||
if (typeof loadedRep === "number" && loadedRep > 0) faction.playerReputation = loadedRep;
|
if (typeof loadedRep === "number" && loadedRep >= 0) {
|
||||||
if (typeof loadedFavor === "number" && loadedFavor > 0) faction.favor = loadedFavor;
|
// `playerReputation` must be in [0, Number.MAX_VALUE].
|
||||||
|
faction.playerReputation = clampNumber(loadedRep, 0);
|
||||||
|
}
|
||||||
|
if (typeof loadedFavor === "number" && loadedFavor >= 0) {
|
||||||
|
// `favor` must be in [0, MaxFavor]. This rule will be enforced in the `setFavor` function.
|
||||||
|
faction.setFavor(loadedFavor);
|
||||||
|
}
|
||||||
if (getEnumHelper("FactionDiscovery").isMember(loadedDiscovery)) faction.discovery = loadedDiscovery;
|
if (getEnumHelper("FactionDiscovery").isMember(loadedDiscovery)) faction.discovery = loadedDiscovery;
|
||||||
}
|
}
|
||||||
// Load joined factions from player save
|
// Load joined factions from player save
|
||||||
|
@ -2,12 +2,18 @@
|
|||||||
// see https://en.wikipedia.org/wiki/Geometric_series#Closed-form_formula
|
// see https://en.wikipedia.org/wiki/Geometric_series#Closed-form_formula
|
||||||
// for information on how to calculate this
|
// for information on how to calculate this
|
||||||
|
|
||||||
|
import { clampNumber } from "../../utils/helpers/clampNumber";
|
||||||
|
|
||||||
|
export const MaxFavor = 35331;
|
||||||
|
|
||||||
export function favorToRep(f: number): number {
|
export function favorToRep(f: number): number {
|
||||||
const raw = 25000 * (Math.pow(1.02, f) - 1);
|
return clampNumber(25000 * (Math.pow(1.02, f) - 1), 0);
|
||||||
return Math.round(raw * 10000) / 10000; // round to make things easier.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function repToFavor(r: number): number {
|
export function repToFavor(r: number): number {
|
||||||
const raw = Math.log(r / 25000 + 1) / Math.log(1.02);
|
return clampNumber(Math.log(r / 25000 + 1) / Math.log(1.02), 0, MaxFavor);
|
||||||
return Math.round(raw * 10000) / 10000; // round to make things easier.
|
}
|
||||||
|
|
||||||
|
export function calculateFavorAfterResetting(favor: number, playerReputation: number) {
|
||||||
|
return repToFavor(favorToRep(favor) + playerReputation);
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import Typography from "@mui/material/Typography";
|
|||||||
import Tooltip from "@mui/material/Tooltip";
|
import Tooltip from "@mui/material/Tooltip";
|
||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import { useRerender } from "../../ui/React/hooks";
|
import { useRerender } from "../../ui/React/hooks";
|
||||||
|
import { calculateFavorAfterResetting } from "../formulas/favor";
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
faction: Faction;
|
faction: Faction;
|
||||||
@ -49,8 +50,6 @@ export function Info(props: IProps): React.ReactElement {
|
|||||||
|
|
||||||
const Assignment = props.factionInfo.assignment ?? DefaultAssignment;
|
const Assignment = props.factionInfo.assignment ?? DefaultAssignment;
|
||||||
|
|
||||||
const favorGain = props.faction.getFavorGain();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Typography classes={{ root: classes.noformat }}>{props.factionInfo.infoText}</Typography>
|
<Typography classes={{ root: classes.noformat }}>{props.factionInfo.infoText}</Typography>
|
||||||
@ -60,8 +59,9 @@ export function Info(props: IProps): React.ReactElement {
|
|||||||
title={
|
title={
|
||||||
<>
|
<>
|
||||||
<Typography>
|
<Typography>
|
||||||
You will have <Favor favor={Math.floor(props.faction.favor + favorGain)} /> faction favor after
|
You will have{" "}
|
||||||
installing an Augmentation.
|
<Favor favor={calculateFavorAfterResetting(props.faction.favor, props.faction.playerReputation)} />{" "}
|
||||||
|
faction favor after installing an Augmentation.
|
||||||
</Typography>
|
</Typography>
|
||||||
<MathJax>{"\\(\\huge{r = \\text{total faction reputation}}\\)"}</MathJax>
|
<MathJax>{"\\(\\huge{r = \\text{total faction reputation}}\\)"}</MathJax>
|
||||||
<MathJax>
|
<MathJax>
|
||||||
|
@ -76,7 +76,7 @@ export function endGoGame(boardState: BoardState) {
|
|||||||
Player.factions.includes(factionName) &&
|
Player.factions.includes(factionName) &&
|
||||||
statusToUpdate.favor < getMaxFavor()
|
statusToUpdate.favor < getMaxFavor()
|
||||||
) {
|
) {
|
||||||
Factions[factionName].favor++;
|
Factions[factionName].setFavor(Factions[factionName].favor + 1);
|
||||||
statusToUpdate.favor++;
|
statusToUpdate.favor++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -570,7 +570,7 @@ export function purchaseHashUpgrade(upgName: string, upgTarget: string, count =
|
|||||||
console.error(`Invalid target specified in purchaseHashUpgrade(): ${upgTarget}`);
|
console.error(`Invalid target specified in purchaseHashUpgrade(): ${upgTarget}`);
|
||||||
throw new Error(`'${upgTarget}' is not a company.`);
|
throw new Error(`'${upgTarget}' is not a company.`);
|
||||||
}
|
}
|
||||||
Companies[upgTarget].favor += 5 * count;
|
Companies[upgTarget].setFavor(Companies[upgTarget].favor + 5 * count);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -24,6 +24,7 @@ import { companyNameAsLocationName } from "../../Company/utils";
|
|||||||
import { JobSummary } from "../../Company/ui/JobSummary";
|
import { JobSummary } from "../../Company/ui/JobSummary";
|
||||||
import { StatsTable } from "../../ui/React/StatsTable";
|
import { StatsTable } from "../../ui/React/StatsTable";
|
||||||
import { JobListings } from "../../Company/ui/JobListings";
|
import { JobListings } from "../../Company/ui/JobListings";
|
||||||
|
import { calculateFavorAfterResetting } from "../../Faction/formulas/favor";
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
companyName: CompanyName;
|
companyName: CompanyName;
|
||||||
@ -98,7 +99,6 @@ export function CompanyLocation(props: IProps): React.ReactElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isEmployedHere = currentPosition != null;
|
const isEmployedHere = currentPosition != null;
|
||||||
const favorGain = company.getFavorGain();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -120,8 +120,9 @@ export function CompanyLocation(props: IProps): React.ReactElement {
|
|||||||
key="repLabel"
|
key="repLabel"
|
||||||
title={
|
title={
|
||||||
<>
|
<>
|
||||||
You will have <Favor favor={company.favor + favorGain} /> company favor upon resetting after
|
You will have{" "}
|
||||||
installing Augmentations
|
<Favor favor={calculateFavorAfterResetting(company.favor, company.playerReputation)} /> company
|
||||||
|
favor upon resetting after installing Augmentations
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
@ -58,6 +58,7 @@ import { JobTracks } from "../Company/data/JobTracks";
|
|||||||
import { ServerConstants } from "../Server/data/Constants";
|
import { ServerConstants } from "../Server/data/Constants";
|
||||||
import { blackOpsArray } from "../Bladeburner/data/BlackOperations";
|
import { blackOpsArray } from "../Bladeburner/data/BlackOperations";
|
||||||
import { calculateEffectiveRequiredReputation } from "../Company/utils";
|
import { calculateEffectiveRequiredReputation } from "../Company/utils";
|
||||||
|
import { calculateFavorAfterResetting } from "../Faction/formulas/favor";
|
||||||
|
|
||||||
export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||||
const runAfterReset = function (cbScript: ScriptFilePath) {
|
const runAfterReset = function (cbScript: ScriptFilePath) {
|
||||||
@ -761,7 +762,8 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
|||||||
getCompanyFavorGain: (ctx) => (_companyName) => {
|
getCompanyFavorGain: (ctx) => (_companyName) => {
|
||||||
helpers.checkSingularityAccess(ctx);
|
helpers.checkSingularityAccess(ctx);
|
||||||
const companyName = getEnumHelper("CompanyName").nsGetMember(ctx, _companyName);
|
const companyName = getEnumHelper("CompanyName").nsGetMember(ctx, _companyName);
|
||||||
return Companies[companyName].getFavorGain();
|
const company = Companies[companyName];
|
||||||
|
return calculateFavorAfterResetting(company.favor, company.playerReputation) - company.favor;
|
||||||
},
|
},
|
||||||
getFactionInviteRequirements: (ctx) => (_facName) => {
|
getFactionInviteRequirements: (ctx) => (_facName) => {
|
||||||
helpers.checkSingularityAccess(ctx);
|
helpers.checkSingularityAccess(ctx);
|
||||||
@ -911,7 +913,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
|||||||
helpers.checkSingularityAccess(ctx);
|
helpers.checkSingularityAccess(ctx);
|
||||||
const facName = getEnumHelper("FactionName").nsGetMember(ctx, _facName);
|
const facName = getEnumHelper("FactionName").nsGetMember(ctx, _facName);
|
||||||
const faction = Factions[facName];
|
const faction = Factions[facName];
|
||||||
return faction.getFavorGain();
|
return calculateFavorAfterResetting(faction.favor, faction.playerReputation) - faction.favor;
|
||||||
},
|
},
|
||||||
donateToFaction: (ctx) => (_facName, _amt) => {
|
donateToFaction: (ctx) => (_facName, _amt) => {
|
||||||
helpers.checkSingularityAccess(ctx);
|
helpers.checkSingularityAccess(ctx);
|
||||||
|
@ -57,11 +57,11 @@ function establishInitialConditions() {
|
|||||||
joinFaction(csec);
|
joinFaction(csec);
|
||||||
joinFaction(slumSnakes);
|
joinFaction(slumSnakes);
|
||||||
csec.playerReputation = 1e6;
|
csec.playerReputation = 1e6;
|
||||||
csec.favor = 20;
|
csec.setFavor(20);
|
||||||
|
|
||||||
// Companies
|
// Companies
|
||||||
const noodleBar = Companies[CompanyName.NoodleBar];
|
const noodleBar = Companies[CompanyName.NoodleBar];
|
||||||
noodleBar.favor = 100;
|
noodleBar.setFavor(100);
|
||||||
noodleBar.playerReputation = 100000;
|
noodleBar.playerReputation = 100000;
|
||||||
|
|
||||||
// Bladeburner. Adding rank will also add bladeburner faction rep.
|
// Bladeburner. Adding rank will also add bladeburner faction rep.
|
||||||
|
Loading…
Reference in New Issue
Block a user