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

public class RealTimeRewardChanger : MonoBehaviour
{
    public GameObject Agent;

    public InputField nonRInputField;
    public InputField shootRInputField;
    public InputField shootWithoutReadyRInputField;
    public InputField hitRInputField;
    public InputField killRInputField;
    public InputField winRInputField;
    public InputField loseRInputField;

    public Text nonRPlaceholder;
    public Text shootRPlaceholder;
    public Text shootWithoutReadyRPlaceholder;
    public Text hitRPlaceholder;
    public Text killRPlaceholder;
    public Text winRPlaceholder;
    public Text loseRPlaceholder;

    private void Start()
    {
        
    }


    public void nonRBTPresses()
    {
        InGameMessages messenger = gameObject.GetComponent<InGameMessages>();
        if (nonRInputField.GetComponent<InputField>().text == "-")
        {
            // input chara not illegal
            nonRPlaceholder.color = Color.red;
            nonRPlaceholder.text = "Wrong Type!";
            nonRInputField.GetComponent<InputField>().text = "";
            messenger.SendMessagetoBox("Wrong Reward Type!", Message.MessageType.error);

        }else if (nonRInputField.GetComponent<InputField>().text == "")
        {
            // empty chara
            nonRPlaceholder.color = Color.gray;
            nonRPlaceholder.text = "nonR";
        }
        else
        {
            // good to go~
            nonRPlaceholder.color = Color.gray;
            nonRPlaceholder.text = "nonR";
            string reward = nonRInputField.GetComponent<InputField>().text;
            Agent.GetComponent<AgentWithGun>().nonReward = float.Parse(reward);
            nonRInputField.GetComponent<InputField>().text = "";
            messenger.SendMessagetoBox("Reward nonR change Success",Message.MessageType.success);
        }
    }

    public void shootRBTPresses()
    {
        InGameMessages messenger = gameObject.GetComponent<InGameMessages>();
        if (shootRInputField.GetComponent<InputField>().text == "-")
        {
            // input chara not illegal
            shootRPlaceholder.color = Color.red;
            shootRPlaceholder.text = "Wrong Type!";
            shootRInputField.GetComponent<InputField>().text = "";
            messenger.SendMessagetoBox("Wrong Reward Type!", Message.MessageType.error);
        }
        else if (shootRInputField.GetComponent<InputField>().text == "")
        {
            // empty chara
            shootRPlaceholder.color = Color.gray;
            shootRPlaceholder.text = "shootR";
        }
        else
        {
            // good to go~
            shootRPlaceholder.color = Color.gray;
            shootRPlaceholder.text = "shootR";
            string reward = shootRInputField.GetComponent<InputField>().text;
            Agent.GetComponent<AgentWithGun>().shootReward = float.Parse(reward);
            shootRInputField.GetComponent<InputField>().text = "";
            messenger.SendMessagetoBox("Reward shootR change Success",Message.MessageType.success);
        }
    }

    public void shootWithoutReadyRBTPresses()
    {
        InGameMessages messenger = gameObject.GetComponent<InGameMessages>();
        if (shootWithoutReadyRInputField.GetComponent<InputField>().text == "-")
        {
            // input chara not illegal
            shootWithoutReadyRPlaceholder.color = Color.red;
            shootWithoutReadyRPlaceholder.text = "Wrong Type!";
            shootWithoutReadyRInputField.GetComponent<InputField>().text = "";
            messenger.SendMessagetoBox("Wrong Reward Type!", Message.MessageType.error);
        }
        else if (shootWithoutReadyRInputField.GetComponent<InputField>().text == "")
        {
            // empty chara
            shootWithoutReadyRPlaceholder.color = Color.gray;
            shootWithoutReadyRPlaceholder.text = "SWORR";
        }
        else
        {
            // good to go~
            shootWithoutReadyRPlaceholder.color = Color.gray;
            shootWithoutReadyRPlaceholder.text = "SWORR";
            string reward = shootWithoutReadyRInputField.GetComponent<InputField>().text;
            Agent.GetComponent<AgentWithGun>().shootWithoutReadyReward = float.Parse(reward);
            shootWithoutReadyRInputField.GetComponent<InputField>().text = "";
            messenger.SendMessagetoBox("Reward SWORR change Success",Message.MessageType.success);
        }
    }

