-
Notifications
You must be signed in to change notification settings - Fork 7
/
MainWindow.xaml.cs
4386 lines (3871 loc) · 225 KB
/
MainWindow.xaml.cs
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
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Text.RegularExpressions;
using System.Windows.Shapes;
using System.Xml;
using Items.Protobuf.Shared;
namespace Devm_items_editor
{
public class Item
{
public Item(string name, int fromID, int toID)
{
Name = name;
FromID = fromID;
ToID = toID;
#region Strings
Article = string.Empty;
Plural = string.Empty;
Type = string.Empty;
Description = string.Empty;
RuneSpellName = string.Empty;
FloorChange = string.Empty;
CorpseType = string.Empty;
FluidSource = string.Empty;
WeaponType = string.Empty;
SlotType = string.Empty;
AmmoType = string.Empty;
ShootType = string.Empty;
Effect = string.Empty;
LootType = string.Empty;
Field_Type = string.Empty;
PartnerDirection = string.Empty;
EditorSuffix = string.Empty; // To-Do
#endregion
#region Int values
Weight = int.MinValue;
Armor = int.MinValue;
Defense = int.MinValue;
ExtraDefense = int.MinValue;
Attack = int.MinValue;
RotateTo = int.MinValue;
WrapableTo = int.MinValue;
ContainerSize = int.MinValue;
MaxTextLenght = int.MinValue;
WriteOnceItemId = int.MinValue;
Range = int.MinValue;
DecayTo = int.MinValue;
EquipTo = int.MinValue;
DequipTo = int.MinValue;
Duration = int.MinValue;
Charges = int.MinValue;
HitChance = int.MinValue;
MaxHitChance = int.MinValue;
Speed = int.MinValue;
HealthGain = int.MinValue;
HealthTicks = int.MinValue;
ManaGain = int.MinValue;
ManaTicks = int.MinValue;
SkillSword = int.MinValue;
SkillAxe = int.MinValue;
SkillClub = int.MinValue;
SkillDistance = int.MinValue;
SkillFish = int.MinValue;
SkillShield = int.MinValue;
SkillFist = int.MinValue;
SkillCriticalChance = int.MinValue;
SkillCriticalDamage = int.MinValue;
SkillLifeChance = int.MinValue;
SkillLifeAmount = int.MinValue;
SkillManaChance = int.MinValue;
SkillManaAmount = int.MinValue;
MaxHitPoints = int.MinValue;
MaxHitPointsPercent = int.MinValue;
MaxManaPoints = int.MinValue;
MaxManaPointsPercent = int.MinValue;
MagicLevel = int.MinValue;
MagicLevelPercent = int.MinValue;
AbsorbFieldEnergy = int.MinValue;
AbsorbFieldFire = int.MinValue;
AbsorbFieldPoison = int.MinValue;
AbsorbAll = int.MinValue;
AbsorbElements = int.MinValue;
AbsorbMagic = int.MinValue; // To-Do
AbsorbEnergy = int.MinValue;
AbsorbFire = int.MinValue;
AbsorbPoison = int.MinValue;
AbsorbIce = int.MinValue;
AbsorbHoly = int.MinValue;
AbsorbDeath = int.MinValue;
AbsorbLifeDrain = int.MinValue;
AbsorbManaDrain = int.MinValue;
AbsorbDrown = int.MinValue;
AbsorbPhysical = int.MinValue;
AbsorbHealing = int.MinValue;
FieldTicks = int.MinValue;
FieldCount = int.MinValue;
FieldDamage = int.MinValue;
FieldStart = int.MinValue;
LevelDoor = int.MinValue;
MaleTransformTo = int.MinValue;
FemaleTransformTo = int.MinValue;
TransformTo = int.MinValue;
DestroyTo = int.MinValue;
ElementIce = int.MinValue;
ElementEarth = int.MinValue;
ElementFire = int.MinValue;
ElementEnergy = int.MinValue;
ElementDeath = int.MinValue;
ElementHoly = int.MinValue;
UpgradeClassification = int.MinValue;
ImbuingSlots = int.MinValue;
ImbueElementalDamage = int.MinValue;
ImbueLifeLeech = int.MinValue;
ImbueManaLeech = int.MinValue;
ImbueCriticalHit = int.MinValue;
ImbueElementalProtectionDeath = int.MinValue;
ImbueElementalProtectionEarth = int.MinValue;
ImbueElementalProtectionFire = int.MinValue;
ImbueElementalProtectionIce = int.MinValue;
ImbueElementalProtectionEnergy = int.MinValue;
ImbueElementalProtectionHoly = int.MinValue;
ImbueIncreaseSpeed = int.MinValue;
ImbueSkillAxe = int.MinValue;
ImbueSkillSword = int.MinValue;
ImbueSkillClub = int.MinValue;
ImbueSkillShield = int.MinValue;
ImbueSkillDistance = int.MinValue;
ImbueSkillMagicLevel = int.MinValue;
ImbueIncreaseCapacity = int.MinValue;
#endregion
#region Bool values
ShowCount = null;
WrapContainer = null;
Moveable = null;
IsPodium = null;
BlockProjectile = null;
Pickupable = null;
Readable = null;
Writeable = null;
StopDuration = null;
ShowDuration = null;
ShowCharges = null;
ShowAttributes = null;
Invisible = null;
ManaShield = null;
SuppressDrunk = false;
SuppressEnergy = false;
SuppressFire = false;
SuppressPoison = false;
SuppressDrown = false;
SuppressPhysical = false;
SuppressFreeze = false;
SuppressDazzle = false;
SuppressCurse = false;
Replaceable = null;
WalkStack = null;
Blocking = null;
DistanceRead = null;
#endregion
#region Internal
Comments = new List<(string text, bool inside)>();
Tag = string.Empty;
ServerIds = new List<int>();
#endregion
}
#region Internal
public string Tag { get; set; }
public List<(string text, bool inside)> Comments { get; set; }
public List<int> ServerIds { get; set; }
#endregion
#region Strings
public string Name { get; set; }
public string Article { get; set; }
public string Plural { get; set; }
public string Type { get; set; }
public string Description { get; set; }
public string RuneSpellName { get; set; }
public string FloorChange { get; set; }
public string CorpseType { get; set; }
public string FluidSource { get; set; }
public string WeaponType { get; set; }
public string SlotType { get; set; }
public string AmmoType { get; set; }
public string ShootType { get; set; }
public string Effect { get; set; }
public string LootType { get; set; }
public string Field_Type { get; set; }
public string PartnerDirection { get; set; }
public string EditorSuffix { get; set; }
#endregion
#region Int values
public int FromID { get; set; }
public int ToID { get; set; }
public int Weight { get; set; }
public int Armor { get; set; }
public int Defense { get; set; }
public int ExtraDefense { get; set; }
public int Attack { get; set; }
public int RotateTo { get; set; }
public int WrapableTo { get; set; }
public int ContainerSize { get; set; }
public int MaxTextLenght { get; set; }
public int WriteOnceItemId { get; set; }
public int Range { get; set; }
public int DecayTo { get; set; }
public int EquipTo { get; set; }
public int DequipTo { get; set; }
public int Duration { get; set; }
public int Charges { get; set; }
public int HitChance { get; set; }
public int MaxHitChance { get; set; }
public int Speed { get; set; }
public int HealthGain { get; set; }
public int HealthTicks { get; set; }
public int ManaGain { get; set; }
public int ManaTicks { get; set; }
public int SkillSword { get; set; }
public int SkillAxe { get; set; }
public int SkillClub { get; set; }
public int SkillDistance { get; set; }
public int SkillFish { get; set; }
public int SkillShield { get; set; }
public int SkillFist { get; set; }
public int SkillCriticalChance { get; set; }
public int SkillCriticalDamage { get; set; }
public int SkillLifeChance { get; set; }
public int SkillLifeAmount { get; set; }
public int SkillManaChance { get; set; }
public int SkillManaAmount { get; set; }
public int MaxHitPoints { get; set; }
public int MaxHitPointsPercent { get; set; }
public int MaxManaPoints { get; set; }
public int MaxManaPointsPercent { get; set; }
public int MagicLevel { get; set; }
public int MagicLevelPercent { get; set; }
public int AbsorbFieldEnergy { get; set; }
public int AbsorbFieldFire { get; set; }
public int AbsorbFieldPoison { get; set; }
public int AbsorbAll { get; set; }
public int AbsorbElements { get; set; }
public int AbsorbMagic { get; set; }
public int AbsorbEnergy { get; set; }
public int AbsorbFire { get; set; }
public int AbsorbPoison { get; set; }
public int AbsorbIce { get; set; }
public int AbsorbHoly { get; set; }
public int AbsorbDeath { get; set; }
public int AbsorbLifeDrain { get; set; }
public int AbsorbManaDrain { get; set; }
public int AbsorbDrown { get; set; }
public int AbsorbPhysical { get; set; }
public int AbsorbHealing { get; set; }
public int FieldTicks { get; set; }
public int FieldCount { get; set; }
public int FieldDamage { get; set; }
public int FieldStart { get; set; }
public int LevelDoor { get; set; }
public int MaleTransformTo { get; set; }
public int FemaleTransformTo { get; set; }
public int TransformTo { get; set; }
public int DestroyTo { get; set; }
public int ElementIce { get; set; }
public int ElementEarth { get; set; }
public int ElementFire { get; set; }
public int ElementEnergy { get; set; }
public int ElementDeath { get; set; }
public int ElementHoly { get; set; }
public int UpgradeClassification { get; set; }
public int ImbuingSlots { get; set; }
public int ImbueElementalDamage { get; set; }
public int ImbueLifeLeech { get; set; }
public int ImbueManaLeech { get; set; }
public int ImbueCriticalHit { get; set; }
public int ImbueElementalProtectionDeath { get; set; }
public int ImbueElementalProtectionEarth { get; set; }
public int ImbueElementalProtectionFire { get; set; }
public int ImbueElementalProtectionIce { get; set; }
public int ImbueElementalProtectionEnergy { get; set; }
public int ImbueElementalProtectionHoly { get; set; }
public int ImbueIncreaseSpeed { get; set; }
public int ImbueSkillAxe { get; set; }
public int ImbueSkillSword { get; set; }
public int ImbueSkillClub { get; set; }
public int ImbueSkillShield { get; set; }
public int ImbueSkillDistance { get; set; }
public int ImbueSkillMagicLevel { get; set; }
public int ImbueIncreaseCapacity { get; set; }
#endregion
#region Bool values
public bool? ShowCount { get; set; }
public bool? WrapContainer { get; set; }
public bool? Moveable { get; set; }
public bool? IsPodium { get; set; }
public bool? BlockProjectile { get; set; }
public bool? Pickupable { get; set; }
public bool? Readable { get; set; }
public bool? Writeable { get; set; }
public bool? StopDuration { get; set; }
public bool? ShowDuration { get; set; }
public bool? ShowCharges { get; set; }
public bool? ShowAttributes { get; set; }
public bool? Invisible { get; set; }
public bool? ManaShield { get; set; }
public bool SuppressDrunk { get; set; }
public bool SuppressEnergy { get; set; }
public bool SuppressFire { get; set; }
public bool SuppressPoison { get; set; }
public bool SuppressDrown { get; set; }
public bool SuppressPhysical { get; set; }
public bool SuppressFreeze { get; set; }
public bool SuppressDazzle { get; set; }
public bool SuppressCurse { get; set; }
public bool? Replaceable { get; set; }
public bool? WalkStack { get; set; }
public bool? Blocking { get; set; }
public bool? DistanceRead { get; set; }
#endregion
}
public class ComboBox_t
{
public ComboBox_t(string name, string xml)
{
Xml = new List<string>();
Name = name;
Xml.Add(xml);
// Used only on wiki loader filter.
FilterChecked = false;
}
public string Name { get; set; }
public List<string> Xml { get; }
public bool FilterChecked { get; set; }
}
public enum DamageElement_t
{
Physical,
Holy,
Death,
Fire,
Energy,
Ice,
Earth,
Drown,
Lifedrain,
Poison,
Unknown
}
public enum Hands_t
{
One,
Two
}
public enum Weapon_t
{
Axe,
Club,
Sword,
Distance
}
public enum SpecialChar : byte
{
NodeStart = 0xFE, // 254 (OTB Only)
EscapeChar = 0xFD, // 253 (OTB Only)
NodeEnd = 0xFF // 255 (OTB Only)
}
public enum RootAttribute : byte
{
Version = 0x01
}
public enum ItemGroup : byte
{
None = 0x00,
Ground = 0x01,
Container = 0x02,
Weapon = 0x03,
Ammunition = 0x04,
Armor = 0x05,
Changes = 0x06,
Teleport = 0x07,
MagicField = 0x08,
Writable = 0x09,
Key = 0x0A,
Splash = 0x0B,
Fluid = 0x0C,
Door = 0x0D,
Deprecated = 0x0E
}
public enum ItemAttribute : byte
{
ServerID = 0x10,
ClientID = 0x11,
Name = 0x12,
GroundSpeed = 0x14,
SpriteHash = 0x20,
MinimaColor = 0x21,
MaxReadWriteChars = 0x22,
MaxReadChars = 0x23,
Light = 0x2A,
StackOrder = 0x2B,
TradeAs = 0x2D
}
public class BinaryTreeReader : IDisposable
{
#region Private Properties
private BinaryReader reader;
private long currentNodePosition;
private uint currentNodeSize;
#endregion
#region Constructor
public BinaryTreeReader(string path)
{
if (string.IsNullOrEmpty(path)) {
throw new ArgumentNullException("input");
}
this.reader = new BinaryReader(new FileStream(path, FileMode.Open));
this.Disposed = false;
}
#endregion
#region Public Properties
public bool Disposed { get; private set; }
#endregion
#region Public Properties
public BinaryReader GetRootNode()
{
return GetChildNode();
}
public BinaryReader GetChildNode()
{
Advance();
return GetNodeData();
}
public BinaryReader GetNextNode()
{
reader.BaseStream.Seek(currentNodePosition, SeekOrigin.Begin);
SpecialChar value = (SpecialChar)reader.ReadByte();
if (value != SpecialChar.NodeStart)
return null;
value = (SpecialChar)reader.ReadByte();
int level = 1;
while (true) {
value = (SpecialChar)reader.ReadByte();
if (value == SpecialChar.NodeEnd) {
--level;
if (level == 0) {
value = (SpecialChar)reader.ReadByte();
if (value == SpecialChar.NodeEnd) {
return null;
} else if (value != SpecialChar.NodeStart) {
return null;
} else {
currentNodePosition = reader.BaseStream.Position - 1;
return GetNodeData();
}
}
} else if (value == SpecialChar.NodeStart) {
++level;
} else if (value == SpecialChar.EscapeChar) {
reader.ReadByte();
}
}
}
public void Dispose()
{
if (reader != null) {
reader.Dispose();
reader = null;
Disposed = true;
}
}
#endregion
#region Private Methods
private BinaryReader GetNodeData()
{
reader.BaseStream.Seek(currentNodePosition, SeekOrigin.Begin);
// read node type
byte value = reader.ReadByte();
if ((SpecialChar)value != SpecialChar.NodeStart)
return null;
MemoryStream ms = new MemoryStream();
currentNodeSize = 0;
while (true) {
value = reader.ReadByte();
if ((SpecialChar)value == SpecialChar.NodeEnd || (SpecialChar)value == SpecialChar.NodeStart)
break;
else if ((SpecialChar)value == SpecialChar.EscapeChar)
value = reader.ReadByte();
currentNodeSize++;
ms.WriteByte(value);
}
reader.BaseStream.Seek(currentNodePosition, SeekOrigin.Begin);
ms.Position = 0;
return new BinaryReader(ms);
}
private bool Advance()
{
try
{
long seekPos = 0;
if (currentNodePosition == 0)
seekPos = 4;
else
seekPos = currentNodePosition;
reader.BaseStream.Seek(seekPos, SeekOrigin.Begin);
SpecialChar value = (SpecialChar)reader.ReadByte();
if (value != SpecialChar.NodeStart)
return false;
if (currentNodePosition == 0) {
currentNodePosition = reader.BaseStream.Position - 1;
return true;
} else {
value = (SpecialChar)reader.ReadByte();
while (true) {
value = (SpecialChar)reader.ReadByte();
if (value == SpecialChar.NodeEnd) {
return false;
} else if (value == SpecialChar.NodeStart) {
currentNodePosition = reader.BaseStream.Position - 1;
return true;
} else if (value == SpecialChar.EscapeChar) {
reader.ReadByte();
}
}
}
} catch (Exception) {
return false;
}
}
#endregion
}
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
#region Utils
private SolidColorBrush _greenBrush = new SolidColorBrush(Color.FromRgb(0, 200, 0));
private SolidColorBrush _yellowBrush = new SolidColorBrush(Color.FromRgb(200, 200, 0));
private int _lastItemId = -1;
private string _itemsNode = "items";
private string _itemNode = "item";
private string _itemChildNode = "attribute";
private string _childKey = "key";
private string _childValue = "value";
private string _xmlVersion = "1.0";
private string _xmlEncoding = "ISO-8859-1";
public string _editedTag = " - edited";
public string _newTag = " - new";
public string _wikiUri = "https://tibiawiki.dev/api/items/";
private bool _hasChange = false;
public List<(int ClientID, int ServerID)> _itemConverterList = new List<(int ClientID, int ServerID)>();
private List<string> _error = new List<string>();
private Grid _selectionGrid;
public Message _message;
public Loader _asyncLoader;
public bool ValidateStringParseToInt(string value) {
if (value == null || value.Length == 0)
return false;
foreach (char c in value) {
if (c != '+' && c != '-' && (c < '0' || c > '9'))
return false;
}
int rt;
return int.TryParse(value, out rt);
}
public int ParseStringToFinalInt(string value, int defaultValue = int.MinValue) {
return ValidateStringParseToInt(value) ? int.Parse(value) : defaultValue;
}
public bool? ParseComboBoxToFinalBool(string value) {
if (value.ToLower() == "true") {
return true;
} else if (value.ToLower() == "false") {
return false;
} else {
return null;
}
}
public string ParseProtobufItemCategoryToLootType(ITEM_CATEGORY category)
{
switch (category) {
case ITEM_CATEGORY.Armors: {
return "armor";
}
case ITEM_CATEGORY.Amulets: {
return "amulet";
}
case ITEM_CATEGORY.Boots: {
return "boots";
}
case ITEM_CATEGORY.Containers: {
return "container";
}
case ITEM_CATEGORY.Decoration: {
return "decoration";
}
case ITEM_CATEGORY.Food: {
return "food";
}
case ITEM_CATEGORY.HelmetsHats: {
return "helmet";
}
case ITEM_CATEGORY.Legs: {
return "legs";
}
case ITEM_CATEGORY.Others: {
return "other";
}
case ITEM_CATEGORY.Potions: {
return "potion";
}
case ITEM_CATEGORY.Rings: {
return "ring";
}
case ITEM_CATEGORY.Runes: {
return "rune";
}
case ITEM_CATEGORY.Shields: {
return "shield";
}
case ITEM_CATEGORY.Tools: {
return "tools";
}
case ITEM_CATEGORY.Valuables: {
return "valuable";
}
case ITEM_CATEGORY.Ammunition: {
return "ammo";
}
case ITEM_CATEGORY.Axes: {
return "axe";
}
case ITEM_CATEGORY.Clubs: {
return "club";
}
case ITEM_CATEGORY.DistanceWeapons: {
return "distance";
}
case ITEM_CATEGORY.Swords: {
return "sword";
}
case ITEM_CATEGORY.WandsRods: {
return "wand";
}
case ITEM_CATEGORY.SpecialCoins: {
return "gold";
}
case ITEM_CATEGORY.CreatureProducts: {
return "creatureproduct";
}
default:
return "unassigned";
}
}
#endregion
#region Logging
public void AppendLog(string text)
{
_error.Add(text);
}
public void ClearLog()
{
_error = new List<string>();
}
public void ShowLog()
{
if (_error.Count == 0 || _message != null) {
return;
}
_message = new Message("Log window", this);
Button closeButton = _message.CreateNewButton("Close");
closeButton.Click += _message.Close_Click;
closeButton.Margin = new Thickness(0, 0, 40, 0);
foreach (string line in _error) {
_message.CreateTextOnLog(line);
}
_message.Show();
}
#endregion
#region Items declarations
public int GetItemServerIDByClientID(int clientId)
{
foreach (var tuple in _itemConverterList) {
if (tuple.ClientID == clientId) {
return tuple.ServerID;
}
}
return int.MinValue;
}
public Item GetItemByID(int id, bool forceClient = false)
{
int finalId = id;
if (forceClient && _itemConverterList.Count > 0) {
finalId = GetItemServerIDByClientID(id);
}
foreach (Item listItem in ItemsList.Items) {
if (listItem.FromID <= finalId && listItem.ToID >= finalId) {
return listItem;
}
}
return null;
}
public void SelectItem()
{
Item item = GetItemByID((int)_selectionGrid.DataContext);
if (item == null) {
return;
}
#region Strings
ItemName.Text = item.Name;
Article.Text = item.Article;
Plural.Text = item.Plural;
Description.Text = item.Description;
EditorSufix.Text = item.EditorSuffix;
RuneSpell.Text = item.RuneSpellName;
foreach (ComboBox_t type in Type.Items) {
if (item.Type.Length == 0) {
if (type.Xml[0].Length == 0) {
Type.SelectedItem = type;
break;
}
} else if (type.Xml.Contains(item.Type)) {
Type.SelectedItem = type;
break;
}
}
foreach (ComboBox_t floorChange in FloorChange.Items) {
if (item.FloorChange.Length == 0) {
if (floorChange.Xml[0].Length == 0) {
FloorChange.SelectedItem = floorChange;
break;
}
} else if (floorChange.Xml.Contains(item.FloorChange)) {
FloorChange.SelectedItem = floorChange;
break;
}
}
foreach (ComboBox_t corpseType in CorpseType.Items) {
if (item.CorpseType.Length == 0) {
if (corpseType.Xml[0].Length == 0) {
CorpseType.SelectedItem = corpseType;
break;
}
} else if (corpseType.Xml.Contains(item.CorpseType)) {
CorpseType.SelectedItem = corpseType;
break;
}
}
foreach (ComboBox_t fluidSource in FluidSource.Items) {
if (item.FluidSource.Length == 0) {
if (fluidSource.Xml[0].Length == 0) {
FluidSource.SelectedItem = fluidSource;
break;
}
} else if (fluidSource.Xml.Contains(item.FluidSource)) {
FluidSource.SelectedItem = fluidSource;
break;
}
}
foreach (ComboBox_t weaponType in WeaponType.Items) {
if (item.WeaponType.Length == 0) {
if (weaponType.Xml[0].Length == 0) {
WeaponType.SelectedItem = weaponType;
break;
}
} else if (weaponType.Xml.Contains(item.WeaponType)) {
WeaponType.SelectedItem = weaponType;
break;
}
}
foreach (ComboBox_t slotType in SlotType.Items) {
if (item.SlotType.Length == 0) {
if (slotType.Xml[0].Length == 0) {
SlotType.SelectedItem = slotType;
break;
}
} else if (slotType.Xml.Contains(item.SlotType)) {
SlotType.SelectedItem = slotType;
break;
}
}
foreach (ComboBox_t ammoType in AmmoType.Items) {
if (item.AmmoType.Length == 0) {
if (ammoType.Xml[0].Length == 0) {
AmmoType.SelectedItem = ammoType;
break;
}
} else if (ammoType.Xml.Contains(item.AmmoType)) {
AmmoType.SelectedItem = ammoType;
break;
}
}
foreach (ComboBox_t shootType in ShootType.Items) {
if (item.ShootType.Length == 0) {
if (shootType.Xml[0].Length == 0) {
ShootType.SelectedItem = shootType;
break;
}
} else if (shootType.Xml.Contains(item.ShootType)) {
ShootType.SelectedItem = shootType;
break;
}
}
foreach (ComboBox_t magicEffect in MagicEffect.Items) {
if (item.Effect.Length == 0) {
if (magicEffect.Xml[0].Length == 0) {
MagicEffect.SelectedItem = magicEffect;
break;
}
} else if (magicEffect.Xml.Contains(item.Effect)) {
MagicEffect.SelectedItem = magicEffect;
break;
}
}
foreach (ComboBox_t lootType in LootType.Items) {
if (item.LootType.Length == 0) {
if (lootType.Xml[0].Length == 0) {
LootType.SelectedItem = lootType;
break;
}
} else if (lootType.Xml.Contains(item.LootType)) {
LootType.SelectedItem = lootType;
break;
}
}
foreach (ComboBox_t fieldType in FieldType.Items) {
if (item.Field_Type.Length == 0) {
if (fieldType.Xml[0].Length == 0) {
FieldType.SelectedItem = fieldType;
break;
}
} else if (fieldType.Xml.Contains(item.Field_Type)) {
FieldType.SelectedItem = fieldType;
break;
}
}
foreach (ComboBox_t partnerDirecttion in PartnerDirection.Items) {
if (item.PartnerDirection.Length == 0) {
if (partnerDirecttion.Xml[0].Length == 0) {
PartnerDirection.SelectedItem = partnerDirecttion;
break;
}
} else if (partnerDirecttion.Xml.Contains(item.PartnerDirection)) {
PartnerDirection.SelectedItem = partnerDirecttion;
break;
}
}
#endregion
#region Integrer
FromID.Text = item.FromID.ToString();
ToID.Text = item.ToID.ToString();
Weight.Text = item.Weight != int.MinValue ? item.Weight.ToString() : string.Empty;
Armor.Text = item.Armor != int.MinValue ? item.Armor.ToString() : string.Empty;
Defense.Text = item.Defense != int.MinValue ? item.Defense.ToString() : string.Empty;
ExtraDefense.Text = item.ExtraDefense != int.MinValue ? item.ExtraDefense.ToString() : string.Empty;
Attack.Text = item.Attack != int.MinValue ? item.Attack.ToString() : string.Empty;
RotateTo.Text = item.RotateTo != int.MinValue ? item.RotateTo.ToString() : string.Empty;
ImbueSlots.Text = item.ImbuingSlots != int.MinValue ? item.ImbuingSlots.ToString() : string.Empty;
WrapTo.Text = item.WrapableTo != int.MinValue ? item.WrapableTo.ToString() : string.Empty;
ContainerSize.Text = item.ContainerSize != int.MinValue ? item.ContainerSize.ToString() : string.Empty;
MaxTextLenght.Text = item.MaxTextLenght != int.MinValue ? item.MaxTextLenght.ToString() : string.Empty;
WritingID.Text = item.WriteOnceItemId != int.MinValue ? item.WriteOnceItemId.ToString() : string.Empty;
Range.Text = item.Range != int.MinValue ? item.Range.ToString() : string.Empty;