forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperformance-monitor.lic
155 lines (138 loc) · 5.02 KB
/
performance-monitor.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
144
145
146
147
148
149
150
151
152
153
154
155
=begin
Documentation: https://elanthipedia.play.net/Lich_script_repository#performance-monitor
=end
unless HAVE_GTK
respond
respond 'error: ruby-gtk bindings are not installed or failed to load'
respond
exit
end
custom_require.call(%w(textsubs))
class PerformanceFilter
def initialize
@settings = get_settings
@weapon_hits = {}
@weapon_rts = {}
@settings.performance_monitor_weapons.each do |x|
@weapon_hits[x] = []
@weapon_rts[x] = []
end
@weapon_stats = []
@last_weapon = nil
@new_hit = false
@damage_subs = [
['a light hit', 'a light hit (1/23)'],
['a good hit', 'a good hit (2/23)'],
['a good strike', 'a good strike (3/23)'],
['a solid hit', 'a solid hit (4/23)'],
['a hard hit', 'a hard hit (5/23)'],
['a strong hit', 'a strong hit (6/23)'],
['a heavy strike', 'a heavy strike (7/23)'],
['a very heavy hit', 'a very heavy hit (8/23)'],
['an extremely heavy hit', 'an extremely heavy hit (9/23)'],
['a powerful strike', 'a powerful strike (10/23)'],
['a massive strike', 'a massive strike (11/23)'],
['an awesome strike', 'an awesome strike (12/23)'],
['a vicious strike', 'a vicious strike (13/23)'],
['an earth-shaking strike', 'an earth-shaking strike (14/23)'],
['a demolishing hit', 'a demolishing hit (15/23)'],
['a spine-rattling strike', 'a spine-rattling strike (16/23)'],
["a devastating hit(?! \(That'll leave a mark!\))", 'a devastating hit (17/23)'],
["a devastating hit \(That'll leave a mark!\)", "a devastating hit (That'll leave a mark!) (18/23)"],
['an overwhelming strike', 'an overwhelming strike (19/23)'],
['an obliterating hit', 'an obliterating hit (20/23)'],
['an annihilating strike', 'an annihilating strike (21/23)'],
['a cataclysmic strike', 'a cataclysmic strike (22/23)'],
['an apocalyptic strike', 'an apocalyptic strike (23/23)']
]
end
def weapon_list
@settings.performance_monitor_weapons
end
def process_line(line)
@damage_subs.each { |x| line.gsub!(x.first, x.last) }
weapon_name = @settings.performance_monitor_weapons.find { |name| %r{^<.*\b#{name}\b.*\((\d+)/23\)} =~ line }
if weapon_name
@weapon_hits[weapon_name].push(Regexp.last_match(1).to_i)
@last_weapon = weapon_name
@new_hit = true
end
if @new_hit && /roundtime.*(\d+)/i =~ line
@new_hit = false
@weapon_rts[@last_weapon].push(Regexp.last_match(1).to_i)
update_stats
true
else
false
end
end
def update_stats
@weapon_stats = []
@weapon_hits.each do |weapon, hits|
dmg = hits.inject(&:+)
rt = @weapon_rts[weapon].inject(&:+)
@weapon_stats.push(weapon: weapon, avgrt: rt * 1.0 / hits.size, avgdps: dmg * 1.0 / rt)
end
end
attr_reader :weapon_stats
end
def update_stat_bar(entry, data)
entry.text = "#{data[:weapon]}:\tavg RT:#{data[:avgrt].round(1)}\tavg DPS:#{data[:avgdps].round(1)}"
end
filter = PerformanceFilter.new
window = nil
window_done = false
load_window_position = CharSettings['window_position'] || []
load_window_width = CharSettings['window_width'] || 300
load_window_height = CharSettings['window_height'] || 100
window_title = "#{checkname} Performance Monitor"
save_window_position = nil
save_window_width = nil
save_window_height = nil
before_dying do
CharSettings['window_position'] = save_window_position if (save_window_position.class == Array) && (save_window_position[0].to_i >= 0) && (save_window_position[1].to_i >= 0)
CharSettings['window_width'] = save_window_width if (save_window_width.class == Integer) && (save_window_width > 100)
CharSettings['window_height'] = save_window_height if (save_window_height.class == Integer) && (save_window_height > 100)
Gtk.queue { window.destroy }
end
begin
weapon_ets = {}
Gtk.queue do
vbox = Gtk::VBox.new
filter.weapon_list.each do |weapon|
stats_et = Gtk::Entry.new
stats_et.editable = false
display_font = Pango::FontDescription.new
display_font.weight = Pango::FontDescription::WEIGHT_BOLD
stats_et.modify_font(display_font)
weapon_ets[weapon] = stats_et
vbox.pack_start(stats_et)
end
window = Gtk::Window.new
window.title = window_title
window.keep_above = true
window.border_width = 1
window.resize(load_window_width, load_window_height)
unless load_window_position.empty?
window.move(load_window_position[0], load_window_position[1])
end
window.add(vbox)
window.signal_connect('delete_event') do
save_window_position = window.position
save_window_width = window.allocation.width
save_window_height = window.allocation.height
window_done = true
end
window.show_all
end
loop do
line = script.gets?
break if window_done
pause 0.05 unless line
next unless line
next unless filter.process_line(line)
filter.weapon_stats.each do |data|
update_stat_bar(weapon_ets[data[:weapon]], data)
end
end
end