From 762313e3880d44fdf3f75ebb86e0dc363b8abd6a Mon Sep 17 00:00:00 2001 From: melancholytron Date: Thu, 22 Dec 2022 12:33:38 -0600 Subject: [PATCH] First Commit --- IonJunkies-Merc/banks.txt | 1 + bait/banks.txt | 4 + banks.txt | 4 + epilectrik/banks.txt | 4 + file | 0 im bait/banks.txt | 3 + im-bait/banks.txt | 4 + mq.py | 10 + mtron/banks.bak | 0 mtron/banks.txt | 1 + mutant function.py | 571 ++++++++++++++++ mutant function.txt | 630 +++++++++++++++++ mutants.py | 661 ++++++++++++++++++ mutants_localbbs.py | 526 +++++++++++++++ mutants_paths.py | 812 ++++++++++++++++++++++ qmutants.py | 1341 +++++++++++++++++++++++++++++++++++++ 16 files changed, 4572 insertions(+) create mode 100644 IonJunkies-Merc/banks.txt create mode 100644 bait/banks.txt create mode 100644 banks.txt create mode 100644 epilectrik/banks.txt create mode 100644 file create mode 100644 im bait/banks.txt create mode 100644 im-bait/banks.txt create mode 100644 mq.py create mode 100644 mtron/banks.bak create mode 100644 mtron/banks.txt create mode 100644 mutant function.py create mode 100644 mutant function.txt create mode 100644 mutants.py create mode 100644 mutants_localbbs.py create mode 100644 mutants_paths.py create mode 100644 qmutants.py diff --git a/IonJunkies-Merc/banks.txt b/IonJunkies-Merc/banks.txt new file mode 100644 index 0000000..cffc203 --- /dev/null +++ b/IonJunkies-Merc/banks.txt @@ -0,0 +1 @@ +done,tra 2000,look,drop monster-bait,east,east,east,east,east,east,east,east,east,east,east,drop nuclear-decay,!deposit,!stock,get nuclear-decay,tra 2000,look,get monster-bait,!return,look,done \ No newline at end of file diff --git a/bait/banks.txt b/bait/banks.txt new file mode 100644 index 0000000..585fc9d --- /dev/null +++ b/bait/banks.txt @@ -0,0 +1,4 @@ +done,tra 2000,drop monster-bait,south,!deposit,drop nuclear-decay,!stock,get nuclear-decay,north,get monster-bait,!return,done +done,tra 2000,drop monster-bait,east,east,east,!deposit,drop nuclear-decay,!stock,get nuclear-decay,tra 2000,get monster-bait,!return,done +done,tra 2000,drop monster-bait,south,south,south,south,south,south,west,west,west,north,!deposit,drop nuclear-decay,!stock,get nuclear-decay,tra 2000,get monster-bait,!return,done + \ No newline at end of file diff --git a/banks.txt b/banks.txt new file mode 100644 index 0000000..e40414c --- /dev/null +++ b/banks.txt @@ -0,0 +1,4 @@ +done,tra 2000,south,!deposit,drop nuclear-decay,!stock,get nuclear-decay,!return,done +done,tra 2000,east,east,east,!deposit,drop nuclear-decay,!stock,get nuclear-decay,!return,done +done,tra 2000,south,south,south,south,south,south,west,west,west,north,!deposit,drop nuclear-decay,!stock,get nuclear-decay,!return,done + \ No newline at end of file diff --git a/epilectrik/banks.txt b/epilectrik/banks.txt new file mode 100644 index 0000000..585fc9d --- /dev/null +++ b/epilectrik/banks.txt @@ -0,0 +1,4 @@ +done,tra 2000,drop monster-bait,south,!deposit,drop nuclear-decay,!stock,get nuclear-decay,north,get monster-bait,!return,done +done,tra 2000,drop monster-bait,east,east,east,!deposit,drop nuclear-decay,!stock,get nuclear-decay,tra 2000,get monster-bait,!return,done +done,tra 2000,drop monster-bait,south,south,south,south,south,south,west,west,west,north,!deposit,drop nuclear-decay,!stock,get nuclear-decay,tra 2000,get monster-bait,!return,done + \ No newline at end of file diff --git a/file b/file new file mode 100644 index 0000000..e69de29 diff --git a/im bait/banks.txt b/im bait/banks.txt new file mode 100644 index 0000000..1065537 --- /dev/null +++ b/im bait/banks.txt @@ -0,0 +1,3 @@ +done,tra 2400,drop monster-bait,north,!deposit,drop nuclear-decay,!stock,get nuclear-decay,south,get monster-bait,!return,done +done,tra 2000,drop monster-bait,south,south,south,south,south,south,west,west,west,north,!deposit,drop nuclear-decay,!stock,get nuclear-decay,tra 2000,get monster-bait,!return,done + \ No newline at end of file diff --git a/im-bait/banks.txt b/im-bait/banks.txt new file mode 100644 index 0000000..585fc9d --- /dev/null +++ b/im-bait/banks.txt @@ -0,0 +1,4 @@ +done,tra 2000,drop monster-bait,south,!deposit,drop nuclear-decay,!stock,get nuclear-decay,north,get monster-bait,!return,done +done,tra 2000,drop monster-bait,east,east,east,!deposit,drop nuclear-decay,!stock,get nuclear-decay,tra 2000,get monster-bait,!return,done +done,tra 2000,drop monster-bait,south,south,south,south,south,south,west,west,west,north,!deposit,drop nuclear-decay,!stock,get nuclear-decay,tra 2000,get monster-bait,!return,done + \ No newline at end of file diff --git a/mq.py b/mq.py new file mode 100644 index 0000000..e3c9652 --- /dev/null +++ b/mq.py @@ -0,0 +1,10 @@ +import paho.mqtt.client as mqtt #import the client1 +broker_address="192.168.86.27" +#broker_address="iot.eclipse.org" +print("creating new instance") +client = mqtt.Client("P1") #create new instance +client.username_pw_set("homeassistant", "oes5gohng9gau1Quei2ohpixashi4Thidoon1shohGai2mae0ru2zaph2vooshai") +print("connecting to broker") +client.connect(broker_address) #connect to broker +username = "butthead three" +client.publish("mutants", username + "just died") \ No newline at end of file diff --git a/mtron/banks.bak b/mtron/banks.bak new file mode 100644 index 0000000..e69de29 diff --git a/mtron/banks.txt b/mtron/banks.txt new file mode 100644 index 0000000..1254e78 --- /dev/null +++ b/mtron/banks.txt @@ -0,0 +1 @@ +done,tra 2000,look,drop monster-bait,east,east,east,east,east,east,east,east,east,east,east,east,east,east,east,east,east,east,east,east,east,east,east,east,!sell,north,north,north,north,north,north,drop nuclear-decay,!deposit,!stock,get nuclear-decay,tra 2000,look,get monster-bait,!return,look,done \ No newline at end of file diff --git a/mutant function.py b/mutant function.py new file mode 100644 index 0000000..0fe30cc --- /dev/null +++ b/mutant function.py @@ -0,0 +1,571 @@ + #search a list + def search(self, list, platform): + for i in range(len(list)): + if list[i] == platform: + return True + return False + + #Reup Ions + def convert_items(self): + for item_l in self.local_items: + for item in convert_list: + if item_l == item: + self.command_str.emit("get "+item+"\r\n") + self.command_str.emit("con "+item+"\r\n") + self.local_items.remove(item_l) + + #Farms valuable stuff + def farm_items(self): + for item_l in self.local_items: + for item in farm_list: + if item_l == item: + self.command_str.emit("get "+item+"\r\n") + self.local_items.remove(item_l) + self.sell_list.append(item_l) + self.no_action_cnt = 0 + + #Sell items + def sell_items(self): + print(self.sell_list) + while len(self.sell_list) > 0: + item_l=self.sell_list[0] + self.sell_list.pop(0) + if item_l != "Nuclear-Decay": + self.command_str.emit("sell "+item_l+"\r\n") + time.sleep(.25) + + #Remove friends from monster list + def remove_friends(self): + for friend in friend_list: + try: + self.local_monsters.remove(friend) + except: + pass + + #Flushes keyboard + def flush_input(self): + try: + import msvcrt + while msvcrt.kbhit(): + msvcrt.getch() + except ImportError: + import sys, termios + termios.tcflush(sys.stdin, termios.TCIOFLUSH) + + #Decode incoming information + def decode_line(self,line): + result = "" + if line.decode('cp1252') != "": + ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])') + result = ansi_escape.sub('', line.decode('cp1252').strip('\n')) + self.console.append(result) + return result + + #initiate combat + def combat_start(self): + self.command_str.emit("combat " + self.local_monsters[0]+"\r\n") + self.in_combat = True + self.heal = True + self.path_step = 0 + self.no_action_cnt = 0 + + #process wander + def wander_process(self, result): + #area clear + if result.find("north - area continues.") != -1 or result.find("north - open gate.") != -1: + self.direction_list.append("north") + if result.find("south - area continues.") != -1 or result.find("south - open gate.") != -1: + self.direction_list.append("south") + if result.find("east - area continues.") != -1 or result.find("east - open gate.") != -1: + self.direction_list.append("east") + if result.find("west - area continues.") != -1 or result.find("west - open gate.") != -1: + self.direction_list.append("west") + + #are there monsters + if result.find("You see shadows to the") != -1: + try: + if result.find("north") != -1: + self.direction_list.remove("north") + if result.find("south") != -1: + self.direction_list.remove("south") + if result.find("east") != -1: + self.direction_list.remove("east") + if result.find("west") != -1: + self.direction_list.remove("west") + except: + pass + + #process combat per loop + def combat_process(self, result): + if result.find("You suffer") != -1: + self.hits = self.hits + 1 + if self.hits == 2: + self.command_str.emit("heal\r\n") + self.command_str.emit("heal\r\n") + self.hits = 0 + + if result.find("have slain") != -1 or result.find("has just left") != -1 or result.find("isn't around here!") != -1 or result.find("You're not ready") != -1: + try: + self.local_monsters.pop(0) + except: + pass + if len(self.local_monsters) > 0: + self.command_str.emit("combat " + self.local_monsters[0]+"\r\n") + else: + print("Area cleared") + self.in_combat = False + + #time travel + def time_travel(self): + self.farm_year = self.farm_year + 100 + if self.farm_year > self.year_limit: + self.farm_year = 2000 + self.command_str.emit("tra "+str(self.farm_year)+"\r\n") + + #process path + def path_process(self): + path_str = self.path_list[self.selected_path][self.path_step] + if path_str != "done": + self.command_str.emit(path_str+"\r\n") + self.path_step = self.path_step + 1 + else: + self.path_step = 0 + + #process stats + def parse_stat(self, result): + if self.stat_parsed == False: + self.sell_list = [] + self.status += result + result.find(">") != -1: + self.stat_parsed = True + + if self.stat_parsed and self.status != "": + for item_l in farm_list: + x = self.status.count(item_l) + for i in range(x): + self.sell_list.append(item_l) + + if self.status.find("Riblets :") != -1: + start_index = self.status.index('Riblets : ') + 16 + riblets_str = self.status[start_index:] + try: + end_index = riblets_str.index(' ') + except: + pass + riblets_str = riblets_str[:end_index] + print("Riblets:" + riblets_str) + self.riblets = int(riblets_str) + self.status != "" + print(self.sell_list) + + #index area + def index_area(self,result): + if self.area_indexed == False: + self.area += result + result.find(">") != -1: + self.area_indexed = True + + if self.area_indexed and self.area != "": + if self.area.find("On the ground lies:") != -1: + start_index = self.area.index('On the ground lies:') + item_str = self.area[start_index:] + try: + end_index = item_str.index('***') + except: + try: + end_index = item_str.index('>') + except: + pass + item_str = item_str[:end_index] + item_str = item_str.replace("On the ground lies:","") + item_str = item_str.replace("0","") + item_str = item_str.replace("1","") + item_str = item_str.replace("2","") + item_str = item_str.replace("3","") + item_str = item_str.replace("4","") + item_str = item_str.replace("5","") + item_str = item_str.replace("6","") + item_str = item_str.replace("7","") + item_str = item_str.replace("8","") + item_str = item_str.replace("9","") + item_str = item_str.replace("(","") + item_str = item_str.replace(")","") + item_str = item_str.replace("A ","") + item_str = item_str.replace("An ","") + item_str = item_str.replace(" ","") + item_str = item_str.replace(".","") + item_str = item_str.replace("\r\n","") + item_str = item_str.replace("***","") + self.local_items = list(item_str.split(",")) + print(self.local_items) + + if self.area.find("here") != -1: + end_index = self.area.index('here') + monster_str = self.area[:end_index] + start_index = monster_str.rindex('***') + monster_str = monster_str[start_index:] + monster_str = monster_str.replace("\r\n","") + monster_str = monster_str.replace(" and ","") + monster_str = monster_str.replace(" are ","") + monster_str = monster_str.replace(" is ","") + monster_str = monster_str.replace(" ","") + monster_str = monster_str.replace(".","") + monster_str = monster_str.replace("***","") + self.local_monsters = list(monster_str.split(",")) + remove_friends() + print(self.local_monsters) + + self.area = "": + + #main game loop + def mutants(self,result): + + #Nothing has happened in a while, time jump + if self.no_action_cnt > self.na_thresh: + time_travel() + self.no_action_cnt = 0 + + #parse status + self.parse_stat(result) + #index area + self.index_area(result) + #deposit riblets + if self.riblets > self.riblet_thresh and self.path_step == 0: + self.path_step = 1 + + #auto farm if sold items + if len(self.sell_list) == 0 and self.wander: + self.auto_farm = True + + #process wander + if self.wander and not self.in_combat and self.path_step == 0: + self.wander_process(result) + + #process combat + if self.in_combat: + self.combat_process(result) + + #scrapers + if result == "(N)onstop, (Q)uit, or (C)ontinue?": + self.command_str.emit("N\r\n") + + #ion starvation + if result.find("You're starving for IONS!") != -1: + self.command_str.emit("con gold-chunck\r\n") + self.auto_combat = True + self.heal = True + + #too heavy + if self.wander and result.find("The weight of all your items forces you to the ground.") != -1: + self.wander = False + self.command_str.emit("X\r\n") + + #dropped your weapon! + if self.auto_farm and result.find("The Nuclear-Decay fell out of your sack!") != -1: + self.time_steps = 0 + self.command_str.emit("con gold-chunck\r\n") + self.command_str.emit("get nuclear-decay\r\n") + + #I can't remember why I did this + if self.auto_farm and result.find("You're not carrying a gold-chunck.") != -1: + self.auto_farm = False + + #Dropped the bait, pick it back up + if result.find("The Monster-Bait fell out of your sack!") != -1: + self.time_steps = 0 + self.command_str.emit("con gold-chunck\r\n") + self.command_str.emit("get monster-bait\r\n") + + #if wander and result.find("fell out of your sack!") != -1: + #wander = False + #self.auto_farm = False + + #GTFO + if self.wander and ((result.find("It's too dark to see anything!") != -1 or + result.find("has hit you with his Nuclear-Decay!") != -1 or + result.find("You're blocked!") != -1) or + len(self.local_monsters) > 4): + + self.heal = True + self.command_str.emit("tra "+str(self.farm_year)+"\r\n") + self.in_combat = False + + #Sell the loot + if result.find("City Trading Centre") != -1: + if len(self.sell_list) > 0: + self.sell_items() + + #New area, take a look + if result.find("Compass:") != -1: + self.area_indexed = True + + #Parse character status + if result.find("stat") != -1: + self.stat_parsed = False + + #Trigger stop healing + if result.find("Nothing happens!") != -1 or result.find("You don't have enough ions to heal!") != -1: + self.heal = False + + #Turn on healing + if result.find("You suffer") != -1 or result.find("You are poisoned!") != -1: + self.heal = True + + #monster list related + if (result.find("yells: Gimmie") != -1 or + result.find("just arrived from") != -1 or + result.find("has hit") != -1 or + result.find("body is glowing") != -1 or + result.find("Get away from me") != -1 or + result.find("has magically appeared") != -1): + m = result.index(' ') + monster = result[:m] + if not search(self.local_monsters, monster): + self.local_monsters.append(monster) + remove_friends() + print(self.local_monsters) + if len(self.local_monsters) > 0 and self.auto_combat and not self.in_combat: + combat_start() + + #Monster took off, remove from list + if result.find("has just left") != -1: + end_index = result.index(' has') + mon_str = result[:end_index] + mon_str = mon_str.replace(" ","") + try: + self.local_monsters.remove(mon_str) + except: + pass + print(mon_str) + print(self.local_monsters) + + #Monster died, remove from list + if result.find("is crumbling to dust") != -1: + end_index = result.index(' is') + mon_str = result[:end_index] + mon_str = mon_str.replace(" ","") + try: + self.local_monsters.remove(mon_str) + except: + pass + print(mon_str) + print(self.local_monsters) + + #Someone picked something up, remove from item list + if result.find("picked up the") != -1: + start_index = result.index('the') + 4 + item_str = result[start_index:] + end_index = item_str.index('.') + item_str = item_str[:end_index] + item_str = item_str.replace(" ","") + try: + self.local_items.remove(item_str) + except: + pass + print(item_str) + print(self.local_items) + + #Dead person dropping stuff, add to local list + if result.find("is falling from") != -1: + start_index = result.index('A') + item_str = result[start_index:] + end_index = item_str.index('is') + item_str = item_str[:end_index] + item_str = item_str.replace(" ","") + item_str = item_str.replace("is","") + item_str = item_str.replace("An","") + item_str = item_str.replace("A","") + self.local_items.append(item_str) + print(self.local_items) + + #You died, do some stuff + if result.find("Select (Bury, 1-5, ?)") != -1: + self.in_combat=False + self.heal = False + self.wander = False + self.auto_farm = False + self.auto_combat = False + + #farm items + if len(self.local_items) > 0 and not self.in_combat: + if self.auto_farm: + self.farm_items() + if self.auto_combat: + self.convert_items() + #print("convert") + + #keyboard related - this part sucks + if keyboard.is_pressed(self.lock_key): + time.sleep(.5) + if self.key_detect: + self.key_detect = False + print("Key detect off") + else: + self.key_detect = True + print("Key detect on") + + if self.key_detect: + if keyboard.is_pressed("?"): + time.sleep(.5) + for help in help_list: + print(help) + + #directions + if keyboard.is_pressed("8"): + self.local_monsters = [] + self.local_items = [] + self.command_str.emit("north\r\n") + time.sleep(.25) + + if keyboard.is_pressed("2"): + self.local_monsters = [] + self.local_items = [] + self.command_str.emit("south\r\n") + time.sleep(.25) + if keyboard.is_pressed("4"): + self.local_monsters = [] + self.local_items = [] + self.command_str.emit("west\r\n") + time.sleep(.25) + if keyboard.is_pressed("6"): + self.local_monsters = [] + self.local_items = [] + self.command_str.emit("east\r\n") + time.sleep(.25) + #functions + if keyboard.is_pressed("a"): + time.sleep(.5) + if self.auto_combat: + self.auto_combat = False + print("Auto combat off") + else: + self.auto_combat = True + print("Auto combat on") + #Auto Ion + if keyboard.is_pressed("i"): + time.sleep(.5) + if self.auto_combat: + self.auto_combat = False + print("Auto ion off") + else: + self.auto_combat = True + print("Auto ion on") + #Auto farm + if keyboard.is_pressed("f"): + time.sleep(.5) + if self.auto_farm: + self.auto_farm = False + print("Auto farm off") + else: + self.auto_farm = True + print("Auto farm on") + + #Year limit + if keyboard.is_pressed("y"): + time.sleep(.25) + self.flush_input() + st = input("Year limit: ") + self.year_limit = int(st) + + #No action threshhold + if keyboard.is_pressed("n"): + time.sleep(.25) + self.flush_input() + st = input("No action: ") + self.na_thresh = int(st) + + #Start combat + if keyboard.is_pressed("c"): + if len(self.local_monsters) > 0: + combat_start() + time.sleep(.25) + + #Start Combat + if keyboard.is_pressed("c"): + if len(self.local_monsters) > 0: + combat_start() + time.sleep(.25) + + #look around + if keyboard.is_pressed("5"): + self.command_str.emit("look ") + time.sleep(.25) + + #meander status + if keyboard.is_pressed("m"): + time.sleep(.5) + if self.wander: + self.wander = False + print("Meander off") + else: + self.wander = True + print("Meander on") + self.command_str.emit("look\r\n") + + #heal + if keyboard.is_pressed("h"): + self.command_str.emit("heal\r\n") + self.heal = True + time.sleep(.25) + + #look around + if keyboard.is_pressed("l"): + self.command_str.emit("look\r\n") + time.sleep(.25) + + #stats + if keyboard.is_pressed("v"): + self.command_str.emit("stat\r\n") + time.sleep(.25) + + #sell items + if keyboard.is_pressed("s"): + self.sell_items() + time.sleep(.25) + + #store path select + if keyboard.is_pressed("p") and not self.in_combat: + time.sleep(.25) + self.flush_input() + #toss = keyboard.read_key() + st = input("Choose path input: ") + self.selected_path = int(st) + self.path_step = 1 + self.command_str.emit("Starting path..\r\n") + self.flush_input() + + #read keyboard + if keyboard.is_pressed("k") and not self.in_combat: + time.sleep(.25) + self.flush_input() + #toss = keyboard.read_key() + st = input("Keyboard input: ") + self.command_str.emit(st+"\r\n") + self.flush_input() + + #wield weapon + if keyboard.is_pressed("w"): + time.sleep(.25) + self.command_str.emit("wie nuclear-decay\r\n") + + #drop item + if keyboard.is_pressed("d"): + time.sleep(.25) + self.flush_input() + #toss = keyboard.read_key() + st = input("drop item: ") + drop_item = "drop " + st + self.command_str.emit(drop_item+"\r\n") + + #time travel + if keyboard.is_pressed("t") and not self.in_combat: + monster_list = [] + time.sleep(.25) + self.flush_input() + #toss = keyboard.read_key() + st = input("year: ") + year = "travel " + st + self.command_str.emit(year+"\r\n") + + if keyboard.is_pressed("x"): + break \ No newline at end of file diff --git a/mutant function.txt b/mutant function.txt new file mode 100644 index 0000000..b14edb1 --- /dev/null +++ b/mutant function.txt @@ -0,0 +1,630 @@ + #search a list + def search(self, list, platform): + for i in range(len(list)): + if list[i] == platform: + return True + return False + + #Reup Ions + def convert_items(self): + for item_l in self.local_items: + for item in convert_list: + if item_l == item: + self.tn.write(b"get "+item.encode('ascii')+b"\r\n") + self.tn.write(b"con "+item.encode('ascii')+b"\r\n") + self.local_items.remove(item_l) + + #Farms valuable stuff + def farm_items(self): + for item_l in self.local_items: + for item in farm_list: + if item_l == item: + self.tn.write(b"get "+item.encode('ascii')+b"\r\n") + self.local_items.remove(item_l) + self.sell_list.append(item_l) + self.no_action_cnt = 0 + + #Sell items + def sell_items(self): + print(self.sell_list) + while len(self.sell_list) > 0: + item_l=self.sell_list[0] + self.sell_list.pop(0) + if item_l != "Nuclear-Decay": + self.tn.write(b"sell "+item_l.encode('ascii')+b"\r\n") + time.sleep(.25) + + #Remove friends from monster list + def remove_friends(self): + for friend in friend_list: + try: + self.local_monsters.remove(friend) + except: + pass + + #Flushes keyboard + def flush_input(self): + try: + import msvcrt + while msvcrt.kbhit(): + msvcrt.getch() + except ImportError: + import sys, termios + termios.tcflush(sys.stdin, termios.TCIOFLUSH) + + #Decode incoming information + def decode_line(self,line): + result = "" + if line.decode('cp1252') != "": + ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])') + result = ansi_escape.sub('', line.decode('cp1252').strip('\n')) + self.console.append(result) + return result + + #initiate combat + def combat_start(self): + self.tn.write(b"combat " + self.local_monsters[0].encode('ascii')+b"\r\n") + self.in_combat = True + self.heal = True + self.path_step = 0 + self.no_action_cnt = 0 + + #process wander + def wander_process(self, result, wander_trigger): + #area clear + if result.find("north - area continues.") != -1 or result.find("north - open gate.") != -1: + self.direction_list.append("north") + if result.find("south - area continues.") != -1 or result.find("south - open gate.") != -1: + self.direction_list.append("south") + if result.find("east - area continues.") != -1 or result.find("east - open gate.") != -1: + self.direction_list.append("east") + if result.find("west - area continues.") != -1 or result.find("west - open gate.") != -1: + self.direction_list.append("west") + + #are there monsters + if result.find("You see shadows to the") != -1: + try: + if result.find("north") != -1: + self.direction_list.remove("north") + if result.find("south") != -1: + self.direction_list.remove("south") + if result.find("east") != -1: + self.direction_list.remove("east") + if result.find("west") != -1: + self.direction_list.remove("west") + except: + pass + + if wander_trigger == 0: + print("wander triggered") + print("no action: " + str(self.no_action_cnt)) + #increment no action counter + self.no_action_cnt = self.no_action_cnt + 1 + if len(self.direction_list) == 0: + self.tn.write(b"look\r\n") + self.local_monsters = [] + self.local_items = [] + + #pick randomly + if len(self.direction_list) > 0 and wander_trigger == 0: + if len(self.direction_list) > 1: + try: + self.direction_list.remove(self.previous_dir) + except: + pass + print(self.direction_list) + dir_choice = random.choice(self.direction_list) + self.tn.write(dir_choice.encode('ascii')+b"\r\n") + self.direction_list = [] + self.previous_dir = opposite_dir[dir_choice] + + #process combat per loop + def combat_process(self): + + if result.find("You suffer") != -1: + self.hits = self.hits + 1 + if self.hits == 2: + self.tn.write(b"heal\r\n") + self.tn.write(b"heal\r\n") + self.hits = 0 + + if result.find("have slain") != -1 or result.find("has just left") != -1 or result.find("isn't around here!") != -1 or result.find("You're not ready") != -1: + try: + self.local_monsters.pop(0) + except: + pass + if len(self.local_monsters) > 0: + self.tn.write(b"combat " + self.local_monsters[0].encode('ascii')+b"\r\n") + else: + print("Area cleared") + self.in_combat = False + + wield = self.time_steps % 10 + + if wield == 0: + self.tn.write(b"wie nuclear-decay\r\n") + + #time travel + def time_travel(self): + self.farm_year = self.farm_year + 100 + if self.farm_year > self.year_limit: + self.farm_year = 2000 + self.tn.write(b"tra "+str(self.farm_year).encode('ascii')+b"\r\n") + + #process path + def path_process(self): + path_str = self.path_list[self.selected_path][self.path_step] + if path_str != "done": + self.tn.write(path_str.encode('ascii')+b"\r\n") + self.path_step = self.path_step + 1 + else: + self.path_step = 0 + + #process stats + def parse_stat(self): + self.sell_list = [] + line = self.tn.read_until(b">",0) # Read one line + result = self.decode_line(line) + for item_l in farm_list: + x = line.decode('ascii').count(item_l) + for i in range(x): + self.sell_list.append(item_l) + + if result.find("Riblets :") != -1: + start_index = result.index('Riblets : ') + 16 + riblets_str = result[start_index:] + try: + end_index = riblets_str.index(' ') + except: + pass + riblets_str = riblets_str[:end_index] + print("Riblets:" + riblets_str) + self.riblets = int(riblets_str) + print(self.sell_list) + + #index area + def index_area(self): + end_index = 0 + line = self.tn.read_until(b">",0) # Read one line + result = self.decode_line(line) + #Index items + if result.find("On the ground lies:") != -1: + start_index = result.index('On the ground lies:') + item_str = result[start_index:] + try: + end_index = item_str.index('***') + except: + try: + end_index = item_str.index('>') + except: + pass + item_str = item_str[:end_index] + item_str = item_str.replace("On the ground lies:","") + item_str = item_str.replace("0","") + item_str = item_str.replace("1","") + item_str = item_str.replace("2","") + item_str = item_str.replace("3","") + item_str = item_str.replace("4","") + item_str = item_str.replace("5","") + item_str = item_str.replace("6","") + item_str = item_str.replace("7","") + item_str = item_str.replace("8","") + item_str = item_str.replace("9","") + item_str = item_str.replace("(","") + item_str = item_str.replace(")","") + item_str = item_str.replace("A ","") + item_str = item_str.replace("An ","") + item_str = item_str.replace(" ","") + item_str = item_str.replace(".","") + item_str = item_str.replace("\r\n","") + item_str = item_str.replace("***","") + self.local_items = list(item_str.split(",")) + print(self.local_items) + + if result.find("here") != -1: + end_index = result.index('here') + monster_str = result[:end_index] + start_index = monster_str.rindex('***') + monster_str = monster_str[start_index:] + monster_str = monster_str.replace("\r\n","") + monster_str = monster_str.replace(" and ","") + monster_str = monster_str.replace(" are ","") + monster_str = monster_str.replace(" is ","") + monster_str = monster_str.replace(" ","") + monster_str = monster_str.replace(".","") + monster_str = monster_str.replace("***","") + self.local_monsters = list(monster_str.split(",")) + remove_friends() + print(self.local_monsters) + + #main game loop + def mutants(self): + area_indexed = False + while True: + #print(self.local_items) + time.sleep(.1) + self.time_steps = self.time_steps + 1 + + #data decode + result = "" + line = None + line = self.tn.read_until(b"\n",0) # Read one line + result = self.decode_line(line) + + #Nothing has happened in a while, time jump + if self.no_action_cnt > self.na_thresh: + time_travel() + self.no_action_cnt = 0 + + #deposit riblets + if self.riblets > self.riblet_thresh and self.path_step == 0: + self.path_step = 1 + + #follow path_list + path_trigger = self.time_steps % 10 + if path_trigger == 0 and not self.in_combat: + self.path_process() + + #parse status + stat_trigger = self.time_steps % 600 + if stat_trigger == 0 and not self.in_combat: + self.tn.write(b"stat\r\n") + + #heal + heal_trigger = self.time_steps % 20 + if heal_trigger == 0: + if self.heal: + self.tn.write(b"heal\r\n") + + #auto farm if sold items + if len(self.sell_list) == 0 and self.wander: + self.auto_farm = True + + #process wander + wander_trigger = self.time_steps % 30 + if self.wander and not self.in_combat and self.path_step == 0: + if wander_trigger == 0: + area_indexed = False + #print("wander triggered") + self.wander_process(result,wander_trigger) + + #Reset time steps + if self.time_steps == 1000: + self.time_steps = 0 + + #process combat + if self.in_combat: + self.combat_process(result) + + #scrapers + if result == "(N)onstop, (Q)uit, or (C)ontinue?": + self.tn.write(b"N\r\n") + + #ion starvation + if result.find("You're starving for IONS!") != -1: + self.tn.write(b"con gold-chunck\r\n") + self.auto_combat = True + self.heal = True + + #too heavy + if self.wander and result.find("The weight of all your items forces you to the ground.") != -1: + self.wander = False + self.tn.write(b"X\r\n") + + #dropped your weapon! + if self.auto_farm and result.find("The Nuclear-Decay fell out of your sack!") != -1: + self.time_steps = 0 + self.tn.write(b"con gold-chunck\r\n") + self.tn.write(b"get nuclear-decay\r\n") + + #I can't remember why I did this + if self.auto_farm and result.find("You're not carrying a gold-chunck.") != -1: + self.auto_farm = False + + #Dropped the bait, pick it back up + if result.find("The Monster-Bait fell out of your sack!") != -1: + self.time_steps = 0 + self.tn.write(b"con gold-chunck\r\n") + self.tn.write(b"get monster-bait\r\n") + + #if wander and result.find("fell out of your sack!") != -1: + #wander = False + #self.auto_farm = False + + #GTFO + if self.wander and ((result.find("It's too dark to see anything!") != -1 or + result.find("has hit you with his Nuclear-Decay!") != -1 or + result.find("You're blocked!") != -1) or + len(self.local_monsters) > 4): + + self.heal = True + self.tn.write(b"tra "+str(self.farm_year).encode('ascii')+b"\r\n") + self.in_combat = False + + #Sell the loot + if result.find("City Trading Centre") != -1: + if len(self.sell_list) > 0: + self.sell_items() + + #New area, take a look + if result.find("Compass:") != -1 and area_indexed == False: + self.index_area() + if self.wander: + self.tn.write(b"look\r\n") + area_indexed = True + + #Parse character status + if result.find("stat") != -1: + self.parse_stat() + + #Trigger stop healing + if result.find("Nothing happens!") != -1 or result.find("You don't have enough ions to heal!") != -1: + self.heal = False + + #Turn on healing + if result.find("You suffer") != -1 or result.find("You are poisoned!") != -1: + self.heal = True + + #monster list related + if (result.find("yells: Gimmie") != -1 or + result.find("just arrived from") != -1 or + result.find("has hit") != -1 or + result.find("body is glowing") != -1 or + result.find("Get away from me") != -1 or + result.find("has magically appeared") != -1): + m = result.index(' ') + monster = result[:m] + if not search(self.local_monsters, monster): + self.local_monsters.append(monster) + remove_friends() + print(self.local_monsters) + if len(self.local_monsters) > 0 and self.auto_combat and not self.in_combat: + combat_start() + + #Monster took off, remove from list + if result.find("has just left") != -1: + end_index = result.index(' has') + mon_str = result[:end_index] + mon_str = mon_str.replace(" ","") + try: + self.local_monsters.remove(mon_str) + except: + pass + print(mon_str) + print(self.local_monsters) + + #Monster died, remove from list + if result.find("is crumbling to dust") != -1: + end_index = result.index(' is') + mon_str = result[:end_index] + mon_str = mon_str.replace(" ","") + try: + self.local_monsters.remove(mon_str) + except: + pass + print(mon_str) + print(self.local_monsters) + + #Someone picked something up, remove from item list + if result.find("picked up the") != -1: + start_index = result.index('the') + 4 + item_str = result[start_index:] + end_index = item_str.index('.') + item_str = item_str[:end_index] + item_str = item_str.replace(" ","") + try: + self.local_items.remove(item_str) + except: + pass + print(item_str) + print(self.local_items) + + #Dead person dropping stuff, add to local list + if result.find("is falling from") != -1: + start_index = result.index('A') + item_str = result[start_index:] + end_index = item_str.index('is') + item_str = item_str[:end_index] + item_str = item_str.replace(" ","") + item_str = item_str.replace("is","") + item_str = item_str.replace("An","") + item_str = item_str.replace("A","") + self.local_items.append(item_str) + print(self.local_items) + + #You died, do some stuff + if result.find("Select (Bury, 1-5, ?)") != -1: + self.in_combat=False + self.heal = False + self.wander = False + self.auto_farm = False + self.auto_combat = False + + #farm items + if len(self.local_items) > 0 and not self.in_combat: + if self.auto_farm: + self.farm_items() + if self.auto_combat: + self.convert_items() + #print("convert") + + #keyboard related - this part sucks + if keyboard.is_pressed(self.lock_key): + time.sleep(.5) + if self.key_detect: + self.key_detect = False + print("Key detect off") + else: + self.key_detect = True + print("Key detect on") + + if self.key_detect: + if keyboard.is_pressed("?"): + time.sleep(.5) + for help in help_list: + print(help) + + #directions + if keyboard.is_pressed("8"): + self.local_monsters = [] + self.local_items = [] + self.tn.write(b"north\r\n") + area_indexed = False + time.sleep(.25) + + if keyboard.is_pressed("2"): + self.local_monsters = [] + self.local_items = [] + self.tn.write(b"south\r\n") + area_indexed = False + time.sleep(.25) + if keyboard.is_pressed("4"): + self.local_monsters = [] + self.local_items = [] + self.tn.write(b"west\r\n") + area_indexed = False + time.sleep(.25) + if keyboard.is_pressed("6"): + self.local_monsters = [] + self.local_items = [] + self.tn.write(b"east\r\n") + area_indexed = False + time.sleep(.25) + #functions + if keyboard.is_pressed("a"): + time.sleep(.5) + if self.auto_combat: + self.auto_combat = False + print("Auto combat off") + else: + self.auto_combat = True + print("Auto combat on") + #Auto Ion + if keyboard.is_pressed("i"): + time.sleep(.5) + if self.auto_combat: + self.auto_combat = False + print("Auto ion off") + else: + self.auto_combat = True + print("Auto ion on") + #Auto farm + if keyboard.is_pressed("f"): + time.sleep(.5) + if self.auto_farm: + self.auto_farm = False + print("Auto farm off") + else: + self.auto_farm = True + print("Auto farm on") + + #Year limit + if keyboard.is_pressed("y"): + time.sleep(.25) + self.flush_input() + st = input("Year limit: ") + self.year_limit = int(st) + + #No action threshhold + if keyboard.is_pressed("n"): + time.sleep(.25) + self.flush_input() + st = input("No action: ") + self.na_thresh = int(st) + + #Start combat + if keyboard.is_pressed("c"): + if len(self.local_monsters) > 0: + combat_start() + time.sleep(.25) + + #Start Combat + if keyboard.is_pressed("c"): + if len(self.local_monsters) > 0: + combat_start() + time.sleep(.25) + + #look around + if keyboard.is_pressed("5"): + self.tn.write(b"look ") + time.sleep(.25) + + #meander status + if keyboard.is_pressed("m"): + time.sleep(.5) + if self.wander: + self.wander = False + print("Meander off") + else: + self.wander = True + print("Meander on") + self.tn.write(b"look\r\n") + + #heal + if keyboard.is_pressed("h"): + self.tn.write(b"heal\r\n") + self.heal = True + time.sleep(.25) + + #look around + if keyboard.is_pressed("l"): + area_indexed = False + self.tn.write(b"look\r\n") + time.sleep(.25) + + #stats + if keyboard.is_pressed("v"): + self.tn.write(b"stat\r\n") + time.sleep(.25) + + #sell items + if keyboard.is_pressed("s"): + self.sell_items() + time.sleep(.25) + + #store path select + if keyboard.is_pressed("p") and not self.in_combat: + time.sleep(.25) + self.flush_input() + #toss = keyboard.read_key() + st = input("Choose path input: ") + self.selected_path = int(st) + self.path_step = 1 + self.tn.write(b"Starting path..\r\n") + self.flush_input() + + #read keyboard + if keyboard.is_pressed("k") and not self.in_combat: + time.sleep(.25) + self.flush_input() + #toss = keyboard.read_key() + st = input("Keyboard input: ") + self.tn.write(st.encode('ascii')+b"\r\n") + self.flush_input() + + #wield weapon + if keyboard.is_pressed("w"): + time.sleep(.25) + self.tn.write(b"wie nuclear-decay\r\n") + + #drop item + if keyboard.is_pressed("d"): + time.sleep(.25) + self.flush_input() + #toss = keyboard.read_key() + st = input("drop item: ") + drop_item = "drop " + st + self.tn.write(drop_item.encode('ascii')+b"\r\n") + + #time travel + if keyboard.is_pressed("t") and not self.in_combat: + monster_list = [] + time.sleep(.25) + self.flush_input() + #toss = keyboard.read_key() + st = input("year: ") + year = "travel " + st + self.tn.write(year.encode('ascii')+b"\r\n") + + if keyboard.is_pressed("x"): + break \ No newline at end of file diff --git a/mutants.py b/mutants.py new file mode 100644 index 0000000..af113c0 --- /dev/null +++ b/mutants.py @@ -0,0 +1,661 @@ +import getpass +import telnetlib +import re +import time +import keyboard +import random + +HOST = "telnet.goldenunicorn.net" +user = "epilectrik" +password = "gupass" +tn = telnetlib.Telnet() +tn.open(HOST,23) + +#static lists +convert_list = ["Ion-Pack","Ion-Decay","Cheese","Nuclear-thong","Skull","Bottle-Cap","Cigarette-Butt","Knife","Gas-Grenade", + "Light-Spear","Silver-Potion","Bastard-Sword","Invisible-Knife","Great-Club","Spear","Blizzard-Staff","Devil_Key","Grey-Dagger","Bone","Axe","BlackJack", + "Golden-Key","Crystal-Key","Trident","Ice-Knife","Iron-Sickle","Gold-Spear","Fang-Dagger","Hound-Fang","Pink-Potion","Small-Dagger","Mage-Stick","Purple-Potion", + "Tree-Branch","Poker","Bronze Knife","Small-Club","Wonderous-Sword","Spell-Potion","Long-Sword","Ion-Gauntlet","Sling-Sword","Green-Vial","Small-Spear", + "Tree-Stump","Saphire","Flame-Sword","Rock-Club","Lava-Dagger","Bloody-Arm","Golden-Needle"] + +farm_list = ["Gold-Chunck","Nuclear-Rock","Nuclear-Decay","Invisible-Cloth","Troll-Skin","Nuclear-Waste"] + +friend_list = ["Epilectrik","ImBait","Mtron","Im"] + +help_list = ["$ - Key listener on/off", + "8 - North", + "2 - South", + "6 - East", + "4 - West", + "5 - Look direction", + "c - Combat", + "w - Wield weapon", + "a - Auto combat on/off", + "f - Auto farm on/off", + "i - Auto Ion on/off", + "t - time travel", + "d - drop item", + "k - keyboard input", + "v - status", + "m - meander" + ] + +#dynamic lists +local_items = [] +local_monsters = [] + +#modes +heal = False +wander = False +auto_combat = False +auto_ion = False +auto_farm = False +key_detect = True +#states +time_steps = 0 +in_combat = False +hits = 0 +lock_key="$" +direction_list = [] +sell_list = [] +previous_dir = "" + +opposite_dir = { + "north":"south", + "south":"north", + "east":"west", + "west":"east", +} + +#search a list +def search(list, platform): + for i in range(len(list)): + if list[i] == platform: + return True + return False + +#Reup Ions +def convert_items(): + global local_items + global convert_list + for item_l in local_items: + for item in convert_list: + if item_l == item: + tn.write(b"get "+item.encode('ascii')+b"\r\n") + tn.write(b"con "+item.encode('ascii')+b"\r\n") + local_items.remove(item_l) + +#Farms valuable stuff +def farm_items(): + global local_items + global farm_list + global sell_list + + for item_l in local_items: + for item in farm_list: + if item_l == item: + tn.write(b"get "+item.encode('ascii')+b"\r\n") + local_items.remove(item_l) + sell_list.append(item_l) + +#Sell items +def sell_items(): + global sell_list + print(sell_list) + while len(sell_list) > 0: + item_l=sell_list[0] + sell_list.pop(0) + if item_l != "Nuclear-Decay": + tn.write(b"sell "+item_l.encode('ascii')+b"\r\n") + time.sleep(.25) + + +#Remove friends from monster list +def remove_friends(): + global local_monsters + for friend in friend_list: + try: + local_monsters.remove(friend) + except: + pass + +#Flushes keyboard +def flush_input(): + + try: + import msvcrt + while msvcrt.kbhit(): + msvcrt.getch() + except ImportError: + import sys, termios + termios.tcflush(sys.stdin, termios.TCIOFLUSH) + +def decode_line(line): + result = "" + if line.decode('cp1252') != "": + ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])') + result = ansi_escape.sub('', line.decode('cp1252').strip('\n')) + print(result) + return result + +#initiate combat +def combat_start(): + global local_monsters + global in_combat + + tn.write(b"combat " + local_monsters[0].encode('ascii')+b"\r\n") + in_combat = True + heal = True + +#process wander +def wander_process(result,wander_trigger): + global heal + global direction_list + global previous_dir + global local_monsters + global local_items + + #area clear + if result.find("north - area continues.") != -1 or result.find("north - open gate.") != -1: + direction_list.append("north") + if result.find("south - area continues.") != -1 or result.find("south - open gate.") != -1: + direction_list.append("south") + if result.find("east - area continues.") != -1 or result.find("east - open gate.") != -1: + direction_list.append("east") + if result.find("west - area continues.") != -1 or result.find("west - open gate.") != -1: + direction_list.append("west") + + #print(direction_list) + #are there monsters + if result.find("You see shadows to the") != -1: + try: + if result.find("north") != -1: + direction_list.remove("north") + if result.find("south") != -1: + direction_list.remove("south") + if result.find("east") != -1: + direction_list.remove("east") + if result.find("west") != -1: + direction_list.remove("west") + except: + pass + + if wander_trigger == 0: + print("wander triggered") + if len(direction_list) == 0: + tn.write(b"look\r\n") + local_monsters = [] + local_items = [] + + #pick randomly + if len(direction_list) > 0 and wander_trigger == 0: + if len(direction_list) > 1: + try: + direction_list.remove(previous_dir) + except: + pass + print(direction_list) + dir_choice = random.choice(direction_list) + tn.write(dir_choice.encode('ascii')+b"\r\n") + direction_list = [] + previous_dir = opposite_dir[dir_choice] + +#process combat per loop +def combat_process(result): + global heal + global hits + global time_steps + global local_monsters + global in_combat + + if result.find("You suffer") != -1: + hits = hits + 1 + if hits == 2: + tn.write(b"heal\r\n") + tn.write(b"heal\r\n") + hits = 0 + + if result.find("have slain") != -1 or result.find("has just left") != -1 or result.find("isn't around here!") != -1 or result.find("You're not ready") != -1: + try: + local_monsters.pop(0) + except: + pass + if len(local_monsters) > 0: + tn.write(b"combat " + local_monsters[0].encode('ascii')+b"\r\n") + else: + print("Area cleared") + in_combat = False + + wield = time_steps % 10 + + if wield == 0: + tn.write(b"wie nuclear-decay\r\n") + +def parse_stat(): + global farm_list + global sell_list + sell_list = [] + line = tn.read_until(b">",0) # Read one line + result = decode_line(line) + for item_l in farm_list: + x = line.decode('ascii').count(item_l) + for i in range(x): + sell_list.append(item_l) + print(sell_list) + +def index_area(): + global local_items + global local_monsters + end_index = 0 + line = tn.read_until(b">",0) # Read one line + result = decode_line(line) + #Index items + if result.find("On the ground lies:") != -1: + start_index = result.index('On the ground lies:') + item_str = result[start_index:] + try: + end_index = item_str.index('***') + except: + try: + end_index = item_str.index('>') + except: + pass + item_str = item_str[:end_index] + item_str = item_str.replace("On the ground lies:","") + item_str = item_str.replace("0","") + item_str = item_str.replace("1","") + item_str = item_str.replace("2","") + item_str = item_str.replace("3","") + item_str = item_str.replace("4","") + item_str = item_str.replace("5","") + item_str = item_str.replace("6","") + item_str = item_str.replace("7","") + item_str = item_str.replace("8","") + item_str = item_str.replace("9","") + item_str = item_str.replace("(","") + item_str = item_str.replace(")","") + item_str = item_str.replace("A ","") + item_str = item_str.replace("An ","") + item_str = item_str.replace(" ","") + item_str = item_str.replace(".","") + item_str = item_str.replace("\r\n","") + item_str = item_str.replace("***","") + local_items = list(item_str.split(",")) + print(local_items) + + if result.find("here") != -1: + end_index = result.index('here') + monster_str = result[:end_index] + start_index = monster_str.rindex('***') + monster_str = monster_str[start_index:] + monster_str = monster_str.replace("\r\n","") + monster_str = monster_str.replace(" and ","") + monster_str = monster_str.replace(" are ","") + monster_str = monster_str.replace(" is ","") + monster_str = monster_str.replace(" ","") + monster_str = monster_str.replace(".","") + monster_str = monster_str.replace("***","") + local_monsters = list(monster_str.split(",")) + remove_friends() + print(local_monsters) + +def mutants(): + global time_steps + global local_items + global local_monsters + global heal + global wander + global in_combat + global key_detect + global auto_combat + global auto_farm + global auto_ion + global lock_key + global direction_list + + area_indexed = False + while True: + #print(local_items) + time.sleep(.1) + time_steps = time_steps + 1 + #data decode + result = "" + line = None + line = tn.read_until(b"\n",0) # Read one line + result = decode_line(line) + + stat_trigger = time_steps % 600 + if stat_trigger == 0 and not in_combat: + tn.write(b"stat\r\n") + + heal_trigger = time_steps % 20 + if heal_trigger == 0: + if heal: + tn.write(b"heal\r\n") + + #auto farm if sold items + if len(sell_list) == 0 and wander: + auto_farm = True + + #process wander[[ + wander_trigger = time_steps % 30 + if wander and not in_combat: + if wander_trigger == 0: + area_indexed = False + #print("wander triggered") + wander_process(result,wander_trigger) + + if time_steps == 1000: + time_steps = 0 + + #process combat + if in_combat: + combat_process(result) + + #scrapers + if result == "(N)onstop, (Q)uit, or (C)ontinue?": + tn.write(b"N\r\n") + + if result.find("You're starving for IONS!") != -1: + tn.write(b"con gold-chunck\r\n") + auto_ion = True + heal = True + + if wander and result.find("The weight of all your items forces you to the ground.") != -1: + wander = False + tn.write(b"X\r\n") + + if auto_farm and result.find("The Nuclear-Decay fell out of your sack!") != -1: + time_steps = 0 + tn.write(b"con gold-chunck\r\n") + tn.write(b"get nuclear-decay\r\n") + + if auto_farm and result.find("You're not carrying a gold-chunck.") != -1: + auto_farm = False + + if result.find("The Monster-Bait fell out of your sack!") != -1: + time_steps = 0 + tn.write(b"con gold-chunck\r\n") + tn.write(b"get monster-bait\r\n") + + #if wander and result.find("fell out of your sack!") != -1: + #wander = False + #auto_farm = False + + if wander and (result.find("It's too dark to see anything!") != -1 or result.find("You're blocked!") != -1): + direction_list = ["north","south","east","west"] + + if result.find("travel") != -1: + local_monsters = [] + + if result.find("City Trading Centre") != -1: + #print("Sell trigger") + if len(sell_list) > 0: + sell_items() + + if result.find("Compass:") != -1 and area_indexed == False: + index_area() + if wander: + tn.write(b"look\r\n") + area_indexed = True + + if result.find("stat") != -1: + parse_stat() + + if result.find("Nothing happens!") != -1 or result.find("You don't have enough ions to heal!") != -1: + heal = False + + if result.find("You suffer") != -1 or result.find("You are poisoned!") != -1: + heal = True + + #monster list related + if (result.find("yells: Gimmie") != -1 or + result.find("just arrived from") != -1 or + result.find("has hit") != -1 or + result.find("body is glowing") != -1 or + result.find("Get away from me") != -1 or + result.find("has magically appeared") != -1): + m = result.index(' ') + monster = result[:m] + if not search(local_monsters, monster): + local_monsters.append(monster) + remove_friends() + print(local_monsters) + if len(local_monsters) > 0 and auto_combat and not in_combat: + combat_start() + + if result.find("has just left") != -1: + end_index = result.index(' has') + mon_str = result[:end_index] + mon_str = mon_str.replace(" ","") + try: + local_monsters.remove(mon_str) + except: + pass + print(mon_str) + print(local_monsters) + + if result.find("is crumbling to dust") != -1: + end_index = result.index(' is') + mon_str = result[:end_index] + mon_str = mon_str.replace(" ","") + try: + local_monsters.remove(mon_str) + except: + pass + print(mon_str) + print(local_monsters) + + if result.find("picked up the") != -1: + start_index = result.index('the') + 4 + item_str = result[start_index:] + end_index = item_str.index('.') + item_str = item_str[:end_index] + item_str = item_str.replace(" ","") + try: + local_items.remove(item_str) + except: + pass + print(item_str) + print(local_items) + + if result.find("is falling from") != -1: + start_index = result.index('A') + item_str = result[start_index:] + end_index = item_str.index('is') + item_str = item_str[:end_index] + item_str = item_str.replace(" ","") + item_str = item_str.replace("is","") + item_str = item_str.replace("An","") + item_str = item_str.replace("A","") + local_items.append(item_str) + print(local_items) + + if result.find("Select (Bury, 1-5, ?)") != -1: + in_combat=False + heal = False + wander = False + auto_farm = False + auto_ion = False + + #farm items + if len(local_items) > 0 and not in_combat: + if auto_farm: + farm_items() + if auto_ion: + convert_items() + #print("convert") + + #functions + if keyboard.is_pressed(lock_key): + time.sleep(.5) + if key_detect: + key_detect = False + print("Key detect off") + else: + key_detect = True + print("Key detect on") + + if key_detect: + if keyboard.is_pressed("?"): + time.sleep(.5) + for help in help_list: + print(help) + #directions + if keyboard.is_pressed("8"): + local_monsters = [] + local_items = [] + tn.write(b"north\r\n") + area_indexed = False + time.sleep(.25) + if keyboard.is_pressed("2"): + local_monsters = [] + local_items = [] + tn.write(b"south\r\n") + area_indexed = False + time.sleep(.25) + if keyboard.is_pressed("4"): + local_monsters = [] + local_items = [] + tn.write(b"west\r\n") + area_indexed = False + time.sleep(.25) + if keyboard.is_pressed("6"): + local_monsters = [] + local_items = [] + tn.write(b"east\r\n") + area_indexed = False + time.sleep(.25) + #functions + if keyboard.is_pressed("a"): + time.sleep(.5) + if auto_combat: + auto_combat = False + print("Auto combat off") + else: + auto_combat = True + print("Auto combat on") + #Auto Ion + if keyboard.is_pressed("i"): + time.sleep(.5) + if auto_ion: + auto_ion = False + print("Auto ion off") + else: + auto_ion = True + print("Auto ion on") + #Auto farm + if keyboard.is_pressed("f"): + time.sleep(.5) + if auto_farm: + auto_farm = False + print("Auto farm off") + else: + auto_farm = True + print("Auto farm on") + + if keyboard.is_pressed("c"): + if len(local_monsters) > 0: + combat_start() + time.sleep(.25) + if keyboard.is_pressed("5"): + tn.write(b"look ") + time.sleep(.25) + + if keyboard.is_pressed("m"): + time.sleep(.5) + if wander: + wander = False + print("Meander off") + else: + wander = True + print("Meander on") + tn.write(b"look\r\n") + + if keyboard.is_pressed("h"): + tn.write(b"heal\r\n") + heal = True + time.sleep(.25) + if keyboard.is_pressed("l"): + area_indexed == False + tn.write(b"look\r\n") + time.sleep(.25) + if keyboard.is_pressed("m"): + wander = True + if keyboard.is_pressed("v"): + tn.write(b"stat\r\n") + time.sleep(.25) + if keyboard.is_pressed("s"): + sell_items() + time.sleep(.25) + if keyboard.is_pressed("k") and not in_combat: + time.sleep(.25) + flush_input() + #toss = keyboard.read_key() + st = input("Keyboard input: ") + tn.write(st.encode('ascii')+b"\r\n") + flush_input() + + if keyboard.is_pressed("w"): + time.sleep(.25) + tn.write(b"wie nuclear-decay\r\n") + + if keyboard.is_pressed("d"): + time.sleep(.25) + flush_input() + #toss = keyboard.read_key() + st = input("drop item: ") + drop_item = "drop " + st + tn.write(drop_item.encode('ascii')+b"\r\n") + + if keyboard.is_pressed("t") and not in_combat: + monster_list = [] + time.sleep(.25) + flush_input() + #toss = keyboard.read_key() + st = input("year: ") + year = "travel " + st + tn.write(year.encode('ascii')+b"\r\n") + + if keyboard.is_pressed("x"): + break + +user = input("User name:") +password = input("Password:") +lock_key = input("Lock key:") + +while True: + line = None + line = tn.read_until(b"\n",1) # Read one line + if line.decode('cp1252') == "": + #print("break") + #break + pass + else: + ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])') + result = ansi_escape.sub('', line.decode('cp1252').strip('\n')) + print(result) + if result == "Otherwise type \"new\": ": + tn.write(user.encode('ascii')+b"\r\n") + + if result == "Enter your password: ": + tn.write(password.encode('ascii')+b"\r\n") + + if result == "(N)onstop, (Q)uit, or (C)ontinue?": + tn.write(b"Q\r\n") + + if result == "Make your selection (G,T,F,M,S,? for help, or X to exit): ": + tn.write(b"G\r\n") + + if result == "help, or X to exit): ": + tn.write(b"C\r\n") + + if result == "Select (P,I,H,S,W,X,?): ": + tn.write(b"P\r\n") + + if result == "Select (Bury, 1-5, ?) ": + tn.write(b"4\r\n") + mutants() + break + + \ No newline at end of file diff --git a/mutants_localbbs.py b/mutants_localbbs.py new file mode 100644 index 0000000..0459934 --- /dev/null +++ b/mutants_localbbs.py @@ -0,0 +1,526 @@ +import getpass +import telnetlib +import re +import time +import keyboard +import random + +HOST = "192.168.86.34" +user = "epilectrik" +password = "gupass" +tn = telnetlib.Telnet() +tn.open(HOST,2323) + +#static lists +convert_list = ["Ion-Pack","Ion-Decay","Cheese","Nuclear-thong","Skull","Bottle-Cap","Cigarette-Butt","Knife","Gas-Grenade", + "Light-Spear","Silver-Potion","Bastard-Sword","Invisible-Knife","Great-Club","Spear","Blizzard-Staff","Devil_Key","Grey-Dagger","Bone","Axe","BlackJack", + "Golden-Key","Crystal-Key","Trident","Ice-Knife","Iron-Sickle","Gold-Spear","Fang-Dagger","Hound-Fang","Pink-Potion","Small-Dagger","Mage-Stick","Purple-Potion", + "Tree-Branch","Poker","Bronze Knife","Small-Club","Wonderous-Sword","Spell-Potion","Long-Sword","Ion-Gauntlet","Sling-Sword","Green-Vial","Small-Spear", + "Tree-Stump","Saphire","Flame-Sword","Rock-Club","Lava-Dagger","Bloody-Arm"] + +farm_list = ["Gold-Chunck","Nuclear-Rock","Nuclear-Decay","Invisible-Cloth","Troll-Skin","Ion-Booster","Nuclear-Waste"] + +friend_list = ["Epilectrik","ImBait","Mtron","Im"] + +help_list = ["$ - Key listener on/off", + "8 - North", + "2 - South", + "6 - East", + "4 - West", + "5 - Look direction", + "c - Combat", + "w - Wield weapon", + "a - Auto combat on/off", + "f - Auto farm on/off", + "i - Auto Ion on/off", + "t - time travel", + "d - drop item", + "k - keyboard input", + "v - status", + "m - meander" + ] + +#dynamic lists +local_items = [] +local_monsters = [] + +#modes +heal = False +wander = False +auto_combat = False +auto_ion = False +auto_farm = False +key_detect = True +#states +time_steps = 0 +in_combat = False +hits = 0 +lock_key="$" +north_ok = True +south_ok = True +west_ok = True +east_ok = True + + +#Reup Ions +def convert_items(): + global local_items + global convert_list + for item_l in local_items: + for item in convert_list: + if item_l == item: + tn.write(b"get "+item.encode('ascii')+b"\r\n") + tn.write(b"con "+item.encode('ascii')+b"\r\n") + local_items.remove(item_l) + +#Farms valuable stuff +def farm_items(): + global local_items + global farm_list + for item_l in local_items: + for item in farm_list: + if item_l == item: + tn.write(b"get "+item.encode('ascii')+b"\r\n") + local_items.remove(item_l) + +#Remove friends from monster list +def remove_friends(): + global local_monsters + for friend in friend_list: + try: + local_monsters.remove(friend) + except: + pass + +#Flushes keyboard +def flush_input(): + + try: + import msvcrt + while msvcrt.kbhit(): + msvcrt.getch() + except ImportError: + import sys, termios + termios.tcflush(sys.stdin, termios.TCIOFLUSH) + +def decode_line(line): + result = "" + if line.decode('cp1252') != "": + ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])') + result = ansi_escape.sub('', line.decode('cp1252').strip('\n')) + print(result) + return result + +#initiate combat +def combat_start(): + global local_monsters + global in_combat + + tn.write(b"combat " + local_monsters[0].encode('ascii')+b"\r\n") + in_combat = True + heal = True + +#process wander +def wander_process(result) + global heal + global north_ok + global south_ok + global east_ok + global west_ok + + direction_list = [] + + #area clear + if result.find("north - area continues.") != -1: + direction_list.add("north") + if result.find("south - area continues.") != -1: + direction_list.add("south") + if result.find("east - area continues.") != -1: + direction_list.add("east") + if result.find("west - area continues.") != -1: + direction_list.add("west") + + #are there monsters + if result.find("You see shadows to the"): + if result.find("north"): + direction_list.remove("north") + if result.find("south"): + direction_list.remove("south") + if result.find("east"): + direction_list.remove("east") + if result.find("west"): + direction_list.remove("west") + print(direction_list) + #pick randomly + if len(direction_list) > 0: + dir_choice = random.choice(direction_list) + tn.write(dir_choice.encode('ascii')+b"\r\n") + +#process combat per loop +def combat_process(result): + global heal + global hits + global time_steps + global local_monsters + global in_combat + + if result.find("You suffer") != -1: + hits = hits + 1 + if hits == 2: + tn.write(b"heal\r\n") + tn.write(b"heal\r\n") + hits = 0 + + if result.find("have slain") != -1 or result.find("has just left") != -1 or result.find("isn't around here!") != -1 or result.find("You're not ready") != -1: + try: + local_monsters.pop(0) + except: + pass + if len(local_monsters) > 0: + tn.write(b"combat " + local_monsters[0].encode('ascii')+b"\r\n") + else: + print("Area cleared") + in_combat = False + + wield = time_steps % 5 + + if wield == 0: + tn.write(b"wie nuclear-decay\r\n") + +def index_area(): + global local_items + global local_monsters + line = tn.read_until(b">",0) # Read one line + result = decode_line(line) + #Index items + if result.find("On the ground lies:") != -1: + start_index = result.index('On the ground lies:') + item_str = result[start_index:] + try: + end_index = item_str.index('***') + except: + end_index = item_str.index('>') + item_str = item_str[:end_index] + item_str = item_str.replace("On the ground lies:","") + item_str = item_str.replace("0","") + item_str = item_str.replace("1","") + item_str = item_str.replace("2","") + item_str = item_str.replace("3","") + item_str = item_str.replace("4","") + item_str = item_str.replace("5","") + item_str = item_str.replace("6","") + item_str = item_str.replace("7","") + item_str = item_str.replace("8","") + item_str = item_str.replace("9","") + item_str = item_str.replace("(","") + item_str = item_str.replace(")","") + item_str = item_str.replace("A ","") + item_str = item_str.replace("An ","") + item_str = item_str.replace(" ","") + item_str = item_str.replace(".","") + item_str = item_str.replace("\r\n","") + item_str = item_str.replace("***","") + local_items = list(item_str.split(",")) + print(local_items) + + if result.find("here") != -1: + end_index = result.index('here') + monster_str = result[:end_index] + start_index = monster_str.rindex('***') + monster_str = monster_str[start_index:] + monster_str = monster_str.replace("\r\n","") + monster_str = monster_str.replace(" and ","") + monster_str = monster_str.replace(" are ","") + monster_str = monster_str.replace(" is ","") + monster_str = monster_str.replace(" ","") + monster_str = monster_str.replace(".","") + monster_str = monster_str.replace("***","") + local_monsters = list(monster_str.split(",")) + remove_friends() + print(local_monsters) + +def mutants(): + global time_steps + global local_items + global local_monsters + global heal + global wander + global in_combat + global key_detect + global auto_combat + global auto_farm + global auto_ion + global lock_key + + while True: + #print(local_items) + time.sleep(.1) + time_steps = time_steps + 1 + #data decode + result = "" + line = None + line = tn.read_until(b"\n",0) # Read one line + result = decode_line(line) + + heal_trigger = time_steps % 20 + if heal_trigger == 0: + if heal: + tn.write(b"heal\r\n") + + #process wander + wander_trigger = time_steps % 50 + if wander: + process_wander(result) + + if time_steps == 1000: + time_steps = 0 + + #process combat + if in_combat: + combat_process(result) + + #scrapers + if result == "(N)onstop, (Q)uit, or (C)ontinue?": + tn.write(b"N\r\n") + + if result.find("travel") != -1: + local_monsters = [] + + if result.find("Compass:") != -1: + index_area() + + if result.find("Nothing happens!") != -1 or result.find("You don't have enough ions to heal!") != -1: + heal = False + + if result.find("You suffer") != -1 or result.find("You are poisoned!") != -1: + heal = True + + #monster list related + if result.find("yells: Gimmie") != -1 or result.find("just arrived from") != -1 or result.find("has magically appeared") != -1: + m = result.index(' ') + monster = result[:m] + local_monsters.append(monster) + remove_friends() + print(local_monsters) + if len(local_monsters) > 0 and auto_combat: + combat_start() + + if result.find("has just left") != -1: + end_index = result.index(' has') + mon_str = result[:end_index] + mon_str = mon_str.replace(" ","") + try: + local_monsters.remove(mon_str) + except: + pass + print(mon_str) + print(local_monsters) + + if result.find("is crumbling to dust") != -1: + end_index = result.index(' is') + mon_str = result[:end_index] + mon_str = mon_str.replace(" ","") + try: + local_monsters.remove(mon_str) + except: + pass + print(mon_str) + print(local_monsters) + + if result.find("picked up the") != -1: + start_index = result.index('the') + 4 + item_str = result[start_index:] + end_index = item_str.index('.') + item_str = item_str[:end_index] + item_str = item_str.replace(" ","") + try: + local_items.remove(item_str) + except: + pass + print(item_str) + print(local_items) + + if result.find("is falling from") != -1: + start_index = result.index('A') + item_str = result[start_index:] + end_index = item_str.index('is') + item_str = item_str[:end_index] + item_str = item_str.replace(" ","") + item_str = item_str.replace("is","") + item_str = item_str.replace("An","") + item_str = item_str.replace("A","") + local_items.append(item_str) + print(local_items) + + if result.find("Select (Bury, 1-5, ?)") != -1: + in_combat=False + heal = False + + #farm items + if len(local_items) > 0: + if auto_farm: + farm_items() + if auto_ion: + convert_items() + #print("convert") + + #functions + if keyboard.is_pressed(lock_key): + time.sleep(.5) + if key_detect: + key_detect = False + print("Key detect off") + else: + key_detect = True + print("Key detect on") + + if key_detect: + if keyboard.is_pressed("?"): + time.sleep(.5) + for help in help_list: + print(help) + #directions + if keyboard.is_pressed("8"): + local_monsters = [] + local_items = [] + tn.write(b"north\r\n") + time.sleep(.25) + if keyboard.is_pressed("2"): + local_monsters = [] + local_items = [] + tn.write(b"south\r\n") + time.sleep(.25) + if keyboard.is_pressed("4"): + local_monsters = [] + local_items = [] + tn.write(b"west\r\n") + time.sleep(.25) + if keyboard.is_pressed("6"): + local_monsters = [] + local_items = [] + tn.write(b"east\r\n") + time.sleep(.25) + #functions + if keyboard.is_pressed("a"): + time.sleep(.5) + if auto_combat: + auto_combat = False + print("Auto combat off") + else: + auto_combat = True + print("Auto combat on") + #Auto Ion + if keyboard.is_pressed("i"): + time.sleep(.5) + if auto_ion: + auto_ion = False + print("Auto ion off") + else: + auto_ion = True + print("Auto ion on") + #Auto farm + if keyboard.is_pressed("f"): + time.sleep(.5) + if auto_farm: + auto_farm = False + print("Auto farm off") + else: + auto_farm = True + print("Auto farm on") + + if keyboard.is_pressed("c"): + if len(local_monsters) > 0: + combat_start() + time.sleep(.25) + if keyboard.is_pressed("5"): + tn.write(b"look ") + time.sleep(.25) + + if keyboard.is_pressed("m"): + time.sleep(.5) + if wander: + wander = False + print("Meander off") + else: + wander = True + print("Meander on") + + if keyboard.is_pressed("h"): + tn.write(b"heal\r\n") + heal = True + time.sleep(.25) + if keyboard.is_pressed("l"): + tn.write(b"look\r\n") + time.sleep(.25) + if keyboard.is_pressed("m"): + wander = True + if keyboard.is_pressed("v"): + tn.write(b"stat\r\n") + time.sleep(.25) + if keyboard.is_pressed("s"): + tn.write(b"sell gold-chunck\r\n") + time.sleep(.25) + if keyboard.is_pressed("k"): + time.sleep(.25) + flush_input() + #toss = keyboard.read_key() + st = input("Keyboard input: ") + tn.write(st.encode('ascii')+b"\r\n") + flush_input() + + if keyboard.is_pressed("d"): + time.sleep(.25) + flush_input() + #toss = keyboard.read_key() + st = input("drop item: ") + drop_item = "drop " + st + tn.write(drop_item.encode('ascii')+b"\r\n") + + if keyboard.is_pressed("t"): + monster_list = [] + time.sleep(.25) + flush_input() + #toss = keyboard.read_key() + st = input("year: ") + year = "travel " + st + tn.write(year.encode('ascii')+b"\r\n") + + if keyboard.is_pressed("x"): + break + +user = input("User name:") +password = input("Password:") +lock_key = input("Lock key:") + +while True: + line = None + line = tn.read_until(b"\n",1) # Read one line + if line.decode('cp1252') == "": + #print("break") + #break + pass + else: + ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])') + result = ansi_escape.sub('', line.decode('cp1252').strip('\n')) + print(result) + if result == "Username: ": + tn.write(user.encode('ascii')+b"\r\n") + + if result == "Password: ": + tn.write(password.encode('ascii')+b"\r\n") + + if result == "(N)onstop, (Q)uit, or (C)ontinue?": + tn.write(b"Q\r\n") + + if result == "Make your selection (X to exit): ": + tn.write(b"1\r\n") + + if result == "Select (P,I,H,S,W,X,?): ": + tn.write(b"P\r\n") + + if result == "Select (Bury, 1-5, ?) ": + tn.write(b"4\r\n") + mutants() + break + + \ No newline at end of file diff --git a/mutants_paths.py b/mutants_paths.py new file mode 100644 index 0000000..cba085a --- /dev/null +++ b/mutants_paths.py @@ -0,0 +1,812 @@ +import getpass +import telnetlib +import re +import time +import keyboard +import random + +HOST = "telnet.goldenunicorn.net" +user = "epilectrik" +password = "gupass" +tn = telnetlib.Telnet() +tn.open(HOST,23) + +#static lists +convert_list = ["Ion-Pack","Ion-Decay","Cheese","Nuclear-thong","Skull","Bottle-Cap","Cigarette-Butt","Knife","Gas-Grenade", + "Light-Spear","Silver-Potion","Bastard-Sword","Invisible-Knife","Great-Club","Spear","Blizzard-Staff","Devil_Key","Grey-Dagger","Bone","Axe","BlackJack", + "Golden-Key","Crystal-Key","Trident","Ice-Knife","Iron-Sickle","Gold-Spear","Fang-Dagger","Hound-Fang","Pink-Potion","Small-Dagger","Mage-Stick","Purple-Potion", + "Tree-Branch","Poker","Bronze Knife","Small-Club","Wonderous-Sword","Spell-Potion","Long-Sword","Ion-Gauntlet","Sling-Sword","Green-Vial","Small-Spear", + "Tree-Stump","Saphire","Flame-Sword","Rock-Club","Lava-Dagger","Bloody-Arm","Golden-Needle","Ion-Booster"] + +farm_list = ["Gold-Chunck","Nuclear-Rock","Nuclear-Waste"] + +stock_list = ["Nuclear-Decay","Troll-Skin","Invisible-Cloth","Hell-Blade",""] + +friend_list = ["Epilectrik","ImBait","Mtron","Im"] + +help_list = ["$ - Key listener on/off", + "8 - North", + "2 - South", + "6 - East", + "4 - West", + "5 - Look direction", + "c - Combat", + "w - Wield weapon", + "a - Auto combat on/off", + "f - Auto farm on/off", + "i - Auto Ion on/off", + "t - time travel", + "d - drop item", + "k - keyboard input", + "v - status", + "m - meander" + ] + +#dynamic lists +local_items = [] +local_monsters = [] + +#modes +heal = False +wander = False +auto_combat = False +auto_ion = False +auto_farm = False +key_detect = True +#states +time_steps = 0 +in_combat = False +hits = 0 +lock_key="$" +direction_list = [] +sell_list = [] +previous_dir = "" +selected_path = 0 +path_step = 0 +riblets = 0 +riblet_thresh = 100000 +farm_year=2000 +year_limit=2500 +no_action_cnt = 0 +na_thresh = 50 + +path_list = [ + ["done","tra 2000","south","deposit "+str(riblet_thresh),"stat","tra "+str(farm_year),"done"], + ["done","tra 2000","east","east","east","deposit "+str(riblet_thresh),"stat","tra "+str(farm_year),"done"], + ["done","tra 2000","south","south","south","south","south","south","west","west","west","north","deposit "+str(riblet_thresh),"stat","tra "+str(farm_year),"done"] + ] + +opposite_dir = { + "north":"south", + "south":"north", + "east":"west", + "west":"east", +} + +#search a list +def search(list, platform): + for i in range(len(list)): + if list[i] == platform: + return True + return False + +#Reup Ions +def convert_items(): + global local_items + global convert_list + for item_l in local_items: + for item in convert_list: + if item_l == item: + tn.write(b"get "+item.encode('ascii')+b"\r\n") + tn.write(b"con "+item.encode('ascii')+b"\r\n") + local_items.remove(item_l) + +#Farms valuable stuff +def farm_items(): + global local_items + global farm_list + global sell_list + global no_action_cnt + + for item_l in local_items: + for item in farm_list: + if item_l == item: + tn.write(b"get "+item.encode('ascii')+b"\r\n") + local_items.remove(item_l) + sell_list.append(item_l) + no_action_cnt = 0 + +#Sell items +def sell_items(): + global sell_list + print(sell_list) + while len(sell_list) > 0: + item_l=sell_list[0] + sell_list.pop(0) + if item_l != "Nuclear-Decay": + tn.write(b"sell "+item_l.encode('ascii')+b"\r\n") + time.sleep(.25) + + +#Remove friends from monster list +def remove_friends(): + global local_monsters + for friend in friend_list: + try: + local_monsters.remove(friend) + except: + pass + +#Flushes keyboard +def flush_input(): + + try: + import msvcrt + while msvcrt.kbhit(): + msvcrt.getch() + except ImportError: + import sys, termios + termios.tcflush(sys.stdin, termios.TCIOFLUSH) + +#Decode incoming information +def decode_line(line): + result = "" + if line.decode('cp1252') != "": + ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])') + result = ansi_escape.sub('', line.decode('cp1252').strip('\n')) + print(result) + return result + +#initiate combat +def combat_start(): + global local_monsters + global in_combat + global path_step + global no_action_cnt + + tn.write(b"combat " + local_monsters[0].encode('ascii')+b"\r\n") + in_combat = True + heal = True + path_step = 0 + no_action_cnt = 0 + +#process wander +def wander_process(result,wander_trigger): + global heal + global direction_list + global previous_dir + global local_monsters + global local_items + global no_action_cnt + + #area clear + if result.find("north - area continues.") != -1 or result.find("north - open gate.") != -1: + direction_list.append("north") + if result.find("south - area continues.") != -1 or result.find("south - open gate.") != -1: + direction_list.append("south") + if result.find("east - area continues.") != -1 or result.find("east - open gate.") != -1: + direction_list.append("east") + if result.find("west - area continues.") != -1 or result.find("west - open gate.") != -1: + direction_list.append("west") + + #are there monsters + if result.find("You see shadows to the") != -1: + try: + if result.find("north") != -1: + direction_list.remove("north") + if result.find("south") != -1: + direction_list.remove("south") + if result.find("east") != -1: + direction_list.remove("east") + if result.find("west") != -1: + direction_list.remove("west") + except: + pass + + if wander_trigger == 0: + print("wander triggered") + print("no action: " + str(no_action_cnt)) + #increment no action counter + no_action_cnt = no_action_cnt + 1 + if len(direction_list) == 0: + tn.write(b"look\r\n") + local_monsters = [] + local_items = [] + + #pick randomly + if len(direction_list) > 0 and wander_trigger == 0: + if len(direction_list) > 1: + try: + direction_list.remove(previous_dir) + except: + pass + print(direction_list) + dir_choice = random.choice(direction_list) + tn.write(dir_choice.encode('ascii')+b"\r\n") + direction_list = [] + previous_dir = opposite_dir[dir_choice] + +#process combat per loop +def combat_process(result): + global heal + global hits + global time_steps + global local_monsters + global in_combat + + if result.find("You suffer") != -1: + hits = hits + 1 + if hits == 2: + tn.write(b"heal\r\n") + tn.write(b"heal\r\n") + hits = 0 + + if result.find("have slain") != -1 or result.find("has just left") != -1 or result.find("isn't around here!") != -1 or result.find("You're not ready") != -1: + try: + local_monsters.pop(0) + except: + pass + if len(local_monsters) > 0: + tn.write(b"combat " + local_monsters[0].encode('ascii')+b"\r\n") + else: + print("Area cleared") + in_combat = False + + wield = time_steps % 10 + + if wield == 0: + tn.write(b"wie nuclear-decay\r\n") + +#time travel +def time_travel(): + global farm_year + global year_limit + farm_year = farm_year + 100 + if farm_year > year_limit: + farm_year = 2000 + tn.write(b"tra "+str(farm_year).encode('ascii')+b"\r\n") + +#process path +def path_process(): + global selected_path + global path_step + path_str = path_list[selected_path][path_step] + if path_str != "done": + tn.write(path_str.encode('ascii')+b"\r\n") + path_step = path_step + 1 + else: + path_step = 0 + +#process stats +def parse_stat(): + global farm_list + global sell_list + global riblets + sell_list = [] + line = tn.read_until(b">",0) # Read one line + result = decode_line(line) + for item_l in farm_list: + x = line.decode('ascii').count(item_l) + for i in range(x): + sell_list.append(item_l) + + if result.find("Riblets :") != -1: + start_index = result.index('Riblets : ') + 16 + riblets_str = result[start_index:] + try: + end_index = riblets_str.index(' ') + except: + pass + riblets_str = riblets_str[:end_index] + print("Riblets:" + riblets_str) + riblets = int(riblets_str) + print(sell_list) + +#index area +def index_area(): + global local_items + global local_monsters + end_index = 0 + line = tn.read_until(b">",0) # Read one line + result = decode_line(line) + #Index items + if result.find("On the ground lies:") != -1: + start_index = result.index('On the ground lies:') + item_str = result[start_index:] + try: + end_index = item_str.index('***') + except: + try: + end_index = item_str.index('>') + except: + pass + item_str = item_str[:end_index] + item_str = item_str.replace("On the ground lies:","") + item_str = item_str.replace("0","") + item_str = item_str.replace("1","") + item_str = item_str.replace("2","") + item_str = item_str.replace("3","") + item_str = item_str.replace("4","") + item_str = item_str.replace("5","") + item_str = item_str.replace("6","") + item_str = item_str.replace("7","") + item_str = item_str.replace("8","") + item_str = item_str.replace("9","") + item_str = item_str.replace("(","") + item_str = item_str.replace(")","") + item_str = item_str.replace("A ","") + item_str = item_str.replace("An ","") + item_str = item_str.replace(" ","") + item_str = item_str.replace(".","") + item_str = item_str.replace("\r\n","") + item_str = item_str.replace("***","") + local_items = list(item_str.split(",")) + print(local_items) + + if result.find("here") != -1: + end_index = result.index('here') + monster_str = result[:end_index] + start_index = monster_str.rindex('***') + monster_str = monster_str[start_index:] + monster_str = monster_str.replace("\r\n","") + monster_str = monster_str.replace(" and ","") + monster_str = monster_str.replace(" are ","") + monster_str = monster_str.replace(" is ","") + monster_str = monster_str.replace(" ","") + monster_str = monster_str.replace(".","") + monster_str = monster_str.replace("***","") + local_monsters = list(monster_str.split(",")) + remove_friends() + print(local_monsters) + +#main game loop +def mutants(): + global time_steps + global local_items + global local_monsters + global heal + global wander + global in_combat + global key_detect + global auto_combat + global auto_farm + global auto_ion + global lock_key + global direction_list + global selected_path + global path_step + global path_list + global riblets + global no_action_cnt + global na_thresh + global year_limit + global farm_year + + area_indexed = False + while True: + #print(local_items) + time.sleep(.1) + time_steps = time_steps + 1 + + #data decode + result = "" + line = None + line = tn.read_until(b"\n",0) # Read one line + result = decode_line(line) + + #Nothing has happened in a while, time jump + if no_action_cnt > na_thresh: + time_travel() + no_action_cnt = 0 + + #deposit riblets + if riblets > riblet_thresh and path_step == 0: + path_step = 1 + + #follow path_list + path_trigger = time_steps % 10 + if path_trigger == 0 and not in_combat: + path_process() + + #parse status + stat_trigger = time_steps % 600 + if stat_trigger == 0 and not in_combat: + tn.write(b"stat\r\n") + + #heal + heal_trigger = time_steps % 20 + if heal_trigger == 0: + if heal: + tn.write(b"heal\r\n") + + #auto farm if sold items + if len(sell_list) == 0 and wander: + auto_farm = True + + #process wander + wander_trigger = time_steps % 30 + if wander and not in_combat and path_step == 0: + if wander_trigger == 0: + area_indexed = False + #print("wander triggered") + wander_process(result,wander_trigger) + + #Reset time steps + if time_steps == 1000: + time_steps = 0 + + #process combat + if in_combat: + combat_process(result) + + #scrapers + if result == "(N)onstop, (Q)uit, or (C)ontinue?": + tn.write(b"N\r\n") + + #ion starvation + if result.find("You're starving for IONS!") != -1: + tn.write(b"con gold-chunck\r\n") + auto_ion = True + heal = True + + #too heavy + if wander and result.find("The weight of all your items forces you to the ground.") != -1: + wander = False + tn.write(b"X\r\n") + + #dropped your weapon! + if auto_farm and result.find("The Nuclear-Decay fell out of your sack!") != -1: + time_steps = 0 + tn.write(b"con gold-chunck\r\n") + tn.write(b"get nuclear-decay\r\n") + + #I can't remember why I did this + if auto_farm and result.find("You're not carrying a gold-chunck.") != -1: + auto_farm = False + + #Dropped the bait, pick it back up + if result.find("The Monster-Bait fell out of your sack!") != -1: + time_steps = 0 + tn.write(b"con gold-chunck\r\n") + tn.write(b"get monster-bait\r\n") + + #if wander and result.find("fell out of your sack!") != -1: + #wander = False + #auto_farm = False + + #GTFO + if wander and ((result.find("It's too dark to see anything!") != -1 or + result.find("has hit you with his Nuclear-Decay!") != -1 or + result.find("You're blocked!") != -1) or + len(local_monsters) > 4): + + heal = True + tn.write(b"tra "+str(farm_year).encode('ascii')+b"\r\n") + in_combat = False + + #Sell the loot + if result.find("City Trading Centre") != -1: + if len(sell_list) > 0: + sell_items() + + #New area, take a look + if result.find("Compass:") != -1 and area_indexed == False: + index_area() + if wander: + tn.write(b"look\r\n") + area_indexed = True + + #Parse character status + if result.find("stat") != -1: + parse_stat() + + #Trigger stop healing + if result.find("Nothing happens!") != -1 or result.find("You don't have enough ions to heal!") != -1: + heal = False + + #Turn on healing + if result.find("You suffer") != -1 or result.find("You are poisoned!") != -1: + heal = True + + #monster list related + if (result.find("yells: Gimmie") != -1 or + result.find("just arrived from") != -1 or + result.find("has hit") != -1 or + result.find("body is glowing") != -1 or + result.find("Get away from me") != -1 or + result.find("has magically appeared") != -1): + m = result.index(' ') + monster = result[:m] + if not search(local_monsters, monster): + local_monsters.append(monster) + remove_friends() + print(local_monsters) + if len(local_monsters) > 0 and auto_combat and not in_combat: + combat_start() + + #Monster took off, remove from list + if result.find("has just left") != -1: + end_index = result.index(' has') + mon_str = result[:end_index] + mon_str = mon_str.replace(" ","") + try: + local_monsters.remove(mon_str) + except: + pass + print(mon_str) + print(local_monsters) + + #Monster died, remove from list + if result.find("is crumbling to dust") != -1: + end_index = result.index(' is') + mon_str = result[:end_index] + mon_str = mon_str.replace(" ","") + try: + local_monsters.remove(mon_str) + except: + pass + print(mon_str) + print(local_monsters) + + #Someone picked something up, remove from item list + if result.find("picked up the") != -1: + start_index = result.index('the') + 4 + item_str = result[start_index:] + end_index = item_str.index('.') + item_str = item_str[:end_index] + item_str = item_str.replace(" ","") + try: + local_items.remove(item_str) + except: + pass + print(item_str) + print(local_items) + + #Dead person dropping stuff, add to local list + if result.find("is falling from") != -1: + start_index = result.index('A') + item_str = result[start_index:] + end_index = item_str.index('is') + item_str = item_str[:end_index] + item_str = item_str.replace(" ","") + item_str = item_str.replace("is","") + item_str = item_str.replace("An","") + item_str = item_str.replace("A","") + local_items.append(item_str) + print(local_items) + + #You died, do some stuff + if result.find("Select (Bury, 1-5, ?)") != -1: + in_combat=False + heal = False + wander = False + auto_farm = False + auto_ion = False + + #farm items + if len(local_items) > 0 and not in_combat: + if auto_farm: + farm_items() + if auto_ion: + convert_items() + #print("convert") + + #keyboard related - this part sucks + if keyboard.is_pressed(lock_key): + time.sleep(.5) + if key_detect: + key_detect = False + print("Key detect off") + else: + key_detect = True + print("Key detect on") + + if key_detect: + if keyboard.is_pressed("?"): + time.sleep(.5) + for help in help_list: + print(help) + + #directions + if keyboard.is_pressed("8"): + local_monsters = [] + local_items = [] + tn.write(b"north\r\n") + area_indexed = False + time.sleep(.25) + if keyboard.is_pressed("2"): + local_monsters = [] + local_items = [] + tn.write(b"south\r\n") + area_indexed = False + time.sleep(.25) + if keyboard.is_pressed("4"): + local_monsters = [] + local_items = [] + tn.write(b"west\r\n") + area_indexed = False + time.sleep(.25) + if keyboard.is_pressed("6"): + local_monsters = [] + local_items = [] + tn.write(b"east\r\n") + area_indexed = False + time.sleep(.25) + #functions + if keyboard.is_pressed("a"): + time.sleep(.5) + if auto_combat: + auto_combat = False + print("Auto combat off") + else: + auto_combat = True + print("Auto combat on") + #Auto Ion + if keyboard.is_pressed("i"): + time.sleep(.5) + if auto_ion: + auto_ion = False + print("Auto ion off") + else: + auto_ion = True + print("Auto ion on") + #Auto farm + if keyboard.is_pressed("f"): + time.sleep(.5) + if auto_farm: + auto_farm = False + print("Auto farm off") + else: + auto_farm = True + print("Auto farm on") + + #Year limit + if keyboard.is_pressed("y"): + time.sleep(.25) + flush_input() + st = input("Year limit: ") + year_limit = int(st) + + #No action threshhold + if keyboard.is_pressed("n"): + time.sleep(.25) + flush_input() + st = input("No action: ") + na_thresh = int(st) + + #Start combat + if keyboard.is_pressed("c"): + if len(local_monsters) > 0: + combat_start() + time.sleep(.25) + + #Start Combat + if keyboard.is_pressed("c"): + if len(local_monsters) > 0: + combat_start() + time.sleep(.25) + + #look around + if keyboard.is_pressed("5"): + tn.write(b"look ") + time.sleep(.25) + + #meander status + if keyboard.is_pressed("m"): + time.sleep(.5) + if wander: + wander = False + print("Meander off") + else: + wander = True + print("Meander on") + tn.write(b"look\r\n") + + #heal + if keyboard.is_pressed("h"): + tn.write(b"heal\r\n") + heal = True + time.sleep(.25) + + #look around + if keyboard.is_pressed("l"): + area_indexed = False + tn.write(b"look\r\n") + time.sleep(.25) + + #stats + if keyboard.is_pressed("v"): + tn.write(b"stat\r\n") + time.sleep(.25) + + #sell items + if keyboard.is_pressed("s"): + sell_items() + time.sleep(.25) + + #store path select + if keyboard.is_pressed("p") and not in_combat: + time.sleep(.25) + flush_input() + #toss = keyboard.read_key() + st = input("Choose path input: ") + selected_path = int(st) + path_step = 1 + tn.write(b"Starting path..\r\n") + flush_input() + + #read keyboard + if keyboard.is_pressed("k") and not in_combat: + time.sleep(.25) + flush_input() + #toss = keyboard.read_key() + st = input("Keyboard input: ") + tn.write(st.encode('ascii')+b"\r\n") + flush_input() + + #wield weapon + if keyboard.is_pressed("w"): + time.sleep(.25) + tn.write(b"wie nuclear-decay\r\n") + + #drop item + if keyboard.is_pressed("d"): + time.sleep(.25) + flush_input() + #toss = keyboard.read_key() + st = input("drop item: ") + drop_item = "drop " + st + tn.write(drop_item.encode('ascii')+b"\r\n") + + #time travel + if keyboard.is_pressed("t") and not in_combat: + monster_list = [] + time.sleep(.25) + flush_input() + #toss = keyboard.read_key() + st = input("year: ") + year = "travel " + st + tn.write(year.encode('ascii')+b"\r\n") + + if keyboard.is_pressed("x"): + break + +user = input("User name:") +password = input("Password:") +lock_key = input("Lock key:") + +while True: + line = None + line = tn.read_until(b"\n",1) # Read one line + if line.decode('cp1252') == "": + #print("break") + #break + pass + else: + ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])') + result = ansi_escape.sub('', line.decode('cp1252').strip('\n')) + print(result) + if result == "Otherwise type \"new\": ": + tn.write(user.encode('ascii')+b"\r\n") + + if result == "Enter your password: ": + tn.write(password.encode('ascii')+b"\r\n") + + if result == "(N)onstop, (Q)uit, or (C)ontinue?": + tn.write(b"Q\r\n") + + if result == "Make your selection (G,T,F,M,S,? for help, or X to exit): ": + tn.write(b"G\r\n") + + if result == "help, or X to exit): ": + tn.write(b"C\r\n") + + if result == "Select (P,I,H,S,W,X,?): ": + tn.write(b"P\r\n") + + if result == "Select (Bury, 1-5, ?) ": + tn.write(b"4\r\n") + mutants() + break + + \ No newline at end of file diff --git a/qmutants.py b/qmutants.py new file mode 100644 index 0000000..e6be01e --- /dev/null +++ b/qmutants.py @@ -0,0 +1,1341 @@ +from PyQt5.QtGui import * +from PyQt5.QtWidgets import * +from PyQt5.QtCore import * + +import os +import getpass +import telnetlib +import re +import time +import keyboard +import random +import sys +import paho.mqtt.client as mqtt + +HOST = "telnet.goldenunicorn.net" + +usr_1 = "epilectrik" +pwrd_1 = "gupass" + +usr_2 = "im bait" +pwrd_2 = "gupass" + +#static lists +convert_list = ["Ion-Pack","Ion-Decay","Cheese","Nuclear-thong","Skull","Bottle-Cap","Cigarette-Butt","Knife","Gas-Grenade","Leather-Vest","Buckler","Bola","Bug-Plate", + "Light-Spear","Silver-Potion","Bastard-Sword","Invisible-Knife","Great-Club","Spear","Blizzard-Staff","Devil_Key","Grey-Dagger","Bone","Axe","BlackJack", + "Golden-Key","Crystal-Key","Trident","Ice-Knife","Iron-Sickle","Gold-Spear","Fang-Dagger","Hound-Fang","Pink-Potion","Small-Dagger","Mage-Stick","Purple-Potion", + "Tree-Branch","Poker","Bronze Knife","Small-Club","Wonderous-Sword","Spell-Potion","Long-Sword","Ion-Gauntlet","Sling-Sword","Small-Spear","Iron-Mace","Iron-Boots", + "Tree-Stump","Saphire","Flame-Sword","Rock-Club","Lava-Dagger","Bloody-Arm","Golden-Needle","Ion-Booster","Devil-Key","Chain-Mail","Weak-Cloth","Splint-Mail","Rags", + "Bug-Skin","Troll-Sword","Axe","Plate-Mail","Common-Hide","Kelp-Mail"] + +farm_sell_list = ["Gold-Chunck","Nuclear-Rock","Nuclear-Waste"] + +farm_stock_list = ["Nuclear-Decay","Troll-Skin","Invisible-Cloth","Green-Vial","Hell-Blade"] + +friend_list = ["Epilectrik","ImBait","Mtron","Im","IonJunkies-Merc"] + +help_list = ["$ - Key listener on/off", + "8 - North", + "2 - South", + "6 - East", + "4 - West", + "5 - Look direction", + "c - Combat", + "w - Wield weapon", + "a - Auto combat on/off", + "f - Auto farm on/off", + "i - Auto Ion on/off", + "t - time travel", + "d - drop item", + "k - keyboard input", + "v - status", + "m - meander" + ] + +opposite_dir = { + "north":"south", + "south":"north", + "east":"west", + "west":"east", +} + +#Heater popup window +class mutant(QWidget): + command_str = pyqtSignal(str) + mqtt_str = pyqtSignal(str) + + def __init__(self,user,password): + QWidget.__init__(self) + #file related + self.path=user + + #dynamic lists + self.local_items = [] + self.local_monsters = [] + self.direction_list = [] + self.sell_list = [] + self.stock_list = [] + self.bank_list = [] + + #modes + self.heal = False + self.wander = False + self.bait = False + self.auto_combat = True + self.auto_ion = False + self.auto_farm = False + self.key_detect = False + + #states + self.time_steps = 0 + self.in_combat = False + self.hits = 0 + self.lock_key="[" + self.area_indexed = True + self.stat_parsed = True + self.previous_dir = "" + self.selected_path = 0 + self.path_step = 0 + self.location = [0,0] + + #value tracking + self.riblets = 0 + self.riblet_thresh = 200000 + self.farm_year=2000 + self.year_limit=2500 + self.no_action_cnt = 0 + self.na_thresh = 50 + self.status = "" + self.area = "" + + #account + self.user = user + self.password = password + self.logged_in = False + + #timers + + #healing + self.heal_timer = QTimer() + self.heal_timer.setInterval(1000) + self.heal_timer.timeout.connect(self.heal_trig) + self.heal_timer.start() + #wielding + self.wield_timer = QTimer() + self.wield_timer.setInterval(200) + self.wield_timer.timeout.connect(self.wield_trig) + self.wield_timer.start() + #wander + self.wander_timer = QTimer() + self.wander_timer.setInterval(500) + self.wander_timer.timeout.connect(self.wander_trig) + self.wander_timer.start() + #stat + self.stat_timer = QTimer() + self.stat_timer.setInterval(30000) + self.stat_timer.timeout.connect(self.stat_trig) + self.stat_timer.start() + #path + self.path_timer = QTimer() + self.path_timer.setInterval(100) + self.path_timer.timeout.connect(self.path_trig) + self.path_timer.start() + + #layout stuff + self.layout = QVBoxLayout() + + # Add console + self.console = QTextEdit() + self.console.setTextColor(QColor(255, 255, 255)) + self.console.setStyleSheet("QTextEdit { color: white; background-color: rgb(0, 0, 0); font-size: 18px; }") + self.console.clear() + self.console.append("test") + self.layout.addWidget(self.console) + + #Add buttons + self.button_group() + + # Add text input + self.formGroupBox = QFormLayout() + self.text_input = QLineEdit() + self.text_button = QPushButton("Send") + self.text_button.clicked.connect(self.send_str) + self.formGroupBox.addRow(self.text_button,self.text_input) + self.layout.addLayout(self.formGroupBox) + + #mode group + self.createModeGroup() + self.layout.addLayout(self.mode_layout) + + #settings group + self.createSettingsGroup() + self.layout.addLayout(self.settingsGroupBox) + + self.setLayout(self.layout) + self.load_bank_paths() + self.init_telnet() + + def init_telnet(self): + + #init telnet thread + self.tn_obj = telnet_thread() + self.tn_thread = QThread() + self.tn_obj.moveToThread(self.tn_thread) + + #Connect signals + self.tn_thread.started.connect(self.tn_obj.telnet_listen) + self.tn_obj.received.connect(self.execute_loop) + self.command_str.connect(self.tn_obj.tn_write) + self.tn_obj.disconnected.connect(self.reconnect) + #start thread + self.tn_thread.start() + + def reconnect(self): + self.logged_in = False + print("obj restarting") + #create buttons + def button_group(self): + hbox1 = QHBoxLayout() + b_grid = QGridLayout() + button_w = 50 + north_button = QPushButton("North") + south_button = QPushButton("South") + east_button = QPushButton("East") + west_button = QPushButton("West") + heal_button = QPushButton("Heal") + combat_button = QPushButton("Combat") + path_button = QPushButton("Path") + look_button = QPushButton("Look") + stat_button = QPushButton("Stat") + + b_grid.addWidget(north_button,0,1) + b_grid.addWidget(south_button,2,1) + b_grid.addWidget(east_button,1,2) + b_grid.addWidget(west_button,1,0) + b_grid.addWidget(heal_button,0,0) + b_grid.addWidget(combat_button,0,2) + b_grid.addWidget(path_button,2,0) + b_grid.addWidget(look_button,1,1) + b_grid.addWidget(stat_button,2,2) + + hbox1.addItem(QSpacerItem(150, 0, QSizePolicy.Minimum)) + hbox1.addLayout(b_grid) + hbox1.addItem(QSpacerItem(150, 0, QSizePolicy.Minimum)) + + north_button.clicked.connect(self.n_btn) + south_button.clicked.connect(self.s_btn) + east_button.clicked.connect(self.e_btn) + west_button.clicked.connect(self.w_btn) + heal_button.clicked.connect(self.h_btn) + combat_button.clicked.connect(self.c_btn) + path_button.clicked.connect(self.p_btn) + look_button.clicked.connect(self.l_btn) + stat_button.clicked.connect(self.st_btn) + + self.layout.addLayout(hbox1) + + #Creates the form groupbox + def createModeGroup(self): + self.mode_layout = QVBoxLayout() + hbox1 = QHBoxLayout() + hbox2 = QHBoxLayout() + self.ac_check = QCheckBox("Auto Combat") + self.ac_check.setChecked(True) + self.af_check = QCheckBox("Auto Farm") + self.ai_check = QCheckBox("Auto Ion") + self.me_check = QCheckBox("Meander") + self.ba_check = QCheckBox("Bait") + + self.ac_check.stateChanged.connect(self.ac_checked) + self.af_check.stateChanged.connect(self.af_checked) + self.ai_check.stateChanged.connect(self.ai_checked) + self.me_check.stateChanged.connect(self.me_checked) + self.ba_check.stateChanged.connect(self.ba_checked) + + hbox1.addWidget(self.ac_check) + hbox1.addWidget(self.af_check) + hbox1.addWidget(self.ba_check) + hbox2.addWidget(self.ai_check) + hbox2.addWidget(self.me_check) + hbox2.addWidget(self.ba_check) + + self.mode_layout.addLayout(hbox1) + self.mode_layout.addLayout(hbox2) + + def createSettingsGroup(self): + self.settingsGroupBox = QFormLayout() + self.fy_input = QLineEdit("2000") + self.na_input = QLineEdit("50") + self.yl_input = QLineEdit("2300") + self.path_input = QLineEdit("0") + + self.settingsGroupBox.addRow(QLabel("Farm Year:"),self.fy_input) + self.settingsGroupBox.addRow(QLabel("No Action:"),self.na_input) + self.settingsGroupBox.addRow(QLabel("Year Limit:"),self.yl_input) + self.settingsGroupBox.addRow(QLabel("Path:"),self.path_input) + + #buttons + def n_btn(self): + self.command_str.emit("north\r\n") + + def s_btn(self): + self.command_str.emit("south\r\n") + + def e_btn(self): + self.command_str.emit("east\r\n") + + def w_btn(self): + self.command_str.emit("west\r\n") + + def h_btn(self): + self.heal = True + + def c_btn(self): + self.combat_start() + + def p_btn(self): + self.path_step=1 + + def l_btn(self): + self.command_str.emit("look\r\n") + + def st_btn(self): + self.command_str.emit("stat\r\n") + + #load bank file + def load_bank_paths(self): + file = "./"+self.path+"/banks.txt" + if (os.path.exists(self.path) == False): + os.makedirs(self.path) + f = open(file, "x") + print("creating "+file) + else: + print("File Exists") + with open(file, 'r') as script: + while True: + in_str = script.readline().strip() + if in_str != "": + self.bank_list.append(in_str.split(",")) + # end of file is reached + if not in_str: + break + + #Button send text + def send_str(self): + self.command_str.emit(self.text_input.text()+"\r\n") + + #auto combat checked + def ac_checked(self): + self.auto_combat = self.ac_check.isChecked() + print("Auto Combat: "+str(self.auto_combat)) + + #auto farm checked + def af_checked(self): + self.auto_farm = self.af_check.isChecked() + print("Auto farm: "+str(self.auto_farm)) + + #auto ion checked + def ai_checked(self): + self.auto_ion = self.ai_check.isChecked() + print("Auto ion: "+str(self.auto_ion)) + + #meander checked + def me_checked(self): + self.wander = self.me_check.isChecked() + print("Wander: "+str(self.wander)) + + #meander checked + def ba_checked(self): + self.bait = self.ba_check.isChecked() + print("Bait: "+str(self.bait)) + + #heal timer + def heal_trig(self): + if self.heal: + self.command_str.emit("heal\r\n") + + #wield timer + def wield_trig(self): + if self.in_combat: + self.command_str.emit("wie nuclear-decay\r\n") + + #wander timer + def wander_trig(self): + if self.wander and not self.in_combat and self.path_step == 0: + self.area_indexed = False + self.local_monsters = [] + self.local_items = [] + print("wander triggered") + print("no action: " + str(self.no_action_cnt)) + #increment no action counter + self.no_action_cnt = self.no_action_cnt + 1 + if len(self.direction_list) == 0: + self.command_str.emit("look\r\n") + + #pick randomly + if len(self.direction_list) > 0: + if len(self.direction_list) > 1: + try: + self.direction_list.remove(self.previous_dir) + except: + pass + #print(self.direction_list) + dir_choice = random.choice(self.direction_list) + try: + if dir_choice == "north": + self.location[1] = self.location[1] + 1 + if dir_choice == "south": + self.location[1] = self.location[1] - 1 + if dir_choice == "east": + self.location[0] = self.location[0] + 1 + if dir_choice == "west": + self.location[0] = self.location[0] - 1 + except: + pass + + self.command_str.emit(dir_choice+"\r\n") + self.direction_list = [] + self.previous_dir = opposite_dir[dir_choice] + + #stat timer + def stat_trig(self): + if not self.in_combat and self.path_step ==0: + self.command_str.emit("stat\r\n") + self.command_str.emit("look\r\n") + + #path timer + def path_trig(self): + if not self.in_combat: + self.path_process() + + #search a list + def search(self, list, platform): + for i in range(len(list)): + if list[i] == platform: + return True + return False + + #Reup Ions + def convert_items(self): + for item_l in self.local_items: + for item in convert_list: + if item_l == item: + self.command_str.emit("get "+item+"\r\n") + self.command_str.emit("con "+item+"\r\n") + try: + self.local_items.remove(item_l) + except: + pass + + #Farms valuable stuff + def farm_sell_items(self): + for item_l in self.local_items: + for item in farm_sell_list: + if item_l == item: + self.command_str.emit("get "+item+"\r\n") + self.local_items.remove(item_l) + self.sell_list.append(item_l) + self.no_action_cnt = 0 + + #Farms valuable stuff + def farm_stock_items(self): + for item_l in self.local_items: + for item in farm_stock_list: + if item_l == item: + self.command_str.emit("get "+item+"\r\n") + self.local_items.remove(item_l) + self.stock_list.append(item_l) + self.no_action_cnt = 0 + + #Sell items + def sell_items(self): + print(self.sell_list) + while len(self.sell_list) > 0: + item_l=self.sell_list[0] + self.sell_list.pop(0) + self.command_str.emit("sell "+item_l+"\r\n") + time.sleep(.25) + + #Stock + def stock_items(self): + print(self.stock_list) + while len(self.stock_list) > 0: + item_l=self.stock_list[0] + self.stock_list.pop(0) + self.command_str.emit("stock "+item_l+"\r\n") + time.sleep(.25) + + #Drop monster baits + def drop_baits(self): + while self.stock_list.count("Monster-Bait") > 1: + self.command_str.emit("drop monster-bait\r\n") + self.stock_list.remove("Monster-Bait") + + #Remove friends from monster list + def remove_friends(self): + for friend in friend_list: + try: + self.local_monsters.remove(friend) + except: + pass + + #Flushes keyboard + def flush_input(self): + try: + import msvcrt + while msvcrt.kbhit(): + msvcrt.getch() + except ImportError: + import sys, termios + termios.tcflush(sys.stdin, termios.TCIOFLUSH) + + #Decode incoming information + def decode_line(self,line): + result = "" + if line.decode('cp1252') != "": + ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])') + result = ansi_escape.sub('', line.decode('cp1252').strip('\n')) + self.console.append(result) + return result + + #initiate combat + def combat_start(self): + try: + self.command_str.emit("combat " + self.local_monsters[0]+"\r\n") + except: + pass + self.in_combat = True + self.heal = True + self.wield_trig() + self.path_step = 0 + self.no_action_cnt = 0 + + #process wander + def wander_process(self, result): + #area clear + if result.find("north - area continues.") != -1 or result.find("north - open gate.") != -1: + self.direction_list.append("north") + if result.find("south - area continues.") != -1 or result.find("south - open gate.") != -1: + self.direction_list.append("south") + if result.find("east - area continues.") != -1 or result.find("east - open gate.") != -1: + self.direction_list.append("east") + if result.find("west - area continues.") != -1 or result.find("west - open gate.") != -1: + self.direction_list.append("west") + + #are there monsters + if result.find("You see shadows to the") != -1: + try: + if result.find("north") != -1: + self.direction_list.remove("north") + if result.find("south") != -1: + self.direction_list.remove("south") + if result.find("east") != -1: + self.direction_list.remove("east") + if result.find("west") != -1: + self.direction_list.remove("west") + except: + pass + + #process combat per loop + def combat_process(self, result): + if result.find("You suffer") != -1: + self.hits = self.hits + 1 + if self.hits == 2: + self.command_str.emit("heal\r\n") + self.command_str.emit("heal\r\n") + self.hits = 0 + + if result.find("have slain") != -1 or result.find("has just left") != -1 or result.find("isn't around here!") != -1 or result.find("You're not ready") != -1: + try: + self.local_monsters.pop(0) + except: + pass + if len(self.local_monsters) > 0: + self.command_str.emit("combat " + self.local_monsters[0]+"\r\n") + else: + #print("Area cleared") + self.in_combat = False + + #time travel + def time_travel(self): + self.local_items = [] + self.location = [0,0] + self.farm_year = self.farm_year + 100 + if self.farm_year > self.year_limit: + self.farm_year = 2000 + self.command_str.emit("tra "+str(self.farm_year)+"\r\n") + self.drop_baits() + if self.bait and not self.stock_list.count("Monster-Bait"): + self.command_str.emit("get Monster-Bait\r\n") + self.stock_list.append("Monster-Bait") + self.command_str.emit("look\r\n") + + #process path + def path_process(self): + path_str = self.bank_list[self.selected_path][self.path_step] + if path_str != "done": + if path_str[0] == "!": + self.script_function(path_str.strip("!").upper()) + else: + self.command_str.emit(path_str+"\r\n") + self.path_step = self.path_step + 1 + self.no_action_cnt = 0 + else: + self.path_step = 0 + + #handle functions in path script + def script_function(self,function): + if function == "DEPOSIT": + self.command_str.emit("deposit "+str(self.riblets)+"\r\n") + self.riblets = 0 + if function == "STOCK": + self.stock_items() + + if function == "SELL": + self.sell_items() + + if function == "RETURN": + self.command_str.emit("tra "+str(self.farm_year)+"\r\n") + + #process stats + def parse_stat(self, result): + if self.stat_parsed == False: + self.sell_list = [] + self.stock_list = [] + self.status += result + if result.find(">") != -1: + self.stat_parsed = True + + if self.stat_parsed and self.status != "": + for item_l in farm_sell_list: + x = self.status.count(item_l) + for i in range(x): + self.sell_list.append(item_l) + + for item_l in farm_stock_list: + x = self.status.count(item_l) + for i in range(x): + self.stock_list.append(item_l) + + #scrape riblets + if self.status.find("Riblets :") != -1: + start_index = self.status.index('Riblets : ') + 16 + riblets_str = self.status[start_index:] + try: + end_index = riblets_str.index('Ions') + except: + pass + + riblets_str = riblets_str[:end_index] + #print("Riblets:" + riblets_str) + try: + self.riblets = int(riblets_str) + except: + pass + + #scrape year + if self.status.find("Year A.D. :") != -1: + start_index = self.status.index('Year A.D. : ') + 17 + year_str = self.status[start_index:] + try: + end_index = 4 + except: + pass + year_str = year_str[:end_index] + #print("Year:" + year_str) + self.farm_year = int(year_str) + + + self.status = "" + #print("sell list") + #print(self.sell_list) + #print("stock list") + #print(self.stock_list) + + #index area + def index_area(self,result): + if self.area_indexed == False: + self.area += result + if result.find(">") != -1: + self.area_indexed = True + + if self.area_indexed and self.area != "": + if self.area.find("On the ground lies:") != -1: + start_index = self.area.index('On the ground lies:') + item_str = self.area[start_index:] + try: + end_index = item_str.index('***') + except: + try: + end_index = item_str.index('>') + except: + pass + item_str = item_str[:end_index] + item_str = item_str.replace("On the ground lies:","") + item_str = item_str.replace("0","") + item_str = item_str.replace("1","") + item_str = item_str.replace("2","") + item_str = item_str.replace("3","") + item_str = item_str.replace("4","") + item_str = item_str.replace("5","") + item_str = item_str.replace("6","") + item_str = item_str.replace("7","") + item_str = item_str.replace("8","") + item_str = item_str.replace("9","") + item_str = item_str.replace("(","") + item_str = item_str.replace(")","") + item_str = item_str.replace("A ","") + item_str = item_str.replace("An ","") + item_str = item_str.replace(" ","") + item_str = item_str.replace(".","") + item_str = item_str.replace("\r\n","") + item_str = item_str.replace("***","") + self.local_items = list(item_str.split(",")) + #print(self.local_items) + + if self.area.find("is here") != -1 or self.area.find("are here") != -1: + try: + end_index = self.area.index('here') + monster_str = self.area[:end_index] + start_index = monster_str.rindex('***') + monster_str = monster_str[start_index:] + monster_str = monster_str.replace("\r\n","") + monster_str = monster_str.replace(" and ","") + monster_str = monster_str.replace(" are ","") + monster_str = monster_str.replace(" is ","") + monster_str = monster_str.replace(" ","") + monster_str = monster_str.replace(".","") + monster_str = monster_str.replace("***","") + self.local_monsters = list(monster_str.split(",")) + self.remove_friends() + #print(self.local_monsters) + except: + pass + + self.area = "" + + #Main game loop + def mutants(self,result): + #update farm year text box + try: + self.fy_input.setText(str(self.farm_year)) + self.na_thresh = int(self.na_input.text()) + self.year_limit = int(self.yl_input.text()) + self.selected_path = int(self.path_input.text()) + except: + pass + + #Nothing has happened in a while, time jump + if self.no_action_cnt > self.na_thresh: + self.time_travel() + self.no_action_cnt = 0 + #New area, take a look + + #New area, set index, get location + if result.find("Compass:") != -1: + res_filter = result.replace("Compass:","") + res_filter = res_filter.replace("Compass:","") + res_filter = res_filter.replace("N","") + res_filter = res_filter.replace("E","") + res_filter = res_filter.replace(":",",") + res_filter = res_filter.replace("(","") + res_filter = res_filter.replace(")","") + res_filter = res_filter.replace(" ","") + try: + self.location = list(map(int, res_filter.split(","))) + except: + print('location failed') + #print(self.location) + self.area_indexed = False + + #drop baits + if self.location == [0,0]: + self.drop_baits() + + #too many baits + if self.stock_list.count("Monster-Bait") > 3: + self.command_str.emit("drop Monster-Bait\r\n") + self.stock_list.remove("Monster-Bait") + #print(self.stock_list) + + #too many nuclear decays + if self.stock_list.count("Nuclear-Decay") > 3: + self.command_str.emit("con nuclear-decay\r\n") + self.stock_list.remove("Nuclear-Decay") + #print(self.stock_list) + + #parse status + self.parse_stat(result) + + #index area + self.index_area(result) + + #deposit riblets + if self.riblets > self.riblet_thresh and self.path_step == 0 and self.wander: + self.path_step = 1 + + #auto farm if sold items + if len(self.sell_list) == 0 and self.wander: + self.auto_farm = True + + #process wander + if self.wander and not self.in_combat and self.path_step == 0: + self.wander_process(result) + + #process combat + if self.in_combat: + self.combat_process(result) + + #scrapers + if result.find("(N)onstop, (Q)uit, or (C)ontinue?") != -1: + self.command_str.emit("C\r\n") + + #ion starvation + if result.find("You're starving for IONS!") != -1: + self.command_str.emit("con gold-chunck\r\n") + self.auto_combat = True + self.heal = True + + #too heavy + if self.wander and result.find("The weight of all your items forces you to the ground.") != -1: + self.wander = False + self.command_str.emit("X\r\n") + + #dropped your weapon! + if self.auto_farm and result.find("The Nuclear-Decay fell out of your sack!") != -1: + self.time_steps = 0 + self.command_str.emit("con gold-chunck\r\n") + self.command_str.emit("get nuclear-decay\r\n") + + #I can't remember why I did this + if self.auto_farm and result.find("You're not carrying a gold-chunck.") != -1: + self.auto_farm = False + + #Dropped the bait, pick it back up + if result.find("The Monster-Bait fell out of your sack!") != -1: + self.time_steps = 0 + self.command_str.emit("con gold-chunck\r\n") + self.command_str.emit("get monster-bait\r\n") + + #Detect bait mode, add or remove from stock list + if self.bait: + if not farm_stock_list.count("Monster-Bait"): + farm_stock_list.append("Monster-Bait") + else: + try: + farm_stock_list.remove("Monster-Bait") + except: + pass + + #Exit game if.. + if self.in_combat and result.find("You're not carrying a nuclear-decay.") != -1: + self.command_str.emit("x\r\n") + + #GTFO + if self.wander and (((result.find("It's too dark to see anything!") != -1 and self.path_step == 0) or + result.find("You're blocked!") != -1) or + len(self.local_monsters) > 4): + + self.heal = True + local_monsters = [] + + self.command_str.emit("tra "+str(self.farm_year)+"\r\n") + self.in_combat = False + + #Sell the loot + if result.find("City Trading Centre") != -1 and self.path_step == 0: + if len(self.sell_list) > 0: + self.sell_items() + + #Parse character status + if result.find("stat") != -1: + self.stat_parsed = False + + #Trigger stop healing + if result.find("Nothing happens!") != -1 or result.find("You don't have enough ions to heal!") != -1: + self.heal = False + + #Turn on healing + if result.find("You suffer") != -1 or result.find("You are poisoned!") != -1: + self.heal = True + + #Monster list related + if (result.find("yells: Gimmie") != -1 or + result.find("just arrived from") != -1 or + result.find("has hit") != -1 or + result.find("body is glowing") != -1 or + result.find("Get away from me") != -1 or + result.find("just appeared through a time portal!") != -1): + m = result.index(' ') + monster = result[:m] + if not self.search(self.local_monsters, monster): + self.local_monsters.append(monster) + self.remove_friends() + #print(self.local_monsters) + if len(self.local_monsters) > 0 and self.auto_combat and not self.in_combat: + self.combat_start() + + #Monster took off, remove from list + if result.find("has just left") != -1: + end_index = result.index(' has') + mon_str = result[:end_index] + mon_str = mon_str.replace(" ","") + try: + self.local_monsters.remove(mon_str) + except: + pass + #print(mon_str) + #print(self.local_monsters) + + #Monster died, remove from list + if result.find("is crumbling to dust") != -1: + end_index = result.index(' is') + mon_str = result[:end_index] + mon_str = mon_str.replace(" ","") + try: + self.local_monsters.remove(mon_str) + except: + pass + #print(mon_str) + #print(self.local_monsters) + + #Someone picked something up, remove from item list + if result.find("picked up the") != -1: + start_index = result.index('the') + 4 + item_str = result[start_index:] + end_index = item_str.index('.') + item_str = item_str[:end_index] + item_str = item_str.replace(" ","") + try: + self.local_items.remove(item_str) + except: + pass + #print(item_str) + #print(self.local_items) + + #Dead person dropping stuff, add to local list + if result.find("is falling from") != -1: + try: + start_index = result.index('A') + item_str = result[start_index:] + end_index = item_str.index('is') + item_str = item_str[:end_index] + item_str = item_str.replace(" ","") + item_str = item_str.replace("is","") + item_str = item_str.replace("An","") + item_str = item_str.replace("A","") + self.local_items.append(item_str) + except: + print("Monster item drop error") + print(result) + #print(self.local_items) + + #You died, do some stuff + if result.find("Select (Bury, 1-5, ?)") != -1: + self.mqtt_str.emit(self.user+" has died") + print("MQTT signal emitted") + self.in_combat=False + self.heal = False + self.wander = False + self.auto_farm = False + self.auto_combat = False + self.ac_check.setChecked(False) + self.af_check.setChecked(False) + self.ai_check.setChecked(False) + self.me_check.setChecked(False) + + #farm items + if len(self.local_items) > 0 and not self.in_combat and not self.path_step: + farm_zero = True + if self.location == [0,0]: + farm_zero = False + if not self.wander: + farm_zero = True + + if self.auto_farm and farm_zero: + self.farm_sell_items() + self.farm_stock_items() + if self.auto_ion: + self.convert_items() + #print("convert") + + def process_keys(self, key): + + #keyboard related - this part sucks + if key==ord(self.lock_key): + if self.key_detect: + self.key_detect = False + print("Key detect off") + else: + self.key_detect = True + print("Key detect on") + + if self.key_detect: + if key==ord("?"): + for help in help_list: + print(help) + + #directions + if key==ord("8"): + self.local_monsters = [] + self.local_items = [] + self.command_str.emit("north\r\n") + + if key==ord("2"): + self.local_monsters = [] + self.local_items = [] + self.command_str.emit("south\r\n") + + if key==ord("4"): + self.local_monsters = [] + self.local_items = [] + self.command_str.emit("west\r\n") + + if key==ord("6"): + self.local_monsters = [] + self.local_items = [] + self.command_str.emit("east\r\n") + + #functions + if key==ord("a"): + if self.auto_combat: + self.auto_combat = False + print("Auto combat off") + else: + self.auto_combat = True + print("Auto combat on") + #Auto Ion + if key==ord("i"): + if self.auto_ion: + self.auto_ion = False + print("Auto ion off") + else: + self.auto_ion = True + print("Auto ion on") + #Auto farm + if key==ord("f"): + if self.auto_farm: + self.auto_farm = False + print("Auto farm off") + else: + self.auto_farm = True + print("Auto farm on") + + #Year limit + if key==ord("y"): + self.flush_input() + st = input("Year limit: ") + self.year_limit = int(st) + + #No action threshhold + if key==ord("n"): + self.flush_input() + st = input("No action: ") + self.na_thresh = int(st) + + #Start combat + if key==ord("c"): + if len(self.local_monsters) > 0: + combat_start() + + #look around + if key==ord("5"): + self.command_str.emit("look ") + + #meander status + if key==ord("m"): + if self.wander: + self.wander = False + print("Meander off") + else: + self.wander = True + print("Meander on") + self.command_str.emit("look\r\n") + + #heal + if key==ord("h"): + self.command_str.emit("heal\r\n") + self.heal = True + + #look around + if key==ord("l"): + self.command_str.emit("look\r\n") + + #stats + if key==ord("v"): + self.command_str.emit("stat\r\n") + + #sell items + if key==ord("s"): + self.sell_items() + + #store path select + if key==ord("p") and not self.in_combat: + self.flush_input() + st = input("Choose path input: ") + self.selected_path = int(st) + self.path_step = 1 + self.command_str.emit("Starting path..\r\n") + self.flush_input() + + if key==ord("K") and not self.in_combat: + print("working?") + st = input("Keyboard input: ") + self.command_str.emit(st+"\r\n") + self.flush_input() + + #wield weapon + if key==ord("w"): + self.command_str.emit("wie nuclear-decay\r\n") + + #drop item + if key==ord("d"): + self.flush_input() + #toss = keyboard.read_key() + st = input("drop item: ") + drop_item = "drop " + st + self.command_str.emit(drop_item+"\r\n") + + #time travel + if key==ord("t") and not self.in_combat: + monster_list = [] + self.flush_input() + #toss = keyboard.read_key() + st = input("year: ") + year = "travel " + st + self.command_str.emit(year+"\r\n") + + if key==ord("x"): + pass + + #login routine + def login_listener(self, result): + + if result == "Otherwise type \"new\": ": + self.command_str.emit(self.user+"\r\n") + + if result == "Enter your password: ": + self.command_str.emit(self.password+"\r\n") + + if result == "(N)onstop, (Q)uit, or (C)ontinue?": + self.command_str.emit("Q\r\n") + + if result == "Make your selection (G,T,F,M,S,? for help, or X to exit): ": + self.command_str.emit("G\r\n") + self.mqtt_str.emit(self.user+" is online") + + if result == "help, or X to exit): ": + self.command_str.emit("C\r\n") + + if result == "Select (P,I,H,S,W,X,?): ": + self.command_str.emit("P\r\n") + + if result == "Select (Bury, 1-5, ?) ": + self.command_str.emit("4\r\n") + #self.mutants() + self.logged_in = True + + #main game loop + def execute_loop(self, result): + self.console.append(result) + self.console.moveCursor(QTextCursor.End) + + if self.logged_in == False: + self.login_listener(result) + else: + self.mutants(result) + + +class telnet_thread(QObject): + received = pyqtSignal(str) + disconnected = pyqtSignal() + + #Init + def __init__(self): + QWidget.__init__(self) + #telnet lib + self.tn = telnetlib.Telnet() + self.open_telnet() + + #Open connection + def open_telnet(self): + try: + self.tn.open(HOST,23) + print("telnet connected..") + except: + print("Connection attempt failed..") + + #Decode incoming information + def decode_line(self,line): + result = "" + if line.decode('cp1252') != "": + ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])') + result = ansi_escape.sub('', line.decode('cp1252').strip('\n')) + return result + + #Write to telnet object + def tn_write(self,send_str): + try: + self.tn.write(send_str.encode('ascii')) + except: + pass + + #Listen perpetually + def telnet_listen(self): + print("listening..") + while True: + #data decode + QApplication.processEvents() + result = "" + line = None + try: + line = self.tn.read_until(b"\n",0) # Read one line + result = self.decode_line(line).strip("\r").strip("\n").strip("\b") + if result != "": + self.received.emit(result) + except: + try: + print("Reconnectiong...") + self.tn.close() + self.disconnected.emit() + self.open_telnet() + except: + print("Reconnect failed!") + +class MainWindow(QMainWindow): + keyPressed = pyqtSignal(int) + def __init__(self): + super(MainWindow, self).__init__() + widget = QWidget(self) + self.layout = QVBoxLayout(widget) + self.setCentralWidget(widget) + self.setup_mqtt() + mutbox = QHBoxLayout() + + self.m1 = mutant(usr_1,pwrd_2) + self.m2 = mutant(usr_2,pwrd_2) + mutbox.addWidget(self.m1) + mutbox.addWidget(self.m2) + self.m1.mqtt_str.connect(self.send_mqtt) + self.m2.mqtt_str.connect(self.send_mqtt) + self.layout.addLayout(mutbox) + self.button_group() + self.createModeGroup() + self.show() + + #Connect signals + #self.keyPressed.connect(self.m.process_keys) + + # Add text input + self.formGroupBox = QFormLayout() + self.text_input = QLineEdit() + self.text_button = QPushButton("Send") + self.text_button.clicked.connect(self.send_str) + self.formGroupBox.addRow(self.text_button,self.text_input) + self.layout.addLayout(self.formGroupBox) + + self.send_mqtt("new testing..") + + #Events like mouse movement and keyboard action that happen on the main form + def eventFilter(self, source, event): + #print(source) + if str(source).find("QWindow") != -1: + if event.type() == QEvent.KeyPress: + self.keyPressed.emit(event.key()) + + return QMainWindow.eventFilter(self, source, event) + + #create buttons + def button_group(self): + hbox1 = QHBoxLayout() + hbox2 = QHBoxLayout() + b_grid = QGridLayout() + + north_button = QPushButton("North") + south_button = QPushButton("South") + east_button = QPushButton("East") + west_button = QPushButton("West") + heal_button = QPushButton("Heal") + combat_button = QPushButton("Combat") + + hbox2.addWidget(heal_button) + hbox2.addWidget(combat_button) + + b_grid.addWidget(north_button,0,1) + b_grid.addWidget(south_button,2,1) + b_grid.addWidget(east_button,1,2) + b_grid.addWidget(west_button,1,0) + b_grid.addLayout(hbox2,1,1) + #b_grid.addWidget(heal_button,2,2) + #b_grid.addWidget(combat_button,2,0) + + hbox1.addItem(QSpacerItem(350, 0, QSizePolicy.Minimum)) + hbox1.addLayout(b_grid) + hbox1.addItem(QSpacerItem(350, 0, QSizePolicy.Minimum)) + + north_button.clicked.connect(self.n_btn) + south_button.clicked.connect(self.s_btn) + east_button.clicked.connect(self.e_btn) + west_button.clicked.connect(self.w_btn) + heal_button.clicked.connect(self.h_btn) + combat_button.clicked.connect(self.c_btn) + + self.layout.addLayout(hbox1) + + #buttons + def n_btn(self): + self.m1.command_str.emit("north\r\n") + self.m2.command_str.emit("north\r\n") + def s_btn(self): + self.m1.command_str.emit("south\r\n") + self.m2.command_str.emit("south\r\n") + def e_btn(self): + self.m1.command_str.emit("east\r\n") + self.m2.command_str.emit("east\r\n") + def w_btn(self): + self.m1.command_str.emit("west\r\n") + self.m2.command_str.emit("west\r\n") + def h_btn(self): + self.m1.heal = True + self.m2.heal = True + def c_btn(self): + self.m1.combat_start() + self.m2.combat_start() + + #Button send text + def send_str(self): + self.m1.command_str.emit(self.text_input.text()+"\r\n") + self.m2.command_str.emit(self.text_input.text()+"\r\n") + + #Creates the form groupbox + def createModeGroup(self): + self.mode_layout = QVBoxLayout() + hbox1 = QHBoxLayout() + hbox2 = QHBoxLayout() + self.mq_check = QCheckBox("MQTT") + self.mq_check.setChecked(True) + + hbox1.addWidget(self.mq_check) + + self.layout.addLayout(hbox1) + + def setup_mqtt(self): + broker_address="192.168.86.27" + print("creating new instance") + self.client = mqtt.Client("P1") #create new instance + self.client.username_pw_set("homeassistant", "oes5gohng9gau1Quei2ohpixashi4Thidoon1shohGai2mae0ru2zaph2vooshai") + self.client.connect(broker_address) + + #Send mqtt + def send_mqtt(self,out_str): + self.setup_mqtt() + if self.mq_check.isChecked(): + self.client.publish("mutants", out_str) + +if __name__ == "__main__": + App = QApplication(sys.argv) + QApplication.setQuitOnLastWindowClosed(True) + Root = MainWindow() + Root.show() + App.installEventFilter(Root) + sys.exit(App.exec()) \ No newline at end of file