示例#1
0
 public void Awake()
 {
     //Get all of the scripts
     InteractionScript  = GetComponent <InteractionCommands>();
     CommandScript      = GetComponent <Commands>();
     CombatCommands     = GetComponent <CombatCommands>();
     MovementCommands   = GetComponent <MovementCommands>();
     DissectingScript   = GetComponent <DissectInputScript>();
     DialogueScript     = GameObject.FindGameObjectWithTag("UI").GetComponent <Dialogue>();
     PlayerScript       = GetComponent <Player>();
     InterfaceScript    = GameObject.FindGameObjectWithTag("UI").GetComponent <InterfaceScript>();
     ItemNameListScript = GameObject.FindGameObjectWithTag("ScriptHolder").GetComponent <ItemNameList>();
     GameTurnController = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameTurnController>();
     if (!GameObject.FindGameObjectWithTag("CommandListHolder"))
     {
         Instantiate(gameObject, Vector3.zero, Quaternion.identity);
         gameObject.tag  = "CommandListHolder";
         gameObject.name = "CommandListHolder";
         gameObject.AddComponent <CommandList>();
         CommandListScript = gameObject.GetComponent <CommandList>();
     }
     else
     {
         CommandListScript = GameObject.FindGameObjectWithTag("CommandListHolder").GetComponent <CommandList>();
     }
     LevelScript = GameObject.FindGameObjectWithTag("ScriptHolder").GetComponent <LevelScript>();
 }
示例#2
0
 public void FindPlayerScript()
 {
     Player            = GameObject.FindGameObjectWithTag("Player");
     _commandScript    = Player.GetComponent <Commands>();
     _dissectingScript = Player.GetComponent <DissectInputScript>();
 }
示例#3
0
    public void PlayerInput()
    {
        //Make sure that the Interface script have the dissecting script
        if (!_dissectingScript)
        {
            _dissectingScript = GameObject.FindGameObjectWithTag("Player").GetComponent <DissectInputScript>();
        }
        //Get the string from the input field, also save it into a different string variable to use with the up-arrow option in Commands.cs Update()
        PlayerInputString = CommandInputField.text;
        LastCommands      = PlayerInputString;
        //If the state is currently enemycombat, just return without doing anything
        if (_gameTurnController.CurrentState == GameTurnController.PlayerState.EnemyCombatTurn)
        {
            return;
        }
        //If the Player is currently looting, run a special function and return
        if (IsGettingLoot)
        {
            GetLoot(PlayerInputString);
            return;
        }
        //Check if the Player is using multiple inputs (using a comma in the input)
        if (IsItMultipleCommands(PlayerInputString))
        {
            return;
        }
        //Make sure the state is PlayerTurn
        if (_gameTurnController.CurrentState == GameTurnController.PlayerState.PlayerTurn)
        {
            //Check if the Player has used Start or Cancel
            switch (PlayerInputString.ToUpper().Trim())
            {
            case "START":
                //Check if the Player has actually saved some commands, if not activate input and return
                if (_dialogueScript.CommandHistoryList.Count == 0)
                {
                    _dialogueScript.ErrorText("You can't do nothing.");
                    ActivateInput();
                    return;
                }
                //Else deactivate input, change to commandchain state and start processing through the saved commands
                DeActivateInput();
                _gameTurnController.CurrentState = GameTurnController.PlayerState.CommandChain;
                _commandScript.StartChain();
                return;

            //If Cancel was used, remove the last command, reactivate the input and return
            case "CANCEL":
                _dialogueScript.RemoveLastCommand();
                ActivateInput();
                return;
            }
            //Otherwise, run the input through the dissect script to check if it's a valid command and be saved
            // then remove the text from the input field, ready to either be deactivated to activated
            _dissectingScript.DissectPlayerInput(PlayerInputString, 1);
            CommandInputField.text = "";
        }
        //If the state is Combat
        else if (_gameTurnController.CurrentState == GameTurnController.PlayerState.Combat)
        {
            //If they use Start, inform them that it's not to be use din combat, activate input and return
            if (PlayerInputString.ToUpper() == "START")
            {
                _dialogueScript.ErrorText("You can't use \"Start\" in combat.");
                ActivateInput();
                return;
            }
            //Otherwise run the dissect script with 2 so it will go to the execute function
            _dissectingScript.DissectPlayerInput(PlayerInputString, 2);
        }
    }