forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavtalia.lic
95 lines (81 loc) · 2.99 KB
/
avtalia.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
=begin
Documentation: https://elanthipedia.play.net/Lich_script_repository#avtalia
=end
custom_require.call(%w[events])
no_kill_all
no_pause_all
### Avtalia defines an UserVars listing items in your avtalia_array.
### Each cambrinth has a value representing how much mana is available
### as well as how fresh the reading is. It can be used by other scripts as-needed
class Avtalia
def initialize
arg_definitions = [
[
{ name: 'window', regex: /window/i, optional: true, description: 'Toggle a window for Avtalia updates.' },
]
]
@args = parse_args(arg_definitions)
@settings = get_settings
@avtalia_array = @settings.avtalia_array
exit if @avtalia_array.empty?
if @args.window
if $frontend == 'genie' # fix genie bullshit
_respond("<streamWindow id='avtaliaWindow' title='avtaliaWindow' location='center' save='true' />")
echo('Be sure to open the avtaliaWindow window if not already open.')
else
_respond("<streamWindow id='avtaliaWindow' title='Avtalia' location='center' save='true' />")
end
_respond("<exposeStream id='avtaliaWindow'/>")
@window_cache = nil
end
add_avtalia_flags
execute
end
def execute
loop do
pause 10
process_avtalia
end
end
def add_avtalia_flags
UserVars.avtalia = {}
@settings.avtalia_array.each do |camb|
first = camb['name'].split.first
second = camb['name'].split.last
short_reg = first == second ? /\b#{first}/i : /#{first}.*\b#{second}/i
Flags.add("avtalia-full-#{camb['name']}", /^Your.* #{short_reg} pulses brightly with Lunar energy/)
Flags.add("avtalia-focus-#{camb['name']}", /A.* #{short_reg}.* pulses? .+ (?<mana>\d+)/)
UserVars.avtalia[camb['name']] = { 'mana' => 0, 'cap' => camb['cap'], 'time_seen' => Time.now }
end
end
def process_avtalia
return if @avtalia_array.empty?
@avtalia_array.each do |camb|
if Flags["avtalia-focus-#{camb['name']}"]
UserVars.avtalia[camb['name']]['mana'] = Flags["avtalia-focus-#{camb['name']}"][:mana].to_i
UserVars.avtalia[camb['name']]['time_seen'] = Time.now
end
if Flags["avtalia-full-#{camb['name']}"]
UserVars.avtalia[camb['name']]['mana'] = camb['cap']
UserVars.avtalia[camb['name']]['time_seen'] = Time.now
end
Flags.reset("avtalia-full-#{camb['name']}")
Flags.reset("avtalia-focus-#{camb['name']}")
end
if @args.window
new_message = UserVars.avtalia.map { |item, stats| "#{item}: #{stats['mana']}/#{stats['cap']}" }.join("\r\n")
return if @window_cache == new_message
@window_cache = new_message
_respond("<clearStream id=\"avtaliaWindow\"/>\r\n")
_respond("<pushStream id=\"avtaliaWindow\"/>#{new_message}\r\n<popStream/>\r\n")
end
end
end
before_dying do
UserVars.avtalia = {}
get_settings.avtalia_array.each do |camb|
Flags.delete("avtalia-full-#{camb['name']}")
Flags.delete("avtalia-focus-#{camb['name']}")
end
end
Avtalia.new