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

namespace GGJ16
{
    public class PlayerData : MonoBehaviour, IPlayer
    {
        public int playerID;
        public int followersNumber;
        public int priestNumber;
        public List<int> preachers;
        public int advantage = 0;
        // public ArrayList actions;

        public PlayerData(int id)
        {
            followersNumber = 10;
            priestNumber = 0;
            preachers = new List<int>();
            playerID = id;
        }


        public int GetPlayerID()
        {
            return playerID;
        }

        // Use this for initialization
        void Start()
        {

        }

        // Update is called once per frame
        void Update()
        {

        }

        public int GetAdvantage()
        {
            return advantage;
        }

        public void levelUp()
        {
            advantage++;
        }

        public void KillFollowers(int killed)
        {
            followersNumber -= killed;
            GameObject.Find("TF_FollowerNumber").GetComponent<Text>().text = followersNumber.ToString();
        }

        public void KillPriests(int killed)
        {
            priestNumber -= killed;
            GameObject.Find("TF_PriestNumber").GetComponent<Text>().text = priestNumber.ToString();
        }

        public void KillPreachers(int killed)
        {
            preachers.RemoveRange(0, killed);
            GameObject.Find("TF_PreacherNumber").GetComponent<Text>().text = preachers.Count.ToString();
        }

        public int GetFollowers()
        {
            return followersNumber;
        }

        public void AddFollowers()
        {
            followersNumber += (advantage + 1);
            GameObject.Find("TF_FollowerNumber").GetComponent<Text>().text = followersNumber.ToString();
        }

        public void AddFollowers(int followers)
        {
            followersNumber += followers;
            GameObject.Find("TF_FollowerNumber").GetComponent<Text>().text = followersNumber.ToString();
        }

        public int GetPriests()
        {
            return priestNumber;
        }

        public int GetPreachers()
        {
            return preachers.Count;
        }

        public void AddPreacher(int rivalID)
        {
            preachers.Add(rivalID);
            GameObject.Find("TF_PreacherNumber").GetComponent<Text>().text = preachers.Count.ToString();
        }

        public void AddPriest()
        {
            priestNumber++;
            GameObject.Find("TF_PriestNumber").GetComponent<Text>().text = priestNumber.ToString();
        }

        public List<int> GetPreacherList()
        {
            return preachers;
        }

        public bool IsAlive()
        {
            bool res = ((followersNumber + preachers.Count + priestNumber) <= 0) ? true : false;
            if (res == false)
            {
                if (playerID == 1)
                {
                    GameObject.Find("XF").GetComponent<Text>().enabled = true;
                }
                else if (playerID == 2)
                {
                    GameObject.Find("XI").GetComponent<Text>().enabled = true;

                }
                else if (playerID == 3)
                {
                    GameObject.Find("XT").GetComponent<Text>().enabled = true;

                }
            }
            return res;
            
        }
    }
}