private void HandleRatBossSetup()
        {
            GameObject SpecialRatBoss = DungeonPlaceableUtility.InstantiateDungeonPlaceable(EnemyDatabase.GetOrLoadByGuid("6868795625bd46f3ae3e4377adce288b").gameObject, m_ParentRoom, new IntVector2(17, 28), true, AIActor.AwakenAnimationType.Awaken, true);
            AIActor    RatBossAIActor = SpecialRatBoss.GetComponent <AIActor>();

            if (RatBossAIActor != null)
            {
                PickupObject.ItemQuality targetQuality = (UnityEngine.Random.value >= 0.2f) ? ((!BraveUtility.RandomBool()) ? PickupObject.ItemQuality.C : PickupObject.ItemQuality.D) : PickupObject.ItemQuality.B;
                GenericLootTable         lootTable     = (!BraveUtility.RandomBool()) ? GameManager.Instance.RewardManager.GunsLootTable : GameManager.Instance.RewardManager.ItemsLootTable;
                PickupObject             item          = LootEngine.GetItemOfTypeAndQuality <PickupObject>(targetQuality, lootTable, false);
                PickupObject             item2         = LootEngine.GetItemOfTypeAndQuality <PickupObject>(targetQuality, lootTable, false);
                Destroy(RatBossAIActor.gameObject.GetComponent <ResourcefulRatDeathController>());
                Destroy(RatBossAIActor.gameObject.GetComponent <ResourcefulRatRewardRoomController>());
                RatBossAIActor.State        = AIActor.ActorState.Awakening;
                RatBossAIActor.StealthDeath = true;
                RatBossAIActor.healthHaver.gameObject.AddComponent <ExpandSpawnGlitchObjectOnDeath>();
                ExpandSpawnGlitchObjectOnDeath ObjectSpawnerComponent = RatBossAIActor.healthHaver.gameObject.GetComponent <ExpandSpawnGlitchObjectOnDeath>();
                ObjectSpawnerComponent.spawnRatCorpse     = true;
                ObjectSpawnerComponent.ratCorpseSpawnsKey = true;
                ObjectSpawnerComponent.parentEnemyWasRat  = true;
                if (item && item2)
                {
                    RatBossAIActor.AdditionalSafeItemDrops = new List <PickupObject> {
                        item, item2
                    };
                }
                RatBossAIActor.healthHaver.enabled = true;
                RatBossAIActor.healthHaver.forcePreventVictoryMusic = true;
                RatBossAIActor.ConfigureOnPlacement(m_ParentRoom);
                RatBossAIActor.specRigidbody.CollideWithOthers = true;
            }
        }
