using GatherAndDefend;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Ally : Entity
{
    public override float DamageMultiplier => GlobalConfig.Instance.Current.allyDamageMultiplier;
    public override float AttackSpeedMultiplier => GlobalConfig.Instance.Current.allyAttackSpeedMultiplier;
    public override float HpMultiplier => GlobalConfig.Instance.Current.allyLifeMultiplier;
    public override Vector2 RangeMultiplier => GlobalConfig.Instance.Current.allyRangeMultiplier;
    public override float SpeedMultiplier => GlobalConfig.Instance.Current.allySpeedMultiplier;
    public float PopulationCost => GlobalConfig.Instance.Current.populationCostPerUnit;

    public AudioTemplate SoundPlayerWhenPlaced;

    public override void Start()
    {
        base.Start();

        if (SoundPlayerWhenPlaced != null)
        {
            PlaySound(SoundPlayerWhenPlaced);
        }
    }

    public override void Update()
    {
        base.Update();
        if (IsEnemyDetected)
        {
            AttackEnemy();
        }

    }

    void AttackEnemy()
    {
        //Attack Cooldown
        if (AttackSpeedWait > AttackInterval)
        {

            Animation.PlayAttackAnim();

            AttackSpeedWait = 0f;
        }

        AttackSpeedWait += Time.deltaTime;
    }

    public Vector3 GetPosition()
    {
        return transform.position;
    }

    public override void LevelStart()
    {
        base.LevelStart();
        if (this is not Building) ResourceManager.Instance.CurrentPopulation += PopulationCost;
    }
    public override void LevelDestroy()
    {
        base.LevelDestroy();
        if (this is not Building) ResourceManager.Instance.CurrentPopulation -= PopulationCost;
    }
}
