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();
}
public update(elapsedMS) {
console.log(this.debris instanceof GameObject);
if (this.debris instanceof GameObject) {
this.debris.update(elapsedMS);
}

View File

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

View File

@ -149,36 +149,47 @@ export function ElectricTowerBehaviour(tower: Tower, elapsedMS: number) {
proj.onCollide = (creep: Creep, proj: Projectile) => {
let chainedCreepIds = [];
proj.pierce = 0;
function checkNearBy(c) {
let nearByCreeps = Engine.Grid.creeps.filter((nCreep) => {
let recursionCount = 0;
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) {
const x = nCreep.x;
const y = nCreep.y;
const radius = 1.5 * Engine.GridCellSize;
const d = distance(c.x, c.y, x, y);
return d < radius;
}
});
nearByCreeps.forEach((nearCreep) => {
if (!chainedCreepIds.find((crID) => crID == nearCreep.id)) chainedCreepIds.push(nearCreep.id);
else return;
checkNearBy(nearCreep);
new VisualLightning(c, nearCreep);
if (d < radius) {
if (chainedCreepIds.find((crID) => crID == nCreep.id) != undefined) return;
chainedCreepIds.push(nCreep.id);
new VisualLightning(c, nCreep);
Engine.GameScene.events.emit(
CreepEvents.TakenDamage,
nearCreep.id,
nCreep.id,
Math.round(proj.damage / 2),
proj.gemResistanceModifications
);
checkNearBy(nCreep);
}
}
});
}
checkNearBy(creep);
Engine.GameScene.events.emit(
CreepEvents.TakenDamage,
creep.id,
proj.damage,
proj.gemResistanceModifications
);
chainedCreepIds.push(creep.id);
checkNearBy(creep);
};
}
}