Adds better type support for pooled enumerables. Refactors code. (#16)

This commit is contained in:
Kamron Batman 2018-08-09 14:08:34 -07:00 committed by GitHub
parent 62b95f4d74
commit b06f5bf60d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 252 additions and 243 deletions

View file

@ -163,14 +163,14 @@ namespace Server.Items
public static SHTeleporter FindSHTeleporter( Map map, Point3D p )
{
IPooledEnumerable eable = map.GetItemsInRange( p, 0 );
IPooledEnumerable<SHTeleporter> eable = map.GetItemsInRange<SHTeleporter>( 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();
}
}
}
}

View file

@ -30,11 +30,11 @@ namespace Server.Items
private static bool FindMarkContainer( Point3D p, Map map )
{
IPooledEnumerable eable = map.GetItemsInRange( p, 0 );
IPooledEnumerable<MarkContainer> eable = map.GetItemsInRange<MarkContainer>( 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();
}
}
}
}

View file

@ -133,12 +133,11 @@ namespace Server.Items
else if ( RootParent == null )
{
List<Mobile> toDamage = new List<Mobile>();
IPooledEnumerable eable = Map.GetMobilesInRange( Location, 1 );
IPooledEnumerable<Mobile> eable = Map.GetMobilesInRange( Location, 1 );
foreach ( Mobile m in eable )
{
toDamage.Add( m );
}
eable.Free();
Mobile victim;

View file

@ -128,7 +128,7 @@ namespace Server.Items
}
}
IPooledEnumerable eable = this.GetClientsInRange( SecureRange );
IPooledEnumerable<NetState> eable = this.GetClientsInRange( SecureRange );
foreach ( NetState state in eable )
{
@ -214,4 +214,4 @@ namespace Server.Items
m_Safe = false;
}
}
}
}

View file

@ -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<IEntity> eable = map.GetObjectsInRange(loc, ExplosionRange, LeveledExplosion, true);
List<IEntity> toExplode = new List<IEntity>();
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
}
}
}
}
}

View file

@ -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<Mobile> targets = new List<Mobile>();
bool playerVsPlayer = false;
IPooledEnumerable eable = from.Map.GetMobilesInRange( new Point3D( loc ), 2 );
IPooledEnumerable<Mobile> eable = from.Map.GetMobilesInRange( new Point3D( loc ), 2 );
foreach ( Mobile m in eable )
{
@ -222,4 +222,4 @@ namespace Server.Items
int version = reader.ReadEncodedInt();
}
}
}
}

View file

@ -1315,22 +1315,20 @@ namespace Server.Items
int inPack = 1;
IPooledEnumerable eable = defender.GetMobilesInRange( 1 );
foreach ( Mobile m in eable )
IPooledEnumerable<BaseCreature> eable = defender.GetMobilesInRange<BaseCreature>( 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<Clone> eable = defender.GetMobilesInRange<Clone>( 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<Mobile> 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 ) ) )