-
Notifications
You must be signed in to change notification settings - Fork 1
/
SOSManager.py
351 lines (286 loc) · 12.5 KB
/
SOSManager.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
#===============================================#
# SOS Manager #
#===============================================#
# #
# Author: CookieLover #
# Latest Release: 10/07/2017 #
# #
#===============================================#
# #
# Info: #
# - by selecting a SOS and hitting Move #
# all the SOS in that sector will be moved #
# in the targeted container #
# #
# What you need: #
# - a bag full of SOS #
# #
# Credits: #
# the degrees - coordinates formula is taken #
# from Enhanced Map #
# #
#===============================================#
import clr, math
clr.AddReference('System')
clr.AddReference('System.Drawing')
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Data')
import System
from System.Collections.Generic import List
from System.Drawing import Point, Color, Size
from System.Windows.Forms import (Application, Button, Form, BorderStyle,
Label, FlatStyle, DataGridView, DataGridViewAutoSizeColumnsMode,
DataGridViewSelectionMode, DataGridViewEditMode, CheckBox)
from System.Data import DataTable
class SOS(object):
def __init__(self, _serial, _x, _y, distance=0):
self.serial = _serial
self.x = _x
self.y = _y
self.distance = distance
class SOSManager(Form):
CurVer = '1.0.1'
ScriptName = 'SOS Manager'
base_btn_offset = (20, 328)
SOSBag = None
SOS = []
def __init__(self, bag):
self.SOSBag = bag
self.MapCatalogue()
self.BackColor = Color.FromArgb(25,25,25)
self.ForeColor = Color.FromArgb(231,231,231)
self.Size = Size(270, 444)
self.Text = '{0} - v{1}'.format(self.ScriptName, self.CurVer)
self.DataGridSetup()
# used to reload SOSes to sort them in the new right order (by distance)
self.btnReload = self.init_btn(2, 1, 'Reload', self.btnReloadPressed)
# used to fish on the coordinates
self.btnFish = self.init_btn(1, 1, 'Fish', self.btnFishPressed)
# this types in the command for UO Enhanced Map
self.btnMarker = self.init_btn(0, 1, 'Marker', self.btnMarkerPressed)
# remove SOS from grid
self.btnRemove = self.init_btn(2, 0, 'Remove', self.btnRemovePressed)
# target a container to move the SOS into
self.btnMove = self.init_btn(1, 0, 'Move', self.btnMovePressed)
# open the SOS gump
self.btnOpen = self.init_btn(0, 0, 'Open', self.btnOpenPressed)
self.Controls.Add(self.DataGrid)
self.Controls.Add(self.btnOpen)
self.Controls.Add(self.btnMove)
self.Controls.Add(self.btnRemove)
self.Controls.Add(self.btnMarker)
self.Controls.Add(self.btnFish)
self.Controls.Add(self.btnReload)
self.TopMost = True
def btn_pos(self, xidx, yidx=0):
_x = self.base_btn_offset[0] + xidx * 70
_y = self.base_btn_offset[1] + yidx * 40
return Point(_x, _y)
def DataGridSetup(self):
self.DataGrid = DataGridView()
self.DataGrid.RowHeadersVisible = False
self.DataGrid.MultiSelect = False
self.DataGrid.SelectionMode = DataGridViewSelectionMode.FullRowSelect
self.DataGrid.BackgroundColor = Color.FromArgb(25,25,25)
self.DataGrid.RowsDefaultCellStyle.BackColor = Color.Silver
self.DataGrid.AlternatingRowsDefaultCellStyle.BackColor = Color.Gainsboro
self.DataGrid.ForeColor = Color.FromArgb(25,25,25)
self.DataGrid.Location = Point(20, 12)
self.DataGrid.Size = Size(230, 306)
self.DataGrid.DataSource = self.Data()
self.DataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
self.DataGrid.EditMode = DataGridViewEditMode.EditProgrammatically
self.DataGrid.BorderStyle = BorderStyle.None
def btnOpenPressed(self, sender, args):
row = self.DataGrid.SelectedCells[0].RowIndex
if row == -1:
Misc.SendMessage('{0}: No row selected.'.format(self.ScriptName), 33)
return
col = self.DataGrid.SelectedCells[0].ColumnIndex
serial = self.DataGrid.Rows[row].Cells[col].Value
Items.UseItem(int(serial, 0))
def btnFishPressed(self, sender, args):
row = self.DataGrid.SelectedCells[0].RowIndex
if row == -1:
Misc.SendMessage('{0}: No row selected.'.format(self.ScriptName), 33)
return
x = int(self.DataGrid.Rows[row].Cells[1].Value)
y = int(self.DataGrid.Rows[row].Cells[2].Value)
Items.UseItemByID(0x0DC0, 0)
Target.WaitForTarget(6000)
Target.TargetExecute(x, y, Player.Position.Z)
def btnMarkerPressed(self, sender, args):
row = self.DataGrid.SelectedCells[0].RowIndex
if row == -1:
Misc.SendMessage('{0}: No row selected.'.format(self.ScriptName), 33)
return
x = str(self.DataGrid.Rows[row].Cells[1].Value)
y = str(self.DataGrid.Rows[row].Cells[2].Value)
Misc.SendToClient('--addmarker %s %s' % (x, y))
def btnMovePressed(self, sender, args):
row = self.DataGrid.SelectedCells[0].RowIndex
if row == -1:
Misc.SendMessage('{0}: No row selected.'.format(self.ScriptName), 33)
return
col = self.DataGrid.SelectedCells[3].ColumnIndex
sector = self.DataGrid.Rows[row].Cells[col].Value
Misc.SendMessage('{0}: Select the bag in which to put the sos.'.format(self.ScriptName), 67)
bag = Target.PromptTarget()
if bag == -1:
Misc.SendMessage('{0}: No bag selected.'.format(self.ScriptName), 33)
Misc.SendMessage('{0}: Please wait until the process is complete.'.format(self.ScriptName), 67)
self.MoveAll(sector, bag)
def btnRemovePressed(self, sender, args):
row = self.DataGrid.SelectedCells[0].RowIndex
if row == -1:
Misc.SendMessage('{0}: No row selected.'.format(self.ScriptName), 33)
return
col = self.DataGrid.SelectedCells[0].ColumnIndex
serial = self.DataGrid.Rows[row].Cells[col].Value
self.DeleteRow(serial)
def btnReloadPressed(self, sender, args):
self.MapCatalogue()
self.Controls.Remove(self.DataGrid)
self.DataGridSetup()
self.Controls.Add(self.DataGrid)
def init_btn(self, x, y, text, handler):
btn = Button()
btn.Text = text
btn.BackColor = Color.FromArgb(50,50,50)
btn.Location = self.btn_pos(x, y)
btn.Size = Size(60, 30)
btn.FlatStyle = FlatStyle.Flat
btn.FlatAppearance.BorderSize = 1
btn.Click += handler
return btn
def MoveAll(self, sector, bag):
rows = []
for r in xrange(self.DataGrid.DataSource.Rows.Count):
row = self.DataGrid.DataSource.Rows[r]
if row['Sector'] == sector:
Items.Move(int(row['ID'], 0), bag, 0)
rows.append(row)
Misc.Pause(600)
for r in rows:
self.DataGrid.DataSource.Rows.Remove(r)
Misc.SendMessage('{0}: Moving process complete.'.format(self.ScriptName), 67)
def DeleteRow(self, serial):
for r in xrange(self.DataGrid.DataSource.Rows.Count):
row = self.DataGrid.DataSource.Rows[r]
if row['ID'] == serial:
self.DataGrid.DataSource.Rows.Remove(row)
return
def getPointsDistance(self, x, y):
_x = abs(Player.Position.X - x) ** 2
_y = abs(Player.Position.Y - y) ** 2
if _x == 0 and _y == 0:
return 0
return int(math.sqrt(_x + _y))
def Data(self):
data = DataTable()
data.Columns.Add('ID', clr.GetClrType(str))
data.Columns.Add('X', clr.GetClrType(int))
data.Columns.Add('Y', clr.GetClrType(int))
data.Columns.Add('Sector', clr.GetClrType(str))
for sos in self.SOS:
sector = self.GetSector(sos.x, sos.y)
data.Rows.Add(hex(sos.serial), sos.x, sos.y, sector)
Misc.SendMessage('{0}: SOS Data has been loaded.'.format(self.ScriptName), 67)
return data
def MapCatalogue(self):
self.SOS = []
sosbag = Items.FindBySerial(self.SOSBag)
Items.WaitForContents(sosbag, 8000)
Misc.Pause(500)
for i in sosbag.Contains:
if i.ItemID == 0x14EE:
Gumps.ResetGump()
Items.UseItem(i)
Gumps.WaitForGump(1426736667, 3000)
if Gumps.CurrentGump() != 1426736667 or Gumps.LastGumpGetLineList().Count < 3:
Misc.SendMessage('{0}: Gump error. Retry once.'.format(self.ScriptName), 33)
if self.LoadRetry(i):
Misc.SendMessage('{0}: Gump error. Skipped.'.format(self.ScriptName), 33)
continue
line = Gumps.LastGumpGetLine(2)
degrees = line.replace('°', '|').replace('\'', "|").replace(',', '|').split('|')
lat = int(degrees[0]) + int(degrees[1]) * .01
lon = int(degrees[3]) + int(degrees[4]) * .01
dir1 = degrees[2]
dir2 = degrees[5]
x, y = self.MapXY(lat, lon, dir1, dir2)
dist = self.getPointsDistance(x, y)
self.SOS.append(SOS(i.Serial, x, y, dist))
Gumps.SendAction(1426736667, 0)
Misc.Pause(500)
self.SOS.sort(key=lambda x: x.distance)
def LoadRetry(self, sos):
Misc.Pause(500)
Gumps.ResetGump()
Items.UseItem(sos)
Gumps.WaitForGump(1426736667, 3000)
if Gumps.CurrentGump() != 1426736667 or Gumps.LastGumpGetLineList().Count < 3:
return True
return False
def MapXY(self, lat, lon, dir1, dir2):
if dir1 == 'S':
y = math.floor(lat) * 60. + lat % 1. * 100.
else:
y = -1.0 * math.ceil(lat) * 60. + lat % 1. * 100.
y = int(y / 21600. * 4096.) + 1624
if y < 0:
y += 4096
if y >= 4096:
y -= 4096
if dir2 == 'E':
x = math.floor(lon) * 60. + lon % 1. * 100.
else:
x = -1.0 * math.ceil(lon) * 60. + lon % 1. * 100.
x = int(x / 21600. * 5120.) + 1323
if x < 0:
x += 5120
if x >= 5120:
x -= 5120
return x, y
def GetSector(self, x, y):
if x < 1385 and 0 <= y < 1280:
return 'Yew'
elif x < 1000 and 1280 <= y < 2027:
return 'Shame'
elif x < 1000 and 2036 <= y < 2450:
return 'Skara'
elif x < 1300 and 2450 <= y < 3200:
return 'Destard'
elif x < 1900 and 3200 <= y <= 4096:
return 'Jhelom'
elif 1385 <= x < 2690 and y < 900:
return 'Wrong'
elif 1385 <= x < 2100 and 1280 <= y < 2030:
return 'Britain'
elif 2100 <= x < 2690 and 1280 <= y < 2030:
return 'Cove'
elif 1385 <= x < 2690 and 2030 <= y < 3075:
return 'Trinsic'
elif 1900 <= x < 2690 and 3075 <= y <= 4096:
return 'Valor'
elif 2580 <= x < 3250 and y < 1890:
return 'Vesper'
elif 3250 <= x < 4100 and y < 1890:
return "Nujel'm"
elif 2100 <= x < 3850 and 1890 <= y < 3075:
return 'Bucca'
elif 2690 <= x < 3850 and 3075 <= y <= 4096:
return 'Fire'
elif x >= 4100 and y < 1890:
return 'Moonglow'
elif x >= 3850 and 1890 <= y < 2890:
return 'Sea Market'
elif x >= 3850 and y >= 2890:
return 'Hythloth'
else:
return 'None'
Misc.SendMessage('Select the SOS container.', 67)
sbag = Target.PromptTarget()
if sbag > -1:
SH = SOSManager(sbag)
Application.Run(SH)