Advertisement
matsamilla

Untitled

Dec 3rd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.20 KB | None | 0 0
  1. #===============================================#
  2. # SOS Manager #
  3. #===============================================#
  4. # #
  5. # Author: CookieLover #
  6. # Latest Release: 10/07/2017 #
  7. # #
  8. #===============================================#
  9. # #
  10. # Info: #
  11. # - by selecting a SOS and hitting Move #
  12. # all the SOS in that sector will be moved #
  13. # in the targeted container #
  14. # #
  15. # What you need: #
  16. # - a bag full of SOS #
  17. # #
  18. # Credits: #
  19. # the degrees - coordinates formula is taken #
  20. # from Enhanced Map #
  21. # #
  22. #===============================================#
  23.  
  24.  
  25.  
  26.  
  27. import clr, math
  28.  
  29. clr.AddReference('System')
  30. clr.AddReference('System.Drawing')
  31. clr.AddReference('System.Windows.Forms')
  32. clr.AddReference('System.Data')
  33.  
  34. import System
  35. from System.Collections.Generic import List
  36. from System.Drawing import Point, Color, Size
  37. from System.Windows.Forms import (Application, Button, Form, BorderStyle,
  38. Label, FlatStyle, DataGridView, DataGridViewAutoSizeColumnsMode,
  39. DataGridViewSelectionMode, DataGridViewEditMode, CheckBox)
  40. from System.Data import DataTable
  41.  
  42.  
  43. class SOS(object):
  44. x = y = 0
  45. serial = 0
  46. def __init__(self, _serial, _x, _y):
  47.  
  48. self.serial = _serial
  49. self.x = _x
  50. self.y = _y
  51.  
  52. class SOSManager(Form):
  53. CurVer = '1.0.1'
  54. ScriptName = 'SOS Manager'
  55.  
  56. SOSBag = None
  57. SOS = []
  58.  
  59. def __init__(self, bag):
  60. self.SOSBag = bag
  61. self.MapCatalogue()
  62.  
  63. self.BackColor = Color.FromArgb(25,25,25)
  64. self.ForeColor = Color.FromArgb(231,231,231)
  65. self.Size = Size(300, 404)
  66. self.Text = '{0} - v{1}'.format(self.ScriptName, self.CurVer)
  67.  
  68. self.DataGridSetup()
  69.  
  70. self.btnRemove = Button()
  71. self.btnRemove.Text = 'Remove'
  72. self.btnRemove.BackColor = Color.FromArgb(50,50,50)
  73. self.btnRemove.Location = Point(180, 328)
  74. self.btnRemove.Size = Size(60, 30)
  75. self.btnRemove.FlatStyle = FlatStyle.Flat
  76. self.btnRemove.FlatAppearance.BorderSize = 1
  77. self.btnRemove.Click += self.btnRemovePressed
  78.  
  79. self.btnMove = Button()
  80. self.btnMove.Text = 'Move'
  81. self.btnMove.BackColor = Color.FromArgb(50,50,50)
  82. self.btnMove.Location = Point(110, 328)
  83. self.btnMove.Size = Size(60, 30)
  84. self.btnMove.FlatStyle = FlatStyle.Flat
  85. self.btnMove.FlatAppearance.BorderSize = 1
  86. self.btnMove.Click += self.btnMovePressed
  87.  
  88. self.btnOpen = Button()
  89. self.btnOpen.Text = 'Open'
  90. self.btnOpen.BackColor = Color.FromArgb(50,50,50)
  91. self.btnOpen.Location = Point(40, 328)
  92. self.btnOpen.Size = Size(60, 30)
  93. self.btnOpen.FlatStyle = FlatStyle.Flat
  94. self.btnOpen.FlatAppearance.BorderSize = 1
  95. self.btnOpen.Click += self.btnOpenPressed
  96.  
  97. self.Controls.Add(self.DataGrid)
  98. self.Controls.Add(self.btnOpen)
  99. self.Controls.Add(self.btnMove)
  100. self.Controls.Add(self.btnRemove)
  101.  
  102. def DataGridSetup(self):
  103. self.DataGrid = DataGridView()
  104. self.DataGrid.RowHeadersVisible = False
  105. self.DataGrid.MultiSelect = False
  106. self.DataGrid.SelectionMode = DataGridViewSelectionMode.FullRowSelect
  107. self.DataGrid.BackgroundColor = Color.FromArgb(25,25,25)
  108. self.DataGrid.RowsDefaultCellStyle.BackColor = Color.Silver
  109. self.DataGrid.AlternatingRowsDefaultCellStyle.BackColor = Color.Gainsboro
  110. self.DataGrid.ForeColor = Color.FromArgb(25,25,25)
  111. self.DataGrid.Location = Point(20, 12)
  112. self.DataGrid.Size = Size(240, 306)
  113. self.DataGrid.DataSource = self.Data()
  114. self.DataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
  115. self.DataGrid.EditMode = DataGridViewEditMode.EditProgrammatically
  116. self.DataGrid.BorderStyle = BorderStyle.None
  117.  
  118. def btnOpenPressed(self, sender, args):
  119. row = self.DataGrid.SelectedCells[0].RowIndex
  120.  
  121. if row == -1:
  122. Misc.SendMessage('{0}: No row selected.'.format(self.ScriptName), 33)
  123. return
  124.  
  125. col = self.DataGrid.SelectedCells[0].ColumnIndex
  126. serial = self.DataGrid.Rows[row].Cells[col].Value
  127.  
  128. Items.UseItem(int(serial, 0))
  129.  
  130. def btnMovePressed(self, sender, args):
  131. row = self.DataGrid.SelectedCells[0].RowIndex
  132.  
  133. if row == -1:
  134. Misc.SendMessage('{0}: No row selected.'.format(self.ScriptName), 33)
  135. return
  136.  
  137. col = self.DataGrid.SelectedCells[3].ColumnIndex
  138. sector = self.DataGrid.Rows[row].Cells[col].Value
  139. Misc.SendMessage('{0}: Select the bag in which to put the sos.'.format(self.ScriptName), 67)
  140. bag = Target.PromptTarget()
  141. if bag == -1:
  142. Misc.SendMessage('{0}: No bag selected.'.format(self.ScriptName), 33)
  143. Misc.SendMessage('{0}: Please wait until the process is complete.'.format(self.ScriptName), 67)
  144. self.MoveAll(sector, bag)
  145.  
  146.  
  147. def btnRemovePressed(self, sender, args):
  148. row = self.DataGrid.SelectedCells[0].RowIndex
  149.  
  150. if row == -1:
  151. Misc.SendMessage('{0}: No row selected.'.format(self.ScriptName), 33)
  152. return
  153.  
  154. col = self.DataGrid.SelectedCells[0].ColumnIndex
  155. serial = self.DataGrid.Rows[row].Cells[col].Value
  156.  
  157. self.DeleteRow(serial)
  158.  
  159. def MoveAll(self, sector, bag):
  160. rows = []
  161. for r in xrange(self.DataGrid.DataSource.Rows.Count):
  162. row = self.DataGrid.DataSource.Rows[r]
  163.  
  164. if row['Sector'] == sector:
  165. Items.Move(int(row['ID'], 0), bag, 0)
  166. rows.append(row)
  167. Misc.Pause(600)
  168.  
  169. for r in rows:
  170. self.DataGrid.DataSource.Rows.Remove(r)
  171.  
  172. Misc.SendMessage('{0}: Moving process complete.'.format(self.ScriptName), 67)
  173.  
  174. def DeleteRow(self, serial):
  175. for r in xrange(self.DataGrid.DataSource.Rows.Count):
  176. row = self.DataGrid.DataSource.Rows[r]
  177. if row['ID'] == serial:
  178. self.DataGrid.DataSource.Rows.Remove(row)
  179. return
  180.  
  181. def Data(self):
  182. data = DataTable()
  183. data.Columns.Add('ID', clr.GetClrType(str))
  184. data.Columns.Add('X', clr.GetClrType(int))
  185. data.Columns.Add('Y', clr.GetClrType(int))
  186. data.Columns.Add('Sector', clr.GetClrType(str))
  187.  
  188. for sos in self.SOS:
  189. sector = self.GetSector(sos.x, sos.y)
  190. data.Rows.Add(hex(sos.serial), sos.x, sos.y, sector)
  191. sosx = str(sos.x)
  192. sosy = str(sos.y)
  193.  
  194. Misc.SendMessage('{0}: SOS Data has been loaded.'.format(self.ScriptName), 67)
  195. return data
  196.  
  197. def MapCatalogue(self):
  198. sosbag = Items.FindBySerial(self.SOSBag)
  199. Items.WaitForContents(sosbag, 8000)
  200. Misc.Pause(600)
  201.  
  202. for i in sosbag.Contains:
  203. if i.ItemID == 0x14EE:
  204. Gumps.ResetGump()
  205. Items.UseItem(i)
  206. Gumps.WaitForGump(1426736667, 3000)
  207.  
  208. if Gumps.CurrentGump() != 1426736667 or Gumps.LastGumpGetLineList().Count < 3:
  209. Misc.SendMessage('{0}: Gump error. Retry once.'.format(self.ScriptName), 33)
  210.  
  211. if self.LoadRetry(i):
  212. Misc.SendMessage('{0}: Gump error. Skipped.'.format(self.ScriptName), 33)
  213. continue
  214.  
  215. line = Gumps.LastGumpGetLine(2)
  216. degrees = line.replace('°', '|').replace('\'', "|").replace(',', '|').split('|')
  217. lat = int(degrees[0]) + int(degrees[1]) * .01
  218. lon = int(degrees[3]) + int(degrees[4]) * .01
  219. dir1 = degrees[2]
  220. dir2 = degrees[5]
  221. x, y = self.MapXY(lat, lon, dir1, dir2)
  222.  
  223. self.SOS.append(SOS(i.Serial, x, y))
  224. Gumps.SendAction(1426736667, 0)
  225. Misc.Pause(600)
  226.  
  227. def LoadRetry(self, sos):
  228. Misc.Pause(600)
  229. Gumps.ResetGump()
  230. Items.UseItem(sos)
  231. Gumps.WaitForGump(1426736667, 3000)
  232.  
  233. if Gumps.CurrentGump() != 1426736667 or Gumps.LastGumpGetLineList().Count < 3:
  234. return True
  235.  
  236. return False
  237.  
  238. def MapXY(self, lat, lon, dir1, dir2):
  239. if dir1 == 'S':
  240. y = math.floor(lat) * 60. + lat % 1. * 100.
  241. else:
  242. y = -1.0 * math.ceil(lat) * 60. + lat % 1. * 100.
  243. y = int(y / 21600. * 4096.) + 1624
  244.  
  245. if y < 0:
  246. y += 4096
  247. if y >= 4096:
  248. y -= 4096
  249.  
  250. if dir2 == 'E':
  251. x = math.floor(lon) * 60. + lon % 1. * 100.
  252. else:
  253. x = -1.0 * math.ceil(lon) * 60. + lon % 1. * 100.
  254.  
  255. x = int(x / 21600. * 5120.) + 1323
  256.  
  257. if x < 0:
  258. x += 5120
  259. if x >= 5120:
  260. x -= 5120
  261.  
  262. return x, y
  263.  
  264. def GetSector(self, x, y):
  265. if x < 1385 and 0 <= y < 1280:
  266. return 'Yew'
  267. elif x < 1000 and 1280 <= y < 2027:
  268. return 'Shame'
  269. elif x < 1000 and 2036 <= y < 2450:
  270. return 'Skara'
  271. elif x < 1300 and 2450 <= y < 3200:
  272. return 'Destard'
  273. elif x < 1900 and 3200 <= y <= 4096:
  274. return 'Jhelom'
  275. elif 1385 <= x < 2690 and y < 900:
  276. return 'Wrong'
  277. elif 1385 <= x < 2100 and 1280 <= y < 2030:
  278. return 'Britain'
  279. elif 2100 <= x < 2690 and 1280 <= y < 2030:
  280. return 'Cove'
  281. elif 1385 <= x < 2690 and 2030 <= y < 3075:
  282. return 'Trinsic'
  283. elif 1900 <= x < 2690 and 3075 <= y <= 4096:
  284. return 'Valor'
  285. elif 2580 <= x < 3250 and y < 1890:
  286. return 'Vesper'
  287. elif 3250 <= x < 4100 and y < 1890:
  288. return "Nujel'm"
  289. elif 2100 <= x < 3850 and 1890 <= y < 3075:
  290. return 'Bucca'
  291. elif 2690 <= x < 3850 and 3075 <= y <= 4096:
  292. return 'Fire'
  293. elif x >= 4100 and y < 1890:
  294. return 'Moonglow'
  295. elif x >= 3850 and 1890 <= y < 2890:
  296. return 'Sea Market'
  297. elif x >= 3850 and y >= 2890:
  298. return 'Hythloth'
  299. else:
  300. return 'None'
  301.  
  302. Misc.SendMessage('Select the SOS container.', 67)
  303. sbag = Target.PromptTarget()
  304. if sbag > -1:
  305. SH = SOSManager(sbag)
  306. Application.Run(SH)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement