fixed infinite recursion on electric tower
This commit is contained in:
parent
a33912d59d
commit
1c3c9b287f
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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) => {
|
||||||
visual.width -= 4;
|
if (visual.width && visual.height && visual.alpha) {
|
||||||
visual.height -= 4;
|
visual.width -= 4;
|
||||||
visual.alpha -= 0.05;
|
visual.height -= 4;
|
||||||
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);
|
Engine.GameScene.stage.addChild(newVisual);
|
||||||
} else this.counter++;
|
} else this.counter++;
|
||||||
|
@ -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);
|
||||||
|
new VisualLightning(c, nCreep);
|
||||||
|
Engine.GameScene.events.emit(
|
||||||
|
CreepEvents.TakenDamage,
|
||||||
|
nCreep.id,
|
||||||
|
Math.round(proj.damage / 2),
|
||||||
|
proj.gemResistanceModifications
|
||||||
|
);
|
||||||
|
checkNearBy(nCreep);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
nearByCreeps.forEach((nearCreep) => {
|
|
||||||
if (!chainedCreepIds.find((crID) => crID == nearCreep.id)) chainedCreepIds.push(nearCreep.id);
|
|
||||||
else return;
|
|
||||||
checkNearBy(nearCreep);
|
|
||||||
new VisualLightning(c, nearCreep);
|
|
||||||
Engine.GameScene.events.emit(
|
|
||||||
CreepEvents.TakenDamage,
|
|
||||||
nearCreep.id,
|
|
||||||
Math.round(proj.damage / 2),
|
|
||||||
proj.gemResistanceModifications
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
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);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user