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

public enum PowerUpType
{
    None,
    ForceMagnet,
    TurboBoost,
    EmergencyDrop
}

public class PlayerObjectShared : ObjectShared
{
    public float coreMagnetRange;
    public float coreMagnetForce;
    private AudioSource _currentAudioSource;

    public AudioClip badPowerUp;

    [SerializeField]
    private AttachablePowerUpEffect _currentPowerUpEffect;

    public AttachablePowerUpEffect currentAbility
    {
        get
        {
            return _currentPowerUpEffect;
        }
    }

    private void Start()
    {
        _currentAudioSource = gameObject.GetComponent<AudioSource>();
    }

    public bool AttachPickUp(AttachablePowerUpEffect newEffect)
    {
        _currentPowerUpEffect = newEffect;
        _currentPowerUpEffect.ApplyEffect();
        return true;
    }

    public void PlaySFX(AudioClip clipToPlay)
    {
        _currentAudioSource.PlayOneShot(clipToPlay);
    }

    private void Update()
    {
        if (Input.GetButtonDown("Fire2"))
        {
            if (_currentPowerUpEffect != null)
            {
                if (!_currentPowerUpEffect.OnUseEffect())
                {
                    if (_currentAudioSource != null)
                    {
                        Debug.Log("Used by failed");
                        _currentAudioSource.PlayOneShot(badPowerUp);
                    }
                }
            }
            else
            {
                if (_currentAudioSource != null)
                {
                    Debug.Log("None Exist failed");
                    _currentAudioSource.PlayOneShot(badPowerUp);
                }                
            }
        }
        if (Input.GetButtonDown("Fire3"))
        {
            if (_currentPowerUpEffect != null)
            {
                if (!_currentPowerUpEffect.OnAltUseEffect())
                {
                    if (_currentAudioSource != null)
                    {
                        Debug.Log("Used by failed");
                        _currentAudioSource.PlayOneShot(badPowerUp);
                    }
                }
            }
            else
            {
                if (_currentAudioSource != null)
                {
                    Debug.Log("None Exist failed");
                    _currentAudioSource.PlayOneShot(badPowerUp);
                }
            }
        }
    }
}
