Browse Source
Merge branch 'master' of https://bibbitgit.duckdns.org/melancholytron/qmutants
BradDev
Merge branch 'master' of https://bibbitgit.duckdns.org/melancholytron/qmutants
BradDev
10 changed files with 264 additions and 3446 deletions
-
4doctor/banks.txt
-
0file
-
10mq.py
-
571mutant function.py
-
630mutant function.txt
-
661mutants.py
-
526mutants_localbbs.py
-
812mutants_paths.py
-
492qmutants.py
-
4robin-hood/banks.txt
@ -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 |
|||
|
|||
@ -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") |
|||
@ -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 |
|||
@ -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 |
|||
|
|||
|
|||
@ -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 |
|||
|
|||
|
|||
@ -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 |
|||
|
|||
|
|||
@ -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 |
|||
|
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue