-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActionMon.html
More file actions
618 lines (519 loc) · 23.8 KB
/
Copy pathActionMon.html
File metadata and controls
618 lines (519 loc) · 23.8 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>ActionMon</title>
<script src="https://act.diemoe.net/overlays/common/common.min.js"></script>
<script src="action_data.js"></script>
<link rel="stylesheet" href="ActionMon.css">
</head>
<body>
<div id="top-bar">
<div id="party-controls"></div>
<button id="toggle-bar-btn" title="收起/展开控制条">
<img src="icon.png" alt="">
</button>
</div>
<div id="party-container"></div>
<script>
if (location.href.indexOf('OVERLAY_WS=') === -1 && !window.OverlayPluginApi) {
window.__isBrowser = true;
const c = document.getElementById('party-controls');
if (c) {
c.innerHTML = `
<div style="color: #d30000; font-weight: bold; text-align: left; padding: 10px;">
⚠️ 未检测到 OverlayPlugin<br>
<span style="font-size:12px; font-weight:normal; color:#fff">
请在 ACT 中添加此悬浮窗。
</span>
</div>`;
c.style.display = 'flex';
}
}
// --- 配置区 ---
// 根据 action ID 排除技能. 见action_data.js.
const IGNORE_SKILL_IDS = new Set([
"4", // 坐骑
"7", // 攻击
]);
// 滚动速度 (像素/秒)
const SCROLL_SPEED = 75;
// 技能图标大小 (像素)
const CELL_SIZE = 50;
// 右侧边距
const PADDING_RIGHT = 10;
// --- 配置区 ---
// const viewportWidthStr = window.getComputedStyle(document.documentElement).getPropertyValue('--viewport-width').trim();
// const VIEWPORT_WIDTH = parseInt(viewportWidthStr) || 500; // 默认值 500px
// 计算生成点
// const SPAWN_X = VIEWPORT_WIDTH - CELL_SIZE - PADDING_RIGHT;
let currentSpawnX = window.innerWidth - 120 - CELL_SIZE - PADDING_RIGHT;
function updateSpawnX() {
const allViewports = document.querySelectorAll('.cast-viewport');
let validWidth = 0;
for (const vp of allViewports) {
if (vp.clientWidth > 0) {
validWidth = vp.clientWidth;
break;
}
}
if (validWidth > 0) {
currentSpawnX = validWidth - CELL_SIZE - PADDING_RIGHT;
} else {
// 估算
const estimatedViewportWidth = window.innerWidth - 120;
if (estimatedViewportWidth > 0) {
currentSpawnX = estimatedViewportWidth - CELL_SIZE - PADDING_RIGHT;
}
}
// 防止算出负数
if (currentSpawnX < 100) currentSpawnX = 100;
}
window.addEventListener('resize', () => {
updateSpawnX();
const btn = document.getElementById('toggle-bar-btn');
if (btn && btn.style.display !== 'none') {
btn.style.width = btn.offsetHeight + 'px';
}
});
// 初始化一次
updateSpawnX();
// --- 多成员数据结构 ---
class PartyMember {
constructor(id, name, job = null) {
this.id = id;
this.name = name;
this.job = job;
this.ribbon = null;
this.activeSkills = [];
this.castingMap = new Map();
this.aoeDedupeMap = { currentActionId: null };
this.visible = false;
this.rowElement = null;
this.buttonElement = null;
this.createUI();
}
createUI() {
const container = document.getElementById('party-container');
// 创建控件行
const row = document.createElement('div');
row.className = 'party-member-row';
row.id = `row-${this.id}`;
row.style.display = 'none';
// 创建名称标签
const nameLabel = document.createElement('div');
nameLabel.className = 'player-name-label';
nameLabel.textContent = this.name;
// 创建视口
const viewport = document.createElement('div');
viewport.className = 'cast-viewport';
viewport.id = `viewport-${this.id}`;
// 创建技能窗
const ribbon = document.createElement('div');
ribbon.id = `ribbon-${this.id}`;
ribbon.style.position = 'absolute';
ribbon.style.top = '0';
ribbon.style.left = '0';
ribbon.style.width = '100%';
ribbon.style.height = '100%';
ribbon.style.pointerEvents = 'none';
viewport.appendChild(ribbon);
row.appendChild(nameLabel);
row.appendChild(viewport);
container.appendChild(row);
this.ribbon = ribbon;
this.rowElement = row;
}
createControlButton() {
const button = document.createElement('button');
button.className = 'member-toggle';
button.id = `toggle-${this.id}`;
button.textContent = this.name;
button.addEventListener('click', () => {
this.toggleVisibility();
});
this.buttonElement = button;
this.updateButtonStyle();
return button;
}
toggleVisibility() {
this.visible = !this.visible;
if (this.rowElement) {
this.rowElement.style.display = this.visible ? 'flex' : 'none';
}
this.updateButtonStyle();
}
updateButtonStyle() {
if (!this.buttonElement) return;
if (this.visible) {
this.buttonElement.classList.add('active');
this.buttonElement.classList.remove('inactive');
} else {
this.buttonElement.classList.remove('active');
this.buttonElement.classList.add('inactive');
}
}
updateName(newName) {
this.name = newName;
if (this.buttonElement) {
this.buttonElement.textContent = newName;
}
const nameLabel = document.querySelector(`#row-${this.id} .player-name-label`);
if (nameLabel) {
nameLabel.textContent = newName;
}
}
remove() {
if (this.rowElement && this.rowElement.parentNode) {
this.rowElement.parentNode.removeChild(this.rowElement);
}
if (this.buttonElement && this.buttonElement.parentNode) {
this.buttonElement.parentNode.removeChild(this.buttonElement);
}
}
}
// 小队成员管理
class PartyManager {
constructor() {
this.members = new Map();
this.currentPlayerId = null;
}
getMember(memberId) {
return this.members.get(memberId) || null;
}
createMember(memberId, memberName, job = null) {
if (!this.members.has(memberId)) {
const member = new PartyMember(memberId, memberName, job);
this.members.set(memberId, member);
}
return this.members.get(memberId);
}
removeMember(memberId) {
const member = this.members.get(memberId);
if (member) {
member.remove();
this.members.delete(memberId);
}
}
updatePartyControls() {
const controlsContainer = document.getElementById('party-controls');
controlsContainer.innerHTML = '';
for (const member of this.members.values()) {
const button = member.createControlButton();
controlsContainer.appendChild(button);
}
}
clearNonPartyMembers(partyIds) {
const partyIdSet = new Set(partyIds);
const membersToRemove = [];
for (const memberId of this.members.keys()) {
if (!partyIdSet.has(memberId)) {
membersToRemove.push(memberId);
}
}
membersToRemove.forEach(memberId => this.removeMember(memberId));
}
}
const partyManager = new PartyManager();
// --- 展开/收回按钮逻辑 ---
const toggleBarBtn = document.getElementById('toggle-bar-btn');
const controlsDiv = document.getElementById('party-controls');
let isFirstPartyLoad = true;
toggleBarBtn.addEventListener('click', () => {
controlsDiv.classList.toggle('collapsed');
toggleBarBtn.classList.toggle('collapsed');
// 动画结束后重新计算一下技能出生点
setTimeout(updateSpawnX, 400);
});
// 更新咏唱条样式
function updateCastBarState(skillObj, state) {
if (!skillObj || !skillObj.castBar) return;
switch (state) {
case 'casting':
// 正在咏唱
skillObj.castBar.style.background = 'linear-gradient(90deg, rgba(100, 200, 255, 0.4), rgba(100, 150, 255, 0.0))';
skillObj.castBar.style.borderColor = 'rgba(150, 220, 255, 0.7)';
skillObj.castBar.style.zIndex = '10';
skillObj.el.style.zIndex = '20';
break;
case 'interrupted':
// 咏唱中断
skillObj.castBar.style.background = 'linear-gradient(90deg, rgba(255, 100, 100, 0.4), rgba(255, 50, 50, 0.0))';
skillObj.castBar.style.borderColor = 'rgba(255, 100, 100, 1)';
skillObj.castBar.style.zIndex = '20';
skillObj.el.style.zIndex = '10';
break;
}
}
// --- 技能事件处理 ---
class SkillEventHandler {
constructor() {
this.ignoreSkillIds = IGNORE_SKILL_IDS;
}
handleLogLine(data) {
if (data.line[0] === '21') {
partyManager.currentPlayerId = data.line[2]; // 获取当前玩家ID
}
const lineType = data.line[0]; // 日志行类型:20(开始),21(完成),22(AOE),23(中断)
const sourceId = data.line[2]; // 技能释放者ID
const actionId = parseInt(data.line[4], 16).toString(); //技能ID
// 获取已存在的成员数据
const member = partyManager.getMember(sourceId);
if (!member) return; // 只处理小队成员的事件
// 如果actionId变化,清空去重对象并存储新的actionId
if (member.aoeDedupeMap.currentActionId !== actionId) {
member.aoeDedupeMap = { currentActionId: actionId };
}
if (typeof ACTION_DATA !== 'undefined' && (lineType === '20' || lineType === '21' || lineType === '22' || lineType === '23')) {
const skill = ACTION_DATA[actionId];
if (skill) {
if (this.ignoreSkillIds.has(actionId)) return;
switch (lineType) {
case '20':
this.handleCastStart(member, actionId, skill.n, skill.i, skill.c);
break;
case '21':
this.handleCastFinish(member, actionId, skill.n, skill.i, skill.c);
break;
case '22':
this.handleAoeCast(member, actionId, skill.n, skill.i, skill.c, data.line[44]);
break;
case '23':
this.handleCastInterrupt(member, actionId);
break;
}
}
}
}
handleCastStart(member, actionId, name, iconId, skillType) {
if (!member.visible) return;
const skillObj = createSkillItem(member, name, iconId, skillType, true);
skillObj.el.classList.add('casting');
updateCastBarState(skillObj, 'casting');
member.castingMap.set(actionId, skillObj);
}
handleCastFinish(member, actionId, name, iconId, skillType) {
// 处理瞬发与读条
if (!member.visible) return;
if (member.castingMap.has(actionId)) {
const skillObj = member.castingMap.get(actionId);
skillObj.isCasting = false;
skillObj.el.classList.remove('casting');
const iconEl = skillObj.el.querySelector('.skill-icon');
if (iconEl) {
iconEl.style.zIndex = '2';
}
member.castingMap.delete(actionId);
} else {
createSkillItem(member, name, iconId, skillType, false);
}
}
handleAoeCast(member, actionId, name, iconId, skillType, effectId) {
//多目标去重
if (!member.visible) return;
if (!member.aoeDedupeMap[effectId]) {
member.aoeDedupeMap[effectId] = true;
this.handleCastFinish(member, actionId, name, iconId, skillType);
}
}
handleCastInterrupt(member, actionId) {
if (!member.visible) return;
if (member.castingMap.has(actionId)) {
const skillObj = member.castingMap.get(actionId);
skillObj.isCasting = false;
updateCastBarState(skillObj, 'interrupted');
member.castingMap.delete(actionId);
}
}
}
const skillEventHandler = new SkillEventHandler();
// 监听日志行事件
addOverlayListener('LogLine', (data) => {
skillEventHandler.handleLogLine(data);
});
addOverlayListener('PartyChanged', (e) => {
if (e.party && e.party.length > 0) {
const controlsDiv = document.getElementById('party-controls');
const containerDiv = document.getElementById('party-container');
if (controlsDiv.style.display === 'none') controlsDiv.style.display = '';
if (containerDiv.style.display === 'none') containerDiv.style.display = '';
toggleBarBtn.style.display = 'flex';
if (isFirstPartyLoad) {
controlsDiv.classList.add('collapsed');
toggleBarBtn.classList.add('collapsed');
isFirstPartyLoad = false;
}
requestAnimationFrame(() => {
toggleBarBtn.style.width = toggleBarBtn.offsetHeight + 'px';
});
const partyIds = [];
e.party.forEach(member => {
const name = member.name;
const id = member.id;
const job = member.job;
partyIds.push(id);
// 更新或创建成员数据
const existingMember = partyManager.getMember(id);
if (existingMember) {
existingMember.updateName(name);
existingMember.job = job;
} else {
partyManager.createMember(id, name, job);
}
console.log(`Party Member: ID=${id}, Name=${name}, Job=${job}`);
});
partyManager.clearNonPartyMembers(partyIds);
partyManager.updatePartyControls();
setTimeout(() => {
updateSpawnX();
}, 50);
}
});
function createSkillItem(member, name, iconId, skillType, hasCastBar) {
const wrapper = document.createElement('div');
wrapper.style.position = 'absolute';
wrapper.style.left = '0px';
wrapper.style.top = '0px';
wrapper.style.height = '100%';
wrapper.style.width = '0px';
const item = document.createElement('div');
item.className = 'skill-item';
if (member.ribbon && member.ribbon.parentElement) {
const specificWidth = member.ribbon.parentElement.clientWidth;
if (specificWidth > 0) {
currentSpawnX = specificWidth - CELL_SIZE - PADDING_RIGHT;
}
}
if (skillType === 4) item.classList.add('ogcd');
const iconEl = document.createElement('div');
iconEl.className = 'skill-icon';
if (iconId) {
const folder = (Math.floor(iconId / 1000) * 1000).toString().padStart(6, '0');
const iconStr = iconId.toString().padStart(6, '0');
iconEl.style.backgroundImage = `url('https://cafemaker.wakingsands.com/i/${folder}/${iconStr}.png')`;
}
item.appendChild(iconEl);
const nameLabel = document.createElement('div');
nameLabel.className = 'skill-name';
nameLabel.innerText = name;
adjustFontSize(nameLabel, name);
item.appendChild(nameLabel);
let castBarEl = null;
if (hasCastBar) {
castBarEl = document.createElement('div');
castBarEl.className = 'cast-bar';
castBarEl.style.width = '0px';
wrapper.appendChild(castBarEl);
}
// 组装 DOM
wrapper.appendChild(item);
member.ribbon.appendChild(wrapper);
const skillObj = {
wrapper: wrapper,
el: item,
castBar: castBarEl,
spawnTime: Date.now(),
isCasting: hasCastBar,
name: name
};
member.activeSkills.push(skillObj);
return skillObj;
}
function adjustFontSize(nameEl, skillName) {
let fontSize = 10;
const nameLength = skillName.length;
if (nameLength >= 6) {
nameEl.style.transform = `scale(0.75)`;
} else if (nameLength >= 4) {
fontSize = 9;
nameEl.style.transform = 'scale(1)';
} else {
nameEl.style.transform = 'scale(1)';
}
nameEl.style.fontSize = `${fontSize}px`;
}
function animationLoop() {
const now = Date.now();
if (currentSpawnX < 50) updateSpawnX();
for (const member of partyManager.members.values()) {
if (!member.visible) continue;
const activeSkills = member.activeSkills;
for (let i = activeSkills.length - 1; i >= 0; i--) {
const skill = activeSkills[i];
const timeAlive = (now - skill.spawnTime) / 1000;
const currentLeft = currentSpawnX - (timeAlive * SCROLL_SPEED);
skill.wrapper.style.transform = `translateX(${currentLeft}px)`;
// 更新咏唱条宽度
if (skill.isCasting && skill.castBar) {
let barWidth = currentSpawnX - currentLeft;
if (barWidth < 0) barWidth = 0;
skill.castBar.style.width = `${barWidth}px`;
}
// 清理不可见元素
if (currentLeft < -400 && timeAlive > 2.5) {
if (skill.wrapper.parentNode) {
skill.wrapper.parentNode.removeChild(skill.wrapper);
}
for (const [key, value] of member.castingMap.entries()) {
if (value === skill) {
member.castingMap.delete(key);
}
}
activeSkills.splice(i, 1);
}
}
}
requestAnimationFrame(animationLoop);
}
// 控件条横向滚动事件处理
(function setupHorizontalScroll() {
const controls = document.getElementById('party-controls');
if (controls) {
controls.addEventListener('wheel', (evt) => {
if (controls.scrollWidth > controls.clientWidth) {
evt.preventDefault();
controls.scrollLeft += evt.deltaY;
}
});
}
})();
function initWelcomeMessage() {
if (window.__isBrowser) return;
const controls = document.getElementById('party-controls');
controls.innerHTML = '<div class="welcome-message">ActionMon 0.2.0 Ready - 等待数据中...</div>';
// setTimeout(() => {
// if (partyManager.members.size === 0) {
// controls.innerHTML = '';
// controls.style.display = 'none';
// document.getElementById('party-container').style.display = 'none';
// }
// }, 5000);
}
window.addEventListener('error', (event) => {
console.error('ActionMon Error:', event.error);
});
// dev
const isLocalServer = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
const isLocalFile = window.location.protocol === 'file:';
const hasDevParam = new URLSearchParams(window.location.search).has('dev');
if (isLocalServer || isLocalFile || hasDevParam) {
let frameCount = 0;
let lastTime = performance.now();
function monitorPerformance() {
frameCount++;
const currentTime = performance.now();
if (currentTime - lastTime >= 1000) {
console.log(`FPS: ${Math.round((frameCount * 1000) / (currentTime - lastTime))}, Members: ${partyManager.members.size}`);
frameCount = 0;
lastTime = currentTime;
}
requestAnimationFrame(monitorPerformance);
}
monitorPerformance();
}
animationLoop();
startOverlayEvents();
initWelcomeMessage();
</script>
</body>
</html>