Exemplo n.º 1
0
        public static GameObject MainHook(GameObject objectToInstantiate, RoomHandler targetRoom,
                                          IntVector2 location, bool deferConfiguration, AIActor.AwakenAnimationType awakenAnimType = AIActor.AwakenAnimationType.Default, bool autoEngage = false)
        {   //hooks into InstantiateDungeonPlaceable
            GameObject result;

            System.Random rnd = new System.Random();
            int           nu  = 0;
            string        enemyGuid;

            GRandomHook.wasBoss = false;
            bool isbossroom = false;


            if (targetRoom.area.PrototypeRoomCategory == PrototypeDungeonRoom.RoomCategory.BOSS &&
                targetRoom.area.PrototypeRoomBossSubcategory == PrototypeDungeonRoom.RoomBossSubCategory.FLOOR_BOSS)
            {
                isbossroom = true;
            }

            else if (GRandomRoomDatabaseHelper.AllSpecificDeathRooms.Contains(targetRoom.GetRoomName()))
            {
                isbossroom = true;
            }


            try
            {
                if (objectToInstantiate != null)
                {
                    Vector3 vector = location.ToVector3(0f) + targetRoom.area.basePosition.ToVector3();
                    vector.z = vector.y + vector.z;
                    AIActor component   = objectToInstantiate.GetComponent <AIActor>(); //notused
                    AIActor ogcomponent = component;


                    if (component is AIActorDummy)
                    {
                        objectToInstantiate = (component as AIActorDummy).realPrefab;
                        component           = objectToInstantiate.GetComponent <AIActor>();
                    }

                    SpeculativeRigidbody component2 = objectToInstantiate.GetComponent <SpeculativeRigidbody>(); //notused
                    if (component && component2)
                    {
                        if (component.EnemyGuid != null)
                        {
                            //Here gets enemyGuid based on room. Pulls from EnemyDatabase   ///////////////////////
                            if (isbossroom)
                            {
                                if (component.healthHaver.IsBoss)
                                {
                                    GRandomHook.wasBoss = true;
                                    if (component.healthHaver.GetMaxHealth() != 60) //sometimes gets health as regular enemy health, 60
                                    {
                                        GRandomHook.boss_health = component.healthHaver.GetMaxHealth();
                                        //getting boss health to set for replacement boss
                                    }

                                    //replacement for Boss
                                    nu        = rnd.Next(0, GRandomEnemyDataBaseHelper.UsedBossRoomDatabase.Count);
                                    enemyGuid = GRandomEnemyDataBaseHelper.UsedBossRoomDatabase[nu];
                                }


                                else
                                { //normal enemies as bosses is off and the enemy is not a boss; pull from no bosses database for enemy spawnings
                                    nu        = rnd.Next(0, GRandomEnemyDataBaseHelper.BossRoomRegularEnemiesOnly.Count);
                                    enemyGuid = GRandomEnemyDataBaseHelper.BossRoomRegularEnemiesOnly[nu];
                                }
                            }

                            else if (targetRoom.GetRoomName() == "ResourcefulRat_PitEntrance_01" | targetRoom.GetRoomName() == "ResourcefulRat_Entrance")
                            {
                                nu        = rnd.Next(0, GRandomEnemyDataBaseHelper.HarmlessEnemyDatabase.Count);
                                enemyGuid = GRandomEnemyDataBaseHelper.HarmlessEnemyDatabase[nu];
                            }

                            else
                            {
                                nu        = rnd.Next(0, GRandomEnemyDataBaseHelper.UsedRegularRoomDatabase.Count);
                                enemyGuid = GRandomEnemyDataBaseHelper.UsedRegularRoomDatabase[nu];
                            }


                            if (component.EnemyGuid == "479556d05c7c44f3b6abb3b2067fc778") //wallmimic
                            {
                                enemyGuid = "479556d05c7c44f3b6abb3b2067fc778";
                            }

                            //
                            //can add specific Guid here for debugging
                            //


                            if (enemyGuid == "465da2bb086a4a88a803f79fe3a27677") //replace DraGun, can't remove him from database or forge dragunroom breaks
                            {
                                enemyGuid = "05b8afe0b6cc4fffa9dc6036fa24c8ec";
                            }

                            // End getting guid //////////////////////////////

                            //initializing new AIActor, not sure why they do it again below
                            AIActor prefabActor = EnemyDatabase.GetOrLoadByGuid(enemyGuid);


                            objectToInstantiate = prefabActor.gameObject;
                            component           = objectToInstantiate.GetComponent <AIActor>();
                            component2          = objectToInstantiate.GetComponent <SpeculativeRigidbody>();
                            //bool specificdeathdoer = prefabActor.healthHaver.ManualDeathHandling;



                            GenericIntroDoer genericIntroDoer = component.GetComponent <GenericIntroDoer>();

                            //if (genericIntroDoer) // is boss
                            // handles initiated boss settings
                            if (component.healthHaver.IsBoss)
                            {
                                if (isbossroom)
                                {
                                    prefabActor.healthHaver.SetHealthMaximum(GRandomHook.boss_health);
                                    ETGModConsole.Log("Newbosshealth " + prefabActor.healthHaver.GetMaxHealth());
                                }
                                else
                                {
                                    prefabActor.healthHaver.SetHealthMaximum(60f);
                                }

                                objectToInstantiate = RandomHandleEnemyInfo.RemoveBossIntros(objectToInstantiate);
                                objectToInstantiate = RandomHandleEnemyInfo.ReplaceSpecificBossDeathController(objectToInstantiate);
                                objectToInstantiate = RandomHandleEnemyInfo.AttackBehaviorManipulator(objectToInstantiate);

                                DemonWallController dwc = objectToInstantiate.GetComponent <DemonWallController>();
                                if (dwc)
                                {
                                    Destroy(dwc);
                                }
                            }

                            if (!component.IsNormalEnemy)
                            {
                                objectToInstantiate = RandomHandleEnemyInfo.HandleCompanions(objectToInstantiate);
                            }
                        }


                        PixelCollider pixelCollider = component2.GetPixelCollider(ColliderType.Ground);
                        if (pixelCollider.ColliderGenerationMode != PixelCollider.PixelColliderGeneration.Manual)
                        {
                            Debug.LogErrorFormat("Trying to spawn an AIActor who doesn't have a manual ground collider... do we still do this? Name: {0}", new object[]
                            {
                                objectToInstantiate.name
                            });
                        }
                        Vector2 a       = PhysicsEngine.PixelToUnit(new IntVector2(pixelCollider.ManualOffsetX, pixelCollider.ManualOffsetY));
                        Vector2 vector2 = PhysicsEngine.PixelToUnit(new IntVector2(pixelCollider.ManualWidth, pixelCollider.ManualHeight));
                        Vector2 vector3 = new Vector2((float)Mathf.CeilToInt(vector2.x), (float)Mathf.CeilToInt(vector2.y));
                        Vector2 b       = new Vector2((vector3.x - vector2.x) / 2f, 0f).Quantize(0.0625f);



                        if (targetRoom.GetRoomName() == "DraGunRoom01" | targetRoom.GetRoomName() == "LichRoom02" |
                            targetRoom.GetRoomName() == "LichRoom03" | targetRoom.GetRoomName() == "Bullet_End_Room_04" |
                            targetRoom.GetRoomName() == "ResourcefulRatRoom01")
                        {
                            b -= new Vector2(0.0f, 5.0f);
                        }

                        Vector3 v3 = a - b;
                        vector -= v3;
                        //vector -= a - b; //Vector3
                    }

                    if (component)
                    {
                        component.AwakenAnimType = awakenAnimType;
                    }


                    GameObject NewEnemyObject = UnityEngine.Object.Instantiate <GameObject>(objectToInstantiate, vector, Quaternion.identity);


                    if (!deferConfiguration)
                    {
                        Component[] componentsInChildren = NewEnemyObject.GetComponentsInChildren(typeof(IPlaceConfigurable));
                        for (int i = 0; i < componentsInChildren.Length; i++)
                        {
                            IPlaceConfigurable placeConfigurable = componentsInChildren[i] as IPlaceConfigurable;
                            if (placeConfigurable != null)
                            {
                                placeConfigurable.ConfigureOnPlacement(targetRoom);
                            }
                        }
                    }
                    ObjectVisibilityManager component3 = NewEnemyObject.GetComponent <ObjectVisibilityManager>();
                    if (component3 != null)
                    {
                        component3.Initialize(targetRoom, autoEngage);
                    }
                    MinorBreakable componentInChildren = NewEnemyObject.GetComponentInChildren <MinorBreakable>();
                    if (componentInChildren != null)
                    {
                        IntVector2 key      = location + targetRoom.area.basePosition;
                        CellData   cellData = GameManager.Instance.Dungeon.data[key];
                        if (cellData != null)
                        {
                            cellData.cellVisualData.containsObjectSpaceStamp = true;
                        }
                    }
                    PlayerItem component4 = NewEnemyObject.GetComponent <PlayerItem>();
                    if (component4 != null)
                    {
                        component4.ForceAsExtant = true;
                    }


                    //[Randomizer] Add AIActor GameObjectInfo
                    AIActor enemy_component = NewEnemyObject.GetComponent <AIActor>();
                    if (enemy_component)
                    {
                        if (enemy_component.healthHaver.IsBoss)
                        {
                            if (isbossroom)

                            { //Boss Room
                                enemy_component.healthHaver.bossHealthBar = HealthHaver.BossBarType.MainBar;
                            }
                            else
                            {
                                enemy_component.healthHaver.bossHealthBar = HealthHaver.BossBarType.None;
                                autoEngage = true;
                            }
                            NewEnemyObject = RandomHandleEnemyInfo.ReinstateBossObjectInfo(NewEnemyObject); //removes boss status if regular boss, needs hitbox stuff reinstated
                        }


                        if (GRandomEnemyDataBaseHelper.SpecificEnemyDatabase.Contains(enemy_component.EnemyGuid))
                        {
                            NewEnemyObject = RandomHandleEnemyInfo.SpecificEnemyHelper(NewEnemyObject);
                        }

                        NewEnemyObject = UniqueBossRoomDeathHandler.SpecificRoomHandler(targetRoom, NewEnemyObject);
                    }


                    result = NewEnemyObject;
                }

                else
                {
                    result = null;
                    //return null;
                }
            }

            catch (Exception message)
            {
                Debug.Log("[RANDOMIZER ERROR] " + message.ToString());


                result = null;
            }

            return(result);
        }
