123
This commit is contained in:
133
public/game.js
133
public/game.js
@ -411,32 +411,139 @@
|
||||
const attackerWrap = document.querySelector(`[data-minion-id="${lastLog.attackerMinionId}"]`);
|
||||
const targetWrap = document.querySelector(`[data-minion-id="${lastLog.targetMinionId}"]`);
|
||||
if (!attackerWrap || !targetWrap) return false;
|
||||
attackerWrap.classList.add('combat-lunge');
|
||||
|
||||
// Вычисляем позиции для точного перемещения карты
|
||||
const attackerRect = attackerWrap.getBoundingClientRect();
|
||||
const targetRect = targetWrap.getBoundingClientRect();
|
||||
|
||||
// Вычисляем смещение
|
||||
const dx = targetRect.left + targetRect.width / 2 - (attackerRect.left + attackerRect.width / 2);
|
||||
const dy = targetRect.top + targetRect.height / 2 - (attackerRect.top + attackerRect.height / 2);
|
||||
|
||||
// Сохраняем начальную позицию
|
||||
const startX = attackerRect.left;
|
||||
const startY = attackerRect.top;
|
||||
const startWidth = attackerRect.width;
|
||||
const startHeight = attackerRect.height;
|
||||
|
||||
// Устанавливаем fixed positioning для наложения
|
||||
attackerWrap.style.position = 'fixed';
|
||||
attackerWrap.style.left = startX + 'px';
|
||||
attackerWrap.style.top = startY + 'px';
|
||||
attackerWrap.style.width = startWidth + 'px';
|
||||
attackerWrap.style.height = startHeight + 'px';
|
||||
attackerWrap.style.zIndex = '1000';
|
||||
attackerWrap.style.transition = 'none';
|
||||
|
||||
// Добавляем класс для анимации
|
||||
attackerWrap.classList.add('combat-lunge-overlay');
|
||||
targetWrap.classList.add('combat-hit');
|
||||
|
||||
// Устанавливаем CSS переменные для перемещения
|
||||
attackerWrap.style.setProperty('--attack-dx', dx + 'px');
|
||||
attackerWrap.style.setProperty('--attack-dy', dy + 'px');
|
||||
|
||||
if (lastLog.damage) showDamageEffect(targetWrap, lastLog.damage, false);
|
||||
if (typeof window.Sounds !== 'undefined') window.Sounds.attack();
|
||||
if (lastLog.attackerDied) {
|
||||
attackerWrap.classList.add('combat-death');
|
||||
showDamageEffect(attackerWrap, '💀', false);
|
||||
}
|
||||
if (lastLog.targetDied) {
|
||||
targetWrap.classList.add('combat-death');
|
||||
showDamageEffect(targetWrap, '💀', false);
|
||||
}
|
||||
|
||||
// Анимация удара
|
||||
setTimeout(() => {
|
||||
targetWrap.classList.add('combat-hit-impact');
|
||||
}, 200);
|
||||
|
||||
// Возврат карты и очистка
|
||||
setTimeout(() => {
|
||||
// Если атакующий не умер, возвращаем карту на место
|
||||
if (!lastLog.attackerDied) {
|
||||
attackerWrap.classList.remove('combat-lunge-overlay');
|
||||
attackerWrap.style.position = '';
|
||||
attackerWrap.style.left = '';
|
||||
attackerWrap.style.top = '';
|
||||
attackerWrap.style.width = '';
|
||||
attackerWrap.style.height = '';
|
||||
attackerWrap.style.zIndex = '';
|
||||
attackerWrap.style.setProperty('--attack-dx', '');
|
||||
attackerWrap.style.setProperty('--attack-dy', '');
|
||||
attackerWrap.style.transition = '';
|
||||
} else {
|
||||
// Если атакующий умер, сразу применяем анимацию смерти
|
||||
attackerWrap.classList.remove('combat-lunge-overlay');
|
||||
attackerWrap.style.position = '';
|
||||
attackerWrap.style.left = '';
|
||||
attackerWrap.style.top = '';
|
||||
attackerWrap.style.width = '';
|
||||
attackerWrap.style.height = '';
|
||||
attackerWrap.style.zIndex = '';
|
||||
attackerWrap.style.setProperty('--attack-dx', '');
|
||||
attackerWrap.style.setProperty('--attack-dy', '');
|
||||
attackerWrap.style.transition = '';
|
||||
attackerWrap.classList.add('combat-death');
|
||||
showDamageEffect(attackerWrap, '💀', false);
|
||||
}
|
||||
|
||||
if (lastLog.targetDied) {
|
||||
targetWrap.classList.add('combat-death');
|
||||
showDamageEffect(targetWrap, '💀', false);
|
||||
}
|
||||
|
||||
targetWrap.classList.remove('combat-hit-impact');
|
||||
}, 500);
|
||||
|
||||
combatTimeout = setTimeout(function () {
|
||||
combatTimeout = null;
|
||||
renderBoards(state);
|
||||
bindGameEvents(state);
|
||||
}, 600);
|
||||
return true;
|
||||
} else if (lastLog.type === 'attackHero' && lastLog.toPlayer !== undefined) {
|
||||
} else if (lastLog.type === 'attackHero' && lastLog.toPlayer !== undefined && lastLog.attackerMinionId) {
|
||||
const attackerWrap = document.querySelector(`[data-minion-id="${lastLog.attackerMinionId}"]`);
|
||||
const targetPlayer = state.players[lastLog.toPlayer];
|
||||
if (targetPlayer) {
|
||||
if (attackerWrap && targetPlayer) {
|
||||
const heroEl = document.querySelector(`[data-player-index="${lastLog.toPlayer}"].hero-target, .opponent-block[data-opponent-index="${lastLog.toPlayer}"] .drop-target-hero`);
|
||||
if (heroEl) {
|
||||
heroEl.classList.add('hero-damage-flash');
|
||||
// Вычисляем позиции для атаки по герою
|
||||
const attackerRect = attackerWrap.getBoundingClientRect();
|
||||
const heroRect = heroEl.getBoundingClientRect();
|
||||
|
||||
const dx = heroRect.left + heroRect.width / 2 - (attackerRect.left + attackerRect.width / 2);
|
||||
const dy = heroRect.top + heroRect.height / 2 - (attackerRect.top + attackerRect.height / 2);
|
||||
|
||||
const startX = attackerRect.left;
|
||||
const startY = attackerRect.top;
|
||||
const startWidth = attackerRect.width;
|
||||
const startHeight = attackerRect.height;
|
||||
|
||||
// Устанавливаем fixed positioning
|
||||
attackerWrap.style.position = 'fixed';
|
||||
attackerWrap.style.left = startX + 'px';
|
||||
attackerWrap.style.top = startY + 'px';
|
||||
attackerWrap.style.width = startWidth + 'px';
|
||||
attackerWrap.style.height = startHeight + 'px';
|
||||
attackerWrap.style.zIndex = '1000';
|
||||
attackerWrap.style.transition = 'none';
|
||||
|
||||
attackerWrap.classList.add('combat-lunge-overlay');
|
||||
attackerWrap.style.setProperty('--attack-dx', dx + 'px');
|
||||
attackerWrap.style.setProperty('--attack-dy', dy + 'px');
|
||||
|
||||
heroEl.classList.add('hero-damage-flash', 'combat-hit-impact');
|
||||
if (lastLog.damage) showDamageEffect(heroEl, lastLog.damage, true);
|
||||
setTimeout(() => heroEl.classList.remove('hero-damage-flash'), 500);
|
||||
if (typeof window.Sounds !== 'undefined') window.Sounds.attack();
|
||||
|
||||
setTimeout(() => {
|
||||
attackerWrap.classList.remove('combat-lunge-overlay');
|
||||
attackerWrap.style.position = '';
|
||||
attackerWrap.style.left = '';
|
||||
attackerWrap.style.top = '';
|
||||
attackerWrap.style.width = '';
|
||||
attackerWrap.style.height = '';
|
||||
attackerWrap.style.zIndex = '';
|
||||
attackerWrap.style.setProperty('--attack-dx', '');
|
||||
attackerWrap.style.setProperty('--attack-dy', '');
|
||||
attackerWrap.style.transition = '';
|
||||
|
||||
heroEl.classList.remove('hero-damage-flash', 'combat-hit-impact');
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user