Skip to content
This repository has been archived by the owner on Dec 30, 2024. It is now read-only.

Commit

Permalink
🐛 Fix the Door interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Chasmical committed Jun 12, 2022
1 parent 4d25edc commit e3731b4
Showing 1 changed file with 90 additions and 42 deletions.
132 changes: 90 additions & 42 deletions RogueLibsCore/Interactions/VanillaInteractions/Door.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private static void Patch_Door()

RogueInteractions.CreateProvider<Door>(static h =>
{
if (h.Helper.interactingFar)
if (h.Helper.interactingFar) // hacking remotely
{
if (h.Object.placedDetonatorInitial is 1)
{
Expand All @@ -30,44 +30,73 @@ private static void Patch_Door()
return;
}

// not interactions for automatic and panic room doors
if (h.Object.doorType is "DoorAutomatic" or "DoorPanicRoom") return;

if (h.Object.open)
if (h.Object.open) // if the door's open, add just the implicit "Close" button
{
h.AddImplicitButton("Close", static m =>
{
if (!m.Object.DoorBlocked(false))
if (m.Object.doorCooldown <= 0f && !m.Object.DoorBlocked(false))
m.Object.CloseDoor(m.Agent);
m.StopInteraction();
});
return;
}

// the door's closed, set the stop callback
h.SetStopCallback(static m => m.Agent.SayDialogue("CantOpenDoor"));

if (h.Object.placedDetonatorInitial is 1 && !h.Agent.isHoisting) // if there's a detonator, add the "Disarm" button
{
h.AddButton("AttemptDisarmDoorDetonator", $" ({h.Object.FindDisarmPercentage(false)}%)",
static m => m.StartOperating(2f, true, "DisarmingDetonator"));
return;
}

bool onInside = h.Object.direction is "E" or "W"
? Mathf.Abs(h.Object.doorHelper.tr.position.x - h.Agent.tr.position.x) < 0.5f
: Mathf.Abs(h.Object.doorHelper.tr.position.y - h.Agent.tr.position.y) < 0.5f;

if (!h.Object.locked || onInside)
bool isSpecialLevel = h.gc.levelType is "Tutorial" or "HomeBase";

static void OpenButton(InteractionModel<Door> m)
{
h.AddImplicitButton("Open", static m =>
{
if (m.Object.doorCooldown <= 0f)
m.Object.OpenDoor(m.Agent);
m.StopInteraction();
});
if (m.Object.doorCooldown <= 0f)
m.Object.OpenDoor(m.Agent);
m.StopInteraction();
}

if (!h.Object.locked) return;

if (h.Object.placedDetonatorInitial is 1 && !h.Agent.isHoisting)
if (h.Object.locked) // the door is locked
{
h.AddButton("AttemptDisarmDoorDetonator", $" ({h.Object.FindDisarmPercentage(false)}%)",
static m => m.StartOperating(2f, true, "DisarmingDetonator"));
if (onInside && h.gc.levelShape is 0 && !isSpecialLevel)
{
// if the player's inside of a locked room, add an implicit "Open" button
h.AddImplicitButton("Open", OpenButton);
return;
}
// can't open, the door is locked
}
else if (h.Object.doorType is "DoorNoEntry") // the door leads to a prohibited area
{
if (onInside && h.gc.levelShape is 0 || isSpecialLevel || !h.Object.outsideDoor)
{
// if the player is inside the prohibited area, or if the door is IN the prohibited area
// (in either case we wouldn't want to prompt the player to open the door)
h.AddImplicitButton("Open", OpenButton);
return;
}
h.AddButton("Open", OpenButton); // prompt the player to go into the prohibited area
}
else // some other kind of door
{
h.AddImplicitButton("Open", OpenButton);
return;
}
if (h.Object.prisonObject is 0 && h.gc.levelShape is 0 && h.Object.extraVar is not 7
&& h.gc.levelType is not "Tutorial" and not "HomeBase")

// at this point, the "Open" button either is not present or is explicit

if (h.Object.prisonObject is 0 && h.gc.levelShape is 0 && h.Object.extraVar is not 7 && !isSpecialLevel)
{
h.AddButton("Knock", static m =>
{
Expand All @@ -76,52 +105,71 @@ private static void Patch_Door()
});
}

// add the Door Detonator interaction
InvItem? doorDetonator = h.Agent.inventory.FindItem("DoorDetonator");
if (!h.Object.hasDetonator && doorDetonator is not null && !h.Agent.isHoisting)
{
h.AddButton("PlaceDetonator", $" ({doorDetonator.invItemCount})", static m
=> m.StartOperating("DoorDetonator", 2f, true, "PlacingDetonator"));
}

if (h.Agent.inventory.InvItemList.Exists(i => i.invItemName is "Key" or "KeyCard"
&& (i.chunks.Contains(h.Object.startingChunk)
|| h.Object.startingSector is not 0
&& i.sectors.Contains(h.Object.startingSector))))
{
h.AddButton("UseKey", static m =>
{
m.Object.Unlock();
m.Object.OpenDoor(m.Agent);
m.StopInteraction();
});
}
else
if (h.Object.locked) // if the door's locked, show options to open it
{
if (h.Agent.inventory.HasItem("SkeletonKey"))
if (h.Agent.inventory.InvItemList.Exists(i => i.invItemName is "Key" or "KeyCard"
&& (i.chunks.Contains(h.Object.startingChunk)
|| h.Object.startingSector is not 0
&& i.sectors.Contains(h.Object.startingSector))))
{
h.AddButton("UseSkeletonKey", static m =>
// if there's a key for this specific door, show it as an only option
h.AddButton("UseKey", static m =>
{
m.Object.Unlock();
m.Object.OpenDoor(m.Agent);
m.StopInteraction();
});
}
InvItem? lockpick = h.Agent.inventory.FindItem("Lockpick");
if (lockpick is not null && !h.Agent.isHoisting)
else
{
h.AddButton("UseLockpick", $" ({lockpick.invItemCount})",
static m => m.StartOperating("Lockpick", 2f, true, "Unlocking"));
}
InvItem? crowbar = h.Agent.inventory.FindItem("Crowbar");
if (crowbar is not null && !h.Agent.isHoisting)
{
h.AddButton("UseCrowbar", $" ({crowbar.invItemCount}) -30",
static m => m.StartOperating("Crowbar", 2f, true, "Unlocking"));
// add the Skeleton Key interaction
if (h.Agent.inventory.HasItem("SkeletonKey"))
{
h.AddButton("UseSkeletonKey", static m =>
{
m.Object.Unlock();
m.Object.OpenDoor(m.Agent);
m.StopInteraction();
});
}

// add the Lockpick interaction
InvItem? lockpick = h.Agent.inventory.FindItem("Lockpick");
if (lockpick is not null && !h.Agent.isHoisting)
{
h.AddButton("UseLockpick", $" ({lockpick.invItemCount})",
static m => m.StartOperating("Lockpick", 2f, true, "Unlocking"));
}

// add the Crowbar interaction
InvItem? crowbar = h.Agent.inventory.FindItem("Crowbar");
if (crowbar is not null && !h.Agent.isHoisting)
{
h.AddButton("UseCrowbar", $" ({crowbar.invItemCount}) -30",
static m => m.StartOperating("Crowbar", 2f, true, "Unlocking"));
}
}
}

});

// run the Tutorial trigger separately, to make sure it always runs
RogueInteractions.CreateProvider<Door>(static h =>
{
if (h.Helper.interactingFar || h.Object.justInteractedImmediate) return;

if (h.gc.levelType == "Tutorial")
h.gc.tutorial.InteractedDoor();
});

}
}
}

0 comments on commit e3731b4

Please sign in to comment.