forked from quisquous/cactbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xephero.js
179 lines (144 loc) · 4.9 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
173
174
175
176
177
178
179
import { addOverlayListener } from '../../../resources/overlay_plugin_api';
import UserConfig from '../../../resources/user_config';
import { defaultOptions, InitDpsModule } from '../dps_common';
import DpsPhaseTracker from './dps_phase_tracker';
import '../../../resources/defaults.css';
import './xephero.css';
const rows = 10;
let rdpsMax = 0;
function hideOverlay() {
$('#overlay').addClass('hide');
}
function showOverlay() {
$('#overlay').removeClass('hide');
}
function update(dps, tracker) {
const encounter = dps.Encounter;
const rdps = parseFloat(encounter.encdps);
if (isNaN(rdps) || rdps === Infinity)
return;
showOverlay();
const combatants = dps.Combatant;
const template = $('#overlaysource li');
const overlay = $('#overlay');
const container = overlay.clone();
// Reserve one row for the phase titles.
const 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);
const 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);
const limit = Math.max(combatants.length, rows);
const names = Object.keys(combatants).slice(0, rows - 1);
let maxdps = false;
const dpsOrder = {};
for (let i = 0; i < names.length; i++) {
const combatant = combatants[names[i]];
const 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) {
const container = $('#phasesource ol').clone();
phase.element = container;
$('#topcontainer').append(container);
// Map of combatants => elements
phase.rowMap = {};
}
const phasename = phase.element.find('.phasename');
phasename.text(phase.name);
const phasetotal = phase.element.find('.phasetotal');
phasetotal.text(phase.diff.Encounter.ENCDPS);
let maxPhaseDPS = null;
for (const 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);
const 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 (const name in phase.rowMap) {
const order = dpsOrder[name];
if (order === undefined)
phase.rowMap[name].addClass('hide');
}
if (maxPhaseDPS)
maxPhaseDPS.row.addClass('highestdps');
}
UserConfig.getUserConfigLocation('xephero', defaultOptions, () => {
const options = { ...defaultOptions };
const tracker = new DpsPhaseTracker(options);
const onOverlayDataUpdateEvent = (e) => {
tracker.onOverlayDataUpdate(e.detail);
update(e.detail, tracker);
};
InitDpsModule(options, onOverlayDataUpdateEvent, hideOverlay);
addOverlayListener('ChangeZone', (e) => {
const currentZone = e.zoneName;
tracker.onChangeZone(currentZone);
});
addOverlayListener('LogLine', (e) => {
tracker.onNetLog(e);
});
addOverlayListener('onInCombatChangedEvent', (e) => {
// Only clear phases when ACT starts a new encounter for consistency.
tracker.inCombatChanged(e.detail.inACTCombat);
});
});