Skip to content

Instantly share code, notes, and snippets.

/k

Created April 15, 2015 09:08
Show Gist options
  • Save anonymous/738b480c718cac880b2b to your computer and use it in GitHub Desktop.
Save anonymous/738b480c718cac880b2b to your computer and use it in GitHub Desktop.
k
#!/usr/bin/env python3
# coding: utf-8
import os
import time
import sys
import platform
origin_point = (95, 155)
class Mouse(object):
def __init__(self, x=0, y=0):
self.origin_point = (x, y)
def set_origin_point(self, x, y):
self.origin_point = (x, y)
class WinMouse(Mouse):
def __init__(self):
import ctypes
## from ctypes.windll import user32
self.user32 = ctypes.windll.user32
def click(self, x=None, y=None):
if x is not None and y is not None:
self.move(x, y)
## self.user32.SetCursorPos(x + self.origin_point[0], y + self.origin_point[1])
self.user32.mouse_event(0x2, 0, 0, 0, 0)
self.user32.mouse_event(0x4, 0, 0, 0, 0)
def move(self, x, y):
x_re = x + self.origin_point[0]
y_re = y + self.origin_point[1]
self.user32.SetCursorPos(x_re, y_re)
class MacMouse(Mouse):
def __init__(self):
pass
def click(self, x=None, y=None):
if x is not None and y is not None:
self.move(self, x, y)
pass
def move(self, x, y):
x_re = x + origin_point[0]
y_re = y + origin_point[1]
pass
class LinuxMouse(Mouse):
def __init__(self):
pass
def click(self, x=None, y=None):
if x is not None and y is not None:
self.move(x, y)
os.system("xte 'mouseclick 1'")
def move(self, x, y):
x_re = x + origin_point[0]
y_re = y + origin_point[1]
os.system("xte 'mousemove {} {}'".format(x_re, y_re))
if platform.system() == 'Windows':
mouse = WinMouse()
elif platform.system() == 'Darwin':
mouse = MacMouse()
elif platform.system() == 'Linux':
mouse = LinuxMouse()
else:
print('platform.system Error')
# ### POINT DEFINE #######
dummy = (0, 0)
bokou = (45, 45)
bokou_hokyu = (75, 215)
bokou_hisho = (600, 350)
bokou_shutsugeki = (205, 250)
hokyu_1stDeck = (145, 115)
hokyu_2ndDeck = (175, 115)
hokyu_3rdDeck = (205, 115)
hokyu_4thDeck = (235, 115)
hokyu_Deck = [dummy, hokyu_1stDeck, hokyu_2ndDeck, hokyu_3rdDeck, hokyu_4thDeck]
hokyu_check = (115, 120)
hokyu_button = (705, 435)
shutsugeki_ensei = (660, 230)
ensei_renshu = (400, 165)
ensei_tyokyori = (400, 195)
ensei_keibi = (400, 225)
ensei_taisen = (400, 255)
ensei_kaijou = (400, 285)
ensei_boukuu = (400, 315)
ensei_id = [dummy, ensei_renshu, ensei_tyokyori, ensei_keibi, ensei_taisen, ensei_kaijou, ensei_boukuu]
ensei_kettei = (675, 445)
ensei_kaishi = (675, 445)
ensei_1stDeck = (365, 115) # no use in Ensei
ensei_2ndDeck = (395, 115)
ensei_3rdDeck = (425, 115)
ensei_4thDeck = (455, 115)
ensei_Deck = [dummy, ensei_1stDeck, ensei_2ndDeck, ensei_3rdDeck, ensei_4thDeck]
ensei_1stArea = (130, 440)
ensei_2ndArea = (190, 440)
ensei_3rdArea = (250, 440)
ensei_4thArea = (310, 440)
ensei_5thArea = (370, 440)
ensei_Area = [dummy, ensei_1stArea, ensei_2ndArea, ensei_3rdArea, ensei_4thArea, ensei_5thArea]
# ######### / POINT DEFINE ##############
def print_flush(string):
print(string, end='')
sys.stdout.flush()
def int_2_min_sec(num):
return (num // 60, num % 60)
def wait_min(num):
print_flush('{} minutes waiting start.'.format(num))
for i in range(60 * num, 0, -1):
print_flush('\rwait {} min {} sec. '.format(*int_2_min_sec(i)))
time.sleep(1)
print_flush('\n\n')
def click():
time.sleep(1)
mouse.click()
# os.system("xte 'mouseclick 1'")
time.sleep(1)
# pass
# def move_abs(x, y):
# os.system("xte 'mousemove {x} {y}'".format(x=x, y=y))
# def move_re(x, y):
# os.system("xte 'mousermove {x} {y}'".fomat(x=x, y=y))
def move_point(tpl):
mouse.move(x=tpl[0], y=tpl[1])
# os.system("xte 'mousemove {x} {y}'".format(x=tpl[0], y=tpl[1]))
def click_point(tpl):
move_point(tpl)
click()
def reload_():
click_point(bokou_hokyu)
click_point(bokou)
def hishoclick(n):
for i in range(n):
## mouse.click(bokou_hisho[0], bokou_hisho[1])
click_point(bokou_hisho)
time.sleep(1.7)
def hokyu(deck_id):
click_point(bokou_hokyu)
click_point(hokyu_Deck[deck_id])
click_point(hokyu_check)
click_point(hokyu_button)
click_point(bokou)
def ensei(deck_id, quest_id):
''' quest_id
1:練習航海, 2:長距離, 3:警備任務, 4:対潜, 5:海上護衛, 6:防空
'''
click_point(bokou_shutsugeki)
click_point(shutsugeki_ensei)
click_point(ensei_id[quest_id])
click_point(ensei_kettei)
click_point(ensei_Deck[deck_id])
click_point(ensei_kaishi)
time.sleep(3)
click_point(bokou)
def a():
hokyu(deck_id=2)
ensei(deck_id=2, quest_id=2)
print_flush('2nd: tyokyori\n')
def b():
hokyu(deck_id=3)
ensei(deck_id=3, quest_id=5)
print_flush('3rd: kaijou\n')
def c():
hokyu(deck_id=4)
ensei(deck_id=4, quest_id=6)
print_flush('4th: boukuu\n')
def _main():
print_flush('**')
wait_min(4)
def main():
mouse.set_origin_point(-1841,115)
aa, bb, cc = 0, 0, 0
if len(sys.argv) == 4:
aa, bb, cc = list(map(int, sys.argv[1:]))
while 1:
## mouse.click(7, 7)
# os.system("xte 'mousemove 7 7'")
# os.system("xte 'mouseclick 1'")
h = (aa == 0) + (bb == 0) + (cc == 0)
if h > 0:
reload_()
hishoclick(5 * h)
if aa <= 0:
a()
aa = 3
if bb <= 0:
b()
bb = 9
if cc <= 0:
c()
cc = 4
print_flush('2nd: {}\n'.format(aa))
print_flush('3rd: {}\n'.format(bb))
print_flush('4th: {}\n'.format(cc))
wait_min(10)
aa -= 1
bb -= 1
cc -= 1
if __name__ == '__main__':
w_time = 0
print_flush('wait {} minutes.\n'.format(w_time))
time.sleep(w_time * 60)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment