-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbl_dps_calc.js
More file actions
352 lines (334 loc) · 12.1 KB
/
bl_dps_calc.js
File metadata and controls
352 lines (334 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
// Borderlands DPS Calculator - JavaScript edition!
//============================================================================
// v0.07 - added weapon name box.
// - added an array list for weapon name / calculated dps.
// - added new functions for grabbing elements.
// v0.06 - allowed "DamagexPellets" (ie. 7x18) damage to be calculated.
// - adjusted textbox widths on html file.
// v0.05 - added guardian rank passive bonuses to calculator.
// - reload speed passive bonus is bugged so I disabled it.
// - updated html form to reflect new changes.
// v0.04 - added elemental damage and element chance to the math formula.
// - updated the html file to include an option to add elemental data.
// - cleaned up javascript code (removed redundant code).
// - added a newer error alert code.
// - added new functions to calculator.
// v0.03 - introduced an html file with form elements that can be manipulated
// - adjusted code in the javascript. added css code to html file.
// v0.02 - added an error alert function
// - updated safety checks
// - fixed an accidental bug in code.
// v0.01 - initial start of project totally works
//============================================================================
var WeaponDamage; var WeaponAccu; var ReloadSpeed;
var FireRate; var MagSize; var ElementalDamage = 0; var ElementalChance;
var guardWepDMG; var guardWepACC; var guardWepRS; var guardWepFR;
var b_gd_p; var b_gacc_p; var b_grs_p; var b_gfr_p;
var secMF = 0; var secMFR = 0; var TotalMagDamage = 0;
var FinalDPS; var AlertMSG; var resAcc; var resDmg; var resFr; var resRs;
var NewDPS; var NumSav = 0;
var myDPSList = new Array();
function roundNumber(number, decimals) {
var newnumber = new Number(number+"").toFixed(parseInt(decimals));
return parseFloat(newnumber);
}
function getWeaponDamage(){
return document.getElementById("wDamage").value;
}
function getWeaponAccu(){
return document.getElementById("wAccu").value;
}
function getMagSize(){
return document.getElementById("wMagSize").value;
}
function getReloadSpeed(){
return document.getElementById("wReloadSpeed").value;
}
function getFireRate(){
return document.getElementById("wFirerate").value;
}
function getElementalDamage(){
return document.getElementById("wEleDamage").value;
}
function getElementalChance(){
return document.getElementById("wEleChance").value;
}
function WeaponName(){
return document.getElementById("wWepName").value;
}
function WeaponCalculatedDPS(){
return document.getElementById("CalcDPS").value;
}
function GuardianWeaponDamage(){
return document.getElementById("wGDB").value;
}
function GuardianWeaponFireRate(){
return document.getElementById("wGFRB").value;
}
function GuardianWeaponAccuracy(){
return document.getElementById("wGAB").value;
}
function GuardianWeaponReloadSpeed(){
return document.getElementById("wGRSB").value;
}
function ErrAlert(eCode, objName){
let oN = objName;
switch(eCode){
case 0:
AlertMSG = "[Error 0] - Cannot compute " + oN + " is less than one";
document.getElementById("CalcDPS").value = AlertMSG;
break;
case 1:
AlertMSG = "[Error 1] - " + oN + " does not contain valid numbers";
document.getElementById("CalcDPS").value = AlertMSG;
break;
}
}
function UpdateNum(){
NumSav = NumSav + 1;
}
function SaveToList(){
AddToArray(WeaponName(), WeaponCalculatedDPS());
SaveResDisplay();
}
function DisplayList() {
var e = "<hr/>";
for (var y=0; y<myDPSList.length; y++)
{
tempY = y + 1;
e += tempY + " = " + myDPSList[y] + "<br/>";
}
document.getElementById("Result").innerHTML = e;
}
function SaveResDisplay(){
var e = "<hr/>";
UpdateNum();
e += "Saved: " + WeaponName() + " to List at #" + NumSav + "<br/>";
document.getElementById("SaveResult").innerHTML = e;
}
function AddToArray(WeaponName, WeaponSustainedDPS){
myDPSList.push("Weapon Name: " + WeaponName + " - DPS: " + WeaponSustainedDPS);
}
function BLCalculate(){
if (ElementalDamage < 1 || ElementalChance < 1 || isNaN(ElementalDamage) || isNaN(ElementalChance)) {
BLC(0); //base calculations.
} else if (isNaN(WeaponAccu) || WeaponAccu < 1) { //no weapon accuracy :)
BLC(1); //base + elemental calculations.
} else { //hopefully they have weapon accuracy.
BLC(2);
}
}
function BLC(choice){
switch(choice){
case 0:
reg_calc();
break;
case 1:
ele_calc();
break;
case 2:
ele_acc_calc();
break;
case 3:
guard_ele_acc_calc();
}
}
function run_datacheck(){ //runs a small input data check.
//if base values have no valid numbers we cannot compute.
if (isNaN(MagSize)) {
ErrAlert(1,"magazine size");
}
if (isNaN(FireRate)) {
ErrAlert(1,"firerate");
}
if (isNaN(ReloadSpeed)) {
ErrAlert(1,"reload speed");
}
if (isNaN(WeaponDamage)) {
ErrAlert(1,"weapon damage");
}
//if base values are less than 1 than we cannot compute.
if (MagSize < 1) {
ErrAlert(0,"magazine size");
}
if (FireRate < 1) {
ErrAlert(0,"firerate");
}
if (WeaponDamage < 1) {
ErrAlert(0,"weapon damage");
}
if (ReloadSpeed < 1) {
ErrAlert(0,"reload speed");
}
}
function ele_calc(){ //calculate with elemental chance/damage.
let testy = WeaponDamage;
testy = testy.replace("x","*");
let NewDPS = eval(testy);
run_datacheck();
let secEle = Number(ElementalChance / 1000 * 10).toFixed(3); //0.345% ?
let secMF = Number(MagSize / FireRate).toFixed(3);
let secMFR = Number(secMF + ReloadSpeed).toFixed(3);
let zebra = Number(ElementalDamage * secEle).toFixed(3);
let TotalMagDamage = Number(MagSize * NewDPS);
let FinalDPS = Number((TotalMagDamage / secMFR) + zebra).toFixed(3);
x = FinalDPS.toString();
document.getElementById("CalcDPS").value = x;
console.log("Weapon DPS (+Elemental): " + x);
}
function ele_acc_calc(){ //calculate with elemental chance/damage with base accuracy data.
let testy = WeaponDamage;
testy = testy.replace("x","*");
let NewDPS = eval(testy);
run_datacheck();
let secEle = Number(parseFloat((ElementalChance / 1000) * 10).toFixed(3)); //34.5 = 0.345% ?
let secAcc = Number(parseFloat((WeaponAccu / 1000) * 10).toFixed(3)); //convert accuracy to a percentage!
let secMF = Number(parseFloat(MagSize / FireRate));
let secMFR = Number(parseFloat(secMF + ReloadSpeed));
let zebra = Number(parseFloat(ElementalDamage * secEle));
let TotalMagDamage = Number(parseFloat(MagSize * NewDPS));
let FinalDPS = Number(parseFloat(secAcc * (((TotalMagDamage / secMFR) + zebra))).toFixed(2));
x = FinalDPS.toString();
document.getElementById("CalcDPS").value = x;
console.log("Weapon DPS (+Elemental+Accuracy): " + x);
}
function sum(input){
if (toString.call(input) !== "[object Array]")
return false;
var total = 0;
for(var i=0;i<input.length;i++)
{
if(isNaN(input[i])){
continue;
}
total += Number(input[i]);
}
return total;
}
function guard_ele_acc_calc(){ //calculate with elemental chance/damage with base accuracy data.
let testy = WeaponDamage;
testy = testy.replace("x","*");
let NewDPS = eval(testy);
run_datacheck();
let b_gd_p = parseFloat((guardWepDMG / 1000) * 10).toFixed(3); //bonus damage
console.log("b_gd_p:" + b_gd_p);
let b_gacc_p = parseFloat((guardWepACC / 1000) * 10).toFixed(3); //bonus accuracy
console.log("b_gacc_p: " + b_gacc_p);
let b_grs_p = parseFloat((guardWepRS / 1000) * 10).toFixed(3); //bonus reload speed
console.log("b_grs_p: " + b_grs_p);
let b_gfr_p = parseFloat((guardWepFR / 1000) * 10).toFixed(2); //bonus fire rate
console.log("b_gfr_p: " + b_gfr_p);
let secEle = parseFloat((ElementalChance / 1000) * 10).toFixed(3); //34.5 = 0.345% ?
console.log("secEle: " + secEle);
let secAcc = parseFloat((WeaponAccu / 1000) * 10).toFixed(3); //convert accuracy to a percentage!
console.log("secAcc: " + secAcc);
var FrBonus = parseFloat((FireRate/1000)*10);
FrBonus = FrBonus+1*b_gfr_p;
console.log("FrBonus: " + FrBonus);
let secMF = parseFloat(roundNumber((MagSize / FrBonus), 2));//* (1 + b_gfr_p))+"%"); //with bonus gun firerate
console.log("secMF: " + secMF);
if (isNaN(guardWepRS) || guardWepRS < 1) { // gotta check ReloadSpeed
let RsBonus = ReloadSpeed; // no change
console.log(("RsBonus: " + RsBonus));
secMFR = parseFloat(sum([secMF, ReloadSpeed]));//(secMF + RsBonus)+"%");
console.log("secMFR: " + secMFR);
} else if (guardWepRS > 1) {
console.log("ReloadSpeed = " + ReloadSpeed);
let RsBonus2 = parseFloat(sum([ReloadSpeed, b_grs_p]));//Math.ceil(ReloadSpeed * b_grs_p);//RsBonus + 1 * insertDecimal(guardWepRS);// + 1 * b_grs_p;
console.log(("RsBonus2: " + RsBonus2));
secMFR = parseFloat(sum([secMF, RsBonus2]));//(secMF + RsBonus)+"%");
console.log("secMFR: " + secMFR);
}
let zebra = parseFloat(sum([ElementalDamage * secEle]).toFixed(3));
console.log("zebra: " + zebra); //elemental reee
let resDmg = parseFloat(sum([NewDPS * (1 + b_gd_p)])).toFixed(3);
console.log("resDmg: " + resDmg);
let TotalMagDamage = parseFloat(sum([MagSize * resDmg])).toFixed(3);
console.log("TotalMagDamage: " + TotalMagDamage);
resAcc = parseFloat(sum([secAcc * (1 + b_gacc_p)])).toFixed(4); //+ b_gacc_p); //bonus acc + acc
console.log("Bonus resAcc: " + resAcc);
let FinalDPS = parseFloat(sum([resAcc * (((TotalMagDamage / secMFR) + zebra))])).toFixed(2);
console.log("FinalDPS: " + FinalDPS);
x = FinalDPS;
document.getElementById("CalcDPS").value = x;
console.log("Weapon DPS (+Elemental+Accuracy): " + x);
}
function reg_calc(){ //calculate without elemental chance/damage.
let testy = WeaponDamage;
testy = testy.replace("x","*");
let NewDPS = eval(testy);
run_datacheck();
let secMF = parseFloat(MagSize / FireRate);
let secMFR = parseFloat(sum([secMF, ReloadSpeed]));
let TotalMagDamage = parseFloat(MagSize * NewDPS);
let FinalDPS = parseFloat(TotalMagDamage / secMFR).toFixed(2);
x = FinalDPS.toString();
console.log("Weapon DPS: " + x);
document.getElementById("CalcDPS").value = x;
}
function submit(){ //grabs form values to use in javascript.
WeaponDamage = getWeaponDamage();
WeaponAccu = getWeaponAccu();
MagSize = getMagSize();
ReloadSpeed = getReloadSpeed();
FireRate = getFireRate();
ElementalDamage = getElementalDamage();
ElementalChance = getElementalChance();
BLCalculate();
}
function submit2(){ //guardian submit
WeaponDamage = getWeaponDamage();
WeaponAccu = getWeaponAccu();
MagSize = getMagSize();
ReloadSpeed = getReloadSpeed();
FireRate = getFireRate();
ElementalDamage = getElementalDamage();
ElementalChance = getElementalChance();
//guardian passives
guardWepDMG = GuardianWeaponDamage();
guardWepFR = GuardianWeaponFireRate();
guardWepACC = GuardianWeaponAccuracy();
guardWepRS = 0;//GuardianWeaponReloadSpeed();//0; // document.getElementById("wGRSB").value;
BLC(3);
}
function clearText(){ //clears out old values on form.
document.getElementById("wDamage").value = "";
document.getElementById("wAccu").value = "";
document.getElementById("wMagSize").value = "";
document.getElementById("wReloadSpeed").value = "";
document.getElementById("wFirerate").value = "";
document.getElementById("wEleDamage").value = "";
document.getElementById("wEleChance").value = "";
//guardian
document.getElementById("wGDB").value = "";
document.getElementById("wGFRB").value = "";
document.getElementById("wGAB").value = "";
//wGRSB
document.getElementById("CalcDPS").value = "0";
}
function openGitHub(){
window.open("http://web.archive.org/web/20191009203337/https://github.com/LeftBased/Borderlands-Weapon-DPS-Calculator-JavaScript")
}
function openDonate(){
window.open("http://web.archive.org/web/20191009203337/https://paypal.me/internprimas")
}
/*
FILE ARCHIVED ON 20:33:37 Oct 09, 2019 AND RETRIEVED FROM THE
INTERNET ARCHIVE ON 06:06:41 Feb 24, 2020.
JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE.
ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C.
SECTION 108(a)(3)).
*/
/*
playback timings (ms):
esindex: 0.018
exclusion.robots.policy: 0.251
PetaboxLoader3.datanode: 194.648 (4)
captures_list: 249.139
CDXLines.iter: 13.405 (3)
exclusion.robots: 0.266
PetaboxLoader3.resolve: 70.576 (2)
load_resource: 84.619
LoadShardBlock: 202.309 (3)
RedisCDXSource: 28.993
*/