Fixes FindItemsByType and FindItemByType and new override of IsLockedDown and IsSecure by renaming their methods.

This commit is contained in:
Kamron Batman 2018-09-15 15:50:35 -07:00
parent 7321fa1b63
commit a48ebb3a5f
50 changed files with 416 additions and 643 deletions

View file

@ -1108,7 +1108,7 @@ namespace Server.Commands.Generic
} }
foreach (BaseHouse house in BaseHouse.AllHouses) foreach (BaseHouse house in BaseHouse.AllHouses)
if (house.IsSecure(item) || house.IsLockedDown(item)) if (house.HasSecureItem(item) || house.HasLockedDownItem(item))
{ {
e.Mobile.SendGump(new PropertiesGump(e.Mobile, house)); e.Mobile.SendGump(new PropertiesGump(e.Mobile, house));
return; return;

View file

@ -82,7 +82,7 @@ namespace Server.Commands.Generic
size = i; size = i;
} }
parsed.Sort(delegate(BaseExtension a, BaseExtension b) { return a.Order - b.Order; }); parsed.Sort((a, b) => a.Order - b.Order);
AssemblyEmitter emitter = null; AssemblyEmitter emitter = null;

View file

@ -5,7 +5,7 @@ namespace Server.Commands.Generic
{ {
public sealed class LimitExtension : BaseExtension public sealed class LimitExtension : BaseExtension
{ {
public static ExtensionInfo ExtInfo = new ExtensionInfo(80, "Limit", 1, delegate { return new LimitExtension(); }); public static ExtensionInfo ExtInfo = new ExtensionInfo(80, "Limit", 1, () => new LimitExtension());
public override ExtensionInfo Info => ExtInfo; public override ExtensionInfo Info => ExtInfo;

View file

@ -6,7 +6,7 @@ namespace Server.Commands.Generic
{ {
public sealed class SortExtension : BaseExtension public sealed class SortExtension : BaseExtension
{ {
public static ExtensionInfo ExtInfo = new ExtensionInfo(40, "Order", -1, delegate { return new SortExtension(); }); public static ExtensionInfo ExtInfo = new ExtensionInfo(40, "Order", -1, () => new SortExtension());
private IComparer m_Comparer; private IComparer m_Comparer;

View file

@ -4,7 +4,7 @@ namespace Server.Commands.Generic
{ {
public sealed class WhereExtension : BaseExtension public sealed class WhereExtension : BaseExtension
{ {
public static ExtensionInfo ExtInfo = new ExtensionInfo(20, "Where", -1, delegate { return new WhereExtension(); }); public static ExtensionInfo ExtInfo = new ExtensionInfo(20, "Where", -1, () => new WhereExtension());
public override ExtensionInfo Info => ExtInfo; public override ExtensionInfo Info => ExtInfo;

View file

@ -1,5 +1,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Server.Items; using Server.Items;
using Server.Targeting; using Server.Targeting;
@ -39,42 +41,36 @@ namespace Server.Commands.Generic
if (command.ObjectTypes == ObjectTypes.Mobiles) if (command.ObjectTypes == ObjectTypes.Mobiles)
return; // sanity check return; // sanity check
if (!(targeted is Container)) if (!(targeted is Container cont))
{
from.SendMessage("That is not a container."); from.SendMessage("That is not a container.");
else return;
try }
try
{
Extensions ext = Extensions.Parse(from, ref args);
if (!CheckObjectTypes(from, command, ext, out bool items, out bool _))
return;
if (!items)
{ {
Extensions ext = Extensions.Parse(from, ref args); from.SendMessage("This command only works on items.");
return;
bool items, mobiles;
if (!CheckObjectTypes(from, command, ext, out items, out mobiles))
return;
if (!items)
{
from.SendMessage("This command only works on items.");
return;
}
Container cont = (Container)targeted;
Item[] found = cont.FindItemsByType(typeof(Item), true);
ArrayList list = new ArrayList();
for (int i = 0; i < found.Length; ++i)
if (ext.IsValid(found[i]))
list.Add(found[i]);
ext.Filter(list);
RunCommand(from, list, command, args);
}
catch (Exception e)
{
from.SendMessage(e.Message);
} }
List<Item> list = cont.FindItemsByType<Item>().Where(item => ext.IsValid(item)).ToList();
// TODO: Is there a way to avoid using ArrayList?
ext.Filter(new ArrayList(list));
RunCommand(from, list, command, args);
}
catch (Exception e)
{
from.SendMessage(e.Message);
}
} }
} }
} }

View file

@ -304,12 +304,7 @@ namespace Server.Commands
return "The properties have been decreased."; return "The properties have been decreased.";
} }
private static string InternalGetValue(object o, PropertyInfo p) private static string InternalGetValue(object o, PropertyInfo p, PropertyInfo[] chain = null)
{
return InternalGetValue(o, p, null);
}
private static string InternalGetValue(object o, PropertyInfo p, PropertyInfo[] chain)
{ {
Type type = p.PropertyType; Type type = p.PropertyType;

View file

@ -924,9 +924,7 @@ namespace Server.Engines.ConPVP
else else
Hue = 0x84C; Hue = 0x84C;
if (m.Backpack.FindItemByType(typeof(BRBomb), true) is BRBomb b) m.Backpack.FindItemByType<BRBomb>()?.CheckScore(this, m, 7);
b.CheckScore(this, m, 7);
return true; return true;
} }
} }
@ -1487,12 +1485,7 @@ namespace Server.Engines.ConPVP
if (mob?.Backpack == null || GetTeamInfo(mob) == null) if (mob?.Backpack == null || GetTeamInfo(mob) == null)
return false; return false;
Item bomb = mob.Backpack.FindItemByType(typeof(BRBomb), true); return mob.Backpack.FindItemByType<BRBomb>() != null;
if (bomb != null)
return true;
return false;
} }
public void ReturnBomb() public void ReturnBomb()
@ -1606,22 +1599,17 @@ namespace Server.Engines.ConPVP
bool hadBomb = false; bool hadBomb = false;
Item[] bombs = corpse.FindItemsByType(typeof(BRBomb), false); corpse.FindItemsByType<BRBomb>(false).ForEach(bomb =>
for (int i = 0; i < bombs.Length; ++i)
(bombs[i] as BRBomb)?.DropTo(mob, killer);
hadBomb = bombs.Length > 0;
if (mob.Backpack != null)
{ {
bombs = mob.Backpack.FindItemsByType(typeof(BRBomb), false); hadBomb = true;
bomb.DropTo(mob, killer);
});
for (int i = 0; i < bombs.Length; ++i) mob.Backpack?.FindItemsByType<BRBomb>(false).ForEach(bomb =>
(bombs[i] as BRBomb)?.DropTo(mob, killer); {
hadBomb = true;
hadBomb = hadBomb || bombs.Length > 0; bomb.DropTo(mob, killer);
} });
if (killer != null && killer.Player) if (killer != null && killer.Player)
{ {

View file

@ -965,22 +965,17 @@ namespace Server.Engines.ConPVP
bool hadFlag = false; bool hadFlag = false;
Item[] flags = corpse.FindItemsByType(typeof(CTFFlag), false); corpse.FindItemsByType<CTFFlag>(false).ForEach(flag =>
for (int i = 0; i < flags.Length; ++i)
(flags[i] as CTFFlag).DropTo(mob, killer);
hadFlag = hadFlag || flags.Length > 0;
if (mob.Backpack != null)
{ {
flags = mob.Backpack.FindItemsByType(typeof(CTFFlag), false); hadFlag = true;
flag.DropTo(mob, killer);
});
for (int i = 0; i < flags.Length; ++i) mob.Backpack?.FindItemsByType<CTFFlag>(false).ForEach(flag =>
(flags[i] as CTFFlag).DropTo(mob, killer); {
hadFlag = true;
hadFlag = hadFlag || flags.Length > 0; flag.DropTo(mob, killer);
} });
if (killer != null && killer.Player) if (killer != null && killer.Player)
{ {

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Server.Commands; using Server.Commands;
using Server.Factions; using Server.Factions;
using Server.Items; using Server.Items;
@ -337,7 +338,7 @@ namespace Server.Engines.Craft
for (int i = 0; i < types.Length; ++i) for (int i = 0; i < types.Length; ++i)
{ {
items[i] = cont.FindItemsByType(types[i], true); items[i] = cont.FindItemsByType(types[i]);
for (int j = 0; j < items[i].Length; ++j) for (int j = 0; j < items[i].Length; ++j)
if (!(items[i][j] is IHasQuantity hq)) if (!(items[i][j] is IHasQuantity hq))
@ -405,7 +406,7 @@ namespace Server.Engines.Craft
public int GetQuantity(Container cont, Type[] types) public int GetQuantity(Container cont, Type[] types)
{ {
Item[] items = cont.FindItemsByType(types, true); Item[] items = cont.FindItemsByType(types);
int amount = 0; int amount = 0;
@ -530,24 +531,12 @@ namespace Server.Engines.Craft
else else
maxAmount = -1; maxAmount = -1;
Item consumeExtra = null; RecallRune consumeExtra = null;
if (NameNumber == 1041267) if (NameNumber == 1041267)
{ {
// Runebooks are a special case, they need a blank recall rune // Runebooks are a special case, they need a blank recall rune
consumeExtra = ourPack.FindItemsByType<RecallRune>().Find(rune => !rune.Marked);
List<RecallRune> runes = ourPack.FindItemsByType<RecallRune>();
for (int i = 0; i < runes.Count; ++i)
{
RecallRune rune = runes[i];
if (rune != null && !rune.Marked)
{
consumeExtra = rune;
break;
}
}
if (consumeExtra == null) if (consumeExtra == null)
{ {
@ -556,7 +545,7 @@ namespace Server.Engines.Craft
} }
} }
int index = 0; int index;
// Consume ALL // Consume ALL
if (consumeType == ConsumeType.All) if (consumeType == ConsumeType.All)
@ -621,7 +610,8 @@ namespace Server.Engines.Craft
if (index == -1) if (index == -1)
{ {
if (consumeType != ConsumeType.None) consumeExtra?.Delete(); if (consumeType != ConsumeType.None)
consumeExtra?.Delete();
return true; return true;
} }

View file

@ -337,15 +337,9 @@ namespace Server.Factions
int killPoints = pl.KillPoints; int killPoints = pl.KillPoints;
if (mob.Backpack != null) //Ordinarily, through normal faction removal, this will never find any sigils.
{ //Only with a leave delay less than the ReturnPeriod or a Faction Kick/Ban, will this ever do anything
//Ordinarily, through normal faction removal, this will never find any sigils. mob.Backpack?.FindItemsByType<Sigil>().ForEach(sigil => sigil.ReturnHome());
//Only with a leave delay less than the ReturnPeriod or a Faction Kick/Ban, will this ever do anything
Item[] sigils = mob.Backpack.FindItemsByType(typeof(Sigil));
for (int i = 0; i < sigils.Length; ++i)
((Sigil)sigils[i]).ReturnHome();
}
if (pl.RankIndex != -1) if (pl.RankIndex != -1)
{ {
@ -936,43 +930,32 @@ namespace Server.Factions
killer = victim.FindMostRecentDamager(true); killer = victim.FindMostRecentDamager(true);
PlayerState killerState = PlayerState.Find(killer); PlayerState killerState = PlayerState.Find(killer);
Container killerPack = killer?.Backpack;
Container pack = victim.Backpack; victim.Backpack?.FindItemsByType<Sigil>().ForEach(sigil =>
if (pack != null)
{ {
Container killerPack = killer?.Backpack; if (killerState == null || killerPack == null)
Item[] sigils = pack.FindItemsByType(typeof(Sigil));
for (int i = 0; i < sigils.Length; ++i)
{ {
Sigil sigil = (Sigil)sigils[i]; sigil.ReturnHome();
return;
if (killerState != null && killerPack != null)
{
if (killer.GetDistanceToSqrt(victim) > 64)
{
sigil.ReturnHome();
killer.SendLocalizedMessage(1042230); // The sigil has gone back to its home location.
}
else if (Sigil.ExistsOn(killer))
{
sigil.ReturnHome();
killer.SendLocalizedMessage(
1010258); // The sigil has gone back to its home location because you already have a sigil.
}
else if (!killerPack.TryDropItem(killer, sigil, false))
{
sigil.ReturnHome();
killer.SendLocalizedMessage(1010259); // The sigil has gone home because your backpack is full.
}
}
else
{
sigil.ReturnHome();
}
} }
}
if (killer.GetDistanceToSqrt(victim) > 64)
{
sigil.ReturnHome();
killer.SendLocalizedMessage(1042230); // The sigil has gone back to its home location.
}
else if (Sigil.ExistsOn(killer))
{
sigil.ReturnHome();
killer.SendLocalizedMessage(
1010258); // The sigil has gone back to its home location because you already have a sigil.
}
else if (!killerPack.TryDropItem(killer, sigil, false))
{
sigil.ReturnHome();
killer.SendLocalizedMessage(1010259); // The sigil has gone home because your backpack is full.
}
});
if (killerState == null) if (killerState == null)
return; return;
@ -1072,9 +1055,7 @@ namespace Server.Factions
if (1 > Utility.Random(3)) if (1 > Utility.Random(3))
killerState.IsActive = true; killerState.IsActive = true;
int silver = 0; int silver = killerState.Faction.AwardSilver(killer, award * 40);
silver = killerState.Faction.AwardSilver(killer, award * 40);
if (silver > 0) if (silver > 0)
killer.SendLocalizedMessage(1042736, killer.SendLocalizedMessage(1042736,
@ -1129,17 +1110,7 @@ namespace Server.Factions
private static void EventSink_Logout(LogoutEventArgs e) private static void EventSink_Logout(LogoutEventArgs e)
{ {
Mobile mob = e.Mobile; e.Mobile.Backpack?.FindItemsByType<Sigil>().ForEach(sigil => sigil.ReturnHome());
Container pack = mob.Backpack;
if (pack == null)
return;
Item[] sigils = pack.FindItemsByType(typeof(Sigil));
for (int i = 0; i < sigils.Length; ++i)
((Sigil)sigils[i]).ReturnHome();
} }
private static void EventSink_Login(LoginEventArgs e) private static void EventSink_Login(LoginEventArgs e)
@ -1166,17 +1137,7 @@ namespace Server.Factions
return null; return null;
} }
public static Faction Find(Mobile mob) public static Faction Find(Mobile mob, bool inherit = false, bool creatureAllegiances = false)
{
return Find(mob, false, false);
}
public static Faction Find(Mobile mob, bool inherit)
{
return Find(mob, inherit, false);
}
public static Faction Find(Mobile mob, bool inherit, bool creatureAllegiances)
{ {
PlayerState pl = PlayerState.Find(mob); PlayerState pl = PlayerState.Find(mob);
@ -1186,9 +1147,9 @@ namespace Server.Factions
if (inherit && mob is BaseCreature bc) if (inherit && mob is BaseCreature bc)
{ {
if (bc.Controlled) if (bc.Controlled)
return Find(bc.ControlMaster, false); return Find(bc.ControlMaster);
if (bc.Summoned) if (bc.Summoned)
return Find(bc.SummonMaster, false); return Find(bc.SummonMaster);
if (creatureAllegiances && bc is BaseFactionGuard guard) if (creatureAllegiances && bc is BaseFactionGuard guard)
return guard.Faction; return guard.Faction;
if (creatureAllegiances) if (creatureAllegiances)

View file

@ -223,9 +223,7 @@ namespace Server.Factions
public static bool ExistsOn(Mobile mob) public static bool ExistsOn(Mobile mob)
{ {
Container pack = mob.Backpack; return mob.Backpack?.FindItemByType<Sigil>() != null;
return pack?.FindItemByType(typeof(Sigil)) != null;
} }
private void BeginCorrupting(Faction faction) private void BeginCorrupting(Faction faction)

View file

@ -168,25 +168,16 @@ namespace Server.Factions
public bool EquipWeapon() public bool EquipWeapon()
{ {
Container pack = m_Guard.Backpack; Item weapon = m_Guard.Backpack?.FindItemByType<BaseWeapon>();
Item weapon = pack?.FindItemByType(typeof(BaseWeapon)); return weapon != null && m_Guard.EquipItem(weapon);
if (weapon == null)
return false;
return m_Guard.EquipItem(weapon);
} }
public bool StartBandage() public bool StartBandage()
{ {
m_Bandage = null; m_Bandage = null;
Container pack = m_Guard.Backpack; if (m_Guard.Backpack?.FindItemByType<Bandage>() == null)
Item bandage = pack?.FindItemByType(typeof(Bandage));
if (bandage == null)
return false; return false;
m_Bandage = BandageContext.BeginHeal(m_Guard, m_Guard); m_Bandage = BandageContext.BeginHeal(m_Guard, m_Guard);

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Server.Engines.Quests; using Server.Engines.Quests;
using Server.Engines.Quests.Collector; using Server.Engines.Quests.Collector;
using Server.Items; using Server.Items;
@ -198,22 +199,9 @@ namespace Server.Engines.Harvest
public override bool CheckResources(Mobile from, Item tool, HarvestDefinition def, Map map, Point3D loc, bool timed) public override bool CheckResources(Mobile from, Item tool, HarvestDefinition def, Map map, Point3D loc, bool timed)
{ {
Container pack = from.Backpack; return from?.Backpack?.FindItemsByType<SOS>().Any(sos =>
(from.Map == Map.Felucca || from.Map == Map.Trammel) && from.InRange(sos.TargetLocation, 60)) ??
if (pack != null) base.CheckResources(from, tool, def, map, loc, timed);
{
List<SOS> messages = pack.FindItemsByType<SOS>();
for (int i = 0; i < messages.Count; ++i)
{
SOS sos = messages[i];
if ((from.Map == Map.Felucca || from.Map == Map.Trammel) && from.InRange(sos.TargetLocation, 60))
return true;
}
}
return base.CheckResources(from, tool, def, map, loc, timed);
} }
public override Item Construct(Type type, Mobile from) public override Item Construct(Type type, Mobile from)
@ -320,9 +308,7 @@ namespace Server.Engines.Harvest
if (preLoot != null) if (preLoot != null)
{ {
if (preLoot is IShipwreckedItem shipwreckedItem) ((IShipwreckedItem)preLoot).IsShipwreckedItem = true;
shipwreckedItem.IsShipwreckedItem = true;
return preLoot; return preLoot;
} }

View file

@ -28,7 +28,7 @@ namespace Server.Items
if (pm.InRange(GetWorldLocation(), 2)) if (pm.InRange(GetWorldLocation(), 2))
{ {
if (MLQuestSystem.GetContext(pm)?.IsDoingQuest(typeof(UnfadingMemoriesPartOne)) == true && if (MLQuestSystem.GetContext(pm)?.IsDoingQuest(typeof(UnfadingMemoriesPartOne)) == true &&
pm.Backpack.FindItemByType(typeof(PrismaticAmber), false) == null) pm.Backpack.FindItemByType<PrismaticAmber>(false) == null)
{ {
Item amber = new PrismaticAmber(); Item amber = new PrismaticAmber();

View file

@ -152,31 +152,20 @@ namespace Server.Engines.MLQuests.Items
if (!base.CanTeleport(m)) if (!base.CanTeleport(m))
return false; return false;
if (m_TicketType != null) if (m_TicketType == null)
return true;
Container pack = m.Backpack;
Item ticket = pack?.FindItemByType(m_TicketType, false) ?? m.Items.Find(item => m_TicketType.IsInstanceOfType(item));
if (ticket == null)
{ {
Item ticket = null; TextDefinition.SendMessageTo(m, Message);
Container pack = m.Backpack; return false;
if (pack != null)
ticket = pack.FindItemByType(m_TicketType, false); // Check (top level) backpack
if (ticket == null)
foreach (Item item in m.Items) // Check paperdoll
if (m_TicketType.IsInstanceOfType(item))
{
ticket = item;
break;
}
if (ticket == null)
{
TextDefinition.SendMessageTo(m, Message);
return false;
}
(ticket as ITicket)?.OnTicketUsed(m);
} }
(ticket as ITicket)?.OnTicketUsed(m);
return true; return true;
} }

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using Server.Gumps; using Server.Gumps;
using Server.Items; using Server.Items;
using Server.Network; using Server.Network;
@ -310,30 +311,20 @@ namespace Server.Engines.Plants
} }
case 6: // Water case 6: // Water
{ {
Item[] item = from.Backpack.FindItemsByType(typeof(BaseBeverage)); BaseBeverage bev = from.Backpack.FindItemsByType<BaseBeverage>().Find(beverage =>
beverage.IsEmpty && beverage.Pourable && beverage.Content == BeverageType.Water);
bool foundUsableWater = false; if (bev == null)
if (item != null && item.Length > 0)
for (int i = 0; i < item.Length; ++i)
{
BaseBeverage beverage = (BaseBeverage)item[i];
if (!beverage.IsEmpty && beverage.Pourable && beverage.Content == BeverageType.Water)
{
foundUsableWater = true;
m_Plant.Pour(from, beverage);
break;
}
}
if (!foundUsableWater)
{ {
from.Target = new PlantPourTarget(m_Plant); from.Target = new PlantPourTarget(m_Plant);
from.SendLocalizedMessage(1060808, from.SendLocalizedMessage(1060808,
"#" + m_Plant "#" + m_Plant
.GetLocalizedPlantStatus()); // Target the container you wish to use to water the ~1_val~. .GetLocalizedPlantStatus()); // Target the container you wish to use to water the ~1_val~.
} }
else
{
m_Plant.Pour(from, bev);
}
from.SendGump(new MainPlantGump(m_Plant)); from.SendGump(new MainPlantGump(m_Plant));

View file

@ -413,25 +413,17 @@ namespace Server.Engines.Plants
{ {
Mobile from = args.Mobile; Mobile from = args.Mobile;
if (from.Backpack != null) from.Backpack?.FindItemsByType<PlantItem>().ForEach(plant =>
{ {
List<PlantItem> plants = from.Backpack.FindItemsByType<PlantItem>(); if (plant.IsGrowable)
plant.PlantSystem.DoGrowthCheck();
});
foreach (PlantItem plant in plants) from.FindBankNoCreate()?.FindItemsByType<PlantItem>().ForEach(plant =>
if (plant.IsGrowable)
plant.PlantSystem.DoGrowthCheck();
}
BankBox bank = from.FindBankNoCreate();
if (bank != null)
{ {
List<PlantItem> plants = bank.FindItemsByType<PlantItem>(); if (plant.IsGrowable)
plant.PlantSystem.DoGrowthCheck();
foreach (PlantItem plant in plants) });
if (plant.IsGrowable)
plant.PlantSystem.DoGrowthCheck();
}
} }
public static void GrowAll() public static void GrowAll()
@ -443,7 +435,7 @@ namespace Server.Engines.Plants
{ {
PlantItem plant = (PlantItem)plants[i]; PlantItem plant = (PlantItem)plants[i];
if (plant.IsGrowable && plant.RootParent as Mobile == null && now >= plant.PlantSystem.NextGrowth) if (plant.IsGrowable && !(plant.RootParent is Mobile) && now >= plant.PlantSystem.NextGrowth)
plant.PlantSystem.DoGrowthCheck(); plant.PlantSystem.DoGrowthCheck();
} }
} }

View file

@ -90,7 +90,7 @@ namespace Server.Engines.Quests.Necro
if (qs.IsObjectiveInProgress(typeof(FindMardothAboutKronusObjective)) || if (qs.IsObjectiveInProgress(typeof(FindMardothAboutKronusObjective)) ||
qs.IsObjectiveInProgress(typeof(FindWellOfTearsObjective)) || qs.IsObjectiveInProgress(typeof(FindWellOfTearsObjective)) ||
qs.IsObjectiveInProgress(typeof(UseCallingScrollObjective))) qs.IsObjectiveInProgress(typeof(UseCallingScrollObjective)))
return from.Backpack?.FindItemByType(typeof(KronusScroll)) == null; return from.Backpack?.FindItemByType<KronusScroll>() == null;
return false; return false;
} }

View file

@ -106,7 +106,7 @@ namespace Server.Engines.Quests.Ninja
if (qs is EminosUndertakingQuest) if (qs is EminosUndertakingQuest)
if (qs.IsObjectiveInProgress(typeof(GiveZoelNoteObjective))) if (qs.IsObjectiveInProgress(typeof(GiveZoelNoteObjective)))
return from.Backpack?.FindItemByType(typeof(NoteForZoel)) == null; return from.Backpack?.FindItemByType<NoteForZoel>() == null;
return false; return false;
} }
@ -120,7 +120,7 @@ namespace Server.Engines.Quests.Ninja
if (qs is EminosUndertakingQuest) if (qs is EminosUndertakingQuest)
if (qs.IsObjectiveInProgress(typeof(GiveEminoSwordObjective))) if (qs.IsObjectiveInProgress(typeof(GiveEminoSwordObjective)))
return from.Backpack?.FindItemByType(typeof(EminosKatana)) == null; return from.Backpack?.FindItemByType<EminosKatana>() == null;
return false; return false;
} }

View file

@ -147,7 +147,7 @@ namespace Server.Engines.Quests.Ninja
Item katana = null; Item katana = null;
if (player.Backpack != null) if (player.Backpack != null)
katana = player.Backpack.FindItemByType(typeof(EminosKatana)); katana = player.Backpack.FindItemByType<EminosKatana>();
if (katana != null) if (katana != null)
{ {

View file

@ -109,7 +109,7 @@ namespace Server.Engines.Quests.Samurai
if (qs is HaochisTrialsQuest) if (qs is HaochisTrialsQuest)
if (qs.IsObjectiveInProgress(typeof(FifthTrialReturnObjective))) if (qs.IsObjectiveInProgress(typeof(FifthTrialReturnObjective)))
return from.Backpack?.FindItemByType(typeof(HaochisKatana)) == null; return from.Backpack?.FindItemByType<HaochisKatana>() == null;
return false; return false;
} }

View file

@ -117,21 +117,18 @@ namespace Server.Engines.Quests.Samurai
if (obj != null && !obj.Completed) if (obj != null && !obj.Completed)
{ {
Container pack = player.Backpack; HaochisKatana katana = player.Backpack?.FindItemByType<HaochisKatana>();
Item katana = pack?.FindItemByType(typeof(HaochisKatana)); if (katana == null)
if (katana != null) return;
{
katana.Delete();
obj.Complete();
obj = qs.FindObjective(typeof(FifthTrialIntroObjective)); katana.Delete();
if (obj != null && ((FifthTrialIntroObjective)obj).StolenTreasure) obj.Complete();
qs.AddConversation(new SixthTrialIntroConversation(true));
else
qs.AddConversation(new SixthTrialIntroConversation(false));
}
return; obj = qs.FindObjective(typeof(FifthTrialIntroObjective));
if (obj != null && ((FifthTrialIntroObjective)obj).StolenTreasure)
qs.AddConversation(new SixthTrialIntroConversation(true));
else
qs.AddConversation(new SixthTrialIntroConversation(false));
} }
obj = qs.FindObjective(typeof(SixthTrialReturnObjective)); obj = qs.FindObjective(typeof(SixthTrialReturnObjective));

View file

@ -117,7 +117,7 @@ namespace Server.Engines.Quests.Haven
if (qs is UzeraanTurmoilQuest) if (qs is UzeraanTurmoilQuest)
if (qs.IsObjectiveInProgress(typeof(ReturnScrollOfPowerObjective))) if (qs.IsObjectiveInProgress(typeof(ReturnScrollOfPowerObjective)))
return from.Backpack?.FindItemByType(typeof(SchmendrickScrollOfPower)) == null; return from.Backpack?.FindItemByType<SchmendrickScrollOfPower>() == null;
return false; return false;
} }
@ -131,7 +131,7 @@ namespace Server.Engines.Quests.Haven
if (qs is UzeraanTurmoilQuest) if (qs is UzeraanTurmoilQuest)
if (qs.IsObjectiveInProgress(typeof(ReturnFertileDirtObjective))) if (qs.IsObjectiveInProgress(typeof(ReturnFertileDirtObjective)))
return from.Backpack?.FindItemByType(typeof(QuestFertileDirt)) == null; return from.Backpack?.FindItemByType<QuestFertileDirt>() == null;
return false; return false;
} }
@ -145,7 +145,7 @@ namespace Server.Engines.Quests.Haven
if (qs is UzeraanTurmoilQuest) if (qs is UzeraanTurmoilQuest)
if (qs.IsObjectiveInProgress(typeof(ReturnDaemonBloodObjective))) if (qs.IsObjectiveInProgress(typeof(ReturnDaemonBloodObjective)))
return from.Backpack?.FindItemByType(typeof(QuestDaemonBlood)) == null; return from.Backpack?.FindItemByType<QuestDaemonBlood>() == null;
return false; return false;
} }
@ -159,7 +159,7 @@ namespace Server.Engines.Quests.Haven
if (qs is UzeraanTurmoilQuest) if (qs is UzeraanTurmoilQuest)
if (qs.IsObjectiveInProgress(typeof(ReturnDaemonBoneObjective))) if (qs.IsObjectiveInProgress(typeof(ReturnDaemonBoneObjective)))
return from.Backpack?.FindItemByType(typeof(QuestDaemonBone)) == null; return from.Backpack?.FindItemByType<QuestDaemonBone>() == null;
return false; return false;
} }

View file

@ -273,12 +273,7 @@ namespace Server.Engines.Events
{ typeof(WrappedCandy), typeof(Lollipops), typeof(NougatSwirl), typeof(Taffy), typeof(JellyBeans) }; { typeof(WrappedCandy), typeof(Lollipops), typeof(NougatSwirl), typeof(Taffy), typeof(JellyBeans) };
if (TrickOrTreat.CheckMobile(target)) if (TrickOrTreat.CheckMobile(target))
for (int i = 0; i < types.Length; i++) return target.Backpack.FindItemByType(types);
{
Item item = target.Backpack.FindItemByType(types[i]);
if (item != null) return item;
}
return null; return null;
} }

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Multis; using Server.Multis;
using Server.Network; using Server.Network;
@ -503,11 +504,12 @@ namespace Server.Items
private void RecountLiveCreatures() private void RecountLiveCreatures()
{ {
LiveCreatures = 0; LiveCreatures = 0;
List<BaseFish> fish = FindItemsByType<BaseFish>();
foreach (BaseFish f in fish) FindItemsByType<BaseFish>().ForEach(fish =>
if (!f.Dead) {
if (!fish.Dead)
++LiveCreatures; ++LiveCreatures;
});
} }
public void Validate() public void Validate()
@ -895,21 +897,7 @@ namespace Server.Items
public static FishBowl GetEmptyBowl(Mobile from) public static FishBowl GetEmptyBowl(Mobile from)
{ {
if (from?.Backpack == null) return from?.Backpack?.FindItemsByType<FishBowl>().Find(bowl => bowl.Empty);
return null;
Item[] items = from.Backpack.FindItemsByType(typeof(FishBowl));
for (int i = 0; i < items.Length; i++)
if (items[i] is FishBowl)
{
FishBowl bowl = (FishBowl)items[i];
if (bowl.Empty)
return bowl;
}
return null;
} }
private static Type[] m_Decorations = private static Type[] m_Decorations =

View file

@ -64,10 +64,10 @@ namespace Server.Items
BaseHouse house = BaseHouse.FindHouseAt(this); BaseHouse house = BaseHouse.FindHouseAt(this);
if (house?.IsLockedDown(this) == true) if (house?.HasLockedDownItem(this) == true)
{ {
if (dropped is VendorRentalContract || dropped is Container container && if (dropped is VendorRentalContract || dropped is Container container &&
container.FindItemByType(typeof(VendorRentalContract)) != null) container.FindItemByType<VendorRentalContract>() != null)
{ {
from.SendLocalizedMessage(1062492); // You cannot place a rental contract in a locked down container. from.SendLocalizedMessage(1062492); // You cannot place a rental contract in a locked down container.
return false; return false;
@ -99,10 +99,10 @@ namespace Server.Items
BaseHouse house = BaseHouse.FindHouseAt(this); BaseHouse house = BaseHouse.FindHouseAt(this);
if (house?.IsLockedDown(this) == true) if (house?.HasLockedDownItem(this) == true)
{ {
if (item is VendorRentalContract || item is Container container && if (item is VendorRentalContract || item is Container container &&
container.FindItemByType(typeof(VendorRentalContract)) != null) container.FindItemByType<VendorRentalContract>() != null)
{ {
from.SendLocalizedMessage(1062492); // You cannot place a rental contract in a locked down container. from.SendLocalizedMessage(1062492); // You cannot place a rental contract in a locked down container.
return false; return false;

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Engines.Craft; using Server.Engines.Craft;
using Server.Network; using Server.Network;
@ -174,14 +175,7 @@ namespace Server.Items
private void SalvageIngots(Mobile from) private void SalvageIngots(Mobile from)
{ {
Item[] tools = from.Backpack.FindItemsByType(typeof(BaseTool)); if (from.Backpack.FindItemsByType<BaseTool>().All(tool => tool.CraftSystem != DefBlacksmithy.CraftSystem))
bool ToolFound = false;
foreach (Item tool in tools)
if (tool is BaseTool baseTool && baseTool.CraftSystem == DefBlacksmithy.CraftSystem)
ToolFound = true;
if (!ToolFound)
{ {
from.SendLocalizedMessage(1079822); // You need a blacksmithing tool in order to salvage ingots. from.SendLocalizedMessage(1079822); // You need a blacksmithing tool in order to salvage ingots.
return; return;
@ -229,7 +223,9 @@ namespace Server.Items
private void SalvageCloth(Mobile from) private void SalvageCloth(Mobile from)
{ {
if (!(from.Backpack.FindItemByType(typeof(Scissors)) is Scissors scissors)) Scissors scissors = from.Backpack.FindItemByType<Scissors>();
if (scissors == null)
{ {
from.SendLocalizedMessage(1079823); // You need scissors in order to salvage cloth. from.SendLocalizedMessage(1079823); // You need scissors in order to salvage cloth.
return; return;
@ -258,10 +254,15 @@ namespace Server.Items
from.SendLocalizedMessage(1079974, from.SendLocalizedMessage(1079974,
$"{salvaged}\t{salvaged + notSalvaged}"); // Salvaged: ~1_COUNT~/~2_NUM~ tailored items $"{salvaged}\t{salvaged + notSalvaged}"); // Salvaged: ~1_COUNT~/~2_NUM~ tailored items
foreach (Item i in FindItemsByType(typeof(Item), true)) Item[] items = FindItemsByType(new[]{
if (i is Leather || i is Cloth || i is SpinedLeather || i is HornedLeather || i is BarbedLeather || typeof(Leather), typeof(Cloth), typeof(SpinedLeather), typeof(HornedLeather), typeof(BarbedLeather),
i is Bandage || i is Bone) typeof(Bandage), typeof(Bone)
from.AddToBackpack(i); });
for (int i = 0; i < items.Length; i++)
{
from.AddToBackpack(items[i]);
}
} }
private void SalvageAll(Mobile from) private void SalvageAll(Mobile from)

View file

@ -697,7 +697,7 @@ namespace Server.Items
{ {
BaseHouse house = BaseHouse.FindHouseAt(this); BaseHouse house = BaseHouse.FindHouseAt(this);
if (house == null || !house.IsLockedDown(this)) if (house == null || !house.HasLockedDownItem(this))
{ {
if (message) if (message)
from.SendLocalizedMessage(502946, "", 0x59); // That belongs to someone else. from.SendLocalizedMessage(502946, "", 0x59); // That belongs to someone else.

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Engines.Harvest; using Server.Engines.Harvest;
using Server.Mobiles; using Server.Mobiles;
@ -301,13 +302,7 @@ namespace Server.Items
if (m.Backpack == null) if (m.Backpack == null)
return false; return false;
List<BaseHarvestTool> items = m.Backpack.FindItemsByType<BaseHarvestTool>(); return m.Backpack.FindItemsByType<BaseHarvestTool>().Any(tool => tool.HarvestSystem == Mining.System);
foreach (BaseHarvestTool tool in items)
if (tool.HarvestSystem == Mining.System)
return true;
return false;
} }
public void OnBeginDig(Mobile from) public void OnBeginDig(Mobile from)

View file

@ -212,7 +212,7 @@ namespace Server.Items
{ {
from.SendLocalizedMessage(1042270); // That is not in your house. from.SendLocalizedMessage(1042270); // That is not in your house.
} }
else if (!house.IsLockedDown(item) && !house.IsSecure(item) && !isDecorableComponent) else if (!house.HasLockedDownItem(item) && !house.HasSecureItem(item) && !isDecorableComponent)
{ {
if (item is AddonComponent && m_Decorator.Command == DecorateCommand.Up) if (item is AddonComponent && m_Decorator.Command == DecorateCommand.Up)
from.SendLocalizedMessage(1042274); // You cannot raise it up any higher. from.SendLocalizedMessage(1042274); // You cannot raise it up any higher.

View file

@ -168,7 +168,7 @@ namespace Server.Items
{ {
BaseHouse house = BaseHouse.FindHouseAt( this ); BaseHouse house = BaseHouse.FindHouseAt( this );
if ( house == null || !house.IsLockedDown( this ) ) if ( house == null || !house.HasLockedDownItem( this ) )
from.SendLocalizedMessage( 1062396 ); // This bulletin board must be locked down in a house to be usable. from.SendLocalizedMessage( 1062396 ); // This bulletin board must be locked down in a house to be usable.
else if ( !from.InRange( GetWorldLocation(), 2 ) || !from.InLOS( this ) ) else if ( !from.InRange( GetWorldLocation(), 2 ) || !from.InLOS( this ) )
from.LocalOverheadMessage( MessageType.Regular, 0x3B2, 1019045 ); // I can't reach that. from.LocalOverheadMessage( MessageType.Regular, 0x3B2, 1019045 ); // I can't reach that.
@ -202,7 +202,7 @@ namespace Server.Items
BaseHouse house = m_House; BaseHouse house = m_House;
BasePlayerBB board = m_Board; BasePlayerBB board = m_Board;
if ( house == null || !house.IsLockedDown( board ) ) if ( house == null || !house.HasLockedDownItem( board ) )
{ {
from.SendLocalizedMessage( 1062396 ); // This bulletin board must be locked down in a house to be usable. from.SendLocalizedMessage( 1062396 ); // This bulletin board must be locked down in a house to be usable.
return; return;
@ -278,7 +278,7 @@ namespace Server.Items
BaseHouse house = m_House; BaseHouse house = m_House;
BasePlayerBB board = m_Board; BasePlayerBB board = m_Board;
if ( house == null || !house.IsLockedDown( board ) ) if ( house == null || !house.HasLockedDownItem( board ) )
{ {
from.SendLocalizedMessage( 1062396 ); // This bulletin board must be locked down in a house to be usable. from.SendLocalizedMessage( 1062396 ); // This bulletin board must be locked down in a house to be usable.
return; return;
@ -369,7 +369,7 @@ namespace Server.Items
BaseHouse house = m_House; BaseHouse house = m_House;
BasePlayerBB board = m_Board; BasePlayerBB board = m_Board;
if ( house == null || !house.IsLockedDown( board ) ) if ( house == null || !house.HasLockedDownItem( board ) )
{ {
from.SendLocalizedMessage( 1062396 ); // This bulletin board must be locked down in a house to be usable. from.SendLocalizedMessage( 1062396 ); // This bulletin board must be locked down in a house to be usable.
return; return;

View file

@ -1067,8 +1067,7 @@ namespace Server.Items
} }
if (GetFlag(ConditionFlag.DenyPackEthereals) && if (GetFlag(ConditionFlag.DenyPackEthereals) &&
(pack.FindItemByType(typeof(EtherealMount)) != null || pack.FindItemByType(new []{typeof(EtherealMount), typeof(BaseImprisonedMobile)}) != null)
pack.FindItemByType(typeof(BaseImprisonedMobile)) != null))
{ {
m.SendMessage("You must empty your backpack of ethereal mounts before proceeding."); m.SendMessage("You must empty your backpack of ethereal mounts before proceeding.");
return false; return false;

View file

@ -91,8 +91,9 @@ namespace Server.Items
{ {
PotionKeg keg = kegs[i]; PotionKeg keg = kegs[i];
if (keg == null) // Should never happen
continue; // if (keg == null)
// continue;
if (keg.Held <= 0 || keg.Held >= 100) if (keg.Held <= 0 || keg.Held >= 100)
continue; continue;

View file

@ -167,7 +167,7 @@ namespace Server.Items
{ {
BaseHouse house = BaseHouse.FindHouseAt(item); BaseHouse house = BaseHouse.FindHouseAt(item);
if (house == null || !house.IsLockedDown(item) && !house.IsSecure(item)) if (house == null || !house.HasLockedDownItem(item) && !house.HasSecureItem(item))
from.SendLocalizedMessage(501022); // Furniture must be locked down to paint it. from.SendLocalizedMessage(501022); // Furniture must be locked down to paint it.
else if (!house.IsCoOwner(from)) else if (!house.IsCoOwner(from))
from.SendLocalizedMessage(501023); // You must be the owner to use this item. from.SendLocalizedMessage(501023); // You must be the owner to use this item.

View file

@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Server.Items; using Server.Items;
using Server.Spells.Sixth; using Server.Spells.Sixth;
using Server.Targeting; using Server.Targeting;
@ -41,13 +42,7 @@ namespace Server.Regions
private bool ContainsDeed(Container cont) private bool ContainsDeed(Container cont)
{ {
List<HouseRaffleDeed> deeds = cont.FindItemsByType<HouseRaffleDeed>(); return cont.FindItemsByType<HouseRaffleDeed>().Any(deed => deed == m_Stone.Deed);
for (int i = 0; i < deeds.Count; ++i)
if (deeds[i] == m_Stone.Deed)
return true;
return false;
} }
public override bool OnTarget(Mobile m, Target t, object o) public override bool OnTarget(Mobile m, Target t, object o)

View file

@ -157,7 +157,7 @@ namespace Server.Items
{ {
if (from.Backpack != null) if (from.Backpack != null)
{ {
PotionKeg keg = from.Backpack.FindItemByType(typeof(PotionKeg)) as PotionKeg; PotionKeg keg = from.Backpack.FindItemByType<PotionKeg>();
if (Validate(keg) > 0) if (Validate(keg) > 0)
from.SendGump(new InternalGump(this, keg)); from.SendGump(new InternalGump(this, keg));
@ -175,17 +175,20 @@ namespace Server.Items
public int Validate(PotionKeg keg) public int Validate(PotionKeg keg)
{ {
if (keg != null && !keg.Deleted && keg.Held == 100) if (keg == null || keg.Deleted || keg.Held != 100)
{ return 0;
if (keg.Type == PotionEffect.ExplosionLesser)
return 5;
if (keg.Type == PotionEffect.Explosion)
return 10;
if (keg.Type == PotionEffect.ExplosionGreater)
return 15;
}
return 0; switch (keg.Type)
{
case PotionEffect.ExplosionLesser:
return 5;
case PotionEffect.Explosion:
return 10;
case PotionEffect.ExplosionGreater:
return 15;
default:
return 0;
}
} }
public void Fill(Mobile from, PotionKeg keg) public void Fill(Mobile from, PotionKeg keg)

View file

@ -84,9 +84,7 @@ namespace Server.Items
} }
else else
{ {
Item diamond = from.Backpack.FindItemByType(typeof(BlueDiamond)); if (from.Backpack.FindItemByType<BlueDiamond>() != null)
if (diamond != null)
from.SendGump(new ConfirmGump(this, null)); from.SendGump(new ConfirmGump(this, null));
else else
from.SendLocalizedMessage( from.SendLocalizedMessage(
@ -130,71 +128,71 @@ namespace Server.Items
public virtual void Recharge(Mobile from, Mobile guildmaster) public virtual void Recharge(Mobile from, Mobile guildmaster)
{ {
if (from.Backpack != null) if (from.Backpack == null)
{ return;
Item diamond = from.Backpack.FindItemByType(typeof(BlueDiamond));
if (guildmaster != null) BlueDiamond diamond = from.Backpack.FindItemByType<BlueDiamond>();
if (guildmaster != null)
{
if (m_UsesRemaining <= 0)
{ {
if (m_UsesRemaining <= 0) if (diamond != null && Banker.Withdraw(from, 100000))
{ {
if (diamond != null && Banker.Withdraw(from, 100000)) diamond.Consume();
{ UsesRemaining = 10;
diamond.Consume(); guildmaster.Say(1076165); // Your weapon engraver should be good as new!
UsesRemaining = 10;
guildmaster.Say(1076165); // Your weapon engraver should be good as new!
}
else
{
guildmaster.Say(
1076167); // You need a 100,000 gold and a blue diamond to recharge the weapon engraver.
}
} }
else else
{ {
guildmaster.Say( guildmaster.Say(
1076164); // I can only help with this if you are carrying an engraving tool that needs repair. 1076167); // You need a 100,000 gold and a blue diamond to recharge the weapon engraver.
} }
} }
else else
{ {
if (from.Skills.Tinkering.Value == 0) guildmaster.Say(
{ 1076164); // I can only help with this if you are carrying an engraving tool that needs repair.
from.SendLocalizedMessage( }
1076179); // Since you have no tinkering skill, you will need to find an NPC tinkerer to repair this for you. }
} else
else if (from.Skills.Tinkering.Value < 75.0) {
{ if (from.Skills.Tinkering.Value == 0)
from.SendLocalizedMessage( {
1076178); // Your tinkering skill is too low to fix this yourself. An NPC tinkerer can help you repair this for a fee. from.SendLocalizedMessage(
} 1076179); // Since you have no tinkering skill, you will need to find an NPC tinkerer to repair this for you.
else if (diamond != null) }
{ else if (from.Skills.Tinkering.Value < 75.0)
diamond.Consume(); {
from.SendLocalizedMessage(
1076178); // Your tinkering skill is too low to fix this yourself. An NPC tinkerer can help you repair this for a fee.
}
else if (diamond != null)
{
diamond.Consume();
if (Utility.RandomDouble() < from.Skills.Tinkering.Value / 100) if (Utility.RandomDouble() < from.Skills.Tinkering.Value / 100)
{ {
UsesRemaining = 10; UsesRemaining = 10;
from.SendLocalizedMessage(1076165); // Your weapon engraver should be good as new! ????? from.SendLocalizedMessage(1076165); // Your weapon engraver should be good as new! ?????
}
else
{
from.SendLocalizedMessage(
1076175); // You cracked the diamond attempting to fix the weapon engraver.
}
} }
else else
{ {
from.SendLocalizedMessage( from.SendLocalizedMessage(
1076166); // You do not have a blue diamond needed to recharge the engraving tool. 1076175); // You cracked the diamond attempting to fix the weapon engraver.
} }
} }
else
{
from.SendLocalizedMessage(
1076166); // You do not have a blue diamond needed to recharge the engraving tool.
}
} }
} }
public static WeaponEngravingTool Find(Mobile from) public static WeaponEngravingTool Find(Mobile from)
{ {
return from.Backpack?.FindItemByType(typeof(WeaponEngravingTool)) as WeaponEngravingTool; return from.Backpack?.FindItemByType<WeaponEngravingTool>();
} }
private class TargetWeapon : Target private class TargetWeapon : Target

View file

@ -68,7 +68,7 @@ namespace Server.Mobiles
// When we have no ammo, we flee // When we have no ammo, we flee
Container pack = m_Mobile.Backpack; Container pack = m_Mobile.Backpack;
if (pack?.FindItemByType(typeof(Arrow)) == null) if (pack?.FindItemByType<Arrow>() == null)
{ {
Action = ActionType.Flee; Action = ActionType.Flee;
return true; return true;

View file

@ -81,7 +81,7 @@ namespace Server.Mobiles
if (cpack != null) if (cpack != null)
{ {
Item steala = cpack.FindItemByType(typeof(Bandage)); Item steala = cpack.FindItemByType<Bandage>();
if (steala != null) if (steala != null)
{ {
m_Mobile.DebugSay("Trying to steal from combatant."); m_Mobile.DebugSay("Trying to steal from combatant.");
@ -89,7 +89,7 @@ namespace Server.Mobiles
m_Mobile.Target?.Invoke(m_Mobile, steala); m_Mobile.Target?.Invoke(m_Mobile, steala);
} }
Item stealb = cpack.FindItemByType(typeof(Nightshade)); Item stealb = cpack.FindItemByType<Nightshade>();
if (stealb != null) if (stealb != null)
{ {
m_Mobile.DebugSay("Trying to steal from combatant."); m_Mobile.DebugSay("Trying to steal from combatant.");
@ -97,7 +97,7 @@ namespace Server.Mobiles
m_Mobile.Target?.Invoke(m_Mobile, stealb); m_Mobile.Target?.Invoke(m_Mobile, stealb);
} }
Item stealc = cpack.FindItemByType(typeof(BlackPearl)); Item stealc = cpack.FindItemByType<BlackPearl>();
if (stealc != null) if (stealc != null)
{ {
m_Mobile.DebugSay("Trying to steal from combatant."); m_Mobile.DebugSay("Trying to steal from combatant.");
@ -105,14 +105,14 @@ namespace Server.Mobiles
m_Mobile.Target?.Invoke(m_Mobile, stealc); m_Mobile.Target?.Invoke(m_Mobile, stealc);
} }
Item steald = cpack.FindItemByType(typeof(MandrakeRoot)); Item steald = cpack.FindItemByType<MandrakeRoot>();
if (steald != null) if (steald != null)
{ {
m_Mobile.DebugSay("Trying to steal from combatant."); m_Mobile.DebugSay("Trying to steal from combatant.");
m_Mobile.UseSkill(SkillName.Stealing); m_Mobile.UseSkill(SkillName.Stealing);
m_Mobile.Target?.Invoke(m_Mobile, steald); m_Mobile.Target?.Invoke(m_Mobile, steald);
} }
else if (steala == null && stealb == null && stealc == null && steald == null) else if (steala == null && stealb == null && stealc == null)
{ {
m_Mobile.DebugSay("I am going to flee from {0}", combatant.Name); m_Mobile.DebugSay("I am going to flee from {0}", combatant.Name);

View file

@ -1778,9 +1778,7 @@ namespace Server.Mobiles
if (Core.AOS && Backpack != null && !Backpack.Deleted) if (Core.AOS && Backpack != null && !Backpack.Deleted)
{ {
List<Item> ilist = Backpack.FindItemsByType<Item>(FindItems_Callback); Backpack.FindItemsByType<Item>(FindItems_Callback).ForEach(item => Backpack.AddItem(item));
for (int i = 0; i < ilist.Count; i++) Backpack.AddItem(ilist[i]);
} }
EquipSnapshot = new List<Item>(Items); EquipSnapshot = new List<Item>(Items);
@ -1813,53 +1811,52 @@ namespace Server.Mobiles
private bool CheckInsuranceOnDeath(Item item) private bool CheckInsuranceOnDeath(Item item)
{ {
if (InsuranceEnabled && item.Insured) if (!InsuranceEnabled || !item.Insured)
return false;
#region Dueling
if (m_DuelPlayer != null && DuelContext != null && DuelContext.Registered && DuelContext.Started &&
!m_DuelPlayer.Eliminated)
return true;
#endregion
if (AutoRenewInsurance)
{ {
#region Dueling int cost = GetInsuranceCost(item);
if (m_DuelPlayer != null && DuelContext != null && DuelContext.Registered && DuelContext.Started && if (m_InsuranceAward != null)
!m_DuelPlayer.Eliminated) cost /= 2;
return true;
#endregion if (Banker.Withdraw(this, cost))
if (AutoRenewInsurance)
{ {
int cost = GetInsuranceCost(item); m_InsuranceCost += cost;
item.PaidInsurance = true;
if (m_InsuranceAward != null) SendLocalizedMessage(1060398,
cost /= 2; cost.ToString()); // ~1_AMOUNT~ gold has been withdrawn from your bank box.
if (Banker.Withdraw(this, cost))
{
m_InsuranceCost += cost;
item.PaidInsurance = true;
SendLocalizedMessage(1060398,
cost.ToString()); // ~1_AMOUNT~ gold has been withdrawn from your bank box.
}
else
{
SendLocalizedMessage(1061079, "", 0x23); // You lack the funds to purchase the insurance
item.PaidInsurance = false;
item.Insured = false;
m_NonAutoreinsuredItems++;
}
} }
else else
{ {
SendLocalizedMessage(1061079, "", 0x23); // You lack the funds to purchase the insurance
item.PaidInsurance = false; item.PaidInsurance = false;
item.Insured = false; item.Insured = false;
m_NonAutoreinsuredItems++;
} }
}
if (m_InsuranceAward != null) else
if (Banker.Deposit(m_InsuranceAward, 300)) {
if (m_InsuranceAward is PlayerMobile mobile) item.PaidInsurance = false;
mobile.m_InsuranceBonus += 300; item.Insured = false;
return true;
} }
return false; if (m_InsuranceAward != null)
if (Banker.Deposit(m_InsuranceAward, 300))
if (m_InsuranceAward is PlayerMobile mobile)
mobile.m_InsuranceBonus += 300;
return true;
} }
public override DeathMoveResult GetParentMoveResultFor(Item item) public override DeathMoveResult GetParentMoveResultFor(Item item)
@ -2014,7 +2011,8 @@ namespace Server.Mobiles
if (!buff.RetainThroughDeath) if (!buff.RetainThroughDeath)
list.Add(buff); list.Add(buff);
for (int i = 0; i < list.Count; i++) RemoveBuff(list[i]); for (int i = 0; i < list.Count; i++)
RemoveBuff(list[i]);
} }
} }
@ -2129,7 +2127,7 @@ namespace Server.Mobiles
{ {
Type type = talisman.Protection.Type; Type type = talisman.Protection.Type;
if (type.IsAssignableFrom(from.GetType())) if (type.IsInstanceOfType(from))
amount = (int)(amount * (1 - (double)talisman.Protection.Amount / 100)); amount = (int)(amount * (1 - (double)talisman.Protection.Amount / 100));
} }
@ -3532,7 +3530,7 @@ namespace Server.Mobiles
Container pack = Backpack; Container pack = Backpack;
if (pack != null) if (pack != null)
items.AddRange(pack.FindItemsByType<Item>(true, DisplayInItemInsuranceGump)); items.AddRange(pack.FindItemsByType<Item>(DisplayInItemInsuranceGump));
// TODO: Investigate item sorting // TODO: Investigate item sorting

View file

@ -48,7 +48,8 @@ namespace Server.Mobiles
List<BankCheck> checks = bank.FindItemsByType<BankCheck>(); List<BankCheck> checks = bank.FindItemsByType<BankCheck>();
balance += gold.Aggregate(0L, (c, t) => c + t.Amount); balance += gold.Aggregate(0L, (c, t) => c + t.Amount);
if (balance >= int.MaxValue) return int.MaxValue; if (balance >= int.MaxValue)
return int.MaxValue;
balance += checks.Aggregate(0L, (c, t) => c + t.Worth); balance += checks.Aggregate(0L, (c, t) => c + t.Worth);
} }
@ -94,8 +95,7 @@ namespace Server.Mobiles
// If for whatever reason the TOL checks fail, we should still try old methods for withdrawing currency. // If for whatever reason the TOL checks fail, we should still try old methods for withdrawing currency.
if (AccountGold.Enabled && from.Account != null && from.Account.WithdrawGold(amount)) return true; if (AccountGold.Enabled && from.Account != null && from.Account.WithdrawGold(amount)) return true;
Item[] gold, checks; int balance = GetBalance(from, out Item[] gold, out Item[] checks);
int balance = GetBalance(from, out gold, out checks);
if (balance < amount) return false; if (balance < amount) return false;
@ -278,11 +278,9 @@ namespace Server.Mobiles
if (split.Length >= 2) if (split.Length >= 2)
{ {
int amount;
Container pack = e.Mobile.Backpack; Container pack = e.Mobile.Backpack;
if (!int.TryParse(split[1], out amount)) if (!int.TryParse(split[1], out int amount))
break; break;
if (!Core.ML && amount > 5000 || Core.ML && amount > 60000) if (!Core.ML && amount > 5000 || Core.ML && amount > 60000)
@ -363,9 +361,7 @@ namespace Server.Mobiles
if (split.Length >= 2) if (split.Length >= 2)
{ {
int amount; if (!int.TryParse(split[1], out int amount))
if (!int.TryParse(split[1], out amount))
break; break;
if (amount < 5000) if (amount < 5000)

View file

@ -41,9 +41,7 @@ namespace Server.Mobiles
{ {
m_NextCheckPack = DateTime.UtcNow + TimeSpan.FromSeconds(2.0); m_NextCheckPack = DateTime.UtcNow + TimeSpan.FromSeconds(2.0);
Item deed = pack.FindItemByType(typeof(HouseDeed), false); if (pack.FindItemByType<HouseDeed>(false) != null)
if (deed != null)
{ {
// If you have a deed, I can appraise it or buy it from you... // If you have a deed, I can appraise it or buy it from you...
PrivateOverheadMessage(MessageType.Regular, 0x3B2, 500605, m.NetState); PrivateOverheadMessage(MessageType.Regular, 0x3B2, 500605, m.NetState);

View file

@ -1105,21 +1105,21 @@ namespace Server.Multis
{ {
BaseHouse house = FindHouseAt(item); BaseHouse house = FindHouseAt(item);
return house != null && house.IsLockedDown(item); return house != null && house.HasLockedDownItem(item);
} }
public static bool CheckSecured(Item item) public static bool CheckSecured(Item item)
{ {
BaseHouse house = FindHouseAt(item); BaseHouse house = FindHouseAt(item);
return house != null && house.IsSecure(item); return house != null && house.HasSecureItem(item);
} }
public static bool CheckLockedDownOrSecured(Item item) public static bool CheckLockedDownOrSecured(Item item)
{ {
BaseHouse house = FindHouseAt(item); BaseHouse house = FindHouseAt(item);
return house != null && (house.IsSecure(item) || house.IsLockedDown(item)); return house != null && (house.HasSecureItem(item) || house.HasLockedDownItem(item));
} }
public static List<BaseHouse> GetHouses(Mobile m) public static List<BaseHouse> GetHouses(Mobile m)
@ -1151,7 +1151,7 @@ namespace Server.Multis
if (house == null || !house.IsAosRules) if (house == null || !house.IsAosRules)
return true; return true;
if (house.IsSecure(cont) && !house.CheckAosStorage(1 + item.TotalItems + plusItems)) if (house.HasSecureItem(cont) && !house.CheckAosStorage(1 + item.TotalItems + plusItems))
{ {
if (message) if (message)
m.SendLocalizedMessage(1061839); // This action would exceed the secure storage limit of the house. m.SendLocalizedMessage(1061839); // This action would exceed the secure storage limit of the house.
@ -1181,7 +1181,7 @@ namespace Server.Multis
case SecureAccessResult.Inaccessible: return false; case SecureAccessResult.Inaccessible: return false;
} }
if (house.IsLockedDown(item)) if (house.HasLockedDownItem(item))
return house.IsCoOwner(m) && item is Container; return house.IsCoOwner(m) && item is Container;
return true; return true;
@ -1248,7 +1248,7 @@ namespace Server.Multis
case SecureAccessResult.Inaccessible: return false; case SecureAccessResult.Inaccessible: return false;
} }
if (!IsLockedDown(item)) if (!HasLockedDownItem(item))
return true; return true;
if (from.AccessLevel >= AccessLevel.GameMaster) if (from.AccessLevel >= AccessLevel.GameMaster)
return true; return true;
@ -1662,7 +1662,7 @@ namespace Server.Multis
if (!IsCoOwner(m) || !IsActive) if (!IsCoOwner(m) || !IsActive)
return false; return false;
if (item is BaseAddonContainer || item.Movable && !IsSecure(item)) if (item is BaseAddonContainer || item.Movable && !HasSecureItem(item))
{ {
int amt = 1 + item.TotalItems; int amt = 1 + item.TotalItems;
@ -1681,11 +1681,11 @@ namespace Server.Multis
{ {
m.SendLocalizedMessage(1005377); //You cannot lock that down m.SendLocalizedMessage(1005377); //You cannot lock that down
} }
else if (IsSecure(rootItem)) else if (HasSecureItem(rootItem))
{ {
m.SendLocalizedMessage(501737); // You need not lock down items in a secure container. m.SendLocalizedMessage(501737); // You need not lock down items in a secure container.
} }
else if (parentItem != null && !IsLockedDown(parentItem)) else if (parentItem != null && !HasLockedDownItem(parentItem))
{ {
m.SendLocalizedMessage(501736); // You must lockdown the container first! m.SendLocalizedMessage(501736); // You must lockdown the container first!
} }
@ -1879,7 +1879,7 @@ namespace Server.Multis
if (!IsCoOwner(m) || !IsActive) if (!IsCoOwner(m) || !IsActive)
return; return;
if (IsLockedDown(item)) if (HasLockedDownItem(item))
{ {
item.PublicOverheadMessage(MessageType.Label, 0x3B2, 501657); //[no longer locked down] item.PublicOverheadMessage(MessageType.Label, 0x3B2, 501657); //[no longer locked down]
SetLockdown(item, false); SetLockdown(item, false);
@ -1887,7 +1887,7 @@ namespace Server.Multis
(item as RewardBrazier)?.TurnOff(); (item as RewardBrazier)?.TurnOff();
} }
else if (IsSecure(item)) else if (HasSecureItem(item))
{ {
ReleaseSecure(m, item); ReleaseSecure(m, item);
} }
@ -1906,7 +1906,7 @@ namespace Server.Multis
{ {
m.SendLocalizedMessage(1005525); // That is not in your house m.SendLocalizedMessage(1005525); // That is not in your house
} }
else if (IsLockedDown(item)) else if (HasLockedDownItem(item))
{ {
m.SendLocalizedMessage(1010550); // This is already locked down and cannot be secured. m.SendLocalizedMessage(1010550); // This is already locked down and cannot be secured.
} }
@ -3117,7 +3117,7 @@ namespace Server.Multis
return false; return false;
} }
public bool IsLockedDown(Item check) public bool HasLockedDownItem(Item check)
{ {
if (check == null) if (check == null)
return false; return false;
@ -3128,7 +3128,7 @@ namespace Server.Multis
return LockDowns.Contains(check) || VendorRentalContracts.Contains(check); return LockDowns.Contains(check) || VendorRentalContracts.Contains(check);
} }
public bool IsSecure(Item item) public bool HasSecureItem(Item item)
{ {
if (item == null) if (item == null)
return false; return false;
@ -3772,7 +3772,7 @@ namespace Server.Multis
isOwned = house is HouseFoundation && ((HouseFoundation)house).IsFixture(item); isOwned = house is HouseFoundation && ((HouseFoundation)house).IsFixture(item);
if (!isOwned) if (!isOwned)
isOwned = house.IsLockedDown(item); isOwned = house.HasLockedDownItem(item);
if (isOwned) if (isOwned)
sec = (ISecurable)item; sec = (ISecurable)item;

View file

@ -87,7 +87,7 @@ namespace Server.Items
public override void OnResponse(NetState sender, RelayInfo info) public override void OnResponse(NetState sender, RelayInfo info)
{ {
if (!m_From.CheckAlive() || m_From.Backpack?.FindItemByType(typeof(HousePlacementTool)) == null) if (!m_From.CheckAlive() || m_From.Backpack?.FindItemByType<HousePlacementTool>() == null)
return; return;
switch (info.ButtonID) switch (info.ButtonID)
@ -194,7 +194,7 @@ namespace Server.Items
public override void OnResponse(NetState sender, RelayInfo info) public override void OnResponse(NetState sender, RelayInfo info)
{ {
if (!m_From.CheckAlive() || m_From.Backpack?.FindItemByType(typeof(HousePlacementTool)) == null) if (!m_From.CheckAlive() || m_From.Backpack?.FindItemByType<HousePlacementTool>() == null)
return; return;
int index = info.ButtonID - 1; int index = info.ButtonID - 1;
@ -231,7 +231,7 @@ namespace Server.Items
protected override void OnTarget(Mobile from, object o) protected override void OnTarget(Mobile from, object o)
{ {
if (!from.CheckAlive() || from.Backpack?.FindItemByType(typeof(HousePlacementTool)) == null) if (!from.CheckAlive() || from.Backpack?.FindItemByType<HousePlacementTool>() == null)
return; return;
IPoint3D ip = o as IPoint3D; IPoint3D ip = o as IPoint3D;
@ -262,7 +262,7 @@ namespace Server.Items
protected override void OnTargetFinish(Mobile from) protected override void OnTargetFinish(Mobile from)
{ {
if (!from.CheckAlive() || from.Backpack?.FindItemByType(typeof(HousePlacementTool)) == null) if (!from.CheckAlive() || from.Backpack?.FindItemByType<HousePlacementTool>() == null)
return; return;
if (!m_Placed) if (!m_Placed)
@ -580,7 +580,7 @@ namespace Server.Items
public void PlacementWarning_Callback(Mobile from, bool okay, object state) public void PlacementWarning_Callback(Mobile from, bool okay, object state)
{ {
if (!from.CheckAlive() || from.Backpack?.FindItemByType(typeof(HousePlacementTool)) == null) if (!from.CheckAlive() || from.Backpack?.FindItemByType<HousePlacementTool>() == null)
return; return;
PreviewHouse prevHouse = (PreviewHouse)state; PreviewHouse prevHouse = (PreviewHouse)state;
@ -700,12 +700,11 @@ namespace Server.Items
public bool OnPlacement(Mobile from, Point3D p) public bool OnPlacement(Mobile from, Point3D p)
{ {
if (!from.CheckAlive() || from.Backpack?.FindItemByType(typeof(HousePlacementTool)) == null) if (!from.CheckAlive() || from.Backpack?.FindItemByType<HousePlacementTool>() == null)
return false; return false;
ArrayList toMove;
Point3D center = new Point3D(p.X - Offset.X, p.Y - Offset.Y, p.Z - Offset.Z); Point3D center = new Point3D(p.X - Offset.X, p.Y - Offset.Y, p.Z - Offset.Z);
HousePlacementResult res = HousePlacement.Check(from, MultiID, center, out toMove); HousePlacementResult res = HousePlacement.Check(from, MultiID, center, out ArrayList toMove);
switch (res) switch (res)
{ {

View file

@ -189,7 +189,7 @@ namespace Server.Regions
public override bool OnDecay(Item item) public override bool OnDecay(Item item)
{ {
if ((House.IsLockedDown(item) || House.IsSecure(item)) && House.IsInside(item)) if ((House.HasLockedDownItem(item) || House.HasSecureItem(item)) && House.IsInside(item))
return false; return false;
return base.OnDecay(item); return base.OnDecay(item);
} }
@ -387,9 +387,9 @@ namespace Server.Regions
{ {
Item item = (Item)o; Item item = (Item)o;
if (House.IsLockedDown(item)) if (House.HasLockedDownItem(item))
item.LabelTo(from, 501643); // [locked down] item.LabelTo(from, 501643); // [locked down]
else if (House.IsSecure(item)) else if (House.HasSecureItem(item))
item.LabelTo(from, 501644); // [locked down & secure] item.LabelTo(from, 501644); // [locked down & secure]
} }

View file

@ -71,13 +71,10 @@ namespace Server.SkillHandlers
from.SendLocalizedMessage(502372); // You fail to disarm the trap... but you don't set it off from.SendLocalizedMessage(502372); // You fail to disarm the trap... but you don't set it off
} }
} }
else if (targeted is BaseFactionTrap) else if (targeted is BaseFactionTrap trap)
{ {
BaseFactionTrap trap = (BaseFactionTrap)targeted;
Faction faction = Faction.Find(from); Faction faction = Faction.Find(from);
FactionTrapRemovalKit kit = from.Backpack?.FindItemByType<FactionTrapRemovalKit>();
FactionTrapRemovalKit kit =
from.Backpack?.FindItemByType(typeof(FactionTrapRemovalKit)) as FactionTrapRemovalKit;
bool isOwner = trap.Placer == from || trap.Faction != null && trap.Faction.IsCommander(from); bool isOwner = trap.Placer == from || trap.Faction != null && trap.Faction.IsCommander(from);
@ -121,12 +118,12 @@ namespace Server.SkillHandlers
} }
if (!isOwner) if (!isOwner)
kit?.ConsumeCharge(from); kit.ConsumeCharge(from);
} }
} }
else else
{ {
from.SendLocalizedMessage(502373); // That does'nt appear to be trapped from.SendLocalizedMessage(502373); // That doesn't appear to be trapped
} }
} }
} }

View file

@ -569,7 +569,7 @@ namespace Server.Spells.Ninjitsu
{ {
if (m_Mobile.Hits < m_Mobile.HitsMax && m_Mobile.Backpack != null) if (m_Mobile.Hits < m_Mobile.HitsMax && m_Mobile.Backpack != null)
{ {
Bandage b = m_Mobile.Backpack.FindItemByType(typeof(Bandage)) as Bandage; Bandage b = m_Mobile.Backpack.FindItemByType<Bandage>();
if (b != null) if (b != null)
{ {

View file

@ -38,8 +38,8 @@ namespace Server.Spells.Spellweaving
if (from?.Backpack == null) if (from?.Backpack == null)
return null; return null;
if (from.Holding is ArcaneFocus) if (from.Holding is ArcaneFocus focus)
return (ArcaneFocus)from.Holding; return focus;
return from.Backpack.FindItemByType<ArcaneFocus>(); return from.Backpack.FindItemByType<ArcaneFocus>();
} }

View file

@ -1292,7 +1292,7 @@ namespace Server.Items
} }
else if (recurse && item is Container) else if (recurse && item is Container)
{ {
RecurseConsumeUpTo(item, type, amount, recurse, ref consumed, toDelete); RecurseConsumeUpTo(item, type, amount, true, ref consumed, toDelete);
} }
} }
} }
@ -1459,12 +1459,7 @@ namespace Server.Items
return best; return best;
} }
public int GetAmount(Type type) public int GetAmount(Type type, bool recurse = true)
{
return GetAmount(type, true);
}
public int GetAmount(Type type, bool recurse)
{ {
Item[] items = FindItemsByType(type, recurse); Item[] items = FindItemsByType(type, recurse);
@ -1476,12 +1471,7 @@ namespace Server.Items
return amount; return amount;
} }
public int GetAmount(Type[] types) public int GetAmount(Type[] types, bool recurse = true)
{
return GetAmount(types, true);
}
public int GetAmount(Type[] types, bool recurse)
{ {
Item[] items = FindItemsByType(types, recurse); Item[] items = FindItemsByType(types, recurse);
@ -1509,29 +1499,24 @@ namespace Server.Items
private static void RecurseFindItemsByType(Item current, Type type, bool recurse, List<Item> list) private static void RecurseFindItemsByType(Item current, Type type, bool recurse, List<Item> list)
{ {
if (current != null && current.Items.Count > 0) if (current == null || current.Items.Count == 0)
return;
List<Item> items = current.Items;
for (int i = 0; i < items.Count; ++i)
{ {
List<Item> items = current.Items; Item item = items[i];
for (int i = 0; i < items.Count; ++i) if (type.IsInstanceOfType(item))
{ list.Add(item);
Item item = items[i];
if (type.IsAssignableFrom(item.GetType())) // item.GetType().IsAssignableFrom( type ) ) if (recurse && item is Container)
list.Add(item); RecurseFindItemsByType(item, type, true, list);
if (recurse && item is Container)
RecurseFindItemsByType(item, type, recurse, list);
}
} }
} }
public Item[] FindItemsByType(Type[] types) public Item[] FindItemsByType(Type[] types, bool recurse = true)
{
return FindItemsByType(types, true);
}
public Item[] FindItemsByType(Type[] types, bool recurse)
{ {
if (m_FindItemsList.Count > 0) if (m_FindItemsList.Count > 0)
m_FindItemsList.Clear(); m_FindItemsList.Clear();
@ -1543,87 +1528,78 @@ namespace Server.Items
private static void RecurseFindItemsByType(Item current, Type[] types, bool recurse, List<Item> list) private static void RecurseFindItemsByType(Item current, Type[] types, bool recurse, List<Item> list)
{ {
if (current != null && current.Items.Count > 0) if (current == null || current.Items.Count == 0)
return;
List<Item> items = current.Items;
for (int i = 0; i < items.Count; ++i)
{ {
List<Item> items = current.Items; Item item = items[i];
for (int i = 0; i < items.Count; ++i) if (InTypeList(item, types))
{ list.Add(item);
Item item = items[i];
if (InTypeList(item, types)) if (recurse && item is Container)
list.Add(item); RecurseFindItemsByType(item, types, true, list);
if (recurse && item is Container)
RecurseFindItemsByType(item, types, recurse, list);
}
} }
} }
public Item FindItemByType(Type type) public Item FindItemByType(Type type, bool recurse = true)
{
return FindItemByType(type, true);
}
public Item FindItemByType(Type type, bool recurse)
{ {
return RecurseFindItemByType(this, type, recurse); return RecurseFindItemByType(this, type, recurse);
} }
private static Item RecurseFindItemByType(Item current, Type type, bool recurse) private static Item RecurseFindItemByType(Item current, Type type, bool recurse)
{ {
if (current != null && current.Items.Count > 0) if (current == null || current.Items.Count == 0)
return null;
List<Item> list = current.Items;
for (int i = 0; i < list.Count; ++i)
{ {
List<Item> list = current.Items; Item item = list[i];
for (int i = 0; i < list.Count; ++i) if (type.IsInstanceOfType(item))
return item;
if (recurse && item is Container)
{ {
Item item = list[i]; Item check = RecurseFindItemByType(item, type, true);
if (type.IsAssignableFrom(item.GetType())) return item; if (check != null)
return check;
if (recurse && item is Container)
{
Item check = RecurseFindItemByType(item, type, recurse);
if (check != null)
return check;
}
} }
} }
return null; return null;
} }
public Item FindItemByType(Type[] types) public Item FindItemByType(Type[] types, bool recurse = true)
{
return FindItemByType(types, true);
}
public Item FindItemByType(Type[] types, bool recurse)
{ {
return RecurseFindItemByType(this, types, recurse); return RecurseFindItemByType(this, types, recurse);
} }
private static Item RecurseFindItemByType(Item current, Type[] types, bool recurse) private static Item RecurseFindItemByType(Item current, Type[] types, bool recurse)
{ {
if (current != null && current.Items.Count > 0) if (current == null || current.Items.Count <= 0)
return null;
List<Item> list = current.Items;
for (int i = 0; i < list.Count; ++i)
{ {
List<Item> list = current.Items; Item item = list[i];
for (int i = 0; i < list.Count; ++i) if (InTypeList(item, types)) return item;
if (recurse && item is Container)
{ {
Item item = list[i]; Item check = RecurseFindItemByType(item, types, true);
if (InTypeList(item, types)) return item; if (check != null)
return check;
if (recurse && item is Container)
{
Item check = RecurseFindItemByType(item, types, recurse);
if (check != null)
return check;
}
} }
} }
@ -1634,28 +1610,14 @@ namespace Server.Items
#region Generic FindItem[s] by Type #region Generic FindItem[s] by Type
public List<T> FindItemsByType<T>() where T : Item
{
return FindItemsByType<T>(true, null);
}
public List<T> FindItemsByType<T>(bool recurse) where T : Item
{
return FindItemsByType<T>(recurse, null);
}
public List<T> FindItemsByType<T>(Predicate<T> predicate) where T : Item public List<T> FindItemsByType<T>(Predicate<T> predicate) where T : Item
{ {
return FindItemsByType(true, predicate); return FindItemsByType(true, predicate);
} }
public List<T> FindItemsByType<T>(bool recurse, Predicate<T> predicate) where T : Item public List<T> FindItemsByType<T>(bool recurse = true, Predicate<T> predicate = null) where T : Item
{ {
if (m_FindItemsList.Count > 0)
m_FindItemsList.Clear();
List<T> list = new List<T>(); List<T> list = new List<T>();
RecurseFindItemsByType(this, recurse, list, predicate); RecurseFindItemsByType(this, recurse, list, predicate);
return list; return list;
@ -1664,79 +1626,58 @@ namespace Server.Items
private static void RecurseFindItemsByType<T>(Item current, bool recurse, List<T> list, Predicate<T> predicate) private static void RecurseFindItemsByType<T>(Item current, bool recurse, List<T> list, Predicate<T> predicate)
where T : Item where T : Item
{ {
if (current != null && current.Items.Count > 0) if (current == null || current.Items.Count == 0)
return;
List<Item> items = current.Items;
for (int i = 0; i < items.Count; ++i)
{ {
List<Item> items = current.Items; Item item = items[i];
for (int i = 0; i < items.Count; ++i) if (item is T typedItem)
{ {
Item item = items[i]; if (predicate?.Invoke(typedItem) == true)
list.Add(typedItem);
if (typeof(T).IsAssignableFrom(item.GetType()))
{
T typedItem = (T)item;
if (predicate == null || predicate(typedItem))
list.Add(typedItem);
}
if (recurse && item is Container)
RecurseFindItemsByType(item, recurse, list, predicate);
} }
if (recurse && item is Container)
RecurseFindItemsByType(item, true, list, predicate);
} }
} }
public T FindItemByType<T>() where T : Item public T FindItemByType<T>(bool recurse = true, Predicate<T> predicate = null) where T : Item
{
return FindItemByType<T>(true);
}
public T FindItemByType<T>(Predicate<T> predicate) where T : Item
{
return FindItemByType(true, predicate);
}
public T FindItemByType<T>(bool recurse) where T : Item
{
return FindItemByType<T>(recurse, null);
}
public T FindItemByType<T>(bool recurse, Predicate<T> predicate) where T : Item
{ {
return RecurseFindItemByType(this, recurse, predicate); return RecurseFindItemByType(this, recurse, predicate);
} }
private static T RecurseFindItemByType<T>(Item current, bool recurse, Predicate<T> predicate) where T : Item private static T RecurseFindItemByType<T>(Item current, bool recurse, Predicate<T> predicate) where T : Item
{ {
if (current != null && current.Items.Count > 0) if (current == null || current.Items.Count == 0)
return null;
List<Item> list = current.Items;
for (int i = 0; i < list.Count; ++i)
{ {
List<Item> list = current.Items; Item item = list[i];
for (int i = 0; i < list.Count; ++i) if (item is T typedItem)
{ {
Item item = list[i]; if (predicate?.Invoke(typedItem) == true)
return typedItem;
}
else if (recurse && item is Container)
{
T check = RecurseFindItemByType(item, true, predicate);
if (typeof(T).IsAssignableFrom(item.GetType())) if (check != null)
{ return check;
T typedItem = (T)item;
if (predicate == null || predicate(typedItem))
return typedItem;
}
else if (recurse && item is Container)
{
T check = RecurseFindItemByType(item, recurse, predicate);
if (check != null)
return check;
}
} }
} }
return null; return null;
} }
#endregion #endregion
} }