From 4e1178350fce53a1cfee6feed86a94f6abcb2dc6 Mon Sep 17 00:00:00 2001 From: Joe DiPrima Date: Thu, 29 Dec 2022 12:08:21 -0600 Subject: [PATCH] 12/29/2022 --- qmutants.py | 256 +++++++++++++++++++++++++--------------------------- 1 file changed, 122 insertions(+), 134 deletions(-) diff --git a/qmutants.py b/qmutants.py index 5037021..b845fb1 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): @@ -438,7 +439,8 @@ 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.send_cmd("look\r\n") @@ -584,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: + 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 @@ -608,7 +614,8 @@ class mutant(QWidget): self.sell_list.pop(0) 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) @@ -616,8 +623,10 @@ class mutant(QWidget): 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) @@ -771,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.send_cmd("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.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 + 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: @@ -1097,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.send_cmd("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.send_cmd("con nuclear-decay\r\n") - self.stock_list.remove("Nuclear-Decay") - #print(self.stock_list) #parse status self.parse_stat(result) @@ -1118,6 +1116,7 @@ class mutant(QWidget): #deposit riblets if self.riblets > self.riblet_thresh and self.path_step == 0 and self.wander: + self.send_cmd("stat\r\n") self.path_step = 1 #process wander @@ -1142,18 +1141,6 @@ class mutant(QWidget): if self.wander and result.find("The weight of all your items forces you to the ground.") != -1: self.wander = False self.send_cmd("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.send_cmd("con gold-chunck\r\n") - self.send_cmd("get nuclear-decay\r\n") - - #Dropped the bait, pick it back up - if result.find("The Monster-Bait fell out of your sack!") != -1: - self.time_steps = 0 - self.send_cmd("con gold-chunck\r\n") - self.send_cmd("get monster-bait\r\n") #Detect bait mode, add or remove from stock list if self.bait: @@ -1168,6 +1155,7 @@ class mutant(QWidget): #Exit game if.. if self.in_combat and result.find("You're not carrying a "+self.weapon.lower()) != -1: self.send_cmd("kick\r\n") + self.mqtt_str.emit(self.user+" has no weapon") #self.exit_game() #Lighten @@ -1585,7 +1573,7 @@ class MainWindow(QMainWindow): mut = mutant(player,index) self.mutant_list.append(mut) mutbox.addWidget(self.mutant_list[-1]) - self.mutant_list[-1].mqtt_str_quiet.connect(self.send_mqtt_quiet) + 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].tab_color.connect(self.color_tab) tab = QWidget() @@ -1700,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)