MediaWiki:Common.js/revocalc.js

// ==UserScript== // @name        revothing // @namespace   http://rs.wikia.com/User:Gaz_Lloyd // @version     0.1 // @description enter something useful // @author      Gaz Lloyd // @match       http://runescape.wikia.com/wiki/User:Gaz_Lloyd/Sandbox_3 // @require      //ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js // @grant        GM_addStyle // ==/UserScript==

//based on work by Cook Me Plox

//TODO: move CSS to .css file /* //css for this, added via GM_addStyle (greasemonkey/tampermonkey method) GM_addStyle('#gazhover {'+           'position: absolute;'+            'background: #0d1f25;'+            'border: #463a38 3px inset;'+           // 'height: 50px;'+           // 'width: 50px;'+            'z-index: 900001;'+            '}'+            '.gazhover-hide {'+            'display: none;'+            '}');

//css for this, added via jQuery $(' #gazhover {'+           'position: absolute;'+            'background: #0d1f25;'+            'border: #463a38 3px inset;'+           // 'height: 50px;'+           // 'width: 50px;'+            'z-index: 900001;'+            '}'+            '.gazhover-hide {'+            'display: none;'+            '}' +  			' ').appendTo("head");

var abilities = {};

var melee = [];

var hideclass="gazhover-hide";

//Ability definition // Name, cooldown in ticks, duration in ticks, maximum damage, optional: minimum damage function Ability(name, img, cooldown, duration, maxdamage) { this.name = name; this.cooldown = cooldown; this.duration = duration; var mindamage = arguments.length >= 6 ? arguments[5] : maxdamage*0.2; //if specified, use mindamage, otherwise 20% of max this.damage = (maxdamage+mindamage)/2; this.cd = 0; this.img = img; this.reducecooldown = function (r) { this.cd = Math.max(this.cd-r,0); };   this.tostring = function  { var s = String(""+this.name+" "+this.cooldown+" "+this.duration+" "+this.damage+""); return s;   }; this.cooldowngroup = [this]; this.rcd = function (r) { for (var i = 0; i < this.cooldowngroup.length; i++) { this.cooldowngroup[i].reducecooldown(r); }   };    abilities[name]=this; console.log("created ability: "+this.tostring); }

function Actionbar { var ab = this; this.bar = []; for (var i = 0; i < 14; i++) { this.bar[i] = " "; }   this.setability = function(i,a) { console.log("set "+i+" to "+a.name); this.bar[i] = a;       $('li[data-actionbar-pos='+i+']').html(''); };   var hover; var selected; var output = $(' '); this.createhover = function { console.log('creating hover'); hover = $(' '); var imgs = " "; hover.html(imgs); console.log('hover created, appending'); $('body').append(hover); $('#gazhover td>img[data-hover-ability]').click(function (event) {           console.log('click event at '+$(event.target).attr('data-hover-ability').toString);            ab.setability(selected,abilities[$(event.target).attr('data-hover-ability')]);            ab.hidehover;            ab.recalc;        }); }   this.showhover = function(event) { var offset = $(event.target).offset; console.log('click event at '+offset.top+','+offset.left); hover.css({'top': (offset.top+39)+'px', 'left': offset.left+'px'}); hover.removeClass(hideclass); selected = $(event.target).attr('data-actionbar-pos'); if (selected == null || selected == undefined) selected = $(event.target).parent.attr('data-actionbar-pos'); };   this.hidehover = function { hover.addClass(hideclass); selected = null; };   this.recalc = function { var barval = trimbar(this.bar); var inside = ''; if (barval === -1) inside += "This revolution bar does not work!"; else inside += "The revolution bar has average DPT of "+(barval*100)+"%"; output.html(inside); };   this.draw = function { var inside = ""; for (var i = 0; i < 14; i++) inside += ' '; $('#gazactionbar').html(inside); };   this.draw; $('#ponies2').append(output); }

