2 changed files with 0 additions and 1201 deletions
@ -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 |
|||
@ -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 |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue