using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Allegiance;

public class ShooterWeapon : BasicWeapon
{
    [SerializeField] private AudioSource shoot;
    public const string SHOOT = "Shoot";
    [SerializeField] private BulletBehaviour bulletPrefab;
    [SerializeField] private Transform bulletOutletPoint;

    private Animator shooterAnim;
    private ShooterAI enemyPsyche;

    protected override void Awake()
    {
        base.Awake();
        shooterAnim = GetComponent<Animator>();
        enemyPsyche = GetComponent<ShooterAI>();
    }

    protected override void Update() {
        base.Update();
        if(this.owner == Ownership.ENEMY) {
            enemyPsyche.enabled = true;
            this.health.owner = Ownership.ENEMY;
        }
        else if(this.owner == Ownership.PLAYER) {
            // enemyPsyche.enabled = false;
            PlayerManager.I.unit = GetComponent<ShooterUnitController>();
            this.health.owner = Ownership.PLAYER;
        }
    }
    public void Shoot()
    {
        if (!this.shooterAnim.GetCurrentAnimatorStateInfo(0).IsName(SHOOT))
        {
            shoot.Play();
            this.shooterAnim.SetTrigger(SHOOT);
            BulletBehaviour bullet = Instantiate(bulletPrefab, bulletOutletPoint.position, bulletOutletPoint.transform.rotation);
            bullet.owner = this.owner;
        }
    }
}
