forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
faux-atmo.lic
94 lines (82 loc) · 2.41 KB
/
faux-atmo.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
=begin
Documentation: https://elanthipedia.play.net/Lich_script_repository#faux-atmo
=end
custom_require.call(%w[common events])
class FauxAtmo
def initialize
arg_definitions = [
[
{ name: 'debug', regex: /debug/i, optional: true, description: 'Enable debug output' }
]
]
args = parse_args(arg_definitions)
settings = get_settings
@debug = UserVars.faux_atmo_debug || args.debug || false
@no_use_scripts = settings.faux_atmo_no_use_scripts
@no_use_rooms = settings.faux_atmo_no_use_rooms
@interval = settings.faux_atmo_interval * 60
@items = settings.faux_atmo_items.select { |item| item_is_valid?(item) }
if @items.empty?
DRC.message("No items to check. Ending script. Double check your settings.")
exit
end
if settings.faux_atmo_random
@items.shuffle!
@items.each { |item| item['verbs'].shuffle! }
echo "shuffled items and verbs: #{@items}" if @debug
end
passive_run
end
def item_is_valid?(item)
echo "Validating item: #{item}" if @debug
if item['name'].nil? || item['name'].empty?
DRC.message("No name for item #{item}. Ignoring item. Double check your settings.")
false
elsif item['verbs'].nil? || item['verbs'].empty?
DRC.message("No verbs for item #{item}. Ignoring item. Double check your settings.")
false
else
true
end
end
def no_use_script?
@no_use_scripts.any? { |name| Script.running?(name) }
end
def no_use_room?
@no_use_rooms.any? { |name| /#{name}/ =~ DRRoom.title || name.to_s == Room.current.id.to_s }
end
def ready_to_use_item?
!invisible? && !hidden? && !no_use_script? && !no_use_room?
end
def passive_run
loop do
loop do
break if ready_to_use_item?
echo "Waiting for conditions to be right..." if @debug
pause 10
end
do_item
echo "Waiting #{@interval} seconds to perform an action again" if @debug
pause @interval
end
end
def do_item
do_verb(get_then_rotate(@items))
end
def do_verb(item)
waitrt?
verb = get_then_rotate(item['verbs'])
fput("#{verb} my #{item['name']}")
waitrt?
end
def get_then_rotate(list)
# This ensures that the first time
# this method is called on a list
# we indeed return the first item,
# not rotate and return the second item.
item = list.first
list.rotate!
item
end
end
FauxAtmo.new