-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLootMaster.py
More file actions
3489 lines (3118 loc) · 136 KB
/
LootMaster.py
File metadata and controls
3489 lines (3118 loc) · 136 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
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using Engine = Assistant.Engine;
namespace RazorEnhanced
{
public class Lootmaster
{
public static readonly bool Debug = false;
private readonly string _version = "v1.0.6";
public static readonly bool IsOSI = false;
private Target _tar = new Target();
private readonly List<int> _gems = new List<int>();
private readonly List<int> ignoreList = new List<int>();
private LootMasterConfig _config = new LootMasterConfig();
private Journal.JournalEntry _lastEntry = null;
private Mobile _player;
private int _lootDelay = IsOSI ? 800 : 200;
private DateTime? DeathClock = null;
readonly Journal _journal = new Journal();
public void Run()
{
try
{
if (Player.IsGhost)
{
Handler.SendMessage(MessageType.Error, "You are a ghost, please ressurrect before running Lootmaster");
return;
}
var firstRun = false;
//Remove existing debug log file
var logFile = Path.Combine(Engine.RootPath, "Lootmaster.log");
if (File.Exists(logFile))
{
File.Delete(logFile);
}
var configFile = Path.Combine(Engine.RootPath, "Lootmaster.config");
firstRun = !File.Exists(configFile);
_config.Init();
Misc.RemoveSharedValue("Lootmaster:DirectContainer");
Misc.RemoveSharedValue("Lootmaster:ReconfigureBags");
Misc.RemoveSharedValue("Lootmaster:ClearCurrentCharacter");
Misc.RemoveSharedValue("Lootmaster:DirectContainerRule");
//SetSpecialRules();
Setup();
UpdateLootMasterGump(Hue.Idle);
if (firstRun)
{
ShowWelcomeGump();
}
_config.ItemLookup[3821] = "Gold Coin";
_config.ItemLookup[41777] = "Coin Purse";
_config.ItemLookup[41779] = "Gem Purse";
while (true)
{
var lm = Gumps.GetGumpData(13659823);
var co = Gumps.GetGumpData(96523485);
var we = Gumps.GetGumpData(546165464);
var ab = Gumps.GetGumpData(492828);
if (lm.buttonid == 500)
{
ShowOptions();
lm.buttonid = -1;
Gumps.SendGump(lm, 150, 150);
}
if (we?.buttonid == 1)
{
Handler.SendMessage(MessageType.Log, "Loading Starter Rules");
LoadStarterRules(true);
we.buttonid = -1;
}
if ((co?.buttonid ?? -1) != -1)
{
var selected = (OptionsItem)co.buttonid;
switch (selected)
{
case OptionsItem.Reload:
ReconfigureBags();
break;
case OptionsItem.Reset:
ClearCurrentCharacterConfig();
break;
case OptionsItem.ManualRun:
var target = Prompt("Target Container to loot");
LootDirectContainer(target);
break;
case OptionsItem.OpenConfig:
ShowConfigurator();
break;
case OptionsItem.LoadStarter:
var confirmResult = MessageBox.Show("Are you sure you want to reset config to Starter Rules? \r\n\r\nIt's recomended to have at least 4 target bags ready.",
"Confirm Reset",
MessageBoxButtons.YesNo);
if (confirmResult == DialogResult.Yes)
{
LoadStarterRules();
}
break;
case OptionsItem.About:
ShowAbout();
break;
}
co.buttonid = -1;
}
if ((ab?.buttonid ?? -1) != -1)
{
switch (ab.buttonid)
{
case (int)OptionsItem.Wiki:
System.Diagnostics.Process.Start("https://gamebible.net/wiki/doku.php?id=lootmaster");
break;
case (int)OptionsItem.Coffee:
System.Diagnostics.Process.Start("https://www.buymeacoffee.com/Dorana");
break;
}
ab.buttonid = -1;
}
if (Player.IsGhost)
{
Misc.Pause(500);
DeathClock = DeathClock ?? DateTime.Now;
continue;
}
if (JustRessed())
{
Handler.SendMessage(MessageType.Info,"Just Ressed");
Misc.Pause(2000);
continue;
}
if (Misc.ReadSharedValue("Lootmaster:ReconfigureBags") is bool reconfigure && reconfigure)
{
ReconfigureBags();
}
if (Misc.ReadSharedValue("Lootmaster:ClearCurrentCharacter") is bool clearCurrentCharacterConfig && clearCurrentCharacterConfig)
{
ClearCurrentCharacterConfig();
}
if (Misc.ReadSharedValue("Lootmaster:DirectContainer") is int directContainerSerial && directContainerSerial != 0)
{
if (directContainerSerial == -1)
{
continue;
}
LootRule rule = null;
if (Misc.ReadSharedValue("Lootmaster:DirectContainerRule") is string directContainerRule && !string.IsNullOrEmpty(directContainerRule))
{
rule = _config.GetCharacter().Rules.FirstOrDefault(r => r.RuleName == directContainerRule);
}
LootDirectContainer(directContainerSerial, rule);
Misc.RemoveSharedValue("Lootmaster:DirectContainer");
Misc.RemoveSharedValue("Lootmaster:DirectContainerRule");
Misc.Pause(200);
continue;
}
var corpses = Items.ApplyFilter(new Items.Filter
{
IsCorpse = 1,
RangeMax = 2,
RangeMin = 0,
});
if (corpses.Any(c => !ignoreList.Contains(c.Serial)))
{
UpdateLootMasterGump(Hue.Looting);
foreach (var corpse in corpses.Where(c => !ignoreList.Contains(c.Serial)))
{
if (corpse.DistanceTo(_player) > 2)
{
break;
}
if (Target.HasTarget())
{
continue;
}
_lastEntry = _journal.GetJournalEntry(null).OrderBy(j => j.Timestamp).LastOrDefault();
LootContainer(corpse);
var rows = _journal.GetJournalEntry(_lastEntry);
if (rows == null) continue;
var filtered = rows.Where(r => r.Type == "System");
if (filtered.Any(r => r.Text == "You must wait to perform another action."))
{
if (_lootDelay >= 700)
{
_lootDelay = 400;
Handler.SendMessage(MessageType.Log, $"Resetting loot delay to {_lootDelay}");
}
else
{
_lootDelay += 10;
Handler.SendMessage(MessageType.Log, $"Adjusting loot delay with 10ms, currently at {_lootDelay}");
}
}
}
UpdateLootMasterGump(Hue.Idle);
}
Misc.Pause(100);
}
}
catch (Exception e)
{
if (e is ThreadAbortException)
{
return;
}
if (!Debug)
{
Handler.SendMessage(MessageType.Error, "Lootmaster encountered an error, and was forced to shut down");
var logFile = Path.Combine(Engine.RootPath, "Lootmaster.log");
File.AppendAllText(logFile, e.ToString());
}
else
{
Handler.SendMessage(MessageType.Debug, e.ToString());
}
throw;
}
}
private bool JustRessed()
{
if (DeathClock == null)
{
return false;
}
var bagRules = _config.GetCharacter().Rules.Where(r => !r.Disabled && r.TargetBag != null && r.TargetBag != Player.Backpack.Serial).ToList();
if (!bagRules.Any())
{
return false;
}
return bagRules.All(br => Items.FindBySerial(br.TargetBag ?? int.MinValue) == null);
}
private void SetStarterRules()
{
_config.CreateRule(LootRule.Gold);
_config.CreateRule(LootRule.Gems);
_config.CreateRule(new LootRule
{
RuleName = "Valuable Weapons",
EquipmentSlots = new List<EquipmentSlot>
{
EquipmentSlot.RightHand
},
Properties = new List<PropertyMatch>
{
new PropertyMatch
{
Property = ItemProperty.HitChanceIncrease,
Value = 15
},
new PropertyMatch
{
Property = ItemProperty.DamageIncrease,
Value = 30,
},
new PropertyMatch
{
Property = ItemProperty.SwingSpeedIncrease,
Value = 10
}
}
});
_config.CreateRule(new LootRule
{
RuleName = "Valuable Caster Jewelry",
EquipmentSlots = new List<EquipmentSlot>
{
EquipmentSlot.Jewellery
},
Properties = new List<PropertyMatch>
{
new PropertyMatch
{
Property = ItemProperty.SpellDamageIncrease,
Value = 18
},
new PropertyMatch
{
Property = ItemProperty.LowerReagentCost,
Value = 20,
},
new PropertyMatch
{
Property = ItemProperty.FasterCasting,
Value = 1
},
new PropertyMatch
{
Property = ItemProperty.FasterCastRecovery,
Value = 2
}
}
});
_config.CreateRule(new LootRule
{
RuleName = "Valuable Gear #1",
EquipmentSlots = new List<EquipmentSlot>
{
EquipmentSlot.Armour
},
Properties = new List<PropertyMatch>
{
new PropertyMatch
{
Property = ItemProperty.DamageEater,
Value = 10
},
new PropertyMatch
{
Property = ItemProperty.Luck,
Value = 100
},
}
});
_config.CreateRule(new LootRule
{
RuleName = "Valuable Gear #2",
EquipmentSlots = new List<EquipmentSlot>
{
EquipmentSlot.Armour
},
Properties = new List<PropertyMatch>
{
new PropertyMatch
{
Property = ItemProperty.Cartography
}
}
});
_config.CreateRule(new LootRule
{
RuleName = "CUB Items",
MinimumRarity = ItemRarity.MajorMagicItem
});
_config.CreateRule(new LootRule("Maps", "Treasure Map"));
}
private void ReconfigureBags()
{
foreach (var rule in _config.GetCharacter().Rules)
{
var tempBag = rule.GetTargetBag();
rule.TargetBag = (tempBag?.Serial == Player.Backpack.Serial || tempBag?.RootContainer == Player.Backpack.Serial) ? tempBag?.Serial : null;
}
Setup();
}
private void ClearCurrentCharacterConfig()
{
var confirmResult = MessageBox.Show("Are you sure you want to clear config for current character?",
"Confirm Delete!",
MessageBoxButtons.YesNo);
if (confirmResult == DialogResult.Yes)
{
var current = _config.Characters.FirstOrDefault(c => c.PlayerName == Player.Name);
_config.Characters.Remove(current);
_config.Save();
Misc.RemoveSharedValue("Lootmaster:ClearCurrentCharacter");
//SetSpecialRules();
Setup();
}
}
private void LoadStarterRules(bool openConfig = false)
{
var current = _config.Characters.FirstOrDefault(c => c.PlayerName == Player.Name);
_config.Characters.Remove(current);
_config.Save();
Misc.RemoveSharedValue("Lootmaster:ClearCurrentCharacter");
SetStarterRules();
if (openConfig)
{
ShowConfigurator();
}
else
{
ReconfigureBags();
}
}
private void LootDirectContainer(int directContainerSerial) => LootDirectContainer(directContainerSerial, null);
private void LootDirectContainer(int directContainerSerial, LootRule rule)
{
var directContainer = Items.FindBySerial(directContainerSerial);
if (directContainer != null)
{
Handler.SendMessage(MessageType.Log, $"Looting direct container {directContainer.Name}");
UpdateLootMasterGump(Hue.Looting);
LootContainer(directContainer, rule);
Misc.Pause(500);
UpdateLootMasterGump(Hue.Idle);
}
}
private void ShowWelcomeGump()
{
var welcome = Gumps.CreateGump();
Gumps.AddBackground(ref welcome, 0, 0, 500, 800, -1);
Gumps.AddPage(ref welcome, 0);
Gumps.AddImage(ref welcome, 0, 0, 1596);
Gumps.AddImage(ref welcome, 0, 142, 1597);
Gumps.AddImage(ref welcome, 0, 283, 1598);
Gumps.AddImage(ref welcome, 0, 425, 1599);
Gumps.AddHtml(ref welcome, 0, 60, 400, 20, "<center><h1>Welcome to Lootmaster</h1></center>", false, false);
Gumps.AddLabel(ref welcome, 30, 90, 0, "It seems this is your first time starting lootmaster.");
Gumps.AddLabel(ref welcome, 30, 105, 0, "First off, let me say THANK YOU");
Gumps.AddLabel(ref welcome, 30, 120, 0, "for deciding to use my script.");
Gumps.AddLabel(ref welcome, 30, 150, 0, "Lootmaster is an Autolooter designed to simplify");
Gumps.AddLabel(ref welcome, 30, 165, 0, "the looting process in Ultima Online.");
Gumps.AddLabel(ref welcome, 30, 195, 0, "It does so by using a set of User Defined Rules");
Gumps.AddLabel(ref welcome, 30, 210, 0, "That you can access from the Configurator");
Gumps.AddLabel(ref welcome, 30, 240, 0, "In order to access the Options of Lootmaster");
Gumps.AddLabel(ref welcome, 30, 255, 0, "press the blue gem in the Lootmaster status window");
Gumps.AddLabel(ref welcome, 30, 270, 0, "This will open the Options Menu");
Gumps.AddLabel(ref welcome, 30, 300, 0, "Since this is your first time using Lootmaster");
Gumps.AddLabel(ref welcome, 30, 315, 0, "I recommend that you start by setting up some of the");
Gumps.AddLabel(ref welcome, 30, 330, 0, "Preset rules found in Configurator");
Gumps.AddLabel(ref welcome, 30, 360, 0, "This will give you a good starting point to learn");
Gumps.AddLabel(ref welcome, 30, 375, 0, "How Lootmaster works and how to use it");
Gumps.AddLabel(ref welcome, 30, 405, 0, "If you are new to Ultima Online or do not know");
Gumps.AddLabel(ref welcome, 30, 420, 0, "What items to look for, I suggest you start with");
Gumps.AddLabel(ref welcome, 30, 435, 0, "our Preset Starter Rules for New Players");
Gumps.AddButton(ref welcome, 25, 470, 2152, 2151, 1, 1, 0);
Gumps.AddLabel(ref welcome, 65, 475, 0, "Load Starter Rules for New Players");
welcome.gumpId = 546165464;
welcome.serial = (uint)Player.Serial;
Gumps.CloseGump(546165464);
Gumps.SendGump(welcome, 700, 500);
}
private void ShowOptions()
{
var options = Gumps.CreateGump();
Gumps.AddBackground(ref options, 0, 0, 400, 290, 1228);
Gumps.AddLabel(ref options, 50, 3, 0, "Lootmaster Options");
Gumps.AddButton(ref options, 25, 25, 2152, 2151, (int)OptionsItem.OpenConfig, 1, 0);
Gumps.AddLabel(ref options, 65, 30, 0, "Open Loot rules Configurator");
Gumps.AddButton(ref options, 25, 65, 2152, 2151, (int)OptionsItem.ManualRun, 1, 0);
Gumps.AddLabel(ref options, 65, 70, 0, "Run Lootmaster on Target Container");
Gumps.AddButton(ref options, 25, 105, 2152, 2151, (int)OptionsItem.Reload, 1, 0);
Gumps.AddLabel(ref options, 65, 110, 0, "Reload Character Config");
Gumps.AddButton(ref options, 25, 145, 5832, 5833, (int)OptionsItem.Reset, 1, 0);
Gumps.AddLabel(ref options, 65, 150, 0, "Reset Character Config");
Gumps.AddButton(ref options, 25, 185, 5832, 5833, (int)OptionsItem.LoadStarter, 1, 0);
Gumps.AddLabel(ref options, 65, 190, 0, "Load Starter Rules (Clears current config)");
Gumps.AddButton(ref options, 25, 225, 5826, 5827, (int)OptionsItem.About, 1, 0);
Gumps.AddLabel(ref options, 65, 230, 0, "About Lootmaster");
Gumps.AddLabel(ref options,300,260,0,_version);
Gumps.CloseGump(96523485);
options.serial = (uint)Player.Serial;
options.gumpId = 96523485;
Gumps.SendGump(options, 150, 150);
}
private void ShowConfigurator()
{
Handler.SendMessage(MessageType.Log, "Pausing Lootmaster while configure is open");
var conf = new Configurator();
conf.Open(_config);
ReconfigureBags();
}
private void ShowAbout()
{
var about = Gumps.CreateGump();
Gumps.AddBackground(ref about, 0, 0, 426, 229, -1);
Gumps.AddImage(ref about, 0,0,11055);
Gumps.AddHtml(ref about, 95, 25, 400, 20, "<h1>About</h1>", false, false);
Gumps.AddLabel(ref about, 55,50,0,"Lootmaster is created");
Gumps.AddLabel(ref about, 55,62,0,"and is maintained by");
Gumps.AddLabel(ref about, 55,74,0,"Matt Dorana");
Gumps.AddLabel(ref about, 55,98,0,"It is free to use and");
Gumps.AddLabel(ref about, 55,110,0,"will receive updates");
Gumps.AddLabel(ref about, 55,122,0,"on the feedback");
Gumps.AddLabel(ref about, 55,134,0,"and requests");
Gumps.AddLabel(ref about, 55,146,0,"is sent in");
Gumps.AddLabel(ref about, 220,50,0,"If you enjoy this");
Gumps.AddLabel(ref about, 220,62,0,"script feel free to");
Gumps.AddLabel(ref about, 220,74,0,"reach out to me on");
Gumps.AddLabel(ref about, 220,86,0,"Discord");
Gumps.AddLabel(ref about, 250,130,0,"Wiki Page");
Gumps.AddButton(ref about, 215, 125, 5843, 5844, (int)OptionsItem.Wiki, 1, 0);
Gumps.AddLabel(ref about, 250,164,0,"Buy me a coffee");
Gumps.AddButton(ref about, 215, 159, 5843, 5844, (int)OptionsItem.Coffee, 1, 0);
about.serial = (uint)Player.Serial;
about.gumpId = 492828;
Gumps.CloseGump(492828);
Gumps.SendGump(about, 500, 350);
}
private void UpdateLootMasterGump(Hue color)
{
var controller = Gumps.CreateGump();
controller.x = 300;
controller.y = 300;
Gumps.AddPage(ref controller, 0);
Gumps.AddBackground(ref controller, 0, 0, 140, 45, 1755);
Gumps.AddButton(ref controller, 10, 8, 2152, 2151, 500, 1, 0);
Gumps.AddLabel(ref controller, 50, 12, (int)color, "Lootmaster");
Gumps.CloseGump(13659823);
controller.serial = (uint)Player.Serial;
controller.gumpId = 13659823;
Gumps.SendGump(controller, 150, 150);
}
private void LootContainer(Item container) => LootContainer(container, null);
private void LootContainer(Item container, LootRule rule)
{
Handler.SendMessage(MessageType.Debug, $"Waiting for contents of {container.Name}");
Items.WaitForContents(container, 10000);
var stamp = DateTime.Now;
Handler.SendMessage(MessageType.Debug, $"Looting {container.Name}");
var timeValidator = DateTimeOffset.Now;
if (container.IsCorpse && container.DistanceTo(_player) > 2)
{
return;
}
if (IsOSI)
{
Misc.Pause(1000);
}
Misc.Pause(_lootDelay);
var entries = _journal.GetJournalEntry(_lastEntry);
if (entries != null && entries.Any(e => e.Type == "system" && (e.Text.ToLower() == "you may not loot this corpse." || e.Text.ToLower() == "you did not earn the right to loot this creature!")))
{
IgnoreCorpse(container);
return;
}
var sum = 1;
Handler.SendMessage(MessageType.Debug, $"Starting loot cycle");
while (sum != 0)
{
sum = Loot(container, rule);
if (sum == int.MinValue)
{
return;
}
if (sum == int.MaxValue)
{
Misc.Pause(2000);
return;
}
Misc.Pause(100);
if (DateTimeOffset.Now - timeValidator > TimeSpan.FromSeconds(IsOSI ? 20 : 10))
{
Handler.SendMessage(MessageType.Error, "Something seems to have locked up, aborting loot cycle");
return;
}
}
if (Player.IsGhost)
{
return;
}
Misc.Pause(IsOSI ? 200 : 100);
IgnoreCorpse(container);
}
private void IgnoreCorpse(Item container)
{
ignoreList.Add(container.Serial);
if (container.IsCorpse && _config.ColorCorpses)
{
Items.SetColor(container.Serial,0x3F6);
}
}
private int Loot(Item container, LootRule singleRule)
{
List <GrabTarget> lootItems = new List<GrabTarget>();
var sum = 0;
foreach (var item in container.Contains.Where(c => c.IsLootable && !(c.Name.Trim().StartsWith("(") && c.Name.Trim().EndsWith(")"))))
{
Handler.SendMessage(MessageType.Debug,$"Checking Item {item.Name}");
if (container.IsCorpse && container.DistanceTo(_player) > 2)
{
return int.MinValue;
}
if (Player.IsGhost)
{
return int.MinValue;
}
Items.WaitForProps(item, 3000);
if (singleRule != null)
{
if (singleRule.Match(item))
{
lootItems.Add(new GrabTarget
{
Item = item,
Rule = singleRule
});
}
}
foreach (var rule in _config.GetCharacter().Rules.Where(r => !r.Disabled))
{
Handler.SendMessage(MessageType.Debug, $"Checking Rule {rule.RuleName}");
if (container.IsCorpse && container.DistanceTo(_player) > 2)
{
return int.MinValue;
}
if (rule.TargetBag == null)
{
continue;
}
if (rule.Match(item))
{
if (rule.TargetBag == container.Serial)
{
// don't loot to the same container
continue;
}
if (rule.TargetBag == item.Serial)
{
// Don't loot into itself
continue;
}
lootItems.Add(new GrabTarget
{
Item = item,
Rule = rule
});
break;
}
}
}
var overLimit = false;
foreach (var li in lootItems)
{
var checkItem = Items.FindBySerial(li.Item.Serial);
if (checkItem?.Container == container.Serial)
{
if (li.Item.Weight + Player.Weight > Player.MaxWeight)
{
overLimit = true;
}
else
{
sum += GrabItem(li.Item, li.Rule);
}
}
}
if (overLimit)
{
Handler.SendMessage(MessageType.Info, "Maximum weight reached, one or more items were left ont he corpse");
return int.MaxValue;
}
return sum;
}
private bool Setup()
{
var character = _config.GetCharacter();
if (character.Rules.Any(r => string.IsNullOrEmpty(r.RuleName)))
{
Handler.SendMessage(MessageType.Error, "One or more rules are missing a name");
return false;
}
foreach (var rule in character.Rules)
{
while (rule.GetTargetBag() == null)
{
var target = Prompt($"Pick loot bag for {rule.RuleName}");
SetBag(target, rule);
}
}
Misc.RemoveSharedValue("LootmasterDirectContainer");
_player = Mobiles.FindBySerial(Player.Serial);
var gems = Enum.GetValues(typeof(Gem)).Cast<Gem>().ToList();
foreach (var gem in gems) _gems.Add((int)gem);
Misc.RemoveSharedValue("Lootmaster:ReconfigureBags");
Handler.SendMessage(MessageType.Info, "Lootmaster is ready to loot");
_config.Save();
return true;
}
private int GrabItem(Item item,LootRule rule)
{
MoveToBag(item, rule.GetTargetBag());
Misc.Pause(200);
if (rule.Alert)
{
Handler.SendMessage(MessageType.Info, $"Looted item for rule {rule.RuleName}");
}
return item.Amount;
}
private void SetBag(int itemSerial, LootRule rule)
{
Item current;
if (itemSerial == Player.Backpack.Serial)
current = Player.Backpack;
else
current = FindBag(itemSerial);
if (current == null || (current.Serial != Player.Backpack.Serial && current.RootContainer != Player.Backpack.Serial))
{
Handler.SendMessage(MessageType.Error, $"Target is not a suitable container for {rule.RuleName}");
return;
}
rule.TargetBag = current.Serial;
}
private Item FindBag(int target)
{
var targetItem = Items.FindBySerial(target);
return targetItem?.IsContainer != true ? null : targetItem;
}
private int Prompt(string text)
{
Handler.SendMessage(MessageType.Prompt, text);
return _tar.PromptTarget(text);
}
private void MoveToBag(Item item, Item destinationBag)
{
Items.Move(item, destinationBag, item.Amount);
Misc.Pause(_lootDelay);
}
}
public class GrabTarget
{
public Item Item { get; set; }
public LootRule Rule { get; set; }
}
public class LootRule
{
public string RuleName { get; set; }
public List<string> ItemNames { get; set; }
public List<EquipmentSlot> EquipmentSlots { get; set; }
public List<PropertyMatch> Properties { get; set; }
public ItemRarity? MinimumRarity { get; set; }
public bool IgnoreWeightCurse { get; set; }
public List<int> ItemIds { get; set; }
public List<ItemProperty> BlackListedProperties { get; set; }
public bool Alert { get; set; }
public bool Disabled { get; set; }
public int? TargetBag { get; set; }
public int? PropertyMatchRequirement { get; set; }
public Item GetTargetBag() => Items.FindBySerial(TargetBag ?? -1);
public static LootRule Gold =>
new LootRule
{
RuleName = "Gold",
ItemIds = new List<int> { 3821, 41777 }, //GoldStacks and GoldBags
IgnoreWeightCurse = true
};
public static LootRule Gems =>
new LootRule
{
RuleName = "Gems",
ItemIds = Enum.GetValues(typeof(Gem)).Cast<Gem>().Select(g => (int)g).ToList().Union(new List<int> { 41779 }).ToList(),
IgnoreWeightCurse = true
};
public static LootRule Ammo =>
new LootRule
{
RuleName = "Bolts and Arrows",
ItemIds = new List<int> { 3903, 7163 } //Arrows and Bolts
};
public static LootRule PureColdWeapon =>
new LootRule
{
RuleName = "Pure Cold Weapon",
Properties = new List<PropertyMatch>
{
new PropertyMatch
{
Property = ItemProperty.ColdDamage,
Value = 100
}
}
};
public static LootRule PureFireWeapon =>
new LootRule
{
RuleName = "Pure Fire Weapon",
Properties = new List<PropertyMatch>
{
new PropertyMatch
{
Property = ItemProperty.FireDamage,
Value = 100
}
}
};
public static LootRule PurePoisonWeapon =>
new LootRule
{
RuleName = "Pure Poison Weapon",
Properties = new List<PropertyMatch>
{
new PropertyMatch
{
Property = ItemProperty.PoisonDamage,
Value = 100
}
}
};
public static LootRule Slayers =>
new LootRule
{
RuleName = "Slayers",
Properties = new List<PropertyMatch>
{
new PropertyMatch
{
Property = ItemProperty.AnySlayer
}
}
};
public static LootRule PureElementalWeapons =>
new LootRule
{
RuleName = "Pure Elemental Weapons",
Properties = new List<PropertyMatch>
{
new PropertyMatch
{
Property = ItemProperty.AnyElement,
Value = 100
}
}
};
public static LootRule PureEnergyWeapon =>
new LootRule
{
RuleName = "Pure Energy Weapon",
Properties = new List<PropertyMatch>
{
new PropertyMatch
{
Property = ItemProperty.EnergyDamage,
Value = 100
}
}
};
public LootRule(string ruleName, params string[] itemName)
{
RuleName = ruleName;
ItemNames = itemName.ToList();
TargetBag = null;
}
public LootRule(string ruleName, string itemName, bool alert = false)
{
RuleName = ruleName;
ItemNames = new List<string> { itemName };
Alert = alert;
TargetBag = null;
}
public LootRule()
{
TargetBag = null;
}
public LootRule(string ruleName, ItemProperty property, int amount, ItemRarity? minimumRarity, EquipmentSlot? slot, bool alert = false)
{
RuleName = ruleName;
EquipmentSlots = slot == null ? null : new List<EquipmentSlot>
{
slot.Value
};
Properties = new List<PropertyMatch>
{
new PropertyMatch
{
Property = property,
Value = amount
}
};
MinimumRarity = minimumRarity;
Alert = alert;
TargetBag = null;
}
public bool Match(Item item)
{
var match = CheckItemIdOrName(item);
Handler.SendMessage(MessageType.Debug,$"CheckItemId / CheckItemName : {match}");
//match = match && CheckBlackListProperties(item);
match = match && CheckWeightCursed(item);