Skip to content

Commit

Permalink
Updates to the revive prices. (#830)
Browse files Browse the repository at this point in the history
* Make revives more generic to call.

* Include price of requested revive in displayed message.

* Show revive request message for 10 seconds instead of 2.5.

* Show revive request prices on the settings page.

* Update changelog.
  • Loading branch information
DeKleineKobini authored Jan 1, 2025
1 parent cfbcc9e commit 73bb571
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 124 deletions.
3 changes: 2 additions & 1 deletion extension/changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
{ "message": "Show an indication when Loot Ranger has not included every NPC in their scheduled attack.", "contributor": "DeKleineKobini" },
{ "message": "Update the core team titles to reflect DeKleineKobini rejoining.", "contributor": "DeKleineKobini" },
{ "message": "Update the missing hint for 'estranged' to include feet.", "contributor": "DeKleineKobini" },
{ "message": "Detect sidebar conditions better for some sidebar features.", "contributor": "DeKleineKobini" }
{ "message": "Detect sidebar conditions better for some sidebar features.", "contributor": "DeKleineKobini" },
{ "message": "Adjust revive request prices to be accurate. Prices are no longer the same for every revive provider.", "contributor": "DeKleineKobini" }
],
"removed": [
{ "message": "Removed bazaar prices from the popup, as they are set to be removed from the API.", "contributor": "DeKleineKobini" },
Expand Down
5 changes: 4 additions & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"scripts/global/functions/formatting.js",
"scripts/global/functions/utilities.js",
"scripts/global/functions/api.js",
"scripts/global/functions/api-external.js",
"scripts/global/functions/torn.js",
"scripts/background.js"
]
Expand Down Expand Up @@ -97,6 +98,7 @@
"scripts/global/functions/utilities.js",
"scripts/global/functions/torn.js",
"scripts/global/functions/api.js",
"scripts/global/functions/api-external.js",
"scripts/global/featureManager.js",
"scripts/global/elements/checkbox/ttCheckbox.js",
"scripts/global/elements/checkbox-list/ttCheckboxList.js",
Expand Down Expand Up @@ -214,7 +216,8 @@
"scripts/global/functions/database.js",
"scripts/global/functions/requires.js",
"scripts/global/functions/utilities.js",
"scripts/global/functions/api.js"
"scripts/global/functions/api.js",
"scripts/global/functions/api-external.js"
],
"run_at": "document_start"
},
Expand Down
1 change: 1 addition & 0 deletions extension/pages/popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ <h1>Stocks</h1>
<script src="../../scripts/global/functions/torn.js"></script>
<script src="../../scripts/global/functions/utilities.js"></script>
<script src="../../scripts/global/functions/api.js"></script>
<script src="../../scripts/global/functions/api-external.js"></script>
<script src="popup.js"></script>
</body>
</html>
10 changes: 2 additions & 8 deletions extension/pages/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,8 @@ <h2>
<label for="global-reviveProvider">Show a revive button for</label>
<select id="global-reviveProvider">
<option value="">none</option>
<option value="uhc">UHC</option>
<option value="nuke">NUKE</option>
<option value="imperium">The Imperium</option>
<option value="hela">HeLa</option>
<option value="shadow_healers">Shadow Healers</option>
<option value="wtf">WTF</option>
<option value="who">WHO</option>
</select>
<label class="note" for="global-reviveProvider">Revives always cost $1m or 1 Xanax.</label>
<label class="note" for="global-reviveProvider">Revives price varies per revive provider.</label>
</div>
<div class="option">
<input id="global-pageTitles" type="checkbox" />
Expand Down Expand Up @@ -1984,6 +1977,7 @@ <h2>About</h2>
<script src="../../scripts/global/functions/torn.js"></script>
<script src="../../scripts/global/functions/utilities.js"></script>
<script src="../../scripts/global/functions/api.js"></script>
<script src="../../scripts/global/functions/api-external.js"></script>
<script src="../../scripts/global/functions/pages.js"></script>
<script type="module" src="settings.js"></script>
</body>
Expand Down
30 changes: 13 additions & 17 deletions extension/pages/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,17 @@ async function setupPreferences(requireCleanup) {
addSaveDialog();
});

const reviveProviderSelectElement = _preferences.find("#global-reviveProvider");
for (const provider of REVIVE_PROVIDERS) {
reviveProviderSelectElement.appendChild(
document.newElement({
type: "option",
text: `${provider.name} (${calculateRevivePrice(provider)})`,
attributes: { value: provider.provider },
})
);
}

if (getSearchParameters().has("section"))
switchSection(_preferences.find(`#preferences > section > nav ul > li[name="${getSearchParameters().get("section")}"]`));

