Example #1
0
        void OnPartyReady(IEventInfo a_info)
        {
            PartyInfo partyInfo = a_info as PartyInfo;

            if (partyInfo != null && partyInfo.partySlot == partySlot)
            {
                //Debug.Log("ON PARTY READY FOR " + partyInfo.partySlot);

                // There can only be one party ready at a time, so unready all others
                for (int i = 0; i < BattleManager.Instance.PartyMembers.Length; ++i)
                {
                    ePartySlot currSlot = (ePartySlot)i;

                    if (partyInfo.partySlot != currSlot)
                    {
                        EventManager.TriggerEvent("PartyUnready", new PartyInfo {
                            partySlot = currSlot
                        });
                    }
                }

                // Update action panel data
                ReferenceManager.Instance.actionPanelName.text = battleProfile.EntityName;

                // Visually move into ready position
                gameObject.transform.localPosition = new Vector3(gameObject.transform.localPosition.x, readyOffset, gameObject.transform.localPosition.z);
            }
        }
        /**
         * @brief Find and set current slot to the first valid one found. If one cannot be found then the player's turn will end.
         * */
        IEnumerator GetNextValidSlot()
        {
            int prevSlot = (int)CurrPartySlot;
            int newSlot  = prevSlot + 1;

            while (newSlot < PartyMembers.Length)
            {
                // Suggested member at slot is unconscious, skip to next
                if (GetPartyEntityBySlot((ePartySlot)newSlot).CurrentStatus == eStatusEffect.UNCONSCIOUS)
                {
                    newSlot++;
                }
                // Found valid member
                else
                {
                    CurrPartySlot = (ePartySlot)newSlot;

                    // Ready new party member
                    EventManager.TriggerEvent("OnPartyReady", new PartyInfo {
                        partySlot = CurrPartySlot
                    });

                    // No need to search for anymore slots
                    yield break;
                }

                yield return(null);
            }

            // Next slot is outside bounds, assume player turn is over
            CurrPartySlot = ePartySlot.NONE;

            EventManager.TriggerEvent("EndPlayerTurn");
        }
        /**
         * @brief Find and return a party member that matches the given slot.
         * @param a_slot is the party slot to check.
         * @return Found party member or null if no slot matched.
         * */
        PartyEntity GetPartyEntityBySlot(ePartySlot a_slot)
        {
            foreach (var pe in PartyEntities)
            {
                if (pe.partySlot == a_slot)
                {
                    return(pe);
                }
            }

            return(null);
        }
        private void Start()
        {
            CurrPartySlot = ePartySlot.NONE;

            /// Priority enemy
            BattleProfile priorityEnemy = Enemies[0];  // Enemy in first slot influences visuals and audio of whole battle

            Debug.Assert(priorityEnemy, "BATTLEMANAGER::No enemies set!");

            // Set enemy background
            ReferenceManager.Instance.enemyBG.sprite = priorityEnemy.BattleBackground;

            // Add enemy audio to main system and secondary systems
            ReferenceManager.Instance.mainAudio.AudioFiles.AddRange(priorityEnemy.BattleSFX);
            ReferenceManager.Instance.secondaryAudio.AudioFiles.AddRange(priorityEnemy.BattleSFX);

            // Start battle music, playing intro first if there is one
            AudioClip introClip = ReferenceManager.Instance.mainAudio.HasClip("INTRO");

            if (introClip)
            {
                // Play intro and then play main loop after it
                ReferenceManager.Instance.mainAudio.SetLooping(false);
                ReferenceManager.Instance.mainAudio.PlayClip("{\"alias\":\"INTRO\",\"volume\":1}");

                ReferenceManager.Instance.secondaryAudio.SetLooping(true);
                ReferenceManager.Instance.secondaryAudio.PlayClipWithDelay("{\"alias\":\"LOOP\",\"volume\":1}", introClip.length, true);
            }
            else if (ReferenceManager.Instance.mainAudio.HasClip("LOOP"))
            {
                ReferenceManager.Instance.mainAudio.SetLooping(true);
                ReferenceManager.Instance.mainAudio.PlayClip("{\"alias\":\"LOOP\",\"volume\":1}");
            }

            /// Enemies
            for (int i = 0; i < Enemies.Length; ++i)
            {
                GameObject  eObj = Instantiate(EnemyBlueprint);
                EnemyEntity eEe  = eObj.GetComponent <EnemyEntity>();

                // Set to relevant slot
                eEe.enemySlot = (eEnemySlot)i;

                // Set type
                eEe.EntityType = eEntityType.ENEMY;

                // Assign battle profile
                eEe.BattleProfile = Enemies[i];

                // Keep track of enemy entity
                EnemyEntities.Add(eEe);

                eObj.transform.SetParent(ReferenceManager.Instance.enemyPanel.transform);
            }

            /// Party members
            for (int i = 0; i < PartyMembers.Length; ++i)
            {
                GameObject  pmObj = Instantiate(PartyBlueprint);
                PartyEntity pmPe  = pmObj.GetComponentInChildren <PartyEntity>();

                // Assign battle profile
                pmPe.BattleProfile = PartyMembers[i];

                // Set type
                pmPe.EntityType = eEntityType.PARTY;

                // Set to relevant slot
                pmPe.partySlot = (ePartySlot)i;

                // Keep track of party entity
                PartyEntities.Add(pmPe);

                pmObj.transform.SetParent(ReferenceManager.Instance.partyPanel.transform);
            }
        }