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

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