mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-18 13:43:49 +01:00
Added option to donate money to faction
This commit is contained in:
parent
0054ab7222
commit
c454e3729b
@ -274,26 +274,45 @@
|
||||
margin: 6px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#faction-hack-div,
|
||||
#faction-fieldwork-div,
|
||||
#faction-securitywork-div {
|
||||
#faction-securitywork-div,
|
||||
#faction-donate-div {
|
||||
overflow: hidden;
|
||||
width: 80%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#faction-hack-div-wrapper,
|
||||
#faction-fieldwork-div-wrapper,
|
||||
#faction-securitywork-div-wrapper {
|
||||
#faction-securitywork-div-wrapper,
|
||||
#faction-donate-div-wrapper {
|
||||
float: left;
|
||||
border: 2px solid #333;
|
||||
padding: 14px 6px 4px 6px;
|
||||
margin: 6px;
|
||||
}
|
||||
|
||||
#faction-hack-button {
|
||||
#faction-hack-button,
|
||||
#faction-fieldwork-button,
|
||||
#faction-securitywork-button {
|
||||
margin: 8px;
|
||||
}
|
||||
|
||||
#faction-donate-amount-txt,
|
||||
#faction-donate-input {
|
||||
padding: 6px;
|
||||
margin: 6px;
|
||||
display: inline-block;
|
||||
color: #66ff33;
|
||||
}
|
||||
|
||||
#faction-donate-amount-txt {
|
||||
width:50%;
|
||||
}
|
||||
|
||||
div.faction-clear {
|
||||
clear: both;
|
||||
}
|
||||
@ -301,6 +320,7 @@ div.faction-clear {
|
||||
#faction-container p {
|
||||
padding: 6px;
|
||||
margin: 6px;
|
||||
width: 80%;
|
||||
}
|
||||
|
||||
/* Faction Augmentations */
|
||||
|
30
index.html
30
index.html
@ -443,7 +443,7 @@
|
||||
|
||||
<p id="faction-reputation"></p>
|
||||
|
||||
<p id="work-description-text">
|
||||
<p id="faction-work-description-text">
|
||||
Perform work/carry out assignments for your faction to help further its cause! By doing so
|
||||
you will gain reputation for your faction. You will also gain reputation passively over time,
|
||||
although at a very slow rate. Note that you cannot
|
||||
@ -454,8 +454,8 @@
|
||||
<div id="faction-hack-div-wrapper">
|
||||
<a href="#" id="faction-hack-button" class="a-link-button">Hacking Contracts</a>
|
||||
<p id="faction-hack-text">
|
||||
Complete hacking contracts for your faction! <br>
|
||||
Your effectiveness, which determines how much reputation you gain for this faction, is based on your hacking skill. <br>
|
||||
Complete hacking contracts for your faction.
|
||||
Your effectiveness, which determines how much reputation you gain for this faction, is based on your hacking skill.
|
||||
You will gain hacking exp.
|
||||
</p>
|
||||
</div>
|
||||
@ -466,8 +466,8 @@
|
||||
<div id="faction-fieldwork-div-wrapper">
|
||||
<a href="#" id="faction-fieldwork-button" class="a-link-button">Field Work</a>
|
||||
<p id="faction-fieldwork-text">
|
||||
Carry out field missions for your faction. <br>
|
||||
Your effectiveness, which determines how much reputation you gain for this faction, is based on all of your stats. <br>
|
||||
Carry out field missions for your faction.
|
||||
Your effectiveness, which determines how much reputation you gain for this faction, is based on all of your stats.
|
||||
You will gain exp for all stats.
|
||||
</p>
|
||||
</div>
|
||||
@ -478,13 +478,29 @@
|
||||
<div id="faction-securitywork-div-wrapper">
|
||||
<a href="#" id="faction-securitywork-button" class="a-link-button">Security Work</a>
|
||||
<p id="faction-securitywork-text">
|
||||
Serve in a security detail for your faction. <br>
|
||||
Your effectiveness, which determines how much reputation you gain for this faction, is based on your combat stats. <br>
|
||||
Serve in a security detail for your faction.
|
||||
Your effectiveness, which determines how much reputation you gain for this faction, is based on your combat stats.
|
||||
You will gain exp for all combat stats.
|
||||
</p>
|
||||
</div>
|
||||
<div class="faction-clear"></div>
|
||||
</div>
|
||||
|
||||
<div id="faction-donate-div">
|
||||
<div id="faction-donate-div-wrapper">
|
||||
<a href="#" id="faction-donate-button" class="a-link-button">Donate Money</a>
|
||||
<p id="faction-donate-text">
|
||||
Donate money to your faction. You will gain reputation based on how much money you donate
|
||||
</p>
|
||||
<div>
|
||||
<label id="faction-donate-amount-txt">Enter amount to donate: $</label>
|
||||
<input id="faction-donate-input" type="number"> </input>
|
||||
</div>
|
||||
<p id="faction-donate-rep-gain"> This donation will result in 0 reputation gain</p>
|
||||
|
||||
</div>
|
||||
<div class="faction-clear"></div>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<br><br><br>
|
||||
|
@ -1,4 +1,21 @@
|
||||
//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/1000, 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
|
||||
@ -553,13 +570,14 @@ displayFactionContent = function(factionName) {
|
||||
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");
|
||||
|
||||
//Set new event listener for all of the work buttons
|
||||
//The old buttons need to be replaced to clear the old event listeners
|
||||
var newHackButton = clearEventListeners("faction-hack-button");
|
||||
var newFieldWorkButton = clearEventListeners("faction-fieldwork-button");
|
||||
var newSecurityWorkButton = clearEventListeners("faction-securitywork-button");
|
||||
|
||||
var newDonateWorkButton = clearEventListeners("faction-donate-button");
|
||||
|
||||
newHackButton.addEventListener("click", function() {
|
||||
Player.startFactionHackWork(faction);
|
||||
@ -576,6 +594,24 @@ displayFactionContent = function(factionName) {
|
||||
return false;
|
||||
});
|
||||
|
||||
newDonateWorkButton.addEventListener("click", function() {
|
||||
var donateAmountVal = document.getElementById("faction-donate-input").value;
|
||||
if (isPositiveNumber(donateAmountVal)) {
|
||||
var numMoneyDonate = Number(donateAmountVal);
|
||||
if (Player.money < numMoneyDonate) {
|
||||
dialogBoxCreate("You cannot afford to donate this much money!");
|
||||
return;
|
||||
}
|
||||
Player.loseMoney(numMoneyDonate);
|
||||
var repGain = numMoneyDonate / 1000;
|
||||
faction.playerReputation += repGain;
|
||||
dialogBoxCreate("You just donated $" + formatNumber(numMoneyDonate, 2) + " to " +
|
||||
faction.name + " to gain " + formatNumber(repGain, 3) + " reputation");
|
||||
} else {
|
||||
dialogBoxCreate("Invalid amount entered!");
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
//Set new event listener for the purchase augmentation buttons
|
||||
//The old button needs to be replaced to clear the old event listeners
|
||||
@ -596,6 +632,7 @@ displayFactionContent = function(factionName) {
|
||||
});
|
||||
|
||||
if (faction.isMember) {
|
||||
donateDiv.style.display = "inline";
|
||||
switch(faction.name) {
|
||||
case "Illuminati":
|
||||
hackDiv.style.display = "inline";
|
||||
|
@ -68,6 +68,11 @@ function isString(str) {
|
||||
return (typeof str === 'string' || str instanceof String);
|
||||
}
|
||||
|
||||
//Returns true if string contains only digits (meaning it would be a positive number)
|
||||
function isPositiveNumber(str) {
|
||||
return /^\d+$/.test(str);
|
||||
}
|
||||
|
||||
//Returns whether an array contains entirely of string objects
|
||||
function containsAllStrings(arr) {
|
||||
return arr.every(isString);
|
||||
|
Loading…
Reference in New Issue
Block a user