forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
almanac.lic
104 lines (81 loc) · 2.96 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
=begin
Documentation: https://elanthipedia.play.net/Lich_script_repository#almanac
=end
custom_require.call(%w[common common-items drinfomon])
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
startup_delay = settings.almanac_startup_delay
pause startup_delay
passive_loop
end
def passive_loop
loop do
use_almanac if should_use_almanac?
pause 20
end
end
def use_almanac
unless @almanac_skills.empty?
training_skill = @almanac_skills
.select { |skill| DRSkill.getxp(skill) < 18 }
.sort_by { |skill| [DRSkill.getxp(skill), DRSkill.getrank(skill)] }.first
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
if training_skill
DRC.bput("turn #{@almanac} to #{training_skill}", 'You turn', 'You attempt to turn')
end
DRC.bput("study my #{@almanac}", 'You set about', 'gleaned all the insight you can', 'Study what', 'interrupt your research', 'The pages of the .* seem worn')
waitrt?
DRCI.put_away_item?(@almanac)
UserVars.almanac_last_use = Time.now
DRC.safe_unpause_list(scripts_to_unpause)
end
def should_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 === DRRoom.title.to_s()[2..-3] || room == Room.current.id }
end
def almanac_on_cooldown?
(Time.now - UserVars.almanac_last_use) < 600
end
def hands_full?
DRC.left_hand && DRC.right_hand && !DRCI.in_hands?(@almanac)
end
end
Almanac.new