import * as THREE from 'three';
import { Weapon } from './Weapon';
import { Player } from './Player';
import { Trap } from './Trap';
import { GasCloud } from './GasCloud';
import { playSound } from './SoundManager';
import { trapCooldown, trapMax, gasCooldown } from './Skills';

export class Trapper extends Weapon {
  skill1(groundPoint: THREE.Vector3, player: Player): void {
    const level = player.game.skillSystem.getLevel('trap');
    if (level <= 0) return;
    if (this.cooldown1 > 0) return;
    if (player.game.traps.length >= trapMax(level)) return;

    this.COOLDOWN1_TIME = trapCooldown(level);
    this.cooldown1 = this.COOLDOWN1_TIME;

    const trap = new Trap(groundPoint.clone(), level);
    player.game.scene.add(trap.body);
    player.game.traps.push(trap);
    playSound('spawn', 0.4);
  }

  skill2(groundPoint: THREE.Vector3, player: Player): void {
    const level = player.game.skillSystem.getLevel('gascloud');
    if (level <= 0) return;
    if (this.cooldown2 > 0) return;

    this.COOLDOWN2_TIME = gasCooldown(level);
    this.cooldown2 = this.COOLDOWN2_TIME;

    const cloud = new GasCloud(groundPoint.clone(), level);
    player.game.scene.add(cloud.body);
    player.game.gasClouds.push(cloud);
    playSound('spawn', 0.4);
  }
}
