mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-20 14:43:48 +01:00
Impl faction augs filter helper function
This commit is contained in:
parent
4d9a8e7bba
commit
5d27ce7aa3
@ -8,6 +8,7 @@ import { CONSTANTS } from "../Constants";
|
||||
import { Faction } from "./Faction";
|
||||
import { Factions } from "./Factions";
|
||||
import { Player } from "../Player";
|
||||
import { IPlayer } from "../PersonObjects/IPlayer";
|
||||
import { Settings } from "../Settings/Settings";
|
||||
import {
|
||||
getHackingWorkRepGain,
|
||||
@ -32,9 +33,8 @@ export function joinFaction(faction: Faction): void {
|
||||
if (faction.isMember) return;
|
||||
faction.isMember = true;
|
||||
Player.factions.push(faction.name);
|
||||
const allFactions = Object.values(FactionNames).map(faction => faction as string)
|
||||
Player.factions.sort((a, b) =>
|
||||
allFactions.indexOf(a) - allFactions.indexOf(b));
|
||||
const allFactions = Object.values(FactionNames).map((faction) => faction as string);
|
||||
Player.factions.sort((a, b) => allFactions.indexOf(a) - allFactions.indexOf(b));
|
||||
const factionInfo = faction.getInfo();
|
||||
|
||||
//Determine what factions you are banned from now that you have joined this faction
|
||||
@ -134,18 +134,18 @@ export function purchaseAugmentation(aug: Augmentation, fac: Faction, sing = fal
|
||||
} else if (!Settings.SuppressBuyAugmentationConfirmation) {
|
||||
dialogBoxCreate(
|
||||
"You purchased " +
|
||||
aug.name +
|
||||
". Its enhancements will not take " +
|
||||
"effect until they are installed. To install your augmentations, go to the " +
|
||||
"'Augmentations' tab on the left-hand navigation menu. Purchasing additional " +
|
||||
"augmentations will now be more expensive.",
|
||||
aug.name +
|
||||
". Its enhancements will not take " +
|
||||
"effect until they are installed. To install your augmentations, go to the " +
|
||||
"'Augmentations' tab on the left-hand navigation menu. Purchasing additional " +
|
||||
"augmentations will now be more expensive.",
|
||||
);
|
||||
}
|
||||
} else {
|
||||
dialogBoxCreate(
|
||||
"Hmm, something went wrong when trying to purchase an Augmentation. " +
|
||||
"Please report this to the game developer with an explanation of how to " +
|
||||
"reproduce this.",
|
||||
"Please report this to the game developer with an explanation of how to " +
|
||||
"reproduce this.",
|
||||
);
|
||||
}
|
||||
return "";
|
||||
@ -193,3 +193,30 @@ export function processPassiveFactionRepGain(numCycles: number): void {
|
||||
faction.playerReputation += rate * numCycles * Player.faction_rep_mult * BitNodeMultipliers.FactionPassiveRepGain;
|
||||
}
|
||||
}
|
||||
|
||||
export const getFactionAugmentationsFiltered = (player: IPlayer, faction: Faction) => {
|
||||
// If player has a gang with this faction, return (almost) all augmentations
|
||||
if (player.hasGangWith(faction.name)) {
|
||||
let augs = Object.values(Augmentations);
|
||||
|
||||
// Remove special augs
|
||||
augs = augs.filter((a) => !a.isSpecial);
|
||||
|
||||
const blacklist = [AugmentationNames.NeuroFluxGovernor];
|
||||
|
||||
if (player.bitNodeN !== 2) {
|
||||
// Remove faction-unique augs that don't belong to this faction
|
||||
augs = augs.filter((a) => a.factions.length > 1 || faction.augmentations.includes(a.name));
|
||||
|
||||
// TRP is not available outside of BN2 for Gangs
|
||||
blacklist.push(AugmentationNames.TheRedPill);
|
||||
}
|
||||
|
||||
// Remove blacklisted augs
|
||||
augs = augs.filter((a) => !blacklist.includes(a.name));
|
||||
|
||||
return augs.map((a) => a.name);
|
||||
}
|
||||
|
||||
return faction.augmentations.slice();
|
||||
};
|
||||
|
@ -10,7 +10,7 @@ import { AugmentationNames } from "../../Augmentation/data/AugmentationNames";
|
||||
import { Faction } from "../Faction";
|
||||
import { PurchaseAugmentationsOrderSetting } from "../../Settings/SettingEnums";
|
||||
import { Settings } from "../../Settings/Settings";
|
||||
import { hasAugmentationPrereqs } from "../FactionHelpers";
|
||||
import { hasAugmentationPrereqs, getFactionAugmentationsFiltered } from "../FactionHelpers";
|
||||
|
||||
import { use } from "../../ui/Context";
|
||||
import { Reputation } from "../../ui/React/Reputation";
|
||||
@ -42,25 +42,7 @@ export function AugmentationsPage(props: IProps): React.ReactElement {
|
||||
}
|
||||
|
||||
function getAugs(): string[] {
|
||||
if (isPlayersGang) {
|
||||
let augs = Object.values(Augmentations);
|
||||
|
||||
// Remove special augs.
|
||||
augs = augs.filter((a) => !a.isSpecial);
|
||||
|
||||
if (player.bitNodeN !== 2) {
|
||||
// Remove faction-unique augs outside BN2. (But keep the one for this faction.)
|
||||
augs = augs.filter((a) => a.factions.length > 1 || props.faction.augmentations.includes(a.name));
|
||||
|
||||
// Remove blacklisted augs.
|
||||
const blacklist = [AugmentationNames.NeuroFluxGovernor, AugmentationNames.TheRedPill];
|
||||
augs = augs.filter((a) => !blacklist.includes(a.name));
|
||||
}
|
||||
|
||||
return augs.map((a) => a.name);
|
||||
} else {
|
||||
return props.faction.augmentations.slice();
|
||||
}
|
||||
return getFactionAugmentationsFiltered(player, props.faction);
|
||||
}
|
||||
|
||||
function getAugsSorted(): string[] {
|
||||
|
@ -9,7 +9,7 @@ import { Table, TableCell } from "../../ui/React/Table";
|
||||
import { IRouter } from "../../ui/Router";
|
||||
|
||||
import { Faction } from "../Faction";
|
||||
import { joinFaction } from "../FactionHelpers";
|
||||
import { joinFaction, getFactionAugmentationsFiltered } from "../FactionHelpers";
|
||||
import { Factions } from "../Factions";
|
||||
import { FactionNames } from "../data/FactionNames";
|
||||
|
||||
@ -52,26 +52,7 @@ export function FactionsRoot(props: IProps): React.ReactElement {
|
||||
}
|
||||
|
||||
const getAugsLeft = (faction: Faction, player: IPlayer): number => {
|
||||
const isPlayersGang = player.inGang() && player.getGangName() === faction.name;
|
||||
let augs: string[] = [];
|
||||
|
||||
if (isPlayersGang) {
|
||||
for (const augName of Object.keys(Augmentations)) {
|
||||
const aug = Augmentations[augName];
|
||||
if (
|
||||
augName === AugmentationNames.NeuroFluxGovernor ||
|
||||
(augName === AugmentationNames.TheRedPill && player.bitNodeN !== 2) ||
|
||||
// Special augs (i.e. Bladeburner augs)
|
||||
aug.isSpecial ||
|
||||
// Exclusive augs (i.e. QLink)
|
||||
(aug.factions.length <= 1 && !faction.augmentations.includes(augName) && player.bitNodeN !== 2)
|
||||
)
|
||||
continue;
|
||||
augs.push(augName);
|
||||
}
|
||||
} else {
|
||||
augs = faction.augmentations.slice();
|
||||
}
|
||||
const augs = getFactionAugmentationsFiltered(player, faction);
|
||||
|
||||
return augs.filter((augmentation: string) => !player.hasAugmentation(augmentation)).length;
|
||||
};
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { INetscriptHelper } from "./INetscriptHelper";
|
||||
import { WorkerScript } from "../Netscript/WorkerScript";
|
||||
import { IPlayer } from "../PersonObjects/IPlayer";
|
||||
import { purchaseAugmentation, joinFaction } from "../Faction/FactionHelpers";
|
||||
import { purchaseAugmentation, joinFaction, getFactionAugmentationsFiltered } from "../Faction/FactionHelpers";
|
||||
import { startWorkerScript } from "../NetscriptWorker";
|
||||
import { Augmentation } from "../Augmentation/Augmentation";
|
||||
import { Augmentations } from "../Augmentation/Augmentations";
|
||||
@ -118,26 +118,7 @@ export function NetscriptSingularity(
|
||||
helper.checkSingularityAccess("getAugmentationsFromFaction");
|
||||
const faction = getFaction("getAugmentationsFromFaction", facName);
|
||||
|
||||
// If player has a gang with this faction, return all augmentations.
|
||||
if (player.hasGangWith(facName)) {
|
||||
let augs = Object.values(Augmentations);
|
||||
|
||||
// Remove special augs.
|
||||
augs = augs.filter((a) => !a.isSpecial);
|
||||
|
||||
if (player.bitNodeN !== 2) {
|
||||
// Remove faction-unique augs outside BN2. (But keep the one for this faction.)
|
||||
augs = augs.filter((a) => a.factions.length > 1 || Factions[facName].augmentations.includes(a.name));
|
||||
|
||||
// Remove blacklisted augs.
|
||||
const blacklist = [AugmentationNames.NeuroFluxGovernor, AugmentationNames.TheRedPill];
|
||||
augs = augs.filter((a) => !blacklist.includes(a.name));
|
||||
}
|
||||
|
||||
return augs.map((a) => a.name);
|
||||
}
|
||||
|
||||
return faction.augmentations.slice();
|
||||
return getFactionAugmentationsFiltered(player, faction);
|
||||
},
|
||||
getAugmentationCost: function (_augName: unknown): [number, number] {
|
||||
const augName = helper.string("getAugmentationCost", "augName", _augName);
|
||||
@ -182,24 +163,7 @@ export function NetscriptSingularity(
|
||||
const fac = getFaction("purchaseAugmentation", facName);
|
||||
const aug = getAugmentation("purchaseAugmentation", augName);
|
||||
|
||||
let augs = [];
|
||||
if (player.hasGangWith(facName)) {
|
||||
for (const augName of Object.keys(Augmentations)) {
|
||||
const aug = Augmentations[augName];
|
||||
if (
|
||||
augName === AugmentationNames.NeuroFluxGovernor ||
|
||||
(augName === AugmentationNames.TheRedPill && player.bitNodeN !== 2) ||
|
||||
// Special augs (i.e. Bladeburner augs)
|
||||
aug.isSpecial ||
|
||||
// Exclusive augs (i.e. QLink)
|
||||
(aug.factions.length <= 1 && !fac.augmentations.includes(augName) && player.bitNodeN !== 2)
|
||||
)
|
||||
continue;
|
||||
augs.push(augName);
|
||||
}
|
||||
} else {
|
||||
augs = fac.augmentations;
|
||||
}
|
||||
const augs = getFactionAugmentationsFiltered(player, fac);
|
||||
|
||||
if (!augs.includes(augName)) {
|
||||
workerScript.log(
|
||||
|
Loading…
Reference in New Issue
Block a user