Fixing Gang-rework bugs

This commit is contained in:
danielyxie 2018-10-02 18:01:37 -05:00
parent 45c434aa35
commit 00741be6c0

@ -21,6 +21,7 @@ import {numeralWrapper} from "./ui/numeralFormat";
import {dialogBoxCreate} from "../utils/DialogBox"; import {dialogBoxCreate} from "../utils/DialogBox";
import {Reviver, Generic_toJSON, import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver"; Generic_fromJSON} from "../utils/JSONReviver";
import {KEY} from "../utils/helpers/keyCodes";
import {createAccordionElement} from "../utils/uiHelpers/createAccordionElement"; import {createAccordionElement} from "../utils/uiHelpers/createAccordionElement";
import {createElement} from "../utils/uiHelpers/createElement"; import {createElement} from "../utils/uiHelpers/createElement";
import {createPopup} from "../utils/uiHelpers/createPopup"; import {createPopup} from "../utils/uiHelpers/createPopup";
@ -951,38 +952,66 @@ function displayGangContent() {
id:"gang-management-recruit-member-btn", class:"a-link-button-inactive", id:"gang-management-recruit-member-btn", class:"a-link-button-inactive",
innerHTML:"Recruit Gang Member", display:"inline-block", margin:"10px", innerHTML:"Recruit Gang Member", display:"inline-block", margin:"10px",
clickListener:()=>{ clickListener:()=>{
var yesBtn = yesNoTxtInpBoxGetYesButton(), noBtn = yesNoTxtInpBoxGetNoButton(); let popupId = "recruit-gang-member-popup";
yesBtn.innerHTML = "Recruit Gang Member";
noBtn.innerHTML = "Cancel"; let yesBtn;
yesBtn.addEventListener("click", ()=>{ const txt = createElement("p", {
var name = yesNoTxtInpBoxGetInput(); innerText:"Please enter a name for your new Gang member:",
if (name === "") { });
dialogBoxCreate("You must enter a name for your Gang member!"); const br = createElement("br");
} else { const nameInput = createElement("input", {
for (var i = 0; i < Player.gang.members.length; ++i) { onkeyup: (e) => {
if (name == Player.gang.members[i].name) { if (e.keyCode === KEY.ENTER) { yesBtn.click(); }
dialogBoxCreate("You already have a gang member with this name!"); },
return false; placeholder: "Name must be unique",
} type: "text",
});
yesBtn = createElement("a", {
class: "a-link-button",
clickListener: () => {
let name = nameInput.value;
// Check for already-existing names
let sameNames = Player.gang.members.filter((m) => {
return m.name === name;
});
if (sameNames.length >= 1) {
dialogBoxCreate("You already have a gang member with this name!");
return false;
} }
var member = new GangMember(name);
Player.gang.members.push(member); if (name === "") {
createGangMemberDisplayElement(member); dialogBoxCreate("You must enter a name for your Gang member!");
updateGangContent(); } else {
} let member = new GangMember(name);
yesNoTxtInpBoxClose(); Player.gang.members.push(member);
createGangMemberDisplayElement(member);
updateGangContent();
removeElementById(popupId);
}
return false;
},
innerText: "Recruit Gang Member",
}); });
noBtn.addEventListener("click", ()=>{ const noBtn = createElement("a", {
yesNoTxtInpBoxClose(); class: "a-link-button",
clickListener: () => {
removeElementById(popupId);
return false;
},
innerText: "Cancel",
}); });
yesNoTxtInpBoxCreate("Please enter a name for your new Gang member:"); createPopup(popupId, [txt, br, nameInput, yesBtn, noBtn]);
return false;
} }
}); });
gangManagementSubpage.appendChild(gangRecruitMemberButton); gangManagementSubpage.appendChild(gangRecruitMemberButton);
//Text for how much reputation is required for recruiting next memberList // Text for how much reputation is required for recruiting next memberList
gangRecruitRequirementText = createElement("p", {color:"red", id:"gang-recruit-requirement-text"}); gangRecruitRequirementText = createElement("p", {
color:"red",
id: "gang-recruit-requirement-text",
margin: "10px",
});
gangManagementSubpage.appendChild(gangRecruitRequirementText); gangManagementSubpage.appendChild(gangRecruitRequirementText);
//Gang Member List management buttons (Expand/Collapse All, select a single member) //Gang Member List management buttons (Expand/Collapse All, select a single member)
@ -1151,14 +1180,14 @@ function updateGangContent() {
wantedPenalty = (1 - wantedPenalty) * 100; wantedPenalty = (1 - wantedPenalty) * 100;
gangInfo.appendChild(createElement("p", { //Wanted Level multiplier gangInfo.appendChild(createElement("p", { //Wanted Level multiplier
display:"inline-block", display:"inline-block",
innerText:`Wanted Level Penalty: - ${formatNumber(wantedPenalty, 2)}%`, innerText:`Wanted Level Penalty: -${formatNumber(wantedPenalty, 2)}%`,
tooltip:"Penalty for respect and money gain rates due to Wanted Level" tooltip:"Penalty for respect and money gain rates due to Wanted Level"
})); }));
gangInfo.appendChild(createElement("br", {})); gangInfo.appendChild(createElement("br", {}));
gangInfo.appendChild(createElement("p", { //Money gain rate gangInfo.appendChild(createElement("p", { //Money gain rate
display:"inline-block", display:"inline-block",
innerText: `Money gain rate: ${numeralWrapper.format(5 * Player.gang.moneyGainRate, $0.000a)} / sec`); innerText: `Money gain rate: ${numeralWrapper.format(5 * Player.gang.moneyGainRate, "$0.000a")} / sec`,
})); }));
gangInfo.appendChild(createElement("br", {})); gangInfo.appendChild(createElement("br", {}));
@ -1189,19 +1218,21 @@ function updateGangContent() {
} }
//Toggle the 'Recruit member button' if valid //Toggle the 'Recruit member button' if valid
var numMembers = Player.gang.members.length; const numMembers = Player.gang.members.length;
const respectCost = Player.gang.getRespectNeededToRecruitMember(); const respectCost = Player.gang.getRespectNeededToRecruitMember();
const btn = gangRecruitMemberButton;
if (numMembers >= MaximumGangMembers) { if (numMembers >= MaximumGangMembers) {
btn.className = "a-link-button-inactive"; btn.className = "a-link-button-inactive";
gangRecruitRequirementText.style.display = "block"; gangRecruitRequirementText.style.display = "inline-block";
gangRecruitRequirementText.innerHTML = "You have reached the maximum amount of gang members"; gangRecruitRequirementText.innerHTML = "You have reached the maximum amount of gang members";
} else if (Player.gang.canRecruitMember()) { } else if (Player.gang.canRecruitMember()) {
btn.className = "a-link-button"; btn.className = "a-link-button";
gangRecruitRequirementText.style.display = "none"; gangRecruitRequirementText.style.display = "none";
} else { } else {
btn.className = "a-link-button-inactive"; btn.className = "a-link-button-inactive";
gangRecruitRequirementText.style.display = "block"; gangRecruitRequirementText.style.display = "inline-block";
gangRecruitRequirementText.innerHTML = `${formatNumber(repCost, 2)} respect needed to recruit next member`; gangRecruitRequirementText.innerHTML = `${formatNumber(respectCost, 2)} respect needed to recruit next member`;
} }
//Update information for each gang member //Update information for each gang member