2022-04-14 19:19:51 +02:00
|
|
|
import { StaticAugmentations } from "../Augmentation/StaticAugmentations";
|
2021-09-24 23:16:14 +02:00
|
|
|
import { Augmentation } from "../Augmentation/Augmentation";
|
2019-04-14 11:08:10 +02:00
|
|
|
import { PlayerOwnedAugmentation } from "../Augmentation/PlayerOwnedAugmentation";
|
|
|
|
import { AugmentationNames } from "../Augmentation/data/AugmentationNames";
|
|
|
|
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
|
2021-09-18 01:43:08 +02:00
|
|
|
|
2019-04-14 11:08:10 +02:00
|
|
|
import { Faction } from "./Faction";
|
|
|
|
import { Factions } from "./Factions";
|
|
|
|
import { Player } from "../Player";
|
2022-03-30 03:10:07 +02:00
|
|
|
import { IPlayer } from "../PersonObjects/IPlayer";
|
2019-04-14 11:08:10 +02:00
|
|
|
import { Settings } from "../Settings/Settings";
|
2021-09-05 01:09:30 +02:00
|
|
|
import {
|
|
|
|
getHackingWorkRepGain,
|
|
|
|
getFactionSecurityWorkRepGain,
|
|
|
|
getFactionFieldWorkRepGain,
|
2021-04-18 17:18:56 +02:00
|
|
|
} from "../PersonObjects/formulas/reputation";
|
2019-04-14 11:08:10 +02:00
|
|
|
|
2021-09-25 20:42:57 +02:00
|
|
|
import { dialogBoxCreate } from "../ui/React/DialogBox";
|
2021-10-01 19:08:37 +02:00
|
|
|
import { InvitationEvent } from "./ui/InvitationModal";
|
2022-03-19 09:09:59 +01:00
|
|
|
import { FactionNames } from "./data/FactionNames";
|
2022-03-31 02:58:09 +02:00
|
|
|
import { SFC32RNG } from "../Casino/RNG";
|
2022-02-28 12:47:37 +01:00
|
|
|
|
2021-09-24 23:16:14 +02:00
|
|
|
export function inviteToFaction(faction: Faction): void {
|
2021-12-09 00:29:56 +01:00
|
|
|
Player.receiveInvite(faction.name);
|
2021-09-13 00:03:07 +02:00
|
|
|
faction.alreadyInvited = true;
|
|
|
|
if (!Settings.SuppressFactionInvites) {
|
2021-10-01 19:08:37 +02:00
|
|
|
InvitationEvent.emit(faction);
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
2019-04-14 11:08:10 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 23:16:14 +02:00
|
|
|
export function joinFaction(faction: Faction): void {
|
2021-09-05 01:09:30 +02:00
|
|
|
if (faction.isMember) return;
|
|
|
|
faction.isMember = true;
|
|
|
|
Player.factions.push(faction.name);
|
2022-03-22 12:24:32 +01:00
|
|
|
const allFactions = Object.values(FactionNames).map((faction) => faction as string);
|
|
|
|
Player.factions.sort((a, b) => allFactions.indexOf(a) - allFactions.indexOf(b));
|
2021-09-05 01:09:30 +02:00
|
|
|
const factionInfo = faction.getInfo();
|
2019-04-14 11:08:10 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
//Determine what factions you are banned from now that you have joined this faction
|
2022-01-16 01:45:03 +01:00
|
|
|
for (const enemy of factionInfo.enemies) {
|
2021-09-05 01:09:30 +02:00
|
|
|
if (Factions[enemy] instanceof Faction) {
|
|
|
|
Factions[enemy].isBanned = true;
|
2019-04-14 11:08:10 +02:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
2021-09-25 07:26:03 +02:00
|
|
|
for (let i = 0; i < Player.factionInvitations.length; ++i) {
|
2021-09-09 05:47:34 +02:00
|
|
|
if (Player.factionInvitations[i] == faction.name || Factions[Player.factionInvitations[i]].isBanned) {
|
2021-09-05 01:09:30 +02:00
|
|
|
Player.factionInvitations.splice(i, 1);
|
|
|
|
i--;
|
2021-05-06 21:49:20 +02:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
2019-04-14 11:08:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//Returns a boolean indicating whether the player has the prerequisites for the
|
|
|
|
//specified Augmentation
|
2021-09-24 23:16:14 +02:00
|
|
|
export function hasAugmentationPrereqs(aug: Augmentation): boolean {
|
2022-04-23 02:18:35 +02:00
|
|
|
return aug.prereqs.every((aug) => Player.hasAugmentation(aug));
|
2019-04-14 11:08:10 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 23:16:14 +02:00
|
|
|
export function purchaseAugmentation(aug: Augmentation, fac: Faction, sing = false): string {
|
2021-09-25 07:26:03 +02:00
|
|
|
const hasPrereqs = hasAugmentationPrereqs(aug);
|
2022-04-14 19:39:38 +02:00
|
|
|
const augCosts = aug.getCost(Player);
|
2021-09-05 01:09:30 +02:00
|
|
|
if (!hasPrereqs) {
|
2022-04-23 02:18:35 +02:00
|
|
|
const txt = `You must first purchase or install ${aug.prereqs
|
|
|
|
.filter((req) => !Player.hasAugmentation(req))
|
|
|
|
.join(",")} before you can purchase this one.`;
|
2021-09-05 01:09:30 +02:00
|
|
|
if (sing) {
|
|
|
|
return txt;
|
|
|
|
} else {
|
|
|
|
dialogBoxCreate(txt);
|
|
|
|
}
|
2022-04-14 19:39:38 +02:00
|
|
|
} else if (augCosts.moneyCost !== 0 && Player.money < augCosts.moneyCost) {
|
2021-09-25 07:26:03 +02:00
|
|
|
const txt = "You don't have enough money to purchase " + aug.name;
|
2021-09-05 01:09:30 +02:00
|
|
|
if (sing) {
|
|
|
|
return txt;
|
|
|
|
}
|
|
|
|
dialogBoxCreate(txt);
|
2022-04-14 19:39:38 +02:00
|
|
|
} else if (fac.playerReputation < augCosts.repCost) {
|
2021-09-25 07:26:03 +02:00
|
|
|
const txt = "You don't have enough faction reputation to purchase " + aug.name;
|
2021-09-05 01:09:30 +02:00
|
|
|
if (sing) {
|
|
|
|
return txt;
|
|
|
|
}
|
|
|
|
dialogBoxCreate(txt);
|
2022-04-14 19:39:38 +02:00
|
|
|
} else if (augCosts.moneyCost === 0 || Player.money >= augCosts.moneyCost) {
|
2021-09-25 07:26:03 +02:00
|
|
|
const queuedAugmentation = new PlayerOwnedAugmentation(aug.name);
|
2021-09-05 01:09:30 +02:00
|
|
|
if (aug.name == AugmentationNames.NeuroFluxGovernor) {
|
2022-04-14 19:39:38 +02:00
|
|
|
queuedAugmentation.level = aug.getLevel(Player);
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
Player.queuedAugmentations.push(queuedAugmentation);
|
2019-04-14 11:08:10 +02:00
|
|
|
|
2022-04-14 19:39:38 +02:00
|
|
|
Player.loseMoney(augCosts.moneyCost, "augmentations");
|
2019-04-14 11:08:10 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
if (sing) {
|
|
|
|
return "You purchased " + aug.name;
|
2022-03-11 16:32:48 +01:00
|
|
|
} else if (!Settings.SuppressBuyAugmentationConfirmation) {
|
2022-03-19 09:09:59 +01:00
|
|
|
dialogBoxCreate(
|
|
|
|
"You purchased " +
|
2022-03-22 12:24:32 +01:00
|
|
|
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.",
|
2022-03-19 09:09:59 +01:00
|
|
|
);
|
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
} else {
|
|
|
|
dialogBoxCreate(
|
|
|
|
"Hmm, something went wrong when trying to purchase an Augmentation. " +
|
2022-03-22 12:24:32 +01:00
|
|
|
"Please report this to the game developer with an explanation of how to " +
|
|
|
|
"reproduce this.",
|
2021-09-05 01:09:30 +02:00
|
|
|
);
|
|
|
|
}
|
2021-09-24 23:16:14 +02:00
|
|
|
return "";
|
2019-04-14 11:08:10 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 23:16:14 +02:00
|
|
|
export function processPassiveFactionRepGain(numCycles: number): void {
|
2022-01-16 01:45:03 +01:00
|
|
|
for (const name of Object.keys(Factions)) {
|
2021-09-05 01:09:30 +02:00
|
|
|
if (name === Player.currentWorkFactionName) continue;
|
|
|
|
if (!Factions.hasOwnProperty(name)) continue;
|
|
|
|
const faction = Factions[name];
|
|
|
|
if (!faction.isMember) continue;
|
|
|
|
// No passive rep for special factions
|
|
|
|
const info = faction.getInfo();
|
|
|
|
if (!info.offersWork()) continue;
|
|
|
|
// No passive rep for gangs.
|
|
|
|
if (Player.getGangName() === name) continue;
|
|
|
|
// 0 favor = 1%/s
|
|
|
|
// 50 favor = 6%/s
|
|
|
|
// 100 favor = 11%/s
|
|
|
|
const favorMult = Math.min(0.1, faction.favor / 1000 + 0.01);
|
|
|
|
// Find the best of all possible favor gain, minimum 1 rep / 2 minute.
|
|
|
|
const hRep = getHackingWorkRepGain(Player, faction);
|
|
|
|
const sRep = getFactionSecurityWorkRepGain(Player, faction);
|
|
|
|
const fRep = getFactionFieldWorkRepGain(Player, faction);
|
2021-09-09 05:47:34 +02:00
|
|
|
const rate = Math.max(hRep * favorMult, sRep * favorMult, fRep * favorMult, 1 / 120);
|
2021-04-18 17:18:56 +02:00
|
|
|
|
2021-09-09 05:47:34 +02:00
|
|
|
faction.playerReputation += rate * numCycles * Player.faction_rep_mult * BitNodeMultipliers.FactionPassiveRepGain;
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
2019-04-14 11:08:10 +02:00
|
|
|
}
|
2022-03-30 03:10:07 +02:00
|
|
|
|
2022-03-31 02:58:09 +02:00
|
|
|
export const getFactionAugmentationsFiltered = (player: IPlayer, faction: Faction): string[] => {
|
2022-03-30 03:10:07 +02:00
|
|
|
// If player has a gang with this faction, return (almost) all augmentations
|
|
|
|
if (player.hasGangWith(faction.name)) {
|
2022-04-14 19:19:51 +02:00
|
|
|
let augs = Object.values(StaticAugmentations);
|
2022-03-30 03:10:07 +02:00
|
|
|
|
|
|
|
// Remove special augs
|
2022-04-26 17:52:58 +02:00
|
|
|
augs = augs.filter((a) => !a.isSpecial && a.name !== AugmentationNames.CongruityImplant);
|
2022-03-30 03:10:07 +02:00
|
|
|
|
2022-04-26 14:44:09 +02:00
|
|
|
if (player.bitNodeN === 2) {
|
2022-03-30 03:10:07 +02:00
|
|
|
// TRP is not available outside of BN2 for Gangs
|
2022-04-27 13:00:42 +02:00
|
|
|
augs.push(StaticAugmentations[AugmentationNames.TheRedPill]);
|
2022-03-30 03:10:07 +02:00
|
|
|
}
|
|
|
|
|
2022-03-31 02:58:09 +02:00
|
|
|
const rng = SFC32RNG(`BN${player.bitNodeN}.${player.sourceFileLvl(player.bitNodeN)}`);
|
|
|
|
// Remove faction-unique augs that don't belong to this faction
|
|
|
|
const uniqueFilter = (a: Augmentation): boolean => {
|
|
|
|
// Keep all the non-unique one
|
|
|
|
if (a.factions.length > 1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Keep all the ones that this faction has anyway.
|
|
|
|
if (faction.augmentations.includes(a.name)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rng() >= 1 - BitNodeMultipliers.GangUniqueAugs;
|
|
|
|
};
|
|
|
|
augs = augs.filter(uniqueFilter);
|
|
|
|
|
2022-03-30 03:10:07 +02:00
|
|
|
return augs.map((a) => a.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return faction.augmentations.slice();
|
|
|
|
};
|