示例#2
0
        private void SpawnObjects(GameObject[] selectedObjects)
        {
            ObjectPrefabSpawnCount = selectedObjects.Length;
            if (ObjectPrefabSpawnCount < 0 | selectedObjects == null)
            {
                if (ExpandSettings.debugMode)
                {
                    ETGModConsole.Log("[DEBUG] ERROR: Object array is empty or null! Nothing to spawn!");
                }
                return;
            }
            IntVector2 pos = specRigidbody.UnitCenter.ToIntVector2(VectorConversions.Floor);

            if (aiActor.IsFalling && !allowSpawnOverPit)
            {
                return;
            }
            if (GameManager.Instance.Dungeon.CellIsPit(specRigidbody.UnitCenter.ToVector3ZUp(0f)) && !allowSpawnOverPit)
            {
                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 < ObjectPrefabSpawnCount; i++)
            {
                if (objectsToSpawn == null)
                {
                    return;
                }
                GameObject SelectedObject = selectedObjects[i];
                if (spawnRatCorpse)
                {
                    SelectedObject = ExpandPrefabs.RatCorpseNPC;
                }
                GameObject SpawnedObject = null;
                if (!usesExternalObjectArray)
                {
                    if (spawnRatCorpse)
                    {
                        SpawnedObject = Instantiate(SelectedObject, (specRigidbody.GetUnitCenter(ColliderType.HitBox) - new Vector2(0.6f, 0.6f)).ToVector3ZUp(), Quaternion.identity);
                    }
                    else if (SelectedObject.GetComponent <Chest>() != null)
                    {
                        if (GameManager.Instance.Dungeon.GetRoomFromPosition(aiActor.transform.PositionVector2().ToIntVector2()) != null)
                        {
                            // RoomHandler currentRoom = aiActor.GetAbsoluteParentRoom();
                            RoomHandler        currentRoom  = GameManager.Instance.Dungeon.GetRoomFromPosition(aiActor.transform.PositionVector2().ToIntVector2());
                            Chest              TruthChest   = SelectedObject.GetComponent <Chest>();
                            WeightedGameObject wChestObject = new WeightedGameObject();
                            wChestObject.rawGameObject = SelectedObject;
                            WeightedGameObjectCollection wChestObjectCollection = new WeightedGameObjectCollection();
                            wChestObjectCollection.Add(wChestObject);
                            Chest PlacedTruthChest = currentRoom.SpawnRoomRewardChest(wChestObjectCollection, aiActor.transform.PositionVector2().ToIntVector2());
                            SpawnedObject = PlacedTruthChest.gameObject;
                        }
                    }
                    else
                    {
                        SpawnedObject = Instantiate(SelectedObject, specRigidbody.UnitCenter.ToIntVector2(VectorConversions.Floor).ToVector3(), Quaternion.identity);
                    }
                    if (SpawnedObject == null)
                    {
                        return;
                    }
                }

                if (SpawnedObject == null)
                {
                    return;
                }

                if (ExpandSettings.debugMode)
                {
                    ETGModConsole.Log("About to Spawn an object after death.");
                    ETGModConsole.Log("Object: " + SpawnedObject.name);
                    ETGModConsole.Log("AIActor:" + aiActor.GetActorName());
                }

                float RandomIntervalFloat       = UnityEngine.Random.Range(0.02f, 0.06f);
                float RandomDispFloat           = UnityEngine.Random.Range(0.1f, 0.16f);
                float RandomDispIntensityFloat  = UnityEngine.Random.Range(0.1f, 0.4f);
                float RandomColorProbFloat      = UnityEngine.Random.Range(0.05f, 0.2f);
                float RandomColorIntensityFloat = UnityEngine.Random.Range(0.1f, 0.25f);

                if (!spawnRatCorpse)
                {
                    if (SpawnedObject.GetComponent <tk2dBaseSprite>() != null)
                    {
                        ExpandShaders.Instance.ApplyGlitchShader(SpawnedObject.GetComponent <tk2dBaseSprite>(), true, RandomIntervalFloat, RandomDispFloat, RandomDispIntensityFloat, RandomColorProbFloat, RandomColorProbFloat);
                    }
                    else if (SpawnedObject.GetComponentInChildren <tk2dBaseSprite>() != null && SpawnedObject.GetComponent <Chest>() == null)
                    {
                        ExpandShaders.Instance.ApplyGlitchShader(SpawnedObject.GetComponentInChildren <tk2dBaseSprite>(), true, RandomIntervalFloat, RandomDispFloat, RandomDispIntensityFloat, RandomColorProbFloat, RandomColorProbFloat);
                    }
                }
                if (SpawnedObject != null)
                {
                    if (!usesExternalObjectArray && SpawnedObject.GetComponent <MysteryMimicManController>() != null)
                    {
                        Destroy(SpawnedObject.GetComponent <MysteryMimicManController>());
                    }

                    if (!usesExternalObjectArray && SpawnedObject.GetComponent <TalkDoerLite>() != null)
                    {
                        TalkDoerLite talkdoerComponent = SpawnedObject.GetComponent <TalkDoerLite>();
                        talkdoerComponent.SpeaksGleepGlorpenese = true;
                        talkdoerComponent.transform.position.XY().GetAbsoluteRoom().RegisterInteractable(talkdoerComponent);
                        if (SpawnedObject.name == ExpandPrefabs.RatCorpseNPC.name && !usesExternalObjectArray)
                        {
                            talkdoerComponent.transform.position.XY().GetAbsoluteRoom().TransferInteractableOwnershipToDungeon(talkdoerComponent);
                        }
                        else if (spawnRatCorpse)
                        {
                            talkdoerComponent.transform.position.XY().GetAbsoluteRoom().TransferInteractableOwnershipToDungeon(talkdoerComponent);
                        }
                        if (SpawnedObject.name.StartsWith(ExpandPrefabs.RatCorpseNPC.name))
                        {
                            talkdoerComponent.playmakerFsm.SetState("Set Mode");
                            // ExpandUtility.AddHealthHaver(talkdoerComponent.gameObject, 60, flashesOnDamage: false, exploderSpawnsItem: ratCorpseSpawnsItemOnExplosion);
                            ExpandUtility.GenerateHealthHaver(talkdoerComponent.gameObject, 60, flashesOnDamage: false, exploderSpawnsItem: ratCorpseSpawnsItemOnExplosion, isCorruptedObject: false, isRatNPC: true);
                            if (ratCorpseSpawnsKey)
                            {
                                HealthHaver ratCorpseHealthHaver = talkdoerComponent.gameObject.GetComponent <HealthHaver>();
                                ratCorpseHealthHaver.gameObject.AddComponent <ExpandSpawnGlitchObjectOnDeath>();
                                ExpandSpawnGlitchObjectOnDeath ratCorpseObjectSpawnOnDeath = ratCorpseHealthHaver.gameObject.GetComponent <ExpandSpawnGlitchObjectOnDeath>();
                                ratCorpseObjectSpawnOnDeath.spawnRatKey = true;
                            }
                        }
                    }

                    if (!usesExternalObjectArray && SpawnedObject.GetComponentInChildren <KickableObject>() != null && SpawnedObject.GetComponent <TalkDoerLite>() == null)
                    {
                        KickableObject kickableObjectComponent = SpawnedObject.GetComponentInChildren <KickableObject>();
                        kickableObjectComponent.transform.position.XY().GetAbsoluteRoom().RegisterInteractable(kickableObjectComponent);
                        kickableObjectComponent.ConfigureOnPlacement(kickableObjectComponent.transform.position.XY().GetAbsoluteRoom());
                    }

                    if (!usesExternalObjectArray && SpawnedObject.GetComponent <FlippableCover>() != null)
                    {
                        FlippableCover tableComponent = SpawnedObject.GetComponent <FlippableCover>();
                        tableComponent.transform.position.XY().GetAbsoluteRoom().RegisterInteractable(tableComponent);
                        tableComponent.ConfigureOnPlacement(tableComponent.transform.position.XY().GetAbsoluteRoom());
                        SpawnedObject.AddComponent <ExpandKickableObject>();
                        ExpandKickableObject chaosKickableComponent = SpawnedObject.GetComponent <ExpandKickableObject>();
                        chaosKickableComponent.transform.position.XY().GetAbsoluteRoom().RegisterInteractable(chaosKickableComponent);
                    }

                    if (!usesExternalObjectArray && SpawnedObject.GetComponent <NoteDoer>() != null)
                    {
                        NoteDoer noteComponent = SpawnedObject.GetComponent <NoteDoer>();
                        noteComponent.transform.position.XY().GetAbsoluteRoom().RegisterInteractable(noteComponent);
                        noteComponent.alreadyLocalized     = true;
                        noteComponent.useAdditionalStrings = false;
                        noteComponent.stringKey            = ("Here lies " + aiActor.GetActorName() + "\nHe was annoying anyways....");
                    }

                    /*if (!usesExternalObjectArray && SpawnedObject.GetComponent<HeartDispenser>() != null) {
                     *  HeartDispenser heartDispenserComponent = SpawnedObject.GetComponent<HeartDispenser>();
                     *  heartDispenserComponent.transform.position.XY().GetAbsoluteRoom().RegisterInteractable(heartDispenserComponent);
                     * }*/

                    if (SpawnedObject.GetComponentInChildren <SpeculativeRigidbody>() != null &&
                        SpawnedObject.GetComponentInChildren <KickableObject>() == null &&
                        SpawnedObject.GetComponent <TrapController>() == null &&
                        SpawnedObject.GetComponent <FlippableCover>() == null &&
                        SpawnedObject.GetComponent <Chest>() == null &&
                        SelectedObject.name != "NPC_ResourcefulRat_Beaten" &&
                        !usesExternalObjectArray)
                    {
                        SpeculativeRigidbody SpawnedObjectRigidBody = SpawnedObject.GetComponentInChildren <SpeculativeRigidbody>();
                        SpawnedObjectRigidBody.PrimaryPixelCollider.Enabled = false;
                        SpawnedObjectRigidBody.HitboxPixelCollider.Enabled  = false;
                        SpawnedObjectRigidBody.CollideWithOthers            = false;
                    }
                }

                if (SpawnedObject.GetComponentInChildren <SpeculativeRigidbody>() != null && SpawnedObject.name.ToLower().StartsWith("Table"))
                {
                    try {
                        SpeculativeRigidbody objectSpecRigidBody = SpawnedObject.GetComponentInChildren <SpeculativeRigidbody>();
                        objectSpecRigidBody.Initialize();
                        Vector2 a      = unitBottomLeft - (objectSpecRigidBody.UnitBottomLeft - SpawnedObject.transform.position.XY());
                        Vector2 vector = a + new Vector2(Mathf.Max(0f, specRigidbody.UnitDimensions.x - objectSpecRigidBody.UnitDimensions.x), 0f);
                        SpawnedObject.transform.position = Vector2.Lerp(a, vector, (ObjectPrefabSpawnCount != 1) ? i / (ObjectPrefabSpawnCount - 1f) : 0f);
                        objectSpecRigidBody.Reinitialize();
                        a      -= new Vector2(PhysicsEngine.PixelToUnit(extraPixelWidth), 0f);
                        vector += new Vector2(PhysicsEngine.PixelToUnit(extraPixelWidth), 0f);
                        Vector2       a2            = Vector2.Lerp(a, vector, (ObjectPrefabSpawnCount != 1) ? i / (ObjectPrefabSpawnCount - 1f) : 0.5f);
                        IntVector2    intVector     = PhysicsEngine.UnitToPixel(a2 - SpawnedObject.transform.position.XY());
                        CollisionData collisionData = null;
                        if (PhysicsEngine.Instance.RigidbodyCastWithIgnores(objectSpecRigidBody, intVector, out collisionData, true, true, null, false, list.ToArray()))
                        {
                            intVector = collisionData.NewPixelsToMove;
                        }
                        CollisionData.Pool.Free(ref collisionData);
                        SpawnedObject.transform.position += PhysicsEngine.PixelToUnit(intVector).ToVector3ZUp(1f);
                        objectSpecRigidBody.Reinitialize();
                        list.Add(objectSpecRigidBody);
                    } catch (Exception ex) {
                        if (ExpandSettings.debugMode)
                        {
                            ETGModConsole.Log("[DEBUG]: Warning: Exception caught while setting up rigid body settings in ChaosSpawnGlitchedObjectONDeath!");
                            Debug.Log("Warning: Exception caught while setting up rigid body settings in ChaosSpawnGlitchedObjectONDeath!");
                            Debug.LogException(ex);
                        }
                    }
                }
            }
            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]);
                        }
                    }
                }
            }
        }