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

[System.Serializable]
public class CardData
{
	public string name;
	public float[] modifiers = new float[11];
	public float baseValue=0;
	public int setMoodPositive=-1;
	public int setMoodNegative=-1;
}

public class Card : MonoBehaviour {

	public Text t;
	private Date date;

	private CardData data;

	void Start()
	{
		date = GameObject.FindGameObjectWithTag ("date").GetComponent<Date>();
	}

	void useOn()
	{
		float diff = data.baseValue;
		for (int i = 0; i < date.personalities.Length; ++i) {
			diff += data.modifiers [i] * date.personalities [i];
		}
		for (int i = 0; i < date.moods.Length; ++i) {
			if (i == date.curMood) {
				diff += data.modifiers [i+date.personalities.Length];
			}
		}
		if (diff > 0 && data.setMoodPositive != -1) {
			date.setMood (data.setMoodPositive);
		}
		else if (diff < 0 && data.setMoodNegative != -1) {
			date.setMood (data.setMoodNegative);
		}
		date.changeLove (diff);
	}

    public void selectCard(CardData data)
	{
		this.data = data;
		t.text = data.name;
    }

    void OnMouseDown()
	{
		Hand h = GameObject.Find("HandController").GetComponent<Hand>();
		if (h.mode == 1) {
			useOn ();
			Destroy (this.gameObject);
			h.mode = 2;
			h.play.SetActive (false);
			h.discard.SetActive (true);
		} else if (h.mode > 1) {
			Destroy (this.gameObject);
			if (h.mode == 2) {
				h.mode = 3;
			} else {
				h.mode = 1;
				h.play.SetActive (true);
				h.discard.SetActive (false);
			}
		}

    }
}
