Advertisement
Icegoten

StatCalculator

Oct 8th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var $=window.jQuery,loc={},player={};
  2. var hits;
  3. var statSTR = $("#pro-stats span").contents()[0];
  4. var statDEX = $("#pro-stats span").contents()[1];
  5. var statINT = $("#pro-stats span").contents()[2];
  6.  
  7.  
  8. function getHits(){
  9.  return hits;
  10. }
  11.  
  12. function addHits(){
  13.     hits++;
  14. }
  15.  
  16. function getStats(stat,type) {
  17.  
  18.   var initial = 5;
  19.   var current = stat;
  20.   var hits = getHits();
  21.   var stats;
  22.   var compmod;
  23.   if (initial==5) { compmod=0.005; } else { compmod=0; }
  24.   var diff=current-initial-compmod;
  25.   var mod, modmax, modin;
  26.   var max, minmax;
  27.   var i, j, g;
  28.  
  29.     if (type == "str") {
  30.       mod=0.0009954;
  31.       max=11;
  32.       modmax=0.0012947;
  33.       minmax=9;
  34.       modin=0.0000014965;
  35.     }
  36.     else if (type == "dex") {
  37.       mod=0.00057334;
  38.       max=10;
  39.       modmax=0.00072171;
  40.       minmax=8;
  41.       modin=0.0000007418493;
  42.     }
  43.     else if (type == "int") {
  44.       mod=0.0001414791;
  45.       max=10;
  46.       modmax=0.000199425;
  47.       minmax=8;
  48.       modin=0.0000002897295;
  49.     }
  50.  
  51. max=(evalmaxStats(initial, current, hits, diff, stats, mod, modmax, modin, max, minmax, i, j, g)+evalminStats(initial, current, hits, diff, stats, mod, modmax, modin, max, minmax, i, j, g))/2;
  52.  
  53. return max;
  54.  
  55. }
  56.  
  57.  
  58. function evalmaxStats(initial, current, hits, diff, stats, mod, modmax, modin, max, minmax, i, j, g, modmod, maxmod, moddub) {
  59.   j=mod;
  60.   for (g=max; g>=minmax; g=g-0.01) {
  61.       initial = 5;
  62.       for (i=1; i<=hits; i++) {
  63.         stats=initial+(g-initial)*j;
  64.         initial=stats;
  65.  
  66.         if (((Math.round(stats*100))/100)==current && i==hits) {
  67.           return g;
  68.         }
  69.       }
  70.       j=j+modin;
  71.   }
  72. }
  73.  
  74.  
  75. function evalminStats(initial, current, hits, diff, stats, mod, modmax, modin, max, minmax, i, j, g, modmod, maxmod, moddub) {
  76.   j=modmax;
  77.   for (g=minmax; g<=max; g=g+0.01) {
  78.       initial = 5;
  79.       for (i=1; i<=hits; i++) {
  80.         stats=initial+(g-initial)*j;
  81.         initial=stats;
  82.  
  83.         if (((Math.round(stats*100))/100)==current && i==hits) {
  84.           return g;
  85.         }
  86.       }
  87.       j=j-modin;
  88.   }
  89. }
  90.  
  91. var StatCalculator = function(){
  92.   var statSTR = $("#pro-stats span").contents()[0];
  93.   var statDEX = $("#pro-stats span").contents()[1];
  94.   var statINT = $("#pro-stats span").contents()[2];
  95.  
  96.   getStats(statSTR,"str");
  97.   getStats(statDEX,"dex");
  98.   getStats(statINT,"int");
  99. };
  100.  
  101. function keepPunching() {
  102.     //for a more CircleMUD feel
  103.     if(IPOptions.AUTO_SWING) {
  104.         if(player.health<IPOptions.AUTO_SWING_THRESHOLD)
  105.         {
  106.             combatMessage("Your health is below the auto-swing threshold", "AUTO-SWING");
  107.             return;
  108.         }
  109.        
  110.         if(loc.type==="in combat!" && window.urlParams.type==="attack" && player.health>IPOptions.AUTO_FLEE)
  111.         {
  112.             setTimeout(function() {
  113.                 if(window.urlParams.hand==="RightHand") {addHits(); window.combatAttackWithRightHand();}  else {addHits(); window.combatAttackWithLeftHand();}
  114.                 combatMessage("Attacking with "+window.urlParams.hand,"AUTO-SWING");
  115.                
  116.             }, IPOptions.COMBAT_DELAY);
  117.         }
  118.         if(loc.type==="in a fight!" && window.urlParams.type==="attack" && player.health>IPOptions.AUTO_FLEE)
  119.         {
  120.             setTimeout(function() {
  121.                 if(window.urlParams.hand==="RightHand") {addHits(); window.combatAttackWithRightHand();}  else {addHits();  window.combatAttackWithLeftHand();}
  122.                 combatMessage("Attacking with "+window.urlParams.hand,"AUTO-SWING");
  123.                 addHits();
  124.             }, IPOptions.INSTANCE_DELAY);
  125.         }
  126.     }
  127.     if(IPOptions.AUTO_FLEE>0) {
  128.         if((loc.type==="in combat!" || loc.type==="in a fight!") && player.health<=IPOptions.AUTO_FLEE) {
  129.             combatMessage("Your health is below "+IPOptions.AUTO_FLEE+"%, trying to gtfo!","AUTO-FLEE");
  130.             window.combatEscape();
  131.         }
  132.     }
  133.     if(IPOptions.AUTO_REST && loc.rest===true && player.health<100) window.doRest();
  134.     if(IPOptions.AUTO_LEAVE_FORGET && loc.type==="combat site") {
  135.         if(IPOptions.AUTO_GOLD) {
  136.             setTimeout(function() {
  137.                 if(window.gotGold===true) {
  138.                     $('a[onclick^="leaveAndForgetCombatSite"]').click();
  139.                 } else {
  140.                     location.reload();//we didn't get gold, reload and try again.
  141.                 }
  142.             }, 7000); //reload after a wait to make sure we got gold
  143.         } else {
  144.             $('a[onclick^="leaveAndForgetCombatSite"]').click();
  145.         }
  146.     }
  147. }
  148.  
  149. //display stats
  150. function statDisplay() {
  151.     var settingKeys = Object.keys(IPOptions);
  152.     var settingsHtml = $(settingKeys).map(function(idx, name) {
  153.         if(typeof IPOptions[name] === "function") return "";
  154.         var sVal = IPOptions[name];
  155.         // Sanitize the setting value by checking if it's a checkbox, and converting value to a boolean.
  156.         var cb = sVal === "true" || sVal === "false";
  157.         if(cb) sVal = sVal === "true";
  158.         return "<div class='row'>" +
  159.             "<div class='cell'>" + name + "</div>" +
  160.             "<div class='cell value'><input id='" + name + "' type='" +
  161.             (typeof sVal === "boolean" ? ("checkbox" + (sVal ? "' checked='checked" : "")) : "text' value='" + sVal) + "'></div>" +
  162.             "</div>";
  163.     }).get().join("");
  164.     $(".header-stats a:last").before("<span class='hint' rel='#InitiumProSettings'><img id='gear_icon' src='"+window.IMG_GEAR+"' border='0'></span>");
  165.     $(".header-stats").append(
  166.         "<div class='hiddenTooltip' id='InitiumProSettings'>" +
  167.         "<div class='header'><h5>InitiumPro Settings</h5></div>" +
  168.         "<div class='table'>" +
  169.         settingsHtml +
  170.         "</div><br/><center><a id='resetSettings'>Default Settings</a><center></div>");
  171.     $("#resetSettings").on("click", resetDefaultSettings);
  172.     // Have to attach at the body, since cluetip functionality is done after load.
  173.     $("body").on("change", "#cluetip #InitiumProSettings input", function(event) {
  174.         var element = $(event.currentTarget);
  175.         var settingId = element.attr("id");
  176.         // We have to modify the original hidden cluetip div as well, otherwise our UI settings won't stick
  177.         if(element.is(":checkbox"))
  178.         {
  179.             // prop returns the correctly typed value of whatever property we're dealing with (in this case, bool)
  180.             $("#InitiumProSettings #"+settingId).not(element).prop("checked", element.prop("checked"));
  181.             IPOptions.ChangeSetting(settingId, element.prop("checked"));
  182.         }
  183.         else
  184.         {
  185.             // Only update the value if it's a valid number. Use + prefix to convert to number, which results in NaN if
  186.             // it's not a valid integer value. Textboxes only "change" when focus is lost.
  187.             if(!isNaN(+element.val()))
  188.             {
  189.                 $("#InitiumProSettings #"+settingId).not(element).val(+element.val());
  190.                 IPOptions.ChangeSetting(settingId, +element.val());
  191.             }
  192.         }
  193.     });
  194.     $.ajaxQueue({
  195.         url: $(".character-display-box:eq(0)").children().first().attr("rel"),
  196.     }).done(function(data) {
  197.         var stats = $(data).find('.main-item-subnote');
  198.         $(".character-display-box:eq(0) > div:eq(1)").append("<div id='pro-stats' class='buff-pane'>"+
  199.                                                              //getStats(statSTR,"str").text();
  200.                                                              "<img src='"+window.IMG_STAT_SWORD+"'><span>"+$(  stats[0] ).text().split(" ")[0]+"</span>"+//str
  201.                                                              "<img src='"+window.IMG_STAT_SHIELD+"'><span>"+$( stats[1] ).text().split(" ")[0]+"</span>"+//def
  202.                                                              "<img src='"+window.IMG_STAT_POTION+"'><span>"+$( stats[2] ).text().split(" ")[0]+"</span>"+//int
  203.                                                              "</a></div>");
  204.         $('.header-stats a:nth-child(2)').children().html("Inv<span style=\"color:#AAA;margin-left:4px;margin-right:-5px;\">("+$( stats[3] ).text().split(" ")[0]+")</span> ");//carry
  205.        
  206.         $(".character-display-box:eq(0) > div:eq(1)").append("<div id='pro-stats' class='buff-pane'>"+
  207.                                                              //getStats(statSTR,"str").text();
  208.                                                              "<img src='"+window.IMG_STAT_SWORD+"'><span>"+"Hits:"+hits+"</span>"+//str
  209.                                                              "<img src='"+window.IMG_STAT_SHIELD+"'><span>"+$( stats[1] ).text().split(" ")[0]+"</span>"+//def
  210.                                                              "<img src='"+window.IMG_STAT_POTION+"'><span>"+$( stats[2] ).text().split(" ")[0]+"</span>"+//int
  211.                                                              "</a></div>");
  212.         $('.header-stats a:nth-child(2)').children().html("Inv<span style=\"color:#AAA;margin-left:4px;margin-right:-5px;\">("+$( stats[3] ).text().split(" ")[0]+")</span> ");//carry
  213.        
  214.     });
  215. }
  216.  
  217. //utility stuff
  218. function getThisPartyStarted() {
  219.     //flags
  220.     window.FLAG_LOADSHOPS=false;
  221.     window.FLAG_LOADSHOPITEMS=false;
  222.     window.gotGold=false;
  223.     window.localItems={};
  224.     window.urlParams=getUrlParams();
  225.     //init stuff
  226.     updateCSS();
  227.     statDisplay();
  228.     getLocalGold();
  229.     getLocalStuff();
  230.     //mutation observer watches the dom
  231.     MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
  232.     //setting up observers
  233.     observe(["#instanceRespawnWarning",".popup_confirm_yes","#popups","#page-popup-root"],{childList:true,characterData:true,attributes:true,subtree:true});
  234.     //finish up when page ready
  235.     $(document).ready(function () {
  236.         $("#page-popup-root").on("click", ".page-popup-Reload", function(event){
  237.             var reloadPopup = $(event.target).parent().find(".page-popup:last");
  238.             console.log(reloadPopup);
  239.             if(reloadPopup.find("div[src^='/odp/ajax_viewstore.jsp']").length > 0)
  240.             {
  241.                 console.log("Reloading store items...");
  242.                 window.ITEM_CACHE = {};
  243.                 var contentUrlParams = getUrlParams(reloadPopup.find("div[src^='/odp/ajax_viewstore.jsp']").attr("src"));
  244.                 if(contentUrlParams["characterId"]) delete window.MERCHANT_CACHE[contentUrlParams["characterId"]];
  245.                 setTimeout(loadShopItemDetails, 500);
  246.             }
  247.             else if(reloadPopup.find("div[src^='locationmerchantlist.jsp']").length > 0){
  248.                 console.log("Reloading merchant list...");
  249.                 window.MERCHANT_CACHE = {};
  250.                 setTimeout(loadLocalMerchantDetails, 500);
  251.             }
  252.         });
  253.         player=getPlayerStats();
  254.         loc=getLocation();
  255.         updateLayouts();
  256.         putHotkeysOnMap();
  257.         keepPunching();
  258.         StatCalculator();
  259.     });
  260.     return true;
  261. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement