﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using UnityEngine;

public class Prepare_CharacterTrigger : MonoBehaviour {

    public DataRow character;
    public PrepareController prepareController;

    void Start()
    {
        prepareController = GameObject.Find("PrepareController").GetComponent<PrepareController>();
    }


    void OnMouseOver()
    {
        float hp = Convert.ToSingle(character["HPC"]) / Convert.ToSingle(character["HP.S"]);
        float mp = Convert.ToSingle(character["MPC"]) / Convert.ToSingle(character["MP.S"]);
        float awaitTime = 0f;

        transform.Find("StateUnit").GetComponent<StateUnit>().SetInfo(hp, mp, awaitTime);

        //设置角色透明度
        GameObject[] allGameObject = GameObject.FindGameObjectsWithTag("character");
        foreach (GameObject childGameObject in allGameObject)
        {
            SpriteRenderer[] allChildren = childGameObject.GetComponentsInChildren<SpriteRenderer>();
            if (childGameObject != gameObject)
            {
                foreach (SpriteRenderer children in allChildren)
                {
                    children.color = new Color(children.color.r, children.color.g, children.color.b, 0.2f);
                }
            }
            else
            {
                foreach (SpriteRenderer children in allChildren)
                {
                    children.color = new Color(children.color.r, children.color.g, children.color.b, 1f);
                }
            }
        }
        
        transform.Find("StateUnit").GetComponent<StateUnit>().isShow = true;
    }
    void OnMouseExit()
    {
        GameObject[] allGameObject = GameObject.FindGameObjectsWithTag("character");
        foreach (GameObject childGameObject in allGameObject)
        {
            SpriteRenderer[] allChildren = childGameObject.GetComponentsInChildren<SpriteRenderer>();
            foreach (SpriteRenderer child in allChildren)
            {
                child.color = new Color(child.color.r, child.color.g, child.color.r, 1f); ;
            }
        }
        this.transform.Find("StateUnit").GetComponent<StateUnit>().isShow = false;
    }

    void OnMouseDown()
    {
        if (!prepareController.isBoardShow)
        {
            prepareController.selectID = Convert.ToInt32(character["BattleID"]);

            GameObject[] selectTags = GameObject.FindGameObjectsWithTag("Select");
            foreach (GameObject selectTag in selectTags)
            {
                selectTag.SetActive(false);
            }
            this.transform.Find("Select").gameObject.SetActive(true);

            GameObject.Find("UI/MainBoard").GetComponent<Prepare_Board>().StateBoard();
        }

    }
}
