export class SimActionMoveProjectiles {
    execute(simMain) {
        const simLevel = simMain.currentLevel;
        const deadProjectiles = [];
        simLevel.simProjectiles.forEach((simProjectile, idx) => {
            if (simProjectile.dead)
                deadProjectiles.push(idx);
        });
        for (const idx of deadProjectiles) {
            simLevel.simProjectiles.splice(idx, 1);
        }
        simLevel.simProjectiles.forEach((simProjectile) => {
            const target = simLevel.simEnemies[simProjectile.targetEnemyIdx];
            if (!target || target.dead) {
                simProjectile.dead = true;
                return;
            }
            const pos1 = simProjectile.position;
            const pos2 = target.position;
            const dir = pos2.subtract(pos1);
            const len = dir.magnitude();
            let duration = simProjectile.speed / simMain.gdRoot.simulation.stepsPerSecond;
            if (len < duration) {
                duration = len;
                simProjectile.dead = true;
                target.suffer(simProjectile.gdEffect);
            }
            simProjectile.position = pos1.add(dir.normalized().multiplyScalar(duration));
        });
    }
}
//# sourceMappingURL=SimActionMoveProjectiles.js.map