Torn Extensions - Gym Torn Gain

calculates gym gain

目前為 2019-12-06 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Torn Extensions - Gym Torn Gain
// @namespace    TornExtensions
// @version      1.2
// @description  calculates gym gain
// @author       Xradiation
// @match        https://www.torn.com/gym.php
// @grant        none
// @run-at document-end
// ==/UserScript==

(function() {
    'use strict';


    //EDIT AT OWN RISK!!!
var apiKey;
if (localStorage.getItem("apiKey") === null) {
apiKey = prompt("Please enter your apiKey", "");
if (apiKey !== null && apiKey !== "" ) {
		window.localStorage.setItem('apiKey', apiKey);
	}
}else {

apiKey = window.localStorage.getItem('apiKey');

}


if (apiKey != null) {

	var Gymlist2 = [
	{
		"Gym": "Premier Fitness",
		"Energy": 5,
		"Str": 2,
		"Spe": 2,
		"Def": 2,
		"Dex": 2},
	{
		"Gym": "Average Joes",
		"Energy": 5,
		"Str": 2.4,
		"Spe": 2.4,
		"Def": 2.8,
		"Dex": 2.4},
	{
		"Gym": "Woody's Workout",
		"Energy": 5,
		"Str": 2.8,
		"Spe": 3.2,
		"Def": 3,
		"Dex": 2.8},
	{
		"Gym": "Beach Bods",
		"Energy": 5,
		"Str": 3.2,
		"Spe": 3.2,
		"Def": 3.2,
		"Dex": "-"},
	{
		"Gym": "Silver Gym",
		"Energy": 5,
		"Str": 3.4,
		"Spe": 3.6,
		"Def": 3.4,
		"Dex": 3.2},
	{
		"Gym": "Pour Femme",
		"Energy": 5,
		"Str": 3.4,
		"Spe": 3.6,
		"Def": 3.6,
		"Dex": 3.8},
	{
		"Gym": "Davies Den",
		"Energy": 5,
		"Str": 3.7,
		"Spe": "-",
		"Def": 3.7,
		"Dex": 3.7},
	{
		"Gym": "Global Gym",
		"Energy": 5,
		"Str": 4,
		"Spe": 4,
		"Def": 4,
		"Dex": 4},
	{
		"Gym": "Knuckle Heads",
		"Energy": 10,
		"Str": 4.8,
		"Spe": 4.4,
		"Def": 4,
		"Dex": 4.2},
	{
		"Gym": "Pioneer Fitness",
		"Energy": 10,
		"Str": 4.4,
		"Spe": 4.6,
		"Def": 4.8,
		"Dex": 4.4},
	{
		"Gym": "Anabolic Anomalies",
		"Energy": 10,
		"Str": 5,
		"Spe": 4.6,
		"Def": 5.2,
		"Dex": 4.6},
	{
		"Gym": "Core",
		"Energy": 10,
		"Str": 5,
		"Spe": 5.2,
		"Def": 5,
		"Dex": 5},
	{
		"Gym": "Racing Fitness",
		"Energy": 10,
		"Str": 5,
		"Spe": 5.4,
		"Def": 4.8,
		"Dex": 5.2},
	{
		"Gym": "Complete Cardio",
		"Energy": 10,
		"Str": 5.5,
		"Spe": 5.8,
		"Def": 5.5,
		"Dex": 5.2},
	{
		"Gym": "Legs, Bums and Tums",
		"Energy": 10,
		"Str": "-",
		"Spe": 5.6,
		"Def": 5.6,
		"Dex": 5.8},
	{
		"Gym": "Deep Burn",
		"Energy": 10,
		"Str": 6,
		"Spe": 6,
		"Def": 6,
		"Dex": 6},
	{
		"Gym": "Apollo Gym",
		"Energy": 10,
		"Str": 6,
		"Spe": 6.2,
		"Def": 6.4,
		"Dex": 6.2},
	{
		"Gym": "Gun Shop",
		"Energy": 10,
		"Str": 6.6,
		"Spe": 6.4,
		"Def": 6.2,
		"Dex": 6.2},
	{
		"Gym": "Force Training",
		"Energy": 10,
		"Str": 6.4,
		"Spe": 6.6,
		"Def": 6.4,
		"Dex": 6.8},
	{
		"Gym": "Cha Cha's",
		"Energy": 10,
		"Str": 6.4,
		"Spe": 6.4,
		"Def": 6.8,
		"Dex": 7},
	{
		"Gym": "Atlas",
		"Energy": 10,
		"Str": 7,
		"Spe": 6.4,
		"Def": 6.4,
		"Dex": 6.6},
	{
		"Gym": "Last Round",
		"Energy": 10,
		"Str": 6.8,
		"Spe": 6.6,
		"Def": 7,
		"Dex": 6.6},
	{
		"Gym": "The Edge",
		"Energy": 10,
		"Str": 6.8,
		"Spe": 7,
		"Def": 7,
		"Dex": 6.8},
	{
		"Gym": "George's",
		"Energy": 10,
		"Str": 7.3,
		"Spe": 7.3,
		"Def": 7.3,
		"Dex": 7.3},
	{
		"Gym": "Balboas Gym",
		"Energy": 25,
		"Str": "-",
		"Spe": "-",
		"Def": 7.5,
		"Dex": 7.5},
	{
		"Gym": "Frontline Fitness",
		"Energy": 25,
		"Str": 7.5,
		"Spe": 7.5,
		"Def": "-",
		"Dex": "-"},
	{
		"Gym": "Gym 3000",
		"Energy": 50,
		"Str": 8,
		"Spe": "-",
		"Def": "-",
		"Dex": "-"},
	{
		"Gym": "Mr. Isoyamas",
		"Energy": 50,
		"Str": "-",
		"Spe": "-",
		"Def": 8,
		"Dex": "-"},
	{
		"Gym": "Total Rebound",
		"Energy": 50,
		"Str": "-",
		"Spe": 8,
		"Def": "-",
		"Dex": "-"},
	{
		"Gym": "Elites",
		"Energy": 50,
		"Str": "-",
		"Spe": "-",
		"Def": "-",
		"Dex": 8},
	{
		"Gym": "Sports Science Lab",
		"Energy": 25,
		"Str": 9,
		"Spe": 9,
		"Def": 9,
		"Dex": 9}
	];

	var Gym,
	gymNumber,
	speed, strength, defense, dexterity,
	strength_modifier, defense_modifier, speed_modifier, dexterity_modifier;

	var modifierSpe = 1;
	var modifierAll = 1;
	var modifierStr = 1;
	var modifierDex = 1;
	var modifierDef = 1;

	var a = 3.480061091 * Math.pow(10, -7);

	var b = 250;

	var c = 3.091619094 * Math.pow(10, -6);

	var d = 6.82775184551527 * Math.pow(10, -5);

	var e = -0.0301431777;

	var happy, energy, i, n;

	// if(document.getElementById("gymroot")){
		var urlStats = 'https://api.torn.com/user/?selections=battlestats&key=' + apiKey;
		var urlGym = 'https://api.torn.com/user/?selections=gym&key=' + apiKey;
		var urlHappy = 'https://api.torn.com/user/?selections=bars&key=' + apiKey;
		var urlMerits = 'https://api.torn.com/user/?selections=perks&key=' + apiKey;


	var apiRequest1 = fetch(urlStats).then(function(response){
			 return response.json();
	});
	var apiRequest2 = fetch(urlHappy).then(function(response){
			 return response.json();
	});
	var apiRequest3 = fetch(urlGym).then(function(response){
			 return response.json();
	});
	var apiRequest4 = fetch(urlMerits).then(function(response){
			 return response.json();
	});
	if( apiRequest1 != null && apiRequest2 != null && apiRequest3 != null && apiRequest4 != null){
		Promise.all([apiRequest1,apiRequest2,apiRequest3,apiRequest4]).then(function(data){

				//apiRequest1
				strength = data[0].strength;
				defense = data[0].defense;
				speed = data[0].speed;
				dexterity = data[0].dexterity;
				strength_modifier = data[0].strength_modifier;
				defense_modifier = data[0].defense_modifier;
				speed_modifier = data[0].speed_modifier;
				dexterity_modifier = data[0].dexterity_modifier;

				//apiRequest2
				happy = data[1].happy.current;
				energy = data[1].energy.current;

				//apiRequest3
				Gym = Gymlist2[data[2].active_gym - 1].Gym;
				gymNumber = data[2].active_gym - 1;

				//apiRequest4
				var string;
				if(data[3].hasOwnProperty('property_perks')){
					for (i = 0; i < data[3].property_perks.length; i++) {
						string = data[3].property_perks[i];
						if(string.includes('Gym gains')){
							n = parseFloat( data[3].property_perks[i].match(/\d+/)[0] );
							n = ( n /100) + 1;
							modifierAll *= n;
						}
					}
				}

				if(data[3].hasOwnProperty('education_perks')){
					for (i = 0; i < data[3].education_perks.length; i++) {
						string = data[3].education_perks[i];
						if(string.includes('1% Gym gains')){
							modifierAll *= 1.01;
						}
						if(string.includes('Dexterity gym gains')){
							modifierDex *= 1.01;
						}
						if(string.includes('Defense gym gains')){
							modifierDef *= 1.01;
						}
						if(string.includes('Speed gym gains')){
							modifierSpe *= 1.01;
						}
						if(string.includes('Strength gym gains')){
							modifierStr *= 1.01;
						}
					}
				}

				if(data[3].hasOwnProperty('company_perks')){
					for (i = 0; i < data[3].company_perks.length; i++) {
						string = data[3].company_perks[i];
						if(string.includes('dexterity gym gains')){
							modifierDex *= 1.1;
						}
						else if(string.includes('defense gym gains')){
							modifierDef *= 1.1;
						}
						else if(string.includes('gym gains')){
							modifierAll *= 1.03;
						}
					}
				}

				if(data[3].hasOwnProperty('book_perks')){
					for (i = 0; i < data[3].book_perks.length; i++) {
						string = data[3].book_perks[i];
						if(string.includes('all gym gains')){
							modifierAll *= 1.2;
						}
						else if(string.includes('Strength gym gains')){
							modifierStr *= 1.3;
						}
						else if(string.includes('Defense gym gains')){
							modifierDef *= 1.3;
						}
						else if(string.includes('Speed gym gains')){
							modifierSpe *= 1.3;
						}
						else if(string.includes('Dexterity gym gains')){
							modifierDex *= 1.3;
						}
					}
				}


				if(data[3].hasOwnProperty('faction_perks')){
					for (i = 0; i < data[3].faction_perks.length; i++) {
						string = data[3].faction_perks[i];
						if(string.includes('strength gym gains')){
							n = parseFloat( data[3].faction_perks[i].match(/\d+/)[0] );
							n = (n/100) + 1;
							modifierStr *= n;
						}
						if(string.includes('speed gym gains')){
							n = parseFloat( data[3].faction_perks[i].match(/\d+/)[0] );
							n = (n/100) + 1;
							modifierSpe *= n;
						}
						if(string.includes('defense gym gains')){
							n = parseFloat( data[3].faction_perks[i].match(/\d+/)[0] );
							n = (n/100) + 1;
							modifierDef *= n;
						}
						if(string.includes('dexterity gym gains by')){
							n = parseFloat( data[3].faction_perks[i].match(/\d+/)[0] );
							n = (n/100) + 1;
							modifierDex *= n;
						}
					}
				}
				modifierStr *= modifierAll;
				modifierSpe *= modifierAll;
				modifierDef *= modifierAll;
				modifierDex *= modifierAll;

				var GymDotsSpe = Gymlist2[gymNumber].Spe;
				var GymDotsDef = Gymlist2[gymNumber].Def;
				var GymDotsDex = Gymlist2[gymNumber].Dex;
				var GymDotsStr = Gymlist2[gymNumber].Str;

				var EnergyPerTrain = Gymlist2[gymNumber].Energy;

				var trains = Math.round( energy / EnergyPerTrain - 0.1 );

				var gainSpe = (modifierSpe)*(GymDotsSpe)*(EnergyPerTrain)*( (a * Math.log(Math.abs(happy + b)) + c) * (speed) + d*(happy+b) + e );
				var gainDef = (modifierDef)*(GymDotsDef)*(EnergyPerTrain)*( (a * Math.log(Math.abs(happy + b)) + c) * (defense) + d*(happy+b) + e );
				var gainDex = (modifierDex)*(GymDotsDef)*(EnergyPerTrain)*( (a * Math.log(Math.abs(happy + b)) + c) * (dexterity) + d*(happy+b) + e );
				var gainStr = (modifierStr)*(GymDotsStr)*(EnergyPerTrain)*( (a * Math.log(Math.abs(happy + b)) + c) * (strength) + d*(happy+b) + e );

				var strText ='<div class="propertyTitle___36JU1 fontSize14___3E9pW"><h3 class="title___3FTtc">' + Math.round(gainStr * 100) / 100 + '</h3><span class="propertyValue___3oAOv">'+ (Math.round(gainStr * 100 * trains) / 100) +'</span></div>';
				var defText ='<div class="propertyTitle___36JU1 fontSize14___3E9pW"><h3 class="title___3FTtc">' + Math.round(gainDef * 100) / 100 + '</h3><span class="propertyValue___3oAOv">'+ (Math.round(gainDef * 100 * trains) / 100) +'</span></div>';
				var speText ='<div class="propertyTitle___36JU1 fontSize14___3E9pW"><h3 class="title___3FTtc">' + Math.round(gainSpe * 100) / 100 + '</h3><span class="propertyValue___3oAOv">'+ (Math.round(gainSpe * 100 * trains) / 100) +'</span></div>';
				var dexText ='<div class="propertyTitle___36JU1 fontSize14___3E9pW"><h3 class="title___3FTtc">' + Math.round(gainDex * 100) / 100 + '</h3><span class="propertyValue___3oAOv">'+ (Math.round(gainDex * 100 * trains) / 100) +'</span></div>';

					var array = [{'speText':speText, 'value':GymDotsSpe}, {'defText':defText,'value':GymDotsDef}, {'dexText':dexText,'value':GymDotsDex}, {'strText':strText,'value':GymDotsStr}];
					var largest= [{'value': 0}];

					array.forEach(function(element) {
						if (element.value>largest[0].value) {
							largest = [element];
						}
						else if (element.value == largest[0].value) {
							largest.push(element);
						}
					});
					i = 0;
					largest.forEach(function(e) {
						var x = Object.keys(e)[0];
                        array[i][x] = e[x].replace('<div class="propertyTitle___36JU1 fontSize14___3E9pW">','<div class="propertyTitle___36JU1 fontSize14___3E9pW" style="color:lightgreen;">');
						i++;
					});


				$(array[3]['strText']).insertAfter( ".strength___1GeGr .propertyTitle___36JU1" );
            console.log(array[3]['strText']);
				$(array[1]['defText']).insertAfter( ".defense___311kR .propertyTitle___36JU1" );
console.log(array[1]['defText']);
				$(array[0]['speText']).insertAfter( ".speed___1o1b_ .propertyTitle___36JU1" );
console.log(array[0]['speText']);
				$(array[2]['dexText']).insertAfter( ".dexterity___1YdUM .propertyTitle___36JU1" );
            console.log(array[2]['dexText']);
		});
	}

}else {
	window.alert("Input a value for apiKey!!");
	apiKey = prompt("Please enter your apiKey", "");
	if (apiKey !== null && apiKey !== "" ) {
		window.localStorage.setItem('apiKey', apiKey);
	}
}

})();