Exemplo n.º 2
0
 private void SpawnEnemies(string[] selectedEnemyGuids)
 {
     if (useGlitchedActorPrefab)
     {
         IntVector2 pos = specRigidbody.UnitCenter.ToIntVector2(VectorConversions.Floor);
         if (aiActor.IsFalling && !IsGlitchedLJ)
         {
             return;
         }
         if (GameManager.Instance.Dungeon.CellIsPit(specRigidbody.UnitCenter.ToVector3ZUp(0f)) && !IsGlitchedLJ)
         {
             return;
         }
         RoomHandler roomFromPosition     = GameManager.Instance.Dungeon.GetRoomFromPosition(pos);
         List <SpeculativeRigidbody> list = new List <SpeculativeRigidbody>();
         list.Add(specRigidbody);
         Vector2 unitBottomLeft = specRigidbody.UnitBottomLeft;
         for (int i = 0; i < ActorPrefabSpawnCount; i++)
         {
             if (IsGlitchedLJ)
             {
                 if (transform.position.GetAbsoluteRoom() != null)
                 {
                     ChaosGlitchedEnemies m_GlitchedEnemyDatabase = new ChaosGlitchedEnemies();
                     RoomHandler          CurrentRoom             = transform.position.GetAbsoluteRoom();
                     IntVector2           actorPosition           = specRigidbody.UnitCenter.ToIntVector2(VectorConversions.Floor) - CurrentRoom.area.basePosition;
                     m_GlitchedEnemyDatabase.SpawnGlitchedSuperReaper(CurrentRoom, actorPosition);
                     Destroy(m_GlitchedEnemyDatabase);
                     return;
                 }
             }
             else
             {
                 if (ActorObjectTarget == null)
                 {
                     return;
                 }
                 AIActor.AwakenAnimationType AnimationType = AIActor.AwakenAnimationType.Default;
                 AIActor    aiactor = null;
                 GameObject CachedTargetActorObject     = Instantiate(ActorObjectTarget);
                 bool       ExplodesOnDeath             = false;
                 bool       spawnsGlitchedObjectOnDeath = false;
                 if (UnityEngine.Random.value <= 0.25f)
                 {
                     ExplodesOnDeath = true;
                 }
                 if (UnityEngine.Random.value <= 0.15f)
                 {
                     spawnsGlitchedObjectOnDeath = true;
                 }
                 ChaosGlitchedEnemies m_GlitchedEnemyDatabase = new ChaosGlitchedEnemies();
                 aiactor = AIActor.Spawn(m_GlitchedEnemyDatabase.GenerateGlitchedActorPrefab(CachedTargetActorObject, ActorOverrideSource, ExplodesOnDeath, spawnsGlitchedObjectOnDeath), specRigidbody.UnitCenter.ToIntVector2(VectorConversions.Floor), roomFromPosition, true, AnimationType, true);
                 Destroy(m_GlitchedEnemyDatabase);
                 if (aiactor == null)
                 {
                     return;
                 }
                 if (aiActor.IsBlackPhantom)
                 {
                     aiactor.BecomeBlackPhantom();
                 }
                 if (aiactor)
                 {
                     aiactor.specRigidbody.Initialize();
                     Vector2 a      = unitBottomLeft - (aiactor.specRigidbody.UnitBottomLeft - aiactor.transform.position.XY());
                     Vector2 vector = a + new Vector2(Mathf.Max(0f, specRigidbody.UnitDimensions.x - aiactor.specRigidbody.UnitDimensions.x), 0f);
                     aiactor.transform.position = Vector2.Lerp(a, vector, (ActorPrefabSpawnCount != 1) ? i / (ActorPrefabSpawnCount - 1f) : 0f);
                     aiactor.specRigidbody.Reinitialize();
                     a      -= new Vector2(PhysicsEngine.PixelToUnit(extraPixelWidth), 0f);
                     vector += new Vector2(PhysicsEngine.PixelToUnit(extraPixelWidth), 0f);
                     Vector2       a2            = Vector2.Lerp(a, vector, (ActorPrefabSpawnCount != 1) ? i / (ActorPrefabSpawnCount - 1f) : 0.5f);
                     IntVector2    intVector     = PhysicsEngine.UnitToPixel(a2 - aiactor.transform.position.XY());
                     CollisionData collisionData = null;
                     if (PhysicsEngine.Instance.RigidbodyCastWithIgnores(aiactor.specRigidbody, intVector, out collisionData, true, true, null, false, list.ToArray()))
                     {
                         intVector = collisionData.NewPixelsToMove;
                     }
                     CollisionData.Pool.Free(ref collisionData);
                     aiactor.transform.position += PhysicsEngine.PixelToUnit(intVector).ToVector3ZUp(1f);
                     aiactor.specRigidbody.Reinitialize();
                     if (i == 0)
                     {
                         aiactor.aiAnimator.FacingDirection = 180f;
                     }
                     else if (i == ActorPrefabSpawnCount - 1)
                     {
                         aiactor.aiAnimator.FacingDirection = 0f;
                     }
                     HandleSpawn(aiactor);
                     list.Add(aiactor.specRigidbody);
                     Destroy(CachedTargetActorObject);
                 }
             }
         }
         if (list.Count > 0)
         {
             for (int j = 0; j < list.Count; j++)
             {
                 for (int k = 0; k < list.Count; k++)
                 {
                     if (j != k)
                     {
                         list[j].RegisterGhostCollisionException(list[k]);
                     }
                 }
             }
         }
     }
     else if (spawnPosition == SpawnPosition.InsideCollider)
     {
         IntVector2 pos = specRigidbody.UnitCenter.ToIntVector2(VectorConversions.Floor);
         if (aiActor.IsFalling)
         {
             return;
         }
         if (GameManager.Instance.Dungeon.CellIsPit(specRigidbody.UnitCenter.ToVector3ZUp(0f)))
         {
             return;
         }
         RoomHandler roomFromPosition     = GameManager.Instance.Dungeon.GetRoomFromPosition(pos);
         List <SpeculativeRigidbody> list = new List <SpeculativeRigidbody>();
         list.Add(specRigidbody);
         Vector2 unitBottomLeft = specRigidbody.UnitBottomLeft;
         for (int i = 0; i < selectedEnemyGuids.Length; i++)
         {
             AIActor orLoadByGuid = EnemyDatabase.GetOrLoadByGuid(selectedEnemyGuids[i]);
             AIActor aiactor      = AIActor.Spawn(orLoadByGuid, specRigidbody.UnitCenter.ToIntVector2(VectorConversions.Floor), roomFromPosition, false, AIActor.AwakenAnimationType.Default, true);
             if (aiActor.IsBlackPhantom)
             {
                 aiactor.ForceBlackPhantom = true;
             }
             if (aiactor)
             {
                 aiactor.specRigidbody.Initialize();
                 Vector2 a      = unitBottomLeft - (aiactor.specRigidbody.UnitBottomLeft - aiactor.transform.position.XY());
                 Vector2 vector = a + new Vector2(Mathf.Max(0f, specRigidbody.UnitDimensions.x - aiactor.specRigidbody.UnitDimensions.x), 0f);
                 aiactor.transform.position = Vector2.Lerp(a, vector, (selectedEnemyGuids.Length != 1) ? i / (selectedEnemyGuids.Length - 1f) : 0f);
                 aiactor.specRigidbody.Reinitialize();
                 a      -= new Vector2(PhysicsEngine.PixelToUnit(extraPixelWidth), 0f);
                 vector += new Vector2(PhysicsEngine.PixelToUnit(extraPixelWidth), 0f);
                 Vector2       a2            = Vector2.Lerp(a, vector, (selectedEnemyGuids.Length != 1) ? i / (selectedEnemyGuids.Length - 1f) : 0.5f);
                 IntVector2    intVector     = PhysicsEngine.UnitToPixel(a2 - aiactor.transform.position.XY());
                 CollisionData collisionData = null;
                 if (PhysicsEngine.Instance.RigidbodyCastWithIgnores(aiactor.specRigidbody, intVector, out collisionData, true, true, null, false, list.ToArray()))
                 {
                     intVector = collisionData.NewPixelsToMove;
                 }
                 CollisionData.Pool.Free(ref collisionData);
                 // aiactor.transform.position += PhysicsEngine.PixelToUnit(intVector);
                 aiactor.transform.position += PhysicsEngine.PixelToUnit(intVector).ToVector3ZUp(1f);
                 aiactor.specRigidbody.Reinitialize();
                 if (i == 0)
                 {
                     aiactor.aiAnimator.FacingDirection = 180f;
                 }
                 else if (i == selectedEnemyGuids.Length - 1)
                 {
                     aiactor.aiAnimator.FacingDirection = 0f;
                 }
                 HandleSpawn(aiactor);
                 list.Add(aiactor.specRigidbody);
             }
         }
         for (int j = 0; j < list.Count; j++)
         {
             for (int k = 0; k < list.Count; k++)
             {
                 if (j != k)
                 {
                     list[j].RegisterGhostCollisionException(list[k]);
                 }
             }
         }
     }
     else if (spawnPosition == SpawnPosition.ScreenEdge)
     {
         for (int l = 0; l < selectedEnemyGuids.Length; l++)
         {
             AIActor orLoadByGuid2 = EnemyDatabase.GetOrLoadByGuid(selectedEnemyGuids[l]);
             AIActor spawnedActor  = AIActor.Spawn(orLoadByGuid2, specRigidbody.UnitCenter.ToIntVector2(VectorConversions.Floor), aiActor.ParentRoom, false, AIActor.AwakenAnimationType.Default, true);
             if (spawnedActor)
             {
                 Vector2       cameraBottomLeft = BraveUtility.ViewportToWorldpoint(new Vector2(0f, 0f), ViewportType.Gameplay);
                 Vector2       cameraTopRight   = BraveUtility.ViewportToWorldpoint(new Vector2(1f, 1f), ViewportType.Gameplay);
                 IntVector2    bottomLeft       = cameraBottomLeft.ToIntVector2(VectorConversions.Ceil);
                 IntVector2    topRight         = cameraTopRight.ToIntVector2(VectorConversions.Floor) - IntVector2.One;
                 CellValidator cellValidator    = delegate(IntVector2 c) {
                     for (int num2 = 0; num2 < spawnedActor.Clearance.x; num2++)
                     {
                         for (int num3 = 0; num3 < spawnedActor.Clearance.y; num3++)
                         {
                             if (GameManager.Instance.Dungeon.data.isTopWall(c.x + num2, c.y + num3))
                             {
                                 return(false);
                             }
                             if (GameManager.Instance.Dungeon.data[c.x + num2, c.y + num3].isExitCell)
                             {
                                 return(false);
                             }
                         }
                     }
                     return(c.x >= bottomLeft.x && c.y >= bottomLeft.y && c.x + spawnedActor.Clearance.x - 1 <= topRight.x && c.y + spawnedActor.Clearance.y - 1 <= topRight.y);
                 };
                 Func <IntVector2, float> cellWeightFinder = delegate(IntVector2 c) {
                     float a3 = float.MaxValue;
                     a3 = Mathf.Min(a3, c.x - cameraBottomLeft.x);
                     a3 = Mathf.Min(a3, c.y - cameraBottomLeft.y);
                     a3 = Mathf.Min(a3, cameraTopRight.x - c.x + spawnedActor.Clearance.x);
                     return(Mathf.Min(a3, cameraTopRight.y - c.y + spawnedActor.Clearance.y));
                 };
                 Vector2    b = spawnedActor.specRigidbody.UnitCenter - spawnedActor.transform.position.XY();
                 IntVector2?randomWeightedAvailableCell = spawnedActor.ParentRoom.GetRandomWeightedAvailableCell(new IntVector2?(spawnedActor.Clearance), new CellTypes?(spawnedActor.PathableTiles), false, cellValidator, cellWeightFinder, 0.25f);
                 if (randomWeightedAvailableCell == null)
                 {
                     Debug.LogError("Screen Edge Spawn FAILED!", spawnedActor);
                     Destroy(spawnedActor);
                 }
                 else
                 {
                     spawnedActor.transform.position = Pathfinder.GetClearanceOffset(randomWeightedAvailableCell.Value, spawnedActor.Clearance) - b;
                     spawnedActor.specRigidbody.Reinitialize();
                     HandleSpawn(spawnedActor);
                 }
             }
         }
     }
     else if (spawnPosition == SpawnPosition.InsideRadius)
     {
         Vector2 unitCenter = specRigidbody.GetUnitCenter(ColliderType.HitBox);
         List <SpeculativeRigidbody> list2 = new List <SpeculativeRigidbody>();
         list2.Add(specRigidbody);
         for (int m = 0; m < selectedEnemyGuids.Length; m++)
         {
             Vector2 vector2 = unitCenter + UnityEngine.Random.insideUnitCircle * spawnRadius;
             if (GameManager.Instance.CurrentLevelOverrideState == GameManager.LevelOverrideState.CHARACTER_PAST && SceneManager.GetActiveScene().name == "fs_robot")
             {
                 RoomHandler entrance = GameManager.Instance.Dungeon.data.Entrance;
                 Vector2     lhs      = entrance.area.basePosition.ToVector2() + new Vector2(7f, 7f);
                 Vector2     lhs2     = entrance.area.basePosition.ToVector2() + new Vector2(38f, 36f);
                 vector2 = Vector2.Min(lhs2, Vector2.Max(lhs, vector2));
             }
             AIActor orLoadByGuid3 = EnemyDatabase.GetOrLoadByGuid(selectedEnemyGuids[m]);
             AIActor aiactor2      = AIActor.Spawn(orLoadByGuid3, unitCenter.ToIntVector2(VectorConversions.Floor), aiActor.ParentRoom, true, AIActor.AwakenAnimationType.Default, true);
             if (aiactor2)
             {
                 aiactor2.specRigidbody.Initialize();
                 Vector2 unit = vector2 - aiactor2.specRigidbody.GetUnitCenter(ColliderType.HitBox);
                 aiactor2.specRigidbody.ImpartedPixelsToMove = PhysicsEngine.UnitToPixel(unit);
                 HandleSpawn(aiactor2);
                 list2.Add(aiactor2.specRigidbody);
             }
         }
         for (int n = 0; n < list2.Count; n++)
         {
             for (int num = 0; num < list2.Count; num++)
             {
                 if (n != num)
                 {
                     list2[n].RegisterGhostCollisionException(list2[num]);
                 }
             }
         }
     }
     else
     {
         Debug.LogError("Unknown spawn type: " + spawnPosition);
     }
 }