-
Notifications
You must be signed in to change notification settings - Fork 177
/
almanac.lic
143 lines (119 loc) · 5.01 KB
/
almanac.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
=begin
Documentation: https://elanthipedia.play.net/Lich_script_repository#almanac
=end
custom_require.call(%w[common common-items])
class Almanac
def initialize
settings = get_settings
UserVars.almanac_last_use ||= Time.now - 600
@no_use_scripts = settings.almanac_no_use_scripts
@no_use_rooms = settings.almanac_no_use_rooms
@almanac_skills = settings.almanac_skills
@almanac = settings.almanac_noun
@priority_skills = settings.almanac_priority_skills
startup_delay = settings.almanac_startup_delay
# check to ensure almanac is defined in gear, and warn user if not
if settings.gear.find { |item| @almanac =~ /#{item[:adjective]}\s*#{item[:name]}/i }.nil?
message = "To minimize the possibility that items that you hold in your hands could be lost they should be listed in your `gear:`. Your almanac is not listed in your `gear:` settings:"
message += "\n - #{@almanac}"
message += "\nIf you need assistance with this, please ask in the lich discord (listed in #{$clean_lich_char}links) for help."
message += "\n\n---The script will now abort.---"
DRC.message(message)
exit
end
pause startup_delay
passive_loop
end
def passive_loop
loop do
use_almanac unless should_not_use_almanac?
pause
end
end
def almanac_sort_by_rate_then_rank(skills)
skills
.select { |skill| DRSkill.getxp(skill) < 18 }
.min_by { |skill| [DRSkill.getxp(skill), DRSkill.getrank(skill)] }
end
def skill_with_lowest_mindstate
list = []
DRSkill.list
.map { |skill| [skill.name, skill.exp, skill.rank] }
.select { |element| element[1] }
.reject { |_skill, _exp, rank| (rank.to_i == 1750 || rank.to_i == 0) }
.reject { |skill, _exp| skill == "Mechanical Lore" }
.select { |skill, exp| list.append [skill, exp] }
skill = list.sort_by(&:last).first[0].sub(/(Lunar|Life|Arcane|Holy|Elemental)\s/, '')
return skill
end
def use_almanac
unless @almanac_skills.empty?
training_skill = almanac_sort_by_rate_then_rank(@priority_skills) || almanac_sort_by_rate_then_rank(@almanac_skills) || skill_with_lowest_mindstate
echo("training skill is #{training_skill}")
return unless training_skill
end
# Pause scripts to prevent interference
until (scripts_to_unpause = DRC.safe_pause_list)
echo('Cannot pause, trying again in 30 seconds.')
pause 30
end
waitrt?
# Wait for any last output from paused scripts to resolve
# to mitigate things like combat-trainer doing `loot treasure`
# and getting a "I could not find what you were referring to" response
# (because no critter to loot) before the response to "get my almanac".
# In that race condition, we think we didn't get your almanac and
# the script exits, but that leaves you with an almanac in your hand
# and can cause combat-trainer to hang if it's trying to use a twohanded weapon.
pause 1
clear
unless DRCI.get_item_if_not_held?(@almanac) && DRCI.in_hands?(@almanac)
if DRCI.exists?(@almanac)
DRC.message('Hands full, will try again later')
DRC.safe_unpause_list(scripts_to_unpause)
return
else
DRC.message('Almanac not found, exiting')
DRC.safe_unpause_list(scripts_to_unpause)
exit
end
end
DRC.bput("turn #{@almanac} to #{training_skill}", 'You turn', 'You attempt to turn', /^What topic/) if training_skill
study_almanac
DRCI.put_away_item?(@almanac)
DRC.safe_unpause_list(scripts_to_unpause)
end
def study_almanac
case DRC.bput("study my #{@almanac}", /You believe you've learned something significant/, /^You've gleaned all the insight you can/, /^Study what/, 'interrupt your research', /^The pages of the .* seem worn/, /is only usable by a character with a Premium subscription/, /STUDY its contents\./)
when /^You've gleaned all the insight you can/, /^The pages of the .* seem worn/
UserVars.almanac_last_use = Time.now - 540
when /You believe you've learned something significant/
UserVars.almanac_last_use = Time.now
when /is only usable by a character with a Premium subscription/
DRC.message('Premium almanac detected in a non-premium account.')
DRC.message('Exiting')
DRCI.put_away_item?(@almanac)
exit
when /STUDY its contents\./
DRC.bput("open my #{@almanac}", /^You open/)
study_almanac
end
waitrt?
end
def should_not_use_almanac?
(hidden? || invisible? || almanac_on_cooldown? || hands_full? || running_no_use_scripts? || inside_no_use_room?)
end
def running_no_use_scripts?
@no_use_scripts.any? { |name| Script.running?(name) }
end
def inside_no_use_room?
@no_use_rooms.any? { |room| room.is_a?(Integer) ? room == Room.current.id : DRRoom.title.to_s[2..-3].match?(room) }
end
def almanac_on_cooldown?
(Time.now - UserVars.almanac_last_use.to_i).to_i < 600
end
def hands_full?
DRC.left_hand && DRC.right_hand && !DRCI.in_hands?(@almanac)
end
end
Almanac.new