Advertisement
Guest User

JA2 inventory drop

a guest
Jun 21st, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. F8::
  2. Dropping: ; Скинуть 12 вещей из рюкзака наемника на землю
  3. If not Wincheck() {
  4.     Return
  5. }
  6.  
  7. Gosub, ScrollPanes ;прокрутить инвентарь в поисках свободного места
  8. FreeCells := FindFreeCells() ;получить массив свободных ячееек
  9.  
  10. ; бросаем
  11. MouseGetPos, OutputVarX, OutputVarY
  12. Xbox := (OutputVarX - 274)//72
  13. Ybox := (OutputVarY - 36)//32
  14. ;MsgBox, %Xbox%, %Ybox%
  15.  
  16. Xpoz := 32-38
  17. Ypoz := 262-24
  18. ArrayCount = 0
  19. ; FreeCells := Object()
  20. Loop, 3
  21. {
  22.     Xpoz += 38
  23.     Loop, 4
  24.     {
  25.         Ypoz += 24
  26.         ; если ячейка не пустая
  27.         If ColorCheck(Xpoz-15,Ypoz+10)
  28.         {
  29.             ArrayCount += 1
  30.             ; MsgBox % "ArrayCount = " . ArrayCount . ", FreeCells.Count = " . FreeCells.Count . ", сумма = " . ArrayCount + FreeCells.Count
  31.             ; exit
  32.             If ArrayCount+0 > FreeCells.Count+0
  33.             {
  34.                 ; MsgBox % "ArrayCount = " . ArrayCount . ", FreeCells.Count = " . FreeCells.Count
  35.                 ; exit
  36.                 SendPlay {Click 562, 343} ; клик на кнопке прокрутки - к следующей панели
  37.                 FreeCells := FindFreeCells() ;получить массив свободных ячееек
  38.                 ArrayCount = 1
  39.             }
  40.             ; хватаем
  41.             SendPlay {ShiftDown}
  42.             SendPlay {Click %Xpoz%, %Ypoz%}
  43.             SendPlay {ShiftUp}
  44.             Sleep 50
  45.             ; бросаем
  46.             ; x1 := 274+Xbox*72+36
  47.             ; y1 := 36+Ybox*32+16
  48.             x1 := 276 + (FreeCells[ArrayCount].X - 1) * 72 + 36
  49.             y1 := 58 + (FreeCells[ArrayCount].Y - 1) * 32 - 16
  50.             ; MsgBox %y1%
  51.             ; exit
  52.             SendPlay {Click %X1%, %Y1%}
  53.             ; MsgBox, x1 = %X1%, y1 = %Y1%
  54.             Sleep 50
  55.             ; Ybox++
  56.             ; If Ybox>8 {
  57.             ;   Ybox := 0
  58.             ;   Xbox++
  59.             ; }
  60.             ; If Xbox>4 {
  61.             ;   Return
  62.             ; }
  63.         }
  64.     }
  65.     Ypoz := 262-24
  66. }
  67. Return
  68.  
  69. ; проверка названия активного окна
  70. Wincheck() {
  71.     WinGetTitle, Title, A
  72.     ;MsgBox, Сейчас активно окно "%Title%"
  73.     If Title = Jagged Alliance 2
  74.     {
  75.         ;MsgBox, Название совпало
  76.         Return True
  77.     }
  78. }
  79.  
  80. ; проверка цвета нижнего пикселя лайфбара ячейки - есть ли в ней предмет.
  81. ColorCheck(X,Y) {
  82.     PixelGetColor, color, X, Y, Slow ;BGR
  83.     Blue:="0x" SubStr(color,3,2) ;substr is to get the piece
  84.     Blue:=Blue+0 ;add 0 is to convert it to the current number format
  85.     If Blue > 80
  86.     {
  87.         Return True
  88.     }
  89. }
  90.  
  91. ;прокрутить инвентарь в поисках свободного места
  92. ScrollPanes:
  93.     PixelGetColor, color, 564, 314, Slow ;проверка крайней ячейки
  94.     Blue:="0x" SubStr(color,3,2) ;substr is to get the piece
  95.     Blue:=Blue+0 ;add 0 is to convert it to the current number format
  96.     If Blue > 80
  97.     {
  98.         SendPlay {Click 562, 343} ; клик на кнопке прокрутки - к следующей панели
  99.         Gosub, ScrollPanes ;выполнить следующую проверку
  100.     }
  101. Return
  102.  
  103. ;поиск свободных ячеек
  104. FindFreeCells() {
  105.     FreeCells := Object()
  106.     FreeCellsCount := 0
  107.     X0 := 276
  108.     Y0 := 58
  109.     Loop, 5 {
  110.         X1 := A_Index
  111.         Xpos := X0 + (A_Index - 1) * 72
  112.         Loop, 9 {
  113.             Y1 := A_Index
  114.             Ypos := Y0 + (A_Index - 1) * 32
  115.             If Not ColorCheck(Xpos,Ypos) {
  116.                 FreeCellsCount += 1
  117.                 FreeCells[FreeCellsCount] := {X: X1, Y: Y1} ; ассоциативный массив
  118.             }
  119.         }
  120.     }
  121. FreeCells.Count := FreeCellsCount
  122. ; MsgBox % "X = " . FreeCells[1].X . ", Y = " . FreeCells[1].Y . ", FreeCellsCount = " . FreeCellsCount . ", FreeCells.Count = " . FreeCells.Count
  123. ; Exit
  124. Return FreeCells
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement