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

@ -873,7 +873,7 @@ namespace Server.Commands
bool res = false;
IPooledEnumerable eable;
IPooledEnumerable<Item> eable;
if ( srcItem is BaseDoor )
{
@ -1002,16 +1002,16 @@ namespace Server.Commands
if ( item is BaseDoor )
{
IPooledEnumerable eable = maps[j].GetItemsInRange( loc, 1 );
IPooledEnumerable<BaseDoor> eable = maps[j].GetItemsInRange<BaseDoor>( 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
}
}
}
}
}

View file

@ -870,7 +870,7 @@ namespace Server.Commands
bool res = false;
IPooledEnumerable eable;
IPooledEnumerable<Item> eable;
if ( srcItem is BaseDoor )
{
@ -999,16 +999,16 @@ namespace Server.Commands
if ( item is BaseDoor )
{
IPooledEnumerable eable = maps[j].GetItemsInRange( loc, 1 );
IPooledEnumerable<BaseDoor> eable = maps[j].GetItemsInRange<BaseDoor>( 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;
}
}

View file

@ -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<Item> m_Queue = new Queue<Item>();
public static bool FindTeleporter( Map map, Point3D p )
{
IPooledEnumerable eable = map.GetItemsInRange( p, 0 );
IPooledEnumerable<Item> 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<Item> 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 )

View file

@ -181,4 +181,4 @@ namespace Server.Commands.Generic
{
}
}
}
}

View file

@ -86,4 +86,4 @@ namespace Server.Commands.Generic
}
}
}
}
}

View file

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

View file

@ -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<Item> eable = map.GetItemsInRange( location, 0 );
foreach ( Item item in eable )
{
@ -136,4 +136,4 @@ namespace Server.Commands
sign.MoveToWorld( location, map );
}
}
}
}

View file

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

View file

@ -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<IEntity> 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();
}
}
}
}