bitburner-src/utils/InfiltrationBox.js

130 lines
6.0 KiB
JavaScript
Raw Normal View History

import {BitNodeMultipliers} from "../src/BitNode";
import {CONSTANTS} from "../src/Constants";
import {Factions, Faction} from "../src/Faction";
import {Player} from "../src/Player";
import {dialogBoxCreate} from "./DialogBox";
import {clearEventListeners} from "./uiHelpers/clearEventListeners";
2018-06-22 23:30:24 +02:00
import {formatNumber} from "./StringHelperFunctions";
//Keep track of last faction
var lastFac = "";
/* InfiltrationBox.js */
function infiltrationBoxClose() {
var box = document.getElementById("infiltration-box-container");
box.style.display = "none";
}
function infiltrationBoxOpen() {
var box = document.getElementById("infiltration-box-container");
box.style.display = "block";
}
function infiltrationSetText(txt) {
var textBox = document.getElementById("infiltration-box-text");
textBox.innerHTML = txt;
}
//ram argument is in GB
function infiltrationBoxCreate(inst) {
2017-09-08 04:56:27 +02:00
//Gain exp
2018-03-12 20:39:04 +01:00
var expMultiplier = 2 * inst.clearanceLevel / inst.maxClearanceLevel;
Player.gainHackingExp(inst.hackingExpGained * expMultiplier);
Player.gainStrengthExp(inst.strExpGained * expMultiplier);
Player.gainDefenseExp(inst.defExpGained * expMultiplier);
Player.gainDexterityExp(inst.dexExpGained * expMultiplier);
Player.gainAgilityExp(inst.agiExpGained * expMultiplier);
Player.gainCharismaExp(inst.chaExpGained * expMultiplier);
Player.gainIntelligenceExp(inst.intExpGained * expMultiplier);
2017-09-15 16:06:59 +02:00
var totalValue = 0;
for (var i = 0; i < inst.secretsStolen.length; ++i) {
totalValue += inst.secretsStolen[i];
}
if (totalValue == 0) {
dialogBoxCreate("You successfully escaped the facility but you did not steal " +
"anything of worth when infiltrating.<br><br>" +
"You gained:<br>" +
formatNumber(inst.hackingExpGained, 3) + " hacking exp<br>" +
formatNumber(inst.strExpGained, 3) + " str exp<br>" +
formatNumber(inst.defExpGained, 3) + " def exp<br>" +
formatNumber(inst.dexExpGained, 3) + " dex exp<br>" +
formatNumber(inst.agiExpGained, 3) + " agi exp<br>" +
formatNumber(inst.chaExpGained, 3) + " cha exp<br>");
return;
}
var facValue = totalValue * Player.faction_rep_mult *
CONSTANTS.InfiltrationRepValue * BitNodeMultipliers.InfiltrationRep;
var moneyValue = totalValue * CONSTANTS.InfiltrationMoneyValue * BitNodeMultipliers.InfiltrationMoney;
infiltrationSetText("You can sell the classified documents and secrets " +
"you stole from " + inst.companyName + " for $" +
formatNumber(moneyValue, 2) + " on the black market or you can give it " +
"to a faction to gain " + formatNumber(facValue, 3) + " reputation with " +
"that faction.");
var selector = document.getElementById("infiltration-faction-select");
selector.innerHTML = "";
for (let i = 0; i < Player.factions.length; ++i) {
if (Player.factions[i] === "Bladeburners") {continue;}
selector.innerHTML += "<option value='" + Player.factions[i] +
"'>" + Player.factions[i] + "</option>";
}
//Set initial value, if applicable
if (lastFac !== "") {
for (let i = 0; i < selector.options.length; ++i) {
if (selector.options[i].value === lastFac) {
selector.selectedIndex = i;
break;
}
}
}
var sellButton = clearEventListeners("infiltration-box-sell");
setTimeout(function() {
sellButton.addEventListener("click", function(e) {
if (!e.isTrusted) {return false;}
Player.gainMoney(moneyValue);
dialogBoxCreate("You sold the classified information you stole from " + inst.companyName +
" for $" + moneyValue + " on the black market!<br><br>" +
"You gained:<br>" +
formatNumber(inst.hackingExpGained, 3) + " hacking exp<br>" +
formatNumber(inst.strExpGained, 3) + " str exp<br>" +
formatNumber(inst.defExpGained, 3) + " def exp<br>" +
formatNumber(inst.dexExpGained, 3) + " dex exp<br>" +
formatNumber(inst.agiExpGained, 3) + " agi exp<br>" +
formatNumber(inst.chaExpGained, 3) + " cha exp<br>");
infiltrationBoxClose();
return false;
});
}, 750);
var factionButton = clearEventListeners("infiltration-box-faction");
setTimeout(function() {
factionButton.addEventListener("click", function(e) {
if (!e.isTrusted) {return false;}
var facName = selector.options[selector.selectedIndex].value;
lastFac = facName;
var faction = Factions[facName];
if (faction == null) {
dialogBoxCreate("Error finding faction. This is a bug please report to developer");
return false;
}
2017-07-22 00:54:55 +02:00
faction.playerReputation += facValue;
dialogBoxCreate("You gave the classified information you stole from " + inst.companyName +
" to " + facName + " and gained " + formatNumber(facValue, 3) + " reputation with the faction. <br><br>" +
"You gained:<br>" +
formatNumber(inst.hackingExpGained, 3) + " hacking exp<br>" +
formatNumber(inst.strExpGained, 3) + " str exp<br>" +
formatNumber(inst.defExpGained, 3) + " def exp<br>" +
formatNumber(inst.dexExpGained, 3) + " dex exp<br>" +
formatNumber(inst.agiExpGained, 3) + " agi exp<br>" +
formatNumber(inst.chaExpGained, 3) + " cha exp<br>");
infiltrationBoxClose();
return false;
});
}, 750);
infiltrationBoxOpen();
}
export {infiltrationBoxCreate};