-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstyleequip.js
More file actions
1374 lines (1141 loc) · 36.8 KB
/
Copy pathstyleequip.js
File metadata and controls
1374 lines (1141 loc) · 36.8 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
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
/*
TODO:
** params **
NoCharge <- need to support staves/merlins
BundleMax <- don't see this in use even in itemdb (old tho)
SetBonus <- don't see this in use
add_shape_collect_rate
AlchemyElementalBonus
AlchemyElemental
cooltime_sec
frostbite_damage_rate
frostbite_duration
frostbite_rate
frozenattack_duration
frozenattack_rate
lance_piercing
magazinetype
max_bullet
max_range_mod
min_range_mod
motion_category
motion_element
random_product
splash_angle
splash_damage
splash_radius
stamina_usage
summon_limit
summon_rate
summon_set
summon_shadow_rgn_only
talent_id
talent_level
trainingbonus
** categories **
big_cooking_kneader | huge_backtool
tamingbaton
trainingbaton
hide_palm
quest_item
collecting_tool
disciple1_weapon
enchant_entrust
giant_full_swing
group_idle_motion
handle
lordweapon
piercing
real_brionac
tool
*/
const DyeNames = {
"0": "",
"1": "Cloth",
"2": "Leather",
"3": "Pixie",
"4": "Nylon",
"33": "Winter Lights",
"35": "Sprinkles",
"58": "Panda",
"61": "Elf",
"62": "Fur",
"65": "Giant",
// Metals
"5": "Armor Metal",
"23": "Weapon Metal",
"24": "Hilt Metal",
"200": "Armor Metal",
"201": "Weapon Metal",
"202": "Hilt Metal",
// Dye Blockers
"12": "None", // slot can still be seen ingame
};
function showSubCategoryStuff(t, h) {
var val = "/" + $(t).val() + "/";
// Enable special forms:
if (!h) $(".equip-category-custom").hide();
val.replace(/\{([^}]+)\}/g, function (_, name) {
console.log(name);
showSubCategoryStuff($("#equip-category-" + name).show(), true);
});
return val;
}
jQuery(function ($) {
// Remove tab-hide from children of comboboxes
$(".combobox input").removeClass("tab-hide").show();
// Set up dynamic pieces for StyleWeapon and StyleEquip.
$("#equip-xml").change(updateEquipForm);
$("#equip").find("input, select, textarea").change(updateEquipOutput);
$(".equip-category :first-child, .equip-category-changer").find("input, select").change(updateEquipCategoryString);
$("#equip-category").change(updateEquipCategorySelectors);
$("#equip-category-hand").change(function () {
var val = $(this).val();
// Hide all first.
$(".equip-category").find("[id^='equip-category-type-']").hide();
// Show relevant one.
if (val) $("#equip-category-type-" + val).show();
$(".equip-speed").show();
if (val == "twohand") {
$("#equip-category-giant_onehand").show();
hidecheck("#equip-category-twin_sword");
} else {
if (!val) {
$(".equip-speed").hide();
}
hidecheck("#equip-category-giant_onehand");
hidecheck("#equip-category-twin_club");
hidecheck("#equip-category-twin_sword");
}
}).change();
$("#equip-category-slot, #equip-category-acc-type").change(function () {
var val = showSubCategoryStuff($("#equip-category-slot"));
});
$("#equip-category-type-righthand, #equip-category-type-twohand, #equip-category-hybrid-type").change(function () {
if (!$(this).is(":visible")) return;
var val = showSubCategoryStuff(this);
// Show dual wielding options
if (val.indexOf("/edged/") >= 0) {
$("#equip-category-twin_sword").show();
hidecheck("#equip-category-twin_club");
} else if (val.indexOf("/blunt/") >= 0) {
$("#equip-category-twin_club").show();
hidecheck("#equip-category-twin_sword");
} else {
hidecheck("#equip-category-twin_club");
hidecheck("#equip-category-twin_sword");
}
// Race-locked triggers and weapon range
$("#equip-human, #equip-giant, #equip-elf").prop("disabled", false);
$(".equip-range").hide();
if (val.indexOf("/lance/") >= 0) {
$("#equip-human, #equip-giant").prop("checked", true);
$("#equip-elf").prop({
"checked": false,
"disabled": true,
});
} else if (val.indexOf("/atlatl/") >= 0) {
$(".equip-range").show();
$("#equip-giant").prop("checked", true);
$("#equip-human, #equip-elf").prop({
"checked": false,
"disabled": true,
});
} else if (val.indexOf("/bow") + val.indexOf("/crossbow/")
+ val.indexOf("/dualgun/") + val.indexOf("/shuriken/") + 4
) {
$(".equip-range").show();
}
// Trigger change on speed bit to switch based on weapon type
$("#equip-speed").change();
}).change();
$("#equip-speed").change(function () {
var speed = $(this).val();
var weapon = $("#equip-category-type-righthand:visible").val();
if (weapon) {
weapon = "/" + weapon + "/";
var bow = weapon.indexOf("/bow") >= 0 || weapon.indexOf("/crossbow/") >= 0;
var gun = weapon.indexOf("/dualgun/") >= 0;
switch (speed) {
case "0":
if (bow) speed = "5";
else if (gun) speed = "15";
break;
case "1":
if (bow) speed = "6";
else if (gun) speed = "16";
break;
case "2":
if (bow) speed = "7";
else if (gun) speed = "17";
break;
case "3":
if (bow) speed = "8";
else if (gun) speed = "18";
break;
case "4":
if (bow) speed = "9";
else if (gun) speed = "19";
break;
}
$("#equip-speed-raw").val(speed);
}
});
$(".equip-market input").change(function () {
// Update the predicted sale price.
var buyprice = $("#equip-buyprice").val(),
sellprice = $("#equip-sellprice").val(),
accurate;
if (!sellprice && buyprice) {
buyprice = parseInt(buyprice);
if (buyprice == 0) {
sellprice = 0;
accurate = true;
} else if (buyprice <= 100) {
sellprice = buyprice / 2;
accurate = false;
} else if (buyprice <= 1000) {
sellprice = buyprice / (2 + (buyprice - 100) * 2 / 900);
accurate = false;
} else if (buyprice <= 10000) {
sellprice = buyprice / (4 + (buyprice - 1000) * 6 / 9000);
accurate = false;
} else {
sellprice = buyprice / 10;
accurate = true;
}
// Truncate float.
var trunc = Math.floor(sellprice * 100).toString();
trunc = trunc.substr(0, trunc.length - 2) + "." + trunc.substr(trunc.length - 2);
var $wps = $("#equip-predictedsale").empty();
$("<span>").text("Predicted: " + trunc).appendTo($wps);
if(!accurate) $('<abbr title="Price may be inaccurate.">*</abbr>').appendTo($wps);
}
});
$("#equip-add-another-saleprice, #equip-add-another-setbonus").click(function () {
var $parent = $(this).parent();
var $addmore = $(this).detach();
var $newlist = $parent.clone(true);
$parent.removeAttr("id");
// Clear fields and add + button back in.
$newlist.find("select").val($newlist.find("select option:first").val());
$newlist.find("input").val("");
$addmore.insertBefore($newlist.find(".help"));
$newlist.insertAfter($parent);
// Add - to old one.
$('<span class="action">-</span>').insertBefore($parent.find(".help")).click(function () {
$(this).parent().remove();
});
});
$("#equip-category-repairable").change(function () {
var val = $(this).val();
if (val == "not_repairable") {
$(".equip-repairs").addClass("hidden");
} else {
$(".equip-repairs").removeClass("hidden").children("span").addClass("hidden");
$(".equip-repairs").children("." + (val || "tailor_repairable")).removeClass("hidden");
}
}).change();
$("#output").val("");
});
function updateEquipForm() {
// Update the form whenever the XML is changed.
var xml = $(this).val().trim();
var weapon = $("#weapon-tab").hasClass("active");
var equip = $("#equip-tab").hasClass("active");
function changeTab(category) {
var $tab;
if (category.indexOf("/righthand/") >= 0
|| category.indexOf("/twohand/") >= 0) {
$tab = $("#weapon-tab");
weapon = true;
equip = false;
} else {
$tab = $("#equip-tab");
equip = true;
weapon = false;
}
if (!$tab.hasClass("active")) $tab.click();
}
function trading(a,b,c,d,e,f,g) {
$("#equip-sellable-npc").prop("checked", !!a);
$("#equip-sellable-player").prop("checked", !!b);
$("#equip-tradable").prop("checked", !!c);
$("#equip-storeonpets").prop("checked", !!d);
$("#equip-otherpick").prop("checked", !!e);
$("#equip-bankable").prop("checked", !!f);
$("#equip-withdrawable").prop("checked", !!g);
}
function setTradability(trade) {
switch (trade) {
// Honestly not too sure on these.
case "0": trading(1,1,1,1,1,1,1); break;
case "1": trading(0,1,1,1,0,1,1); break;
case "2": trading(0,0,0,0,0,0,0); break;
case "3": trading(0,0,0,0,0,1,1); break;
case "4": trading(0,0,1,0,1,0,0); break;
case "5": trading(0,0,0,0,0,1,0); break;
case "8": trading(0,0,0,0,0,0,0); break;
case "12": trading(0,0,0,1,0,1,1); break;
case "14": trading(0,1,1,0,0,1,1); break;
}
}
function setRace(race) {
$("#equip-human").prop("checked", !race || race.indexOf("/human/") >= 0);
$("#equip-elf").prop("checked", !race || race.indexOf("/elf/") >= 0);
$("#equip-giant").prop("checked", !race || race.indexOf("/giant/") >= 0);
$("#equip-female, #equip-male").prop("checked", true);
if (race) {
if (race.indexOf("/male/") >= 0) $("#equip-female").prop("checked", false);
else if (race.indexOf("/female/") >= 0) $("#equip-male").prop("checked", false);
}
}
function setDye(name, idx) {
var sel = ".equip-dyeing input[name='" + name + "']";
$(sel).prop("checked", false);
$(sel + "[value='" + (idx || 0) + "']").prop("checked", true);
}
function clearList(sel) {
$(sel + ":not(:last) .action").click();
}
var firstBonus = true;
function addSetBonus(b, n, x) {
if (firstBonus) firstBonus = false;
else $("#equip-add-another-setbonus").click();
var $row = $(".equip-set-bonus:last");
$row.find(".equip-bonus").val(b);
$row.find(".equip-minbonus").val(n);
$row.find(".equip-maxbonus").val(x);
}
if (xml.charAt(0) == "<") {
// XML Version
var element = jQuery.parseXML(xml);
// Set bonus?
var bonus;
if (bonus = element.getElementsByTagName("Item").item(0)) {
// Clear existing entries...
clearList(".equip-set-bonus");
var splits = bonus.getAttribute("element").split(" ");
$.each(bonus.getElementsByTagName("quality"), function (_, e) {
splits = splits.concat(e.getAttribute("bonus").split(" "));
});
// Add set bonuses
for (var i = 0; i < splits.length; i++) {
var sp2 = splits[i].split(":");
var b = sp2[0];
var xn = sp2[1].split("~");
var n = xn[0];
var x = xn.length > 1 ? xn[1] : n;
addSetBonus(b, n, x);
}
return;
}
var item = element.getElementsByTagName("Mabi_Item").item(0);
if (!item) {
console.warn("Bad XML pasted. Not Mabi_Item?");
return;
}
// Automatically change tabs
changeTab(item.getAttribute("Category"));
function set(s, attr, f) {
var v = item.getAttribute(attr);
return $(s).val(f ? f(v) : v);
}
function ref(x) {
return x.replace(/_LT\[xml\.itemdb\.([^\]]+)\]/, "Lookup $1 in data/local/xml/itemdb.english.txt");
}
function nozero(x) { return x == "0" ? "" : x; }
function defaultTo(x) { return function (y) { return y || x; } }
// Decode XML attribute.
var subxml = (item.getAttribute("XML") || "").trim();
var specials = {};
if (subxml) {
// Fix common bugs in it...
var floatingParams = subxml.match(/<(\s*\S+\s*=\s*"[^"]*")+\s*\/\s*>/);
if (floatingParams) {
// Throw these into root XML tag.
subxml.replace(/^<xml/, "<xml " + floatingParams[1]);
}
var openStuff = subxml.match(/^<xml([^"\/>]+|"[^"]*")*/);
if (openStuff && subxml.charAt(openStuff[0].length) != "/" && !subxml.match(/<\s*\/\s*xml\s*>$/)) {
// No closing main element.
subxml += "</xml>";
}
// Add space between ending " of a param value and next attribute
subxml = subxml.replace(/(=\s*"[^"]*")(\S)/g, "$1 $2");
var subdoc = jQuery.parseXML(subxml);
function addAll(pfx, x) {
if (x.tagName != "xml") pfx += x.tagName + "_";
for (var i = 0; i < x.attributes.length; ++i) {
var attr = x.attributes[i];
specials[attr.name] = attr.value;
}
for (var i = 0; i < x.children.length; ++i) {
addAll(pfx, x.children[i]);
}
}
addAll("", subdoc.firstChild);
}
function set2(s, attr, f) {
if (attr in specials) {
var v = specials[attr];
s = $(s).val(f ? f(v) : v)
delete specials[attr];
return s;
} else {
return $(s).val("");
}
}
set("#equip-name", "Text_Name1", ref).prev().addClass("highlight");
set("#equip-desc", "Text_Desc1", ref).prev().addClass("highlight");
set("#equip-width", "Inv_XSize");
set("#equip-height", "Inv_YSize");
setRace(item.getAttribute("Attr_RaceFilter"));
set("#equip-category", "Category").change();
setTradability(item.getAttribute("Attr_ActionFlag"));
if (weapon) {
var speed = parseInt(item.getAttribute("Par_AttackSpeed"));
$("#equip-speed").val((speed % 5).toString());
$("#equip-speed-raw").val(speed.toString());
set("#equip-hits", "Par_DownHitCount");
set("#equip-min-damage", "Par_AttackMin");
set("#equip-max-damage", "Par_AttackMax");
set("#equip-min-injury", "Par_WAttackMin");
set("#equip-max-injury", "Par_WAttackMax");
set("#equip-critical", "Par_CriticalRate");
set("#equip-balance", "Par_AttackBalance");
set("#equip-range", "Par_EffectiveRange", nozero);
}
set("#equip-durability", "Par_DurabilityMax");
set("#equip-defense", "Par_Defense", nozero);
if (equip) {
set("#equip-protection", "Par_ProtectRate", nozero);
set2("#equip-magic-defense", "magic_defense");
set2("#equip-magic-protection", "magic_protect");
}
$("#equip-category-reforgeable").prop("checked", item.getAttribute("Metalware_UItooltip") == "true");
$("#equip-category-enchantable").prop("checked", item.getAttribute("Enchant_UItooltip") == "true");
//$(".equip-repairs > span").addClass("highlight");
if (item.getAttribute("Upgrade_UItooltip") == "true") {
set("#equip-upgrades", "Par_UpgradeMax");
set("#equip-gem-upgrades", "Par_GemUpgradeMax", defaultTo("0"));
} else {
$("#equip-upgrades").val("");
$("#equip-gem-upgrades").val("");
}
if (weapon) {
$("#equip-spupable").prop("checked", specials["enhance_type_s"] || specials["enhance_type_r"]);
if (item.getAttribute("Category").indexOf("/not_ego/") >= 0) {
$("#equip-spirit").prop("checked", false);
} else {
$("#equip-spirit").addClass("highlight")
}
}
// Dyeing
function setXmlDye(name, attr) {
setDye(name, item.getAttribute(attr));
}
setXmlDye("color1", "App_Color1");
setXmlDye("color2", "App_Color2");
setXmlDye("color3", "App_Color3");
setXmlDye("color4", "App_Color5");
setXmlDye("color5", "App_Color6");
setXmlDye("color6", "App_Color7");
// Market
$(".equip-market").show();
set("#equip-buyprice", "Price_Buy").change();
if (set("#equip-sellprice", "Price_Sell").val() == "") {
$(".equip-sellprice").hide();
$(".equip-resell label").addClass("highlight")
} else {
$(".equip-resell").hide();
}
// Add leftover XML param stuff
var specialsString = "";
for (var x in specials) {
specialsString += x + "=" + specials[x] + "\n";
}
$("#equip-properties").val(specialsString);
$("#equip-obtain, .equip-sellers, .equip-saleprice").addClass("highlight");
} else if (xml.substr(0, 2) == "{{") {
// Wiki data format
var wikiSplits = xml
// Remove template surroundings
.replace("{{{1}}}", "")
.replace(/\{\{\{format\|?\}\}\}/, "")
.replace(/^\{\{/, '').replace(/\}\}<noinclude>[\s\S]+$|\}\}\s*$/, '')
// Remove comments
.replace(/<!--[\s\S]*?-->/g, '')
// Split by pipes
.split("\n|");
var wiki = {};
for (var i = 0; i < wikiSplits.length; i++) {
var splits = wikiSplits[i].split("=");
var key = splits[0].trim();
if (key) wiki[key] = splits.slice(1).join("=").trim();
}
function set(s, name, def) {
if (name in wiki) {
s = $(s).val(wiki[name]);
delete wiki[name];
return s;
} else {
return $(s).val(def || "");
}
}
function get(name, def) {
if (name in wiki) {
var v = wiki[name];
delete wiki[name];
return v;
} else {
return def;
}
}
function getTrue(name, def) {
var v = get(name, def || "").toLowerCase();
return v == "true" || v == "y";
}
function setTrue(sel, name, def) {
$(sel).prop("checked", !!getTrue(name, def));
}
var $cat = set("#equip-category", "Category");
// Automatically change tabs
changeTab($cat.val());
set("#equip-name", "Name");
var icon;
if(set("#equip-page", "Page").val()
|| (icon = set("#equip-icon", "Icon").val())) {
// Make this section visible.
$("#equip-custom-page").click();
// Add in the ext...
if ("Ext" in wiki) {
$("#equip-icon").val(icon + "." + get("Ext"));
} else if (icon.indexOf(".") >= 0) {
$("#equip-icon").val(icon + ".png");
}
}
set("#equip-desc", "Desc");
$cat.change();
if ("BuyPrice" in wiki) {
$(".equip-market").show();
set("#equip-buyprice", "BuyPrice");
set("#equip-sellprice", "SellPrice");
}
if ("Tradability" in wiki) {
// Old form tradability
setTradability(get("Tradability"));
} else {
// New form tradability
trading(
getTrue("CanSellToNPC", "False"),
getTrue("CanSellToPlayer", "False"),
getTrue("CanTrade", "False"),
getTrue("CanStorePet", "False"),
getTrue("CanPickupOther", "False"),
getTrue("CanBank", "False"),
getTrue("CanWithdrawOther", "False")
);
}
if ("Race" in wiki) {
// Old form Race string
setRace(get("Race"));
} else {
// New form race params
var HM = getTrue("HumanMale"), HF = getTrue("HumanFemale"),
EM = getTrue("ElfMale"), EF = getTrue("ElfFemale"),
GM = getTrue("GiantMale"), GF = getTrue("GiantFemale");
var human = HM + HF, elf = EM + EF, giant = GM + GF,
male = HM + EM + GM, female = HF + EF + GF;
$("#equip-human").prop("checked", !!human);
$("#equip-elf").prop("checked", !!elf);
$("#equip-giant").prop("checked", !!giant);
$("#equip-male").prop("checked", !!male);
$("#equip-female").prop("checked", !!female);
function warnBadScore(t, x, s) {
if (x && x != s) console.warn("Race " + t + " disjointed. Scored " + x.toString() + "/" + s.toString());
}
warnBadScore("human", human, 2);
warnBadScore("elf", elf, 2);
warnBadScore("giant", giant, 2);
warnBadScore("male", male, 3);
warnBadScore("female", female, 3);
}
// Inventory dims
set("#equip-width", "Width");
set("#equip-height", "Height");
// Color palettes
setDye("color1", get("Color1"));
setDye("color2", get("Color2"));
setDye("color3", get("Color3"));
setDye("color4", get("Color4"));
setDye("color5", get("Color5"));
setDye("color6", get("Color6"));
// Can*
setTrue("#equip-category-reforgeable", "CanReforge", "False");
setTrue("#equip-category-enchantable", "CanEnchant", "False");
if (weapon) {
var speed = get("AttackSpeed");
if (speed) {
$("#equip-speed").val((parseInt(speed) % 5).toString());
$("#equip-speed-raw").val(speed);
}
var hits = get("DownHitCount");
if (hits) {
$("#equip-hits").val(parseInt(hits) + 1);
}
// Weapon stats
set("#equip-min-damage", "MinDamage");
set("#equip-max-damage", "MaxDamage");
set("#equip-min-injury", "MinInjury");
set("#equip-max-injury", "MaxInjury");
set("#equip-critical", "Critical");
set("#equip-balance", "Balance");
var range = get("Range");
if (range) {
$(".equip-range").show();
$("#equip-range").val(range);
}
}
set("#equip-durability", "Durability");
set("#equip-defense", "Defense");
if (equip) {
set("#equip-protection", "Protection");
}
set("#equip-magic-defense", "magic_defense");
set("#equip-magic-protection", "magic_protect");
// Upgrades
set("#equip-upgrades", "Upgrades");
set("#equip-gem-upgrades", "GemUpgrades");
if (weapon) {
setTrue("#equip-spupable", "SpecialUpgrade");
setTrue("#equip-spirit", "Spirit");
}
// Set bonuses
clearList(".equip-set-bonus");
var setBonusSplits = get("SetBonus", "").split("\n");
var qualities = [];
for (var i = 0; i < setBonusSplits.length; i++) {
var sp = setBonusSplits[i];
if (!sp) continue;
var mo = sp.match(/\+(\d+)(~(\d+))?\s+([^<\r\n.]+)/);
var val = $('.equip-bonus:first option:contains("' + mo[4] + '")').val();
var n = mo[1];
var x = mo[3] || n;
if (sp.substr(0, 2) == "**") {
// Quality bonus
qualities.push([val, n, x]);
} else {
// Base bonus
addSetBonus(val, n, x);
}
}
for (var i = 0; i < qualities.length; i++) {
addSetBonus.apply(null, qualities[i]);
}
// TODO: Repair costs
// Resell
var resell = get("Resell");
if (resell) {
$(".equip-resell").show();
$("#equip-resell").val(resell);
}
// Lists
function setList(s, x) {
var list = get(x, "");
$(s).val(list.replace(/^\*/, "").replace(/\n\*/g, "\n"));
}
setList("#equip-obtain", "ObtainList");
clearList(".equip-seller-list");
var sell = get("SellList", "").split("\n");
var $sellers = $(".equip-seller-list:last .equip-sellers");
var sellers = [];
for (var i = 0; i < sell.length; i++) {
var line = sell[i];
if (!line) continue;
if (line.substr(0, 2) == "**") {
sellers.push(line.substr(2).replace(/\[\[|\]\]/g, "").trim());
} else {
if (i) $("#equip-add-another-saleprice").click();
var $last = $(".equip-seller-list:last");
$sellers.val(sellers.join("\n"));
$sellers = $last.find(".equip-sellers");
sellers = [];
// Parse out price and currency.
var mo = line.substr(1).match(/^\s*(\d+)\s*(.+)$/);
$last.find(".equip-saleprice").val(mo[1]);
$last.find(".equip-salecurrency").val(mo[2].toUpperCase());
}
}
setList("#equip-information", "Information");
// Extra special properties
delete wiki.UUID;
delete wiki.XML;
var specials = "";
for (var x in wiki) {
specials += x + "=" + wiki[x] + "\n";
}
$("#equip-properties").val(specials);
} else {
console.warn("Unknown paste format.");
}
}
function updateEquipCategoryString() {
// When a selector is changed the string must be changed too.
// TODO: Respect changes made in the string?
var cat = "/equip/";
function slash(x) { return x && x.charAt(x.length - 1) != "/" ? x + "/" : x; }
function check(s, t, f) { return slash($(s).is(":checked") ? t : f); }
// Pull off anything that's tacked onto the end, roughly
var tacks = "";
function tackOn(x) {
var endPoint = x.indexOf("/*/");
if (endPoint >= 0) {
tacks += x.substr(endPoint + 2);
return x.substr(0, endPoint);
}
return x;
}
var preformatted = {};
function formatter(_, name) {
var $target = $("#equip-category-" + name);
if ($target.is("select")) {
var val = $target.val().replace(/\{([^}]+)\}(\/|$)/g, formatter);
return slash(tackOn(val));
} else if (name in preformatted) {
return preformatted[name];
}
return "";
}
var $hand = $("#equip-category-hand");
var hand = $hand.val();
var weapon = $hand.is(":visible") && hand;
if (weapon) {
var $weapcat = $("#equip-category-category");
var weapcat = $weapcat.is(":visible") ? $weapcat.val() : "";
var type = $("#equip-category-type-" + hand).val();
type = tackOn(type);
var chargeable = !!$("#equip-category-bolt-charge").val();
preformatted = {
// Construct magic string
"magic": check("#equip-category-melee_wand", "melee_wand", "")
+ check("#equip-category-party_healing",
$("#equip-category-healing_wand").is(":checked") ? "healing_wand" : "party_healing",
"")
+ (chargeable ? "" :
check("#equip-category-ice_wand", "ice_wand", "")
+ check("#equip-category-lightning_wand", "lightning_wand", "")
+ check("#equip-category-fire_wand", "fire_wand", "")),
"suppup-expire": $("#equip-suppup-daily_expire").val() ? "daily_expire" : "",
};
// Add handedness and formatted type with hybridization
cat += hand + "/";
cat += (type + "/" + slash($("#equip-category-hybrid-type").val()))
.replace(/\{([^}]+)\}\//g, formatter);
// Fomor weapons are both /weapon/ and /demon_weapon/
if (weapcat == "demon_weapon") cat += "demon_weapon/";
}
var $slot = $("#equip-category-slot");
var equip = $slot.is(":visible") && $slot.val();
if (equip) {
cat = "/" + formatter(null, "slot");
}
if (weapon || equip) {
// Standard selects
cat += slash($("#equip-category-repairable").val());
// Standard checkboxes
cat += check("#equip-category-enchantable", "", "not_enchantable");
cat += check("#equip-category-bless", "", "not_bless");
cat += check("#equip-category-holyfire", "", "not_holyfire");
cat += check("#equip-category-reforgeable", "", "not_metalware");
cat += check("#equip-category-dropable", "", "not_dropable");
cat += check("#equip-category-destroyable", "destroyable", "");
// Add race restrictions
cat += weaponRaceMap({
"000": "", // Assume all
"001": "elf_only/",
"010": "giant_only/",
"011": "?_only/", // Not actually possible
"100": "human_only/",
"101": "human_elf_only/",
"110": "human_giant_only/",
"111": "",
});
// Dyeability (don't remember where this goes)
cat += slash($("#equip-category-dyeable").val());
//if (weapon) {
// TODO: Chance of freezing enemy
//frozenattack
//}
// Tack ons
cat += slash(tacks.substr(1));
$("#equip-category").val(cat);
}
}
function weaponRaceMap(raceMap) {
var raceKey = ($("#equip-human").is(":checked") ? "1" : "0")
+ ($("#equip-giant").is(":checked") ? "1" : "0")
+ ($("#equip-elf").is(":checked") ? "1" : "0");
return raceMap[raceKey];
}
function updateEquipCategorySelectors() {
// When the string is changed the selectors must be updated.
var weapon = $("#weapon-tab").hasClass("active");
var equip = $("#equip-tab").hasClass("active");
var text = $("#equip-category").val();
if (text.charAt(0) != "/") text = "/" + text;
if (text.charAt(text.length - 1) != "/") text += "/";
var splits = text.substring(1, text.length - 1).split("/");
function allPartsExist(sel) {
var val = $(sel).val();
var vs = val.split("/"), success = true;
for (var i = 0; i < vs.length; ++i) {
var v = vs[i];
if (v.charAt(0) != "{" && v != "?" && v != "*" && splits.indexOf(v) == -1) {
success = false;
break;
}
}
if (success) {
$(sel).parent().val(val).change();
return true;
}
}
var sel;
if (weapon) {
$("#equip-category-hand").val(splits[1]).change();
sel = "#equip-category-type-" + splits[1];
} else {
sel = "#equip-category-slot";
}
$(sel).children().each(function () { if (allPartsExist(this)) return false });
$("#equip-category-enchantable, #equip-category-reforgeable, #equip-category-bless, #equip-category-holyfire, #equip-category-dropable").prop("checked", true);
var not2id = {
"not_enchantable": "#equip-category-enchantable",
"not_bless": "#equip-category-bless",
"not_holyfire": "#equip-category-holyfire",
"not_metalware": "#equip-category-reforgeable",
"not_dropable": "#equip-category-dropable",
};
// Select container parts