private static void SpawnChests(RoomHandler r)//, Chest chest) { Chest chest = new Chest(); chest = GameManager.Instance.RewardManager.A_Chest; WeightedGameObject wGameObject = new WeightedGameObject(); wGameObject.rawGameObject = chest.gameObject; WeightedGameObjectCollection wGameObjectCollection = new WeightedGameObjectCollection(); wGameObjectCollection.Add(wGameObject); Chest spawnedChest = GameManager.Instance.RewardManager.SpawnTotallyRandomChest(r.GetBestRewardLocation(new IntVector2(2, 1), Dungeonator.RoomHandler.RewardLocationStyle.PlayerCenter, true)); spawnedChest.ForceUnlock(); spawnedChest.overrideMimicChance = 0f; }
void SpawnChest(string[] args) { if (!ArgCount(args, 1, 2)) { return; } Dungeonator.RoomHandler currentRoom = GameManager.Instance.PrimaryPlayer.CurrentRoom; Chest chest; bool glitched = false; string name = args[0].ToLower(); switch (name) { case "brown": case "d": chest = GameManager.Instance.RewardManager.D_Chest; break; case "blue": case "c": chest = GameManager.Instance.RewardManager.C_Chest; break; case "green": case "b": chest = GameManager.Instance.RewardManager.B_Chest; break; case "red": case "a": chest = GameManager.Instance.RewardManager.A_Chest; break; case "black": case "s": chest = GameManager.Instance.RewardManager.S_Chest; break; case "rainbow": case "r": chest = GameManager.Instance.RewardManager.Rainbow_Chest; break; case "glitched": case "g": chest = GameManager.Instance.RewardManager.B_Chest; glitched = true; break; default: Log("Chest type " + args[0] + " doesn't exist! Valid types: brown, blue, green, red, black, rainbow"); return; } WeightedGameObject wGameObject = new WeightedGameObject(); wGameObject.rawGameObject = chest.gameObject; WeightedGameObjectCollection wGameObjectCollection = new WeightedGameObjectCollection(); wGameObjectCollection.Add(wGameObject); int count = 1; float origMimicChance = chest.overrideMimicChance; chest.overrideMimicChance = 0f; if (args.Length > 1) { bool success = int.TryParse(args[1], out count); if (!success) { Log("Second argument must be an integer (number)"); return; } } for (int i = 0; i < count; i++) { Chest spawnedChest = currentRoom.SpawnRoomRewardChest(wGameObjectCollection, currentRoom.GetBestRewardLocation(new IntVector2(2, 1), Dungeonator.RoomHandler.RewardLocationStyle.PlayerCenter, true)); spawnedChest.ForceUnlock(); if (glitched) { spawnedChest.BecomeGlitchChest(); } } chest.overrideMimicChance = origMimicChance; }
public void TeleportToGlitchRoom() { try { PlayerController primaryPlayer = GameManager.Instance.PrimaryPlayer; PlayerController secondaryPlayer = GameManager.Instance.SecondaryPlayer; Dungeon dungeon = GameManager.Instance.Dungeon; ChaosRoomRandomizer roomRandomizer = new ChaosRoomRandomizer(); int SelectedRoomIndex = UnityEngine.Random.Range(0, roomRandomizer.MasterRoomArray.Length); int SelectedCombatRoomIndex = UnityEngine.Random.Range(0, ChaosPrefabs.CustomRoomTable.includedRooms.elements.Count); if (BraveUtility.RandomBool()) { SelectedPrototypeDungeonRoom = Instantiate(roomRandomizer.MasterRoomArray[SelectedRoomIndex]); } else { SelectedPrototypeDungeonRoom = Instantiate(ChaosPrefabs.CustomRoomTable.includedRooms.elements[SelectedCombatRoomIndex].room); } Destroy(roomRandomizer); // roomRandomizer = null; if (SelectedPrototypeDungeonRoom == null) { Invoke("TentacleRelease", 1f); Invoke("TentacleShowPlayer", 1.45f); Invoke("Unfreeze", 2f); return; } if (SelectedPrototypeDungeonRoom.category == PrototypeDungeonRoom.RoomCategory.SECRET) { SelectedPrototypeDungeonRoom.category = PrototypeDungeonRoom.RoomCategory.NORMAL; } SelectedPrototypeDungeonRoom.name = ("Glitched " + SelectedPrototypeDungeonRoom.name); GlitchRoom = ChaosUtility.Instance.AddCustomRuntimeRoom(SelectedPrototypeDungeonRoom); // Spawn Rainbow chest. This room doesn't spawn NPC it seems.(unless player hasn't unlocked it yet? Not likely. Most would have unlocked this one by now) if (GlitchRoom.GetRoomName().ToLower().EndsWith("earlymetashopcell")) { IntVector2 SpecialChestLocation = new IntVector2(10, 14); WeightedGameObject wChestObject = new WeightedGameObject(); Chest RainbowChest = GameManager.Instance.RewardManager.Rainbow_Chest; wChestObject.rawGameObject = RainbowChest.gameObject; WeightedGameObjectCollection wChestObjectCollection = new WeightedGameObjectCollection(); wChestObjectCollection.Add(wChestObject); Chest PlacableChest = GlitchRoom.SpawnRoomRewardChest(wChestObjectCollection, (SpecialChestLocation + GlitchRoom.area.basePosition)); } primaryPlayer.EscapeRoom(PlayerController.EscapeSealedRoomStyle.TELEPORTER, true, GlitchRoom); primaryPlayer.WarpFollowersToPlayer(); Invoke("TentacleRelease", 1f); Invoke("TentacleShowPlayer", 1.45f); Invoke("Unfreeze", 2f); if (GameManager.Instance.CurrentGameType == GameManager.GameType.COOP_2_PLAYER) { GameManager.Instance.GetOtherPlayer(secondaryPlayer).ReuniteWithOtherPlayer(primaryPlayer, false); } } catch (Exception ex) { if (ChaosConsole.debugMimicFlag) { ETGModConsole.Log("[DEBUG] Error! Exception occured while attempting to generate glitch room!", false); ETGModConsole.Log(ex.Message, false); ETGModConsole.Log(ex.Source, false); ETGModConsole.Log(ex.StackTrace, false); ETGModConsole.Log(ex.TargetSite.ToString(), false); Debug.LogException(ex); } Invoke("TentacleRelease", 1f); Invoke("TentacleShowPlayer", 1.45f); Invoke("Unfreeze", 2f); return; } return; }
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]); } } } } }