fix: Cleans up FindItems and removes allocations (#1516)
This commit is contained in:
parent
a4cabe2fa4
commit
d77dac9516
17 changed files with 105 additions and 127 deletions
|
|
@ -141,7 +141,7 @@ namespace Server.Engines.Craft
|
|||
|
||||
if (from.Backpack != null)
|
||||
{
|
||||
foreach (var item in from.Backpack.FindItemsByType())
|
||||
foreach (var item in from.Backpack.FindItems())
|
||||
{
|
||||
if (resourceType.IsInstanceOfType(item))
|
||||
{
|
||||
|
|
@ -186,7 +186,7 @@ namespace Server.Engines.Craft
|
|||
|
||||
if (from.Backpack != null)
|
||||
{
|
||||
foreach (var item in from.Backpack.FindItemsByType())
|
||||
foreach (var item in from.Backpack.FindItems())
|
||||
{
|
||||
if (resourceType.IsInstanceOfType(item))
|
||||
{
|
||||
|
|
@ -266,7 +266,7 @@ namespace Server.Engines.Craft
|
|||
if (from.Backpack != null)
|
||||
{
|
||||
var type = subResource.ItemType;
|
||||
foreach (var item in from.Backpack.FindItemsByType())
|
||||
foreach (var item in from.Backpack.FindItems())
|
||||
{
|
||||
if (type.IsInstanceOfType(item))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -530,23 +530,20 @@ namespace Server.Engines.Craft
|
|||
|
||||
public int GetQuantity(Container cont, Type[] types)
|
||||
{
|
||||
var items = cont.FindItemsByType(types);
|
||||
|
||||
var amount = 0;
|
||||
|
||||
for (var i = 0; i < items.Count; ++i)
|
||||
foreach (var item in cont.FindItems())
|
||||
{
|
||||
if (items[i] is not IHasQuantity hq)
|
||||
if (!item.InTypeList(types))
|
||||
{
|
||||
amount += items[i].Amount;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((hq as BaseBeverage)?.Content != RequiredBeverage)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item is not IHasQuantity hq)
|
||||
{
|
||||
amount += item.Amount;
|
||||
}
|
||||
else if ((hq as BaseBeverage)?.Content == RequiredBeverage)
|
||||
{
|
||||
amount += hq.Quantity;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ namespace Server.Engines.MLQuests.Objectives
|
|||
}
|
||||
|
||||
var total = 0;
|
||||
foreach (var item in pack.FindItemsByType(false))
|
||||
foreach (var item in pack.FindItems(false))
|
||||
{
|
||||
if (ClaimTypePredicate(item) && item.QuestItem && Objective.CheckItem(item))
|
||||
{
|
||||
|
|
@ -135,7 +135,7 @@ namespace Server.Engines.MLQuests.Objectives
|
|||
return;
|
||||
}
|
||||
|
||||
foreach (var item in pack.FindItemsByType(false))
|
||||
foreach (var item in pack.FindItems(false))
|
||||
{
|
||||
// does another quest still need this item? (OSI just unmarks everything)
|
||||
if (ClaimTypePredicate(item) &&
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ namespace Server.Engines.MLQuests.Objectives
|
|||
}
|
||||
|
||||
var total = 0;
|
||||
foreach (var item in pack.FindItemsByType(false))
|
||||
foreach (var item in pack.FindItems(false))
|
||||
{
|
||||
if (ClaimTypePredicate(item))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -430,9 +430,7 @@ namespace Server.Engines.Plants
|
|||
return null;
|
||||
}
|
||||
|
||||
var items = from.Backpack.FindItemsByType(new[] { typeof(BasePotion), typeof(PotionKeg) });
|
||||
|
||||
foreach (var item in items)
|
||||
foreach (var item in from.Backpack.FindItems())
|
||||
{
|
||||
if (item is BasePotion potion)
|
||||
{
|
||||
|
|
@ -441,14 +439,9 @@ namespace Server.Engines.Plants
|
|||
return potion;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (item is PotionKeg keg && keg.Held > 0 && Array.IndexOf(effects, keg.Type) >= 0)
|
||||
{
|
||||
var keg = (PotionKeg)item;
|
||||
|
||||
if (keg.Held > 0 && Array.IndexOf(effects, keg.Type) >= 0)
|
||||
{
|
||||
return keg;
|
||||
}
|
||||
return keg;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -225,32 +225,19 @@ namespace Server.Items
|
|||
return true;
|
||||
}
|
||||
|
||||
return IsInTypeList(t, TreasuresOfTokuno.TokunoDyable)
|
||||
|| IsInTypeList(t, TreasuresOfTokuno.LesserArtifactsTotal)
|
||||
|| IsInTypeList(t, TreasuresOfTokuno.GreaterArtifacts)
|
||||
|| IsInTypeList(t, DemonKnight.ArtifactRarity10)
|
||||
|| IsInTypeList(t, DemonKnight.ArtifactRarity11)
|
||||
|| IsInTypeList(t, MondainsLegacy.Artifacts)
|
||||
|| IsInTypeList(t, StealableArtifacts.TypesOfEntries)
|
||||
|| IsInTypeList(t, Paragon.Artifacts)
|
||||
|| IsInTypeList(t, Leviathan.Artifacts)
|
||||
|| IsInTypeList(t, TreasureMapChest.Artifacts)
|
||||
|| IsInTypeList(t, m_Replicas)
|
||||
|| IsInTypeList(t, m_DyableHeritageItems)
|
||||
|| IsInTypeList(t, m_Glasses);
|
||||
}
|
||||
|
||||
private static bool IsInTypeList(Type t, Type[] list)
|
||||
{
|
||||
for (var i = 0; i < list.Length; i++)
|
||||
{
|
||||
if (list[i].IsAssignableFrom(t))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return t.InTypeList(TreasuresOfTokuno.TokunoDyable)
|
||||
|| t.InTypeList(TreasuresOfTokuno.LesserArtifactsTotal)
|
||||
|| t.InTypeList(TreasuresOfTokuno.GreaterArtifacts)
|
||||
|| t.InTypeList(DemonKnight.ArtifactRarity10)
|
||||
|| t.InTypeList(DemonKnight.ArtifactRarity11)
|
||||
|| t.InTypeList(MondainsLegacy.Artifacts)
|
||||
|| t.InTypeList(StealableArtifacts.TypesOfEntries)
|
||||
|| t.InTypeList(Paragon.Artifacts)
|
||||
|| t.InTypeList(Leviathan.Artifacts)
|
||||
|| t.InTypeList(TreasureMapChest.Artifacts)
|
||||
|| t.InTypeList(m_Replicas)
|
||||
|| t.InTypeList(m_DyableHeritageItems)
|
||||
|| t.InTypeList(m_Glasses);
|
||||
}
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
|
|
|
|||
|
|
@ -295,7 +295,7 @@ namespace Server.Mobiles
|
|||
|
||||
var buttons = ToTTurnInGump.FindRedeemableItems(pm);
|
||||
|
||||
if (buttons.Count > 0 && !pm.HasGump<ToTTurnInGump>())
|
||||
if (buttons?.Count > 0 && !pm.HasGump<ToTTurnInGump>())
|
||||
{
|
||||
pm.SendGump(new ToTTurnInGump(this, buttons));
|
||||
}
|
||||
|
|
@ -344,16 +344,17 @@ namespace Server.Gumps
|
|||
var pack = m.Backpack;
|
||||
if (pack == null)
|
||||
{
|
||||
return new List<ImageTileButtonInfo>();
|
||||
return null;
|
||||
}
|
||||
|
||||
var buttons = new List<ImageTileButtonInfo>();
|
||||
|
||||
var items = pack.FindItemsByType(TreasuresOfTokuno.LesserArtifactsTotal);
|
||||
|
||||
for (var i = 0; i < items.Count; i++)
|
||||
foreach (var item in pack.FindItems())
|
||||
{
|
||||
var item = items[i];
|
||||
if (!item.InTypeList(TreasuresOfTokuno.LesserArtifactsTotal))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item is ChestOfHeirlooms heirlooms && (!heirlooms.Locked || heirlooms.TrapLevel != 10))
|
||||
{
|
||||
continue;
|
||||
|
|
@ -407,7 +408,7 @@ namespace Server.Gumps
|
|||
|
||||
pm.CloseGump<ToTTurnInGump>(); // Sanity
|
||||
|
||||
if (buttons.Count > 0)
|
||||
if (buttons?.Count > 0)
|
||||
{
|
||||
pm.SendGump(new ToTTurnInGump(m_Collector, buttons));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue