forked from TAEB/Eeek
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Eeek.py
executable file
·143 lines (119 loc) · 4.75 KB
/
Eeek.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/python
import sys
from curses import *
from myconstants import *
from NethackSock import *
from FramebufferParser import *
from SocketLogger import *
from DGLParser import *
from Personality import *
from Senses import *
from Console import *
from Hero import *
from Dungeon import *
from MonsterSpoiler import *
from Pathing import *
from TestBrain import *
from Cursor import *
from ItemDB import *
from Inventory import *
class Eeek:
def __init__(self):
self.mode = MODE_COMMANDS # Other is MODE_USERPLAY where you are in control of the hero
if CURSES:
# Initialize curses
cbreak()
noecho()
# Initialize the Kernel
Kernel()
# Set's up the socket
NethackSock()
# Socket observers
SocketLogger() # This should be before other stuff for easier debugging
FramebufferParser()
DGLParser()
# Stuff
Console()
Cursor()
Dungeon()
Hero()
MonsterSpoiler()
ItemDB()
Inventory()
# AI
Personality()
Senses()
Pathing()
# Brains
curBrain = TestBrain()
Kernel.instance.Personality.setBrain(curBrain) # Default brain
def connect(self, server, port):
Kernel.instance.NethackSock.connect(server, port)
Kernel.instance.NethackSock.start()
def run(self):
# User input
try:
while not Kernel.instance.NethackSock.done:
if CURSES:
input = chr(stdscr.getch())
if input == '/' and self.mode not in [MODE_CONSOLE, MODE_CURSOR]:
if Kernel.instance.Hero.y != None and Kernel.instance.Hero.x != None:
Kernel.instance.log("Starting cursor")
Kernel.instance.Cursor.start()
self.mode = MODE_CURSOR
Kernel.instance.Cursor.was = Kernel.instance.paused()
Kernel.instance.setPause(True)
Kernel.instance.Cursor.draw()
continue
elif input in ['~', '|'] and self.mode not in [MODE_CONSOLE, MODE_CURSOR]:
Kernel.instance.log("Opening console")
self.mode = MODE_CONSOLE
Kernel.instance.Console.was = Kernel.instance.paused()
Kernel.instance.setPause(True)
Kernel.instance.Console.draw()
elif self.mode == MODE_CURSOR:
if input == '/':
Kernel.instance.log("Stopping cursor")
self.mode = MODE_COMMANDS
Kernel.instance.setPause(Kernel.instance.Cursor.was)
continue
else:
Kernel.instance.Cursor.input(input)
Kernel.instance.Cursor.draw()
elif self.mode == MODE_CONSOLE:
if input in ['~', '|']:
Kernel.instance.log("Closing console")
self.mode = MODE_COMMANDS
Kernel.instance.setPause(Kernel.instance.Console.was)
else:
Kernel.instance.Console.input(input)
Kernel.instance.Console.draw()
elif self.mode == MODE_USERPLAY:
if input == '-':
Kernel.instance.log("Enering commands-mode")
self.mode = MODE_COMMANDS
else:
Kernel.instance.send(input)
elif self.mode == MODE_COMMANDS:
if input == ';':
Kernel.instance.log(str(Kernel.instance.curTile()))
elif input == 'u':
if not Kernel.instance.paused():
Kernel.instance.setPause(True)
else:
Kernel.instance.setPause(False)
elif input == 'p':
Kernel.instance.log("Entering userplay-mode")
self.mode = MODE_USERPLAY
except KeyboardInterrupt:
self.die("Ctrl+C")
except:
err = ",".join(map(str,sys.exc_info()))
self.die(msg=err)
self.die()
def die(self, msg='No quitmsg'):
Kernel.instance.NethackSock.send("Sy ")
Kernel.instance.NethackSock.done = True
if CURSES:
endwin()
Kernel.instance.die("Died from Eeek:%s" % msg)