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)
if (house.IsSecure(item) || house.IsLockedDown(item))
if (house.HasSecureItem(item) || house.HasLockedDownItem(item))
{
e.Mobile.SendGump(new PropertiesGump(e.Mobile, house));
return;

View file

@ -82,7 +82,7 @@ namespace Server.Commands.Generic
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;

View file

@ -5,7 +5,7 @@ namespace Server.Commands.Generic
{
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;

View file

@ -6,7 +6,7 @@ namespace Server.Commands.Generic
{
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;

View file

@ -4,7 +4,7 @@ namespace Server.Commands.Generic
{
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;

View file

@ -1,5 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Server.Items;
using Server.Targeting;
@ -39,42 +41,36 @@ namespace Server.Commands.Generic
if (command.ObjectTypes == ObjectTypes.Mobiles)
return; // sanity check
if (!(targeted is Container))
if (!(targeted is Container cont))
{
from.SendMessage("That is not a container.");
else
try
return;
}
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);
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);
from.SendMessage("This command only works on items.");
return;
}
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.";
}
private static string InternalGetValue(object o, PropertyInfo p)
{
return InternalGetValue(o, p, null);
}
private static string InternalGetValue(object o, PropertyInfo p, PropertyInfo[] chain)
private static string InternalGetValue(object o, PropertyInfo p, PropertyInfo[] chain = null)
{
Type type = p.PropertyType;

View file

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

View file

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

View file

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

View file

@ -337,15 +337,9 @@ namespace Server.Factions
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
Item[] sigils = mob.Backpack.FindItemsByType(typeof(Sigil));
for (int i = 0; i < sigils.Length; ++i)
((Sigil)sigils[i]).ReturnHome();
}
//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
mob.Backpack?.FindItemsByType<Sigil>().ForEach(sigil => sigil.ReturnHome());
if (pl.RankIndex != -1)
{
@ -936,43 +930,32 @@ namespace Server.Factions
killer = victim.FindMostRecentDamager(true);
PlayerState killerState = PlayerState.Find(killer);
Container pack = victim.Backpack;
if (pack != null)
Container killerPack = killer?.Backpack;
victim.Backpack?.FindItemsByType<Sigil>().ForEach(sigil =>
{
Container killerPack = killer?.Backpack;
Item[] sigils = pack.FindItemsByType(typeof(Sigil));
for (int i = 0; i < sigils.Length; ++i)
if (killerState == null || killerPack == null)
{
Sigil sigil = (Sigil)sigils[i];
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();
}
sigil.ReturnHome();
return;
}
}
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)
return;
@ -1072,9 +1055,7 @@ namespace Server.Factions
if (1 > Utility.Random(3))
killerState.IsActive = true;
int silver = 0;
silver = killerState.Faction.AwardSilver(killer, award * 40);
int silver = killerState.Faction.AwardSilver(killer, award * 40);
if (silver > 0)
killer.SendLocalizedMessage(1042736,
@ -1129,17 +1110,7 @@ namespace Server.Factions
private static void EventSink_Logout(LogoutEventArgs e)
{
Mobile mob = e.Mobile;
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();
e.Mobile.Backpack?.FindItemsByType<Sigil>().ForEach(sigil => sigil.ReturnHome());
}
private static void EventSink_Login(LoginEventArgs e)
@ -1166,17 +1137,7 @@ namespace Server.Factions
return null;
}
public static Faction Find(Mobile mob)
{
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)
public static Faction Find(Mobile mob, bool inherit = false, bool creatureAllegiances = false)
{
PlayerState pl = PlayerState.Find(mob);
@ -1186,9 +1147,9 @@ namespace Server.Factions
if (inherit && mob is BaseCreature bc)
{
if (bc.Controlled)
return Find(bc.ControlMaster, false);
return Find(bc.ControlMaster);
if (bc.Summoned)
return Find(bc.SummonMaster, false);
return Find(bc.SummonMaster);
if (creatureAllegiances && bc is BaseFactionGuard guard)
return guard.Faction;
if (creatureAllegiances)

View file

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

View file

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

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Server.Engines.Quests;
using Server.Engines.Quests.Collector;
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)
{
Container pack = from.Backpack;
if (pack != null)
{
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);
return from?.Backpack?.FindItemsByType<SOS>().Any(sos =>
(from.Map == Map.Felucca || from.Map == Map.Trammel) && from.InRange(sos.TargetLocation, 60)) ??
base.CheckResources(from, tool, def, map, loc, timed);
}
public override Item Construct(Type type, Mobile from)
@ -320,9 +308,7 @@ namespace Server.Engines.Harvest
if (preLoot != null)
{
if (preLoot is IShipwreckedItem shipwreckedItem)
shipwreckedItem.IsShipwreckedItem = true;
((IShipwreckedItem)preLoot).IsShipwreckedItem = true;
return preLoot;
}

View file

@ -28,7 +28,7 @@ namespace Server.Items
if (pm.InRange(GetWorldLocation(), 2))
{
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();

View file

@ -152,31 +152,20 @@ namespace Server.Engines.MLQuests.Items
if (!base.CanTeleport(m))
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;
Container pack = m.Backpack;
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);
TextDefinition.SendMessageTo(m, Message);
return false;
}
(ticket as ITicket)?.OnTicketUsed(m);
return true;
}