function trimbar(bar) { var tbar = []; var last = 0; for (var i = 0; i < bar.length; i++) { if (bar[i].name === undefined || bar[i].name === null) continue; tbar[last] = bar[i]; last++; }   return calcrevo(tbar); }

function setcooldowngroup(ab) { var abil = []; for (var i = 0; i < ab.length; i++) { abil[i] = abilities[ab[i]]; }   for (i = 0; i < abil.length; i++) { abil[i].cooldowngroup = abil; } }

function setupAbilities { console.log("setting up abilities..."); //attack new Ability("Slice","http://img2.wikia.nocookie.net/__cb20120626183224/runescape/images/a/ad/Slice.png",5,3,1.10,0.3); //averages 0.7 new Ability("Havoc","http://img3.wikia.nocookie.net/__cb20120626183251/runescape/images/5/5b/Havoc.png",17,3,1.25); new Ability("Backhand","http://img2.wikia.nocookie.net/__cb20120626183257/runescape/images/8/82/Backhand.png",25,3,1); new Ability("Smash","http://img1.wikia.nocookie.net/__cb20120626184615/runescape/images/2/29/Smash.png",17,3,1.25); new Ability("Barge","http://img1.wikia.nocookie.net/__cb20120626184623/runescape/images/5/5b/Barge.png",34,3,1.25); new Ability("Sever","http://img2.wikia.nocookie.net/__cb20120626184641/runescape/images/f/fa/Sever.png",25,3,1.88); //strength new Ability("Kick","http://img4.wikia.nocookie.net/__cb20120626192336/runescape/images/e/e5/Kick.png",25,3,1); new Ability("Punish","http://img2.wikia.nocookie.net/__cb20120626192343/runescape/images/7/7b/Punish.png",5,3,0.94); new Ability("Dismember","http://img1.wikia.nocookie.net/__cb20120626192352/runescape/images/8/80/Dismember.png",25,3,1.22,1.22); //averages 1.22, weirdly new Ability("Fury","http://img3.wikia.nocookie.net/__cb20120626192401/runescape/images/4/46/Fury.png",9,6,0.75+0.82+0.89); new Ability("Cleave","http://img3.wikia.nocookie.net/__cb20120626193538/runescape/images/c/c8/Cleave.png",17,3,1.88); new Ability("Decimate","http://img2.wikia.nocookie.net/__cb20120626193556/runescape/images/0/04/Decimate.png",12,3,1.88); setcooldowngroup(["Kick","Backhand"]); melee = ["Slice","Havoc","Backhand","Smash","Barge","Sever","Kick","Punish","Dismember","Fury","Cleave","Decimate"]; //autoattack placeholder //new Ability("auto","",3,3,1,0); }

function revobar(abils) { var bar = []; console.log("reading abilities..."); for (var i = 0; i < abils.length; i++) { bar[i] = abilities[abils[i]]; console.log("set abils "+abils[i]+" to "+bar[i].tostring); }   return calcrevo(bar); }

function calcrevo(bar) { console.log("calculating revolution..."); var time=0, incr=0, damage=0, next, broke=false; while (time <= 3000) { next = "auto"; for (var i in abilities) { abilities[i].rcd(incr); }       for (i = 0; i < bar.length; i++) { if (bar[i].cd === 0) { next = bar[i]; break; }       }        if (next === "auto") { console.log("autoattack here"); broke = true; break; }       next.cd = next.cooldown; incr = next.duration; time += incr; damage += next.damage; }   if (!broke) { console.log("working! simulated for "+time+" ticks, giving DPS: "+damage/time*100+"%"); return damage/time; }   else { console.log("this isn't a working revo bar"); return -1; } }

displaybar = function { setupAbilities; $('#ponies2').append(''); var ab = new Actionbar; ab.createhover; $("#gazactionbar>li").click(function(event) {       ab.showhover(event);    }); };

$(function {    console.log("ready, displaying bar");    displaybar; });