Jump to content

My MTGO Bot (work in progress)


Recommended Posts

Im working on a magic online bot, and this is what i have so far. right now im at a stand still because my OCR program suddenly stopped working. I was using freeOCR, and for some reason, whenever i try to use it (even on a file that ive ocr'd before and got a result out of) it returns NOTHING... at all. Meh...I was unhappy with it anyways. It took too long to go through a collection of cards and I need something faster to set it up to buy cards rather then just sell them. I was hoping to get a simple sell bot up and running, but i cant now because i have no ocr program. I tried tesseract, but i cant for the life of me figure out how to use it. If i could figure out how to install it, and if i figured out how to use the tesseract.au3 i found on these forums, i might be able to speed it up a little. looking around, it looks like what i need is an ocr program that i can use on the command line. Im not even sure how the command line works...im learning as i go here.

Any help or comments would be appricated.

#include <ScreenCapture.au3>
#Include <File.au3>


WinActivate("Magic Online", "")
$ChecksumMenuClick = PixelChecksum(75, 625, 210, 710)
$ChecksumCommunityClick = PixelChecksum(220, 625, 350, 685)
$ChecksumMarketplaceClick = PixelChecksum(360, 625, 490, 640)
$ChecksumWhatScreen = PixelChecksum(54, 9, 175, 18)
$ChecksumOCRDone = PixelChecksum(670, 350, 815, 370)
$ChecksumBuySellDone = PixelChecksum(835, 55, 1000 ,550)
$ChecksumGetGiveNumber = PixelChecksum(69, 552, 85, 561)


;wait for a change in what room im in
Func WaitFOCRhange()
    While $ChecksumWhatScreen = PixelChecksum(54, 9, 175, 18)
        Sleep(100)
    WEnd
    Call ("WhatScreen")
EndFunc


;capture image of top left corner (shows what screen im in)
Func WhatScreen()
    ;Capture image
    _ScreenCapture_Capture(@DesktopDir & "\test images 2\WhatScreen.jpg", 54, 9, 175, 18)
    ;activate my Optical character recognition program
    WinActivate("FreeOCR V3 Free OCR Software", "")
    Sleep(100)
    MouseClick("left", 400, 300, 1)
    Sleep(100)
    Send("WhatScreen.jpg{enter}")
    Sleep(100)
    MouseClick("left", 530, 300, 1)
    ;wait for ocr to finish
    While $ChecksumOCRDone = PixelChecksum(670, 350, 815, 370)
        Sleep(100)
    Wend
    ;get ocr result
    Send("{Down}{Down}{bs}{bs}")
    MouseClick("left", 645, 440, 1)
    MouseClick("left", 645, 360, 1)
    WinActivate("Magic Online", "")
    $WhatScreen = ClipGet()
    ;compare ocr result to top left corner
    If $WhatScreen = "CARD Trade" Then
        Call ("Trade")
    ElseIf $WhatScreen = "HDME" Then
        Call("JoinClassifieds")
    ElseIf $WhatScreen = "CDMMUNITY Classifieds" Then
        Call("EnterAd")
    EndIf
EndFunc



;Join the room to post that im selling cards
Func JoinClassifieds()
    ;click menu
    MouseClick("left", 100, 725, 1)
    While $ChecksumMenuClick = PixelChecksum(75, 625, 210, 710)
        Sleep(100)
    WEnd
    ;click community
    MouseClick("left", 100, 630, 1)
    While $ChecksumCommunityClick = PixelChecksum(220, 625, 350, 685)
        Sleep(100)
    WEnd
    ;click marketplace
    MouseClick("left", 260, 630, 1)
    While $ChecksumMarketplaceClick = PixelChecksum(360, 625, 490, 640)
        Sleep(100)
    WEnd
    ;click classifieds
    MouseClick("left", 400, 630, 1)
    While $ChecksumWhatScreen = PixelChecksum(54, 9, 175, 18)
        Sleep(100)
    WEnd
EndFunc



;Enter an ad in the classifieds saying that im selling cards
Func EnterAd()
    ;check to see if i already have an ad posted
    MouseClick("left", 500, 450, 1)
    MouseClick("left", 400, 15, 1)
    Send("blackmage999")
    $IsAdBoxHidden = PixelGetColor( 130 , 40 )
    if $IsAdBoxHidden <> 0x000000 then
        MouseClick("left", 750, 40, 1)
    EndIf
    $IsAdUp = PixelSearch( 40, 125, 125, 140, 0x000000 )
    If @error Then
        ;click edit posting and set my ad
        MouseClick("left", 730, 40, 2)
        Send("Selling Any 160 cards for 1")
        ;click submit
        MouseClick("left", 400, 50, 1)
        While $ChecksumWhatScreen = PixelChecksum(54, 9, 175, 18)
            Sleep(100)
        WEnd
    Else
        Call ("WaitFOCRhange")
    EndIf
EndFunc



;trade function (work in progress
Func Trade()
    
;dock chat window
$FindDock = PixelSearch( 766, 36, 994, 568, 0xFEFEFE )
If Not @error Then
    MouseClick("left", $FindDock[0], $FindDock[1], 1)
Else
    $coord = PixelSearch( 766, 0, 994, 38, 0xFEFEFE )
    If Not @error Then
    MouseClick("left", $FindDock[0], $FindDock[1], 1)   
    EndIf
EndIf

;get player name
MouseClick("left", 880, 615, 1)
Send("^c")
$PlayerName = ClipGet()

;open credit file or create new
$PlayerCreditFile = FileOpen(@DesktopDir & "\PlayerCredits\" & $PlayerName & ".txt", 8)

;get player credits from .txt file
$PlayerCredit = FileRead($PlayerCreditFile)
If $PlayerCredit = "" Then
    $PlayerCredit = 0
EndIf
FileClose($PlayerCreditFile)

;enter in chat that im selling 160 cards for 1 ticket
MouseClick("left", 900, 560, 1)
Send("Preping chat. Please wait.{enter}...{enter}...{enter}...{enter}...{enter}...{enter}")
Send("...{enter}...{enter}...{enter}...{enter}...{enter}...{enter}...{enter}...{enter}")
Send("Hello " & $PlayerName & ". I am selling 160 cards for 1. You have " & $PlayerCredit & " credits.{enter}")
$PlayerCardsTaken = $PlayerCredit * 160
$PlayerCardsLeft = 160 - $PlayerCardsTaken
Send("You have taken " & $PlayerCardsTaken & " cards. Please take " & $PlayerCardsLeft & "more. Type done when you're ready.{enter}")

;check what the player has typed
While $ChecksumBuySellDone = PixelChecksum(835, 55, 1000, 550)
  Sleep(100)
WEnd
MouseClick("left", 900, 535, 1)
Send("^c")
$PlayerMessage = ClipGet()
$PlayerMessage = StringLower($PlayerMessage)
$BuySellorDone = StringRight($PlayerMessage, 4)

;decide what to do based on ClipGet
If $BuySellorDone = "sell" Then
    MouseClick("left", 900, 560, 1)
    Send("I do not buy cards at the moment. This bot is still a work in progress.")
ElseIf $BuySellorDone = " buy" Then
    MouseClick("left", 900, 560, 1)
    Send("Take the cards you want and type done when your ready.")
ElseIf $BuySellorDone = "done" Then
    
    ;check to see if i need to take a ticket or not
    If $PlayerCredit = 0 Or $PlayerCredit > 1 Then
        $TakeTicket = True
    Else 
        $TakeTicket = False
    EndIf
    
    ;take ticket
    If $TakeTicket = true then
        
        ;search for "event ticket"
        MouseClick("left", 140, 40, 1)
        Send("event ticket")
        Sleep(100)
        MouseClick("left", 600, 118, 1)
        
        ;check to see if the item i clicked is a ticket
        _ScreenCapture_Capture(@DesktopDir & "\test images\Event Ticket.jpg", 17, 111, 175, 125)
        WinActivate("FreeOCR V3 Free OCR Software", "")
        Sleep(100)
        MouseClick("left", 400, 300, 1)
        Sleep(100)
        Send("Event Ticket.jpg{enter}")
        Sleep(100)
        MouseClick("left", 530, 300, 1)
        While $ChecksumOCRDone = PixelChecksum(670, 350, 815, 370)
            Sleep(100)
        Wend
        Sleep(100)
        Send("{Down}{Down}{bs}{bs}")
        Sleep(100)
        MouseClick("left", 645, 440, 1)
        MouseClick("left", 645, 360, 1)
        $WhatCard = ClipGet()
        if $WhatCard = "Event Ticket" Then
            WinActivate("Magic Online", "")
            
            ;dbl click the ticket to take it
            MouseClick("left", 50, 120, 2)
        EndIf
    Send("Please hit comfirm and I will check your cards.")
    
    ;click confirm
    MouseClick("left", 340, 70, 1)
    While $ConfirmCheck = PixelChecksum(835, 55, 1000, 550)
        Sleep(100)
    WEnd
    
    ;check the number of cards the player has taken
    _ScreenCapture_Capture(@DesktopDir & "\BotData\OCR\PlayerGetNumberTaken.jpg", 69, 552, 85, 561)
    WinActivate("FreeOCR V3 Free OCR Software", "")
    Sleep(100)
    MouseClick("left", 400, 300, 1)
    Sleep(100)
    Send("PlayerGetNumberTaken.jpg{enter}")
    Sleep(100)
    MouseClick("left", 530, 300, 1)
    While $ChecksumWhatScreen = PixelChecksum(54, 9, 175, 18)
        Sleep(100)
    WEnd
    Sleep(100)
    Send("{Down}{Down}{bs}{bs}")
    Sleep(100)
    MouseClick("left", 645, 440, 1)
    MouseClick("left", 645, 360, 1) 
    $OCRResult = FileOpen(@DesktopDir & "\BotData\GiveGetNumbers\" & $OCRPlayerNumberCards & ".txt", 0)
    $PlayerNumberCards = FileRead($OCRPlayerNumberCards)
    FileClose($OCRResult)
    ;;; I need to put a checksum here to see if the trade window is closed, then check to 
    ;;; see if my ticket number has changed (need to write a check before trade also)
    
    ;write to the players credit file (not finished)
    $PlayerCreditThisSession = $PlayerNumberCards * .00625
    
EndFunc
Link to comment
Share on other sites

  • Moderators

blackmage999,

You obviously missed this on the way in. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...