Expand Down Expand Up @@ -500,15 +511,7 @@ async function setupPreferences(requireCleanup) {
const provider = event.target.value;
if (!provider) return;

let origin;
if (provider === "nuke") origin = FETCH_PLATFORMS.nukefamily;
else if (provider === "uhc") origin = FETCH_PLATFORMS.uhc;
else if (provider === "imperium") origin = FETCH_PLATFORMS.imperium;
else if (provider === "hela") origin = FETCH_PLATFORMS.hela;
else if (provider === "shadow_healers") origin = FETCH_PLATFORMS.shadow_healers;
else if (provider === "wtf") origin = FETCH_PLATFORMS.wtf;
else if (provider === "who") origin = FETCH_PLATFORMS.who;

const origin = REVIVE_PROVIDERS.find((p) => p === provider)?.origin;
if (!origin) return;

if (!chrome.permissions) {
Expand Down Expand Up @@ -1270,14 +1273,7 @@ async function setupPreferences(requireCleanup) {

const reviveProvider = _preferences.find("#global-reviveProvider").value;
if (reviveProvider) {
let origin;
if (reviveProvider === "nuke") origin = FETCH_PLATFORMS.nukefamily;
else if (reviveProvider === "uhc") origin = FETCH_PLATFORMS.uhc;
else if (reviveProvider === "imperium") origin = FETCH_PLATFORMS.imperium;
else if (reviveProvider === "hela") origin = FETCH_PLATFORMS.hela;
else if (reviveProvider === "shadow_healers") origin = FETCH_PLATFORMS.shadow_healers;
else if (reviveProvider === "wtf") origin = FETCH_PLATFORMS.wtf;
else if (reviveProvider === "who") origin = FETCH_PLATFORMS.who;
const origin = REVIVE_PROVIDERS.find((p) => p === reviveProvider)?.origin;

if (origin) origins.push(origin);
}
Expand Down
1 change: 1 addition & 0 deletions extension/pages/targets/targets.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ <h2>Stakeouts</h2>
<script src="../../scripts/global/functions/torn.js"></script>
<script src="../../scripts/global/functions/utilities.js"></script>
<script src="../../scripts/global/functions/api.js"></script>
<script src="../../scripts/global/functions/api-external.js"></script>
<script src="../../scripts/global/functions/pages.js"></script>
<script type="module" src="targets.js"></script>
</body>
Expand Down
1 change: 1 addition & 0 deletions extension/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if (typeof importScripts !== "undefined")
"global/functions/formatting.js",
"global/functions/utilities.js",
"global/functions/api.js",
"global/functions/api-external.js",
"global/functions/torn.js",
]
);
Expand Down
102 changes: 5 additions & 97 deletions extension/scripts/features/revive-request/ttReviveRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@
}

async function requestRevive() {
const provider = settings.pages.global.reviveProvider || "";

const details = getUserDetails();
if (details.error) return false; // TODO - Show error message.

Expand All @@ -110,103 +108,13 @@
else if (country === "uae") country = "UAE";
else country = capitalizeText(country.replaceAll("-", " "), { everyWord: true });

const source = `TornTools v${chrome.runtime.getManifest().version}`;

if (provider === "nuke") {
const response = await fetchData("nukefamily", {
section: "api/revive-request",
method: "POST",
body: { torn_player_id: id, torn_player_name: name, torn_player_country: country, app_info: source },
relay: true,
silent: true,
succeedOnError: true,
});

if (response.success) {
displayMessage("Revive requested!");
} else {
displayMessage("Failed to request!", true);
button.removeAttribute("disabled");
console.log("TT - Failed to request a revive with Nuke!", response);
}
} else if (provider === "uhc") {
const response = await fetchData("uhc", {
section: "api/request",
method: "POST",
body: { userID: id, userName: name, factionName: faction, source },
relay: true,
silent: true,
succeedOnError: true,
});

if (response.success) {
displayMessage("Revive requested!");
} else {
displayMessage("Failed to request!", true);
button.removeAttribute("disabled");
console.log("TT - Failed to request a revive with UHC!", response);
}
} else if (provider === "imperium") {
const response = await fetchData("imperium", {
section: "revive",
method: "POST",
body: { userID: id, userName: name, factionName: faction, source },
relay: true,
silent: true,
succeedOnError: true,
});

if (response.success) {
displayMessage("Revive requested!");
} else {
displayMessage("Failed to request!", true);
button.removeAttribute("disabled");
console.log("TT - Failed to request a revive with Imperium!", response);
}
} else if (provider === "hela" || provider === "shadow_healers" || provider === "who") {
const providers = { hela: "HeLa", shadow_healers: "Shadow Healers", who: "The Wolverines" };
const response = await fetchData(provider, {
section: "request",
method: "POST",
body: {
tornid: id.toString(),
username: name,
source: source,
vendor: providers[provider],
type: "revive",
},
relay: true,
silent: true,
succeedOnError: true,
});

if (response.hasOwnProperty("contract")) {
displayMessage((response["contract"] ? "Contract " : "") + " Revive requested!");
} else {
doRequestRevive(id, name, country, faction)
.then(({ provider }) => displayMessage(`Revive requested for ${calculateRevivePrice(provider)}!`))
.catch(({ provider, response }) => {
displayMessage("Failed to request!", true);
button.removeAttribute("disabled");
console.log("TT - Failed to request a revive with " + providers[provider] + "!", response);
}
} else if (provider === "wtf") {
const response = await fetchData("wtf", {
section: "wtfapi/revive",
method: "POST",
body: { userID: id, userName: name, Faction: faction, Country: country, requestChannel: source },
relay: true,
silent: true,
succeedOnError: true,
console.log(`TT - Failed to request a revive with ${provider.name}!`, response);
});

if (response.success) {
displayMessage("Revive requested!");
} else {
displayMessage("Failed to request!", true);
button.removeAttribute("disabled");
console.log("TT - Failed to request a revive with WTF!", response);
}
} else {
console.error("There was an attempt to request revives from an non-existing provider.", settings.pages.global.reviveProvider);
}
}

function getSidebar() {
Expand All @@ -223,7 +131,7 @@
setTimeout(() => {
element.textContent = "Request Revive";
element.classList.remove("tt-revive-success");
}, 2500);
}, 10 * TO_MILLIS.SECONDS);
}
}

Expand Down
Loading

0 comments on commit 73bb571

Please sign in to comment.