diff --git a/YAMS-LIB/Program.cs b/YAMS-LIB/Program.cs index 8101f7a..4713d83 100644 --- a/YAMS-LIB/Program.cs +++ b/YAMS-LIB/Program.cs @@ -579,8 +579,6 @@ public static void Main(string am2rPath, string outputAm2rPath, string jsonPath) // Set option on whether supers can destroy missile doors if (seedObject.Patches.CanUseSupersOnMissileDoors) characterVarsCode.ReplaceGMLInCode("global.canUseSupersOnMissileDoors = 0", "global.canUseSupersOnMissileDoors = 1"); - // TODO: For the future, with room rando, go through each door and modify where it leads to - // Add in-game Hints AddInGameHints.Apply(gmData, decompileContext, seedObject); @@ -590,6 +588,9 @@ public static void Main(string am2rPath, string outputAm2rPath, string jsonPath) // Pipe rando PipeRando.Apply(gmData, decompileContext, seedObject); + // Entrance rando + EntranceRando.Apply(gmData, decompileContext, seedObject); + // Make Bosses now spawns PB drops on death gmData.Code.ByName("gml_Script_spawn_many_powerups").ReplaceGMLInCode("if ((global.hasBombs == 0 && global.maxpbombs > 0) || (oControl.mod_insanitymode == 1 && global.maxpbombs > 0))", "if (global.maxpbombs > 0)"); diff --git a/YAMS-LIB/SeedObject.cs b/YAMS-LIB/SeedObject.cs index 1825030..ea25c98 100644 --- a/YAMS-LIB/SeedObject.cs +++ b/YAMS-LIB/SeedObject.cs @@ -34,6 +34,10 @@ public class SeedObject [JsonPropertyName("pipes")] public Dictionary PipeObjects = new Dictionary(); + [JsonInclude] + [JsonPropertyName("entrances")] + public Dictionary EntranceObjects = new Dictionary(); + [JsonInclude] [JsonPropertyName("starting_items")] public Dictionary StartingItems = new Dictionary(); @@ -670,6 +674,21 @@ public class PipeObject public string Room = ""; } +public class EntranceObject +{ + [JsonInclude] + [JsonPropertyName("dest_id")] + public uint DestEntranceID; + + [JsonInclude] + [JsonPropertyName("dest_direction")] + public DoorFacingDirection Direction; + + [JsonInclude] + [JsonPropertyName("dest_room")] + public string Room = ""; +} + public struct Coordinate { [JsonInclude] diff --git a/YAMS-LIB/patches/EntranceRando.cs b/YAMS-LIB/patches/EntranceRando.cs new file mode 100644 index 0000000..a9d389f --- /dev/null +++ b/YAMS-LIB/patches/EntranceRando.cs @@ -0,0 +1,75 @@ +using UndertaleModLib; +using UndertaleModLib.Decompiler; +using UndertaleModLib.Models; + +namespace YAMS_LIB.patches; + +public class EntranceRando +{ + public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileContext, SeedObject seedObject) + { + foreach (var entrance in seedObject.EntranceObjects) + { + foreach (UndertaleRoom? room in gmData.Rooms) + { + foreach (UndertaleRoom.GameObject? sourceEntrance in room.GameObjects) + { + if (sourceEntrance.InstanceID != entrance.Key) continue; + + if (entrance.Value.Direction == DoorFacingDirection.Invalid) throw new NotSupportedException("Entrance must have a valid direction"); + + var targetRoom = gmData.Rooms.ByName(entrance.Value.Room); + var targetEntrance = targetRoom.GameObjects.ByInstanceID(entrance.Value.DestEntranceID); + + int xMod = 0; + int yMod = 0; + int finalDirection = 0; + int camYMod = 0; + int transX = 0; + int transY = 0; + + switch (entrance.Value.Direction) + { + case DoorFacingDirection.Right: + xMod = 16; + finalDirection = 0; + camYMod = 120; + transX = (targetEntrance.X + 4) % 320; + transY = ((targetEntrance.Y) % 240); + break; + case DoorFacingDirection.Left: + xMod = -16; + finalDirection = 180; + camYMod = -120; + transX = (targetEntrance.X - 4) % 320; + transY = ((targetEntrance.Y) % 240); + break; + // At one point:tm: also implement up and down + } + + int targetX = targetEntrance.X + xMod; + int targetY = targetEntrance.Y + yMod; + + int finalHeight = 64; // TODO: this is a broad assumption for now, change this later. + + int camStartX = targetEntrance.X + (xMod * 10); + + // if less than y = 136, use y = 120, otherwise use y + var camStartY = targetEntrance.Y < 136 ? 120 : targetEntrance.Y; + + sourceEntrance.CreationCode.SubstituteGMLCode($$""" + targetroom = {{targetRoom.Name.Content}} + targetx = {{targetX}} + targety = {{targetY}} + height = {{finalHeight}} + direction = {{finalDirection}} + camstartx = {{camStartX}} + camstarty = {{camStartY}} + transitionx = {{transX}} + transitiony = {{transY}} + """); + } + } + } + } +}