Fix for getting Mythical prefix by name fixes #374
Also optimised processing so it only does one pass instead of two as well as minimising string manipulation functions
This commit is contained in:
parent
d34199b17d
commit
aeab6d9e45
1 changed files with 24 additions and 12 deletions
|
|
@ -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};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue