-
Notifications
You must be signed in to change notification settings - Fork 8
/
readscrolls.lic
106 lines (93 loc) · 2.98 KB
/
readscrolls.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
=begin
This script reads every scroll in your scrollsack and displays a list of all the spells, and how many times they appear.
https://github.com/matt-lowe/lich-scripts
tillmen@lichproject.org
=end
unless defined?(GameObj)
echo 'Your version of Lich is too old for this script.'
exit
end
unless UserVars.scrollsack
echo 'scrollsack is not set. Use ;setting change scrollsack <container>'
exit
end
status_tags
scrollsack = GameObj.inv.find { |obj| obj.name =~ /#{UserVars.scrollsack}/ }
if scrollsack.nil?
scrollsack = GameObj.inv.find { |obj| obj.name =~ /#{UserVars.scrollsack.gsub(/\s+/, '.*')}/ }
echo scrollsack
end
if scrollsack.nil?
echo "failed to find scrollsack (#{UserVars.scrollsack}) in your inventory"
exit
end
if scrollsack.contents.nil? or scrollsack.contents.empty?
fput "open ##{scrollsack.id}"
end
if scrollsack.contents.nil? or scrollsack.contents.empty?
fput "look in ##{scrollsack.id}"
end
if scrollsack.contents.nil? or scrollsack.contents.empty?
echo 'failed to get the contents of your scrollsack.'
exit
end
scroll_list = scrollsack.contents
scroll_list.delete_if { |obj| obj.noun !~ /scroll|papyrus|palimpsest|paper|vellum|parchment/ }
maxlen = 0
scroll_count = 0
spell_count = 0
spell_list = Hash.new
spell_name = Hash.new
bad_scrolls = Array.new
for scroll in scroll_list
short_list = Array.new
dothis "read ##{scroll.id}", /^On the/
while (read_result = get) and (read_result !~ /<prompt/)
if read_result =~ /noun="([0-9]+)">([^<]+)</
spell_list[$1] = spell_list[$1].to_i + 1
spell_name[$1] = $2
maxlen = [$2.length,maxlen].max
short_list.push($1.to_i)
end
end
# bad_scrolls.push(scroll.id) if (short_list & [ 204, 208, 213, 113, 119, 114, 215, 207, 1718, 315, 713, 1711, 715, 716, 109, 210, 1720 ]).empty?
# bad_scrolls.push(scroll.id) if (short_list & [ 207, 208, 213, 713, 113, 1718, 1711, 119, 215, 204, 116, 715, 315, 1720, 114, 109, 618 ]).empty?
end
respond
for spell in spell_list.keys
respond(sprintf("%4s: %#{maxlen}s (%s)", spell, spell_name[spell], spell_list[spell].to_s))
end
respond
respond "#{spell_list.length} spells found on #{scroll_list.length} scrolls."
respond
#respond "bad scrolls: #{bad_scrolls.join(', ')}"
#respond
exit
look_result = dothis 'look in my ' + UserVars.scrollsack, /^In the(?:.*?In the)? <a[^>]+>[\w\s]+<\/a> you see/
look_result = look_result.split(/(<a[^>]+>)/)
scroll_list = Array.new
for link in look_result
if link =~ /exist="([^"]+)" noun="(?:scroll|papyrus|palimpsest|paper|vellum|parchment)"/
scroll_list.push('#' + $1)
end
end
maxlen = 0
spell_list = Hash.new
spell_name = Hash.new
for scroll in scroll_list
dothis 'read ' + scroll, /^On the/
begin
read_result = get
if read_result =~ /noun="([0-9]+)">([^<]+)</
spell_list[$1] = spell_list[$1].to_i + 1
spell_name[$1] = $2
maxlen = [$2.length,maxlen].max
end
end while read_result !~ /<prompt/
end
toggle_status
respond
for spell in spell_list.keys
respond(sprintf("%4s: %#{maxlen}s (%s)", spell, spell_name[spell], spell_list[spell].to_s))
end
respond