Example #1
0
        public void PlaceRandomEnemies(Dungeon dungeon, int currentFloor)
        {
            if (!dungeon.IsGlitchDungeon)
            {
                return;
            }

            List <string> BannedRooms = new List <string>();

            foreach (WeightedRoom wRoom in ExpandPrefabs.MegaMiniBossRoomTable.includedRooms.elements)
            {
                if (wRoom.room != null)
                {
                    BannedRooms.Add(wRoom.room.name);
                }
            }
            foreach (WeightedRoom wRoom in ExpandPrefabs.MegaBossRoomTable.includedRooms.elements)
            {
                if (wRoom.room != null)
                {
                    BannedRooms.Add(wRoom.room.name);
                }
            }

            PlayerController player    = GameManager.Instance.PrimaryPlayer;
            int   RandomEnemiesPlaced  = 0;
            int   RandomEnemiesSkipped = 0;
            int   MaxEnemies           = 20;
            float GlitchedBossOdds     = 0.15f;
            float BonusGlitchEnemyOdds = 0.05f;

            if (dungeon.IsGlitchDungeon)
            {
                MaxEnemies = 65; GlitchedBossOdds = 0.3f; BonusGlitchEnemyOdds = 0.28f;
            }

            if (dungeon.data.rooms == null | dungeon.data.rooms.Count <= 0)
            {
                return;
            }
            foreach (RoomHandler currentRoom in dungeon.data.rooms)
            {
                PrototypeDungeonRoom.RoomCategory roomCategory = currentRoom.area.PrototypeRoomCategory;
                try {
                    if (currentRoom != null && !string.IsNullOrEmpty(currentRoom.GetRoomName()) &&
                        currentRoom.HasActiveEnemies(RoomHandler.ActiveEnemyType.RoomClear) && !currentRoom.IsMaintenanceRoom() &&
                        !currentRoom.IsSecretRoom && !currentRoom.IsWinchesterArcadeRoom && !currentRoom.IsGunslingKingChallengeRoom &&
                        !currentRoom.GetRoomName().StartsWith("Boss Foyer") && !BannedRooms.Contains(currentRoom.GetRoomName()))
                    {
                        if (roomCategory != PrototypeDungeonRoom.RoomCategory.BOSS && roomCategory != PrototypeDungeonRoom.RoomCategory.ENTRANCE &&
                            roomCategory != PrototypeDungeonRoom.RoomCategory.REWARD && roomCategory != PrototypeDungeonRoom.RoomCategory.EXIT)
                        {
                            List <IntVector2> m_CachedPositions        = new List <IntVector2>();
                            IntVector2?       RandomGlitchEnemyVector  = GetRandomAvailableCell(dungeon, currentRoom, m_CachedPositions);
                            IntVector2?       RandomGlitchEnemyVector2 = null;
                            IntVector2?       RandomGlitchEnemyVector3 = null;
                            IntVector2?       RandomGlitchEnemyVector4 = null;

                            if (m_CachedPositions.Count > 0)
                            {
                                RandomGlitchEnemyVector2 = GetRandomAvailableCell(dungeon, currentRoom, m_CachedPositions);
                            }
                            if (m_CachedPositions.Count > 0)
                            {
                                RandomGlitchEnemyVector3 = GetRandomAvailableCell(dungeon, currentRoom, m_CachedPositions, ExitClearence: 13);
                            }
                            if (m_CachedPositions.Count > 0)
                            {
                                RandomGlitchEnemyVector4 = GetRandomAvailableCell(dungeon, currentRoom, m_CachedPositions);
                            }


                            if (RandomGlitchEnemyVector.HasValue)
                            {
                                m_GlitchEnemyDatabase.SpawnRandomGlitchEnemy(currentRoom, RandomGlitchEnemyVector.Value, false, AIActor.AwakenAnimationType.Spawn);
                            }
                            else
                            {
                                RandomEnemiesSkipped++;
                            }

                            if (RandomGlitchEnemyVector2.HasValue && Random.value <= BonusGlitchEnemyOdds)
                            {
                                m_GlitchEnemyDatabase.SpawnRandomGlitchEnemy(currentRoom, RandomGlitchEnemyVector2.Value, false, AIActor.AwakenAnimationType.Spawn);
                            }
                            else
                            {
                                RandomEnemiesSkipped++;
                            }

                            if (RandomGlitchEnemyVector3.HasValue && Random.value <= GlitchedBossOdds)
                            {
                                m_GlitchEnemyDatabase.SpawnRandomGlitchBoss(currentRoom, RandomGlitchEnemyVector3.Value, false, AIActor.AwakenAnimationType.Spawn);
                            }

                            if (RandomGlitchEnemyVector4.HasValue && Random.value <= GlitchedBossOdds)
                            {
                                if (Random.value <= 0.65f)
                                {
                                    m_GlitchEnemyDatabase.SpawnGlitchedObjectAsEnemy(currentRoom, RandomGlitchEnemyVector4.Value, false, AIActor.AwakenAnimationType.Spawn);
                                }
                                else
                                {
                                    m_GlitchEnemyDatabase.SpawnGlitchedPlayerAsEnemy(currentRoom, RandomGlitchEnemyVector4.Value, false, AIActor.AwakenAnimationType.Spawn);
                                }
                            }

                            RandomEnemiesPlaced++;
                            if (RandomEnemiesPlaced + RandomEnemiesSkipped >= MaxEnemies)
                            {
                                break;
                            }
                        }
                    }
                } catch (System.Exception ex) {
                    if (ExpandStats.debugMode)
                    {
                        ETGModConsole.Log("[DEBUG] Exception while setting up or placing enemy for current room" /*+ currentRoom.GetRoomName()*/, false);
                    }
                    if (ExpandStats.debugMode)
                    {
                        ETGModConsole.Log("[DEBUG] Skipping current room...", false);
                    }
                    if (ExpandStats.debugMode)
                    {
                        ETGModConsole.Log(ex.Message + ex.StackTrace + ex.Source, false);
                    }
                    continue;
                }
                AIActor[] allAIActors = FindObjectsOfType <AIActor>();
                if (allAIActors != null && allAIActors.Length > 0)
                {
                    foreach (AIActor enemy in allAIActors)
                    {
                        if (enemy.name.ToLower().StartsWith("corrupted"))
                        {
                            RoomHandler ParentRoom = enemy.transform.position.GetAbsoluteRoom();
                            if (ParentRoom != null)
                            {
                                if (!enemy.gameObject.transform.parent)
                                {
                                    enemy.transform.parent = ParentRoom.hierarchyParent;
                                }
                            }
                        }
                    }
                }
            }
            if (ExpandStats.debugMode)
            {
                ETGModConsole.Log("[DEBUG] Max Number of Glitched Enemies assigned to floor: " + MaxEnemies, false);
                ETGModConsole.Log("[DEBUG] Number of Glitched Enemies placed: " + RandomEnemiesPlaced, false);
                ETGModConsole.Log("[DEBUG] Number of Glitched Enemies skipped: " + RandomEnemiesSkipped, false);
                if (RandomEnemiesPlaced <= 0)
                {
                    ETGModConsole.Log("[DEBUG] Error: No Glitched Enemies have been placed!", false);
                }
            }
            Destroy(m_GlitchEnemyDatabase);
            return;
        }
        private void HandleChooseCorruptionEnemySource()
        {
            aiActor.enabled            = false;
            behaviorSpeculator.enabled = false;
            aiActor.ToggleRenderers(false);
            specRigidbody.enabled = false;
            aiActor.IsGone        = true;
            RoomHandler currentRoom    = transform.position.GetAbsoluteRoom();
            IntVector2  cachedPosition = (transform.PositionVector2().ToIntVector2() - currentRoom.area.basePosition);

            // bool WillBeBigEnemy = UnityEngine.Random.value <= 0.2f;
            // bool WillBeGlitchObject = UnityEngine.Random.value <= 0.2f;

            if (aiShooter)
            {
                aiShooter.ToggleGunAndHandRenderers(false, "ExpandCorruptedEnemyEngageDoer");
            }
            GameObject newEnemy = null;

            ExpandGlitchedEnemies glitchedEnemies = new ExpandGlitchedEnemies();

            try {
                newEnemy = glitchedEnemies.SpawnRandomGlitchEnemy(currentRoom, cachedPosition, true);
            } catch (Exception) {
                // If something broke, destroy broken Enemy (if it exist) to prevent possible softlocks.
                if (newEnemy)
                {
                    if (newEnemy.GetComponent <AIActor>())
                    {
                        currentRoom.DeregisterEnemy(newEnemy.GetComponent <AIActor>());
                    }
                    Destroy(newEnemy);
                }
            }

            glitchedEnemies = null;

            if (newEnemy && newEnemy.GetComponent <AIActor>())
            {
                newEnemy.GetComponent <AIActor>().aiAnimator.PlayDefaultAwakenedState();
                newEnemy.GetComponent <AIActor>().aiActor.State = AIActor.ActorState.Normal;
                newEnemy.GetComponent <AIActor>().aiActor.invisibleUntilAwaken = false;
            }

            currentRoom.DeregisterEnemy(aiActor);
            Destroy(gameObject);
            return;

            /*string SelectedEnemyToBecome;
             *
             * if (WillBeBigEnemy) {
             *  SelectedEnemyToBecome = BraveUtility.RandomElement(ValidTransformSpecialEnemies);
             * } else {
             *  SelectedEnemyToBecome = BraveUtility.RandomElement(ValidTransformEnemies);
             *  ValidSourceEnemies.Remove(SelectedEnemyToBecome);
             * }
             *
             * string SelectedEnemyToUseAttacks = BraveUtility.RandomElement(ValidSourceEnemies);
             *
             * ReplaceEnemyData(SelectedEnemyToBecome, SelectedEnemyToUseAttacks, WillBeBigEnemy, WillBeGlitchObject);
             *
             * aiActor.enabled = true;
             * RegenerateCache();
             * behaviorSpeculator.enabled = true;
             * behaviorSpeculator.RegenerateCache();
             * // behaviorSpeculator.RefreshBehaviors();
             * aiActor.ToggleRenderers(true);
             * if (aiShooter) { aiShooter.ToggleGunAndHandRenderers(true, "ExpandCorruptedEnemyEngageDoer"); }
             * specRigidbody.enabled = true;
             * specRigidbody.RegenerateCache();
             * specRigidbody.RegenerateColliders = true;
             * // specRigidbody.Reinitialize();
             * healthHaver.RegenerateCache();
             * aiActor.IsGone = false;
             * aiAnimator.PlayDefaultAwakenedState();
             * aiActor.State = AIActor.ActorState.Normal;
             * aiActor.invisibleUntilAwaken = false;
             * // transform.position = cachedPosition;
             * // specRigidbody.Reinitialize();
             * return;*/
        }