diff --git a/doctor/banks.txt b/doctor/banks.txt deleted file mode 100644 index e40414c..0000000 --- a/doctor/banks.txt +++ /dev/null @@ -1,4 +0,0 @@ -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/file b/file deleted file mode 100644 index e69de29..0000000 diff --git a/mq.py b/mq.py deleted file mode 100644 index e3c9652..0000000 --- a/mq.py +++ /dev/null @@ -1,10 +0,0 @@ -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/mutant function.py b/mutant function.py deleted file mode 100644 index 0fe30cc..0000000 --- a/mutant function.py +++ /dev/null @@ -1,571 +0,0 @@ - #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 deleted file mode 100644 index b14edb1..0000000 --- a/mutant function.txt +++ /dev/null @@ -1,630 +0,0 @@ - #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 deleted file mode 100644 index af113c0..0000000 --- a/mutants.py +++ /dev/null @@ -1,661 +0,0 @@ -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 deleted file mode 100644 index 0459934..0000000 --- a/mutants_localbbs.py +++ /dev/null @@ -1,526 +0,0 @@ -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 deleted file mode 100644 index cba085a..0000000 --- a/mutants_paths.py +++ /dev/null @@ -1,812 +0,0 @@ -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 index ae51831..afb048a 100644 --- a/qmutants.py +++ b/qmutants.py @@ -15,6 +15,7 @@ import paho.mqtt.client as mqtt HOST = "telnet.goldenunicorn.net" player_list = [] +MAX_SELL_ITEMS = 1 class player(): def __init__(self): @@ -51,12 +52,12 @@ def player_add(usr,pwd,char_sel,weapon,spell,ac,ai,me,af,hu,ba): player_list.append(plyr) if choice == 1: - player_add("epilectrik","gupass",4,"Nuclear-Decay","dispell",True,True,True,True,True,False) - player_add("im bait","gupass",4,"Nuclear-Decay","dispell",True,True,True,True,True,False) - player_add("doctor","gupass",2,"Nuclear-Decay","cure poison",True,True,False,False,False,False) - player_add("robin-hood","gupass",1,"Nuclear-Decay","invisibility",True,True,False,False,False,False) - player_add("assassin","gupass",4,"Nuclear-Decay","dispell",True,True,True,True,True,False) - player_add("mercenary","gupass",4,"Nuclear-Decay","dispell",True,True,True,True,True,False) + player_add("epilectrik","gupass",4,"Nuclear-Decay","dispell",True,True,True,False,True,False) + player_add("im bait","gupass",4,"Nuclear-Decay","dispell",True,True,True,False,True,False) + player_add("doctor","gupass",2,"Nuclear-Decay","cure poison",True,True,True,False,True,False) + player_add("robin-hood","gupass",1,"Nuclear-Decay","invisibility",True,True,True,False,True,False) + player_add("assassin","gupass",4,"Nuclear-Decay","dispell",True,True,True,False,True,False) + player_add("mercenary","gupass",4,"Nuclear-Decay","dispell",True,True,True,False,True,False) player_add("mutant-warrior-1","gupass",4,"Nuclear-Decay","dispell",True,True,False,False,False,False) player_add("mutant-warrior-2","gupass",4,"Nuclear-Decay","dispell",True,True,False,False,False,False) @@ -107,10 +108,12 @@ opposite_dir = { class mutant(QWidget): command_str = pyqtSignal(str) mqtt_str = pyqtSignal(str) - mqtt_str_quiet = pyqtSignal(str,str) - def __init__(self,player): + mqtt_str_quiet = pyqtSignal(str,str) + tab_color = pyqtSignal(int,str) + def __init__(self,player,idx): QWidget.__init__(self) self.player=player + self.idx=idx #file related self.path=player.usr @@ -121,6 +124,7 @@ class mutant(QWidget): self.sell_list = [] self.stock_list = [] self.bank_list = [] + self.cmd_buffer = [] #modes self.heal = False @@ -147,6 +151,8 @@ class mutant(QWidget): self.weapon = "Nuclear-Decay" self.spell = player.spell self.watchdog = 0 + self.cmd_watchdog = 0 + self.prompt = False #value tracking self.riblets = 0 @@ -203,7 +209,11 @@ class mutant(QWidget): self.watchdog_timer.setInterval(30000) self.watchdog_timer.timeout.connect(self.watchdog_t) self.watchdog_timer.start() - + #cmd watchdog + self.watchdog_cmd_timer = QTimer() + self.watchdog_cmd_timer.setInterval(100) + self.watchdog_cmd_timer.timeout.connect(self.watchdog_cmd) + self.watchdog_cmd_timer.start() #layout stuff self.layout = QVBoxLayout() @@ -242,6 +252,23 @@ class mutant(QWidget): self.setLayout(self.layout) self.load_bank_paths() self.init_telnet() + + #self.set_color() + + def send_cmd(self,cmd_str): + if self.prompt: + self.command_str.emit(cmd_str) + else: + self.cmd_buffer.append(cmd_str) + + def transmit_bfr(self): + while len(self.cmd_buffer)>0: + self.command_str.emit(self.cmd_buffer[0]) + self.cmd_buffer.pop(0) + + def set_color(self): + self.setAttribute(Qt.WA_StyledBackground, True) + self.setStyleSheet('background-color: red;') def init_telnet(self): @@ -394,16 +421,16 @@ class mutant(QWidget): #buttons def n_btn(self): - self.command_str.emit("north\r\n") + self.send_cmd("north\r\n") def s_btn(self): - self.command_str.emit("south\r\n") + self.send_cmd("south\r\n") def e_btn(self): - self.command_str.emit("east\r\n") + self.send_cmd("east\r\n") def w_btn(self): - self.command_str.emit("west\r\n") + self.send_cmd("west\r\n") def h_btn(self): self.heal = True @@ -412,13 +439,14 @@ class mutant(QWidget): self.combat_start() def p_btn(self): - self.path_step=1 + self.send_cmd("stat\r\n") + self.path_step = 1 def l_btn(self): - self.command_str.emit("look\r\n") + self.send_cmd("look\r\n") def st_btn(self): - self.command_str.emit("stat\r\n") + self.send_cmd("stat\r\n") #load bank file def load_bank_paths(self): @@ -442,7 +470,7 @@ class mutant(QWidget): #Button send text def send_str(self): - self.command_str.emit(self.text_input.text()+"\r\n") + self.send_cmd(self.text_input.text()+"\r\n") #auto combat checked def ac_checked(self): @@ -477,13 +505,13 @@ class mutant(QWidget): #heal timer def heal_trig(self): if self.heal and self.logged_in and self.in_play: - self.command_str.emit("heal\r\n") + self.send_cmd("heal\r\n") #self.mqtt_str_quiet.emit(self.user," is healing." ) #wield timer def wield_trig(self): if self.in_combat and self.logged_in and self.in_play: - self.command_str.emit("wie "+self.weapon+"\r\n") + self.send_cmd("wie "+self.weapon+"\r\n") #wander timer def wander_trig(self): @@ -491,12 +519,12 @@ class mutant(QWidget): self.area_indexed = False self.local_monsters = [] self.local_items = [] - print("wander triggered") - print("no action: " + str(self.no_action_cnt)) + #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") + self.send_cmd("look\r\n") #pick randomly if len(self.direction_list) > 0: @@ -519,15 +547,15 @@ class mutant(QWidget): except: pass - self.command_str.emit(dir_choice+"\r\n") + self.send_cmd(dir_choice+"\r\n") self.direction_list = [] self.previous_dir = opposite_dir[dir_choice] #stat timer def stat_trig(self): if self.logged_in and self.in_play and not self.in_combat and self.path_step == 0: - self.command_str.emit("stat\r\n") - self.command_str.emit("look\r\n") + self.send_cmd("stat\r\n") + self.send_cmd("look\r\n") #path timer def path_trig(self): @@ -546,8 +574,8 @@ class mutant(QWidget): 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.send_cmd("get "+item+"\r\n") + self.send_cmd("con "+item+"\r\n") self.mqtt_str_quiet.emit(self.user," converted " + item ) try: self.local_items.remove(item_l) @@ -558,10 +586,14 @@ class mutant(QWidget): 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") + if item_l == item and self.sell_list.count(item) < MAX_SELL_ITEMS: + print("Farm sell count:"+item) + print(self.sell_list.count(item)) + print(self.sell_list) + self.send_cmd("get "+item+"\r\n") self.local_items.remove(item_l) self.sell_list.append(item_l) + print(self.sell_list) self.no_action_cnt = 0 #Farms valuable stuff @@ -569,7 +601,7 @@ class mutant(QWidget): 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.send_cmd("get "+item+"\r\n") self.local_items.remove(item_l) self.stock_list.append(item_l) self.no_action_cnt = 0 @@ -580,22 +612,30 @@ class mutant(QWidget): 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") + self.send_cmd("sell "+item_l+"\r\n") time.sleep(.05) - + self.send_cmd("stat\r\n") + #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(.05) - + for item_s in farm_stock_list: + for item in self.stock_list: + if item == item_s: + cnt = self.stock_list.count(item) + print("item count: "+str(cnt)) + if item == self.weapon: + cnt = cnt - 1 + print("sub weapon count: "+str(cnt)) + for x in range(cnt): + self.send_cmd("stock "+item+"\r\n") + self.stock_list.remove(item) + time.sleep(.05) + #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.send_cmd("drop monster-bait\r\n") self.stock_list.remove("Monster-Bait") #Remove friends from monster list @@ -628,7 +668,7 @@ class mutant(QWidget): #initiate combat def combat_start(self): try: - self.command_str.emit("combat " + self.local_monsters[0]+"\r\n") + self.send_cmd("combat " + self.local_monsters[0]+"\r\n") self.mqtt_str_quiet.emit(self.user," is attacking " + self.local_monsters[0] ) except: pass @@ -670,8 +710,8 @@ class mutant(QWidget): self.hits = self.hits + 1 if self.hits == 2: - self.command_str.emit("heal\r\n") - self.command_str.emit("heal\r\n") + self.send_cmd("heal\r\n") + self.send_cmd("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: @@ -680,7 +720,7 @@ class mutant(QWidget): except: pass if len(self.local_monsters) > 0: - self.command_str.emit("combat " + self.local_monsters[0]+"\r\n") + self.send_cmd("combat " + self.local_monsters[0]+"\r\n") else: #print("Area cleared") self.in_combat = False @@ -692,12 +732,12 @@ class mutant(QWidget): 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.send_cmd("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.send_cmd("get Monster-Bait\r\n") self.stock_list.append("Monster-Bait") - self.command_str.emit("look\r\n") + self.send_cmd("look\r\n") #process path def path_process(self): @@ -706,7 +746,7 @@ class mutant(QWidget): if path_str[0] == "!": self.script_function(path_str.strip("!").upper()) else: - self.command_str.emit(path_str+"\r\n") + self.send_cmd(path_str+"\r\n") self.path_step = self.path_step + 1 self.no_action_cnt = 0 else: @@ -715,15 +755,15 @@ class mutant(QWidget): #handle functions in path script def script_function(self,function): if function == "DEPOSIT": - self.command_str.emit("deposit "+str(self.riblets)+"\r\n") + self.send_cmd("deposit "+str(self.riblets)+"\r\n") self.mqtt_str_quiet.emit(self.user," deposited "+str(self.riblets)+" riblets" ) self.riblets = 0 if self.ions > 2000000: - self.command_str.emit("secure "+str(self.ions-2000000)+"\r\n") + self.send_cmd("secure "+str(self.ions-2000000)+"\r\n") self.mqtt_str_quiet.emit(self.user," secured "+str(self.ions-2000000)+" ions" ) self.ions = 2000000 - if function == "STOCK": + if function == "STOCK" and self.auto_farm: self.stock_items() if function == "SELL": @@ -731,7 +771,7 @@ class mutant(QWidget): if function == "RETURN": self.path_step = -1 - self.command_str.emit("tra "+str(self.farm_year)+"\r\n") + self.send_cmd("tra "+str(self.farm_year)+"\r\n") new_path = self.selected_path + 1 if new_path == len(self.bank_list): new_path = 0 @@ -740,125 +780,126 @@ class mutant(QWidget): #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 - #Retally items, convert extras - if self.stat_parsed and self.status != "": - self.watchdog = 0 - for item_l in farm_sell_list: - x = self.status.count(item_l) - for i in range(x): - if i < 3: - self.sell_list.append(item_l) - else: - self.command_str.emit("con "+item_l+"\r\n") - - for item_l in farm_stock_list: - x = self.status.count(item_l) - for i in range(x): - if i < 3: - self.stock_list.append(item_l) - else: - self.command_str.emit("con "+item_l+"\r\n") - #HP - if self.status.find("Hit Points :") != -1: - start_index = self.status.index('Hit Points : ') + 15 - hp_str = self.status[start_index:] - try: - end_index = hp_str.index('/') - except: - pass + if result.find(">") != -1: + #Retally items, convert extras + if not self.stat_parsed and self.status != "": + print(self.sell_list) + print("deleted list") + self.sell_list = [] + self.stock_list = [] + self.watchdog = 0 + for item_l in farm_sell_list: + x = self.status.count(item_l) + for i in range(x): + if i < MAX_SELL_ITEMS: + self.sell_list.append(item_l) + else: + self.send_cmd("con "+item_l+"\r\n") + print(self.sell_list) + for item_l in farm_stock_list: + x = self.status.count(item_l) + for i in range(x): + if i < 3: + self.stock_list.append(item_l) + else: + self.send_cmd("con "+item_l+"\r\n") + #HP + if self.status.find("Hit Points :") != -1: + start_index = self.status.index('Hit Points : ') + 15 + hp_str = self.status[start_index:] + try: + end_index = hp_str.index('/') + except: + pass - hp_str = hp_str[:end_index] + hp_str = hp_str[:end_index] - try: - self.hp = int(hp_str) - except: - pass + try: + self.hp = int(hp_str) + except: + pass - #exp - if self.status.find("Exp. Points :") != -1: - start_index = self.status.index('Exp. Points : ') + 15 - exp_str = self.status[start_index:] - try: - end_index = exp_str.index('Level') - except: - pass + #exp + if self.status.find("Exp. Points :") != -1: + start_index = self.status.index('Exp. Points : ') + 15 + exp_str = self.status[start_index:] + try: + end_index = exp_str.index('Level') + except: + pass - exp_str = exp_str[:end_index] + exp_str = exp_str[:end_index] - try: - self.exp = int(exp_str) - except: - pass + try: + self.exp = int(exp_str) + except: + pass - #scrape level - if self.status.find("Level: ") != -1: - start_index = self.status.index('Level: ') + 7 - level_str = self.status[start_index:] - try: - end_index = level_str.index('Riblets') - except: - pass + #scrape level + if self.status.find("Level: ") != -1: + start_index = self.status.index('Level: ') + 7 + level_str = self.status[start_index:] + try: + end_index = level_str.index('Riblets') + except: + pass - level_str = level_str[:end_index] + level_str = level_str[:end_index] - try: - self.level = int(level_str) - except: - pass + try: + self.level = int(level_str) + except: + pass - #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 + #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 + riblets_str = riblets_str[:end_index] + #print("Riblets:" + riblets_str) + try: + self.riblets = int(riblets_str) + except: + pass - #scrape ions - if self.status.find("Ions : ") != -1: - start_index = self.status.index('Ions : ') + 16 - ions_str = self.status[start_index:] - try: - end_index = riblets_str.index('Wearing') - except: - pass + #scrape ions + if self.status.find("Ions : ") != -1: + start_index = self.status.index('Ions : ') + 16 + ions_str = self.status[start_index:] + try: + end_index = riblets_str.index('Wearing') + except: + pass - ions_str = ions_str[:end_index] - #print("Riblets:" + riblets_str) - try: - self.ions = int(ions_str) - except: - pass + ions_str = ions_str[:end_index] + #print("Riblets:" + riblets_str) + try: + self.ions = int(ions_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) - try: - self.farm_year = int(year_str) - except: - pass - self.status = "" - + #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) + try: + self.farm_year = int(year_str) + except: + pass + self.status = "" + self.stat_parsed = True #index area def index_area(self,result): if self.area_indexed == False: @@ -937,6 +978,8 @@ class mutant(QWidget): self.me_check.setChecked(False) self.ba_check.setChecked(False) self.hu_check.setChecked(False) + + self.tab_color.emit(self.idx,'red') #Player starting condition def player_init(self): @@ -957,6 +1000,8 @@ class mutant(QWidget): self.me_check.setChecked(self.wander) self.ba_check.setChecked(self.bait) self.hu_check.setChecked(self.hunt) + + self.tab_color.emit(self.idx,'green') #Player starting condition def player_exit(self): @@ -978,6 +1023,8 @@ class mutant(QWidget): self.ba_check.setChecked(self.bait) self.hu_check.setChecked(self.hunt) + self.tab_color.emit(self.idx,'red') + #Resets connection with no activity def watchdog_t(self): if self.watchdog > 4: @@ -986,6 +1033,14 @@ class mutant(QWidget): self.watchdog = 0 else: self.watchdog = self.watchdog + 1 + + def watchdog_cmd(self): + if self.cmd_watchdog > 2: + if len(self.cmd_buffer)>0: + self.transmit_bfr() + self.cmd_watchdog = 0 + else: + self.cmd_watchdog = self.cmd_watchdog + 1 #Main game loop def mutants(self,result): @@ -1007,7 +1062,15 @@ class mutant(QWidget): self.selected_path = int(self.path_input.text()) except: pass - + + #Detect prompt + if result.find(">") != -1: + self.transmit_bfr() + self.cmd_watchdog = 0 + self.prompt = True + else: + self.prompt = False + #Nothing has happened in a while, time jump if self.no_action_cnt > self.na_thresh: self.time_travel() @@ -1017,10 +1080,11 @@ class mutant(QWidget): #Detect in play if result.find("Prepare to walk a thousand years!") != -1: self.in_play = True - self.player_init() - self.command_str.emit("blurb\r\n") - self.command_str.emit("deaf\r\n") - self.command_str.emit("memorize "+self.spell+"\r\n") + #self.player_init() + self.send_cmd("blurb\r\n") + self.send_cmd("deaf\r\n") + self.send_cmd("memorize "+self.spell+"\r\n") + self.tab_color.emit(self.idx,'green') print("Character in play..") #New area, set index, get location @@ -1043,18 +1107,6 @@ class mutant(QWidget): #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) @@ -1063,13 +1115,10 @@ class mutant(QWidget): self.index_area(result) #deposit riblets - if self.riblets > self.riblet_thresh and self.path_step == 0 and self.wander: + if self.riblets > self.riblet_thresh and self.path_step == 0 and self.wander and not self.in_combat: + self.send_cmd("stat\r\n") 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) @@ -1084,30 +1133,14 @@ class mutant(QWidget): #ion starvation if result.find("You're starving for IONS!") != -1: - self.command_str.emit("con gold-chunck\r\n") + self.send_cmd("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") + self.send_cmd("X\r\n") #Detect bait mode, add or remove from stock list if self.bait: @@ -1121,12 +1154,16 @@ class mutant(QWidget): #Exit game if.. if self.in_combat and result.find("You're not carrying a "+self.weapon.lower()) != -1: - self.command_str.emit("kick\r\n") + self.send_cmd("kick\r\n") + self.mqtt_str.emit(self.user+" has no weapon") #self.exit_game() #Lighten if self.wander and (result.find("It's too dark to see anything!") != -1 and self.path_step == 0): - self.command_str.emit("cast\r\n") + if self.char_sel == 4: + self.send_cmd("cast\r\n") + else: + self.time_travel() #GTFO #if result.find("You're blocked!") != -1 or len(self.local_monsters) > 4: @@ -1136,7 +1173,7 @@ class mutant(QWidget): # self.in_combat = False #Sell the loot - if (result.find("City Trading Centre") != -1 or result.find("Satan Inc. Trade Centre") != -1) and self.path_step == 0: + if (result.find("City Trading Centre") != -1 or result.find("Satan Inc. Trade Centre") != -1) and self.path_step == 0 and not self.in_combat: if len(self.sell_list) > 0: self.sell_items() @@ -1239,7 +1276,7 @@ class mutant(QWidget): self.farm_stock_items() if self.auto_ion: self.convert_items() - #print("convert") + #push("convert") def process_keys(self, key): @@ -1261,22 +1298,22 @@ class mutant(QWidget): if key==ord("8"): self.local_monsters = [] self.local_items = [] - self.command_str.emit("north\r\n") + self.send_cmd("north\r\n") if key==ord("2"): self.local_monsters = [] self.local_items = [] - self.command_str.emit("south\r\n") + self.send_cmd("south\r\n") if key==ord("4"): self.local_monsters = [] self.local_items = [] - self.command_str.emit("west\r\n") + self.send_cmd("west\r\n") if key==ord("6"): self.local_monsters = [] self.local_items = [] - self.command_str.emit("east\r\n") + self.send_cmd("east\r\n") #functions if key==ord("a"): @@ -1322,7 +1359,7 @@ class mutant(QWidget): #look around if key==ord("5"): - self.command_str.emit("look ") + self.send_cmd("look ") #meander status if key==ord("m"): @@ -1332,20 +1369,20 @@ class mutant(QWidget): else: self.wander = True print("Meander on") - self.command_str.emit("look\r\n") + self.send_cmd("look\r\n") #heal if key==ord("h"): - self.command_str.emit("heal\r\n") + self.send_cmd("heal\r\n") self.heal = True #look around if key==ord("l"): - self.command_str.emit("look\r\n") + self.send_cmd("look\r\n") #stats if key==ord("v"): - self.command_str.emit("stat\r\n") + self.send_cmd("stat\r\n") #sell items if key==ord("s"): @@ -1357,18 +1394,18 @@ class mutant(QWidget): st = input("Choose path input: ") self.selected_path = int(st) self.path_step = 1 - self.command_str.emit("Starting path..\r\n") + self.send_cmd("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.send_cmd(st+"\r\n") self.flush_input() #wield weapon if key==ord("w"): - self.command_str.emit("wie "+self.weapon+"\r\n") + self.send_cmd("wie "+self.weapon+"\r\n") #drop item if key==ord("d"): @@ -1376,7 +1413,7 @@ class mutant(QWidget): #toss = keyboard.read_key() st = input("drop item: ") drop_item = "drop " + st - self.command_str.emit(drop_item+"\r\n") + self.send_cmd(drop_item+"\r\n") #time travel if key==ord("t") and not self.in_combat: @@ -1385,7 +1422,7 @@ class mutant(QWidget): #toss = keyboard.read_key() st = input("year: ") year = "travel " + st - self.command_str.emit(year+"\r\n") + self.send_cmd(year+"\r\n") if key==ord("x"): pass @@ -1417,6 +1454,8 @@ class mutant(QWidget): self.command_str.emit(str(self.char_sel)+"\r\n") #self.mutants() self.logged_in = True + self.player_init() + #doesnt work yet def delete_line(self,line): cursor = self.console.textCursor() @@ -1430,7 +1469,7 @@ class mutant(QWidget): #main game loop def execute_loop(self, result): self.console.append(result) - self.console_lines = self.console_lines +1 + self.console_lines = self.console_lines + 1 if self.logged_in == False: self.login_listener(result) @@ -1524,27 +1563,22 @@ class MainWindow(QMainWindow): self.tab3 = QWidget() self.tab4 = QWidget() - #self.tabs.addTab(self.tab2,"Group 2") - #self.tabs.addTab(self.tab3,"Group 3") - #self.tabs.addTab(self.tab4,"Group 4") - self.mutant_list = [] print(player_list) for player in player_list: mutbox = QHBoxLayout() + index = player_list.index(player) print(player.usr) - mut = mutant(player) + print(index) + mut = mutant(player,index) self.mutant_list.append(mut) mutbox.addWidget(self.mutant_list[-1]) + self.mutant_list[-1].mqtt_str.connect(self.send_mqtt) self.mutant_list[-1].mqtt_str_quiet.connect(self.send_mqtt_quiet) - self.mutant_list[-1].mqtt_str_quiet.connect(self.send_mqtt_quiet) + self.mutant_list[-1].tab_color.connect(self.color_tab) tab = QWidget() tab.setLayout(mutbox) self.tabs.addTab(tab,player.usr) - - #self.tab2.setLayout(self.h_2.layout) - #self.tab3.setLayout(self.h_1.layout) - #self.tab4.setLayout(self.h_2.layout) self.layout.addWidget(self.tabs) self.setLayout(self.layout) @@ -1565,7 +1599,9 @@ class MainWindow(QMainWindow): self.formGroupBox.addRow(self.text_button,self.text_input) self.layout.addLayout(self.formGroupBox) - + def color_tab(self,idx,color): + self.tabs.tabBar().setTabTextColor(idx, QColor(color)) + #Events like mouse movement and keyboard action that happen on the main form def eventFilter(self, source, event): #print(source) @@ -1652,7 +1688,7 @@ class MainWindow(QMainWindow): def setup_mqtt(self): broker_address="192.168.86.27" - print("creating new instance") + #print("creating new instance") self.client = mqtt.Client("P1") #create new instance self.client.username_pw_set("homeassistant", "oes5gohng9gau1Quei2ohpixashi4Thidoon1shohGai2mae0ru2zaph2vooshai") self.client.connect(broker_address) diff --git a/robin-hood/banks.txt b/robin-hood/banks.txt deleted file mode 100644 index e40414c..0000000 --- a/robin-hood/banks.txt +++ /dev/null @@ -1,4 +0,0 @@ -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