Skip to content

Commit

Permalink
Initial entrance rando.
Browse files Browse the repository at this point in the history
  • Loading branch information
Miepee committed Jul 6, 2024
1 parent 2d65ae5 commit c84b652
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 2 deletions.
5 changes: 3 additions & 2 deletions YAMS-LIB/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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)");

Expand Down
19 changes: 19 additions & 0 deletions YAMS-LIB/SeedObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public class SeedObject
[JsonPropertyName("pipes")]
public Dictionary<uint, PipeObject> PipeObjects = new Dictionary<uint, PipeObject>();

[JsonInclude]
[JsonPropertyName("entrances")]
public Dictionary<uint, EntranceObject> EntranceObjects = new Dictionary<uint, EntranceObject>();

[JsonInclude]
[JsonPropertyName("starting_items")]
public Dictionary<ItemEnum, int> StartingItems = new Dictionary<ItemEnum, int>();
Expand Down Expand Up @@ -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]
Expand Down
75 changes: 75 additions & 0 deletions YAMS-LIB/patches/EntranceRando.cs
Original file line number Diff line number Diff line change
@@ -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}}
""");
}
}
}
}
}

0 comments on commit c84b652

Please sign in to comment.