-
Notifications
You must be signed in to change notification settings - Fork 14
/
sneezy.py
224 lines (197 loc) · 7.13 KB
/
sneezy.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import importlib
import json
import time
import traceback
import modular
import modules.gzlogging
import modules.eval
# import modules.repeat
import modules.mapper
importlib.reload(modular)
importlib.reload(modules.gzlogging)
importlib.reload(modules.eval)
# importlib.reload(modules.repeat)
importlib.reload(modules.mapper)
honeToType = {
'heal light': 'cleric',
'harm light': 'cleric',
'armor': 'cleric',
'bless': 'cleric',
'rain brimstone': 'cleric',
'clot': 'cleric',
'create food': 'cleric',
'create water': 'cleric',
'cure poison': 'cleric',
'salve': 'cleric',
'heal serious': 'cleric',
'sterilize': 'cleric',
'remove curse': 'cleric',
'cure disease': 'cleric',
'refresh': 'cleric',
'heal critical': 'cleric',
'harm serious': 'cleric',
'cure blindness': 'cleric',
'cleric repair': 'cleric',
'expel': 'cleric',
'flamestrike': 'cleric',
'curse': 'cleric',
'disease': 'cleric',
'harm critical': 'cleric',
'numb': 'cleric',
'poison': 'cleric',
'infect': 'cleric',
'heal': 'cleric',
'summon': 'cleric',
'harm': 'cleric',
'plague of locusts': 'cleric',
'word of recall': 'cleric',
'blindness': 'cleric',
'paralyze limb': 'cleric',
'knit bone': 'cleric',
'penance': 'theolog',
'attune': 'theolog',
'blunt proficiency': 'combat',
'slash proficiency': 'combat',
'pierce proficiency': 'combat',
'barehand proficiency': 'combat',
'ranged proficiency': 'combat',
'sharpen': 'combat',
'smooth': 'combat',
'tactics': 'advent',
'bandage': 'advent',
'ride': 'advent',
'dissect': 'advent',
'butcher': 'advent',
'swim': 'advent',
'know animal': 'advent',
'defense': 'advent',
'know people': 'advent',
'lumberjack': 'advent',
'fishing': 'advent',
'alcoholism': 'advent',
'offense': 'advent',
'read magic': 'advent',
'climbing': 'advent',
'know veggie': 'advent',
'sign': 'advent',
'mend': 'advent',
'encamp': 'advent',
'know reptile': 'advent',
'know giantkin': 'advent',
'whittle': 'advent',
'evaluate': 'advent',
'know other': 'advent',
'know undead': 'advent',
'gutter cant': 'advent',
'gnoll jargon': 'advent',
'troglodyte pidgin': 'advent',
'know demon': 'advent',
'devotion': 'faith',
}
def honed(mud, groups):
skill = groups[0]
if 'honing' in mud.state:
mud.log("Honed {} in {} tries".format(skill, mud.state['honing'][1]))
del mud.state['honing']
if skill in honeToType:
honeType = 'prac ' + honeToType[skill]
mud.send(honeType)
if 'hones' not in mud.state:
mud.state['hones'] = {}
mud.state['hones'][skill] = time.time()
if 'hone_on_success' in mud.state:
mud.state['hone_on_success'](skill)
mud.timers["hone_again_notification_for_" + skill] = mud.mkdelay(301, lambda m: mud.log("You can now hone " + skill))
def showHones(mud, _):
found = False
if 'hones' in mud.state:
remove = set()
now = time.time()
for skill, honetime in mud.state['hones'].items():
if now - honetime > 300:
remove.add(skill)
else:
found = True
mud.show("{}: {}s remaining\n".format(skill, 300 - int(now - honetime)))
for skill in remove:
del mud.state['hones'][skill]
if not mud.state['hones']:
del mud.state['hones']
if not found:
mud.show("No skills honed recently")
def setSkillLevel(mud, groups):
if 'skillLevels' not in mud.state:
mud.state['skillLevels'] = {}
skill = groups[0]
learned = groups[1]
potential = groups[2] if len(groups) >= 3 else 'maxed'
mud.log('scraped {} at {}/{}'.format(skill, learned, potential))
mud.state['skillLevels'][skill] = (learned, potential)
ALIASES={
'sc': 'score',
'#hones': showHones,
}
TRIGGERS={
r'^You are thirsty\.$': 'drink waterskin',
r'^\*\*\* PRESS RETURN:': '',
r'^You feel your skills honing in regards to (.+)\.': honed,
r'^You feel Mezan, the father favoring you more in respects to (.+)\.': honed,
r'^(.+?) +Current: \((.+)\) +Potential: \((.+)\)': setSkillLevel,
r'^(.+?) +Current: \((.+)\) *': setSkillLevel,
}
class Sneezy(modular.ModularClient):
def __init__(self, mud, name):
self.name = name
self.logfname = '{}.log.gz'.format(name)
self.mapfname = 'sneezy.map'
self.modules = {}
mods = {
'eval': (modules.eval.Eval, []),
# 'repeat': (modules.repeat.Repeat, []),
'gzlogging': (modules.gzlogging.GzLogging, [self.logfname]),
'mapper': (modules.mapper.Mapper, [True, self.mapfname, True]),
}
for modname, module in mods.items():
try:
constructor, args = module
args = [mud] + args
self.modules[modname] = constructor(*args)
except Exception:
traceback.print_exc()
super().__init__(mud)
self.aliases.update(ALIASES)
self.triggers.update(TRIGGERS)
with open('passwords_sneezy.json', 'rb') as pws:
self.triggers.update(json.load(pws))
self.triggers["Type 'C' to connect with an existing character, or <enter> to see account menu."] = 'c\n' + name
self.aliases['#autohone ([^,]+), (.+)'] = lambda mud, groups: self.startAutoHone(groups[0], groups[1])
self.aliases['#killify'] = self.killify
def killify(self, mud, groups):
maxLevelsAboveMine = 0
myLevel = 2
mobs = self.gmcp['room']['mobs']
lowLevelMobs = list(filter(lambda x: x['level'] + maxLevelsAboveMine <= myLevel, mobs))
if not lowLevelMobs:
self.log('No candidate mobs')
return
mob = sorted(lowLevelMobs, key=lambda x: x['level'])[-1]
mud.send('k {}'.format(mob['name']))
def startAutoHone(self, skill, cmd):
self.log("Autohoning {} as {}".format(skill, cmd))
self.timers['autohone_' + cmd] = self.mktimernow(60*5 + 1, lambda mud: self.honeTimer(skill, cmd))
def honeTimer(self, skill, cmd):
def onHoneSuccess(skillHoned):
if skill == skillHoned:
# TODO: check for maxed skills
if skill in self.state['skillLevels'] and self.state['skillLevels'][skill][0] >= 99:
self.log("Removing " + skill + " from autohone")
del self.timers['autohone_' + cmd]
else:
self.setTimerRemaining('autohone_' + cmd, 301)
# multi-hone timers need work
self.state['hone_on_success'] = onHoneSuccess
self.state['honing'] = (cmd, 1)
def getHostPort(self):
return 'sneezymud.org', 7900
def getClass():
return Sneezy