-
Notifications
You must be signed in to change notification settings - Fork 19
/
item.js
1472 lines (1427 loc) · 67.8 KB
/
item.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
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* jshint node: true */
/* jshint jquery: true */
/* jshint esversion: 6 */
"use strict";
/**
* Item class
*
* Extract mods, properties and socket information from items
* @params Nothing
* @return Item object
*/
var async = require( "async" );
const {app} = require( "electron" ).remote;
const path = require( "path" );
var config = require( app.getPath( "userData" ) + path.sep + "config.json" );
// Item price RegExp
var priceReg = /(?:([0-9\.]+)|([0-9]+)\/([0-9]+)) ([a-z]+)/g;
var Misc = require( "./misc.js" );
var Currency = require( "./currency.js" );
var mods = require( "./affixes.json" );
var types = require( "./reverseItemType.json" );
class Item {
/**
* Update item entry with dps values
*
* @params Item, DPS, callback
* @return Item with DPS values through callback
*/
static insertDPSValues( item, dps, callback ) {
// console.log( "inserting DPS values" );
if ( dps.pDPS && !item.hasPDPS ) {
item.properties.push({
name: "pDPS",
values: [[dps.pDPS]]
});
item.hasPDPS = true;
}
if ( dps.eDPS && !item.hasEDPS ) {
item.properties.push({
name: "eDPS",
values: [[dps.eDPS]]
});
item.hasEDPS = true;
}
if ( dps.DPS && !item.hasDPS ) {
item.properties.push({
name: "DPS",
values: [[dps.DPS]]
});
item.hasDPS = true;
}
callback( item );
}
/**
* Check if item is underpriced
*
* @params Item to check against, currency rates, itemRates, callback
* @return item through callback
*/
static checkUnderpriced( item, minPrice, maxPrice, currencyRates, itemRates, value, metric, league, callback ) {
var self = this;
// Clean up the item name and typeLine
item.name = item.name.replace( "<<set:MS>><<set:M>><<set:S>>", "" );
item.typeLine = item.typeLine.replace( "<<set:MS>><<set:M>><<set:S>>", "" );
var itemName = item.name.replace( "<<set:MS>><<set:M>><<set:S>>", "" );
var typeLine = item.typeLine.replace( "<<set:MS>><<set:M>><<set:S>>", "" );
var name = itemName;
// If item name is empty, the name is the type instead
if ( itemName === "" ) {
name = typeLine;
}
var itemLeague = item.league;
if ( config.useBeta ) {
itemLeague = "beta-" + itemLeague;
}
var prices = {};
if ( itemLeague === league ) {
prices = Item.computePrice( item, currencyRates );
}
if ( prices.originalPrice !== "Negotiate price" && itemLeague === league &&
name !== "" && prices.convertedPriceChaos > minPrice &&
prices.convertedPriceChaos < maxPrice && !item.corrupted ) {
Item.getLinksAmountAndColor( item, function( res ) {
var ref = "";
if ( item.frameType === 3 || item.frameType === 9 ) {
ref = name + "_" + ( res.linkAmount <= 4 ? 3 : ( res.linkAmount - 1 )) + "_" + item.frameType;
} else if ( item.frameType === 5 || item.frameType === 6 || item.frameType === 8 ) {
ref = name + "_0_" + item.frameType;
}
// If percentage value is not defined, default to 30%
if ( !value ) {
value = 70;
}
var metricValueChaos = 0;
if ( ref && itemRates[itemLeague][ref]) {
// console.log( ref + " in " + itemLeague );
// console.log( itemRates[itemLeague][ref] );
if ( metric === "min_mode_median" ) {
metricValueChaos = Math.min( itemRates[itemLeague][ref].mode, itemRates[itemLeague][ref].median );
} else if ( metric === "min" ) {
metricValueChaos = itemRates[itemLeague][ref].min;
} else if ( metric === "mode" ) {
metricValueChaos = itemRates[itemLeague][ref].mode;
} else if ( metric === "median" ) {
metricValueChaos = itemRates[itemLeague][ref].median;
}
}
if ( itemRates[itemLeague][ref] &&
( item.frameType === 3 || item.frameType === 8 || item.frameType === 6 || item.frameType === 9 || item.frameType === 5 ) &&
prices.convertedPriceChaos <= metricValueChaos * value / 100 ) {
item.confidence = itemRates[itemLeague][ref].confidence;
// console.log( item.name + " " + res.linkAmount + "L for " + prices.convertedPriceChaos + " instead of " + (itemRates[itemLeague][ref]) + " in " + itemLeague );
Item.parseProperties( item, function( newItem, parsedProperties ) {
// console.log( newItem );
// If we have an attack per second property, compute DPS
if ( parsedProperties["Attacks per Second"]) {
Item.computeDPS( parsedProperties, function( dps ) {
parsedProperties.DPS = dps.DPS;
parsedProperties.pDPS = dps.pDPS;
Item.insertDPSValues( newItem, dps, function( item ) {
console.log( "Inserted DPS value for item" );
Item.formatItem( item, name, prices, 0, 0, function( newItem ) {
newItem.fullPrice = Math.round( metricValueChaos );
callback( newItem );
});
});
});
} else {
Item.formatItem( newItem, name, prices, 0, 0, function( newItem ) {
newItem.fullPrice = Math.round( metricValueChaos );
callback( newItem );
});
}
});
} else {
callback( false );
}
});
} else {
callback( false );
}
}
/**
* Computes the amount of links and the socket colors of an item
*
* @param item data, callback
* @return pass the amount and colors to callback
*/
static getLinksAmountAndColor( item, callback ) {
var groups = {};
var groupColors = {};
var colors = [];
var colorCount = {};
// For each sockets in the item
async.each( item.sockets, function( socket, cb ) {
if ( !socket.attr ) {
socket.attr = "A";
}
// If we have a new socket group
if ( !groups[socket.group] ) {
groups[socket.group] = 1;
groupColors[socket.group] = [socket.attr];
// Otherwise, add a new socket to this group
} else {
groups[socket.group]++;
groupColors[socket.group].push( socket.attr );
}
if ( !colorCount[socket.attr]) {
colorCount[socket.attr] = 0;
}
colorCount[socket.attr]++;
colors.push( socket.attr );
cb();
}, function( err ) {
if ( err ) {
console.log( err );
}
var linkAmount = 0;
var linkColors = [];
// Extract largest group
for ( var key in groups ) {
if ( groups.hasOwnProperty( key )) {
if ( groups[key] > linkAmount ) {
linkAmount = groups[key];
linkColors = groupColors[key];
}
}
}
callback({ "linkAmount": linkAmount,
"colors": colors,
"linkedColors": linkColors,
"colorCount": colorCount
});
});
}
/**
* Format time to display on the interface
*
* @params Nothing
* @return Formatted time
*/
static formatTime() {
var date = new Date();
var hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
var min = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
var sec = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
return hour + " : " + min + " : " + sec;
}
static formatAffixes( affixes, values, explicitMod, affixType, maxValue, callback ) {
var iteration = affixes.length;
var index;
var explicit = "";
var added = false;
// For mods without values
if ( values.length === 0 ) {
values[0] = 0;
}
async.each( affixes, function( affix, cbAffix ) {
// console.log( affix );
// console.log( explicitMod + " : " + JSON.stringify( affix.min ) + " : " + affix.min.length + " : " + JSON.stringify( values ) );
if ( affix.min && affix.min.length > 1 ) {
if ( !added &&
affix.min[0] <= values[0] &&
affix.min[1] >= values[0] &&
affix.max[0] <= values[1] &&
affix.max[1] >= values[1]) {
index = iteration;
added = true;
if ( affixType === "corrupted" ) {
explicit +=
"<span class=\"badge affix-" + affixType + "\" data-badge-caption=\"Implicit" +
"\"></span><span class=\"explicit\">" + explicitMod + "</span><br>";
} else if ( affixType === "signature" ) {
explicit +=
"<span class=\"badge affix-" + affix.drop + "\" data-badge-caption=\"" + affix.drop +
"\"></span><span class=\"explicit\">" + explicitMod + "</span><br>";
} else {
explicit +=
"<span class=\"badge affix-" + affixType + "\" data-badge-caption=\"" + affixType +
index + "\"></span><span class=\"explicit\">" + explicitMod + "</span><br>";
}
} else {
iteration--;
}
cbAffix();
} else {
if ( !added && affix.min &&
affix.min[0] <= values[0] &&
affix.max[0] >= values[0]) {
index = iteration;
added = true;
if ( affixType === "corrupted" ) {
explicit +=
"<span class=\"badge affix-" + affixType + "\" data-badge-caption=\"Implicit" +
"\"></span><span class=\"explicit\">" + explicitMod + "</span><br>";
} else if ( affixType === "signature" ) {
explicit +=
"<span class=\"badge affix-" + affix.drop + "\" data-badge-caption=\"" + affix.drop +
"\"></span><span class=\"explicit\">" + explicitMod + "</span><br>";
} else {
explicit +=
"<span class=\"badge affix-" + affixType + "\" data-badge-caption=\"" + affixType +
index + "\"></span><span class=\"explicit\">" + explicitMod + "</span><br>";
}
} else {
iteration--;
}
cbAffix();
}
}, function() {
if ( explicit === "" && values[0] > maxValue ) {
explicit += "<span class=\"badge affix-legacy\" data-badge-caption=\"Legacy" +
"\"></span><span class=\"explicit\">" + explicitMod + "</span><br>";
} else if ( explicit === "" ) {
explicit += "<span class=\"badge affix-explicit\" data-badge-caption=\"?" +
"\"></span><span class=\"explicit\">" + explicitMod + "</span><br>";
}
callback( explicit );
});
}
/**
* Format item to display in the results
*
* @params Item, item name, prices and callback
* @returns Formatted item through callback
*/
static formatItem( item, name, prices, openPrefix, openSuffix, callback ) {
var magicReg = /[a-zA-Z']+\s([a-zA-Z ']+)\sof.*/;
openPrefix = openPrefix === "" ? 0 : openPrefix;
openSuffix = openSuffix === "" ? 0 : openSuffix;
var time = Item.formatTime();
var guid = Misc.guidGenerator();
var implicit = "";
var explicit = "";
var crafted = "";
var enchant = "";
var total = "";
var pseudo = "";
var properties = "";
var totalPrefix = 0;
var totalSuffix = 0;
var totalCrafted = 0;
var itemType;
if ( item.implicitMods ) {
if ( item.corrupted ) {
// If object is magic, we have to guess the type another way
if ( item.frameType === 1 ) {
var cleanedTypeLine = item.typeLine.replace( "Shaped ", "" );
var match = magicReg.exec( cleanedTypeLine );
console.log( item.typeLine );
if ( match ) {
itemType = types[match[1]];
console.log( item.typeLine + ", " + match[1] + ", " + itemType );
} else {
console.log( "Could not match " + item.typeLine );
}
} else {
itemType = types[item.typeLine];
}
if ( itemType ) {
var split = itemType.split( "_" );
// console.log( split );
// console.log( item.typeLine );
var corrupted = [];
var maxValues = [];
var iterationP;
var iterationS;
var iterationC;
if ( split.length > 1 ) {
corrupted = mods[split[0]][split[1]]["corrupted"];
maxValues = mods[split[0]][split[1]]["maxValues"];
} else {
corrupted = mods[split[0]]["corrupted"];
maxValues = mods[split[0]]["maxValues"];
}
async.each( item.implicitMods, function( implicitMod, cbImplicit ) {
var reg = /([0-9.]+)/g;
var match = reg.exec( implicitMod );
var values = [];
while ( match !== null ) {
values.push( match[1]);
match = reg.exec( implicitMod );
}
var index = "";
var implicitTitle = implicitMod.replace( reg, "#" );
// If this mod is a corrupted implicit
if ( corrupted[implicitTitle]) {
Item.formatAffixes( corrupted[implicitTitle], values, implicitMod, "corrupted", maxValues[implicitTitle], function( res ) {
// Amethyst ring have chaos implicit which is also a corrupted implicit
if ( res === "" ) {
implicit +=
"<span class=\"badge affix-implicit\" data-badge-caption=\"Implicit" +
"\"></span><span class=\"implicit\">" + implicitMod + "</span><br>";
} else {
implicit += res;
}
cbImplicit();
});
// Otherwise
} else {
implicit +=
"<span class=\"badge affix-implicit\" data-badge-caption=\"Implicit" +
"\"></span><span class=\"implicit\">" + implicitMod + "</span><br>";
cbImplicit();
}
}, function() {
});
}
} else {
implicit += "<span class=\"badge affix-implicit\" data-badge-caption=\"Implicit\"></span><span class=\"implicit\">";
implicit += item.implicitMods.join( "</span><br><span class=\"badge affix-implicit\" data-badge-caption=\"Implicit\"></span><span class=\"implicit\">" );
implicit += "</span><br>";
}
}
if ( !itemType ) {
if ( item.frameType === 1 ) {
var cleanedTypeLine = item.typeLine.replace( "Shaped ", "" );
var match = magicReg.exec( cleanedTypeLine );
// console.log( item.typeLine );
if ( match ) {
itemType = types[match[1]];
// console.log( item.typeLine + ", " + match[1] + ", " + itemType );
} else {
// console.log( "Could not match " + item.typeLine );
}
} else {
itemType = types[item.typeLine];
}
}
if ( item.explicitMods && item.identified ) {
// console.log( item.typeLine );
// console.log( itemType );
if ( itemType && ( item.frameType === 1 || item.frameType === 2 )) {
var split = itemType.split( "_" );
// console.log( split );
// console.log( item.typeLine );
var prefixes = [];
var suffixes = [];
var corrupted = [];
var maxValues = [];
var iterationP;
var iterationS;
var iterationC;
if ( split.length > 1 ) {
prefixes = mods[split[0]][split[1]]["prefix"];
suffixes = mods[split[0]][split[1]]["suffix"];
corrupted = mods[split[0]][split[1]]["corrupted"];
maxValues = mods[split[0]][split[1]]["maxValues"];
} else {
prefixes = mods[split[0]]["prefix"];
suffixes = mods[split[0]]["suffix"];
corrupted = mods[split[0]]["corrupted"];
maxValues = mods[split[0]]["maxValues"];
}
async.each( item.explicitMods, function( explicitMod, cbExplicit ) {
var reg = /([0-9.]+)/g;
var match = reg.exec( explicitMod );
var values = [];
while ( match !== null ) {
values.push( match[1]);
match = reg.exec( explicitMod );
}
var index = "";
var explicitTitle = explicitMod.replace( reg, "#" );
// console.log( explicitTitle );
// console.log( mods["signature"][explicitTitle]);
// If this mod is a prefix
if ( prefixes[explicitTitle]) {
Item.formatAffixes( prefixes[explicitTitle], values, explicitMod, "P", maxValues[explicitTitle], function( res ) {
explicit += res;
totalPrefix++;
cbExplicit();
});
// If this mod is a suffix
} else if ( suffixes[explicitTitle]) {
Item.formatAffixes( suffixes[explicitTitle], values, explicitMod, "S", maxValues[explicitTitle], function( res ) {
explicit += res;
totalSuffix++;
cbExplicit();
});
// If this mod is corrupted
} else if ( corrupted[explicitTitle]) {
Item.formatAffixes( corrupted[explicitTitle], values, explicitMod, "C", maxValues[explicitTitle], function( res ) {
explicit += res;
cbExplicit();
});
// If this mod is a signature mod
} else if ( mods["signature"][explicitTitle]) {
Item.formatAffixes( mods["signature"][explicitTitle], values, explicitMod, "signature", maxValues[explicitTitle], function( res ) {
explicit += res;
cbExplicit();
});
// Otherwise
} else {
explicit +=
"<span class=\"badge affix-explicit\" data-badge-caption=\"?" +
"\"></span><span class=\"explicit\">" + explicitMod + "</span><br>";
// console.log( explicit );
cbExplicit();
}
}, function() {
});
} else {
if ( !itemType ) {
// console.log( "Unknown item type " + itemType + " (" + item.typeLine + ")" );
}
explicit += "<span class=\"badge affix-explicit\" data-badge-caption=\"Explicit\"></span><span class=\"explicit\">";
explicit += item.explicitMods.join( "</span><br><span class=\"badge affix-explicit\" data-badge-caption=\"Explicit\"></span></span><span class=\"explicit\">" );
explicit += "</span><br>";
}
}
// If item is a prophecy
if ( item.frameType === 8 ) {
explicit += item.prophecyText;
}
if ( item.craftedMods ) {
crafted += "<span class=\"badge affix-crafted\" data-badge-caption=\"Crafted\"></span><span class=\"crafted\">";
crafted += item.craftedMods.join( "</span><br><span class=\"badge affix-crafted\" data-badge-caption=\"Crafted\"></span><span class=\"crafted\">" );
crafted += "</span><br>";
totalCrafted = item.craftedMods.length;
}
if ( item.enchantMods ) {
enchant += "<span class=\"badge affix-enchant\" data-badge-caption=\"Enchant\"></span><span class=\"enchant\">";
enchant += item.enchantMods.join( "</span><br><span class=\"badge affix-enchant\" data-badge-caption=\"Enchant\"></span><span class=\"enchant\">" );
enchant += "</span><br>";
}
// console.log( item.totalMods );
if ( item.totalMods && item.totalMods.length > 0 ) {
total += "<span class=\"badge affix-total\" data-badge-caption=\"Total\"></span><span class=\"total\">";
total += item.totalMods.join( "</span><br><span class=\"badge affix-total\" data-badge-caption=\"Total\"></span><span class=\"total\">" );
total += "</span><br>";
}
// console.log( item.pseudoMods );
if ( item.pseudoMods && item.pseudoMods.length > 0 ) {
pseudo += "<span class=\"badge affix-pseudo\" data-badge-caption=\"Pseudo\"></span><span class=\"pseudo\">";
pseudo += item.pseudoMods.join( "</span><br><span class=\"badge affix-pseudo\" data-badge-caption=\"Pseudo\"></span><span class=\"pseudo\">" );
pseudo += "</span><br>";
}
// console.log( item );
properties += "<span class=\"property\"><span class=\"col s5 property-title\">Item Level</span><span class=\"col s7 property-value\">" + item.ilvl + "</span></span><br>";
async.each( item.properties, function( property, cbProperty ) {
// console.log( property );
var prop = "<span class=\"property\"><span class=\"col s5 property-title\">" + property.name + "</span><span class=\"col s7 property-value\">";
if ( property.values.length > 0 ) {
async.each( property.values, function( propertyValue, cbPropertyValue ) {
prop += propertyValue[0] + " ";
cbPropertyValue();
}, function() {
prop += "</span></span><br>";
properties += prop;
cbProperty();
});
} else {
cbProperty();
}
}, function( err ) {
if ( err ) {
console.log( err );
}
// If no b/o price
if ( !prices.convertedPrice ) {
prices.currency = "Negotiate price";
}
var whisperName = name;
if ( item.linkAmount > 4 ) {
name += " " + item.linkAmount + "L";
}
var itemType = item.typeLine.replace( "<<set:MS>><<set:M>><<set:S>>", "" );
if ( itemType === whisperName ) {
if ( item.frameType === 4 ) {
itemType = "Gem";
} else if ( item.frameType === 5 ) {
itemType = "Currency";
} else if ( item.frameType === 6 ) {
itemType = "Divination Card";
} else if ( item.frameType === 8 ) {
itemType = "Prophecy";
} else if ( name.indexOf( "Leaguestone" ) !== -1 ) {
itemType = "Leaguestone";
} else if ( item.frameType === 1 ) {
itemType = "";
}
} else {
whisperName += " " + itemType;
}
// If beta is used, add full path to icon
var imageDomain = "";
if ( config.useBeta ) {
imageDomain = "http://web.poecdn.com/";
}
// If the item is a divination card
if ( item.frameType === 6 ) {
item.icon = "http://web.poecdn.com/image/gen/divination_cards/" + item.artFilename + ".png";
}
var passed = true;
// Compare with open prefix/suffix condition
// console.log( item.frameType + ", " + openSuffix + " >= " + ( 3 - totalSuffix ) + " and " + openPrefix + " >= " + ( 3 - totalPrefix ));
if ( item.frameType === 2 &&
( openSuffix > ( 3 - totalSuffix ) || openPrefix > ( 3 - totalPrefix ) || ( totalPrefix + totalSuffix + totalCrafted ) > ( 6 - openSuffix - openPrefix ))) {
passed = false;
}
callback({
time: time,
account: item.lastCharacterName,
item: name,
whisperName: whisperName,
frameType: item.frameType,
price: prices.convertedPrice,
currency: prices.currency,
originalPrice: prices.originalPrice,
itemId: item.id,
id: guid,
icon: imageDomain + item.icon,
implicit: implicit,
explicit: explicit,
crafted: crafted,
corrupted: item.corrupted,
enchant: enchant,
total: total,
pseudo: pseudo,
properties: properties,
links: item.linkAmount,
league: item.league,
stashTab: item.stashTab,
left: item.x,
top: item.y,
typeLine: item.typeLine,
sockets: item.sockets,
type: itemType,
confidence: item.confidence,
passed: passed
});
});
}
/**
* Compute item price
*
* @params Item, currencyRates
* @return Price
*/
static computePrice( item, currencyRates ) {
// Default currency is chaos
var currency = "chaos";
var originalPrice = "";
var originalAmount = "";
var originalCurrency = "";
var convertedPrice;
var convertedPriceChaos;
var league = item.league;
if ( config.useBeta ) {
league = "beta-" + league;
}
// console.log( JSON.stringify( currencyRates ));
// The price is the name of the stash
var price = item.stashTab;
// If item has a note, the price is the note instead
if ( item.note ) {
price = item.note;
}
priceReg.lastIndex = 0;
var match = priceReg.exec( price );
// If the price is recognized by the RegExp
if ( match ) {
// and if the price is a fraction
if ( match[1] === undefined ) {
// Compute the fraction: 1/2 exa -> 0.5 exa
var fraction = match[2] / match[3];
originalPrice = Math.round( fraction * 100 ) / 100 + " " + match[4];
originalAmount = Math.round( fraction * 100 ) / 100;
originalCurrency = match[4];
// console.log( match[2] + "/" + match[3] + " " + match[4]);
// Same but convert to chaos: 1/2 exa -> 0.5 x chaos_rate(exa)
convertedPrice = fraction * currencyRates[league][Currency.shortToLongLookupTable[match[4]]];
// Otherwise
} else {
// console.log( league );
// console.log( currencyRates[league] );
// Same thing as above without divisions
originalPrice = Math.round( match[1] * 100 ) / 100 + " " + match[4];
originalAmount = Math.round( match[1] * 100 ) / 100;
originalCurrency = match[4];
// console.log( match[1] + " " + match[4]);
convertedPrice = match[1] * currencyRates[league][Currency.shortToLongLookupTable[match[4]]];
}
convertedPriceChaos = convertedPrice;
// If the converted price is above the rate of exalted orbs in this league
// convert the price to exalted instead
if ( convertedPrice > currencyRates[league].exa ) {
convertedPrice /= currencyRates[league].exa;
currency = "exa";
}
// Round up the price to .00 precision
convertedPrice = Math.round( convertedPrice * 100 ) / 100;
// console.log( "Found entry: " + name + " for " + convertedPriceChaos + ":" + convertedPrice + " " + currency + " (" + originalPrice + ")" );
return { convertedPrice: convertedPrice,
convertedPriceChaos: convertedPriceChaos,
originalPrice: originalPrice,
originalAmount: originalAmount,
originalCurrency: originalCurrency,
currency: currency };
// If there is no price, this is barter
} else {
// console.log( "Invalid price: " + price );
originalPrice = "Negotiate price";
return { originalPrice: originalPrice };
}
}
static matchPseudoMod( mod, val, tags, callback ) {
var pseudoMods = {};
var match = {
"+#% to Cold Resistance": function( val ) {
if ( !tags.cold ) {
pseudoMods["(Pseudo) # Resistances"] = 1;
pseudoMods["(Pseudo) # Elemental Resistances"] = 1;
tags.cold = true;
}
pseudoMods["(Pseudo) +#% total Resistance"] = val[0];
pseudoMods["(Pseudo) +#% total Elemental Resistance"] = val[0];
},
"+#% to Lightning Resistance": function( val ) {
if ( !tags.lightning ) {
pseudoMods["(Pseudo) # Resistances"] = 1;
pseudoMods["(Pseudo) # Elemental Resistances"] = 1;
tags.lightning = true;
}
pseudoMods["(Pseudo) +#% total Resistance"] = val[0];
pseudoMods["(Pseudo) +#% total Elemental Resistance"] = val[0];
},
"+#% to Fire Resistance": function( val ) {
if ( !tags.fire ) {
pseudoMods["(Pseudo) # Resistances"] = 1;
pseudoMods["(Pseudo) # Elemental Resistances"] = 1;
tags.fire = true;
}
pseudoMods["(Pseudo) +#% total Resistance"] = val[0];
pseudoMods["(Pseudo) +#% total Elemental Resistance"] = val[0];
},
"+#% to Chaos Resistance": function( val ) {
if ( !tags.chaos ) {
pseudoMods["(Pseudo) # Resistances"] = 1;
tags.chaos = true;
}
pseudoMods["(Pseudo) +#% total Resistance"] = val[0];
},
"+#% to all Elemental Resistances": function( val ) {
if ( !tags.cold ) {
pseudoMods["(Pseudo) # Resistances"] = 1;
pseudoMods["(Pseudo) # Elemental Resistances"] = 1;
tags.cold = true;
}
if ( !tags.lightning ) {
pseudoMods["(Pseudo) # Resistances"] += 1;
pseudoMods["(Pseudo) # Elemental Resistances"] += 1;
tags.lightning = true;
}
if ( !tags.fire ) {
pseudoMods["(Pseudo) # Resistances"] += 1;
pseudoMods["(Pseudo) # Elemental Resistances"] += 1;
tags.fire = true;
}
pseudoMods["(Pseudo) +#% total Resistance"] = val[0] * 3;
pseudoMods["(Pseudo) +#% total Elemental Resistance"] = val[0] * 3;
},
"+#% to Cold and Lightning Resistances": function( val ) {
if ( !tags.cold ) {
pseudoMods["(Pseudo) # Resistances"] = 1;
pseudoMods["(Pseudo) # Elemental Resistances"] = 1;
tags.cold = true;
}
if ( !tags.lightning ) {
pseudoMods["(Pseudo) # Resistances"] += 1;
pseudoMods["(Pseudo) # Elemental Resistances"] += 1;
tags.lightning = true;
}
pseudoMods["(Pseudo) +#% total Resistance"] = val[0] * 2;
pseudoMods["(Pseudo) +#% total Elemental Resistance"] = val[0] * 2;
},
"+#% to Fire and Cold Resistances": function( val ) {
if ( !tags.cold ) {
pseudoMods["(Pseudo) # Resistances"] = 1;
pseudoMods["(Pseudo) # Elemental Resistances"] = 1;
tags.cold = true;
}
if ( !tags.fire ) {
pseudoMods["(Pseudo) # Resistances"] += 1;
pseudoMods["(Pseudo) # Elemental Resistances"] += 1;
tags.fire = true;
}
pseudoMods["(Pseudo) +#% total Resistance"] = val[0] * 2;
pseudoMods["(Pseudo) +#% total Elemental Resistance"] = val[0] * 2;
},
"+#% to Fire and Lightning Resistances": function( val ) {
if ( !tags.lightning ) {
pseudoMods["(Pseudo) # Resistances"] = 1;
pseudoMods["(Pseudo) # Elemental Resistances"] = 1;
tags.lightning = true;
}
if ( !tags.fire ) {
pseudoMods["(Pseudo) # Resistances"] += 1;
pseudoMods["(Pseudo) # Elemental Resistances"] += 1;
tags.fire = true;
}
pseudoMods["(Pseudo) +#% total Resistance"] = val[0] * 2;
pseudoMods["(Pseudo) +#% total Elemental Resistance"] = val[0] * 2;
}
};
mod = mod.replace( /^\([a-zA-Z ]+\)\s*/, "" );
if ( match[mod]) {
match[mod]( val );
}
callback( pseudoMods, tags );
}
static matchTotalMod( mod, val, callback ) {
var totalMods = {};
var match = {
// # Life Regenerated per second
"# Life Regenerated per second": function( val ) {
totalMods["(Total) # Life Regenerated per second"] = val[0];
},
// #% increased Attack Speed
"#% increased Attack Speed": function( val ) {
totalMods["(Total) #% increased Attack Speed"] = val[0];
},
// #% increased Cast Speed
"#% increased Cast Speed": function( val ) {
totalMods["(Total) #% increased Cast Speed"] = val[0];
},
"#% increased Attack and Cast Speed": function( val ) {
totalMods["(Total) #% increased Cast Speed"] = val[0];
totalMods["(Total) #% increased Attack Speed"] = val[0];
},
// #% Elemental damage and spells
"#% increased Burning Damage": function( val ) {
totalMods["(Total) #% increased Burning Damage"] = val[0];
},
"#% increased Fire Damage": function( val ) {
totalMods["(Total) #% increased Burning Damage"] = val[0];
totalMods["(Total) #% increased Fire Damage with Attack Skills"] = val[0];
totalMods["(Total) #% increased Fire Spell Damage"] = val[0];
totalMods["(Total) #% increased Fire Area Damage"] = val[0];
},
"#% increased Elemental Damage": function( val ) {
totalMods["(Total) #% increased Burning Damage"] = val[0];
totalMods["(Total) #% increased Cold Damage with Attack Skills"] = val[0];
totalMods["(Total) #% increased Fire Damage with Attack Skills"] = val[0];
totalMods["(Total) #% increased Lightning Damage with Attack Skills"] = val[0];
totalMods["(Total) #% increased Cold Spell Damage"] = val[0];
totalMods["(Total) #% increased Fire Spell Damage"] = val[0];
totalMods["(Total) #% increased Lightning Spell Damage"] = val[0];
totalMods["(Total) #% increased Elemental Damage with Attack Skills"] = val[0];
totalMods["(Total) #% increased Fire Area Damage"] = val[0];
},
"#% increased Cold Damage": function( val ) {
totalMods["(Total) #% increased Cold Damage with Attack Skills"] = val[0];
totalMods["(Total) #% increased Cold Spell Damage"] = val[0];
},
"#% increased Elemental Damage with Attack Skills": function( val ) {
totalMods["(Total) #% increased Cold Damage with Attack Skills"] = val[0];
totalMods["(Total) #% increased Fire Damage with Attack Skills"] = val[0];
totalMods["(Total) #% increased Lightning Damage with Attack Skills"] = val[0];
totalMods["(Total) #% increased Elemental Damage with Attack Skills"] = val[0];
},
"#% increased Lightning Damage": function( val ) {
totalMods["(Total) #% increased Lightning Damage with Attack Skills"] = val[0];
totalMods["(Total) #% increased Lightning Spell Damage"] = val[0];
},
"#% increased Spell Damage": function( val ) {
totalMods["(Total) #% increased Cold Spell Damage"] = val[0];
totalMods["(Total) #% increased Fire Spell Damage"] = val[0];
totalMods["(Total) #% increased Lightning Spell Damage"] = val[0];
totalMods["(Total) #% increased Spell Damage"] = val[0];
},
"#% increased Area Damage": function( val ) {
totalMods["(Total) #% increased Fire Area Damage"] = val[0];
},
// +# to maximum Life
"+# to maximum Life": function( val ) {
totalMods["(Total) +# to maximum Life"] = val[0];
},
// +# to maximum Mana
"+# to maximum Mana": function( val ) {
totalMods["(Total) +# to maximum Mana"] = val[0];
},
// #% increased Critical Strike Chance for Spells
"#% increased Critical Strike Chance for Spells": function( val ) {
totalMods["(Total) #% increased Critical Strike Chance for Spells"] = val[0];
},
"#% increased Global Critical Strike Chance": function( val ) {
totalMods["(Total) #% increased Critical Strike Chance for Spells"] = val[0];
totalMods["(Total) #% increased Global Critical Strike Chance"] = val[0];
},
"#% increased Mana Regeneration Rate": function( val ) {
totalMods["(Total) #% increased Mana Regeneration Rate"] = val[0];
},
"#% increased maximum Energy Shield": function( val ) {
totalMods["(Total) #% increased maximum Energy Shield"] = val[0];
},
"#% increased Physical Damage": function( val ) {
totalMods["(Total) #% increased Physical Damage"] = val[0];
},
"#% increased Rarity of Items found": function( val ) {
totalMods["(Total) #% increased Rarity of Items found"] = val[0];
},
"#% of Physical Attack Damage Leeched as Life": function( val ) {
totalMods["(Total) #% of Physical Attack Damage Leeched as Life"] = val[0];
},
"+# to all Attributes": function( val ) {
totalMods["(Total) +# to all Attributes"] = val[0];
totalMods["(Total) +# to Dexterity"] = val[0];
totalMods["(Total) +# to Intelligence"] = val[0];
totalMods["(Total) +# to Strength"] = val[0];
totalMods["(Total) +# to maximum Life"] = Math.floor( val[0] / 2 );
totalMods["(Total) +# to maximum Mana"] = Math.floor( val[0] / 2 );
},
"+# to Dexterity": function( val ) {
totalMods["(Total) +# to Dexterity"] = val[0];
},
"+# to Intelligence": function( val ) {
totalMods["(Total) +# to Intelligence"] = val[0];
totalMods["(Total) +# to maximum Mana"] = Math.floor( val[0] / 2 );
},
"+# to Strength": function( val ) {
totalMods["(Total) +# to Strength"] = val[0];
totalMods["(Total) +# to maximum Life"] = Math.floor( val[0] / 2 );
},
"+# to Dexterity and Intelligence": function( val ) {
totalMods["(Total) +# to Dexterity"] = val[0];
totalMods["(Total) +# to Intelligence"] = val[0];
totalMods["(Total) +# to maximum Mana"] = Math.floor( val[0] / 2 );
},
"+# to Strength and Dexterity": function( val ) {
totalMods["(Total) +# to Dexterity"] = val[0];
totalMods["(Total) +# to Strength"] = val[0];
totalMods["(Total) +# to maximum Life"] = Math.floor( val[0] / 2 );
},
"+# to Strength and Intelligence": function( val ) {
totalMods["(Total) +# to Strength"] = val[0];
totalMods["(Total) +# to Intelligence"] = val[0];
totalMods["(Total) +# to maximum Life"] = Math.floor( val[0] / 2 );
totalMods["(Total) +# to maximum Mana"] = Math.floor( val[0] / 2 );
},
"+# to Level of Socketed Gems": function( val ) {
totalMods["(Total) +# to Level of Socketed Aura Gems"] = val[0];
totalMods["(Total) +# to Level of Socketed Bow Gems"] = val[0];
totalMods["(Total) +# to Level of Socketed Chaos Gems"] = val[0];
totalMods["(Total) +# to Level of Socketed Fire Gems"] = val[0];
totalMods["(Total) +# to Level of Socketed Cold Gems"] = val[0];
totalMods["(Total) +# to Level of Socketed Lightning Gems"] = val[0];
totalMods["(Total) +# to Level of Socketed Elemental Gems"] = val[0];
totalMods["(Total) +# to Level of Socketed Melee Gems"] = val[0];
totalMods["(Total) +# to Level of Socketed Minion Gems"] = val[0];
totalMods["(Total) +# to Level of Socketed Movement Gems"] = val[0];
totalMods["(Total) +# to Level of Socketed Spell Gems"] = val[0];
totalMods["(Total) +# to Level of Socketed Strength Gems"] = val[0];
totalMods["(Total) +# to Level of Socketed Vaal Gems"] = val[0];
},
"+# to Level of Socketed Aura Gems": function( val ) {
totalMods["(Total) +# to Level of Socketed Aura Gems"] = val[0];
},
"+# to Level of Socketed Bow Gems": function( val ) {
totalMods["(Total) +# to Level of Socketed Bow Gems"] = val[0];
},
"+# to Level of Socketed Chaos Gems": function( val ) {
totalMods["(Total) +# to Level of Socketed Chaos Gems"] = val[0];
},
"+# to Level of Socketed Fire Gems": function( val ) {
totalMods["(Total) +# to Level of Socketed Fire Gems"] = val[0];
},
"+# to Level of Socketed Cold Gems": function( val ) {
totalMods["(Total) +# to Level of Socketed Cold Gems"] = val[0];
},
"+# to Level of Socketed Lightning Gems": function( val ) {
totalMods["(Total) +# to Level of Socketed Lightning Gems"] = val[0];
},
"+# to Level of Socketed Elemental Gems": function( val ) {
totalMods["(Total) +# to Level of Socketed Elemental Gems"] = val[0];
},
"+# to Level of Socketed Melee Gems": function( val ) {
totalMods["(Total) +# to Level of Socketed Melee Gems"] = val[0];
},
"+# to Level of Socketed Minion Gems": function( val ) {
totalMods["(Total) +# to Level of Socketed Minion Gems"] = val[0];
},
"+# to Level of Socketed Movement Gems": function( val ) {
totalMods["(Total) +# to Level of Socketed Movement Gems"] = val[0];
},
"+# to Level of Socketed Spell Gems": function( val ) {
totalMods["(Total) +# to Level of Socketed Spell Gems"] = val[0];
},
"+# to Level of Socketed Strength Gems": function( val ) {
totalMods["(Total) +# to Level of Socketed Strength Gems"] = val[0];
},
"+# to Level of Socketed Vaal Gems": function( val ) {
totalMods["(Total) +# to Level of Socketed Vaal Gems"] = val[0];
},
"+# to maximum Energy Shield": function( val ) {
totalMods["(Total) +# to maximum Energy Shield"] = val[0];
},
"+#% to all Elemental Resistances": function( val ) {
totalMods["(Total) +#% to all Elemental Resistances"] = val[0];
totalMods["(Total) +#% to Cold Resistance"] = val[0];
totalMods["(Total) +#% to Fire Resistance"] = val[0];
totalMods["(Total) +#% to Lightning Resistance"] = val[0];
},