forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlichbot.lic
298 lines (246 loc) · 9.13 KB
/
lichbot.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
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# want_script_output
=begin
Documentation: https://elanthipedia.play.net/Lich_script_repository#lichbot
=end
custom_require.call(%w(common common-arcana common-items common-validation drinfomon events))
class Lichbot
include DRC
include DRCA
include DRCI
def initialize(sleep)
Flags.add('give-accepted', '.* has accepted your offer and is now holding .*')
Flags.add('give-declined', '.* has declined the offer')
Flags.add('give-expired', 'Your offer to .* has expired')
Flags.add('stopped-listening', 'Your teacher is not here, so you are no longer learning anything', '.* stops teaching')
@settings = get_settings
@last_action = Time.now
@last_dump_junk = Time.now
@last_teacher = nil
@inventory = []
refresh_inventory
fput('avoid !all')
fput('avoid whispering')
fput('avoid teaching') unless sleep
end
def accept(character)
@last_action = Time.now
waitrt?
case bput('accept', 'You accept', 'would push you over your item limit')
when 'would push you over your item limit'
fput "whisper #{character} ***ERROR*** I am at my inventory limit and cannot accept that."
fput 'decline'
return
end
stow_hands
if right_hand || left_hand
fput("drop my #{right_hand}") if right_hand
fput("drop my #{left_hand}") if left_hand
fput "whisper #{character} ***ERROR*** I was unable to stow that item, so I have dropped it. If you cannot pick it up, try again in 30 seconds."
else
refresh_inventory
end
end
def list_buffs(character)
@last_action = Time.now
fput "whisper #{character} My buffs are:"
@settings.lichbot_buffs.each { |buff| fput "whisper #{character} #{buff['name']} [#{buff['abbrev']}] - #{buff['description']}" }
fput "whisper #{character} END"
end
def cast_buff(character, abbrev)
@last_action = Time.now
buff_data = @settings.lichbot_buffs.find { |buff| buff['abbrev'] == abbrev }
unless buff_data
fput "whisper #{character} I'm sorry, I do not know spell [#{abbrev}]"
return
end
fput "whisper #{character} Preparing [#{buff_data['name']}] now"
buff_data = buff_data.clone
buff_data['cast'] = "cast #{character}"
buff(buff_data, @settings)
fput "whisper #{character} Buffing complete"
end
def give(character, item)
@last_action = Time.now
unless get_item?(item)
fput "whisper #{character} Sorry, I failed to find [#{item}] in my inventory"
return
end
Flags.reset('give-accepted')
Flags.reset('give-expired')
Flags.reset('give-declined')
return unless give_item?(character, item, false)
pause 0.5 until Flags['give-accepted'] || Flags['give-expired'] || Flags['give-declined']
stow_hands
refresh_inventory if Flags['give-accepted']
end
def give_item?(character, item, repeat = false)
if repeat
fput('swap') unless right_hand
command = "give #{character}"
else
command = "give my #{item} to #{character}"
end
case bput(command, 'You offer', 'What is it', "You don't need to specify the object")
when 'What is it'
fput "whisper #{character} Sorry, I failed to give you [#{item}]"
stow_hands
return false
when "You don't need to specify the object"
return give_item?(character, item, true)
end
true
end
def inventory(character)
@last_action = Time.now
fput "whisper #{character} My inventory is:"
@inventory.each { |item| fput "whisper #{character} #{item}" }
fput "whisper #{character} END"
end
def help(character)
@last_action = Time.now
fput "whisper #{character} Supported commands are:"
fput "whisper #{character} (help) - this list"
fput "whisper #{character} (inv|inventory) - view the items I have available"
fput "whisper #{character} (give|giveme) [item] - take an item from me"
if @settings.lichbot_buffs
fput "whisper #{character} (buffs|spells) - view the buffs I can cast"
fput "whisper #{character} (buff|cast) [abbreviation] - receive [abbreviation] buff from me"
end
fput "whisper #{character} I will also accept and stow any item you trade me."
end
def ping
check_for_junk
return unless @settings.lichbot_train_when_idle
return if @last_action + 60 * 3 > Time.now
@last_action = Time.now
if Flags['stopped-listening'] || @last_teacher.nil? || !listen?(@last_teacher)
classes = assess_teach
@last_teacher = classes
.reject { |t, s| t.nil? || s.nil? }
.sort_by { |_t, s| [DRSkill.getxp(s), DRSkill.getrank(s)] }
.find { |t, _s| listen?(t) }
.first
Flags.reset('stopped-listening')
end
if should_train?('Attunement')
bput('perc', 'You reach out')
waitrt?
end
return unless should_train?('Augmentation') || should_train?('Arcana')
buff_data = @settings
.lichbot_buffs
.sort_by { |spell| DRSpells.active_spells[spell['name']] || 0 }
.first
buff(buff_data, @settings) if buff_data
end
private
def check_for_junk
return if DRRoom.room_objs.count < 10
return if @last_dump_junk + 60 * 1 > Time.now
@last_dump_junk = Time.now
if @settings.lichbot_compost
prepare?('compost', 1)
pause 1
cast?
end
return if DRRoom.room_objs.count.zero?
fix_standing
fput('dump junk')
end
def should_train?(skill)
DRSkill.getxp(skill) < 28
end
def get_item?(item)
waitrt?
case bput("get #{item}", 'You get', 'You are already holding', 'But that is already in your inventory', 'Please rephrase', 'What were you', 'You should stop playing')
when 'But that is already in your inventory'
return get_item?("second #{item}")
when 'You should stop playing'
bput('stop play', 'You stop playing your song', 'In the name of', 'But you\'re not performing')
return get_item?(item)
when 'Please rephrase', 'What were you'
return false
end
true
end
def refresh_inventory
waitrt?
bput('inv list', 'Roundtime')
log = reget(400)
start_index = log.rindex { |x| x =~ /You have/i } + 1
end_index = log.rindex { |x| x =~ /Roundtime/i } - 1
return unless start_index && end_index
@inventory =
log[start_index..end_index]
.select { |item| item.lstrip.start_with?('-') }
.map { |item| item.strip[1..-1] }
end
end
arg_definitions = [
[
{ name: 'start', regex: /start/i, description: 'Required: prevents accidentally starting up lichbot' },
{ name: 'announce', regex: /announce/i, optional: true, description: 'If arg is present, lichbot will announce its presence in LNet' },
{ name: 'sleep', regex: /sleep/i, optional: true, description: 'If arg is present, lichbot will sleep so as not to gain experience' },
{ name: 'greet', regex: /greet/i, optional: true, description: 'If arg is present, lichbot will greet characters after validating (but only once)' }
]
]
args = parse_args(arg_definitions)
lichbot = Lichbot.new(args.sleep)
validator = CharacterValidator.new(args.announce, args.sleep, args.greet, 'Lichbot')
@last_room_list = []
loop do
line = script.gets?
pause 0.05 unless line
if DRRoom.pcs != @last_room_list
(DRRoom.pcs - @last_room_list).each { |name| validator.validate(name) }
@last_room_list = DRRoom.pcs
end
case line
when /^(.*) offers you (.*). Enter ACCEPT to accept the offer or DECLINE to decline it. The offer will expire in 30 seconds.$/
character = Regexp.last_match(1)
if validator.valid?(character)
lichbot.accept(character)
else
fput('decline')
end
when /^(.*) whispers, "(inv|inventory)"$/i
character = Regexp.last_match(1)
next unless validator.valid?(character)
lichbot.inventory(character)
when /^(.*) whispers, "(help)"$/i
character = Regexp.last_match(1)
next unless validator.valid?(character)
lichbot.help(character)
when /^(.*) whispers, "(buffs|spells)"$/i
character = Regexp.last_match(1)
next unless validator.valid?(character)
lichbot.list_buffs(character)
when /^(.*) whispers, "(give|giveme) (.*)"$/i
character = Regexp.last_match(1)
item = Regexp.last_match(3)
next unless validator.valid?(character)
lichbot.give(character, item)
when /^(.*) whispers, "(buff|cast) (.*)"$/i
character = Regexp.last_match(1)
abbrev = Regexp.last_match(3)
next unless validator.valid?(character)
lichbot.cast_buff(character, abbrev)
when /^(.*) whispers, ".*"$/i
character = Regexp.last_match(1)
next unless validator.valid?(character)
fput "whisper #{character} I'm sorry, I did not understand that command"
lichbot.help(character)
when /^\[server\]: "DR:(.*) is tuned to the following channels.*"$/
character = Regexp.last_match(1)
validator.confirm(character)
when /^\[server\]: "DR:(.*) is connected but not tuned to any channels.*"$/
character = Regexp.last_match(1)
validator.confirm(character)
when /^\[Private\]-.*:(.*): "RequestSlackToken"/
character = Regexp.last_match(1)
validator.confirm(character)
validator.send_slack_token(character)
else
lichbot.ping
end
end