|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using FunkEngine; |
| 4 | +using Godot; |
| 5 | + |
| 6 | +public class MapLevels |
| 7 | +{ |
| 8 | + public struct MapConfig |
| 9 | + { |
| 10 | + public int Width { get; private set; } |
| 11 | + public int Height { get; private set; } |
| 12 | + public int Paths { get; private set; } |
| 13 | + |
| 14 | + /// <summary> |
| 15 | + /// Rooms that exist at set levels, only one room can be set per y-level. |
| 16 | + /// </summary> |
| 17 | + public Dictionary<int, Stages> SetRooms { get; private set; } = |
| 18 | + new() |
| 19 | + { |
| 20 | + { 0, Stages.Battle }, //The first, e.g. y = 0 room, should always be a battle. |
| 21 | + }; |
| 22 | + |
| 23 | + /// <summary> |
| 24 | + /// Adds a set room type to be generated guaranteed. Additional entries in the same y-level are ignored. |
| 25 | + /// This ignores minimum y-heights. |
| 26 | + /// </summary> |
| 27 | + /// <param name="height">The y-level of the rooms</param> |
| 28 | + /// <param name="roomType">The room type to be set.</param> |
| 29 | + public MapConfig AddSetRoom(int height, Stages roomType) |
| 30 | + { |
| 31 | + SetRooms.TryAdd(height, roomType); |
| 32 | + return this; |
| 33 | + } |
| 34 | + |
| 35 | + public const int NumStages = 2; |
| 36 | + |
| 37 | + public static readonly Stages[] StagsToRoll = new[] { Stages.Battle, Stages.Chest }; |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// The odds for each stage to appear in a non-set room position. |
| 41 | + /// </summary> |
| 42 | + public float[] StageOdds = new float[2]; |
| 43 | + |
| 44 | + public MapConfig(int width, int height, int paths, float[] odds) |
| 45 | + { |
| 46 | + Width = width; |
| 47 | + Height = height; |
| 48 | + Paths = paths; |
| 49 | + for (int i = 0; i < NumStages; i++) |
| 50 | + { |
| 51 | + StageOdds[i] = odds[i]; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// Rooms that exist at set levels, only one room can be set per y-level. |
| 57 | + /// </summary> |
| 58 | + public Dictionary<Stages, int> MinHeights { get; private set; } = new(); |
| 59 | + |
| 60 | + /// <summary> |
| 61 | + /// Adds a minimum y-height for a room type. Can only have one set per room type |
| 62 | + /// </summary> |
| 63 | + /// <param name="height">The y-level of the room type</param> |
| 64 | + /// <param name="roomType">The room type to be set.</param> |
| 65 | + public MapConfig AddMinHeight(Stages roomType, int height) |
| 66 | + { |
| 67 | + MinHeights.TryAdd(roomType, height); |
| 68 | + return this; |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + private MapLevels( |
| 73 | + int id, |
| 74 | + MapConfig config, |
| 75 | + int[] battleSongs, |
| 76 | + int[] eliteSongs, |
| 77 | + int[] bossSongs, |
| 78 | + int nextLevelId = -1, |
| 79 | + string backgroundPath = "res://SharedAssets/BackGround_Full.png" |
| 80 | + ) |
| 81 | + { |
| 82 | + Id = id; |
| 83 | + CurMapConfig = config; |
| 84 | + NormalBattles = battleSongs; |
| 85 | + EliteBattles = eliteSongs; |
| 86 | + BossBattles = bossSongs; |
| 87 | + NextLevel = nextLevelId; |
| 88 | + BackgroundPath = backgroundPath; |
| 89 | + } |
| 90 | + |
| 91 | + public int Id { get; private set; } |
| 92 | + public string BackgroundPath { get; private set; } |
| 93 | + private MapConfig CurMapConfig; |
| 94 | + private int NextLevel; |
| 95 | + |
| 96 | + //These tie into the Scribe SongDictionary |
| 97 | + public int[] NormalBattles { get; private set; } |
| 98 | + public int[] EliteBattles { get; private set; } |
| 99 | + public int[] BossBattles { get; private set; } |
| 100 | + |
| 101 | + #region Preset Levels |
| 102 | + private static readonly MapConfig FirstMapConfig = new MapConfig(7, 6, 3, [10, 1]) |
| 103 | + .AddSetRoom(3, Stages.Chest) |
| 104 | + .AddMinHeight(Stages.Chest, 2); |
| 105 | + |
| 106 | + private static readonly MapConfig TutorialMapConfig = new MapConfig(1, 2, 1, [10, 0]); |
| 107 | + |
| 108 | + private static readonly MapLevels[] PresetLevels = new[] |
| 109 | + { |
| 110 | + new MapLevels(0, TutorialMapConfig, [0], [], [3], 1), |
| 111 | + new MapLevels(1, FirstMapConfig, [1, 2, 3], [], [0], -1), |
| 112 | + }; |
| 113 | + #endregion |
| 114 | + |
| 115 | + public MapConfig GetCurrentConfig() |
| 116 | + { |
| 117 | + return CurMapConfig; |
| 118 | + } |
| 119 | + |
| 120 | + public bool HasMoreMaps() |
| 121 | + { |
| 122 | + return NextLevel != -1; |
| 123 | + } |
| 124 | + |
| 125 | + public MapLevels GetNextLevel() |
| 126 | + { |
| 127 | + return !HasMoreMaps() ? null : PresetLevels[NextLevel]; |
| 128 | + } |
| 129 | + |
| 130 | + public static MapLevels GetLevelFromId(int id) |
| 131 | + { |
| 132 | + return PresetLevels[id]; |
| 133 | + } |
| 134 | +} |
0 commit comments