You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

526 lines
17 KiB

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