mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-26 09:33:49 +01:00
Merge pull request #3280 from nickofolas/improvement/filter-helper-func
[Improvement] Implement helper function for filtering Faction Augmentations
This commit is contained in:
commit
ce944bfccb
@ -8,6 +8,7 @@ import { CONSTANTS } from "../Constants";
|
|||||||
import { Faction } from "./Faction";
|
import { Faction } from "./Faction";
|
||||||
import { Factions } from "./Factions";
|
import { Factions } from "./Factions";
|
||||||
import { Player } from "../Player";
|
import { Player } from "../Player";
|
||||||
|
import { IPlayer } from "../PersonObjects/IPlayer";
|
||||||
import { Settings } from "../Settings/Settings";
|
import { Settings } from "../Settings/Settings";
|
||||||
import {
|
import {
|
||||||
getHackingWorkRepGain,
|
getHackingWorkRepGain,
|
||||||
@ -32,9 +33,8 @@ export function joinFaction(faction: Faction): void {
|
|||||||
if (faction.isMember) return;
|
if (faction.isMember) return;
|
||||||
faction.isMember = true;
|
faction.isMember = true;
|
||||||
Player.factions.push(faction.name);
|
Player.factions.push(faction.name);
|
||||||
const allFactions = Object.values(FactionNames).map(faction => faction as string)
|
const allFactions = Object.values(FactionNames).map((faction) => faction as string);
|
||||||
Player.factions.sort((a, b) =>
|
Player.factions.sort((a, b) => allFactions.indexOf(a) - allFactions.indexOf(b));
|
||||||
allFactions.indexOf(a) - allFactions.indexOf(b));
|
|
||||||
const factionInfo = faction.getInfo();
|
const factionInfo = faction.getInfo();
|
||||||
|
|
||||||
//Determine what factions you are banned from now that you have joined this faction
|
//Determine what factions you are banned from now that you have joined this faction
|
||||||
@ -193,3 +193,30 @@ export function processPassiveFactionRepGain(numCycles: number): void {
|
|||||||
faction.playerReputation += rate * numCycles * Player.faction_rep_mult * BitNodeMultipliers.FactionPassiveRepGain;
|
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: string[] = [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 { Faction } from "../Faction";
|
||||||
import { PurchaseAugmentationsOrderSetting } from "../../Settings/SettingEnums";
|
import { PurchaseAugmentationsOrderSetting } from "../../Settings/SettingEnums";
|
||||||
import { Settings } from "../../Settings/Settings";
|
import { Settings } from "../../Settings/Settings";
|
||||||
import { hasAugmentationPrereqs } from "../FactionHelpers";
|
import { hasAugmentationPrereqs, getFactionAugmentationsFiltered } from "../FactionHelpers";
|
||||||
|
|
||||||
import { use } from "../../ui/Context";
|
import { use } from "../../ui/Context";
|
||||||
import { Reputation } from "../../ui/React/Reputation";
|
import { Reputation } from "../../ui/React/Reputation";
|
||||||
@ -42,28 +42,7 @@ export function AugmentationsPage(props: IProps): React.ReactElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getAugs(): string[] {
|
function getAugs(): string[] {
|
||||||
if (isPlayersGang) {
|
return getFactionAugmentationsFiltered(player, props.faction);
|
||||||
// TODO: this code is duplicated in getAugmentationsFromFaction DRY
|
|
||||||
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].map(
|
|
||||||
(augmentation) => augmentation as string,
|
|
||||||
);
|
|
||||||
augs = augs.filter((a) => !blacklist.includes(a.name));
|
|
||||||
}
|
|
||||||
|
|
||||||
return augs.map((a) => a.name);
|
|
||||||
} else {
|
|
||||||
return props.faction.augmentations.slice();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAugsSorted(): string[] {
|
function getAugsSorted(): string[] {
|
||||||
|
@ -9,7 +9,7 @@ import { Table, TableCell } from "../../ui/React/Table";
|
|||||||
import { IRouter } from "../../ui/Router";
|
import { IRouter } from "../../ui/Router";
|
||||||
|
|
||||||
import { Faction } from "../Faction";
|
import { Faction } from "../Faction";
|
||||||
import { joinFaction } from "../FactionHelpers";
|
import { joinFaction, getFactionAugmentationsFiltered } from "../FactionHelpers";
|
||||||
import { Factions } from "../Factions";
|
import { Factions } from "../Factions";
|
||||||
import { FactionNames } from "../data/FactionNames";
|
import { FactionNames } from "../data/FactionNames";
|
||||||
|
|
||||||
@ -52,26 +52,7 @@ export function FactionsRoot(props: IProps): React.ReactElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getAugsLeft = (faction: Faction, player: IPlayer): number => {
|
const getAugsLeft = (faction: Faction, player: IPlayer): number => {
|
||||||
const isPlayersGang = player.inGang() && player.getGangName() === faction.name;
|
const augs = getFactionAugmentationsFiltered(player, faction);
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
return augs.filter((augmentation: string) => !player.hasAugmentation(augmentation)).length;
|
return augs.filter((augmentation: string) => !player.hasAugmentation(augmentation)).length;
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { INetscriptHelper } from "./INetscriptHelper";
|
import { INetscriptHelper } from "./INetscriptHelper";
|
||||||
import { WorkerScript } from "../Netscript/WorkerScript";
|
import { WorkerScript } from "../Netscript/WorkerScript";
|
||||||
import { IPlayer } from "../PersonObjects/IPlayer";
|
import { IPlayer } from "../PersonObjects/IPlayer";
|
||||||
import { purchaseAugmentation, joinFaction } from "../Faction/FactionHelpers";
|
import { purchaseAugmentation, joinFaction, getFactionAugmentationsFiltered } from "../Faction/FactionHelpers";
|
||||||
import { startWorkerScript } from "../NetscriptWorker";
|
import { startWorkerScript } from "../NetscriptWorker";
|
||||||
import { Augmentation } from "../Augmentation/Augmentation";
|
import { Augmentation } from "../Augmentation/Augmentation";
|
||||||
import { Augmentations } from "../Augmentation/Augmentations";
|
import { Augmentations } from "../Augmentation/Augmentations";
|
||||||
@ -118,28 +118,7 @@ export function NetscriptSingularity(
|
|||||||
helper.checkSingularityAccess("getAugmentationsFromFaction");
|
helper.checkSingularityAccess("getAugmentationsFromFaction");
|
||||||
const faction = getFaction("getAugmentationsFromFaction", facName);
|
const faction = getFaction("getAugmentationsFromFaction", facName);
|
||||||
|
|
||||||
// If player has a gang with this faction, return all augmentations.
|
return getFactionAugmentationsFiltered(player, faction);
|
||||||
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].map(
|
|
||||||
(augmentation) => augmentation as string,
|
|
||||||
);
|
|
||||||
augs = augs.filter((a) => !blacklist.includes(a.name));
|
|
||||||
}
|
|
||||||
|
|
||||||
return augs.map((a) => a.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return faction.augmentations.slice();
|
|
||||||
},
|
},
|
||||||
getAugmentationCost: function (_augName: unknown): [number, number] {
|
getAugmentationCost: function (_augName: unknown): [number, number] {
|
||||||
const augName = helper.string("getAugmentationCost", "augName", _augName);
|
const augName = helper.string("getAugmentationCost", "augName", _augName);
|
||||||
@ -184,24 +163,7 @@ export function NetscriptSingularity(
|
|||||||
const fac = getFaction("purchaseAugmentation", facName);
|
const fac = getFaction("purchaseAugmentation", facName);
|
||||||
const aug = getAugmentation("purchaseAugmentation", augName);
|
const aug = getAugmentation("purchaseAugmentation", augName);
|
||||||
|
|
||||||
let augs = [];
|
const augs = getFactionAugmentationsFiltered(player, fac);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!augs.includes(augName)) {
|
if (!augs.includes(augName)) {
|
||||||
workerScript.log(
|
workerScript.log(
|
||||||
|
Loading…
Reference in New Issue
Block a user