fixed infinite recursion on electric tower

This commit is contained in:
koneko 2025-02-18 22:51:59 +01:00
parent a33912d59d
commit 1c3c9b287f
3 changed files with 33 additions and 21 deletions

View File

@ -12,7 +12,6 @@ class Debris {
this.debris.destroy(); this.debris.destroy();
} }
public update(elapsedMS) { public update(elapsedMS) {
console.log(this.debris instanceof GameObject);
if (this.debris instanceof GameObject) { if (this.debris instanceof GameObject) {
this.debris.update(elapsedMS); this.debris.update(elapsedMS);
} }

View File

@ -143,10 +143,12 @@ export class RailProjectile extends Projectile {
newVisual.anchor.set(0.5, 0.5); newVisual.anchor.set(0.5, 0.5);
this.visuals.push(newVisual); this.visuals.push(newVisual);
this.visuals.forEach((visual) => { this.visuals.forEach((visual) => {
if (visual.width && visual.height && visual.alpha) {
visual.width -= 4; visual.width -= 4;
visual.height -= 4; visual.height -= 4;
visual.alpha -= 0.05; visual.alpha -= 0.1;
if (visual.width <= 0 && visual.height <= 0) visual.destroy(); if (visual.width <= 0 || visual.height <= 0 || visual.alpha <= 0) visual.destroy();
}
}); });
Engine.GameScene.stage.addChild(newVisual); Engine.GameScene.stage.addChild(newVisual);
} else this.counter++; } else this.counter++;

View File

@ -149,36 +149,47 @@ export function ElectricTowerBehaviour(tower: Tower, elapsedMS: number) {
proj.onCollide = (creep: Creep, proj: Projectile) => { proj.onCollide = (creep: Creep, proj: Projectile) => {
let chainedCreepIds = []; let chainedCreepIds = [];
proj.pierce = 0; proj.pierce = 0;
function checkNearBy(c) { let recursionCount = 0;
let nearByCreeps = Engine.Grid.creeps.filter((nCreep) => { function checkNearBy(c: Creep) {
if (recursionCount >= 50) {
Engine.GameScene.PauseGame();
Engine.NotificationManager.Notify(
'Electric Tower max recursion exceeded! Please tell koneko! (game paused)',
'danger'
);
return;
}
recursionCount++;
Engine.Grid.creeps.forEach((nCreep) => {
if (nCreep.id != creep.id) { if (nCreep.id != creep.id) {
const x = nCreep.x; const x = nCreep.x;
const y = nCreep.y; const y = nCreep.y;
const radius = 1.5 * Engine.GridCellSize; const radius = 1.5 * Engine.GridCellSize;
const d = distance(c.x, c.y, x, y); const d = distance(c.x, c.y, x, y);
return d < radius; if (d < radius) {
} if (chainedCreepIds.find((crID) => crID == nCreep.id) != undefined) return;
}); chainedCreepIds.push(nCreep.id);
nearByCreeps.forEach((nearCreep) => { new VisualLightning(c, nCreep);
if (!chainedCreepIds.find((crID) => crID == nearCreep.id)) chainedCreepIds.push(nearCreep.id);
else return;
checkNearBy(nearCreep);
new VisualLightning(c, nearCreep);
Engine.GameScene.events.emit( Engine.GameScene.events.emit(
CreepEvents.TakenDamage, CreepEvents.TakenDamage,
nearCreep.id, nCreep.id,
Math.round(proj.damage / 2), Math.round(proj.damage / 2),
proj.gemResistanceModifications proj.gemResistanceModifications
); );
checkNearBy(nCreep);
}
}
}); });
} }
checkNearBy(creep);
Engine.GameScene.events.emit( Engine.GameScene.events.emit(
CreepEvents.TakenDamage, CreepEvents.TakenDamage,
creep.id, creep.id,
proj.damage, proj.damage,
proj.gemResistanceModifications proj.gemResistanceModifications
); );
chainedCreepIds.push(creep.id);
checkNearBy(creep);
}; };
} }
} }