using UnityEngine;
using System.Collections;

public abstract class ItemScript : MonoBehaviour {

    public enum w_type { CUP };
    protected int owner;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    public abstract bool use(int direction);

    public virtual bool isReady()
    {
        return true;
    }

    public virtual void drop(int direction)
    {
        GetComponent<Rigidbody2D>().isKinematic = false;
        GetComponent<Rigidbody2D>().AddForce(new Vector2(-1 * 30 * direction, 70));
        Invoke("looseFocus", 1);
    }

    void looseFocus()
    {
        this.owner = 0;
    }

    public void dropDead()
    {
        GetComponent<Rigidbody2D>().isKinematic = false;
        this.owner = 0;
    }


    public virtual void setOwner(int id) {
        this.owner = id;
        GetComponent<Rigidbody2D>().isKinematic = true;
    }

    public virtual int getOwner()
    {
        return this.owner;
    }

    void OnCollisionEnter2D(Collision2D coll)
    {
        if (coll.gameObject.tag == "floor")
        {
            this.owner = 0;
        }
        if (coll.gameObject.tag == "player")
        {
            // Debug.Log("trigger!");
        }
        if (this.owner != 0 && coll.gameObject.tag == "player" && coll.gameObject.GetComponent<PlayerScript>().id != this.owner)
        {
            // GameObject.Destroy(coll.gameObject);
        }
    }

}