    public void hitRBTPresses()
    {
        InGameMessages messenger = gameObject.GetComponent<InGameMessages>();
        if (hitRInputField.GetComponent<InputField>().text == "-")
        {
            // input chara not illegal
            hitRPlaceholder.color = Color.red;
            hitRPlaceholder.text = "Wrong Type!";
            hitRInputField.GetComponent<InputField>().text = "";
            messenger.SendMessagetoBox("Wrong Reward Type!", Message.MessageType.error);
        }
        else if (hitRInputField.GetComponent<InputField>().text == "")
        {
            // empty chara
            hitRPlaceholder.color = Color.gray;
            hitRPlaceholder.text = "hitR";
        }
        else
        {
            // good to go~
            hitRPlaceholder.color = Color.gray;
            hitRPlaceholder.text = "hitR";
            string reward = hitRInputField.GetComponent<InputField>().text;
            Agent.GetComponent<AgentWithGun>().hitReward = float.Parse(reward);
            hitRInputField.GetComponent<InputField>().text = "";
            messenger.SendMessagetoBox("Reward hitR change Success",Message.MessageType.success);
        }
    }

    public void killRBTPresses()
    {
        InGameMessages messenger = gameObject.GetComponent<InGameMessages>();
        if (killRInputField.GetComponent<InputField>().text == "-")
        {
            // input chara not illegal
            killRPlaceholder.color = Color.red;
            killRPlaceholder.text = "Wrong Type!";
            killRInputField.GetComponent<InputField>().text = "";
            messenger.SendMessagetoBox("Wrong Reward Type!", Message.MessageType.error);
        }
        else if (killRInputField.GetComponent<InputField>().text == "")
        {
            // empty chara
            killRPlaceholder.color = Color.gray;
            killRPlaceholder.text = "killR";
        }
        else
        {
            // good to go~
            killRPlaceholder.color = Color.gray;
            killRPlaceholder.text = "killR";
            string reward = killRInputField.GetComponent<InputField>().text;
            Agent.GetComponent<AgentWithGun>().killReward = float.Parse(reward);
            killRInputField.GetComponent<InputField>().text = "";
            messenger.SendMessagetoBox("Reward killR change Success",Message.MessageType.success);
        }
    }

    public void winRBTPresses()
    {
        InGameMessages messenger = gameObject.GetComponent<InGameMessages>();
        if (winRInputField.GetComponent<InputField>().text == "-")
        {
            // input chara not illegal
            winRPlaceholder.color = Color.red;
            winRPlaceholder.text = "Wrong Type!";
            winRInputField.GetComponent<InputField>().text = "";
            messenger.SendMessagetoBox("Wrong Reward Type!", Message.MessageType.error);
        }
        else if (winRInputField.GetComponent<InputField>().text == "")
        {
            // empty chara
            winRPlaceholder.color = Color.gray;
            winRPlaceholder.text = "winR";
        }
        else
        {
            // good to go~
            winRPlaceholder.color = Color.gray;
            winRPlaceholder.text = "winR";
            string reward = winRInputField.GetComponent<InputField>().text;
            Agent.GetComponent<AgentWithGun>().winReward = float.Parse(reward);
            winRInputField.GetComponent<InputField>().text = "";
            messenger.SendMessagetoBox("Reward winR change Success", Message.MessageType.success);
        }
    }

    public void loseRBTPresses()
    {
        InGameMessages messenger = gameObject.GetComponent<InGameMessages>();
        if (loseRInputField.GetComponent<InputField>().text == "-")
        {
            // input chara not illegal
            loseRPlaceholder.color = Color.red;
            loseRPlaceholder.text = "Wrong Type!";
            loseRInputField.GetComponent<InputField>().text = "";
            messenger.SendMessagetoBox("Wrong Reward Type!", Message.MessageType.error);
        }
        else if (loseRInputField.GetComponent<InputField>().text == "")
        {
            // empty chara
            loseRPlaceholder.color = Color.gray;
            loseRPlaceholder.text = "loseR";
        }
        else
        {
            // good to go~
            loseRPlaceholder.color = Color.gray;
            loseRPlaceholder.text = "loseR";
            string reward = loseRInputField.GetComponent<InputField>().text;
            Agent.GetComponent<AgentWithGun>().loseReward = float.Parse(reward);
            loseRInputField.GetComponent<InputField>().text = "";
            messenger.SendMessagetoBox("Reward loseR change Success",Message.MessageType.success);
        }
    }
}