forked from blind-coder/nethack-nhbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fixself.pm
executable file
·130 lines (118 loc) · 2.78 KB
/
Fixself.pm
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
use Comm;
my @safefoods = ("lichen corpse", "lizard corpse", "food ration", "perl",
"fortune cookie", "K-ration", "kelp frond",
"eucalyptus lea(?:f|ves)", "apple", "orange", "pear",
"melon", "banana", "carrot", "sprigs? of wolfsbane",
"cloves? of garlic", "lumps? of royal jelly", "cream pie",
"candy bar", "fortune cookie", "pancake", "lembas wafer",
"cram ration", "C-ration");
sub pickup_safefood($)
{
my $food = shift;
my $response;
foreach $safefood (@safefoods)
{
if ($food =~ /^(?:$safefood)s?$/)
{
out(",");
$response = response();
if ($response =~ /Pick up (?:an?|[0-9]+) (?:blessed |uncursed |cursed )?(.*?)s?\? \[yn#?aq\] \(y\)/)
{
out("y");
$response = response();
}
if ($response =~ /([a-zA-Z]) - (.*?)\./)
{
debug("Picked up safe? food item: $2 [slot $1] matches /$safefood/");
}
return 1;
}
}
return 0;
}
sub pickup_safefoods()
{
my ($response, $food, $safefood, $safe);
out(",");
response();
out("%\n");
while (1)
{
$response = response();
if ($response =~ /There are no %'s here\./)
{
out("q");
last;
}
elsif ($response =~ /Pick up (?:an?|[0-9]+) (?:blessed |uncursed |cursed )?(.*?)s?\? \[yn#?aq\] \(y\)/)
{
$food = $1;
$safe = 0;
foreach $safefood (@safefoods)
{
if ($food =~ /^$safefood$/)
{
debug("Picking up $food, matches /$safefood/");
out("y");
$safe = $safefood;
last;
}
}
out("n") unless ($safe);
}
elsif ($response =~ /([a-zA-Z]) - (.*?)\./)
{
debug("Picked up safe? food item: $2 [slot $1] matches /$safe/");
}
else
{
last;
}
}
return 0;
}
sub fix_hungry()
{
my ($response, $food, $safe);
out('e');
while (1)
{
$response = response();
return 0 if ($response =~ /You don't have anything to eat\./);
if ($response =~ /What do you want to eat\? \[([a-zA-Z-])+ or /)
{
$food = $1;
debug("Eating inventory item $food.");
out($food);
return 1;
}
elsif ($response =~ /There (?:is an?|are [0-9]+) (?:blessed |uncursed |cursed )?(.*?)(?:e?s)? here; eat (?:it|one)\?/)
{
$food = $1;
foreach $safe (@safefoods)
{
if ($food =~ /$safe/)
{
debug("Eating floor item $food.");
out('y');
return 1;
}
}
out('n');
}
}
return 0;
}
sub fix_weak()
{
my $response;
return 1 if fix_hungry();
# if fix_hungry fails, let's try some more drastic measures like prayer..
out("#pray\n");
return 1; #assume it worked for now..
}
sub fix_fainting()
{
return fix_weak();
}
1;