📜 ⬆️ ⬇️

Browser robot on Sikuli IDE for the game MusicWars

pumping toy

Background:

Somehow before me was the task: “I want to pump a character, but because of the work I don’t have enough time”. Craz decided: "I am an engineer, now we will solve the problem."
Music Wars is a new browser-based MMORPG where you have to defend your musical preferences in a tough battle. Bright graphics, non-standard combat system will attract not only avid music lovers, but all fans of computer games.

After studying the MusicWars toy, it turned out that it, like many browser games, was made in Flash, which does not give the full possibility of manipulation. There is a way out, using scripts is focused on GUI programming. I decided to use sikuli thanks to the article “More about Sikuli in test automation” from Gulsom .

The advantage of such writing is visual objects without any programming wisdom. Anyone who knows more or less ideas about programming can cope with such writing. All writing with debugging took a couple of ches!

Character on pumping:


The logic itself is to search for the enemy from 2 windows. I choose a lower level and a smaller force and attack if there is no such thing, then we exit and reload the opponents, and so on in a circle.
')
The logic of choosing the enemy

I used the Region for more speed in finding the elements because The game took only half the screen.

The logic of choosing the enemy
def left_open_doi(): #  region_left = Region(561,414,386,387) if region_left.exists("aIE.png"): #   if region_left.exists("HAI1ACIh2g.png"): region_left.hover("Cmna.png") if region_left.exists("1404561848539.png"): right_open_boi() else: region_left.click("HAI1ACIh2g.png") if Region(177,250,779,551).exists("1404562400404.png"): Region(177,250,779,551).click("1404562484299.png") sleep(0.23) new_okno_boi() else: if Region(161,175,795,633).exists("Heqocrarouuo.png"): Region(161,175,795,633).click("1404562484299.png") else_none_boi() else: if Region(163,171,797,636).exists("HEAOCTBTOHH0.png"): sleep(100) new_okno_boi() else: sleep(30) close_boi() else: right_open_boi() else: right_open_boi() def right_open_boi(): region_right = Region(175,418,388,381) if region_right.exists("aIE-1.png"): if region_right.exists("HAI1ACIh2g.png"): region_right.hover("Cmna.png") if Region(447,499,96,22).exists("1404561848539.png"): new_okno_boi() else: region_right.click("HAI1ACIh2g.png") if Region(177,250,779,551).exists("1404562400404.png"): Region(177,250,779,551).click("1404562484299.png") sleep(0.23) new_okno_boi() else: if Region(161,175,795,633).exists("Heqocrarouuo.png"): Region(161,175,795,633).click("1404562484299.png") else_none_boi() else: if Region(163,171,797,636).exists("HEAOCTBTOHH0.png"): sleep(100) new_okno_boi() else: sleep(30) close_boi() else: new_okno_boi() else: new_okno_boi() start() 


Close after attack
 def close_boi(): #    if Region(240,250,652,320).exists("QBuxcn.png"): Region(240,250,652,320).click("QBuxcn.png") new_okno_boi() else: click(Location(555,484)) Region(237,253,652,311).click("1404559699899.png") if Region(183,266,767,547).exists("Floanpanrmen.png"): Region(183,266,767,547).click("1404562484299.png") Region(240,250,652,320).click("QBuxcn.png") new_okno_boi() else: sleep(0) Region(183,266,767,547).click("QBuxcn.png") sleep(10) new_okno_boi() #      


Change the window if there are no suitable opponents
 def new_okno_boi(): Region(411,279,155,100).click("1404557642674.png") if Region(177,306,378,486).exists("BUKBAJI.png"): Region(195,412,201,102).click("BUKBAJI.png") sleep(0.10) Region(736,627,220,179).hover("1404582245445.png") sleep(2) Region(192,316,740,474).click(Pattern("1404559393979.png").targetOffset(-55,20)) if Region(181,253,142,41).exists("BVITBA.png"): left_open_doi() else: sleep(0.10) Region(192,316,740,474).click(Pattern("1404559393979.png").targetOffset(-55,20)) Region(175,306,770,489).click("1404547957758.png") left_open_doi() else: if Region(216,326,149,128).exists("DBOPbI.png"): Region(188,310,190,151).click("DBOPbI-1.png") Region(736,627,220,179).hover("1404582245445.png") sleep(2) Region(192,316,740,474).click(Pattern("1404559393979.png").targetOffset(-55,20)) if Region(181,253,142,41).exists("BVITBA.png"): left_open_doi() else: sleep(0.10) Region(192,316,740,474).click(Pattern("1404559393979.png").targetOffset(-55,20)) Region(175,306,770,489).click("1404547957758.png") left_open_doi() else: if Region(376,313,125,121).exists("KOCTEFI.png"): Region(373,313,127,108).click("KOCTEFI-1.png") Region(736,627,220,179).hover("1404582245445.png") sleep(2) Region(192,316,740,474).click(Pattern("1404559393979.png").targetOffset(-55,20)) if Region(181,253,142,41).exists("BVITBA.png"): left_open_doi() else: sleep(0.10) Region(192,316,740,474).click(Pattern("1404559393979.png").targetOffset(-55,20)) Region(175,306,770,489).click("1404547957758.png") left_open_doi() 


The script in the Sikuli IDE editor will be ironed like this:

Script in the editor Sikuli IDE

Link to repository .

The following articles were inspired to write such a script:


Learn more about Sikuli in Gulsom testing automation
A special case of using Sikuli to solve a problem in Facebook Xtragalattico

Source: https://habr.com/ru/post/230705/


All Articles