View file

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Server.Gumps;
using Server.Items;
using Server.Network;
@ -310,30 +311,20 @@ namespace Server.Engines.Plants
}
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 (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)
if (bev == null)
{
from.Target = new PlantPourTarget(m_Plant);
from.SendLocalizedMessage(1060808,
"#" + m_Plant
.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));

View file

@ -413,25 +413,17 @@ namespace Server.Engines.Plants
{
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)
if (plant.IsGrowable)
plant.PlantSystem.DoGrowthCheck();
}
BankBox bank = from.FindBankNoCreate();
if (bank != null)
from.FindBankNoCreate()?.FindItemsByType<PlantItem>().ForEach(plant =>
{
List<PlantItem> plants = bank.FindItemsByType<PlantItem>();
foreach (PlantItem plant in plants)
if (plant.IsGrowable)
plant.PlantSystem.DoGrowthCheck();
}
if (plant.IsGrowable)
plant.PlantSystem.DoGrowthCheck();
});
}
public static void GrowAll()
@ -443,7 +435,7 @@ namespace Server.Engines.Plants
{
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();
}
}

View file

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

View file

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

View file

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

View file

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

View file

@ -117,21 +117,18 @@ namespace Server.Engines.Quests.Samurai
if (obj != null && !obj.Completed)
{
Container pack = player.Backpack;
Item katana = pack?.FindItemByType(typeof(HaochisKatana));
if (katana != null)
{
katana.Delete();
obj.Complete();
HaochisKatana katana = player.Backpack?.FindItemByType<HaochisKatana>();
if (katana == null)
return;
katana.Delete();
obj.Complete();
obj = qs.FindObjective(typeof(FifthTrialIntroObjective));
if (obj != null && ((FifthTrialIntroObjective)obj).StolenTreasure)
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));

View file

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

View file

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

View file

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

View file

