fix(types): Fixes casting spell by type and [Add keyword search (#668)
* Fixes `[cast` * Fixes `[add` search
This commit is contained in:
parent
4bad733366
commit
ebac984543
3 changed files with 44 additions and 19 deletions
|
|
@ -538,7 +538,7 @@ namespace Server.Commands.Generic
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
e.Mobile.SendGump(new AddGump(e.Mobile, match, 0, AddGump.Match(match).ToArray(), true));
|
e.Mobile.SendGump(new AddGump(e.Mobile, match, 0, AddGump.Match(match), true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -112,14 +112,14 @@ namespace Server.Gumps
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
types = Match(val).ToArray();
|
types = Match(val);
|
||||||
explicitSearch = true;
|
explicitSearch = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
e.Mobile.SendGump(new AddGump(e.Mobile, val, 0, types, explicitSearch));
|
e.Mobile.SendGump(new AddGump(e.Mobile, val, 0, types, explicitSearch));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Match(string match, Type[] types, List<Type> results)
|
private static void Match(string match, Type[] types, HashSet<Type> results)
|
||||||
{
|
{
|
||||||
if (match.Length == 0)
|
if (match.Length == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -128,31 +128,44 @@ namespace Server.Gumps
|
||||||
|
|
||||||
match = match.ToLower();
|
match = match.ToLower();
|
||||||
|
|
||||||
for (var i = 0; i < types.Length; ++i)
|
for (var i = 0; i < types.Length; i++)
|
||||||
{
|
{
|
||||||
var t = types[i];
|
var t = types[i];
|
||||||
|
|
||||||
if ((typeofMobile.IsAssignableFrom(t) || typeofItem.IsAssignableFrom(t)) &&
|
if (!(typeofMobile.IsAssignableFrom(t) || typeofItem.IsAssignableFrom(t)) ||
|
||||||
t.Name.InsensitiveContains(match) && !results.Contains(t))
|
!t.Name.InsensitiveContains(match) || results.Contains(t))
|
||||||
{
|
{
|
||||||
var ctors = t.GetConstructors();
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
for (var j = 0; j < ctors.Length; ++j)
|
var ctors = t.GetConstructors();
|
||||||
|
|
||||||
|
for (var j = 0; j < ctors.Length; j++)
|
||||||
|
{
|
||||||
|
var ctor = ctors[j];
|
||||||
|
var isEmptyCtor = true;
|
||||||
|
var paramsList = ctor.GetParameters();
|
||||||
|
for (var k = 0; k < paramsList.Length; k++)
|
||||||
{
|
{
|
||||||
if (ctors[j].GetParameters().Length == 0 &&
|
if (!paramsList[k].HasDefaultValue)
|
||||||
ctors[j].IsDefined(typeof(ConstructibleAttribute), false))
|
|
||||||
{
|
{
|
||||||
results.Add(t);
|
isEmptyCtor = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isEmptyCtor && ctors[j].IsDefined(typeof(ConstructibleAttribute), false))
|
||||||
|
{
|
||||||
|
results.Add(t);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Type> Match(string match)
|
public static Type[] Match(string match)
|
||||||
{
|
{
|
||||||
var results = new List<Type>();
|
var results = new HashSet<Type>();
|
||||||
Type[] types;
|
Type[] types;
|
||||||
|
|
||||||
var asms = AssemblyHandler.Assemblies;
|
var asms = AssemblyHandler.Assemblies;
|
||||||
|
|
@ -166,9 +179,20 @@ namespace Server.Gumps
|
||||||
types = AssemblyHandler.GetTypeCache(Core.Assembly).Types;
|
types = AssemblyHandler.GetTypeCache(Core.Assembly).Types;
|
||||||
Match(match, types, results);
|
Match(match, types, results);
|
||||||
|
|
||||||
results.Sort(new TypeNameComparer());
|
if (results.Count == 0)
|
||||||
|
{
|
||||||
|
return Array.Empty<Type>();
|
||||||
|
}
|
||||||
|
|
||||||
return results;
|
var finalResults = new Type[results.Count];
|
||||||
|
var index = 0;
|
||||||
|
foreach (var t in results)
|
||||||
|
{
|
||||||
|
finalResults[index++] = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
Array.Sort(finalResults, TypeNameComparer.Instance);
|
||||||
|
return finalResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnResponse(NetState sender, RelayInfo info)
|
public override void OnResponse(NetState sender, RelayInfo info)
|
||||||
|
|
@ -189,7 +213,7 @@ namespace Server.Gumps
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
from.SendGump(new AddGump(from, match, 0, Match(match).ToArray(), true));
|
from.SendGump(new AddGump(from, match, 0, Match(match), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -234,6 +258,7 @@ namespace Server.Gumps
|
||||||
|
|
||||||
private class TypeNameComparer : IComparer<Type>
|
private class TypeNameComparer : IComparer<Type>
|
||||||
{
|
{
|
||||||
|
public static readonly TypeNameComparer Instance = new();
|
||||||
public int Compare(Type x, Type y) => string.CompareOrdinal(x?.Name, y?.Name);
|
public int Compare(Type x, Type y) => string.CompareOrdinal(x?.Name, y?.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -156,9 +156,9 @@ namespace Server.Spells
|
||||||
|
|
||||||
for (var i = 0; i < m_CircleNames.Length; ++i)
|
for (var i = 0; i < m_CircleNames.Length; ++i)
|
||||||
{
|
{
|
||||||
var t =
|
var t = name.InsensitiveEndsWith("spell") ?
|
||||||
AssemblyHandler.FindTypeByName($"Server.Spells.{m_CircleNames[i]}.{name}") ??
|
AssemblyHandler.FindTypeByFullName($"Server.Spells.{m_CircleNames[i]}.{name}") :
|
||||||
AssemblyHandler.FindTypeByName($"Server.Spells.{m_CircleNames[i]}.{name}Spell");
|
AssemblyHandler.FindTypeByFullName($"Server.Spells.{m_CircleNames[i]}.{name}Spell");
|
||||||
|
|
||||||
if (t?.IsSubclassOf(typeof(SpecialMove)) == false)
|
if (t?.IsSubclassOf(typeof(SpecialMove)) == false)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue