-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpercolator.js
270 lines (233 loc) · 8.88 KB
/
percolator.js
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
//http://stackoverflow.com/questions/1038746/equivalent-of-string-format-in-jquery
String.prototype.format = String.prototype.f = function() {
var s = this,
i = arguments.length;
while (i--) {
s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]);
}
return s;
};
var percolator = {
pveWeapons: undefined,
pvpWeapons: undefined,
getWeaponData: function() {
var self = this;
$.get('pveWeapons.csv', function(data) {
self.pveWeapons = $.csv.toArrays(data);
});
$.get('pvpWeapons.csv', function(data) {
self.pvpWeapons = $.csv.toArrays(data);
});
$.get('destinyWeapons.csv', function(data) {
self.characterItems = $.csv.toArrays(data);
});
},
translateClassHash: function(classHash) {
// https://github.com/sebastianbarfurth/destiny-php/blob/master/src/Destiny/Support/Translators/HashTranslator.php
switch(classHash)
{
case 3655393761:
return 'Titan';
case 671679327:
return 'Hunter';
case 2271682572:
return 'Warlock';
default:
return 'Unknown';
}
},
getWeaponName: function(itemHash, items) {
var weaponName = "Unknown Weapon";
$.each(items, function(n, item) {
if(item.itemHash == itemHash) {
weaponName = item.itemName;
return false;
}
});
return weaponName;
},
getItems: function() {
if(!($("#characterInventory").val())) {
return this.characterItems;
}
var rawCharacterWeaponData = $.csv.toArrays($("#characterInventory").val());
return rawCharacterWeaponData;
},
findBlessed: function() {
var weapons = this.getItems();
this.findBlessedPve(weapons);
this.findBlessedPvp(weapons);
},
getMatchGrade: function(matchAmount) {
switch(matchAmount) {
case 0:
return "Bad";
case 1:
return "Forgettable";
case 2:
return "Passable";
case 3:
return "Good";
case 4:
return "Excellent";
default:
return "unknown";
}
},
getWeaponLocation: function(weapon) {
return weapon[6];
},
getInventoryWeaponLightLevel: function(weapon) {
return weapon[4];
},
findBlessedPve: function(weapons) {
var self = this;
$('#pveWeaponList').empty();
$.each(weapons, function(n, weapon) {
$.each(self.pveWeapons, function(n, pveWeapon) {
var matchAmount = self.weaponMatchesBlessedWeapon(weapon, pveWeapon);
if(matchAmount > 2)
{
var hypeMessage = self.getHypeMessage(weapon, pveWeapon, matchAmount);
if (matchAmount > 3) {
$('#pveWeaponList').prepend("<li>{0}</li>".format(hypeMessage));
} else {
$('#pveWeaponList').append("<li>{0}</li>".format(hypeMessage));
}
}
})
});
},
findBlessedPvp: function(weapons) {
var self = this;
$('#pvpWeaponList').empty();
$.each(weapons, function(n, weapon) {
$.each(self.pvpWeapons, function(n, pvpWeapon) {
var matchAmount = self.weaponMatchesBlessedWeapon(weapon, pvpWeapon);
if(matchAmount > 2)
{
var hypeMessage = self.getHypeMessage(weapon, pvpWeapon, matchAmount);
if (matchAmount > 3) {
$('#pvpWeaponList').prepend("<li>{0}</li>".format(hypeMessage));
} else {
$('#pvpWeaponList').append("<li>{0}</li>".format(hypeMessage));
}
}
})
});
},
getHypeMessage: function(inventoryWeapon, blessedWeapon, matchAmount) {
var matchGrade = this.getMatchGrade(matchAmount);
var weaponName = this.getInventoryWeaponName(inventoryWeapon);
var lightLevel = this.getInventoryWeaponLightLevel(inventoryWeapon);
var weaponLocation = this.getWeaponLocation(inventoryWeapon);
var perkNodes = [this.getBlessedWeaponPerkOne(blessedWeapon),
this.getBlessedWeaponPerkTwo(blessedWeapon),
this.getBlessedWeaponPerkThree(blessedWeapon),
this.getBlessedWeaponPerkFour(blessedWeapon)];
var perkNodeDescription = perkNodes.join("</li><li>");
return "<span class='grade {4}'>{4}</span>: <span class='ll'>{0}</span> <span class='name'>{1}</span> <span class='location'>{3}</span> <ul class='perks'><li>{2}</li></ul>".format(lightLevel, weaponName, perkNodeDescription, weaponLocation, matchGrade);
},
getInventoryWeaponName: function (inventoryWeapon) {
return inventoryWeapon[0];
},
getBlessedWeaponName: function(blessedWeapon) {
return blessedWeapon[0];
},
getBlessedWeaponPerkOne: function(blessedWeapon) {
return blessedWeapon[1];
},
getBlessedWeaponPerkTwo: function(blessedWeapon) {
return blessedWeapon[2];
},
getBlessedWeaponPerkThree: function(blessedWeapon) {
return blessedWeapon[3];
},
getBlessedWeaponPerkFour: function(blessedWeapon) {
return blessedWeapon[4];
},
getPerkNodes: function(inventoryWeapon, wantSelectedPerks) {
var perkNames = [];
for(var i = 20; i < 40; i++) {
if(inventoryWeapon[i]) {
var perkName = inventoryWeapon[i];
if ((wantSelectedPerks) &&
(perkName.indexOf("*") == -1)) {
continue;
}
var strippedPerkName = perkName.replace(/\*/g , "");
perkNames.push(strippedPerkName);
}
}
return perkNames;
},
weaponMatchesBlessedWeapon: function(inventoryWeapon, blessedWeapon) {
var inventoryWeaponPerks = this.getPerkNodes(inventoryWeapon);
if ((inventoryWeaponPerks.length == 0) ||
(this.getInventoryWeaponName(inventoryWeapon) != this.getBlessedWeaponName(blessedWeapon))) {
return 0;
}
var matchCount = 0;
matchCount += (this.weaponHasPerk(inventoryWeaponPerks, this.getBlessedWeaponPerkOne(blessedWeapon)));
matchCount += (this.weaponHasPerk(inventoryWeaponPerks, this.getBlessedWeaponPerkTwo(blessedWeapon)));
matchCount += (this.weaponHasPerk(inventoryWeaponPerks, this.getBlessedWeaponPerkThree(blessedWeapon)));
matchCount += (this.weaponHasPerk(inventoryWeaponPerks, this.getBlessedWeaponPerkFour(blessedWeapon)));
return matchCount;
},
weaponHasPerk: function(inventoryWeaponPerks, particularPerk) {
for(var i = 0; i < inventoryWeaponPerks.length; i++) {
var inventoryWeaponPerk = inventoryWeaponPerks[i];
if(particularPerk.indexOf(inventoryWeaponPerk) != -1) {
return true;
}
}
return false;
},
extractNewSourceItems: function() {
var self = this;
var newInventoryWeapons = $.csv.toArrays($("#dimSourceWeaponry").val());
var newSourceItems = [];
$.each(newInventoryWeapons, function(n, newInventoryWeapon) {
var newWeaponName = self.getInventoryWeaponName(newInventoryWeapon);
if(newWeaponName.length > 0) {
var newSourceItem = []
.concat(newWeaponName)
.concat(self.getPerkNodes(newInventoryWeapon,
true));
newSourceItems.push(newSourceItem);
}
});
return newSourceItems;
},
shouldAddToPvP: function() {
return ($("#destinationList").val() == "PvP");
},
shouldAddToPvE: function() {
return ($("#destinationList").val() == "PvE");
},
addAndTranslate: function() {
var newSourceItems = this.extractNewSourceItems();
$.each(newSourceItems, function(n, newSourceItem) {
$("#percolatorSourceWeaponry").append("{0}\n\n".format(newSourceItem.join(",")));
});
if(this.shouldAddToPvE) {
this.pveWeapons = this.pveWeapons.concat(newSourceItems);
}
if(this.shouldAddToPvP) {
this.pvpWeapons = this.pvpWeapons.concat(newSourceItems);
}
},
init: function() {
this.getWeaponData();
this.initEvents();
},
initEvents: function() {
var self = this;
$("#findBlessed").click(function() {
self.findBlessed();
});
$("#addAndTranslate").click(function() {
self.addAndTranslate();
});
}
};