forked from ScriptB3ast/razor-enhanced
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ELoot.py
1955 lines (1529 loc) · 66.1 KB
/
ELoot.py
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
# RAZOR ENHANCED LOOT SCRIPT
#
# discord : Jewele
#
# Script for Razor Enhanced to show loot in nearby corpses.
#
# If you obtained this script by itself, stop immediately. It will not work without image files.
# Go to : https://github.com/gmccord333/UOScripts/tree/master/RazorEnhanced/EnhancedLoot
# and download the entire package.
#
# VERSION HISTORY
# ===============
# 1.6.2 - Initial release
#
import clr, time, thread, time, re, datetime, sys
clr.AddReference('System')
clr.AddReference('System.Drawing')
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Data')
import System
from System import TimeSpan, Guid
from System.IO import File, Directory, MemoryStream
from System.ComponentModel import BackgroundWorker
from System.Timers import Timer
from System.Collections.Generic import List
from System.Threading import Mutex, AbandonedMutexException
from System.Threading import Thread
from System.Threading.Thread import Sleep
from System.Drawing import Point, Color, Size, Image, Font, ContentAlignment
from System.Windows.Forms import (
Application, Button, Form, BorderStyle, FormBorderStyle, Cursor, Cursors,
Label, FlatStyle, DataGridView, DataGridViewAutoSizeColumnMode,
DataGridViewRow, DataGridViewAutoSizeColumnsMode,
DataGridViewSelectionMode, DataGridViewEditMode, CheckBox,
DataGridViewDataErrorContexts, ControlStyles, DataGridViewCellBorderStyle,
DataGridViewAdvancedCellBorderStyle, ToolTip,
DataGridViewColumnHeadersHeightSizeMode, PictureBox, FormWindowState,
ImageList, DataGridViewHeaderBorderStyle, DataGridViewCheckBoxColumn,
DataGridViewColumn, DataGridViewColumnSortMode, BindingSource)
from System.Data import DataTable
SCRIPT_NAME = 'UORazor Enhanced Loot'
SCRIPT_VERSION = '1.6.2'
COLOR_NORMAL = 76
COLOR_WARN = 44
COLOR_ERROR = 33
BACKGROUND = Directory.GetCurrentDirectory() + "\\scripts\\images\\loot.png"
IMG_HAND = Directory.GetCurrentDirectory() + "\\scripts\\images\\hand.png"
IMG_PICK = Directory.GetCurrentDirectory() + "\\scripts\\images\\pick.png"
IMG_CLOSE = Directory.GetCurrentDirectory() + "\\scripts\\images\\close.png"
IMG_CUT = Directory.GetCurrentDirectory() + "\\scripts\\images\\cut.png"
IMG_HIDDEN = Directory.GetCurrentDirectory() + "\\scripts\\images\\hidden.png"
IMG_JEWEL = Directory.GetCurrentDirectory() + "\\scripts\\images\\jewel.png"
IMG_COIN = Directory.GetCurrentDirectory() + "\\scripts\\images\\coin.png"
IMG_BAG = Directory.GetCurrentDirectory() + "\\scripts\\images\\bag.png"
IMG_REDSKULL = Directory.GetCurrentDirectory() + "\\scripts\\images\\redskull.png"
IMG_SKULL = Directory.GetCurrentDirectory() + "\\scripts\\images\\skull.png"
FILE_LOOT = Directory.GetCurrentDirectory() + "\\loot.txt"
FILE_DEBUG = Directory.GetCurrentDirectory() + "\\debug.txt"
LOADED_IMG_REDSKULL = None
LOADED_IMG_SKULL = None
MSG_EMPTY = 'Corpse is empty, use Cut button to harvest materials or Close'
MSG_INNOCENT = 'You have disabled opening innocent corpses. Hit Refresh to renew status'
MSG_HIDDEN = 'You are hidden, opening a corpse not your own will reveal you!'
ZEROPOS_ITEMS = ['magical crystal (1F19)']
# Affects time to wait between looting multiple items.
# 100ms is aggressive
# 400ms is safe
# 500ms was very safe
LOOT_WAIT = 300
# This is how often the script tries to synchronize itself with the
# world around the player. A good estimate is 500 ms. There isn`t much
# benefit to making this a low number.
WORKER_WAIT = 1000
COLOR_NORMAL = 76
COLOR_WARN = 44
COLOR_ERROR = 33
MUTEX_NAME = Guid.NewGuid()
MUTEX = Mutex(MUTEX_NAME)
# do not enable this unless you are debugging
DEBUG = False
# word fix patterns I know about
WORD_FIXES = {
"scro[l]+": "scroll",
"scr?$": "scroll",
"scro$": "scroll",
"sc$": "scroll"
}
blades = [
0x1401, 0xf52, 0x13b9, 0xf61, 0x1441, 0x13b6, 0xec4, 0x13f6, 0xf5e, 0x13ff,
0xec3
]
axes = [0xf43, 0xf4b, 0x143e, 0xf45, 0x1443, 0xf4d]
##########
# Debug output to file, leave off unless investigating code issues.
#
def _debug(s):
if DEBUG:
with open(FILE_DEBUG, "a") as myfile:
myfile.write("{0} {1}\n".format(datetime.datetime.now(), s))
##########
# Loads image from disk in non-blocking way so we dont have resource contention locks
#
def Image_From_File(path):
try:
bytes = File.ReadAllBytes(path)
ms = MemoryStream(bytes)
img = Image.FromStream(ms)
return img
except Exception as e:
_debug("Caught exception in Image FromFile : {0}".format(str(e)))
##########
# Class which interfaces with a local file, containing user loot preferences
#
class Settings_Manager(object):
##########
# Class initialization
#
def __init__(self, file):
try:
self.File = file
if not File.Exists(self.File):
File.Create(self.File)
self.IDs = List[System.String]
self.Load()
except Exception as e:
_debug("Caught exception in Settings_Manager.__init__: {0}".format(
str(e)))
raise
##########
# Loads player preferences into memory
#
def Load(self):
try:
assert File.Exists(self.File), "Missing file : {0}".format(
self.File)
self.IDs = List[System.String](File.ReadAllLines(self.File))
except Exception as e:
_debug("Caught exception in Settings_Manager.Load {0}".format(
str(e)))
raise
##########
# Allows script to query whether an item has been set as preferred
#
def IsAlwaysLoot(self, id):
try:
assert File.Exists(self.File), "Missing file : {0}".format(
self.File)
return self.IDs.Contains(str(id))
except Exception as e:
_debug("Caught exception in Settings_Manager.IsAlwaysLoot: {0}".
format(str(e)))
raise
##########
# Allows script to save an item`s preferred status. Only writes to file
# if there was actually a change.
#
def SetAlwaysLoot(self, id, toggle):
try:
assert File.Exists(self.File), "Missing file : {0}".format(
self.File)
updated = False
# amend list for new or removed items
if self.IDs.Contains(str(id)):
if toggle == False:
self.IDs.Remove(str(id))
updated = True
else:
if toggle == True:
self.IDs.Add(str(id))
updated = True
if updated:
file = open(self.File, 'w')
file.write(System.String.Join("\n", self.IDs))
file.close()
except Exception as e:
_debug(
"Caught exception in Settings_Manager.SetAlwaysLoot() : {0}".
format(str(e)))
##########
# Class which keeps track of all nearby corpses and tags the ones the user has processed already.
#
class Corpse_Manager(object):
_corpses = []
_ignore = []
##########
# Copies the passed in list to a local variable; accepts a list of items from a filter
# configured to locate corpses.
#
def Synchronize(self, corpses):
_debug("Corpse_Manager.Synchronize.start")
_debug(corpses)
if not MUTEX.WaitOne(TimeSpan.Zero):
return
try:
self._corpses = []
for corpse in corpses:
# do not add corpse if Player has already processed it
if corpse.Serial in self._ignore:
_debug("ignored by serial {0}".format(corpse.Serial))
continue
_debug("added {0}".format(corpse.Serial))
self._corpses.append(corpse)
_debug("_corpses = {0}".format(self._corpses))
except Exception as e:
_debug("Caught exception in Corpse_Manager.Synchronize() : {0}".
format(str(e)))
finally:
MUTEX.ReleaseMutex()
_debug("Corpse_Manager.Synchronize.exit")
##########
# Ignores a corpse; for example, user has looted it, or closed the window on viewing it
#
def Ignore(self, o):
try:
assert o is not None, "A valid object was passed to function"
if o.Serial not in self._ignore:
self._ignore.append(o.Serial)
old = list(self._corpses)
self.Synchronize(old)
except Exception as e:
_debug("Caught exception in Corpse_Manager.Ignore() : {0}".format(
str(e)))
##########
# Reports whether a corpse has been inventoried by this class instance. For example,
# if a player encounters a new corpse, script can query this class to find out whether
# the corpse was seen before, or is new.
#
def Contains(self, o):
try:
if o == None:
return False
for corpse in self._corpses:
if corpse.Serial == o.Serial:
return True
return False
except Exception as e:
_debug(
"Caught exception in Corpse_Manager.Contains() : {0}".format(
str(e)))
##########
# Returns first object in list or None
#
def GetNext(self):
_debug("Corpse_Manager.GetNext (currently at {0})".format(
len(self._corpses)))
if len(self._corpses) > 0:
return self._corpses[0]
else:
return None
##########
# User form
class LootForm(Form):
CM = Corpse_Manager()
SM = Settings_Manager(FILE_LOOT)
DT = DataTable()
BS = BindingSource()
Corpse = None
IsInnocent = False
IsCriminal = False
Loaded = False
HasBag = False
Contents = []
LootBag = None
isMouseDown = False
lastLocation = None
def __init__(self):
_debug("LootForm.__init__.start()")
try:
self.ShownInTaskbar = True
self.FormBorderStyle = System.Windows.Forms.FormBorderStyle. None
self.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
self.BackColor = Color.FromArgb(0, 0, 1)
self.ForeColor = Color.FromArgb(231, 231, 231)
self.Size = Size(280, 340)
self.Text = '{0} - v{1}'.format(SCRIPT_NAME, SCRIPT_VERSION)
self.TopMost = True
self.MinimizeBox = False
self.MaximizeBox = False
self.DT.Columns.Add('Item', System.Type.GetType("System.Object"))
self.DT.Columns.Add('Loot?', System.Type.GetType("System.Boolean"))
self.DT.Columns.Add('Name', clr.GetClrType(str))
self.DT.Columns.Add('Always',
System.Type.GetType("System.Boolean"))
# Data binding
self.BS.DataSource = self.DT
self.DataGridSetup()
self.DataGrid.DataSource = self.BS
# lbl name
self.lblName = Label()
self.lblName.Text = Player.Name
self.lblName.Location = Point(51, 10)
self.lblName.Width = 180
self.lblName.Font = Font("Tahoma", 11)
self.lblName.ForeColor = Color.Cyan
self.lblName.BackColor = Color.Transparent
self.lblName.TextAlign = ContentAlignment.MiddleCenter
# lbl status
self.lblStatus = Label()
self.lblStatus.Text = ""
self.lblStatus.Location = Point(51, 251)
self.lblStatus.Width = 180
self.lblStatus.Font = Font("Tahoma", 10)
self.lblStatus.ForeColor = Color.White
self.lblStatus.BackColor = Color.Transparent
self.lblStatus.TextAlign = ContentAlignment.MiddleCenter
self.lblStatus.Visible = False
# lbl weight
self.lblWeight = Label()
self.lblWeight.Text = ''
self.lblWeight.Location = Point(101, 40)
self.lblWeight.Width = 80
self.lblWeight.Font = Font("Tahoma", 9)
self.lblWeight.ForeColor = Color.Gold
self.lblWeight.BackColor = Color.Transparent
self.lblWeight.TextAlign = ContentAlignment.MiddleCenter
# lbl message
self.lblMsg = Label()
self.lblMsg.Text = ""
self.lblMsg.Location = Point(40, 120)
self.lblMsg.Width = 200
self.lblMsg.Height = 80
self.lblMsg.Font = Font("Tahoma", 9)
self.lblMsg.ForeColor = Color.White
self.lblMsg.BackColor = Color.Black
self.lblMsg.Visible = True
# open button
self.btnOpen = Button()
self.btnOpen.ForeColor = Color.White
self.btnOpen.BackColor = Color.Transparent
self.btnOpen.Text = "Open"
self.btnOpen.Cursor = Cursors.Hand
self.btnOpen.Location = Point(110, 175)
self.btnOpen.Size = Size(50, 50)
self.btnOpen.FlatStyle = FlatStyle.Flat
self.btnOpen.FlatAppearance.BorderSize = 0
self.btnOpen.Click += self.btnOpenPressed
self.btnOpen.Image = Image_From_File(IMG_HIDDEN)
self.btnOpen.GotFocus += self.Form_Open_GotFocus
self.btnOpen.MouseEnter += self.Form_Open_MouseEnter
self.btnOpen.MouseLeave += self.Form_Open_MouseLeave
self.btnOpen.Visible = False
# get button
self.btnGet = Button()
self.btnGet.BackColor = Color.Transparent
self.btnGet.Cursor = Cursors.Hand
self.btnGet.Location = Point(5, 285)
self.btnGet.Size = Size(50, 50)
self.btnGet.FlatStyle = FlatStyle.Flat
self.btnGet.FlatAppearance.BorderSize = 0
self.btnGet.Click += self.btnGetPressed
self.btnGet.Image = Image_From_File(IMG_HAND)
self.btnGet.GotFocus += self.Form_Get_GotFocus
self.btnGet.MouseEnter += self.Form_Get_MouseEnter
self.btnGet.MouseLeave += self.Form_Get_MouseLeave
self.btnGet.Visible = False
# cut button
self.btnCut = Button()
self.btnCut.Cursor = Cursors.Hand
self.btnCut.BackColor = Color.Transparent
self.btnCut.Location = Point(60, 285)
self.btnCut.Size = Size(50, 50)
self.btnCut.FlatStyle = FlatStyle.Flat
self.btnCut.FlatAppearance.BorderSize = 0
self.btnCut.Click += self.btnCutPressed
self.btnCut.Image = Image_From_File(IMG_CUT)
self.btnCut.GotFocus += self.Form_Cut_GotFocus
self.btnCut.MouseEnter += self.Form_Cut_MouseEnter
self.btnCut.MouseLeave += self.Form_Cut_MouseLeave
self.btnCut.Visible = False
# bag button
self.btnBag = Button()
self.btnBag.Cursor = Cursors.Hand
self.btnBag.BackColor = Color.Transparent
self.btnBag.Location = Point(115, 285)
self.btnBag.Size = Size(50, 50)
self.btnBag.FlatStyle = FlatStyle.Flat
self.btnBag.FlatAppearance.BorderSize = 0
self.btnBag.Click += self.btnBagPressed
self.btnBag.Image = Image_From_File(IMG_BAG)
self.btnBag.GotFocus += self.Form_Bag_GotFocus
self.btnBag.MouseEnter += self.Form_Bag_MouseEnter
self.btnBag.MouseLeave += self.Form_Bag_MouseLeave
self.btnBag.Visible = False
# pick button
self.btnPick = Button()
self.btnPick.Cursor = Cursors.Hand
self.btnPick.BackColor = Color.Transparent
self.btnPick.Location = Point(170, 285)
self.btnPick.Size = Size(50, 50)
self.btnPick.FlatStyle = FlatStyle.Flat
self.btnPick.FlatAppearance.BorderSize = 0
self.btnPick.Click += self.btnPickPressed
self.btnPick.Image = Image_From_File(IMG_PICK)
self.btnPick.GotFocus += self.Form_Pick_GotFocus
self.btnPick.MouseEnter += self.Form_Pick_MouseEnter
self.btnPick.MouseLeave += self.Form_Pick_MouseLeave
self.btnPick.Visible = False
# close button
self.btnClose = Button()
self.btnClose.Cursor = Cursors.Hand
self.btnClose.BackColor = Color.Transparent
self.btnClose.Location = Point(225, 285)
self.btnClose.Size = Size(50, 50)
self.btnClose.FlatStyle = FlatStyle.Flat
self.btnClose.FlatAppearance.BorderSize = 0
self.btnClose.Click += self.btnClosePressed
self.btnClose.Image = Image_From_File(IMG_CLOSE)
self.btnClose.GotFocus += self.Form_Close_GotFocus
self.btnClose.MouseEnter += self.Form_Close_MouseEnter
self.btnClose.MouseLeave += self.Form_Close_MouseLeave
self.btnClose.Visible = False
# upper right corner skull overlay
self.picSkull = PictureBox()
self.picSkull.Cursor = Cursors.Hand
self.picSkull.Location = Point(221, 0)
self.picSkull.Size = Size(59, 61)
self.picSkull.Image = LOADED_IMG_SKULL
self.picSkull.Click += self.picSkullPressed
self.picSkull.MouseEnter += self.Form_Skull_MouseEnter
self.picSkull.MouseLeave += self.Form_Skull_MouseLeave
self.picSkull.Visible = True
# mouse form move event handlers
self.MouseDown += self.Form_MouseDown
self.MouseMove += self.Form_MouseMove
self.MouseUp += self.Form_MouseUp
self.lblName.MouseDown += self.Form_MouseDown
self.lblName.MouseMove += self.Form_MouseMove
self.lblName.MouseUp += self.Form_MouseUp
self.lblWeight.MouseDown += self.Form_MouseDown
self.lblWeight.MouseMove += self.Form_MouseMove
self.lblWeight.MouseUp += self.Form_MouseUp
self.lblStatus.MouseDown += self.Form_MouseDown
self.lblStatus.MouseMove += self.Form_MouseMove
self.lblStatus.MouseUp += self.Form_MouseUp
self.DataGrid.MouseDown += self.Form_MouseDown
self.DataGrid.MouseMove += self.Form_MouseMove
self.DataGrid.MouseUp += self.Form_MouseUp
# tooltips
self.ToolTip = ToolTip()
self.ToolTip.SetToolTip(self.btnClose, "Close")
self.ToolTip.SetToolTip(self.btnCut, "Cut corpse")
self.ToolTip.SetToolTip(self.btnGet, "Get selected")
self.ToolTip.SetToolTip(self.btnPick, "Set bag")
self.ToolTip.SetToolTip(self.btnBag, "Open containers")
# add controls
self.Controls.Add(self.DataGrid)
self.Controls.Add(self.btnGet)
self.Controls.Add(self.btnOpen)
self.Controls.Add(self.btnClose)
self.Controls.Add(self.btnPick)
self.Controls.Add(self.btnCut)
self.Controls.Add(self.btnBag)
self.Controls.Add(self.lblWeight)
self.Controls.Add(self.lblMsg)
self.Controls.Add(self.lblName)
self.Controls.Add(self.picSkull)
self.Controls.Add(self.lblStatus)
self.BackgroundImage = Image_From_File(BACKGROUND)
# add background worker
self._worker = BackgroundWorker()
self._worker.DoWork += self.__start
self._worker.ProgressChanged += self.__update
self._worker.WorkerReportsProgress = True;
self._worker.WorkerSupportsCancellation = True;
self._worker.RunWorkerAsync();
# hide on startup
self.Opacity = 0
self.ShowInTaskbar = False
except Exception as e:
_debug("Caught exception in LootForm.__init__() : {0}".format(
str(e)))
raise
_debug("LootForm.__init__.exit")
##########
# Sets up the DataGrid, doing initialization, formatting, and adding event handlers
#
def DataGridSetup(self):
_debug("LootForm.DataGridSetup.start")
self.DataGrid = DataGridView()
self.DataGrid.RowHeadersVisible = False
self.DataGrid.MultiSelect = False
self.DataGrid.BackgroundColor = Color.Black
self.DataGrid.RowsDefaultCellStyle.BackColor = Color.Black
self.DataGrid.RowsDefaultCellStyle.ForeColor = Color.White
self.DataGrid.EnableHeadersVisualStyles = False
self.DataGrid.ColumnHeadersDefaultCellStyle.BackColor = Color.Black
self.DataGrid.CellBorderStyle = DataGridViewCellBorderStyle. None
self.DataGrid.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle. None
self.DataGrid.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle. None
self.DataGrid.AdvancedCellBorderStyle.Left = DataGridViewAdvancedCellBorderStyle. None
self.DataGrid.AdvancedCellBorderStyle.Right = DataGridViewAdvancedCellBorderStyle. None
self.DataGrid.AutoGenerateColumns = True
self.DataGrid.BorderStyle = BorderStyle. None
self.DataGrid.ForeColor = Color.White
self.DataGrid.Location = Point(40, 60)
self.DataGrid.Width = 200
self.DataGrid.Height = 180
self.DataGrid.AllowUserToResizeColumns = False
self.DataGrid.AllowUserToResizeRows = False
self.DataGrid.AllowUserToAddRows = False
self.DataGrid.BorderStyle = BorderStyle. None
self.DataGrid.DefaultCellStyle.Font = Font("Tahoma", 9)
self.DataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode. None
self.DataGrid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
self.DataGrid.CellMouseEnter += self.Form_DataGrid_MouseEnter
self.DataGrid.CellContentClick += self.CellClick
self.DataGrid.SelectionChanged += self.SelectionChanged
self.DataGrid.CellPainting += self.Form_DataGrid_CellPaint
self.DataGrid.Visible = False
_debug("LootForm.DataGridSetup.exit")
##########
# Event handler for drawing icons in the datagridview header row
#
def Form_DataGrid_CellPaint(self, sender, e):
if e.RowIndex == -1 and e.ColumnIndex == 1:
point = e.CellBounds.Location
e.Graphics.DrawImage(Image_From_File(IMG_COIN), point)
e.Handled = True
elif e.RowIndex == -1 and e.ColumnIndex == 3:
point = e.CellBounds.Location
e.Graphics.DrawImage(Image_From_File(IMG_JEWEL), point)
e.Handled = True
##########
# (WORKER THREAD)
# Function which the worker thread will execute outside the main thread. Script constantly
# scans near player for a list of corpses, and if found, passes that list back to the UI
# thread for processing.
#
def __start(self, sender, e):
_debug("LootForm.[Worker].__start.start")
_mutex = Mutex(MUTEX_NAME)
try:
# Loop waiting for cancel request from Form or script
while not self._worker.CancellationPending:
Thread.Sleep(WORKER_WAIT)
# if dead just loop
if Player.Hits == 0:
continue
if not _mutex.WaitOne(TimeSpan.Zero):
_debug("worker: mutex locked")
continue
try:
# 3 tiles, diagonal loot fix.
filter = Items.Filter()
filter.Enabled = True
filter.OnGround = True
filter.Movable = False
filter.RangeMax = 3
filter.IsCorpse = True
# this generates a list of coordinates around which a player can loot
loot_range = self.GetLootCoords()
# re-process the filter results, and add anything in range
corpse_list = []
for corpse in Items.ApplyFilter(filter):
for coord in loot_range:
if corpse.Position.X == coord[0] and corpse.Position.Y == coord[1]:
corpse_list.append(corpse)
# send list out of background worker to main thread
sender.ReportProgress(0, corpse_list)
except Exception as e:
_debug(
"Caught exception in LootForm.[Worker].__start : {0} - {1}".
format(type(ex), ex))
finally:
_mutex.ReleaseMutex()
# Got the cancel request, exit normally
if self._worker.CancellationPending:
_debug(
"LootForm.[Worker].__start CancellationPending detected, sending Cancel request"
)
e.Cancel = True
except Exception as ex:
_debug("Caught exception in LootForm.[Worker].__start : {0} - {1}".
format(type(ex), ex))
_debug("LootForm.[Worker].__start.exit")
##########
# UORazor Enhanced range filters only work in straight lines on X,Y axes. It does not work in
# diagonals, although the game supports looting at 2 diagonal tiles away from player.
# In order to fix this, we need to generate a list of valid tiles around player in which
# a corpse can be looted.
#
def GetLootCoords(self):
_out = []
# calculate tuples of coordinates around player within 2 spaces
for x in range(Player.Position.X - 2, Player.Position.X + 3):
for y in range(Player.Position.Y - 2, Player.Position.Y + 3):
_out.append((x, y))
return _out
##########
# Event handler for worker thread progress notifications. When the worker thread updates
# nearby corpses, it will send that list to this function, which runs in the main thread.
#
def __update(self, sender, e):
_debug("LootForm.__update.start [{0}]".format(e.UserState))
if not MUTEX.WaitOne(TimeSpan.FromSeconds(1)):
return
try:
# synchronize Corpse Manager with corpses around player
self.CM.Synchronize(e.UserState)
# update player wait
self.UpdateWeight()
# process next corpse if not viewing one
if self.Corpse == None:
self.Corpse = self.CM.GetNext()
# reset corpse flags and clear contents
self.IsInnocent = False
self.IsCriminal = False
self.Loaded = False
self.HasBag = False
self.Contents = []
# if we got valid corpse
if self.Corpse != None:
# if player visible, load it
if Player.Visible:
self.LoadCorpse()
self.UpdateViewState()
# player is viewing an invalid corpse
elif not self.CM.Contains(self.Corpse):
self.Corpse = None
self.UpdateViewState()
# player is visible and corpse wasn`t loaded
# (handles case where player was hidden but
# becomes visible at corpse)
elif Player.Visible and not self.Loaded and not self.IsInnocent:
self.LoadCorpse()
self.UpdateViewState()
except Exception as ex:
_debug("Caught exception in LootForm.__update : {0}".format(ex))
raise
finally:
MUTEX.ReleaseMutex()
_debug("LootForm.__update.exit")
##########
# Retrieves contents of a container and sets local variables IsInnocent and IsCriminal
#
def InventoryContainer(self, container):
_debug("LootForm.InventoryContainer.start")
try:
contents = []
Journal.Clear()
if container != None:
# Tries to open a container and get its contents 5 times
# If we do not get a `must wait` in journal, that means we opened it.
# There is no mechanism in the game to determine that you have opened a container,
# other than trying to open it when its not ready will print a journal message.
# If we do not get the wait message, we can conclude it opened.
#
# This is what a debug log looks like when this occurs:
# -----------------------------------------------------
# 2018-08-10 21:34:22.215000 LootForm.InventoryContainer.start
# 2018-08-10 21:34:22.218000 Container open attempt 0
# 2018-08-10 21:34:22.473000 Received journal wait message
# 2018-08-10 21:34:22.482000 Container open attempt 1
# 2018-08-10 21:34:22.673000 Received journal wait message
# 2018-08-10 21:34:22.679000 Container open attempt 2
# 2018-08-10 21:34:22.786000 No journal wait message
# 2018-08-10 21:34:22.792000 Found item : clean bandage%s% (0E21)
#
# In example, failed twice, got it on 3rd attempt. ^^
#
for i in range(6):
_debug("Container open attempt {0}".format(i))
Items.UseItem(container)
# Pause to let journal catch up
Misc.Pause(100)
# Wait for contents
Items.WaitForContents(container, 100)
# Wait for disabled corpse messages
if Journal.Search("disabled opening innocent corpses"):
_debug ("Innocent warning detected, returning")
self.IsInnocent = True
return []
else:
_debug ("No innocent warning detected")
# Wait for criminal act messages
if Journal.Search("criminal act"):
_debug ("Criminal act warning detected")
self.IsCriminal = True
else:
_debug ("No criminal warning detected")
# Wait for must wait messages
if Journal.Search("must wait"):
_debug("Received journal wait message")
Journal.Clear()
continue
else:
_debug("No journal wait message")
break
# load container contents
for item in container.Contains:
_debug("Found item : {0}".format(item.Name))
_debug(" -- container? {0}".format(item.IsContainer))
if item.Position.X == 0 and item.Position.Y == 0 and item.Position.Z == 0 and item.Name:
_debug("Zero position item found")
if item.Name in ZEROPOS_ITEMS:
_debug("Adding")
else:
_debug("Phantom item detected, skipping")
continue
contents.append(item)
_debug("Added {0}".format(item.Name))
# Perform one _last_ check on journal to make sure there
# were no innocent or criminal messages - getting someone
# killed because they flagged is REALLY bad. I hate to wait
# yet more time - but this is the stuff which kills people.
Misc.Pause(500)
# Wait for disabled corpse messages
if Journal.Search("disabled opening innocent corpses"):
_debug ("Innocent warning detected, returning")
self.IsInnocent = True
return []
else:
_debug ("No innocent warning detected")
# Wait for criminal act messages
if Journal.Search("criminal act"):
_debug ("Criminal act warning detected")
self.IsCriminal = True
else:
_debug ("No criminal warning detected")
return contents
else:
_debug("Corpse invalid, returning")
return []
except Exception as e:
_debug(
"Caught exception in LootForm.InventoryContainer : {0}".format(
str(e)))
raise
finally:
_debug("LootForm.InventoryContainer.exit")
##########
# Performs a range check on the current corpse, and, if valid, loads the contents
# into the data bound table. Contents of corpses are sorted by importance, using
# settings manager.
#
def LoadCorpse(self):
_debug("LootForm.LoadCorpse.start")
if not MUTEX.WaitOne(TimeSpan.Zero):
return
try:
# reset corpse flags and clear contents
self.IsInnocent = False
self.IsCriminal = False
self.Loaded = False
self.HasBag = False
self.Contents = []
# clear data table
self.DT.Clear()
# clear status
self.lblStatus.Text = ""
# run a quick range check
self.RangeCheckCorpse()
# if corpse still valid
if self.Corpse != None:
# get contents
contents = self.InventoryContainer(self.Corpse)
# IsInnocent flags return immediately
if self.IsInnocent:
return
# sort contents and detect bags
sorted_contents = []
for item in contents:
# preferred items appear at top
if self.SM.IsAlwaysLoot(item.ItemID):
sorted_contents.insert(0, item)
else:
sorted_contents.append(item)
self.HasBag += item.IsContainer
# load data table with contents
self.LoadDataTable(sorted_contents)
# refresh data grid view
self.DataGrid.Refresh()
# set loaded flag
self.Loaded = True
except Exception as ex:
_debug("Caught exception in LootForm.LoadCorpse : {0}".format(ex))
raise
finally:
MUTEX.ReleaseMutex()
_debug("LootForm.LoadCorpse.exit")
##########
# Performs a range check on current corpse handle, and if it is not in range, invalidates it
# by setting class variable Corpse to None.
#
def RangeCheckCorpse(self):
_debug("LootForm.RangeCheckCorpse.start")
try:
if self.Corpse != None:
# check coordinates
for coord in self.GetLootCoords():
if self.Corpse.Position.X == coord[0] and self.Corpse.Position.Y == coord[1]:
_debug("Corpse in range")
return True
# invalidate handle
_debug("corpse out of range")
self.Corpse = None
return False
except Exception as ex:
_debug("Caught exception in LootForm.RangeCheckCorpse: {0}".format(
ex))
raise
finally:
_debug("LootForm.RangeCheckCorpse.exit")
##########
# Accepts a list of Items contained within a corpse and loads the class
# data table instance.
#
# Data Table Structure:
# =====================
# Column 0 = bool (loot bool)
# Column 1 = object (Item)
# Column 2 = string (name)
# Column 3 = bool (preference bool)