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

public class Stealable : MonoBehaviour
{
    public int pointsWorth;
    public bool hasBeenStolen;
    public enum Type
    {
        Disappear,
        SpriteChange
    }
    public Type type;
    public Sprite stolenSprite;
	public GameObject moneyEffect;
	
	public Color alternateColor;
	public bool useAlternateColor;

    void Awake()
    {
		Color prizeColor = useAlternateColor ? alternateColor : new Color(0.47f, 0.9f, 0.47f, 1);
		transform.GetComponent<SpriteRenderer>().color = prizeColor;
    }

    public void Steal()
    {
        if (!hasBeenStolen)
        {
            GameObject.FindGameObjectWithTag(Tags.endPoint).GetComponent<ScoreSystem>().AddToScore(pointsWorth);

            hasBeenStolen = true;

            switch (type)
            {
                case Type.Disappear:
                    gameObject.SetActive(false);

                    break;
                case Type.SpriteChange:
                    transform.GetComponent<SpriteRenderer>().sprite = stolenSprite;
                    break;
                default:
                    break;
            }
			
			AudioSource source = gameObject.GetComponent<AudioSource>();
			if(source != null)
				source.Play();
			
			if(moneyEffect != null)
				Instantiate(moneyEffect, transform.position, Quaternion.identity);
        }
    }
}
