Exemple #1
0
    /// <summary>
    /// Starts the turn of the next character. Initializes UI elements, etc.
    /// </summary>
    public void StartNextTurn()
    {
        //Get reference to the script whose turn is next
        CharMgrScript currentChar = this.GetCombatantTurn(this.PlayerParty, this.EnemyParty);

        //Set it to local variable
        currentTurnChar = currentChar;
        //Set flag for which team is taking its turn - In a PVE encounter, either payer party or NPC party
        if (this.PlayerParty.Contains(currentChar))
        {
            /*Debug statement for test*/
            if (TestScript._instance.TestMode)
            {
                Debug.Log("--StartNextTurn() called and character from *Player Party* found: " + currentChar.stats.CharName);
            }

            this._waitForPlayer = true;
            //Display the action selection menu if it's not already open and highlight current character
            if (CombatUIManager._instance.MenuLevel == GameConstants.CombatMenuPage.Unopened)
            {
                //Create the action menu
                CombatUIManager._instance.CreateActionMenu(CombatUIManager._instance.ActionMenuPos);
                //Update menu state
                CombatUIManager._instance.MenuLevel = GameConstants.CombatMenuPage.Action;
            }
        }
        else if (this.EnemyParty.Contains(currentChar))
        {
            /*Debug statement for test*/
            if (TestScript._instance.TestMode)
            {
                Debug.Log("--StartNextTurn() called and character from ~~Enemy Party~~ found: " + currentChar.stats.CharName);
            }

            this._waitForNPC = true;
            //Setup npc turn and pass in targets
            SetupNPCTurn(currentChar, this.PlayerParty);
        }

        //Handle  w/e character specific highlighting is involved
        currentChar.UITurnEmphasisStatus(true);
    }
