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]); } } } } }
private void Start() { sprite.HeightOffGround = -7; sprite.UpdateZDepth(); ExpandObjectDatabase objectDatabase = new ExpandObjectDatabase(); Vector3 NoteSpawnPoint = (new Vector3(7, 3) + m_ParentRoom.area.basePosition.ToVector3()); GameObject DeadGuyNote = Instantiate(ExpandPrefabs.PlayerLostRatNote, NoteSpawnPoint, Quaternion.identity); NoteDoer DeadGuyNoteComponent = DeadGuyNote.GetComponent <NoteDoer>(); if (DeadGuyNoteComponent != null) { DeadGuyNoteComponent.stringKey = "We shipwrecked chasing a terrible monster.\n\nManaged to lure and trap it in this weird dungeon full of living bullets...\n\nAlas, I could not slay the beast but managed to trap it in this chamber. I used a teleporter prototype to teleport the key to this chamber far away.\n\nI don't know where it ended up, but I hope no one finds it."; DeadGuyNoteComponent.useAdditionalStrings = false; DeadGuyNoteComponent.alreadyLocalized = true; DeadGuyNoteComponent.name = "Dead Man's Note"; m_ParentRoom.RegisterInteractable(DeadGuyNoteComponent); } Gun m_CachedMutantArmGun = (PickupObjectDatabase.GetById(333) as Gun); GameObject m_GoopInstance1 = new GameObject("Bloodstain 1", typeof(tk2dSprite)) { layer = 0 }; GameObject m_GoopInstance2 = new GameObject("Bloodstain 2", typeof(tk2dSprite)) { layer = 0 }; GameObject m_GoopInstance3 = new GameObject("Bloodstain 3", typeof(tk2dSprite)) { layer = 0 }; GameObject m_GoopInstance4 = new GameObject("Bloodstain 4", typeof(tk2dSprite)) { layer = 0 }; GameObject m_GoopInstance5 = new GameObject("Bloodstain 5", typeof(tk2dSprite)) { layer = 0 }; GameObject m_GoopInstance6 = new GameObject("Bloodstain 6", typeof(tk2dSprite)) { layer = 0 }; m_GoopInstance1.transform.position = (m_ParentRoom.area.basePosition.ToVector3() + new Vector3(13, 2)); m_GoopInstance2.transform.position = (m_ParentRoom.area.basePosition.ToVector3() + new Vector3(33, 5)); m_GoopInstance3.transform.position = (m_ParentRoom.area.basePosition.ToVector3() + new Vector3(40, 2)); m_GoopInstance4.transform.position = (m_ParentRoom.area.basePosition.ToVector3() + new Vector3(48, 3)); m_GoopInstance5.transform.position = (m_ParentRoom.area.basePosition.ToVector3() + new Vector3(57, 5)); m_GoopInstance6.transform.position = (m_ParentRoom.area.basePosition.ToVector3() + new Vector3(58, 2)); m_GoopInstance1.transform.parent = m_ParentRoom.hierarchyParent; m_GoopInstance2.transform.parent = m_ParentRoom.hierarchyParent; m_GoopInstance3.transform.parent = m_ParentRoom.hierarchyParent; m_GoopInstance4.transform.parent = m_ParentRoom.hierarchyParent; m_GoopInstance5.transform.parent = m_ParentRoom.hierarchyParent; m_GoopInstance6.transform.parent = m_ParentRoom.hierarchyParent; GoopDoer[] m_BloodGoopDoers = new GoopDoer[] { m_GoopInstance1.AddComponent <GoopDoer>(), m_GoopInstance2.AddComponent <GoopDoer>(), m_GoopInstance3.AddComponent <GoopDoer>(), m_GoopInstance4.AddComponent <GoopDoer>(), m_GoopInstance5.AddComponent <GoopDoer>(), m_GoopInstance6.AddComponent <GoopDoer>() }; tk2dSprite[] m_DummySprites = new tk2dSprite[] { m_GoopInstance1.GetComponent <tk2dSprite>(), m_GoopInstance2.GetComponent <tk2dSprite>(), m_GoopInstance3.GetComponent <tk2dSprite>(), m_GoopInstance4.GetComponent <tk2dSprite>(), m_GoopInstance5.GetComponent <tk2dSprite>(), m_GoopInstance6.GetComponent <tk2dSprite>(), }; foreach (tk2dSprite sprite in m_DummySprites) { sprite.Collection = m_CachedMutantArmGun.sprite.Collection; sprite.SetSprite(0); sprite.renderer.enabled = false; } foreach (GoopDoer goop in m_BloodGoopDoers) { goop.goopDefinition = m_CachedMutantArmGun.singleModule.projectiles[0].gameObject.GetComponent <GoopModifier>().goopDefinition; goop.positionSource = GoopDoer.PositionSource.SpriteCenter; goop.updateTiming = GoopDoer.UpdateTiming.Always; goop.updateFrequency = 0.05f; goop.isTimed = false; goop.goopTime = 1; goop.updateOnPreDeath = true; goop.updateOnDeath = false; goop.updateOnAnimFrames = true; goop.updateOnCollision = false; goop.updateOnGrounded = false; goop.updateOnDestroy = false; goop.defaultGoopRadius = 1; goop.suppressSplashes = false; goop.goopSizeVaries = true; goop.varyCycleTime = 0.9f; goop.radiusMin = UnityEngine.Random.Range(0.8f, 1); goop.radiusMax = UnityEngine.Random.Range(1.25f, 1.6f); goop.goopSizeRandom = true; goop.UsesDispersalParticles = false; goop.DispersalDensity = 3; goop.DispersalMinCoherency = 0.2f; goop.DispersalMaxCoherency = 1; } }