/// <summary> /// Handle death /// </summary> /// <param name="resultSet">Result set</param> public override void HandleDeath(ResultSet resultSet) { var game = (RetroDungeoneerGame)RB.Game; var pos = owner.e.pos; int attempts = 40; int babyCount = Random.Range(2, 5); while (attempts > 0 && babyCount > 0) { var randomPos = new Vector2i(Random.Range(pos.x - 1, pos.x + 2), Random.Range(pos.y - 1, pos.y + 2)); if (randomPos.x != pos.x || randomPos.y != pos.y) { if (EntityFunctions.GetBlockingEntityAtPos(randomPos).isEmpty&& !game.map.IsBlocked(randomPos)) { var babySlime = EntityFunctions.CreateMonster(MonsterType.SlimeSmall, randomPos); babySlime.e.Move(Vector2i.zero); // Cause map update SoundBank.Instance.SoundPlayDelayed(game.assets.soundSlime, 1.0f, RandomUtils.RandomPitch(0.1f), (babyCount - 1) * 3); babyCount--; } } attempts--; } }
private void PlaceEntities(Rect2i room, int numOfItems, int numOfMonsters) { var mMonsterChances = EntityFunctions.GetMonsterChances(dungeonLevel); var mItemChances = EntityFunctions.GetItemChances(dungeonLevel); // Place monsters var existingMonsterPositions = new List <Vector2i>(); for (int i = 0; i < numOfMonsters; i++) { var randomPos = new Vector2i( Random.Range(room.min.x + 1, room.max.x), Random.Range(room.min.y + 1, room.max.y)); if (!existingMonsterPositions.Contains(randomPos)) { var monsterType = (MonsterType)RandomUtils.RandomChoiceIndex(mMonsterChances); var monster = EntityFunctions.CreateMonster(monsterType, randomPos); if (!monster.isEmpty) { existingMonsterPositions.Add(randomPos); } } } // Place items var existingItemPositions = new List <Vector2i>(); for (int i = 0; i < numOfItems; i++) { var randomPos = new Vector2i( Random.Range(room.min.x + 1, room.max.x), Random.Range(room.min.y + 1, room.max.y)); if (!existingItemPositions.Contains(randomPos)) { var itemType = (ItemType)RandomUtils.RandomChoiceIndex(mItemChances); var item = EntityFunctions.CreateItem(itemType, randomPos); if (!item.isEmpty) { existingItemPositions.Add(randomPos); } } } }
private void MakeForestMap(int mapWidth, int mapHeight, EntityID player) { backgroundColor = new Color32(0x25, 0x8f, 0x4a, 255); mMusic = C.MUSIC_FOREST; var playerEntity = EntityStore.Get(player); if (playerEntity == null) { return; } int width = Random.Range(14, 18); int height = Random.Range(14, 18); int x = (mapWidth / 2) - (width / 2); int y = (mapHeight / 2) - (height / 2); var newRoom = new Rect2i(x, y, width, height); CreateRoom(newRoom, RoomShape.EllipseFuzzy); var roomCenter = newRoom.center; int randExit = Random.Range(0, 4); Vector2i blockadePos = Vector2i.zero; Vector2i thugPos = Vector2i.zero; Vector2i gameExitPos = Vector2i.zero; Vector2i gameExitDir = Vector2i.zero; if (randExit == 0) { CreateHTunnel(roomCenter.x, 0, roomCenter.y); blockadePos = new Vector2i(roomCenter.x - (newRoom.width / 2) - 2, roomCenter.y); gameExitPos = blockadePos; gameExitPos.x -= 3; gameExitDir = new Vector2i(-1, 0); thugPos = blockadePos; thugPos.x += 4; } else if (randExit == 1) { CreateHTunnel(roomCenter.x, mapWidth - 1, roomCenter.y); blockadePos = new Vector2i(roomCenter.x + (newRoom.width / 2) + 2, roomCenter.y); gameExitPos = blockadePos; gameExitPos.x += 3; gameExitDir = new Vector2i(1, 0); thugPos = blockadePos; thugPos.x -= 4; } else if (randExit == 2) { CreateVTunnel(0, roomCenter.y, roomCenter.x); blockadePos = new Vector2i(roomCenter.x, roomCenter.y - (newRoom.height / 2) - 2); gameExitPos = blockadePos; gameExitPos.y -= 3; gameExitDir = new Vector2i(0, -1); thugPos = blockadePos; thugPos.y += 4; } else if (randExit == 3) { CreateVTunnel(mapHeight - 1, roomCenter.y, roomCenter.x); blockadePos = new Vector2i(roomCenter.x, roomCenter.y + (newRoom.height / 2) + 2); gameExitPos = blockadePos; gameExitPos.y += 3; gameExitDir = new Vector2i(0, 1); thugPos = blockadePos; thugPos.y -= 4; } // This is the first room, put the player in the center of it playerEntity.pos = RandomUtils.RandomRectPerimeterPos(new Rect2i(roomCenter.x - 1, roomCenter.y - 1, 3, 3)); EntityID thug = EntityID.empty; if (dungeonLevel == 0) { thug = EntityFunctions.CreateMonster(MonsterType.InvincibleThug, thugPos); EntityFunctions.CreateMonster(MonsterType.InvincibleBlockade, blockadePos); } else { thug = EntityFunctions.CreateMonster(MonsterType.Thug, thugPos); EntityFunctions.CreateMonster(MonsterType.Blockade, blockadePos); while (gameExitPos.x > 0 && gameExitPos.y > 0 && gameExitPos.x < size.width && gameExitPos.y < size.height) { EntityFunctions.CreateInteractable(InteractableType.GameExit, gameExitPos); gameExitPos += gameExitDir; } } // Give thug a dagger and armor var dagger = EntityFunctions.CreateItem(ItemType.Dagger, new Vector2i(-1, -1)); thug.e.inventory = new Inventory(1); thug.e.equipment = new Equipment(); thug.e.equipment.equipment[(int)dagger.e.equippable.slot] = dagger; var armor = EntityFunctions.CreateItem(ItemType.LeatherArmor, new Vector2i(-1, -1)); thug.e.equipment.equipment[(int)armor.e.equippable.slot] = armor; var well = EntityFunctions.CreateInteractable(InteractableType.Well, new Vector2i(roomCenter.x, roomCenter.y + 2)); well.e.stairs = new Stairs(dungeonLevel + 1); if (dungeonLevel == 0) { well.e.stairs.type = Stairs.StairType.WELL; } else { well.e.stairs.type = Stairs.StairType.WELL_CLOSED; } UpdateAllEntityMapPositions(); BeautifyForestMap(); RecomputeFov(player, C.FOV_RADIUS); var game = (RetroDungeoneerGame)RB.Game; var options = new List <SceneMessage.MessageBoxOption>(); options.Add(new SceneMessage.MessageBoxOption(C.FSTR.Set("Continue"), CloseMessageBox)); if (dungeonLevel == 0) { C.FSTR.Set(C.STR_COLOR_DIALOG); C.FSTR.Append("You've been travelling through the forest for hours and decide to rest at a nearby clearing."); C.FSTR.Append("\n\n"); C.FSTR.Append("As you settle down a man appears behind you. He swings his sword at a rope tied to a tree beside him. Branches and debris fall onto the path blocking your only exit. It appears you've been ambushed."); C.FSTR.Append("\n\n"); C.FSTR.Append(C.STR_COLOR_NAME); C.FSTR.Append("\"I'll take what you're carrying, once I'm done carving you up!\"").Append(C.STR_COLOR_DIALOG).Append(" the brigand says with a grimace."); C.FSTR.Append("\n\n"); C.FSTR.Append("Your eyes dart to an old well in the middle of the clearing. Your options seem clear... jump down the well, or die here."); game.ShowMessageBox( C.FSTR2.Set("Trapped"), C.FSTR, options); } else { C.FSTR.Set(C.STR_COLOR_DIALOG); C.FSTR.Append("You open your eyes, the swirling portal closes behind you. You find yourself back where it all started, in the forest clearing."); C.FSTR.Append("\n\n"); C.FSTR.Append("The brigand who ambushed you is still here, preparing his trap for the next victim."); C.FSTR.Append("\n\n"); C.FSTR.Append(C.STR_COLOR_NAME); C.FSTR.Append("\"How did you... nevermind, lets finish what we started!\"").Append(C.STR_COLOR_DIALOG).Append(" he says, startled by your sudden appearance."); C.FSTR.Append("\n\n"); C.FSTR.Append("You tighten your grip on your weapon, you won't be jumping into the well this time..."); game.ShowMessageBox( C.FSTR2.Set("A Sudden Return"), C.FSTR, options); } }
/// <summary> /// Make test final boss room /// </summary> /// <param name="room">Room rect</param> public void MakeTestBossRoom(Rect2i room) { var boss = EntityFunctions.CreateMonster(MonsterType.Golem, new Vector2i(room.center.x, room.center.y - (room.height / 4))); boss.e.fighter.hp = 1; }
/// <summary> /// Make final boss room /// </summary> /// <param name="room">Room rect</param> public void MakeBossRoom(Rect2i room) { EntityFunctions.CreateMonster(MonsterType.Golem, new Vector2i(room.center.x, room.center.y - (room.height / 4))); }