forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuff-watcher.lic
More file actions
129 lines (105 loc) · 4.52 KB
/
Copy pathbuff-watcher.lic
File metadata and controls
129 lines (105 loc) · 4.52 KB
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
=begin
Documentation: https://elanthipedia.play.net/Lich_script_repository#buff-watcher
=end
no_kill_all
no_pause_all
custom_require.call(%w[common common-arcana common-items drinfomon spellmonitor])
class BuffWatcher
def initialize
arg_definitions = [
[
# override the buff name, optionally override the startup delay
{ name: 'buff_set_name', regex: /^[a-z][\w\-]+$/i, optional: false, description: 'Name of a set of buffs defined in waggle_sets in your YAML' },
{ name: 'delay', regex: /^\d+$/, optional: true, description: 'Override buff_watcher_startup_delay from yaml' }
],
[
# use yaml config for buff name, override the startup delay
{ name: 'delay', regex: /^\d+$/, optional: false, description: 'Override buff_watcher_startup_delay from yaml' }
],
[
# no args, use yaml config and defaults
]
]
args = parse_args(arg_definitions)
@settings = get_settings
@no_use_scripts = @settings.buff_watcher_no_use_scripts
@no_use_rooms = @settings.buff_watcher_no_use_rooms
@startup_delay = args.delay || @settings.buff_watcher_startup_delay
@passive_delay = @settings.buff_watcher_passive_delay
@buff_set_name = args.buff_set_name || @settings.buff_watcher_name || 'default'
@barb_buffs_inner_fire_threshold = @settings.barb_buffs_inner_fire_threshold
# Don't allow users to make foolish mistakes, always prevent use during go2/burgle
@no_use_scripts << 'go2'
@no_use_scripts << 'burgle'
# Pause for the startup delay so you can control spammyness of autostart scripts
pause @startup_delay
unless @settings.waggle_sets[@buff_set_name]
DRC.message("No spells defined in buff set '#{@buff_set_name}'. Ending script. Double check your settings.")
exit
end
# Run passively in a loop
# If you want to run this only once, just call `buff` script directly
passive_run
end
def passive_run
loop do
activate_buffs if should_activate_buffs?
pause @passive_delay
end
end
def should_activate_buffs?
!(hidden? || invisible? || running_no_use_scripts? || inside_no_use_room? || need_inner_fire? || buffs_active? || DRStats.guild.nil?)
end
def activate_buffs
# Pause other scripts so they don't interfere with our casting
scripts_to_unpause = DRC.smart_pause_all
temp_left_item = nil
waitrt?
# Free up a hand in case you use held cambrinth
unless DRStats.thief? || DRStats.barbarian? || !use_stored_cambrinth?
if /nothing in your left hand\.$|at your empty hands\.$/ !~ DRC.bput('glance', /You glance down .*/)
# If both hands are full, store the left hand item in a variable for future
# use and lower the left hand to the feet slot.
# - Left causes less problems with combat (less likely to be a loaded weapon)
# - Feet slot causes less space/correct container issues
if DRC.left_hand && DRC.right_hand
temp_left_item = DRC.left_hand
temp_left_item = nil unless DRCI.lower_item?(DRC.left_hand)
end
end
end
# Do the needful
DRCA.do_buffs(@settings, @buff_set_name)
# Pick item back up if you lowered something
DRCI.get_item?(temp_left_item) if temp_left_item
# Resume scripts
DRC.unpause_all_list(scripts_to_unpause)
end
def buffs_active?
if DRStats.thief?
# Elements in the waggle set are ability names (strings) without the Khri prefix
return @settings.waggle_sets[@buff_set_name].all? { |name| DRSpells.active_spells["Khri #{name}"] }
elsif DRStats.barbarian?
# Elements in the waggle set are ability names (strings)
return @settings.waggle_sets[@buff_set_name].all? { |name| DRSpells.active_spells[name] }
else
# Elements in the waggle set are maps of spell name to spell data
return @settings.waggle_sets[@buff_set_name].all? { |name, data| DRSpells.active_spells[name] && (data['recast'].nil? || DRSpells.active_spells[name].to_i > data['recast']) }
end
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 need_inner_fire?
return false unless DRStats.barbarian?
DRStats.mana < @barb_buffs_inner_fire_threshold
end
def use_stored_cambrinth?
@settings.stored_cambrinth || @settings.cambrinth_items.any? { |item| item['stored'] }
end
end
# Don't auto-run during unit tests
BuffWatcher.new unless $_TEST_MODE_