def save(ctrl: Controller): ctrl.X() ctrl.pause(0.5) ctrl.R() ctrl.pause(1.5) ctrl.A() ctrl.pause(4)
from NXController import Controller ctr = Controller() ## Or use your serial port if you have many # ctr = Controller('/dev/tty.usbserial-AO0099VT'); ctr.A() ctr.B() ctr.X() ctr.Y() ctr.L() ctr.R() ctr.ZL() ctr.ZR() ctr.LS() ctr.RS() ctr.PLUS() ctr.MINUS() ## long press to quit ctr.B(5) ctr.close()
class EggHatcher(object): """ 初始化需要背包队伍为空,蛋箱满 """ def __init__(self, cycle): super(EggHatcher, self).__init__() self.m_Cycle = cycle self.m_CurCol = 0 self.m_nxCtrl = Controller(printout=True) self.m_nxCtrl.LS() self.m_nxCtrl.pause(2) def start_hatch_egg(self): while self.m_CurCol <= 6: print("Cur Round: %s" % self.m_CurCol) # 取蛋 self.pick_egg() if self.m_CurCol == 6: break # 孵蛋 all_range = int(self.m_Cycle / 10) for i in range(all_range): # 5rang=10周期 for j in range(5): print("周期: %s" % (i * 10 + j * 2)) self.run_round() self.m_nxCtrl.ls_r(-1) self.m_nxCtrl.ls_u(-1) for cnt in range(20 * 5): self.m_nxCtrl.B() self.m_nxCtrl.pause(0.8) self.m_nxCtrl.ls_r(-1) self.m_nxCtrl.ls_u(-1) self.m_nxCtrl.pause(6.5) self.m_nxCtrl.release() # 列数+1 self.m_CurCol = self.m_CurCol + 1 print("Patch Egg Finished!!!") def run_round(self): self.m_nxCtrl.ls_l(-1) self.m_nxCtrl.ls_u(-1) self.m_nxCtrl.pause(5.6) self.m_nxCtrl.release() # back self.m_nxCtrl.ls_r(-1) self.m_nxCtrl.ls_u(-1) self.m_nxCtrl.pause(6.3) self.m_nxCtrl.release() def switch_2_box(self): self.m_nxCtrl.X() self.m_nxCtrl.pause(1) self.m_nxCtrl.A() self.m_nxCtrl.pause(2) self.m_nxCtrl.R() self.m_nxCtrl.pause(2) self.m_nxCtrl.Y() self.m_nxCtrl.pause(0.1) self.m_nxCtrl.Y() self.m_nxCtrl.pause(0.1) self.m_nxCtrl.l() self.m_nxCtrl.pause(0.1) def back_2_road(self): for i in range(3): self.m_nxCtrl.B(2) self.m_nxCtrl.pause(0.1) def move_2_follow(self): self.m_nxCtrl.r() self.m_nxCtrl.pause(0.01) self.m_nxCtrl.A() self.m_nxCtrl.pause(0.01) self.m_nxCtrl.u() self.m_nxCtrl.pause(0.01) self.m_nxCtrl.A() self.m_nxCtrl.pause(0.01) for i in range(self.m_CurCol + 1): self.m_nxCtrl.l() self.m_nxCtrl.pause(0.01) self.m_nxCtrl.d() self.m_nxCtrl.pause(0.01) self.m_nxCtrl.A() self.m_nxCtrl.pause(0.01) def move_2_box(self): self.m_nxCtrl.d() self.m_nxCtrl.pause(0.01) self.m_nxCtrl.A() self.m_nxCtrl.pause(0.01) for i in range(2): self.m_nxCtrl.u() self.m_nxCtrl.pause(0.01) self.m_nxCtrl.A() self.m_nxCtrl.pause(0.01) for i in range(self.m_CurCol): self.m_nxCtrl.r() self.m_nxCtrl.pause(0.01) self.m_nxCtrl.u() self.m_nxCtrl.pause(0.01) self.m_nxCtrl.A() self.m_nxCtrl.pause(0.01) def pick_egg(self): print(f"Picking {self.m_CurCol + 1}th egg(s)") self.switch_2_box() if self.m_CurCol != 0: self.move_2_box() if self.m_CurCol != 6: self.move_2_follow() self.back_2_road() def close_controller(self): self.m_nxCtrl.release() self.m_nxCtrl.close()
class TimeSkipper(object): """ 过帧控制,起始状态要在坑前定位 """ def __init__(self, startDate, skipFrameNum): super(TimeSkipper, self).__init__() self.m_curDate = startDate self.m_skipFrameNum = skipFrameNum self.m_nxCtrl = Controller(printout=True) self.m_nxCtrl.LS() self.m_nxCtrl.pause(2) self.m_timeClickDuration = 0.005 self.m_nxCtrl.buttondelay = 0.02 def start_skip_frame(self): self.save(collectWatt=False) firstOpenTime = True for i in range(self.m_skipFrameNum): print("Current Skip = %s, Date = %s" % (i, self.m_curDate)) self.skip_one_frame(firstOpenTime) firstOpenTime = False self.m_curDate = self.m_curDate + datetime.timedelta(days=1) # 1.1/4.1/8.1各保存一次,防崩溃 if self.m_curDate.day == 1 and (self.m_curDate.month == 1 or self.m_curDate.month == 4 or self.m_curDate.month == 8): print("Save Date = %s" % self.m_curDate) self.save() firstOpenTime = True self.save() print("Skip Frame Finished!!!") def close_controller(self): self.m_nxCtrl.release() self.m_nxCtrl.close() def skip_one_frame(self, firstOpenTime=False): self.m_nxCtrl.A(0.15) self.m_nxCtrl.pause(0.1) self.skip_time_from_year(firstOpenTime) def skip_time_from_year(self, firstOpenTime=False): tmpDate = self.m_curDate + datetime.timedelta(days=1) # 跨年,年跳1 if tmpDate.year > self.m_curDate.year: # 不是首次点开时间,要回退到年位置 if not firstOpenTime: for i in range(5): self.m_nxCtrl.l() self.pause_skip_time() firstOpenTime = True self.m_nxCtrl.u() self.pause_skip_time() if firstOpenTime: self.m_nxCtrl.r() self.pause_skip_time() self.skip_time_from_month(firstOpenTime) def skip_time_from_month(self, firstOpenTime=False): # 跨月,月跳1 lastMonthDay = self.last_day_of_month(self.m_curDate) if self.m_curDate.day == lastMonthDay.day: # 不是首次点开时间,回退到月位置 if not firstOpenTime: for i in range(4): self.m_nxCtrl.l() self.pause_skip_time() firstOpenTime = True self.m_nxCtrl.u() self.pause_skip_time() # 补全由于月份跳动没有加到的日 appendDay = 0 if self.m_curDate.day == 28: appendDay = 3 elif self.m_curDate.day == 29: appendDay = 2 elif self.m_curDate.day == 30: appendDay = 1 # 回到日位置 if appendDay > 0: self.m_nxCtrl.r() self.pause_skip_time() # 日修正 for i in range(appendDay): self.m_nxCtrl.u() self.pause_skip_time() # 回月位置 if appendDay > 0: self.m_nxCtrl.l() self.pause_skip_time() if firstOpenTime: self.m_nxCtrl.r() self.pause_skip_time() self.skip_time_from_day(firstOpenTime) def skip_time_from_day(self, firstOpenTime=False): # 不是首次点开时间,要回退到月位置 if not firstOpenTime: for i in range(3): self.m_nxCtrl.l() self.pause_skip_time() firstOpenTime = True # 日跳1 self.m_nxCtrl.u() self.pause_skip_time() for i in range(3): self.m_nxCtrl.r() self.pause_skip_time() self.m_nxCtrl.A(0.15) self.m_nxCtrl.pause(0.1) def pause_skip_time(self): self.m_nxCtrl.pause(self.m_timeClickDuration) def save(self, collectWatt=True): # 回桌面进游戏 self.m_nxCtrl.h(0.1) self.m_nxCtrl.pause(1) self.m_nxCtrl.A(0.1) self.m_nxCtrl.pause(2) # 收瓦特 if collectWatt: self.collect_watt() # 保存 self.m_nxCtrl.X(0.5) self.m_nxCtrl.pause(2) self.m_nxCtrl.R(0.5) self.m_nxCtrl.pause(2) self.m_nxCtrl.A(0.5) self.m_nxCtrl.pause(3) print("Save!!!") # 回桌面进时间界面 self.m_nxCtrl.h(0.1) self.m_nxCtrl.pause(0.5) self.m_nxCtrl.d(0.1) self.m_nxCtrl.pause(0.5) for i in range(4): self.m_nxCtrl.r(0.1) self.m_nxCtrl.pause(0.05) self.m_nxCtrl.A(0.1) self.m_nxCtrl.pause(1) self.m_nxCtrl.d(-1) self.m_nxCtrl.pause(2) self.m_nxCtrl.release() self.m_nxCtrl.r(0.1) self.m_nxCtrl.pause(0.05) # 定位到时间上 for i in range(4): self.m_nxCtrl.d(0.1) self.m_nxCtrl.pause(0.05) self.m_nxCtrl.A(0.1) self.m_nxCtrl.pause(0.5) for i in range(2): self.m_nxCtrl.d(0.1) self.m_nxCtrl.pause(0.05) def collect_watt(self): self.m_nxCtrl.A(0.1) self.m_nxCtrl.pause(2) for i in range(5): self.m_nxCtrl.B(0.1) self.m_nxCtrl.pause(1) def last_day_of_month(self, any_day): next_month = any_day.replace(day=28) + datetime.timedelta( days=4) # this will never fail return next_month - datetime.timedelta(days=next_month.day)