Exemple #2
0
    public void StartCombat(Scene pOneWin, Scene pTwoWin)
    {
        Vector3 partyPos, enemyPos;

        this.PartyOneReturnScene = pOneWin;
        this.PartyTwoReturnScene = pTwoWin;

        /*Check referenc to tagged starting pos objects*/
        if (CombatPartyStartPos == null)
        {
            partyPos = new Vector3(GameConstants.CombatPartyStartPosX, GameConstants.CombatPartyStartPosY, 0);
        }
        else
        {
            partyPos = CombatPartyStartPos.position;
        }
        if (CombatEnemyStartPos == null)
        {
            enemyPos = new Vector3(GameConstants.CombatPartyStartPosX, GameConstants.CombatPartyStartPosY, 0);
        }
        else
        {
            enemyPos = CombatEnemyStartPos.position;
        }

        Debug.Log("StartCombat() called!");

        //Counter to use for positioning
        int count = 0;

        //Instantiate an object for each member of the player's party and set their variables accordingly
        foreach (CharStatsData characterStats in PlayerStateManager.Instance.PlayerParty)
        {
            Debug.Log("Party Member" + characterStats.CharName + "Instantiated called!");
            //Debug.Log("Creating character" + character.stats.CharName + "for combat scene.");
            //Create empty object from prefab
            GameObject partyMemberCopy = GameObject.Instantiate(EmptyCharacter);
            //Set position for the party member
            partyMemberCopy.transform.position = partyPos + (DistCharsCombat * (float)count);

            //Grab the new script
            CharMgrScript partyMemberCopyScript = partyMemberCopy.GetComponent <CharMgrScript>();
            //Init necessary variables
            partyMemberCopyScript.Init();
            /* --- Set the variables of the script --- */
            //Dialogue
            partyMemberCopyScript.dialogMgr = characterStats.DialogMgr;
            //Stats & Abilities
            characterStats.StatsAsScript(ref partyMemberCopyScript.stats);
            //Character sprite
            partyMemberCopy.GetComponent <SpriteRenderer>().sprite = characterStats.charSprite;
            //change object name in hierarchy
            partyMemberCopy.name = characterStats.CharName;

            /*Create UI objects (highlight arrow, hp counter) and parent them to the canvas, assign them to the characters script and disable via script*/

            //Create or recreate menu objects and refresh references

            //Instantiate the UI object used for emphasis when indicating it's a character's turn
            GameObject uiTurnEmphasisObj = GameObject.Instantiate(this.UITurnEmphasisObj);
            //Parent the turn emphasis object to the canvas
            uiTurnEmphasisObj.transform.SetParent(CombatUIManager._instance.CanvasObject.transform, false);
            //Assign the prefab as a member of the current charMgr script
            partyMemberCopyScript.UITurnEmphasisElem = uiTurnEmphasisObj;
            //Move the emphasis object under the character
            partyMemberCopyScript.UITurnEmphasisElem.GetComponent <UIAnim>().PositionElementOnSprite(partyMemberCopyScript.gameObject);
            //Disable the UI element for now
            partyMemberCopyScript.UITurnEmphasisStatus(false);

            //Instantiate the HP counter UI text prefab
            GameObject hpUIText = GameObject.Instantiate(HPUITxtObj);
            //Parent the ui text to the canvas for positioning purposes
            hpUIText.transform.SetParent(CombatUIManager._instance.CanvasObject.transform, false);
            //Assign the prefab as a member of the charMgr script
            partyMemberCopyScript.HPUITxt = hpUIText;
            //Move the hp text under the character
            partyMemberCopyScript.HPUITxt.GetComponent <UIAnim>().PositionElementOnSprite(partyMemberCopyScript.gameObject);
            //Set HP text's initial values
            partyMemberCopyScript.HPUITxt.GetComponent <UIAnim>().SetText(partyMemberCopyScript.stats.HP.ToString() + "/" + partyMemberCopyScript.stats.MaxHP.ToString());
            //Enable HP Text for now
            partyMemberCopyScript.HPTextStatus(true);

            //Instantiate the arrow prefab
            GameObject highlightArrow = GameObject.Instantiate(HighlightArrowObj);
            //Parent the highlight arrow to the canvas
            highlightArrow.transform.SetParent(CombatUIManager._instance.CanvasObject.transform, false);
            //Assign the sprite component as a member of the charMgr script
            partyMemberCopyScript.HighlightArrow = highlightArrow;
            //Move highlight arrow over character's head via setting it = to pos, + half the sprite's height
            partyMemberCopyScript.HighlightArrow.GetComponent <UIAnim>().PositionElementOnSprite(partyMemberCopyScript.gameObject);
            //Disable highlight arrow for now
            partyMemberCopyScript.HighlightArrowStatus(false);

            /********** Animator asset loading **********/

            //Attempt to load character's animator and attach it
            partyMemberCopy.GetComponent <Animator>().runtimeAnimatorController = this.LoadCharacterAnimator(partyMemberCopyScript);
            /*Add the character script to the total list of combatants for determining turn order*/
            Combatants.Add(partyMemberCopyScript);
            PlayerParty.Add(partyMemberCopyScript);

            //Set team direction
            partyMemberCopyScript.TeamDirection = GameConstants.COMBAT_DIR_LEFT_SIDE;

            //Increment counter for spacing
            count++;
        }

        //Clear counter
        count = 0;

        //Instantiate each enemy party member
        foreach (CharStatsData characterStats in this.EnemyPartyData)
        {
            Debug.Log("Enemy Member" + characterStats.CharName + "Instantiated called!");
            //Create empty enemy object from prefab
            GameObject enemyCharCopy = GameObject.Instantiate(EmptyCharacter);
            //Set position for the enemy
            enemyCharCopy.transform.position = CombatEnemyStartPos.position + (DistCharsCombat * (float)count);
            //Get reference to prefab's script
            CharMgrScript enemyScript = enemyCharCopy.GetComponent <CharMgrScript>();
            //init necessary variables
            enemyScript.Init();
            /* --- Set script variables --*/
            //Dialogue
            enemyScript.dialogMgr = characterStats.DialogMgr;
            //Stats & Abilities
            characterStats.StatsAsScript(ref enemyScript.stats);
            //Character sprite
            enemyScript.GetComponent <SpriteRenderer>().sprite = characterStats.charSprite;
            //change object name in hierarchy
            enemyCharCopy.name = enemyScript.stats.CharName;
            /*Create UI objects, parent them to the canvas, assign them to the the characters scripts and disable via script*/

            //Instantiate the UI object used for emphasis when indicating it's a character's turn
            GameObject uiTurnEmphasisObj = GameObject.Instantiate(this.UITurnEmphasisObj);
            //Parent the turn emphasis object to the canvas
            uiTurnEmphasisObj.transform.SetParent(CombatUIManager._instance.CanvasObject.transform, false);
            //Assign the prefab as a member of the current charMgr script
            enemyScript.UITurnEmphasisElem = uiTurnEmphasisObj;
            //Move the emphasis object under the character
            enemyScript.UITurnEmphasisElem.GetComponent <UIAnim>().PositionElementOnSprite(enemyScript.gameObject);
            //Disable the UI element for now
            enemyScript.UITurnEmphasisStatus(false);

            //Instantiate the HP counter UI text prefab
            GameObject hpUIText = GameObject.Instantiate(HPUITxtObj);
            //Parent the ui text to the canvas for positioning purposes
            hpUIText.transform.SetParent(CombatUIManager._instance.CanvasObject.transform, false);
            //Assign the prefab as a member of the charMgr script
            enemyScript.HPUITxt = hpUIText;
            //Move the hp text under the character
            enemyScript.HPUITxt.GetComponent <UIAnim>().PositionElementOnSprite(enemyScript.gameObject);
            //Set HP text's initial values
            enemyScript.HPUITxt.GetComponent <UIAnim>().SetText(enemyScript.stats.HP.ToString() + "/" + enemyScript.stats.MaxHP.ToString());
            //Ensure HP Text is enabled for now
            enemyScript.HPTextStatus(true);

            //Instantiate the highlight arrow prefab
            GameObject highlightArrow = GameObject.Instantiate(HighlightArrowObj);
            //Parent the highlight arrow to the canvas
            highlightArrow.transform.SetParent(CombatUIManager._instance.CanvasObject.transform, false);
            //Assign the sprite component as a member of the charMgr script
            enemyScript.HighlightArrow = highlightArrow;
            //Move highlight arrow over character's head via setting it = to pos, + half the sprite's height
            enemyScript.HighlightArrow.GetComponent <UIAnim>().PositionElementOnSprite(enemyScript.gameObject);
            //Disable highlight arrow for now
            enemyScript.HighlightArrowStatus(false);

            /********** Animator asset loading **********/

            //Attempt to load character's animator and attach it
            enemyCharCopy.GetComponent <Animator>().runtimeAnimatorController = this.LoadCharacterAnimator(enemyScript);
            /*Add the character script to the total list of combatants for determining turn order*/
            Combatants.Add(enemyScript);
            EnemyParty.Add(enemyScript);

            //Set team direction
            enemyScript.TeamDirection = GameConstants.COMBAT_DIR_RIGHT_SIDE;

            //Increment counter for spacing
            count++;
        }

        /********Set flag to track game state that manager is done initializing and waiting for player input********/
        this._initializing = false;
        //this._waitForPlayer = true;
        /****************/
    }