private void HandleHideKeyOnTable() { ExpandObjectDatabase objectDatabase = new ExpandObjectDatabase(); IntVector2 GlitchedTable1Position = new IntVector2(9, 10); IntVector2 GlitchedTable2Position = new IntVector2(9, 8); GameObject GlitchedVerticalTable1 = ExpandUtility.GenerateDungeonPlacable(objectDatabase.TableVertical, false, true).InstantiateObject(m_ParentRoom, GlitchedTable1Position); GameObject GlitchedVerticalTable2 = ExpandUtility.GenerateDungeonPlacable(objectDatabase.TableVertical, false, true).InstantiateObject(m_ParentRoom, GlitchedTable2Position); GlitchedVerticalTable1.transform.SetParent(m_ParentRoom.hierarchyParent, true); GlitchedVerticalTable2.transform.SetParent(m_ParentRoom.hierarchyParent, true); GlitchedVerticalTable1.AddComponent <ExpandKickableObject>(); GlitchedVerticalTable2.AddComponent <ExpandKickableObject>(); 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.2f); float RandomColorProbFloat = UnityEngine.Random.Range(0.05f, 0.2f); float RandomColorIntensityFloat = UnityEngine.Random.Range(0.1f, 0.22f); if (BraveUtility.RandomBool()) { ExpandKickableObject GlitchedTable1Component = GlitchedVerticalTable1.GetComponent <ExpandKickableObject>(); GlitchedTable1Component.SpawnedObject = PickupObjectDatabase.GetById(727).gameObject; GlitchedTable1Component.willDefinitelyExplode = true; GlitchedTable1Component.spawnObjectOnSelfDestruct = true; ExpandShaders.Instance.ApplyGlitchShader(GlitchedTable1Component.GetComponentInChildren <tk2dBaseSprite>(), true, RandomIntervalFloat, RandomDispFloat, RandomDispIntensityFloat, RandomColorProbFloat, RandomColorIntensityFloat); } else { ExpandKickableObject GlitchedTable1Component = GlitchedVerticalTable2.GetComponent <ExpandKickableObject>(); GlitchedTable1Component.SpawnedObject = PickupObjectDatabase.GetById(727).gameObject; GlitchedTable1Component.willDefinitelyExplode = true; GlitchedTable1Component.spawnObjectOnSelfDestruct = true; ExpandShaders.Instance.ApplyGlitchShader(GlitchedTable1Component.GetComponentInChildren <tk2dBaseSprite>(), true, RandomIntervalFloat, RandomDispFloat, RandomDispIntensityFloat, RandomColorProbFloat, RandomColorIntensityFloat); } m_ParentRoom.RegisterInteractable(GlitchedVerticalTable1.GetComponentInChildren <FlippableCover>()); m_ParentRoom.RegisterInteractable(GlitchedVerticalTable2.GetComponentInChildren <FlippableCover>()); m_ParentRoom.RegisterInteractable(GlitchedVerticalTable1.GetComponent <ExpandKickableObject>()); m_ParentRoom.RegisterInteractable(GlitchedVerticalTable2.GetComponent <ExpandKickableObject>()); }
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]); } } } } }