import {Augmentations, AugmentationNames, PlayerOwnedAugmentation} from "./Augmentations.js"; import {BitNodeMultipliers} from "./BitNode.js"; import {CONSTANTS} from "./Constants.js"; import {Engine} from "./engine.js"; import {FactionInfo} from "./FactionInfo.js"; import {Locations} from "./Location.js"; import {HackingMission, setInMission} from "./Missions.js"; import {Player} from "./Player.js"; import {Settings} from "./Settings.js"; import {dialogBoxCreate} from "../utils/DialogBox.js"; import {factionInvitationBoxCreate} from "../utils/FactionInvitationBox.js"; import {clearEventListeners} from "../utils/HelperFunctions.js"; import {Reviver, Generic_toJSON, Generic_fromJSON} from "../utils/JSONReviver.js"; import {formatNumber, isPositiveNumber} from "../utils/StringHelperFunctions.js"; import {yesNoBoxCreate, yesNoBoxGetYesButton, yesNoBoxGetNoButton, yesNoBoxClose} from "../utils/YesNoBox.js"; //Netburner Faction class function factionInit() { $('#faction-donate-input').on('input', function() { if (Engine.currentPage == Engine.Page.Faction) { var val = document.getElementById("faction-donate-input").value; if (isPositiveNumber(val)) { var numMoneyDonate = Number(val); document.getElementById("faction-donate-rep-gain").innerHTML = "This donation will result in " + formatNumber(numMoneyDonate/1000000 * Player.faction_rep_mult, 3) + " reputation gain"; } else { document.getElementById("faction-donate-rep-gain").innerHTML = "This donation will result in 0 reputation gain"; } } }); } document.addEventListener("DOMContentLoaded", factionInit, false); function Faction(name="") { this.name = name; this.augmentations = []; //Name of augmentation only this.info = ""; //Introductory/informational text about the faction //Player-related properties for faction this.isMember = false; //Whether player is member this.isBanned = false; //Whether or not player is banned from joining this faction this.playerReputation = 0; //"Reputation" within faction this.alreadyInvited = false; //Multipliers for unlocking and purchasing augmentations this.augmentationPriceMult = 1; this.augmentationRepRequirementMult = 1; //Faction favor this.favor = 0; this.rolloverRep = 0; }; Faction.prototype.setAugmentationMultipliers = function(price, rep) { this.augmentationPriceMult = price; this.augmentationRepRequirementMult = rep; } Faction.prototype.setInfo = function(inf) { this.info = inf; } Faction.prototype.gainFavor = function() { if (this.favor == null || this.favor == undefined) {this.favor = 0;} if (this.rolloverRep == null || this.rolloverRep == undefined) {this.rolloverRep = 0;} var res = this.getFavorGain(); if (res.length != 2) { console.log("Error: invalid result from getFavorGain() function"); return; } this.favor += res[0]; this.rolloverRep = res[1]; } //Returns an array with [How much favor would be gained, how much favor would be left over] Faction.prototype.getFavorGain = function() { if (this.favor == null || this.favor == undefined) {this.favor = 0;} if (this.rolloverRep == null || this.rolloverRep == undefined) {this.rolloverRep = 0;} var favorGain = 0, rep = this.playerReputation + this.rolloverRep; var reqdRep = CONSTANTS.FactionReputationToFavorBase * Math.pow(CONSTANTS.FactionReputationToFavorMult, this.favor); while(rep > 0) { if (rep >= reqdRep) { ++favorGain; rep -= reqdRep; } else { break; } reqdRep *= CONSTANTS.FactionReputationToFavorMult; } return [favorGain, rep]; } //Adds all Augmentations to this faction. Faction.prototype.addAllAugmentations = function() { this.augmentations.length = 0; for (var name in Augmentations) { if (Augmentations.hasOwnProperty(name)) { this.augmentations.push(name); } } } Faction.prototype.toJSON = function() { return Generic_toJSON("Faction", this); } Faction.fromJSON = function(value) { return Generic_fromJSON(Faction, value.data); } Reviver.constructors.Faction = Faction; //Map of factions indexed by faction name let Factions = {} function loadFactions(saveString) { Factions = JSON.parse(saveString, Reviver); } function AddToFactions(faction) { var name = faction.name; Factions[name] = faction; } function factionExists(name) { return Factions.hasOwnProperty(name); } //TODO Augmentation price and rep requirement mult are 1 for everything right now, // This might change in the future for balance function initFactions() { //Endgame var Illuminati = new Faction("Illuminati"); Illuminati.setInfo(FactionInfo.IlluminatiInfo); if (factionExists("Illuminati")) { Illuminati.favor = Factions["Illuminati"].favor; delete Factions["Illuminati"]; } AddToFactions(Illuminati); var Daedalus = new Faction("Daedalus"); Daedalus.setInfo(FactionInfo.DaedalusInfo); if (factionExists("Daedalus")) { Daedalus.favor = Factions["Daedalus"].favor; delete Factions["Daedalus"]; } AddToFactions(Daedalus); var Covenant = new Faction("The Covenant"); Covenant.setInfo(FactionInfo.CovenantInfo); if (factionExists("The Covenant")) { Covenant.favor = Factions["The Covenant"].favor; delete Factions["The Covenant"]; } AddToFactions(Covenant); //Megacorporations, each forms its own faction var ECorp = new Faction("ECorp"); ECorp.setInfo(FactionInfo.ECorpInfo); if (factionExists("ECorp")) { ECorp.favor = Factions["ECorp"].favor; delete Factions["ECorp"]; } AddToFactions(ECorp); var MegaCorp = new Faction("MegaCorp"); MegaCorp.setInfo(FactionInfo.MegaCorpInfo); if (factionExists("MegaCorp")) { MegaCorp.favor = Factions["MegaCorp"].favor; delete Factions["MegaCorp"]; } AddToFactions(MegaCorp); var BachmanAndAssociates = new Faction("Bachman & Associates"); BachmanAndAssociates.setInfo(FactionInfo.BachmanAndAssociatesInfo); if (factionExists("Bachman & Associates")) { BachmanAndAssociates.favor = Factions["Bachman & Associates"].favor; delete Factions["Bachman & Associates"]; } AddToFactions(BachmanAndAssociates); var BladeIndustries = new Faction("Blade Industries"); BladeIndustries.setInfo(FactionInfo.BladeIndustriesInfo); if (factionExists("Blade Industries")) { BladeIndustries.favor = Factions["Blade Industries"].favor; delete Factions["Blade Industries"]; } AddToFactions(BladeIndustries); var NWO = new Faction("NWO"); NWO.setInfo(FactionInfo.NWOInfo); if (factionExists("NWO")) { NWO.favor = Factions["NWO"].favor; delete Factions["NWO"]; } AddToFactions(NWO); var ClarkeIncorporated = new Faction("Clarke Incorporated"); ClarkeIncorporated.setInfo(FactionInfo.ClarkeIncorporatedInfo); if (factionExists("Clarke Incorporated")) { ClarkeIncorporated.favor = Factions["Clarke Incorporated"].favor; delete Factions["Clarke Incorporated"]; } AddToFactions(ClarkeIncorporated); var OmniTekIncorporated = new Faction("OmniTek Incorporated"); OmniTekIncorporated.setInfo(FactionInfo.OmniTekIncorporatedInfo); if (factionExists("OmniTek Incorporated")) { OmniTekIncorporated.favor = Factions["OmniTek Incorporated"].favor; delete Factions["OmniTek Incorporated"]; } AddToFactions(OmniTekIncorporated); var FourSigma = new Faction("Four Sigma"); FourSigma.setInfo(FactionInfo.FourSigmaInfo); if (factionExists("Four Sigma")) { FourSigma.favor = Factions["Four Sigma"].favor; delete Factions["Four Sigma"]; } AddToFactions(FourSigma); var KuaiGongInternational = new Faction("KuaiGong International"); KuaiGongInternational.setInfo(FactionInfo.KuaiGongInternationalInfo); if (factionExists("KuaiGong International")) { KuaiGongInternational.favor = Factions["KuaiGong International"].favor; delete Factions["KuaiGong International"]; } AddToFactions(KuaiGongInternational); //Other corporations var FulcrumTechnologies = new Faction("Fulcrum Secret Technologies"); FulcrumTechnologies.setInfo(FactionInfo.FulcrumSecretTechnologiesInfo); if (factionExists("Fulcrum Secret Technologies")) { FulcrumTechnologies.favor = Factions["Fulcrum Secret Technologies"].favor; delete Factions["Fulcrum Secret Technologies"]; } AddToFactions(FulcrumTechnologies); //Hacker groups var BitRunners = new Faction("BitRunners"); BitRunners.setInfo(FactionInfo.BitRunnersInfo); if (factionExists("BitRunners")) { BitRunners.favor = Factions["BitRunners"].favor; delete Factions["BitRunners"]; } AddToFactions(BitRunners); var BlackHand = new Faction("The Black Hand"); BlackHand.setInfo(FactionInfo.BlackHandInfo); if (factionExists("The Black Hand")) { BlackHand.favor = Factions["The Black Hand"].favor; delete Factions["The Black Hand"]; } AddToFactions(BlackHand); var NiteSec = new Faction("NiteSec"); NiteSec.setInfo(FactionInfo.NiteSecInfo); if (factionExists("NiteSec")) { NiteSec.favor = Factions["NiteSec"].favor; delete Factions["NiteSec"]; } AddToFactions(NiteSec); //City factions, essentially governments var Chongqing = new Faction("Chongqing"); Chongqing.setInfo(FactionInfo.ChongqingInfo); if (factionExists("Chongqing")) { Chongqing.favor = Factions["Chongqing"].favor; delete Factions["Chongqing"]; } AddToFactions(Chongqing); var Sector12 = new Faction("Sector-12"); Sector12.setInfo(FactionInfo.Sector12Info); if (factionExists("Sector-12")) { Sector12.favor = Factions["Sector-12"].favor; delete Factions["Sector-12"]; } AddToFactions(Sector12); var NewTokyo = new Faction("New Tokyo"); NewTokyo.setInfo(FactionInfo.NewTokyoInfo); if (factionExists("New Tokyo")) { NewTokyo.favor = Factions["New Tokyo"].favor; delete Factions["New Tokyo"]; } AddToFactions(NewTokyo); var Aevum = new Faction("Aevum"); Aevum.setInfo(FactionInfo.AevumInfo); if (factionExists("Aevum")) { Aevum.favor = Factions["Aevum"].favor; delete Factions["Aevum"]; } AddToFactions(Aevum); var Ishima = new Faction("Ishima"); Ishima.setInfo var Volhaven = new Faction("Volhaven"); Volhaven.setInfo(FactionInfo.VolhavenInfo); if (factionExists("Volhaven")) { Volhaven.favor = Factions["Volhaven"].favor; delete Factions["Volhaven"]; } AddToFactions(Volhaven);(FactionInfo.IshimaInfo); if (factionExists("Ishima")) { Ishima.favor = Factions["Ishima"].favor; delete Factions["Ishima"]; } AddToFactions(Ishima); //Criminal Organizations/Gangs var SpeakersForTheDead = new Faction("Speakers for the Dead"); SpeakersForTheDead.setInfo(FactionInfo.SpeakersForTheDeadInfo); if (factionExists("Speakers for the Dead")) { SpeakersForTheDead.favor = Factions["Speakers for the Dead"].favor; delete Factions["Speakers for the Dead"]; } AddToFactions(SpeakersForTheDead); var DarkArmy = new Faction("The Dark Army"); DarkArmy.setInfo(FactionInfo.DarkArmyInfo); if (factionExists("The Dark Army")) { DarkArmy.favor = Factions["The Dark Army"].favor; delete Factions["The Dark Army"]; } AddToFactions(DarkArmy); var TheSyndicate = new Faction("The Syndicate"); TheSyndicate.setInfo(FactionInfo.TheSyndicateInfo); if (factionExists("The Syndicate")) { TheSyndicate.favor = Factions["The Syndicate"].favor; delete Factions["The Syndicate"]; } AddToFactions(TheSyndicate); var Silhouette = new Faction("Silhouette"); Silhouette.setInfo(FactionInfo.SilhouetteInfo); if (factionExists("Silhouette")) { Silhouette.favor = Factions["Silhouette"].favor; delete Factions["Silhouette"]; } AddToFactions(Silhouette); var Tetrads = new Faction("Tetrads"); //Low-medium level asian crime gang Tetrads.setInfo(FactionInfo.TetradsInfo); if (factionExists("Tetrads")) { Tetrads.favor = Factions["Tetrads"].favor; delete Factions["Tetrads"]; } AddToFactions(Tetrads); var SlumSnakes = new Faction("Slum Snakes"); //Low level crime gang SlumSnakes.setInfo(FactionInfo.SlumSnakesInfo); if (factionExists("Slum Snakes")) { SlumSnakes.favor = Factions["Slum Snakes"].favor; delete Factions["Slum Snakes"]; } AddToFactions(SlumSnakes); //Earlygame factions - factions the player will prestige with early on that don't //belong in other categories var Netburners = new Faction("Netburners"); Netburners.setInfo(FactionInfo.NetburnersInfo); if (factionExists("Netburners")) { Netburners.favor = Factions["Netburners"].favor; delete Factions["Netburners"]; } AddToFactions(Netburners); var TianDiHui = new Faction("Tian Di Hui"); //Society of the Heaven and Earth TianDiHui.setInfo(FactionInfo.TianDiHuiInfo); if (factionExists("Tian Di Hui")) { TianDiHui.favor = Factions["Tian Di Hui"].favor; delete Factions["Tian Di Hui"]; } AddToFactions(TianDiHui); var CyberSec = new Faction("CyberSec"); CyberSec.setInfo(FactionInfo.CyberSecInfo); if (factionExists("CyberSec")) { CyberSec.favor = Factions["CyberSec"].favor; delete Factions["CyberSec"]; } AddToFactions(CyberSec); } function inviteToFaction(faction) { if (Settings.SuppressFactionInvites) { faction.alreadyInvited = true; Player.factionInvitations.push(faction.name); } else { factionInvitationBoxCreate(faction); } } function joinFaction(faction) { faction.isMember = true; Player.factions.push(faction.name); //Determine what factions you are banned from now that you have joined this faction if (faction.name == "Chongqing") { Factions["Sector-12"].isBanned = true; Factions["Aevum"].isBanned = true; Factions["Volhaven"].isBanned = true; } else if (faction.name == "Sector-12") { Factions["Chongqing"].isBanned = true; Factions["New Tokyo"].isBanned = true; Factions["Ishima"].isBanned = true; Factions["Volhaven"].isBanned = true; } else if (faction.name == "New Tokyo") { Factions["Sector-12"].isBanned = true; Factions["Aevum"].isBanned = true; Factions["Volhaven"].isBanned = true; } else if (faction.name == "Aevum") { Factions["Chongqing"].isBanned = true; Factions["New Tokyo"].isBanned = true; Factions["Ishima"].isBanned = true; Factions["Volhaven"].isBanned = true; } else if (faction.name == "Ishima") { Factions["Sector-12"].isBanned = true; Factions["Aevum"].isBanned = true; Factions["Volhaven"].isBanned = true; } else if (faction.name == "Volhaven") { Factions["Chongqing"].isBanned = true; Factions["Sector-12"].isBanned = true; Factions["New Tokyo"].isBanned = true; Factions["Aevum"].isBanned = true; Factions["Ishima"].isBanned = true; } } //Displays the HTML content for a specific faction function displayFactionContent(factionName) { var faction = Factions[factionName]; document.getElementById("faction-name").innerHTML = factionName; document.getElementById("faction-info").innerHTML = "" + faction.info + ""; var repGain = faction.getFavorGain(); if (repGain.length != 2) {repGain = 0;} repGain = repGain[0]; document.getElementById("faction-reputation").innerHTML = "Reputation: " + formatNumber(faction.playerReputation, 4) + "You will earn " + formatNumber(repGain, 4) + " faction favor upon resetting after installing an Augmentation"; document.getElementById("faction-favor").innerHTML = "Faction Favor: " + formatNumber(faction.favor, 4) + "Faction favor increases the rate at which " + "you earn reputation for this faction by 1% per favor. Faction favor " + "is gained whenever you reset after installing an Augmentation. The amount of " + "favor you gain depends on how much reputation you have with the faction"; var hackMissionDiv = document.getElementById("faction-hack-mission-div"); var hackDiv = document.getElementById("faction-hack-div"); var fieldWorkDiv = document.getElementById("faction-fieldwork-div"); var securityWorkDiv = document.getElementById("faction-securitywork-div"); var donateDiv = document.getElementById("faction-donate-div"); var gangDiv = document.getElementById("faction-gang-div"); var newHackMissionButton = clearEventListeners("faction-hack-mission-button"); var newHackButton = clearEventListeners("faction-hack-button"); var newFieldWorkButton = clearEventListeners("faction-fieldwork-button"); var newSecurityWorkButton = clearEventListeners("faction-securitywork-button"); var newDonateWorkButton = clearEventListeners("faction-donate-button"); newHackMissionButton.addEventListener("click", function() { Engine.loadMissionContent(); var mission = new HackingMission(faction.playerReputation, faction); setInMission(true, mission); //Sets inMission flag to true mission.init(); return false; }); newHackButton.addEventListener("click", function() { Player.startFactionHackWork(faction); return false; }); newFieldWorkButton.addEventListener("click", function() { Player.startFactionFieldWork(faction); return false; }); newSecurityWorkButton.addEventListener("click", function() { Player.startFactionSecurityWork(faction); return false; }); newDonateWorkButton.addEventListener("click", function() { var donateAmountVal = document.getElementById("faction-donate-input").value; if (isPositiveNumber(donateAmountVal)) { var numMoneyDonate = Number(donateAmountVal); if (Player.money.lt(numMoneyDonate)) { dialogBoxCreate("You cannot afford to donate this much money!"); return; } Player.loseMoney(numMoneyDonate); var repGain = numMoneyDonate / 1000000 * Player.faction_rep_mult; faction.playerReputation += repGain; dialogBoxCreate("You just donated $" + formatNumber(numMoneyDonate, 2) + " to " + faction.name + " to gain " + formatNumber(repGain, 3) + " reputation"); displayFactionContent(factionName); } else { dialogBoxCreate("Invalid amount entered!"); } return false; }); var newPurchaseAugmentationsButton = clearEventListeners("faction-purchase-augmentations"); newPurchaseAugmentationsButton.addEventListener("click", function() { Engine.hideAllContent(); Engine.Display.factionAugmentationsContent.style.visibility = "visible"; var newBackButton = clearEventListeners("faction-augmentations-back-button"); newBackButton.addEventListener("click", function() { Engine.loadFactionContent(); displayFactionContent(factionName); return false; }); displayFactionAugmentations(factionName); return false; }); if (Player.bitNodeN == 2 && (factionName == "Slum Snakes" || factionName == "Tetrads" || factionName == "The Syndicate" || factionName == "The Dark Army" || factionName == "Speakers for the Dead" || factionName == "NiteSec" || factionName == "The Black Hand")) { //Set everything else to invisible hackDiv.style.display = "none"; fieldWorkDiv.style.display = "none"; securityWorkDiv.style.display = "none"; donateDiv.style.display = "none"; var gangDiv = document.getElementById("faction-gang-div"); if (Player.inGang() && Player.gang.facName != factionName) { //If the player has a gang but its not for this faction if (gangDiv) { gangDiv.style.display = "none"; } return; } //Create the "manage gang" button if it doesn't exist if (gangDiv == null) { gangDiv = document.createElement("div"); gangDiv.setAttribute("id", "faction-gang-div"); gangDiv.setAttribute("class", "faction-work-div"); gangDiv.style.display = "inline"; gangDiv.innerHTML = '
' + 'Create and manage a gang for this Faction. ' + 'Gangs will earn you money and faction reputation.' + '
' + '