fix: Adds multis to map iterators, fixes searching empty nested containers (#1581)
### Summary
Eliminates `IPooledEnumerable<BaseMulti>` and `eable.Free()` from `Map` for multis. This drastically simplifies code that iterates in range, for example:
```cs
foreach (var m in m.GetMultisInRange(5))
{
}
```
The code above no longer requires an eable and calling `Free()`.
### Bug Fixes
- [X] Fixes an issue with searching through nested empty containers.
This commit is contained in:
parent
1f04a13f67
commit
ca3df9cfa7
12 changed files with 960 additions and 860 deletions
|
|
@ -243,11 +243,9 @@ namespace Server.Multis
|
|||
|
||||
public static BaseBoat FindBoatAt(Point3D loc, Map map)
|
||||
{
|
||||
var sector = map.GetSector(loc);
|
||||
|
||||
for (var i = 0; i < sector.Multis.Count; i++)
|
||||
foreach (var boat in map.GetMultisAt<BaseBoat>(loc))
|
||||
{
|
||||
if (sector.Multis[i] is BaseBoat boat && boat.Contains(loc.X, loc.Y))
|
||||
if (boat.Contains(loc.X, loc.Y))
|
||||
{
|
||||
return boat;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1401,11 +1401,9 @@ namespace Server.Multis
|
|||
return null;
|
||||
}
|
||||
|
||||
var sector = map.GetSector(loc);
|
||||
|
||||
for (var i = 0; i < sector.Multis.Count; ++i)
|
||||
foreach (var house in map.GetMultisAt<BaseHouse>(loc))
|
||||
{
|
||||
if (sector.Multis[i] is BaseHouse house && house.IsInside(loc, height))
|
||||
if (house.IsInside(loc, height))
|
||||
{
|
||||
return house;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -370,58 +370,35 @@ namespace Server.Multis
|
|||
}
|
||||
}
|
||||
|
||||
var _sectors = new List<Map.Sector>();
|
||||
var _houses = new List<BaseHouse>();
|
||||
|
||||
for (var i = 0; i < yard.Count; i++)
|
||||
{
|
||||
var sector = map.GetSector(yard[i]);
|
||||
var yardPoint = yard[i];
|
||||
|
||||
if (!_sectors.Contains(sector))
|
||||
foreach (var house in map.GetMultisAt<BaseHouse>(yardPoint))
|
||||
{
|
||||
_sectors.Add(sector);
|
||||
|
||||
for (var j = 0; j < sector.Multis?.Count; j++)
|
||||
{
|
||||
if (sector.Multis[j] is BaseHouse)
|
||||
{
|
||||
var _house = (BaseHouse)sector.Multis[j];
|
||||
if (!_houses.Contains(_house))
|
||||
{
|
||||
_houses.Add(_house);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < yard.Count; ++i)
|
||||
{
|
||||
foreach (var b in _houses)
|
||||
{
|
||||
if (b.Contains(yard[i]))
|
||||
if (house.Contains(yard[i]))
|
||||
{
|
||||
return HousePlacementResult.BadStatic; // Broke rule #3
|
||||
}
|
||||
}
|
||||
}
|
||||
/*Point2D yardPoint = yard[i];
|
||||
|
||||
IPooledEnumerable eable = map.GetMultiTilesAt( yardPoint.X, yardPoint.Y );
|
||||
|
||||
foreach ( StaticTile[] tile in eable )
|
||||
{
|
||||
for ( int j = 0; j < tile.Length; ++j )
|
||||
{
|
||||
if ((TileData.ItemTable[tile[j].ID & TileData.MaxItemValue].Flags & (TileFlag.Impassable | TileFlag.Surface)) != 0)
|
||||
{
|
||||
eable.Free();
|
||||
return HousePlacementResult.BadStatic; // Broke rule #3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
eable.Free();*/
|
||||
// TODO: Should we check for MultiTilesAt each yard point?
|
||||
// for (var i = 0; i < yard.Count; i++)
|
||||
// {
|
||||
// var yardPoint = yard[i];
|
||||
//
|
||||
// foreach (var tiles in map.GetMultiTilesAt(yardPoint))
|
||||
// {
|
||||
// for (int j = 0; j < tiles.Length; ++j)
|
||||
// {
|
||||
// if ((TileData.ItemTable[tiles[j].ID & TileData.MaxItemValue].Flags & (TileFlag.Impassable | TileFlag.Surface)) != 0)
|
||||
// {
|
||||
// return HousePlacementResult.BadStatic; // Broke rule #3
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
return HousePlacementResult.Valid;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue