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

@ -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;
}