@ -64,10 +64,10 @@ namespace Server.Items
BaseHouse house = BaseHouse.FindHouseAt(this);
if (house?.IsLockedDown(this) == true)
if (house?.HasLockedDownItem(this) == true)
{
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.
return false;
@ -99,10 +99,10 @@ namespace Server.Items
BaseHouse house = BaseHouse.FindHouseAt(this);
if (house?.IsLockedDown(this) == true)
if (house?.HasLockedDownItem(this) == true)
{
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.
return false;

View file

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

View file

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

View file

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

View file

@ -212,7 +212,7 @@ namespace Server.Items
{
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)
from.SendLocalizedMessage(1042274); // You cannot raise it up any higher.

View file

@ -168,7 +168,7 @@ namespace Server.Items
{
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.
else if ( !from.InRange( GetWorldLocation(), 2 ) || !from.InLOS( this ) )
from.LocalOverheadMessage( MessageType.Regular, 0x3B2, 1019045 ); // I can't reach that.
@ -202,7 +202,7 @@ namespace Server.Items
BaseHouse house = m_House;
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.
return;
@ -278,7 +278,7 @@ namespace Server.Items
BaseHouse house = m_House;
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.
return;
@ -369,7 +369,7 @@ namespace Server.Items
BaseHouse house = m_House;
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.
return;

View file

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

View file

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

View file

@ -167,7 +167,7 @@ namespace Server.Items
{
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.
else if (!house.IsCoOwner(from))
from.SendLocalizedMessage(501023); // You must be the owner to use this item.

View file

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

View file

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

View file

@ -84,9 +84,7 @@ namespace Server.Items
}
else
{
Item diamond = from.Backpack.FindItemByType(typeof(BlueDiamond));
if (diamond != null)
if (from.Backpack.FindItemByType<BlueDiamond>() != null)
from.SendGump(new ConfirmGump(this, null));
else
from.SendLocalizedMessage(
@ -130,71 +128,71 @@ namespace Server.Items
public virtual void Recharge(Mobile from, Mobile guildmaster)
{
if (from.Backpack != null)
{
Item diamond = from.Backpack.FindItemByType(typeof(BlueDiamond));
if (from.Backpack == null)
return;
BlueDiamond diamond = from.Backpack.FindItemByType<BlueDiamond>();
if (guildmaster != null)
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;
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.
}
diamond.Consume();
UsesRemaining = 10;
guildmaster.Say(1076165); // Your weapon engraver should be good as new!
}
else
{
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
{
if (from.Skills.Tinkering.Value == 0)
{
from.SendLocalizedMessage(
1076179); // Since you have no tinkering skill, you will need to find an NPC tinkerer to repair this for you.
}
else if (from.Skills.Tinkering.Value < 75.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.
}
else if (diamond != null)
{
diamond.Consume();
guildmaster.Say(
1076164); // I can only help with this if you are carrying an engraving tool that needs repair.
}
}
else
{
if (from.Skills.Tinkering.Value == 0)
{
from.SendLocalizedMessage(
1076179); // Since you have no tinkering skill, you will need to find an NPC tinkerer to repair this for you.
}
else if (from.Skills.Tinkering.Value < 75.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.
}
else if (diamond != null)
{
diamond.Consume();
if (Utility.RandomDouble() < from.Skills.Tinkering.Value / 100)
{
UsesRemaining = 10;
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.
}
if (Utility.RandomDouble() < from.Skills.Tinkering.Value / 100)
{
UsesRemaining = 10;
from.SendLocalizedMessage(1076165); // Your weapon engraver should be good as new! ?????
}
else
{
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)
{
return from.Backpack?.FindItemByType(typeof(WeaponEngravingTool)) as WeaponEngravingTool;
return from.Backpack?.FindItemByType<WeaponEngravingTool>();
}
private class TargetWeapon : Target

View file

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

View file

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

View file

@ -1778,9 +1778,7 @@ namespace Server.Mobiles
if (Core.AOS && Backpack != null && !Backpack.Deleted)
{
List<Item> ilist = Backpack.FindItemsByType<Item>(FindItems_Callback);
for (int i = 0; i < ilist.Count; i++) Backpack.AddItem(ilist[i]);
Backpack.FindItemsByType<Item>(FindItems_Callback).ForEach(item => Backpack.AddItem(item));
}
EquipSnapshot = new List<Item>(Items);
@ -1813,53 +1811,52 @@ namespace Server.Mobiles
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 &&
!m_DuelPlayer.Eliminated)
return true;
if (m_InsuranceAward != null)
cost /= 2;
#endregion
if (AutoRenewInsurance)
if (Banker.Withdraw(this, cost))
{
int cost = GetInsuranceCost(item);
if (m_InsuranceAward != null)
cost /= 2;
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++;
}
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++;
}
if (m_InsuranceAward != null)
if (Banker.Deposit(m_InsuranceAward, 300))
if (m_InsuranceAward is PlayerMobile mobile)
mobile.m_InsuranceBonus += 300;
return true;
}
else
{
item.PaidInsurance = false;
item.Insured = false;
}
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)
@ -2014,7 +2011,8 @@ namespace Server.Mobiles
if (!buff.RetainThroughDeath)
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;
if (type.IsAssignableFrom(from.GetType()))
if (type.IsInstanceOfType(from))
amount = (int)(amount * (1 - (double)talisman.Protection.Amount / 100));
}
@ -3532,7 +3530,7 @@ namespace Server.Mobiles
Container pack = Backpack;
if (pack != null)
items.AddRange(pack.FindItemsByType<Item>(true, DisplayInItemInsuranceGump));
items.AddRange(pack.FindItemsByType<Item>(DisplayInItemInsuranceGump));
// TODO: Investigate item sorting

View file

@ -48,7 +48,8 @@ namespace Server.Mobiles
List<BankCheck> checks = bank.FindItemsByType<BankCheck>();
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);
}
@ -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 (AccountGold.Enabled && from.Account != null && from.Account.WithdrawGold(amount)) return true;
Item[] gold, checks;
int balance = GetBalance(from, out gold, out checks);
int balance = GetBalance(from, out Item[] gold, out Item[] checks);
if (balance < amount) return false;
@ -278,11 +278,9 @@ namespace Server.Mobiles
if (split.Length >= 2)
{
int amount;
Container pack = e.Mobile.Backpack;
if (!int.TryParse(split[1], out amount))
if (!int.TryParse(split[1], out int amount))
break;
if (!Core.ML && amount > 5000 || Core.ML && amount > 60000)
@ -363,9 +361,7 @@ namespace Server.Mobiles
if (split.Length >= 2)
{
int amount;
if (!int.TryParse(split[1], out amount))
if (!int.TryParse(split[1], out int amount))
break;
if (amount < 5000)

View file

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

View file

@ -1105,21 +1105,21 @@ namespace Server.Multis
{
BaseHouse house = FindHouseAt(item);
return house != null && house.IsLockedDown(item);
return house != null && house.HasLockedDownItem(item);
}
public static bool CheckSecured(Item item)
{
BaseHouse house = FindHouseAt(item);
return house != null && house.IsSecure(item);
return house != null && house.HasSecureItem(item);
}
public static bool CheckLockedDownOrSecured(Item 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)
@ -1151,7 +1151,7 @@ namespace Server.Multis
if (house == null || !house.IsAosRules)
return true;
if (house.IsSecure(cont) && !house.CheckAosStorage(1 + item.TotalItems + plusItems))
if (house.HasSecureItem(cont) && !house.CheckAosStorage(1 + item.TotalItems + plusItems))
{
if (message)
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;
}
if (house.IsLockedDown(item))
if (house.HasLockedDownItem(item))
return house.IsCoOwner(m) && item is Container;
return true;
@ -1248,7 +1248,7 @@ namespace Server.Multis
case SecureAccessResult.Inaccessible: return false;
}
if (!IsLockedDown(item))
if (!HasLockedDownItem(item))
return true;
if (from.AccessLevel >= AccessLevel.GameMaster)
return true;
@ -1662,7 +1662,7 @@ namespace Server.Multis
if (!IsCoOwner(m) || !IsActive)
return false;
if (item is BaseAddonContainer || item.Movable && !IsSecure(item))
if (item is BaseAddonContainer || item.Movable && !HasSecureItem(item))
{
int amt = 1 + item.TotalItems;
@ -1681,11 +1681,11 @@ namespace Server.Multis
{
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.
}
else if (parentItem != null && !IsLockedDown(parentItem))
else if (parentItem != null && !HasLockedDownItem(parentItem))
{
m.SendLocalizedMessage(501736); // You must lockdown the container first!
}
@ -1879,7 +1879,7 @@ namespace Server.Multis
if (!IsCoOwner(m) || !IsActive)
return;
if (IsLockedDown(item))
if (HasLockedDownItem(item))
{
item.PublicOverheadMessage(MessageType.Label, 0x3B2, 501657); //[no longer locked down]
SetLockdown(item, false);
@ -1887,7 +1887,7 @@ namespace Server.Multis
(item as RewardBrazier)?.TurnOff();
}
else if (IsSecure(item))
else if (HasSecureItem(item))
{
ReleaseSecure(m, item);
}
@ -1906,7 +1906,7 @@ namespace Server.Multis
{
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.
}
@ -3117,7 +3117,7 @@ namespace Server.Multis
return false;
}
public bool IsLockedDown(Item check)
public bool HasLockedDownItem(Item check)
{
if (check == null)
return false;
@ -3128,7 +3128,7 @@ namespace Server.Multis
return LockDowns.Contains(check) || VendorRentalContracts.Contains(check);
}
public bool IsSecure(Item item)
public bool HasSecureItem(Item item)
{
if (item == null)
return false;
@ -3772,7 +3772,7 @@ namespace Server.Multis
isOwned = house is HouseFoundation && ((HouseFoundation)house).IsFixture(item);
if (!isOwned)
isOwned = house.IsLockedDown(item);
isOwned = house.HasLockedDownItem(item);
if (isOwned)
sec = (ISecurable)item;

View file

@ -87,7 +87,7 @@ namespace Server.Items
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;
switch (info.ButtonID)
@ -194,7 +194,7 @@ namespace Server.Items
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;
int index = info.ButtonID - 1;
@ -231,7 +231,7 @@ namespace Server.Items
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;
IPoint3D ip = o as IPoint3D;
@ -262,7 +262,7 @@ namespace Server.Items
protected override void OnTargetFinish(Mobile from)
{
if (!from.CheckAlive() || from.Backpack?.FindItemByType(typeof(HousePlacementTool)) == null)
if (!from.CheckAlive() || from.Backpack?.FindItemByType<HousePlacementTool>() == null)
return;
if (!m_Placed)
@ -580,7 +580,7 @@ namespace Server.Items
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;
PreviewHouse prevHouse = (PreviewHouse)state;
@ -700,12 +700,11 @@ namespace Server.Items
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;
ArrayList toMove;
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)
{

View file

@ -189,7 +189,7 @@ namespace Server.Regions
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 base.OnDecay(item);
}
@ -387,9 +387,9 @@ namespace Server.Regions
{
Item item = (Item)o;
if (House.IsLockedDown(item))
if (House.HasLockedDownItem(item))
item.LabelTo(from, 501643); // [locked down]
else if (House.IsSecure(item))
else if (House.HasSecureItem(item))
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
}
}
else if (targeted is BaseFactionTrap)
else if (targeted is BaseFactionTrap trap)
{
BaseFactionTrap trap = (BaseFactionTrap)targeted;
Faction faction = Faction.Find(from);
FactionTrapRemovalKit kit =
from.Backpack?.FindItemByType(typeof(FactionTrapRemovalKit)) as FactionTrapRemovalKit;
FactionTrapRemovalKit kit = from.Backpack?.FindItemByType<FactionTrapRemovalKit>();
bool isOwner = trap.Placer == from || trap.Faction != null && trap.Faction.IsCommander(from);
@ -121,12 +118,12 @@ namespace Server.SkillHandlers
}
if (!isOwner)
kit?.ConsumeCharge(from);
kit.ConsumeCharge(from);
}
}
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)
{
Bandage b = m_Mobile.Backpack.FindItemByType(typeof(Bandage)) as Bandage;
Bandage b = m_Mobile.Backpack.FindItemByType<Bandage>();
if (b != null)
{

View file

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