Ejemplo n.º 1
0
    private void SwitchToBattleStateProcess()
    {
        // Pause keepers
        foreach (PawnInstance pi in allKeepersList)
        {
            bool mustBeDisabled = false;
            for (int i = 0; i < currentFighters.Length && i < 3; i++)
            {
                if (pi == currentFighters[i])
                {
                    mustBeDisabled = true;
                }
            }

            if (mustBeDisabled)
            {
                pi.GetComponent <NavMeshAgent>().enabled = false;
            }
            else
            {
                NavMeshAgent currentAgent = pi.GetComponent <NavMeshAgent>();
                if (currentAgent != null && currentAgent.isActiveAndEnabled)
                {
                    currentAgent.Stop();
                    pausedAgents.Add(currentAgent);
                    pi.transform.GetChild(0).gameObject.SetActive(false);
                    disabledModels.Add(pi.transform.GetChild(0).gameObject);
                    if (pi.GetComponent <GlowObjectCmd>() != null)
                    {
                        GlowController.UnregisterObject(pi.GetComponent <GlowObjectCmd>());
                        unregisteredGlows.Add(pi.GetComponent <GlowObjectCmd>());
                    }
                }
            }

            pi.GetComponent <Keeper>().ShowSelectedPanelUI(false);
            ui.ClearActionPanel();
            ui.HideInventoryPanels();
        }

        // Pause NPCs
        // If needed, we should register all PNJ on tiles in TileManager so we can handle AI behaviours when the game paused
        // For now we'll only deal with the prisoner
        if (currentFighters[currentFighters.Length - 1].GetComponent <Prisoner>() != null)
        {
            NavMeshAgent prisonerAgent = currentFighters[currentFighters.Length - 1].GetComponent <NavMeshAgent>();
            if (prisonerAgent != null && prisonerAgent.isActiveAndEnabled)
            {
                prisonerAgent.enabled = false;
            }
        }
        else
        {
            if (prisonerInstance != null)
            {
                NavMeshAgent prisonerAgent = prisonerInstance.GetComponent <NavMeshAgent>();
                if (prisonerAgent != null && prisonerAgent.isActiveAndEnabled)
                {
                    prisonerAgent.Stop();
                    pausedAgents.Add(prisonerAgent);
                }
            }
        }

        // Pause monsters
        foreach (Tile tile in tileManagerReference.MonstersOnTile.Keys)
        {
            if (tile != cameraManagerReference.ActiveTile)
            {
                List <PawnInstance> monsterList = tileManagerReference.MonstersOnTile[tile];
                foreach (PawnInstance pi in monsterList)
                {
                    NavMeshAgent currentAgent = pi.GetComponent <NavMeshAgent>();
                    if (currentAgent != null && currentAgent.isActiveAndEnabled)
                    {
                        currentAgent.Stop();
                        pausedAgents.Add(currentAgent);
                    }
                }
            }
            else
            {
                List <PawnInstance> monsterList = tileManagerReference.MonstersOnTile[tile];
                foreach (PawnInstance pi in monsterList)
                {
                    NavMeshAgent currentAgent = pi.GetComponent <NavMeshAgent>();
                    if (currentAgent != null)
                    {
                        pi.GetComponent <AnimatedPawn>().WasAgentActiveBeforeBattle = currentAgent.isActiveAndEnabled;
                        if (currentAgent.isActiveAndEnabled)
                        {
                            currentAgent.enabled = false;
                        }
                    }
                    if (pi.GetComponent <GlowObjectCmd>() != null)
                    {
                        GlowController.RegisterObject(pi.GetComponent <GlowObjectCmd>());
                    }

                    if (pi.GetComponentInChildren <AggroBehaviour>() != null)
                    {
                        pi.GetComponentInChildren <AggroBehaviour>().gameObject.SetActive(false);
                    }
                }
            }
        }

        // Mask tile portals
        Transform tilePortals = currentFighters[0].CurrentTile.transform.GetChild(0).GetChild((int)TilePrefabChildren.PortalTriggers);

        for (int i = 0; i < tilePortals.childCount; i++)
        {
            if (tilePortals.GetChild(i).gameObject.activeSelf)
            {
                tilePortalsDisabled.Add(tilePortals.GetChild(i).gameObject);
                tilePortals.GetChild(i).gameObject.SetActive(false);
            }
        }

        // Mask quest reminder button
        gameScreens.transform.GetChild(0).GetChild((int)IngameScreensEnum.QuestReminderButton).gameObject.SetActive(false);

        Transform tileModel = ActiveTile.transform.GetChild(0).GetChild((int)TilePrefabChildren.Model);

        for (int i = 0; i < tileModel.childCount; i++)
        {
            if (tileModel.GetChild(i).name.Equals("Center"))
            {
                tileModel.GetChild(i).gameObject.SetActive(false);
                disabledModels.Add(tileModel.GetChild(i).gameObject);
            }
        }

        PawnInstance[] toDisable = ActiveTile.GetComponentsInChildren <PawnInstance>();
        foreach (PawnInstance pi in toDisable)
        {
            if (pi.GetComponent <Monster>() == null)
            {
                pi.gameObject.SetActive(false);
                disabledModels.Add(pi.gameObject);
            }
        }

        LootInstance[] lootToDisable = ActiveTile.GetComponentsInChildren <LootInstance>();
        foreach (LootInstance li in lootToDisable)
        {
            li.gameObject.SetActive(false);
            disabledModels.Add(li.gameObject);
        }

        // Make escortable disappear
        if (TileManager.Instance.EscortablesOnTile.ContainsKey(ActiveTile))
        {
            foreach (PawnInstance pi in TileManager.Instance.EscortablesOnTile[ActiveTile])
            {
                pi.gameObject.SetActive(false);
                disabledModels.Add(pi.gameObject);
            }
        }

        // Hide item instance
        for (int i = 1; i < ActiveTile.transform.childCount; i++)
        {
            ItemInstance curItem = ActiveTile.transform.GetChild(i).GetComponentInChildren <ItemInstance>();
            if (curItem != null)
            {
                curItem.transform.parent.gameObject.SetActive(false);
                disabledModels.Add(curItem.transform.parent.gameObject);
            }
        }

        Ui.GoActionPanelQ.transform.parent.SetParent(Ui.transform);
    }