forked from quisquous/cactbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xephero.js
172 lines (134 loc) · 4.43 KB
/
xephero.js
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
'use strict';
let rows = 10;
let rdpsMax = 0;
let tracker = new DpsPhaseTracker;
function hideOverlay() {
$('#overlay').addClass('hide');
}
function showOverlay() {
$('#overlay').removeClass('hide');
}
function update(dps) {
let encounter = dps.Encounter;
let rdps = parseFloat(encounter.encdps);
if (isNaN(rdps) || rdps == Infinity)
return;
showOverlay();
let combatants = dps.Combatant;
let template = $('#overlaysource li');
let overlay = $('#overlay');
let container = overlay.clone();
// Reserve one row for the phase titles.
let rows = Math.floor($(window).height() / template.height()) - 1;
// todo: animate changes while combat is active?
// for now, always just fully replace the content
container.html('');
// sanity check
if (!isNaN(rdps) && rdps != Infinity)
rdpsMax = Math.max(rdpsMax, rdps);
let header = template.clone();
if (encounter.encdps.length <= 7)
header.find('.dps').text(encounter.encdps);
else
header.find('.dps').text(encounter.ENCDPS);
header.find('.name').text(tracker.title || '');
header.find('.number').text(encounter.duration);
header.find('.bar').css('width', ((rdps / rdpsMax) * 100) + '%');
container.append(header);
let limit = Math.max(combatants.length, rows);
let names = Object.keys(combatants).slice(0, rows-1);
let maxdps = false;
let dpsOrder = {};
for (let i = 0; i < names.length; i++) {
let combatant = combatants[names[i]];
let row = template.clone();
if (!maxdps)
maxdps = parseFloat(combatant.encdps);
if (combatant.name == 'YOU')
row.addClass('you');
dpsOrder[combatant.name] = i;
row.find('.dps').text(combatant.encdps);
row.find('.name').text(combatant.Job.toUpperCase() + ' ' + combatant.name);
row.find('.number').text(combatant.damage);
row.find('.misses').text(combatant.misses > 0 ? '(' + combatant.misses + ')' : '');
row.find('.bar').css('width', ((parseFloat(combatant.encdps) / maxdps) * 100) + '%');
container.append(row);
}
overlay.replaceWith(container);
if (tracker.phases.length >= 1) {
// Don't show the first phase if it starts immediately with the encounter.
if (tracker.phases[0].start && tracker.phases[0].start.Encounter.DURATION > 1 ||
tracker.phases.length >= 2) {
for (let i = 0; i < tracker.phases.length; ++i)
updatePhase(tracker.phases[i], dpsOrder);
}
}
}
function updatePhase(phase, dpsOrder) {
if (!phase.diff)
return;
if (!phase.element) {
let container = $('#phasesource ol').clone();
phase.element = container;
$('#topcontainer').append(container);
// Map of combatants => elements
phase.rowMap = {};
}
let phasename = phase.element.find('.phasename');
phasename.text(phase.name);
let phasetotal = phase.element.find('.phasetotal');
phasetotal.text(phase.diff.Encounter.ENCDPS);
let maxPhaseDPS = null;
for (let name in dpsOrder) {
let combatant = phase.diff.Combatant[name];
if (!combatant) {
phase.diff.Combatant[name] = combatant = {
ENCDPS: '',
};
}
let row = phase.rowMap[name];
if (!row) {
row = $('#phasenumbersource li').clone();
if (name == 'YOU')
row.addClass('you');
phase.element.append(row);
phase.rowMap[name] = row;
}
row.find('.number').text(combatant.ENCDPS);
let order = dpsOrder[name];
row.removeClass('hide');
row.removeClass('highestdps');
row.css('order', dpsOrder[name]);
if (!maxPhaseDPS || combatant.ENCDPS > maxPhaseDPS.dps) {
maxPhaseDPS = {
dps: combatant.ENCDPS,
row: row,
};
}
}
// Rows that used to be in dpsOrder but now aren't should be
// hidden.
for (let name in phase.rowMap) {
let order = dpsOrder[name];
if (order === undefined)
phase.rowMap[name].addClass('hide');
}
if (maxPhaseDPS)
maxPhaseDPS.row.addClass('highestdps');
}
function onOverlayDataUpdateEvent(e) {
tracker.onOverlayDataUpdate(e.detail);
update(e.detail);
}
addOverlayListener('onZoneChangedEvent', function(e) {
let currentZone = e.detail.zoneName;
tracker.onZoneChange(currentZone);
});
addOverlayListener('onLogEvent', function(e) {
tracker.onLogEvent(e.detail.logs);
});
addOverlayListener('onInCombatChangedEvent', function(e) {
// Only clear phases when ACT starts a new encounter for consistency.
tracker.inCombatChanged(e.detail.inACTCombat);
});
InitDpsModule('xephero', onOverlayDataUpdateEvent, hideOverlay);