Merge pull request #398 from stevenh/general-devel

Fix for getting Mythical prefix by name fixes #374
This commit is contained in:
Steven Hartland 2012-02-20 16:26:15 -08:00
commit 14377bea54

View file

@ -29,6 +29,8 @@ namespace TShockAPI
{ {
public class Utils public class Utils
{ {
private readonly static int firstItemPrefix = 1;
private readonly static int lastItemPrefix = 83;
// Utils is a Singleton // Utils is a Singleton
private static readonly Utils instance = new Utils(); private static readonly Utils instance = new Utils();
private Utils() {} private Utils() {}
@ -442,22 +444,32 @@ namespace TShockAPI
{ {
Item item = new Item(); Item item = new Item();
item.SetDefaults(0); item.SetDefaults(0);
for (int i = 1; i < 83; i++) string lowerName = name.ToLower();
{
item.prefix = (byte) i;
if (item.AffixName().Trim() == name)
return new List<int> {i};
}
var found = new List<int>(); var found = new List<int>();
for (int i = 1; i < 83; i++) for (int i = firstItemPrefix; i <= lastItemPrefix; i++)
{ {
try try
{ {
item.prefix = (byte)i; item.prefix = (byte)i;
if (item.AffixName().Trim().ToLower() == name.ToLower()) string trimmed = item.AffixName().Trim();
return new List<int> {i}; if (trimmed == name)
if (item.AffixName().Trim().ToLower().StartsWith(name.ToLower())) {
// Exact match
found.Add(i); found.Add(i);
return found;
}
else
{
string trimmedLower = trimmed.ToLower();
if (trimmedLower == lowerName)
{
// Exact match (caseinsensitive)
found.Add(i);
return found;
}
else if (trimmedLower.StartsWith(lowerName)) // Partial match
found.Add(i);
}
} }
catch catch
{ {
@ -474,7 +486,7 @@ namespace TShockAPI
public List<int> GetPrefixByIdOrName(string idOrName) public List<int> GetPrefixByIdOrName(string idOrName)
{ {
int type = -1; int type = -1;
if (int.TryParse(idOrName, out type) && type > 0 && type < 84) if (int.TryParse(idOrName, out type) && type >= firstItemPrefix && type <= lastItemPrefix)
{ {
return new List<int> {type}; return new List<int> {type};
} }