Skip to content

Commit

Permalink
narrowed down pet summon items, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
direwolf420 committed Apr 25, 2019
1 parent c94ccd8 commit 3fab4e5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
38 changes: 31 additions & 7 deletions PRCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;

namespace PetRenamer
Expand All @@ -15,33 +14,51 @@ public override CommandType Type
}
}

private const string COMMANDNAME = "renamepet";

public override string Command
{
get
{
return "renamepet";
return COMMANDNAME;
}
}

public override string Usage
{
get
{
return "/renamepet newName";
return "/" + COMMANDNAME + " newName";
}
}

public override string Description
{
get
{
return "Set a name or rename the pet item in your mouse. newName = reset -> remove name";
return "Set a name or rename the pet item in your mouse. newName = " + Reset + " -> remove name";
}
}

public string Reset
{
get
{
return "reset";
}
}

public static string CommandStart
{
get
{
return "/" + COMMANDNAME + " ";
}
}

public override void Action(CommandCaller caller, string input, string[] args)
{
if (args.Length < 1) Main.NewText("/renamepet newName");
if (args.Length < 1) Main.NewText(Usage);
else
{
Item item = Main.mouseItem;
Expand All @@ -58,7 +75,7 @@ public override void Action(CommandCaller caller, string input, string[] args)
newName += args[i] + ((i != args.Length - 1)?" ": "");
}

if (previousName != "" && newName == "reset")
if (previousName != "" && newName == Reset)
{
petItem.petName = "";
petItem.petOwner = "";
Expand All @@ -84,7 +101,14 @@ public override void Action(CommandCaller caller, string input, string[] args)
}
else
{
Main.NewText(item.Name + "not a valid item!", Color.OrangeRed);
if (item.type > 0)
{
Main.NewText(item.Name + " is not a valid item!", Color.OrangeRed);
}
else
{
Main.NewText("No item to rename! Hold a pet summon item in your cursor", Color.OrangeRed);
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions PRPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public override void PostUpdateEquips()
((PetRenamer.IsPetItem(Main.mouseItem) && !Main.chatRelease) ||
MouseItemChangedToPetItem))
{
if (!Main.chatText.StartsWith("/renamepet") && Main.chatText.Length == 0)
if (!Main.chatText.StartsWith(PRCommand.CommandStart) && Main.chatText.Length == 0)
{
ChatManager.AddChatText(Main.fontMouseText, "/renamepet ", Vector2.One);
ChatManager.AddChatText(Main.fontMouseText, PRCommand.CommandStart, Vector2.One);
}
}

Expand Down
8 changes: 7 additions & 1 deletion PetRenamer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ class PetRenamer : Mod

public static bool IsPetItem(Item item)
{
return item.type > 0 && (item.shoot != 0 || item.buffType != 0);
bool checkItem = item.type > 0 && item.shoot != 0 && item.buffType != 0;
bool checkBuff = false;
if (checkItem && item.buffType < Main.vanityPet.Length)
{
checkBuff = Main.vanityPet[item.buffType] || Main.lightPet[item.buffType];
}
return checkItem && checkBuff;
}

public override void Load()
Expand Down

0 comments on commit 3fab4e5

Please sign in to comment.