'use strict';

/* ────────────────────────────────────────────────────────────────
   Phase 6 Sprint 6.1 — Action Templates
   
   Platformer, Run & Gun, Beat 'em up, Hack & Slash, Twin-stick
──────────────────────────────────────────────────────────────── */
const DEFAULT_PLATFORMER_CONFIG = {
    moveSpeed: 6,
    jumpForce: 14,
    gravity: 40,
    maxJumps: 2,
    coyoteTime: 0.1,
    jumpBufferTime: 0.12,
    wallSlideSpeed: 2,
    wallJumpForce: { x: 10, y: 14 },
    dashSpeed: 18,
    dashDuration: 0.15,
    groundCheckDistance: 0.1,
    maxFallSpeed: 20,
};
function createPlatformerState() {
    return {
        grounded: false, jumpsRemaining: 0, coyoteTimer: 0,
        jumpBufferTimer: 0, wallSliding: false, dashing: false,
        dashTimer: 0, facingRight: true, velocity: { x: 0, y: 0 },
    };
}
function updatePlatformer(state, input, config, dt) {
    // Coyote time
    if (state.grounded) {
        state.coyoteTimer = config.coyoteTime;
        state.jumpsRemaining = config.maxJumps;
    }
    else {
        state.coyoteTimer = Math.max(0, state.coyoteTimer - dt);
    }
    // Jump buffer
    if (input.jump)
        state.jumpBufferTimer = config.jumpBufferTime;
    else
        state.jumpBufferTimer = Math.max(0, state.jumpBufferTimer - dt);
    // Dash
    if (input.dash && !state.dashing && state.dashTimer <= 0) {
        state.dashing = true;
        state.dashTimer = config.dashDuration;
    }
    if (state.dashing) {
        state.dashTimer -= dt;
        if (state.dashTimer <= 0)
            state.dashing = false;
    }
    // Horizontal
    if (state.dashing) {
        state.velocity.x = (state.facingRight ? 1 : -1) * config.dashSpeed;
    }
    else {
        state.velocity.x = input.moveX * config.moveSpeed;
    }
    if (input.moveX !== 0)
        state.facingRight = input.moveX > 0;
    // Jump
    if (state.jumpBufferTimer > 0 && (state.coyoteTimer > 0 || state.jumpsRemaining > 0)) {
        state.velocity.y = config.jumpForce;
        state.jumpsRemaining--;
        state.jumpBufferTimer = 0;
        state.coyoteTimer = 0;
        state.grounded = false;
    }
    // Gravity / wall slide
    if (!state.grounded && !state.dashing) {
        if (state.wallSliding) {
            state.velocity.y = Math.max(-config.wallSlideSpeed, state.velocity.y - config.gravity * dt * 0.4);
        }
        else {
            state.velocity.y -= config.gravity * dt;
            state.velocity.y = Math.max(-config.maxFallSpeed, state.velocity.y);
        }
    }
    return { x: state.velocity.x * dt, y: state.velocity.y * dt };
}
const DEFAULT_RUN_AND_GUN_CONFIG = {
    moveSpeed: 5,
    jumpForce: 12,
    gravity: 30,
    fireRate: 8,
    bulletSpeed: 20,
    bulletDamage: 10,
    spreadAngle: 0.05,
    maxAmmo: 30,
    reloadTime: 1.5,
    aimDirections: 8,
    scrollSpeed: 0,
};
const PRESET_WEAPONS = {
    pistol: { type: 'pistol', name: 'Pistol', damage: 10, fireRate: 4, bulletSpeed: 20, spread: 0.02, bulletsPerShot: 1, ammoMax: 12, reloadTime: 1, piercing: false, explosive: false, explosionRadius: 0 },
    shotgun: { type: 'shotgun', name: 'Shotgun', damage: 6, fireRate: 1.5, bulletSpeed: 18, spread: 0.2, bulletsPerShot: 6, ammoMax: 6, reloadTime: 2, piercing: false, explosive: false, explosionRadius: 0 },
    machinegun: { type: 'machinegun', name: 'Machine Gun', damage: 5, fireRate: 12, bulletSpeed: 22, spread: 0.08, bulletsPerShot: 1, ammoMax: 50, reloadTime: 2.5, piercing: false, explosive: false, explosionRadius: 0 },
    rocket: { type: 'rocket', name: 'Rocket Launcher', damage: 50, fireRate: 0.8, bulletSpeed: 12, spread: 0, bulletsPerShot: 1, ammoMax: 4, reloadTime: 3, piercing: false, explosive: true, explosionRadius: 3 },
    laser: { type: 'laser', name: 'Laser', damage: 15, fireRate: 6, bulletSpeed: 50, spread: 0, bulletsPerShot: 1, ammoMax: 20, reloadTime: 2, piercing: true, explosive: false, explosionRadius: 0 },
    flamethrower: { type: 'flamethrower', name: 'Flamethrower', damage: 3, fireRate: 20, bulletSpeed: 8, spread: 0.15, bulletsPerShot: 1, ammoMax: 100, reloadTime: 3, piercing: false, explosive: false, explosionRadius: 0 },
};
const DEFAULT_BEAT_EM_UP_CONFIG = {
    moveSpeed: 4,
    combo: [
        { name: 'Triple Punch', sequence: ['attack', 'attack', 'attack'], damage: [5, 8, 15], timing: 0.4 },
        { name: 'Uppercut', sequence: ['attack', 'attack', 'special'], damage: [5, 8, 25], timing: 0.35 },
    ],
    grabRange: 1.2,
    throwDamage: 20,
    knockbackForce: 8,
    healthMax: 100,
    lives: 3,
    iFrameDuration: 0.5,
    specialMeterMax: 100,
    specialCostPerUse: 40,
    laneCount: 3,
    laneHeight: 16,
};
function createBeatEmUpState(config) {
    return {
        comboIndex: 0, comboTimer: 0, specialMeter: 0,
        iFrameTimer: 0, health: config.healthMax, lives: config.lives,
        currentLane: 1,
    };
}
const DEFAULT_HACK_AND_SLASH_CONFIG = {
    moveSpeed: 6,
    attackSpeed: 2,
    attackRange: 2,
    attackArc: Math.PI * 0.6,
    damage: 15,
    critChance: 0.1,
    critMultiplier: 2,
    dodgeSpeed: 15,
    dodgeDuration: 0.2,
    dodgeCooldown: 0.8,
    healthMax: 200,
    manaMax: 100,
    manaRegen: 5,
    xpPerLevel: 100,
    xpScaling: 1.5,
    skillSlots: 4,
};
const DEFAULT_TWIN_STICK_CONFIG = {
    moveSpeed: 6,
    fireRate: 6,
    bulletSpeed: 15,
    bulletDamage: 10,
    bulletLifetime: 2,
    healthMax: 100,
    shieldMax: 50,
    shieldRegenRate: 10,
    shieldRegenDelay: 3,
    maxBullets: 50,
    spreadAngle: 0,
    bulletCount: 1,
    homingStrength: 0,
};
function createTwinStickState(config) {
    return {
        health: config.healthMax, shield: config.shieldMax,
        shieldRegenTimer: 0, fireTimer: 0, score: 0,
        killStreak: 0, multiplier: 1,
    };
}
class ProjectilePool {
    constructor() {
        this.pool = [];
        this.active = [];
        this.nextId = 1;
    }
    spawn(x, y, vx, vy, damage, lifetime, ownerId, piercing = false) {
        let p = this.pool.pop();
        if (!p) {
            p = { id: 0, x: 0, y: 0, vx: 0, vy: 0, damage: 0, lifetime: 0, ownerId: 0, piercing: false, hitEntities: new Set() };
        }
        p.id = this.nextId++;
        p.x = x;
        p.y = y;
        p.vx = vx;
        p.vy = vy;
        p.damage = damage;
        p.lifetime = lifetime;
        p.ownerId = ownerId;
        p.piercing = piercing;
        p.hitEntities.clear();
        this.active.push(p);
        return p;
    }
    update(dt) {
        for (let i = this.active.length - 1; i >= 0; i--) {
            const p = this.active[i];
            p.x += p.vx * dt;
            p.y += p.vy * dt;
            p.lifetime -= dt;
            if (p.lifetime <= 0) {
                this.pool.push(p);
                this.active.splice(i, 1);
            }
        }
    }
    getActive() { return this.active; }
    remove(id) {
        const idx = this.active.findIndex(p => p.id === id);
        if (idx >= 0) {
            this.pool.push(this.active[idx]);
            this.active.splice(idx, 1);
        }
    }
    clear() {
        for (const p of this.active)
            this.pool.push(p);
        this.active.length = 0;
    }
}

exports.DEFAULT_BEAT_EM_UP_CONFIG = DEFAULT_BEAT_EM_UP_CONFIG;
exports.DEFAULT_HACK_AND_SLASH_CONFIG = DEFAULT_HACK_AND_SLASH_CONFIG;
exports.DEFAULT_PLATFORMER_CONFIG = DEFAULT_PLATFORMER_CONFIG;
exports.DEFAULT_RUN_AND_GUN_CONFIG = DEFAULT_RUN_AND_GUN_CONFIG;
exports.DEFAULT_TWIN_STICK_CONFIG = DEFAULT_TWIN_STICK_CONFIG;
exports.PRESET_WEAPONS = PRESET_WEAPONS;
exports.ProjectilePool = ProjectilePool;
exports.createBeatEmUpState = createBeatEmUpState;
exports.createPlatformerState = createPlatformerState;
exports.createTwinStickState = createTwinStickState;
exports.updatePlatformer = updatePlatformer;
//# sourceMappingURL=ActionTemplates.js.map
