fix: Removes GetObjectsInRange and fixes boat planks closing (#1579)

## BREAKING CHANGE

- Deletes `map.GetObjectsInRange` and `map.GetObejctsInBounds`

### Notes

Developers are expected to enumerate mobiles and items separately now using `map.GetMobilesInRange` and `map.GetItemsInRange`. This helps keep the code streamlined so we don't have to maintain multiple copies of ref struct enumerators that do the same thing.


### Fixes

- [X] Fixes bug with planks closing
- [X] Fixes issue with iterating items/mobiles from a null map
This commit is contained in:
Kamron Batman 2023-11-03 13:45:18 -07:00 • committed by GitHub
parent cb1638591b
commit 977fdc2c5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 543 additions and 461 deletions

View file

@ -255,25 +255,25 @@ namespace Server.Factions
public static bool IsNearType(Mobile mob, Type type, int range)
{
var mobs = type.IsSubclassOf(typeof(Mobile));
var items = type.IsSubclassOf(typeof(Item));
if (!(items || mobs))
if (type.IsAssignableTo(typeof(Mobile)))
{
return false;
foreach (var obj in mob.Map.GetMobilesInRange(mob.Location, range))
{
if (type.IsInstanceOfType(obj))
{
return true;
}
}
}
var eable = mob.Map.GetObjectsInRange(mob.Location, range);
foreach (var obj in eable)
if (type.IsAssignableTo(typeof(Item)))
{
if (!mobs && obj is Mobile || !items && obj is Item)
foreach (var item in mob.Map.GetItemsInRange(mob.Location, range))
{
continue;
}
if (type.IsInstanceOfType(obj))
{
return true;
if (type.IsInstanceOfType(item))
{
return true;
}
}
}
@ -282,17 +282,44 @@ namespace Server.Factions
public static bool IsNearType(Mobile mob, Type[] types, int range)
{
var eable = mob.GetObjectsInRange(range);
foreach (var obj in eable)
bool mobs = false;
bool items = false;
for (var i = 0; !(mobs && items) && i < types.Length; i++)
{
for (int i = 0; i < types.Length; i++)
var type = types[i];
if (type.IsAssignableTo(typeof(Mobile)))
{
if (types[i].IsInstanceOfType(obj))
mobs = true;
}
if (type.IsAssignableTo(typeof(Item)))
{
items = true;
}
}
if (mobs)
{
foreach (var m in mob.Map.GetMobilesInRange(mob.Location, range))
{
if (m.InTypeList(types))
{
return true;
}
}
}
if (items)
{
foreach (var item in mob.Map.GetItemsInRange(mob.Location, range))
{
if (item.InTypeList(types))
{
return true;
}
}
}
return false;
}

View file

@ -81,43 +81,9 @@ namespace Server.Movement
var checkMobs = (m as BaseCreature)?.Controlled == false && (xForward != _goal.X || yForward != _goal.Y);
foreach (var entity in map.GetObjectsInRange(loc, 1))
if (checkMobs)
{
if (entity is Item item)
{
if (ignoreMovableImpassables && item.Movable && item.ItemData.ImpassableSurface)
{
continue;
}
if (!item.ItemData[reqFlags] || item.ItemID > TileData.MaxItemValue || item.Parent != null)
{
continue;
}
if (item is BaseMulti)
{
continue;
}
if (item.AtPoint(xStart, yStart))
{
itemsStart.Add(item);
}
else if (item.AtPoint(xForward, yForward))
{
itemsForward.Add(item);
}
else if (checkDiagonals && item.AtPoint(xLeft, yLeft))
{
itemsLeft.Add(item);
}
else if (checkDiagonals && item.AtPoint(xRight, yRight))
{
itemsRight.Add(item);
}
}
else if (checkMobs && entity is Mobile mob)
foreach (var mob in map.GetMobilesInRange(loc, 1))
{
if (mob.AtPoint(xForward, yForward))
{
@ -134,6 +100,41 @@ namespace Server.Movement
}
}
foreach (var item in map.GetItemsInRange(loc, 1))
{
if (ignoreMovableImpassables && item.Movable && item.ItemData.ImpassableSurface)
{
continue;
}
if (!item.ItemData[reqFlags] || item.ItemID > TileData.MaxItemValue || item.Parent != null)
{
continue;
}
if (item is BaseMulti)
{
continue;
}
if (item.AtPoint(xStart, yStart))
{
itemsStart.Add(item);
}
else if (item.AtPoint(xForward, yForward))
{
itemsForward.Add(item);
}
else if (checkDiagonals && item.AtPoint(xLeft, yLeft))
{
itemsLeft.Add(item);
}
else if (checkDiagonals && item.AtPoint(xRight, yRight))
{
itemsRight.Add(item);
}
}
GetStartZ(m, map, loc, itemsStart, out var startZ, out var startTop);
var moveIsOk = Check(map, m, itemsForward, mobsForward, xForward, yForward, startTop, startZ, out newZ);