-
Notifications
You must be signed in to change notification settings - Fork 8
/
autoforage.lic
193 lines (178 loc) · 6.73 KB
/
autoforage.lic
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
=begin
This script runs around foraging for herbs until you have a herbsack with 50 bites of each herb
author: Tillmen (tillmen@lichproject.org)
game: Gemstone
tags: herbs
version: 0.2
required: Lich >= 4.6.0
changelog:
0.2 (2015-04-27):
add support for scripted containers
don't heal when injured if Troll's Blood is active
use map tags instead of hard-coded room numbers
cast 603 if known and not active
cast sanctury if known and kneel
=end
unless Vars.herbsack
echo 'error: No herbsack has been set. Use ;vars set herbsack=<container>'
exit
end
unless Vars.lootsack
echo 'error: No lootsack has been set. Use ;vars set lootsack=<container>'
exit
end
# fixme: add options for use_sanct, max_travel_time, herb_list, and done_goto
use_sanct = true
max_travel_time = 30
done_goto = Room.current.id
herb_list = [ 'haphip root', 'pothinir grass', 'ephlox moss', 'calamia fruit', 'sovyn clove', 'wolifrew lichen', 'woth flower', 'torban leaf', 'acantha leaf', 'ambrominas leaf', 'cactacae spine', 'basal moss', 'aloeas stem' ]
put_regex = /^You (?:attempt to shield .*? from view as you |discreetly |carefully |absent-mindedly )?(?:put|place|slip|tuck|add|hang|drop|untie your|find an incomplete bundle|wipe off .*? and sheathe)|^A sigh of grateful pleasure can be heard as you feed .*? to your|^As you place|^I could not find what you were referring to\.$|^Your bundle would be too large|^The .+ is too large to be bundled\.|^As you place your|^The .*? is already a bundle|^Your .*? won't fit in .*?\.$|^You can't .+ It's closed!$/
get_regex = /^You (?:shield the opening of .*? from view as you |discreetly |carefully |deftly )?(?:remove|draw|grab|reach|slip|tuck|retrieve|already have|unsheathe)|^Get what\?$|^Why don't you leave some for others\?$|^You need a free hand/
get_success_regex = /^You (?:shield the opening of .*? from view as you |discreetly |carefully |deftly )?(?:remove|draw|grab|reach|slip|tuck|retrieve|already have|unsheathe)/
last_sanct_id = nil
#
# this proc handles all the foraging and bundling in a room
# returns true if the bundle is full and we should move on to the next herb
# returns false if the room ran dry
#
forage = proc { |herb|
bundle_full = false
begin
#
# Bring up minor sanctuary for safety and quiet and kneels to speed things up
#
if use_sanct and Spell[213].known? and Spell[213].affordable? and (last_sanct_id != Room.current.id)
Spell[213].cast
fput 'kneel'
last_sanct_id = Room.current.id
end
#
# forage faster
#
if Spell[506].known? and Spell[506].affordable? and not Spell[506].active?
Spell[506].cast
elsif Spell[402].known? and Spell[402].affordable? and not Spell[402].active?
Spell[402].cast
elsif Spell[602].known? and Spell[603].affordable? and not Spell[603].active?
Spell[603].cast
end
#
# paranoia
#
if checkleft
dothis 'stow left', put_regex
end
if checkright
dothis 'stow right', put_regex
end
#
# forage
#
forage_result = dothistimeout "forage for #{herb}", 5, /^You forage|^You make so much noise that only the dead would not notice you thrashing about in your unsuccessful search\.$|^You stumble about in a fruitless attempt at foraging\.$|you are unable to find anything useful|^As you carefully forage around you (can find no hint|see no evidence) of what you are looking for\.|^You begin to forage around when your hand comes into contact with something that stabs you in the finger\.$|^As you forage around you suddenly feel a sharp pain in your right hand!|^You begin to forage around when suddenly you feel a burning sensation in your hand\.$|^You fumble about so badly in your search that you can only hope no one was watching you\.$/
sleep 0.5
waitrt?
if forage_result =~ /^You forage briefly and manage to find/
#
# we found something, try to bundle it
#
get_result = dothis "get my #{herb} from my #{Vars.herbsack}", get_regex
if get_result =~ get_success_regex
#
# bundle; if theres too much to bundle, eat and try again
#
loop {
bundle_result = dothistimeout 'bundle', 3, /^Carefully, you combine|^If you add anything more to this bundle|^You do not have anything to bundle!$/
if bundle_result =~ /^Carefully, you combine/
dothis "put my #{herb} in my #{Vars.herbsack}", put_regex
break
elsif bundle_result =~ /^If you add anything more to this bundle/
dothis "eat my #{herb}", /^You take a bite/
#
# stop foraging for this herb
#
bundle_full = true
else
break
end
}
else
#
# there's nothing to bundle with, just put it away and continue
#
dothis "put my #{herb} in my #{Vars.herbsack}", put_regex
end
elsif forage_result =~ /^As you forage around you suddenly feel a sharp pain in your right hand!/
if Spell[1125].active?
# Troll's Blood
elsif Spell[1102].known? and Spell[1102].affordable?
Spell[1102].cast # Limb Repair
else
Script.run('useherbs')
end
end
#
# try again unless the room is dry or the bundle is full
#
end until (bundle_full == true) or forage_result.nil? or (forage_result =~ /you are unable to find anything useful|^As you carefully forage around you (can find no hint|see no evidence) of what you are looking for\./)
bundle_full
}
#
# try to open the herb pouch, remember to close it or not
#
open_result = dothis "open my #{Vars.herbsack}", /^You open|^That is already open\.$/
if open_result =~ /^You open/
close_herbsack = true
else
close_herbsack = false
end
empty_hands
for herb in herb_list
room_list = Room.list.find_all { |r| r.tags.include?("some #{herb}") }.collect { |r| r.id }
room_list.delete(3603)
room_list.delete(3602)
room_list.delete(3601)
until room_list.empty?
#
# goto a room with this herb, or move on to the next herb
#
this_room = Room.current
next_room = this_room.find_nearest(room_list)
room_list.delete(next_room)
break if next_room.nil?
unless (next_room == Room.current.id)
path = Room.current.path_to(next_room)
break if path.nil?
path.push(next_room)
if (Map.estimate_time(path) > max_travel_time)
echo "nearest room with #{herb} exceeds max_travel_time setting"
break
end
Script.run('go2', next_room.to_s)
if (this_room == Room.current)
echo 'move appears to have failed'
break
end
end
unless checkpcs or checknpcs
#
# forage until the room is dry or the bundle is full
#
bundle_full = forage.call(herb)
#
# move on to the next herb if the bundle is full
#
break if bundle_full
end
end
end
fill_hands
#
# close the herbsack if we opened it
#
if close_herbsack
dothis "close my #{Vars.herbsack}", /^You close|^That is already closed\.$/
end
#
# go somewhere nice
#
Script.run('go2', done_goto.to_s) if done_goto