public void IterateOneFullSector()
    {
        var e = new SectorEnumerator(new Rectangle(64, 64, 64, 64), false);

        e.MoveNext().IsSameOrEqualTo(true);
        e.Current.IsSameOrEqualTo(
            new PartialSector(new SectorLoc(1, 1), true, new Rectangle(0, 0, 64, 64), default));
        e.MoveNext().IsSameOrEqualTo(false);
    }
    public void IterateSingleTileInMiddle()
    {
        var e = new SectorEnumerator(new Rectangle(10, 10, 1, 1), false);

        e.MoveNext().IsSameOrEqualTo(true);
        e.Current.IsSameOrEqualTo(new PartialSector(new SectorLoc(0, 0), false, new Rectangle(10, 10, 1, 1),
                                                    default));
        e.MoveNext().IsSameOrEqualTo(false);
    }
Example #3
0
			public bool MoveNext()
			{
				while ( true )
				{
					if ( m_Enumerator.MoveNext() )
					{
						object o;

						try
						{
							o = m_Enumerator.Current;
						}
						catch
						{
							continue;
						}

						if ( o is Mobile )
						{
							Mobile m = (Mobile) o;

							if ( !m.Deleted && m_Bounds.Contains( m.Location ) )
							{
								m_Current = o;
								return true;
							}
						}
						else if ( o is Item )
						{
							Item item = (Item) o;

							if ( !item.Deleted && item.Parent == null && m_Bounds.Contains( item.Location ) )
							{
								m_Current = o;
								return true;
							}
						}
						else if ( o is NetState )
						{
							Mobile m = ( (NetState) o ).Mobile;

							if ( m != null && !m.Deleted && m_Bounds.Contains( m.Location ) )
							{
								m_Current = o;
								return true;
							}
						}
					}
					else
					{
						m_Current = null;

						m_Enumerator.Free();
						m_Enumerator = null;

						return false;
					}
				}
			}
Example #4
0
			public bool MoveNext()
			{
				while ( true )
				{
					if ( m_Enumerator.MoveNext() )
					{
						object o;

						try
						{
							o = m_Enumerator.Current;
						}
						catch
						{
							continue;
						}

						if ( o is Mobile )
						{
							Mobile m = (Mobile) o;

							if ( m_Bounds.Contains( m.Location ) )
							{
								m_Current = o;
								return true;
							}
						}
						else if ( o is Item )
						{
							Item item = (Item) o;

							if ( item.Parent == null && m_Bounds.Contains( item.Location ) )
							{
								m_Current = o;
								return true;
							}
						}
					}
					else if ( m_Stage == 0 )
					{
						m_Enumerator.Free();
						m_Enumerator = SectorEnumerator.Instantiate( m_Map, m_Bounds, SectorEnumeratorType.Mobiles );

						m_Current = null;
						m_Stage = 1;
					}
					else
					{
						m_Enumerator.Free();
						m_Enumerator = null;

						m_Current = null;
						m_Stage = -1;

						return false;
					}
				}
			}
    public void IterateFourTilesSpanningFourSectors()
    {
        var e = new SectorEnumerator(new Rectangle(63, 63, 2, 2), false);

        e.MoveNext().IsSameOrEqualTo(true);
        e.Current.IsSameOrEqualTo(new PartialSector(new SectorLoc(0, 0), false, new Rectangle(63, 63, 1, 1),
                                                    default));
        e.MoveNext().IsSameOrEqualTo(true);
        e.Current.IsSameOrEqualTo(
            new PartialSector(new SectorLoc(1, 0), false, new Rectangle(0, 63, 1, 1), default));
        e.MoveNext().IsSameOrEqualTo(true);
        e.Current.IsSameOrEqualTo(new PartialSector(new SectorLoc(0, 1), false, new Rectangle(63, 63, 1, 1),
                                                    default));
        e.MoveNext().IsSameOrEqualTo(true);
        e.Current.IsSameOrEqualTo(new PartialSector(new SectorLoc(1, 1), false, new Rectangle(63, 63, 1, 1),
                                                    default));
        e.MoveNext().IsSameOrEqualTo(false);
    }
    public void IterateThreeByThreeSectorsWithOneTileBorder()
    {
        var e = new SectorEnumerator(new Rectangle(1, 1, 64 * 3 - 2, 64 * 3 - 2), false);

        // First Row of 3x3
        e.MoveNext().Should().BeTrue();
        e.Current.SectorLoc.Should().Be(new SectorLoc(0, 0));
        e.Current.TileRectangle.Should().Be(new Rectangle(1, 1, 63, 63));
        e.MoveNext().Should().BeTrue();
        e.Current.SectorLoc.Should().Be(new SectorLoc(1, 0));
        e.Current.TileRectangle.Should().Be(new Rectangle(0, 1, 64, 63));
        e.MoveNext().Should().BeTrue();
        e.Current.SectorLoc.Should().Be(new SectorLoc(2, 0));
        e.Current.TileRectangle.Should().Be(new Rectangle(0, 1, 63, 63));

        // Second Row of 3x3
        e.MoveNext().Should().BeTrue();
        e.Current.SectorLoc.Should().Be(new SectorLoc(0, 1));
        e.Current.TileRectangle.Should().Be(new Rectangle(1, 0, 63, 64));
        e.MoveNext().Should().BeTrue();
        e.Current.SectorLoc.Should().Be(new SectorLoc(1, 1));
        e.Current.TileRectangle.Should().Be(new Rectangle(0, 0, 64, 64));
        e.MoveNext().Should().BeTrue();
        e.Current.SectorLoc.Should().Be(new SectorLoc(2, 1));
        e.Current.TileRectangle.Should().Be(new Rectangle(0, 0, 63, 64));

        // Third Row of 3x3
        e.MoveNext().Should().BeTrue();
        e.Current.SectorLoc.Should().Be(new SectorLoc(0, 2));
        e.Current.TileRectangle.Should().Be(new Rectangle(1, 0, 63, 63));
        e.MoveNext().Should().BeTrue();
        e.Current.SectorLoc.Should().Be(new SectorLoc(1, 2));
        e.Current.TileRectangle.Should().Be(new Rectangle(0, 0, 64, 63));
        e.MoveNext().Should().BeTrue();
        e.Current.SectorLoc.Should().Be(new SectorLoc(2, 2));
        e.Current.TileRectangle.Should().Be(new Rectangle(0, 0, 63, 63));

        e.MoveNext().Should().BeFalse();
    }
    public void IterateEmpty()
    {
        SectorEnumerator e = default;

        e.MoveNext().IsSameOrEqualTo(false);
    }