Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuz-zzz authored Jan 31, 2024
1 parent 9db3f42 commit e75f290
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 0 deletions.
102 changes: 102 additions & 0 deletions BothMimics/BothMimics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using Terraria;
using Terraria.ID;
using Terraria.Localization;
using TerrariaApi.Server;
using TShockAPI;


namespace BothMimics
{
[ApiVersion(2, 1)]
public class Plugin : TerrariaPlugin
{
public override string Author => "Mariothedog, updated by Kuz_";

public override string Description => "Lets you summon both crimosn and corruption mimics with commands";

public override string Name => "Both Evil Biome Mimics";

public override Version Version => new(1, 1, 0, 0);

public Plugin(Main game) : base(game) {}


public override void Initialize()
{
Commands.ChatCommands.Add(new Command("tshock.mimic.corrupt", TradeForCorruptMimic, "corruptmimic"));
Commands.ChatCommands.Add(new Command("tshock.mimic.crimson", TradeForCrimsonMimic, "crimsonmimic"));
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}

private bool TryTradeForEvilMimic(TSPlayer tSPlayer, int npcID)
{
int keyOfNightIndex = -1;
Item keyOfNightItem = null;
for (int i = 0; i < NetItem.InventorySlots; i++)
{
Item item = tSPlayer.TPlayer.inventory[i];
if (item.type == ItemID.NightKey)
{
keyOfNightIndex = i;
keyOfNightItem = item;
break;
}
}

if (keyOfNightItem == null)
{
tSPlayer.SendErrorMessage("You do not have a key of night in your inventory!");
return false;
}

keyOfNightItem.stack -= 1;
if (keyOfNightItem.stack == 0)
{
keyOfNightItem.netDefaults(0);
}
NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.Empty, tSPlayer.Index, keyOfNightIndex);

NPC npc = TShock.Utils.GetNPCById(npcID);
bool foundValidTile = false;
var validTileX = 0;
var validTileY = 0;
while (!foundValidTile)
{
TShock.Utils.GetRandomClearTileWithInRange(tSPlayer.TileX, tSPlayer.TileY, 50, 30, out var tileX, out var tileY);
if (Math.Abs(tSPlayer.TileX - tileX) > 5)
{
foundValidTile = true;
validTileX = tileX;
validTileY = tileY;
}
}

NPC.NewNPC(new Terraria.DataStructures.EntitySource_DebugCommand(), validTileX * 16, validTileY * 16, npcID);
return true;
}

private void TradeForCorruptMimic(CommandArgs args)
{
TSPlayer tSPlayer = args.Player;
if (tSPlayer == null) return;

if (!TryTradeForEvilMimic(tSPlayer, NPCID.BigMimicCorruption)) return;

tSPlayer.SendSuccessMessage("A corrupt mimic has been spawned!");
}

private void TradeForCrimsonMimic(CommandArgs args)
{
TSPlayer tSPlayer = args.Player;
if (tSPlayer == null) return;

if (!TryTradeForEvilMimic(tSPlayer, NPCID.BigMimicCrimson)) return;

tSPlayer.SendSuccessMessage("A crimson mimic has been spawned!");
}
}
}
13 changes: 13 additions & 0 deletions BothMimics/BothMimics.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="TShock" Version="5.2.0" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions BothMimics/BothMimics.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34309.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BothMimics", "BothMimics.csproj", "{0666F403-C0D1-4C0D-B991-E294A2CD7CB8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0666F403-C0D1-4C0D-B991-E294A2CD7CB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0666F403-C0D1-4C0D-B991-E294A2CD7CB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0666F403-C0D1-4C0D-B991-E294A2CD7CB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0666F403-C0D1-4C0D-B991-E294A2CD7CB8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {96144AED-9279-4ED6-ADF1-4C12EEAD996D}
EndGlobalSection
EndGlobal

0 comments on commit e75f290

Please sign in to comment.