/
CodeByKate
/
lastserver-game
Обзор
Документация
Войти
/
CodeByKate
/
lastserver-game
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
bugs.js
86 строк
3 KB
CodeByKate
upload files
21 дек 2025, 21:44
21 дек 2025, 21:44
136e74f
Код
Авторство
О чём код?
/* bugs.js Max's ability: freeze decay of all platforms for a timed global window, with proper cooldown (40s) and clear start/end behavior. - When active, engine.decayPaused = true so platform ages are frozen. - Active lasts this.duration seconds (18s), cooldown decreases each update(dt). - On end, decayPaused is cleared and visual glitch cleared explicitly. - Uses a cleanup to ensure glitch does not persist. */ export default class MaxBug { constructor(engine, entities){ this.engine = engine; this.entities = entities; this.cooldown = 40.0; this.cooldownRemaining = 0; this.active = false; this.activeTime = 0; this.duration = 18.0; this._cleanupTimer = null; } reset(){ this.cooldownRemaining = 0; this.active = false; this.activeTime = 0; this.engine.decayPaused = false; // clear any lingering visual effects const root = this.engine.canvas.parentElement; root.style.transition = ''; root.style.filter = ''; if(this.engine.canvas.classList.contains('glitch')) this.engine.canvas.classList.remove('glitch'); if(this._cleanupTimer) { clearTimeout(this._cleanupTimer); this._cleanupTimer = null; } } tryUse(){ if(this.active || this.cooldownRemaining > 0 || this.engine.gameOver || this.engine.win){ if(this.cooldownRemaining > 0){ const uiMsg = document.getElementById('ability-msg'); if(uiMsg){ uiMsg.textContent = `Перезарядка: ${Math.ceil(this.cooldownRemaining)} сек`; uiMsg.style.display='block'; setTimeout(()=>uiMsg.style.display='none',1000); } this.engine._triggerFlash('red', 200); } return; } // activate this.active = true; this.activeTime = this.duration; this.cooldownRemaining = this.cooldown; // visual cue and freeze global decay progression this.engine._triggerFlash('green', 220); this.engine.decayPaused = true; // slight immediate stability cost for using hack this.engine.decayTimer = Math.max(0, this.engine.decayTimer - Math.round(this.engine.decayTimerMax * 0.03)); // apply glitch class to canvas for visual feedback if(!this.engine.canvas.classList.contains('glitch')) this.engine.canvas.classList.add('glitch'); // ensure a cleanup safety in case something goes wrong if(this._cleanupTimer) clearTimeout(this._cleanupTimer); this._cleanupTimer = setTimeout(()=>{ // safety: ensure deactivation after duration+2s if something failed if(this.active){ this.active = false; this.engine.decayPaused = false; } if(this.engine.canvas.classList.contains('glitch')) this.engine.canvas.classList.remove('glitch'); this._cleanupTimer = null; }, (this.duration + 2.0) * 1000); } update(dt){ if(this.cooldownRemaining > 0) this.cooldownRemaining = Math.max(0, this.cooldownRemaining - dt); if(this.active){ this.activeTime = Math.max(0, this.activeTime - dt); if(this.activeTime <= 0){ // deactivate reliably this.active = false; this.engine.decayPaused = false; this.engine._triggerFlash('green', 260); const root = this.engine.canvas.parentElement; root.style.transition = 'filter 0.18s linear'; root.style.filter = ''; if(this.engine.canvas.classList.contains('glitch')) this.engine.canvas.classList.remove('glitch'); if(this._cleanupTimer){ clearTimeout(this._cleanupTimer); this._cleanupTimer = null; } } } } }