From b06f5bf60d187cbcb8a5e12d6d77547157e11844 Mon Sep 17 00:00:00 2001 From: Kamron Batman Date: Thu, 9 Aug 2018 14:08:34 -0700 Subject: [PATCH] Adds better type support for pooled enumerables. Refactors code. (#16) --- Scripts/Commands/Decorate.cs | 12 +-- Scripts/Commands/DecorateMag.cs | 10 +-- Scripts/Commands/GenTeleporter.cs | 12 +-- .../Generic/Extensions/BaseExtension.cs | 2 +- .../Generic/Extensions/DistinctExtension.cs | 2 +- .../Implementors/AreaCommandImplementor.cs | 15 ++-- Scripts/Commands/SignParser.cs | 4 +- Scripts/Commands/Statics.cs | 4 +- Scripts/Commands/Wipe.cs | 10 +-- Scripts/Engines/ConPVP/Games/BombingRun.cs | 16 ++-- Scripts/Engines/Craft/Core/CraftItem.cs | 2 +- Scripts/Engines/Craft/DefBlacksmithy.cs | 4 +- Scripts/Engines/Factions/Core/Faction.cs | 20 ++--- Scripts/Engines/Khaldun/KhaldunGen.cs | 4 +- .../Character Statue Maker/CharacterStatue.cs | 2 +- Scripts/Items/Addons/SHTeleporter.cs | 10 +-- Scripts/Items/Containers/MarkContainer.cs | 6 +- Scripts/Items/Misc/Firebomb.cs | 5 +- Scripts/Items/Skill Items/Camping/Campfire.cs | 4 +- .../Explosion Potions/BaseExplosionPotion.cs | 8 +- Scripts/Items/Skill Items/Misc/FireHorn.cs | 8 +- Scripts/Items/Weapons/BaseWeapon.cs | 28 +++---- Scripts/Misc/VendorGenerator.cs | 13 ++- Scripts/Misc/uoamVendors.cs | 12 ++- Scripts/Mobiles/AI/BaseAI.cs | 4 +- Scripts/Mobiles/BaseCreature.cs | 8 +- .../Monsters/Misc/Melee/PlagueBeast.cs | 29 +++---- Scripts/Mobiles/PlayerMobile.cs | 4 +- Scripts/Mobiles/Vendors/PlayerVendor.cs | 10 +-- Scripts/Multis/BaseHouse.cs | 16 ++-- Scripts/Multis/Boats/BaseBoat.cs | 8 +- Scripts/Regions/GuardedRegion.cs | 17 ++-- Scripts/Skills/DetectHidden.cs | 21 ++--- Scripts/Skills/Snooping.cs | 4 +- Scripts/Spells/Fifth/PoisonField.cs | 4 +- Scripts/Spells/Fourth/ArchCure.cs | 4 +- Scripts/Spells/Fourth/ArchProtection.cs | 2 +- Scripts/Spells/Seventh/ChainLightning.cs | 4 +- Scripts/Spells/Seventh/GateTravel.cs | 4 +- Scripts/Spells/Seventh/MassDispel.cs | 8 +- Scripts/Spells/Seventh/MeteorSwarm.cs | 4 +- Scripts/Spells/Sixth/MassCurse.cs | 4 +- Scripts/Spells/Sixth/Reveal.cs | 4 +- Scripts/Spells/Spellweaving/ArcaneCircle.cs | 4 +- Scripts/Spells/Third/Teleport.cs | 4 +- Server/Map.cs | 84 ++++++++++++++----- Server/Mobile.cs | 21 +++-- Server/Network/PacketHandlers.cs | 10 +-- 48 files changed, 252 insertions(+), 243 deletions(-) diff --git a/Scripts/Commands/Decorate.cs b/Scripts/Commands/Decorate.cs index 2b2b44972..f851b157b 100644 --- a/Scripts/Commands/Decorate.cs +++ b/Scripts/Commands/Decorate.cs @@ -873,7 +873,7 @@ namespace Server.Commands bool res = false; - IPooledEnumerable eable; + IPooledEnumerable eable; if ( srcItem is BaseDoor ) { @@ -1002,16 +1002,16 @@ namespace Server.Commands if ( item is BaseDoor ) { - IPooledEnumerable eable = maps[j].GetItemsInRange( loc, 1 ); + IPooledEnumerable eable = maps[j].GetItemsInRange( loc, 1 ); Type itemType = item.GetType(); - foreach ( Item link in eable ) + foreach ( BaseDoor link in eable ) { if ( link != item && link.Z == item.Z && link.GetType() == itemType ) { - ((BaseDoor)item).Link = (BaseDoor)link; - ((BaseDoor)link).Link = (BaseDoor)item; + ((BaseDoor)item).Link = link; + link.Link = (BaseDoor)item; break; } } @@ -1151,4 +1151,4 @@ namespace Server.Commands } } } -} \ No newline at end of file +} diff --git a/Scripts/Commands/DecorateMag.cs b/Scripts/Commands/DecorateMag.cs index 8939f309d..e85d82478 100644 --- a/Scripts/Commands/DecorateMag.cs +++ b/Scripts/Commands/DecorateMag.cs @@ -870,7 +870,7 @@ namespace Server.Commands bool res = false; - IPooledEnumerable eable; + IPooledEnumerable eable; if ( srcItem is BaseDoor ) { @@ -999,16 +999,16 @@ namespace Server.Commands if ( item is BaseDoor ) { - IPooledEnumerable eable = maps[j].GetItemsInRange( loc, 1 ); + IPooledEnumerable eable = maps[j].GetItemsInRange( loc, 1 ); Type itemType = item.GetType(); - foreach ( Item link in eable ) + foreach ( BaseDoor link in eable ) { if ( link != item && link.Z == item.Z && link.GetType() == itemType ) { - ((BaseDoor)item).Link = (BaseDoor)link; - ((BaseDoor)link).Link = (BaseDoor)item; + ((BaseDoor)item).Link = link; + link.Link = (BaseDoor)item; break; } } diff --git a/Scripts/Commands/GenTeleporter.cs b/Scripts/Commands/GenTeleporter.cs index 94e4abf31..a51797bd4 100644 --- a/Scripts/Commands/GenTeleporter.cs +++ b/Scripts/Commands/GenTeleporter.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using Server; using Server.Items; @@ -37,11 +37,11 @@ namespace Server.Commands { } - private static Queue m_Queue = new Queue(); + private static Queue m_Queue = new Queue(); public static bool FindTeleporter( Map map, Point3D p ) { - IPooledEnumerable eable = map.GetItemsInRange( p, 0 ); + IPooledEnumerable eable = map.GetItemsInRange( p, 0 ); foreach ( Item item in eable ) { @@ -57,7 +57,7 @@ namespace Server.Commands eable.Free(); while ( m_Queue.Count > 0 ) - ((Item)m_Queue.Dequeue()).Delete(); + m_Queue.Dequeue().Delete(); return false; } @@ -96,7 +96,7 @@ namespace Server.Commands public void DestroyTeleporter( int x, int y, int z, Map map ) { Point3D p = new Point3D( x, y, z ); - IPooledEnumerable eable = map.GetItemsInRange( p, 0 ); + IPooledEnumerable eable = map.GetItemsInRange( p, 0 ); foreach ( Item item in eable ) { @@ -107,7 +107,7 @@ namespace Server.Commands eable.Free(); while ( m_Queue.Count > 0 ) - ((Item)m_Queue.Dequeue()).Delete(); + m_Queue.Dequeue().Delete(); } public void CreateTeleportersMap( Map map ) diff --git a/Scripts/Commands/Generic/Extensions/BaseExtension.cs b/Scripts/Commands/Generic/Extensions/BaseExtension.cs index 62bdd8728..574d01baa 100644 --- a/Scripts/Commands/Generic/Extensions/BaseExtension.cs +++ b/Scripts/Commands/Generic/Extensions/BaseExtension.cs @@ -181,4 +181,4 @@ namespace Server.Commands.Generic { } } -} \ No newline at end of file +} diff --git a/Scripts/Commands/Generic/Extensions/DistinctExtension.cs b/Scripts/Commands/Generic/Extensions/DistinctExtension.cs index 396cf7262..b57446b07 100644 --- a/Scripts/Commands/Generic/Extensions/DistinctExtension.cs +++ b/Scripts/Commands/Generic/Extensions/DistinctExtension.cs @@ -86,4 +86,4 @@ namespace Server.Commands.Generic } } } -} \ No newline at end of file +} diff --git a/Scripts/Commands/Generic/Implementors/AreaCommandImplementor.cs b/Scripts/Commands/Generic/Implementors/AreaCommandImplementor.cs index d948b8732..b06230691 100644 --- a/Scripts/Commands/Generic/Implementors/AreaCommandImplementor.cs +++ b/Scripts/Commands/Generic/Implementors/AreaCommandImplementor.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Server; namespace Server.Commands.Generic @@ -47,20 +48,16 @@ namespace Server.Commands.Generic if ( !CheckObjectTypes( from, command, ext, out items, out mobiles ) ) return; - IPooledEnumerable eable; + IPooledEnumerable eable; - if ( items && mobiles ) - eable = map.GetObjectsInBounds( rect ); - else if ( items ) - eable = map.GetItemsInBounds( rect ); - else if ( mobiles ) - eable = map.GetMobilesInBounds( rect ); + if (items || mobiles) + eable = map.GetObjectsInBounds(rect, items, mobiles); else return; ArrayList objs = new ArrayList(); - foreach ( object obj in eable ) + foreach ( IEntity obj in eable ) { if ( mobiles && obj is Mobile && !BaseCommand.IsAccessible( from, obj ) ) continue; @@ -81,4 +78,4 @@ namespace Server.Commands.Generic } } } -} \ No newline at end of file +} diff --git a/Scripts/Commands/SignParser.cs b/Scripts/Commands/SignParser.cs index 673208143..bde8f067e 100644 --- a/Scripts/Commands/SignParser.cs +++ b/Scripts/Commands/SignParser.cs @@ -100,7 +100,7 @@ namespace Server.Commands public static void Add_Static( int itemID, Point3D location, Map map, string name ) { - IPooledEnumerable eable = map.GetItemsInRange( location, 0 ); + IPooledEnumerable eable = map.GetItemsInRange( location, 0 ); foreach ( Item item in eable ) { @@ -136,4 +136,4 @@ namespace Server.Commands sign.MoveToWorld( location, map ); } } -} \ No newline at end of file +} diff --git a/Scripts/Commands/Statics.cs b/Scripts/Commands/Statics.cs index 0e16cd20f..ac9b69c74 100644 --- a/Scripts/Commands/Statics.cs +++ b/Scripts/Commands/Statics.cs @@ -127,7 +127,7 @@ namespace Server CommandLogging.WriteLine( from, "{0} {1} invoking freeze from {2} to {3} in {4}", from.AccessLevel, CommandLogging.Format( from ), start, end, targetMap ); - IPooledEnumerable eable = targetMap.GetItemsInBounds( new Rectangle2D( start.X, start.Y, end.X - start.X + 1, end.Y - start.Y + 1 ) ); + IPooledEnumerable eable = targetMap.GetItemsInBounds( new Rectangle2D( start.X, start.Y, end.X - start.X + 1, end.Y - start.Y + 1 ) ); foreach ( Item item in eable ) { @@ -567,4 +567,4 @@ namespace Server } } } -} \ No newline at end of file +} diff --git a/Scripts/Commands/Wipe.cs b/Scripts/Commands/Wipe.cs index c594ee70a..265842d7a 100644 --- a/Scripts/Commands/Wipe.cs +++ b/Scripts/Commands/Wipe.cs @@ -76,14 +76,10 @@ namespace Server.Commands Rectangle2D rect = new Rectangle2D( start.X, start.Y, end.X - start.X + 1, end.Y - start.Y + 1 ); - IPooledEnumerable eable; + IPooledEnumerable eable; if ( (items || multis) && mobiles ) - eable = map.GetObjectsInBounds( rect ); - else if ( items || multis ) - eable = map.GetItemsInBounds( rect ); - else if ( mobiles ) - eable = map.GetMobilesInBounds( rect ); + eable = map.GetObjectsInBounds( rect, items || multis, mobiles ); else return; @@ -103,4 +99,4 @@ namespace Server.Commands toDelete[i].Delete(); } } -} \ No newline at end of file +} diff --git a/Scripts/Engines/ConPVP/Games/BombingRun.cs b/Scripts/Engines/ConPVP/Games/BombingRun.cs index 656b7cd83..574b7ead5 100644 --- a/Scripts/Engines/ConPVP/Games/BombingRun.cs +++ b/Scripts/Engines/ConPVP/Games/BombingRun.cs @@ -172,7 +172,7 @@ namespace Server.Engines.ConPVP if ( m_Flying || !Visible || m_Game == null || this.Parent != null ) return; - IPooledEnumerable eable = this.GetClientsInRange( 0 ); + IPooledEnumerable eable = this.GetClientsInRange( 0 ); foreach ( NetState ns in eable ) { Mobile m = ns.Mobile; @@ -518,7 +518,7 @@ namespace Server.Engines.ConPVP if ( landTile.ID == 0x244 && statics.Length == 0 ) // 0x244 = invalid land tile { bool empty = true; - IPooledEnumerable eable = this.Map.GetItemsInRange( point, 0 ); + IPooledEnumerable eable = this.Map.GetItemsInRange( point, 0 ); foreach ( Item item in eable ) { @@ -559,7 +559,7 @@ namespace Server.Engines.ConPVP Rectangle2D rect = new Rectangle2D( pTop.X, pTop.Y, ( pBottom.X - pTop.X ) + 1, ( pBottom.Y - pTop.Y ) + 1 ); - IPooledEnumerable area = this.Map.GetItemsInBounds( rect ); + IPooledEnumerable area = this.Map.GetItemsInBounds( rect ); foreach ( Item i in area ) { if ( i == this || i.ItemID >= 0x4000 ) @@ -620,8 +620,8 @@ namespace Server.Engines.ConPVP area.Free(); - area = this.Map.GetClientsInBounds( rect ); - foreach ( NetState ns in area ) + IPooledEnumerable clients = this.Map.GetClientsInBounds( rect ); + foreach ( NetState ns in clients) { Mobile m = ns.Mobile; @@ -645,7 +645,7 @@ namespace Server.Engines.ConPVP if ( !found ) continue; - area.Free(); + clients.Free(); // TODO: probably need to change this a lot... DoCatch( m ); @@ -653,7 +653,7 @@ namespace Server.Engines.ConPVP return; } - area.Free(); + clients.Free(); m_PathIdx = pathCheckEnd; @@ -683,7 +683,7 @@ namespace Server.Engines.ConPVP myZ = t.Z + height; } - IPooledEnumerable eable = this.GetItemsInRange( 0 ); + IPooledEnumerable eable = this.GetItemsInRange( 0 ); foreach ( Item item in eable ) { if ( item.Visible && item != this ) diff --git a/Scripts/Engines/Craft/Core/CraftItem.cs b/Scripts/Engines/Craft/Core/CraftItem.cs index bbd878587..8633f8a21 100644 --- a/Scripts/Engines/Craft/Core/CraftItem.cs +++ b/Scripts/Engines/Craft/Core/CraftItem.cs @@ -452,7 +452,7 @@ namespace Server.Engines.Craft if ( map == null ) return false; - IPooledEnumerable eable = map.GetItemsInRange( from.Location, 2 ); + IPooledEnumerable eable = map.GetItemsInRange( from.Location, 2 ); foreach ( Item item in eable ) { diff --git a/Scripts/Engines/Craft/DefBlacksmithy.cs b/Scripts/Engines/Craft/DefBlacksmithy.cs index 72e4989e1..e57dd8153 100644 --- a/Scripts/Engines/Craft/DefBlacksmithy.cs +++ b/Scripts/Engines/Craft/DefBlacksmithy.cs @@ -64,7 +64,7 @@ namespace Server.Engines.Craft if ( map == null ) return; - IPooledEnumerable eable = map.GetItemsInRange( from.Location, range ); + IPooledEnumerable eable = map.GetItemsInRange( from.Location, range ); foreach ( Item item in eable ) { @@ -738,4 +738,4 @@ namespace Server.Engines.Craft { } } -} \ No newline at end of file +} diff --git a/Scripts/Engines/Factions/Core/Faction.cs b/Scripts/Engines/Factions/Core/Faction.cs index ac18bb57e..9b5def674 100644 --- a/Scripts/Engines/Factions/Core/Faction.cs +++ b/Scripts/Engines/Factions/Core/Faction.cs @@ -251,16 +251,12 @@ namespace Server.Factions bool mobs = type.IsSubclassOf( typeof( Mobile ) ); bool items = type.IsSubclassOf( typeof( Item ) ); - IPooledEnumerable eable; - - if ( mobs ) - eable = mob.GetMobilesInRange( range ); - else if ( items ) - eable = mob.GetItemsInRange( range ); - else + if ( !(items || mobs) ) return false; - foreach ( object obj in eable ) + IPooledEnumerable eable = mob.Map.GetObjectsInRange(mob.Location, range, items, mobs); + + foreach ( IEntity obj in eable ) { if ( type.IsAssignableFrom( obj.GetType() ) ) { @@ -275,15 +271,15 @@ namespace Server.Factions public static bool IsNearType( Mobile mob, Type[] types, int range ) { - IPooledEnumerable eable = mob.GetObjectsInRange( range ); + IPooledEnumerable eable = mob.GetObjectsInRange( range ); - foreach( object obj in eable ) + foreach( IEntity obj in eable ) { Type objType = obj.GetType(); for( int i = 0; i < types.Length; i++ ) { - if( types[i].IsAssignableFrom( objType ) ) + if ( types[i].IsAssignableFrom( objType ) ) { eable.Free(); return true; @@ -1434,4 +1430,4 @@ namespace Server.Factions } } } -} \ No newline at end of file +} diff --git a/Scripts/Engines/Khaldun/KhaldunGen.cs b/Scripts/Engines/Khaldun/KhaldunGen.cs index 7c8f867c7..341516c90 100644 --- a/Scripts/Engines/Khaldun/KhaldunGen.cs +++ b/Scripts/Engines/Khaldun/KhaldunGen.cs @@ -15,7 +15,7 @@ namespace Server.Commands public static bool FindMorphItem( int x, int y, int z, int inactiveItemID, int activeItemID ) { - IPooledEnumerable eable = Map.Felucca.GetItemsInRange( new Point3D( x, y, z ), 0 ); + IPooledEnumerable eable = Map.Felucca.GetItemsInRange( new Point3D( x, y, z ), 0 ); foreach ( Item item in eable ) { @@ -49,7 +49,7 @@ namespace Server.Commands public static Item TryCreateItem( int x, int y, int z, Item srcItem ) { - IPooledEnumerable eable = Map.Felucca.GetItemsInBounds( new Rectangle2D( x, y, 1, 1 ) ); + IPooledEnumerable eable = Map.Felucca.GetItemsInBounds( new Rectangle2D( x, y, 1, 1 ) ); foreach ( Item item in eable ) { diff --git a/Scripts/Engines/VeteranRewards/Character Statue Maker/CharacterStatue.cs b/Scripts/Engines/VeteranRewards/Character Statue Maker/CharacterStatue.cs index fbd386d3a..62d01a9e6 100644 --- a/Scripts/Engines/VeteranRewards/Character Statue Maker/CharacterStatue.cs +++ b/Scripts/Engines/VeteranRewards/Character Statue Maker/CharacterStatue.cs @@ -376,7 +376,7 @@ namespace Server.Mobiles Packet p = null; - IPooledEnumerable eable = Map.GetClientsInRange( Location ); + IPooledEnumerable eable = Map.GetClientsInRange( Location ); foreach( NetState state in eable ) { diff --git a/Scripts/Items/Addons/SHTeleporter.cs b/Scripts/Items/Addons/SHTeleporter.cs index 87e8fd04d..2937ea0af 100644 --- a/Scripts/Items/Addons/SHTeleporter.cs +++ b/Scripts/Items/Addons/SHTeleporter.cs @@ -163,14 +163,14 @@ namespace Server.Items public static SHTeleporter FindSHTeleporter( Map map, Point3D p ) { - IPooledEnumerable eable = map.GetItemsInRange( p, 0 ); + IPooledEnumerable eable = map.GetItemsInRange( p, 0 ); - foreach ( Item item in eable ) + foreach (SHTeleporter item in eable ) { - if ( item is SHTeleporter && item.Z == p.Z ) + if ( item.Z == p.Z ) { eable.Free(); - return (SHTeleporter)item; + return item; } } @@ -450,4 +450,4 @@ namespace Server.Items m_LeftTele = (SHTeleComponent)reader.ReadItem(); } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Containers/MarkContainer.cs b/Scripts/Items/Containers/MarkContainer.cs index 1ed6f535f..e9462d4d2 100644 --- a/Scripts/Items/Containers/MarkContainer.cs +++ b/Scripts/Items/Containers/MarkContainer.cs @@ -30,11 +30,11 @@ namespace Server.Items private static bool FindMarkContainer( Point3D p, Map map ) { - IPooledEnumerable eable = map.GetItemsInRange( p, 0 ); + IPooledEnumerable eable = map.GetItemsInRange( p, 0 ); foreach ( Item item in eable ) { - if ( item.Z == p.Z && item is MarkContainer ) + if ( item.Z == p.Z ) { eable.Free(); return true; @@ -264,4 +264,4 @@ namespace Server.Items m_Description = reader.ReadString(); } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Misc/Firebomb.cs b/Scripts/Items/Misc/Firebomb.cs index d8427bb7d..51650bc6d 100644 --- a/Scripts/Items/Misc/Firebomb.cs +++ b/Scripts/Items/Misc/Firebomb.cs @@ -133,12 +133,11 @@ namespace Server.Items else if ( RootParent == null ) { List toDamage = new List(); - IPooledEnumerable eable = Map.GetMobilesInRange( Location, 1 ); + IPooledEnumerable eable = Map.GetMobilesInRange( Location, 1 ); foreach ( Mobile m in eable ) - { toDamage.Add( m ); - } + eable.Free(); Mobile victim; diff --git a/Scripts/Items/Skill Items/Camping/Campfire.cs b/Scripts/Items/Skill Items/Camping/Campfire.cs index 2d165a1b9..cb2cf4e06 100644 --- a/Scripts/Items/Skill Items/Camping/Campfire.cs +++ b/Scripts/Items/Skill Items/Camping/Campfire.cs @@ -128,7 +128,7 @@ namespace Server.Items } } - IPooledEnumerable eable = this.GetClientsInRange( SecureRange ); + IPooledEnumerable eable = this.GetClientsInRange( SecureRange ); foreach ( NetState state in eable ) { @@ -214,4 +214,4 @@ namespace Server.Items m_Safe = false; } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs b/Scripts/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs index 5d3074cbf..da6adbc6c 100644 --- a/Scripts/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs +++ b/Scripts/Items/Skill Items/Magical/Potions/Explosion Potions/BaseExplosionPotion.cs @@ -252,12 +252,12 @@ namespace Server.Items if ( direct ) alchemyBonus = (int)(from.Skills.Alchemy.Value / (Core.AOS ? 5 : 10)); - IPooledEnumerable eable = LeveledExplosion ? (IPooledEnumerable)map.GetObjectsInRange( loc, ExplosionRange ) : (IPooledEnumerable)map.GetMobilesInRange( loc, ExplosionRange ); - ArrayList toExplode = new ArrayList(); + IPooledEnumerable eable = map.GetObjectsInRange(loc, ExplosionRange, LeveledExplosion, true); + List toExplode = new List(); int toDamage = 0; - foreach ( object o in eable ) + foreach ( IEntity o in eable ) { if ( o is Mobile && (from == null || (SpellHelper.ValidIndirectTarget( from, (Mobile)o ) && from.CanBeHarmful( (Mobile)o, false )))) { @@ -306,4 +306,4 @@ namespace Server.Items } } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Skill Items/Misc/FireHorn.cs b/Scripts/Items/Skill Items/Misc/FireHorn.cs index b6efbbe83..377dbeb24 100644 --- a/Scripts/Items/Skill Items/Misc/FireHorn.cs +++ b/Scripts/Items/Skill Items/Misc/FireHorn.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using Server; using Server.Network; using Server.Targeting; @@ -84,10 +84,10 @@ namespace Server.Items from.PlaySound( 0x15F ); Effects.SendPacket( from, from.Map, new HuedEffect( EffectType.Moving, from.Serial, Serial.Zero, 0x36D4, from.Location, loc, 5, 0, false, true, 0, 0 ) ); - ArrayList targets = new ArrayList(); + List targets = new List(); bool playerVsPlayer = false; - IPooledEnumerable eable = from.Map.GetMobilesInRange( new Point3D( loc ), 2 ); + IPooledEnumerable eable = from.Map.GetMobilesInRange( new Point3D( loc ), 2 ); foreach ( Mobile m in eable ) { @@ -222,4 +222,4 @@ namespace Server.Items int version = reader.ReadEncodedInt(); } } -} \ No newline at end of file +} diff --git a/Scripts/Items/Weapons/BaseWeapon.cs b/Scripts/Items/Weapons/BaseWeapon.cs index a66098712..1bf3039c1 100644 --- a/Scripts/Items/Weapons/BaseWeapon.cs +++ b/Scripts/Items/Weapons/BaseWeapon.cs @@ -1315,22 +1315,20 @@ namespace Server.Items int inPack = 1; - IPooledEnumerable eable = defender.GetMobilesInRange( 1 ); - foreach ( Mobile m in eable ) + IPooledEnumerable eable = defender.GetMobilesInRange( 1 ); + foreach ( BaseCreature m in eable ) { - if ( m != attacker && m is BaseCreature ) + if ( m != attacker ) { - BaseCreature tc = (BaseCreature)m; - - if ( (tc.PackInstinct & bc.PackInstinct) == 0 || (!tc.Controlled && !tc.Summoned) ) + if ( (m.PackInstinct & bc.PackInstinct) == 0 || (!m.Controlled && !m.Summoned) ) continue; - Mobile theirMaster = tc.ControlMaster; + Mobile theirMaster = m.ControlMaster; if ( theirMaster == null ) - theirMaster = tc.SummonMaster; + theirMaster = m.SummonMaster; - if ( master == theirMaster && tc.Combatant == defender ) + if ( master == theirMaster && m.Combatant == defender ) ++inPack; } } @@ -1365,14 +1363,10 @@ namespace Server.Items { if ( MirrorImage.HasClone( defender ) && (defender.Skills.Ninjitsu.Value / 150.0) > Utility.RandomDouble() ) { - Clone bc; - - IPooledEnumerable eable = defender.GetMobilesInRange( 4 ); - foreach ( Mobile m in eable) + IPooledEnumerable eable = defender.GetMobilesInRange( 4 ); + foreach ( Clone m in eable ) { - bc = m as Clone; - - if ( bc != null && bc.Summoned && bc.SummonMaster == defender ) + if ( m != null && m.Summoned && m.SummonMaster == defender ) { attacker.SendLocalizedMessage( 1063141 ); // Your attack has been diverted to a nearby mirror image of your target! defender.SendLocalizedMessage( 1063140 ); // You manage to divert the attack onto one of your nearby mirror images. @@ -1916,7 +1910,7 @@ namespace Server.Items int range = Core.ML ? 5 : 10; - IPooledEnumerable eable = from.GetMobilesInRange(range); + IPooledEnumerable eable = from.GetMobilesInRange(range); foreach ( Mobile m in eable ) { if ( from != m && defender != m && SpellHelper.ValidIndirectTarget( from, m ) && from.CanBeHarmful( m, false ) && ( !Core.ML || from.InLOS( m ) ) ) diff --git a/Scripts/Misc/VendorGenerator.cs b/Scripts/Misc/VendorGenerator.cs index 1ecf6f1d7..5372d64c5 100644 --- a/Scripts/Misc/VendorGenerator.cs +++ b/Scripts/Misc/VendorGenerator.cs @@ -144,15 +144,12 @@ namespace Server xTotal += fp.X; yTotal += fp.Y; - IPooledEnumerable eable = map.GetItemsInRange( new Point3D( fp.X, fp.Y, 0 ), 0 ); + IPooledEnumerable eable = map.GetItemsInRange( new Point3D( fp.X, fp.Y, 0 ), 0 ); - foreach ( Item item in eable ) + foreach ( Spawner item in eable ) { - if ( item is Spawner ) - { - hasSpawner = true; - break; - } + hasSpawner = true; + break; } eable.Free(); @@ -529,4 +526,4 @@ namespace Server } } } -} \ No newline at end of file +} diff --git a/Scripts/Misc/uoamVendors.cs b/Scripts/Misc/uoamVendors.cs index d9ace089b..bd161c62e 100644 --- a/Scripts/Misc/uoamVendors.cs +++ b/Scripts/Misc/uoamVendors.cs @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.IO; using Server.Mobiles; using Server.Items; @@ -40,7 +40,6 @@ namespace Server if ( File.Exists( vendor_path ) ) { - ArrayList list = new ArrayList(); from.SendMessage( "Generating Vendors..." ); using ( StreamReader ip = new StreamReader( vendor_path ) ) @@ -295,15 +294,14 @@ namespace Server return z; } - private static Queue m_ToDelete = new Queue(); - public static void ClearSpawners( int x, int y, int z, Map map ) { - IPooledEnumerable eable = map.GetItemsInRange( new Point3D( x, y, z ), 0 ); + IPooledEnumerable eable = map.GetItemsInRange( new Point3D( x, y, z ), 0 ); + Queue m_ToDelete = new Queue(); - foreach ( Item item in eable ) + foreach ( Spawner item in eable ) { - if ( item is Spawner && item.Z == z ) + if ( item.Z == z ) m_ToDelete.Enqueue( item ); } diff --git a/Scripts/Mobiles/AI/BaseAI.cs b/Scripts/Mobiles/AI/BaseAI.cs index bff3f8490..c9539ce6e 100644 --- a/Scripts/Mobiles/AI/BaseAI.cs +++ b/Scripts/Mobiles/AI/BaseAI.cs @@ -2078,7 +2078,7 @@ namespace Server.Mobiles int destroyables = 0; - IPooledEnumerable eable = map.GetItemsInRange(new Point3D(x, y, m_Mobile.Location.Z), 1); + IPooledEnumerable eable = map.GetItemsInRange(new Point3D(x, y, m_Mobile.Location.Z), 1); foreach (Item item in eable) { @@ -2634,7 +2634,7 @@ namespace Server.Mobiles if (srcSkill <= 0) return; - IPooledEnumerable eable = m_Mobile.GetMobilesInRange(m_Mobile.RangePerception); + IPooledEnumerable eable = m_Mobile.GetMobilesInRange(m_Mobile.RangePerception); foreach (Mobile trg in eable) { if (trg != m_Mobile && trg.Player && trg.Alive && trg.Hidden && trg.AccessLevel == AccessLevel.Player && m_Mobile.InLOS(trg)) diff --git a/Scripts/Mobiles/BaseCreature.cs b/Scripts/Mobiles/BaseCreature.cs index 9a73fe26d..656927134 100644 --- a/Scripts/Mobiles/BaseCreature.cs +++ b/Scripts/Mobiles/BaseCreature.cs @@ -5450,12 +5450,12 @@ namespace Server.Mobiles { Corpse toRummage = null; - IPooledEnumerable eable = this.GetItemsInRange(2); - foreach ( Item item in eable ) + IPooledEnumerable eable = this.GetItemsInRange(2); + foreach ( Corpse item in eable ) { - if ( item is Corpse && item.Items.Count > 0 ) + if ( item.Items.Count > 0 ) { - toRummage = (Corpse)item; + toRummage = item; break; } } diff --git a/Scripts/Mobiles/Monsters/Misc/Melee/PlagueBeast.cs b/Scripts/Mobiles/Monsters/Misc/Melee/PlagueBeast.cs index 88d18fc68..7c1dabe2f 100644 --- a/Scripts/Mobiles/Monsters/Misc/Melee/PlagueBeast.cs +++ b/Scripts/Mobiles/Monsters/Misc/Melee/PlagueBeast.cs @@ -182,20 +182,15 @@ namespace Server.Mobiles base.OnThink(); // Check to see if we need to devour any corpses - IPooledEnumerable eable = GetItemsInRange( 3 ); // Get all corpses in range + IPooledEnumerable eable = GetItemsInRange( 3 ); // Get all corpses in range - foreach( Item item in eable ) + foreach( Corpse item in eable ) { - if( item is Corpse ) // For each Corpse + // Ensure that the corpse was killed by us + if ( item.Killer == this && item.Owner != null ) { - Corpse corpse = item as Corpse; - - // Ensure that the corpse was killed by us - if( corpse != null && corpse.Killer == this && corpse.Owner != null ) - { - if( !corpse.DevourCorpse() && !corpse.Devoured ) - PublicOverheadMessage( MessageType.Emote, 0x3B2, 1053032 ); // * The plague beast attempts to absorb the remains, but cannot! * - } + if( !item.DevourCorpse() && !item.Devoured ) + PublicOverheadMessage( MessageType.Emote, 0x3B2, 1053032 ); // * The plague beast attempts to absorb the remains, but cannot! * } } eable.Free(); @@ -229,10 +224,10 @@ namespace Server.Mobiles private void IncreaseHits( int hp ) { - int maxhits = 2000; + int maxhits = 2000; - if ( this.IsParagon ) - maxhits = (int)(maxhits * Paragon.HitsBuff); + if ( this.IsParagon ) + maxhits = (int)(maxhits * Paragon.HitsBuff); if( hp < 1000 && !Core.AOS ) hp = (hp * 100) / 60; @@ -241,9 +236,9 @@ namespace Server.Mobiles { HitsMaxSeed = maxhits; - int newHits = this.Hits + hp + Utility.RandomMinMax( 10, 20 ); // increase the hp until it hits if it goes over it'll max at 2000 + int newHits = this.Hits + hp + Utility.RandomMinMax( 10, 20 ); // increase the hp until it hits if it goes over it'll max at 2000 - this.Hits = Math.Min( maxhits, newHits ); + this.Hits = Math.Min( maxhits, newHits ); // Also provide heal for each devour on top of the hp increase } else @@ -258,4 +253,4 @@ namespace Server.Mobiles } } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/PlayerMobile.cs b/Scripts/Mobiles/PlayerMobile.cs index 28333b4fd..d545dc7a3 100644 --- a/Scripts/Mobiles/PlayerMobile.cs +++ b/Scripts/Mobiles/PlayerMobile.cs @@ -605,7 +605,7 @@ namespace Server.Mobiles if ( Core.AOS ) { - IPooledEnumerable mobiles = Map.GetMobilesInRange( location, 0 ); + IPooledEnumerable mobiles = Map.GetMobilesInRange( location, 0 ); foreach ( Mobile m in mobiles ) { @@ -5175,4 +5175,4 @@ namespace Server.Mobiles m_AutoStabled.Clear(); } } -} \ No newline at end of file +} diff --git a/Scripts/Mobiles/Vendors/PlayerVendor.cs b/Scripts/Mobiles/Vendors/PlayerVendor.cs index 8b6a2d7c0..0ee269b92 100644 --- a/Scripts/Mobiles/Vendors/PlayerVendor.cs +++ b/Scripts/Mobiles/Vendors/PlayerVendor.cs @@ -1315,11 +1315,11 @@ namespace Server.Mobiles OpenBackpack( from ); else { - IPooledEnumerable mobiles = e.Mobile.GetMobilesInRange( 2 ); + IPooledEnumerable mobiles = e.Mobile.GetMobilesInRange( 2 ); - foreach ( Mobile m in mobiles ) - if ( m is PlayerVendor && m.CanSee( e.Mobile ) && m.InLOS( e.Mobile ) ) - ((PlayerVendor)m).OpenBackpack( from ); + foreach ( PlayerVendor m in mobiles ) + if ( m.CanSee( e.Mobile ) && m.InLOS( e.Mobile ) ) + m.OpenBackpack( from ); mobiles.Free(); } @@ -1741,4 +1741,4 @@ namespace Server.Mobiles Timer.DelayCall( TimeSpan.Zero, new TimerCallback( Delete ) ); } } -} \ No newline at end of file +} diff --git a/Scripts/Multis/BaseHouse.cs b/Scripts/Multis/BaseHouse.cs index 107976fde..6fa74c8bc 100644 --- a/Scripts/Multis/BaseHouse.cs +++ b/Scripts/Multis/BaseHouse.cs @@ -448,7 +448,7 @@ namespace Server.Multis vendor = false; rentalContract = false; - IPooledEnumerable eable = map.GetObjectsInRange( location, 0 ); + IPooledEnumerable eable = map.GetObjectsInRange( location, 0 ); foreach ( IEntity entity in eable ) { @@ -902,7 +902,7 @@ namespace Server.Multis List list = new List(); - IPooledEnumerable eable = this.Map.GetItemsInBounds( rect ); + IPooledEnumerable eable = this.Map.GetItemsInBounds( rect ); foreach ( Item item in eable ) if ( item.Movable && IsInside( item ) ) @@ -1689,7 +1689,7 @@ namespace Server.Multis bool valid = m_House != null && Sextant.Format( m_House.Location, m_House.Map, ref xLong, ref yLat, ref xMins, ref yMins, ref xEast, ref ySouth ); if ( valid ) - location = String.Format( "{0}° {1}'{2}, {3}° {4}'{5}", yLat, yMins, ySouth ? "S" : "N", xLong, xMins, xEast ? "E" : "W" ); + location = String.Format( "{0}° {1}'{2}, {3}° {4}'{5}", yLat, yMins, ySouth ? "S" : "N", xLong, xMins, xEast ? "E" : "W" ); else location = "unknown"; @@ -3465,14 +3465,14 @@ namespace Server.Multis return null; MultiComponentList mcl = Components; - IPooledEnumerable eable = map.GetItemsInBounds( new Rectangle2D( X + mcl.Min.X, Y + mcl.Min.Y, mcl.Width, mcl.Height ) ); + IPooledEnumerable eable = map.GetItemsInBounds( new Rectangle2D( X + mcl.Min.X, Y + mcl.Min.Y, mcl.Width, mcl.Height ) ); - foreach ( Item item in eable ) + foreach ( Guildstone item in eable ) { - if ( item is Guildstone && Contains( item ) ) + if ( Contains( item ) ) { eable.Free(); - return (Guildstone)item; + return item; } } @@ -3976,4 +3976,4 @@ namespace Server.Multis return ( from == m_RegionOwner || AccountHandler.CheckAccount( from, m_RegionOwner ) ); } } -} \ No newline at end of file +} diff --git a/Scripts/Multis/Boats/BaseBoat.cs b/Scripts/Multis/Boats/BaseBoat.cs index 4810ed655..7f24ec05d 100644 --- a/Scripts/Multis/Boats/BaseBoat.cs +++ b/Scripts/Multis/Boats/BaseBoat.cs @@ -612,7 +612,7 @@ namespace Server.Multis if ( from.AccessLevel < AccessLevel.GameMaster && from != m_Owner ) { if ( m_TillerMan != null ) - m_TillerMan.Say( Utility.Random( 1042876, 4 ) ); // Arr, don't do that! | Arr, leave me alone! | Arr, watch what thour'rt doing, matey! | Arr! Do that again and I’ll throw ye overhead! + m_TillerMan.Say( Utility.Random( 1042876, 4 ) ); // Arr, don't do that! | Arr, leave me alone! | Arr, watch what thour'rt doing, matey! | Arr! Do that again and I’ll throw ye overhead! return; } @@ -897,8 +897,8 @@ namespace Server.Multis { string sNumber = navPoint.Substring( start ); - if ( !int.TryParse( sNumber, out number ) ) - number = -1; + if ( !int.TryParse( sNumber, out number ) ) + number = -1; if ( number != -1 ) { @@ -1225,7 +1225,7 @@ namespace Server.Multis } } - IPooledEnumerable eable = map.GetItemsInBounds( new Rectangle2D( p.X + newComponents.Min.X, p.Y + newComponents.Min.Y, newComponents.Width, newComponents.Height ) ); + IPooledEnumerable eable = map.GetItemsInBounds( new Rectangle2D( p.X + newComponents.Min.X, p.Y + newComponents.Min.Y, newComponents.Width, newComponents.Height ) ); foreach ( Item item in eable ) { diff --git a/Scripts/Regions/GuardedRegion.cs b/Scripts/Regions/GuardedRegion.cs index 331783c3b..863d8e3f4 100644 --- a/Scripts/Regions/GuardedRegion.cs +++ b/Scripts/Regions/GuardedRegion.cs @@ -176,18 +176,13 @@ namespace Server.Regions { BaseGuard useGuard = null; - IPooledEnumerable eable = focus.GetMobilesInRange( 8 ); - foreach ( Mobile m in eable) + IPooledEnumerable eable = focus.GetMobilesInRange( 8 ); + foreach (BaseGuard m in eable) { - if ( m is BaseGuard ) + if ( m.Focus == null ) // idling { - BaseGuard g = (BaseGuard)m; - - if ( g.Focus == null ) // idling - { - useGuard = g; - break; - } + useGuard = m; + break; } } @@ -322,7 +317,7 @@ namespace Server.Regions if ( IsDisabled() ) return; - IPooledEnumerable eable = Map.GetMobilesInRange( p, 14 ); + IPooledEnumerable eable = Map.GetMobilesInRange( p, 14 ); foreach ( Mobile m in eable ) { diff --git a/Scripts/Skills/DetectHidden.cs b/Scripts/Skills/DetectHidden.cs index 85135d574..bdb13ead0 100644 --- a/Scripts/Skills/DetectHidden.cs +++ b/Scripts/Skills/DetectHidden.cs @@ -58,7 +58,7 @@ namespace Server.SkillHandlers if ( range > 0 ) { - IPooledEnumerable inRange = src.Map.GetMobilesInRange( p, range ); + IPooledEnumerable inRange = src.Map.GetMobilesInRange( p, range ); foreach ( Mobile trg in inRange ) { @@ -83,23 +83,18 @@ namespace Server.SkillHandlers if ( Faction.Find( src ) != null ) { - IPooledEnumerable itemsInRange = src.Map.GetItemsInRange( p, range ); + IPooledEnumerable itemsInRange = src.Map.GetItemsInRange( p, range ); - foreach ( Item item in itemsInRange ) + foreach ( BaseFactionTrap trap in itemsInRange ) { - if ( item is BaseFactionTrap ) + if ( src.CheckTargetSkill( SkillName.DetectHidden, trap, 80.0, 100.0 ) ) { - BaseFactionTrap trap = (BaseFactionTrap) item; + src.SendLocalizedMessage( 1042712, true, " " + (trap.Faction == null ? "" : trap.Faction.Definition.FriendlyName) ); // You reveal a trap placed by a faction: - if ( src.CheckTargetSkill( SkillName.DetectHidden, trap, 80.0, 100.0 ) ) - { - src.SendLocalizedMessage( 1042712, true, " " + (trap.Faction == null ? "" : trap.Faction.Definition.FriendlyName) ); // You reveal a trap placed by a faction: + trap.Visible = true; + trap.BeginConceal(); - trap.Visible = true; - trap.BeginConceal(); - - foundAnyone = true; - } + foundAnyone = true; } } diff --git a/Scripts/Skills/Snooping.cs b/Scripts/Skills/Snooping.cs index 7131bef67..20cd68fb2 100644 --- a/Scripts/Skills/Snooping.cs +++ b/Scripts/Skills/Snooping.cs @@ -67,7 +67,7 @@ namespace Server.SkillHandlers { string message = String.Format( "You notice {0} attempting to peek into {1}'s belongings.", from.Name, root.Name ); - IPooledEnumerable eable = map.GetClientsInRange( from.Location, 8 ); + IPooledEnumerable eable = map.GetClientsInRange( from.Location, 8 ); foreach ( NetState ns in eable ) { @@ -103,4 +103,4 @@ namespace Server.SkillHandlers } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Fifth/PoisonField.cs b/Scripts/Spells/Fifth/PoisonField.cs index c324a53ec..1dc1fcb99 100644 --- a/Scripts/Spells/Fifth/PoisonField.cs +++ b/Scripts/Spells/Fifth/PoisonField.cs @@ -252,7 +252,7 @@ namespace Server.Spells.Fifth if ( map != null && caster != null ) { bool eastToWest = ( m_Item.ItemID == 0x3915 ); - IPooledEnumerable eable = map.GetMobilesInBounds( new Rectangle2D( m_Item.X - (eastToWest ? 0 : 1), m_Item.Y - (eastToWest ? 1 : 0), (eastToWest ? 1 : 2), (eastToWest ? 2 : 1) ) ); + IPooledEnumerable eable = map.GetMobilesInBounds( new Rectangle2D( m_Item.X - (eastToWest ? 0 : 1), m_Item.Y - (eastToWest ? 1 : 0), (eastToWest ? 1 : 2), (eastToWest ? 2 : 1) ) ); foreach ( Mobile m in eable ) { @@ -298,4 +298,4 @@ namespace Server.Spells.Fifth } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Fourth/ArchCure.cs b/Scripts/Spells/Fourth/ArchCure.cs index 0dbcdd9a8..a2dfed733 100644 --- a/Scripts/Spells/Fourth/ArchCure.cs +++ b/Scripts/Spells/Fourth/ArchCure.cs @@ -57,7 +57,7 @@ namespace Server.Spells.Fourth if ( directTarget != null && Caster.CanBeBeneficial( directTarget, false ) ) targets.Add( directTarget ); - IPooledEnumerable eable = map.GetMobilesInRange( new Point3D( p ), 2 ); + IPooledEnumerable eable = map.GetMobilesInRange( new Point3D( p ), 2 ); foreach ( Mobile m in eable ) { @@ -187,4 +187,4 @@ namespace Server.Spells.Fourth } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Fourth/ArchProtection.cs b/Scripts/Spells/Fourth/ArchProtection.cs index ac4d46b1c..7202b1737 100644 --- a/Scripts/Spells/Fourth/ArchProtection.cs +++ b/Scripts/Spells/Fourth/ArchProtection.cs @@ -48,7 +48,7 @@ namespace Server.Spells.Fourth if ( map != null ) { - IPooledEnumerable eable = map.GetMobilesInRange( new Point3D( p ), Core.AOS ? 2 : 3 ); + IPooledEnumerable eable = map.GetMobilesInRange( new Point3D( p ), Core.AOS ? 2 : 3 ); foreach ( Mobile m in eable ) { diff --git a/Scripts/Spells/Seventh/ChainLightning.cs b/Scripts/Spells/Seventh/ChainLightning.cs index d94f2fb42..d6342405d 100644 --- a/Scripts/Spells/Seventh/ChainLightning.cs +++ b/Scripts/Spells/Seventh/ChainLightning.cs @@ -53,7 +53,7 @@ namespace Server.Spells.Seventh if ( map != null ) { - IPooledEnumerable eable = map.GetMobilesInRange( new Point3D( p ), 2 ); + IPooledEnumerable eable = map.GetMobilesInRange( new Point3D( p ), 2 ); foreach ( Mobile m in eable ) { @@ -140,4 +140,4 @@ namespace Server.Spells.Seventh } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Seventh/GateTravel.cs b/Scripts/Spells/Seventh/GateTravel.cs index a1e317c5c..198a4a413 100644 --- a/Scripts/Spells/Seventh/GateTravel.cs +++ b/Scripts/Spells/Seventh/GateTravel.cs @@ -66,7 +66,7 @@ namespace Server.Spells.Seventh { bool _gateFound = false; - IPooledEnumerable eable = map.GetItemsInRange( loc, 0 ); + IPooledEnumerable eable = map.GetItemsInRange( loc, 0 ); foreach ( Item item in eable ) { if ( item is Moongate || item is PublicMoongate ) @@ -255,4 +255,4 @@ namespace Server.Spells.Seventh } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Seventh/MassDispel.cs b/Scripts/Spells/Seventh/MassDispel.cs index e651d6abd..14a572585 100644 --- a/Scripts/Spells/Seventh/MassDispel.cs +++ b/Scripts/Spells/Seventh/MassDispel.cs @@ -49,10 +49,10 @@ namespace Server.Spells.Seventh if ( map != null ) { - IPooledEnumerable eable = map.GetMobilesInRange( new Point3D( p ), 8 ); + IPooledEnumerable eable = map.GetMobilesInRange( new Point3D( p ), 8 ); - foreach ( Mobile m in eable ) - if ( m is BaseCreature && (m as BaseCreature).IsDispellable && Caster.CanBeHarmful( m, false ) ) + foreach ( BaseCreature m in eable ) + if ( m.IsDispellable && Caster.CanBeHarmful( m, false ) ) targets.Add( m ); eable.Free(); @@ -111,4 +111,4 @@ namespace Server.Spells.Seventh } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Seventh/MeteorSwarm.cs b/Scripts/Spells/Seventh/MeteorSwarm.cs index d6258714e..e519db6c8 100644 --- a/Scripts/Spells/Seventh/MeteorSwarm.cs +++ b/Scripts/Spells/Seventh/MeteorSwarm.cs @@ -53,7 +53,7 @@ namespace Server.Spells.Seventh if ( map != null ) { - IPooledEnumerable eable = map.GetMobilesInRange( new Point3D( p ), 2 ); + IPooledEnumerable eable = map.GetMobilesInRange( new Point3D( p ), 2 ); foreach ( Mobile m in eable ) { @@ -136,4 +136,4 @@ namespace Server.Spells.Seventh } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Sixth/MassCurse.cs b/Scripts/Spells/Sixth/MassCurse.cs index 5517d287a..3eb47876e 100644 --- a/Scripts/Spells/Sixth/MassCurse.cs +++ b/Scripts/Spells/Sixth/MassCurse.cs @@ -49,7 +49,7 @@ namespace Server.Spells.Sixth if ( map != null ) { - IPooledEnumerable eable = map.GetMobilesInRange( new Point3D( p ), 2 ); + IPooledEnumerable eable = map.GetMobilesInRange( new Point3D( p ), 2 ); foreach ( Mobile m in eable ) { @@ -106,4 +106,4 @@ namespace Server.Spells.Sixth } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Sixth/Reveal.cs b/Scripts/Spells/Sixth/Reveal.cs index 8eace928c..e93ccd7cd 100644 --- a/Scripts/Spells/Sixth/Reveal.cs +++ b/Scripts/Spells/Sixth/Reveal.cs @@ -46,7 +46,7 @@ namespace Server.Spells.Sixth if ( map != null ) { - IPooledEnumerable eable = map.GetMobilesInRange( new Point3D( p ), 1 + (int)(Caster.Skills[SkillName.Magery].Value / 20.0) ); + IPooledEnumerable eable = map.GetMobilesInRange( new Point3D( p ), 1 + (int)(Caster.Skills[SkillName.Magery].Value / 20.0) ); foreach ( Mobile m in eable ) { @@ -120,4 +120,4 @@ namespace Server.Spells.Sixth } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Spellweaving/ArcaneCircle.cs b/Scripts/Spells/Spellweaving/ArcaneCircle.cs index 96c70b933..b948d2bf9 100644 --- a/Scripts/Spells/Spellweaving/ArcaneCircle.cs +++ b/Scripts/Spells/Spellweaving/ArcaneCircle.cs @@ -86,7 +86,7 @@ namespace Server.Spells.Spellweaving return true; } - IPooledEnumerable eable = map.GetItemsInRange( location, 0 ); // Added Tiles + IPooledEnumerable eable = map.GetItemsInRange( location, 0 ); // Added Tiles foreach( Item item in eable ) { @@ -162,4 +162,4 @@ namespace Server.Spells.Spellweaving } } } -} \ No newline at end of file +} diff --git a/Scripts/Spells/Third/Teleport.cs b/Scripts/Spells/Third/Teleport.cs index ce6733415..bc4dcbd2b 100644 --- a/Scripts/Spells/Third/Teleport.cs +++ b/Scripts/Spells/Third/Teleport.cs @@ -100,7 +100,7 @@ namespace Server.Spells.Third m.PlaySound( 0x1FE ); - IPooledEnumerable eable = m.GetItemsInRange( 0 ); + IPooledEnumerable eable = m.GetItemsInRange( 0 ); foreach ( Item item in eable ) { @@ -137,4 +137,4 @@ namespace Server.Spells.Third } } } -} \ No newline at end of file +} diff --git a/Server/Map.cs b/Server/Map.cs index 603b29a46..542c64e35 100644 --- a/Server/Map.cs +++ b/Server/Map.cs @@ -172,8 +172,8 @@ namespace Server { ClientSelector = SelectClients; EntitySelector = SelectEntities; - MobileSelector = SelectMobiles; - ItemSelector = SelectItems; + MobileSelector = SelectMobiles; + ItemSelector = SelectItems; MultiSelector = SelectMultis; MultiTileSelector = SelectMultiTiles; } @@ -185,21 +185,27 @@ namespace Server public static IEnumerable SelectEntities(Sector s, Rectangle2D bounds) { - return - Enumerable.Empty() - .Union(s.Mobiles.Where(o => o != null && !o.Deleted)) - .Union(s.Items.Where(o => o != null && !o.Deleted && o.Parent == null)) - .Where(bounds.Contains); + return SelectEntities(s, true, true, bounds); } - public static IEnumerable SelectMobiles(Sector s, Rectangle2D bounds) + public static IEnumerable SelectEntities(Sector s, bool items, bool mobiles, Rectangle2D bounds) { - return s.Mobiles.Where(o => o != null && !o.Deleted && bounds.Contains(o)); + IEnumerable eable = Enumerable.Empty(); + if (mobiles) + eable = eable.Union(s.Mobiles.Where(o => o != null && !o.Deleted)); + if (items) + eable = eable.Union(s.Items.Where(o => o != null && !o.Deleted && o.Parent == null)); + + return eable.Where(bounds.Contains); } - public static IEnumerable SelectItems(Sector s, Rectangle2D bounds) + public static IEnumerable SelectMobiles(Sector s, Rectangle2D bounds) where T : Mobile { - return s.Items.Where(o => o != null && !o.Deleted && o.Parent == null && bounds.Contains(o)); + return s.Mobiles.OfType().Where(o => o != null && !o.Deleted && bounds.Contains(o)); + } + public static IEnumerable SelectItems(Sector s, Rectangle2D bounds) where T : Item + { + return s.Items.OfType().Where(o => o != null && !o.Deleted && o.Parent == null && o is T && bounds.Contains(o)); } public static IEnumerable SelectMultis(Sector s, Rectangle2D bounds) @@ -261,18 +267,26 @@ namespace Server } public static Map.PooledEnumerable GetEntities(Map map, Rectangle2D bounds) + { + return GetEntities(map, bounds, true, true); + } + + public static Map.PooledEnumerable GetEntities(Map map, Rectangle2D bounds, bool items, bool mobiles) { return Map.PooledEnumerable.Instantiate(map, bounds, EntitySelector ?? SelectEntities); } public static Map.PooledEnumerable GetMobiles(Map map, Rectangle2D bounds) { - return Map.PooledEnumerable.Instantiate(map, bounds, MobileSelector ?? SelectMobiles); + return GetMobiles(map, bounds); } - - public static Map.PooledEnumerable GetItems(Map map, Rectangle2D bounds) + public static Map.PooledEnumerable GetMobiles(Map map, Rectangle2D bounds) where T : Mobile { - return Map.PooledEnumerable.Instantiate(map, bounds, ItemSelector ?? SelectItems); + return Map.PooledEnumerable.Instantiate(map, bounds, SelectMobiles); + } + public static Map.PooledEnumerable GetItems(Map map, Rectangle2D bounds) where T : Item + { + return Map.PooledEnumerable.Instantiate(map, bounds, SelectItems); } public static Map.PooledEnumerable GetMultis(Map map, Rectangle2D bounds) @@ -615,10 +629,20 @@ namespace Server public IPooledEnumerable GetObjectsInRange(Point3D p, int range) { - return GetObjectsInBounds(new Rectangle2D(p.m_X - range, p.m_Y - range, range * 2 + 1, range * 2 + 1)); + return GetObjectsInRange(p, range, true, true); + } + + public IPooledEnumerable GetObjectsInRange(Point3D p, int range, bool items, bool mobiles) + { + return GetObjectsInBounds(new Rectangle2D(p.m_X - range, p.m_Y - range, range * 2 + 1, range * 2 + 1), items, mobiles); } public IPooledEnumerable GetObjectsInBounds(Rectangle2D bounds) + { + return GetObjectsInBounds(bounds, true, true); + } + + public IPooledEnumerable GetObjectsInBounds(Rectangle2D bounds, bool items, bool mobiles) { return PooledEnumeration.GetEntities(this, bounds); } @@ -650,15 +674,21 @@ namespace Server return GetItemsInRange(p, 18); #endif } - public IPooledEnumerable GetItemsInRange(Point3D p, int range) { - return GetItemsInBounds(new Rectangle2D(p.m_X - range, p.m_Y - range, range * 2 + 1, range * 2 + 1)); + return GetItemsInRange(p, range); + } + public IPooledEnumerable GetItemsInRange(Point3D p, int range) where T : Item + { + return GetItemsInBounds(new Rectangle2D(p.m_X - range, p.m_Y - range, range * 2 + 1, range * 2 + 1)); } - public IPooledEnumerable GetItemsInBounds(Rectangle2D bounds) { - return PooledEnumeration.GetItems(this, bounds); + return GetItemsInBounds(bounds); + } + public IPooledEnumerable GetItemsInBounds(Rectangle2D bounds) where T : Item + { + return PooledEnumeration.GetItems(this, bounds); } public IPooledEnumerable GetMobilesInRange(Point3D p) @@ -672,12 +702,22 @@ namespace Server public IPooledEnumerable GetMobilesInRange(Point3D p, int range) { - return GetMobilesInBounds(new Rectangle2D(p.m_X - range, p.m_Y - range, range * 2 + 1, range * 2 + 1)); + return GetMobilesInRange(p, range); + } + + public IPooledEnumerable GetMobilesInRange(Point3D p, int range) where T : Mobile + { + return GetMobilesInBounds(new Rectangle2D(p.m_X - range, p.m_Y - range, range * 2 + 1, range * 2 + 1)); } public IPooledEnumerable GetMobilesInBounds(Rectangle2D bounds) { - return PooledEnumeration.GetMobiles(this, bounds); + return GetMobilesInBounds(bounds); + } + + public IPooledEnumerable GetMobilesInBounds(Rectangle2D bounds) where T : Mobile + { + return PooledEnumeration.GetMobiles(this, bounds); } #endregion diff --git a/Server/Mobile.cs b/Server/Mobile.cs index 1d86495a0..30c55939c 100644 --- a/Server/Mobile.cs +++ b/Server/Mobile.cs @@ -4710,15 +4710,18 @@ namespace Server } #region Get*InRange - - public IPooledEnumerable GetItemsInRange( int range ) + public IPooledEnumerable GetItemsInRange(int range) + { + return GetItemsInRange(range); + } + public IPooledEnumerable GetItemsInRange( int range ) where T : Item { Map map = m_Map; if( map == null ) - return Server.Map.NullEnumerable.Instance; + return Server.Map.NullEnumerable.Instance; - return map.GetItemsInRange( m_Location, range ); + return map.GetItemsInRange( m_Location, range ); } public IPooledEnumerable GetObjectsInRange( int range ) @@ -4732,13 +4735,17 @@ namespace Server } public IPooledEnumerable GetMobilesInRange( int range ) + { + return GetMobilesInRange(range); + } + public IPooledEnumerable GetMobilesInRange(int range) where T : Mobile { Map map = m_Map; - if( map == null ) - return Server.Map.NullEnumerable.Instance; + if (map == null) + return Server.Map.NullEnumerable.Instance; - return map.GetMobilesInRange( m_Location, range ); + return map.GetMobilesInRange(m_Location, range); } public IPooledEnumerable GetClientsInRange(int range) diff --git a/Server/Network/PacketHandlers.cs b/Server/Network/PacketHandlers.cs index 60a1ef2ab..e4a1aa7b6 100644 --- a/Server/Network/PacketHandlers.cs +++ b/Server/Network/PacketHandlers.cs @@ -2084,10 +2084,10 @@ namespace Server.Network if ( match ) authOK = true; } - else - { - pvSrc.Seek( 16, SeekOrigin.Current ); - } + else + { + pvSrc.Seek( 16, SeekOrigin.Current ); + } ThirdPartyAuthCallback( state, authOK ); } @@ -2734,4 +2734,4 @@ namespace Server.Network state.Dispose(); } } -} \ No newline at end of file +}