Skip to content

Instantly share code, notes, and snippets.

@smj72
Last active February 21, 2018 07:32
Show Gist options
  • Save smj72/bd81b6fd62ff2b8b5a89 to your computer and use it in GitHub Desktop.
Save smj72/bd81b6fd62ff2b8b5a89 to your computer and use it in GitHub Desktop.
cRPG equipment page info addon
// ==UserScript==
// @name cRPG equipment page info addon
// @description Adds item weight and effective WPF info to inventory page
// @namespace crpg.addons
// @include http://c-rpg.net/index.php?page=equipinvgear*
// @include http://c-rpg.net/?page=equipinvgear*
// @downloadURL https://gist.github.com/smj72/bd81b6fd62ff2b8b5a89/raw/cRPGInfoAddon.user.js
// @version 0.0.6
// @grant none
// ==/UserScript==
var armorWeight = null;
var effectiveArmorWeight = null;
var effectiveWeightLabel = null;
var weaponWeight = null;
var weightLabel = null;
var totalweightLabel = null;
var e1hWpfElement = null;
var e2hWpfElement = null;
var poleWpfElement = null;
var throwWpfElement = null;
var xbowWpfElement = null;
var archeryWpfElement = null;
var head = null;
var body = null;
var legs = null;
var hand = null;
var item1 = null;
var item2 = null;
var item3 = null;
var item4 = null;
var basePT = null;
var basePD = null;
var baseIF = null;
var baseStr = null;
var base1hWpf = null;
var base2hWpf = null;
var basePoleWpf = null;
var baseThrowWpf = null;
var baseXbowWpf = null;
var baseArcheryWpf = null;
var isChrome = null;
var isFirefox = null;
function UpdateArmorWeight()
{
var headItem = null;
var bodyItem = null;
var legsItem = null;
var handItem = null;
if(isFirefox)
{
headItem = unsafeWindow.getItem(head.options[head.selectedIndex].value);
bodyItem = unsafeWindow.getItem(body.options[body.selectedIndex].value);
legsItem = unsafeWindow.getItem(legs.options[legs.selectedIndex].value);
handItem = unsafeWindow.getItem(hand.options[hand.selectedIndex].value);
}
else
{ // Chrome
headItem = window.getItem(head.options[head.selectedIndex].value);
bodyItem = window.getItem(body.options[body.selectedIndex].value);
legsItem = window.getItem(legs.options[legs.selectedIndex].value);
handItem = window.getItem(hand.options[hand.selectedIndex].value);
}
var weight = 0;
effectiveArmorWeight = 0;
armorWeight = 0;
if(headItem != null){
weight += headItem.weight;
effectiveArmorWeight += 2*headItem.weight;}
if(bodyItem != null){
weight += bodyItem.weight;
effectiveArmorWeight += bodyItem.weight;}
if(legsItem != null){
weight += legsItem.weight;
effectiveArmorWeight += legsItem.weight;}
if(handItem != null){
weight += handItem.weight;
effectiveArmorWeight += 6*handItem.weight;}
armorWeight = weight.toFixed(1);
weightLabel.innerHTML = armorWeight;
if(armorWeight != null)
{
UpdateItemWeight();
total = (parseFloat(armorWeight) + parseFloat(weaponWeight)).toFixed(1);
totalweightLabel.innerHTML = total;
}
effectiveArmorWeight = Math.pow(Math.max(effectiveArmorWeight - Math.max(Math.max(baseIF * 2, (baseStr/3 + 1)), 6),0), 1.12).toFixed(1);
effectiveWeightLabel.innerHTML = effectiveArmorWeight;
UpdateWpfTable();
}
function UpdateItemWeight(){
var item1Item = null;
var item2Item = null;
var item3Item = null;
var item4Item = null;
if(isFirefox)
{
item1Item = unsafeWindow.getItem(item1.options[item1.selectedIndex].value);
item2Item = unsafeWindow.getItem(item2.options[item2.selectedIndex].value);
item3Item = unsafeWindow.getItem(item3.options[item3.selectedIndex].value);
item4Item = unsafeWindow.getItem(item4.options[item4.selectedIndex].value);
}
else
{
item1Item = window.getItem(item1.options[item1.selectedIndex].value);
item2Item = window.getItem(item2.options[item2.selectedIndex].value);
item3Item = window.getItem(item3.options[item3.selectedIndex].value);
item4Item = window.getItem(item4.options[item4.selectedIndex].value);
}
var weight = 0;
if(item1Item != null){
weight += item1Item.weight;}
if(item2Item != null){
weight += item2Item.weight;}
if(item3Item != null){
weight += item3Item.weight;}
if(item4Item != null){
weight += item4Item.weight;}
weaponWeight = weight.toFixed(1);
if(armorWeight != null && weaponWeight != null)
{
total = (parseFloat(armorWeight) + parseFloat(weaponWeight)).toFixed(1);
totalweightLabel.innerHTML = total;
}
}
function CalculateWpf(baseWpf){
// src: http://forum.melee.org/beginner%27s-help-and-guides/game-mechanic-megathread!/msg341261/#msg341261
// Armor weight modified proficiency = base proficiency * (1 - 0.01 * effective armor weight)
// Effective armor weight = 2*head armor weight + body armor weight + leg armor weight + 6*hand armor weight - a dynamic weight threshold of the max of 6, STR / 3 + 1, and IF * 2
// (Source: WaltF4, updated 31.7.2012 based on the new formula)
// Slightly outdated, but very close to actual wpf//
return Math.ceil((Math.abs((2 * effectiveArmorWeight)/3 - 100) * baseWpf) / 100);
}
function CalculateWpfRanged(baseWpf){
// src: http://forum.melee.org/beginner%27s-help-and-guides/game-mechanic-megathread!/msg341261/#msg341261
// Armor weight modified proficiency = base proficiency * (1 - 0.01 * effective armor weight)
// Effective armor weight = 2*head armor weight + body armor weight + leg armor weight + 6*hand armor weight - a dynamic weight threshold of the max of 6, STR / 3, and IF * 2
// (Source: WaltF4, updated 31.7.2012 based on the new formula)
// Slightly outdated, but very close to actual wpf//
return Math.ceil((Math.abs(effectiveArmorWeight - 100) * baseWpf) / 100);
}
function UpdateWpfTable(){
var penalty = effectiveArmorWeight > 0;
e1hWpfElement.innerHTML = '<b>' + (base1hWpf > 1 ? (penalty ? CalculateWpf(base1hWpf) : base1hWpf) : 1) + '</b>/' + base1hWpf;
e2hWpfElement.innerHTML = '<b>' + (base2hWpf > 1 ? (penalty ? CalculateWpf(base2hWpf) : base2hWpf) : 1) + '</b>/' + base2hWpf;
epolewpfElement.innerHTML = '<b>' + (basePoleWpf > 1 ? (penalty ? CalculateWpf(basePoleWpf) : basePoleWpf) : 1) + '</b>/' + basePoleWpf;
var throwingwpfAfterPenalty = 1;
var PTpenalty = 0;
var throwingArmorPenalty = 0;
if(baseThrowWpf > 1)
{
throwingArmorPenalty = Math.max(CalculateWpfRanged(baseThrowWpf),0);
PTpenalty = 11*basePT;
throwingwpfAfterPenalty = Math.ceil(Math.max(throwingArmorPenalty - PTpenalty,0));
throwingArmorPenalty = baseThrowWpf - throwingArmorPenalty;
}
else
{
throwWpfElement.innerHTML = '<b>' + throwingwpfAfterPenalty + '</b>/' + baseThrowWpf + ' | PT penalty: ' + PTpenalty + ' | Armor Penalty: ' + throwingArmorPenalty;
}
throwWpfElement.innerHTML = '<b>' + throwingwpfAfterPenalty + '</b>/' + baseThrowWpf;
xbowWpfElement.innerHTML = '<b>' + (baseXbowWpf > 1 ? (penalty ? CalculateWpfRanged(baseXbowWpf) : baseXbowWpf) : 1) + '</b>/' + baseXbowWpf;
var archerywpfAfterPenalty = 1;
var PDpenalty = 0;
var archerArmorPenalty = 0;
if(baseArcheryWpf > 1)
{
archerArmorPenalty = Math.max(CalculateWpfRanged(baseArcheryWpf),0);
PDpenalty = Math.ceil(Math.max(14*basePD - Math.pow(1.35,basePD) - 35, 0));
archerywpfAfterPenalty = archerArmorPenalty - PDpenalty;
archerArmorPenalty = baseArcheryWpf - archerArmorPenalty;
archeryWpfElement.innerHTML = '<b>' + archerywpfAfterPenalty + '</b>/' + baseArcheryWpf + ' | PD penalty: ' + PDpenalty + ' | Armor Penalty: ' + archerArmorPenalty;
}
else
{
archeryWpfElement.innerHTML = '<b>' + archerywpfAfterPenalty + '</b>/' + baseArcheryWpf;
}
}
function EndIndexOf(text, search){
if(text != null && search != null){
var ind = text.indexOf(search);
if(ind > -1)
return ind + search.length;
}
}
function LoadWpfValues(){
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", 'http://c-rpg.net/index.php?page=charstats', false );
xmlHttp.send( null );
var data = xmlHttp.responseText;
var start = EndIndexOf(data, 'id="wpfOneHandedField" value="');
var val = data.substring(start, data.indexOf('"', start));
base1hWpfTemp = parseInt(val);
start = EndIndexOf(data, 'id="wpfTwoHandedField" value="');
val = data.substring(start, data.indexOf('"', start));
base2hWpfTemp = parseInt(val);
start = EndIndexOf(data, 'id="wpfPolearmField" value="');
val = data.substring(start, data.indexOf('"', start));
basePoleWpfTemp = parseInt(val);
start = EndIndexOf(data, 'id="wpfThrowingField" value="');
val = data.substring(start, data.indexOf('"', start));
baseThrowWpf = parseInt(val);
start = EndIndexOf(data, 'id="wpfCrossbowField" value="');
val = data.substring(start, data.indexOf('"', start));
baseXbowWpf = parseInt(val);
start = EndIndexOf(data, 'id="wpfArcheryField" value="');
val = data.substring(start, data.indexOf('"', start));
baseArcheryWpf = parseInt(val);
start = EndIndexOf(data, 'id="skillPowerDrawField" value="');
val = data.substring(start, data.indexOf('"', start));
basePD = parseInt(val);
start = EndIndexOf(data, 'id="skillPowerThrowField" value="');
val = data.substring(start, data.indexOf('"', start));
basePT = parseInt(val);
start = EndIndexOf(data, 'id="skillIronFleshField" value="');
val = data.substring(start, data.indexOf('"', start));
baseIF = parseInt(val);
baseStr = document.getElementById('attrStrength');
base1hWpf = Math.floor((Math.max(base2hWpfTemp*0.7-30, 0) + Math.max(basePoleWpfTemp*0.7-30, 0)) * 0.3 + base1hWpfTemp);
base2hWpf = Math.floor((Math.max(base1hWpfTemp*0.7-30, 0) + Math.max(basePoleWpfTemp*0.7-30, 0)) * 0.3 + base2hWpfTemp);
basePoleWpf = Math.floor((Math.max(base1hWpfTemp*0.7-30, 0) + Math.max(base2hWpfTemp*0.7-30, 0)) * 0.3 + basePoleWpfTemp);
e1hWpfElement = document.getElementById('effective1hWpf');
e2hWpfElement = document.getElementById('effective2hWpf');
epolewpfElement = document.getElementById('effectivePoleWpf');
throwWpfElement = document.getElementById('effectiveThrowWpf');
xbowWpfElement = document.getElementById('effectiveXbowWpf');
archeryWpfElement = document.getElementById('effectiveArcheryWpf');
}
function Init(){
var isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
isFirefox = typeof InstallTrigger != 'undefined'; // Firefox 1.0+
isChrome = !!window.chrome && !isOpera; // Chrome 1+
weightLabel = document.getElementById('armorweight');
totalweightLabel = document.getElementById('totalweight');
effectiveWeightLabel = document.getElementById('effectiveArmorWeight');
head = document.getElementById('itemheadvalue');
body = document.getElementById('itembodyvalue');
legs = document.getElementById('itemlegvalue');
hand = document.getElementById('itemhandvalue');
item1 = document.getElementById('itemweapon1value');
item2 = document.getElementById('itemweapon2value');
item3 = document.getElementById('itemweapon3value');
item4 = document.getElementById('itemweapon4value');
AddItemChangedEvent(head, UpdateArmorWeight);
AddItemChangedEvent(body, UpdateArmorWeight);
AddItemChangedEvent(legs, UpdateArmorWeight);
AddItemChangedEvent(hand, UpdateArmorWeight);
AddItemChangedEvent(item1, UpdateItemWeight);
AddItemChangedEvent(item2, UpdateItemWeight);
AddItemChangedEvent(item3, UpdateItemWeight);
AddItemChangedEvent(item4, UpdateItemWeight);
LoadWpfValues();
}
function AddItemChangedEvent(el, func)
{
if(el != null)
{
if (el.addEventListener){
el.addEventListener('change', func, false);}
else{
el.attachEvent('change', func);}
}
}
var upkeepElement = document.getElementById('upkeep');
var saveEl = document.getElementsByName('save');
if(upkeepElement != null){
awdiv = document.createElement('div');
awdiv.className = 'labelvalue groupstart';
awspan = document.createElement('span');
awspan.id = 'armorweight';
awspan.className = 'value';
awlabel = document.createElement('span');
awlabel.className = 'label';
awlabel.innerHTML = 'Armor weight';
awdiv.appendChild(awspan);
awdiv.appendChild(awlabel);
upkeepElement.parentNode.parentNode.appendChild(awdiv);
twdiv = document.createElement('div');
twdiv.className = 'labelvalue groupstart';
twspan = document.createElement('span');
twspan.id = 'totalweight';
twspan.className = 'value';
twlabel = document.createElement('span');
twlabel.className = 'label';
twlabel.innerHTML = 'Total weight';
twdiv.appendChild(twspan);
twdiv.appendChild(twlabel);
upkeepElement.parentNode.parentNode.appendChild(twdiv);
ewdiv = document.createElement('div');
ewdiv.className = 'labelvalue groupstart';
ewspan = document.createElement('span');
ewspan.id = 'effectiveArmorWeight';
ewspan.className = 'value';
ewlabel = document.createElement('span');
ewlabel.className = 'label';
ewlabel.innerHTML = 'Wpf penalty weight';
ewdiv.appendChild(ewspan);
ewdiv.appendChild(ewlabel);
upkeepElement.parentNode.parentNode.appendChild(ewdiv);
if(saveEl != null && saveEl.length > 0){
gridr = document.createElement('div');
gridr.className = 'gridrow';
gridc = document.createElement('div');
gridc.className = 'gridcol full';
gridr.appendChild(gridc);
wpft = document.createElement('div');
wpft.className = 'header2';
wpfh = document.createElement('h1');
wpfh.innerHTML = 'Stat modifiers';
wpft.appendChild(wpfh);
gridc.appendChild(wpft);
desc = document.createElement('div');
desc.className = 'desc';
desct = document.createElement('span');
desct.innerHTML = 'Approximate effective WPF with selected equipment.';
desc.appendChild(desct);
wpft.appendChild(desc);
wt = document.createElement('div');
wt.className = 'gridrow';
wt.Id = 'wpfTable';
wt.innerHTML = '<table style=\'border=0px; margin-left:7px;margin-top:10px\'>'+
'<tr><td style="padding-right:10px">One Handed:</td><td id=\'effective1hWpf\'></td></tr>'+
'<tr><td>Two Handed:</td><td id=\'effective2hWpf\'></td></tr>'+
'<tr><td>Polearm:</td><td id=\'effectivePoleWpf\'></td></tr>' +
'<tr><td>Throwing:</td><td id=\'effectiveThrowWpf\'></td></tr>' +
'<tr><td>Crossbow:</td><td id=\'effectiveXbowWpf\'></td></tr>' +
'<tr><td>Archery:</td><td id=\'effectiveArcheryWpf\'></td></tr></table>';
pnode = saveEl[0].parentNode.parentNode.parentNode;
pnode.appendChild(gridr);
pnode.appendChild(wt);
}
Init();
UpdateArmorWeight();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment