Skip to content

Commit

Permalink
thorium integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Flashkirby committed Aug 5, 2024
1 parent ff6540d commit 0dff7f0
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 14 deletions.
5 changes: 4 additions & 1 deletion CampingMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

namespace CampingMod
{
partial class CampingMod : Mod {
partial class CampingMod : Mod
{
public static bool ThoriumModLoaded { get { return ModLoader.HasMod("ThoriumMod"); } }

public const string LANG_KEY = "Mods.CampingMod.";

public CampingMod() {
Expand Down
68 changes: 55 additions & 13 deletions Common/SpawnTentMapLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,66 @@ private void MouseOverIcon(ref MapOverlayDrawContext context, ref string text, C
// Click on the map icon
if (Main.mouseLeft && Main.mouseLeftRelease) {

if (!modPlayer.Player.HasUnityPotion()) {
bool teleport = false;
Main.mouseLeftRelease = false;
Main.mapFullscreen = false;

if (!teleport && CampingMod.ThoriumModLoaded) { teleport = TeleportWithModdedItem(modPlayer, "ThoriumMod", "WormHoleMirror"); }

if (!teleport) { teleport = TeleportWithWormholdPotion(modPlayer); }

if (!teleport) {
// Can't use this feature without wormhole potions
CampingMod.PrintInfo("CampTent.CannotTeleportToTentBecauseNotMeetingItemRequirements", Language.GetTextValue("ItemName.WormholePotion"));
}
else {
Main.mouseLeftRelease = false;
Main.mapFullscreen = false;

// Consume wormhole potions
if (modPlayer.TeleportToTent(PlayerSpawnContext.RecallFromItem)) {
modPlayer.Player.TakeUnityPotion();
// Prevent any other wormhole teleports
Main.cancelWormHole = true;
}
}

}

}

private bool TeleportWithWormholdPotion(CampingModPlayer modPlayer)
{
if (modPlayer.Player.HasUnityPotion()) {

// Consume wormhole potions
if (modPlayer.TeleportToTent(PlayerSpawnContext.RecallFromItem)) {
modPlayer.Player.TakeUnityPotion();
// Prevent any other wormhole teleports
Main.cancelWormHole = true;
return true;
}
}
return false;
}

private bool TeleportWithModdedItem(CampingModPlayer modPlayer, string modName, string itemName)
{
if (ModLoader.TryGetMod(modName, out Mod mod) && mod.TryFind(itemName, out ModItem modItem)) {
// equivalent to wormhole potion check, but for this specific item
bool found = false;

foreach( Item i in modPlayer.Player.inventory) {
if (i.type == modItem.Type && i.stack > 0) {
found = true;
break;
}
}

if(!found && modPlayer.Player.useVoidBag()) {
foreach (Item i in modPlayer.Player.bank4.item) {
if (i.type == modItem.Type && i.stack > 0) {
found = true;
break;
}
}
}

if (found) {
modPlayer.TeleportToTent(PlayerSpawnContext.RecallFromItem);
Main.cancelWormHole = true;
return true;
}
}
return false;
}
}
}

0 comments on commit 0dff7f0

Please sign in to comment.