Core/Map: Change all foreach loops over objects in maps to for loops, Fixes Collection was modified enumeration operation may not execute
This commit is contained in:
@@ -596,53 +596,56 @@ namespace Game.Entities
|
||||
|
||||
public override void Visit(IList<Player> objs)
|
||||
{
|
||||
foreach (var target in objs)
|
||||
for (var i = 0; i < objs.Count; ++i)
|
||||
{
|
||||
if (!IsInRangeHelper(target))
|
||||
Player player = objs[i];
|
||||
if (!IsInRangeHelper(player))
|
||||
continue;
|
||||
|
||||
// Send packet to all who are sharing the player's vision
|
||||
if (target.HasSharedVision())
|
||||
if (player.HasSharedVision())
|
||||
{
|
||||
foreach (var visionTarget in target.GetSharedVisionList())
|
||||
if (visionTarget.seerView == target)
|
||||
foreach (var visionTarget in player.GetSharedVisionList())
|
||||
if (visionTarget.seerView == player)
|
||||
SendPacket(visionTarget);
|
||||
}
|
||||
|
||||
if (target.seerView == target || target.GetVehicle())
|
||||
SendPacket(target);
|
||||
if (player.seerView == player || player.GetVehicle())
|
||||
SendPacket(player);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Visit(IList<Creature> objs)
|
||||
{
|
||||
foreach (var target in objs)
|
||||
for (var i = 0; i < objs.Count; ++i)
|
||||
{
|
||||
if (!IsInRangeHelper(target))
|
||||
Creature creature = objs[i];
|
||||
if (!IsInRangeHelper(creature))
|
||||
continue;
|
||||
|
||||
// Send packet to all who are sharing the creature's vision
|
||||
if (target.HasSharedVision())
|
||||
if (creature.HasSharedVision())
|
||||
{
|
||||
foreach (var visionTarget in target.GetSharedVisionList())
|
||||
if (visionTarget.seerView == target)
|
||||
foreach (var visionTarget in creature.GetSharedVisionList())
|
||||
if (visionTarget.seerView == creature)
|
||||
SendPacket(visionTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
public override void Visit(IList<DynamicObject> objs)
|
||||
{
|
||||
foreach (var target in objs)
|
||||
for (var i = 0; i < objs.Count; ++i)
|
||||
{
|
||||
if (!IsInRangeHelper(target))
|
||||
DynamicObject dynamicObject = objs[i];
|
||||
if (!IsInRangeHelper(dynamicObject))
|
||||
continue;
|
||||
|
||||
Unit caster = target.GetCaster();
|
||||
Unit caster = dynamicObject.GetCaster();
|
||||
if (caster)
|
||||
{
|
||||
// Send packet back to the caster if the caster has vision of dynamic object
|
||||
Player player = caster.ToPlayer();
|
||||
if (player && player.seerView == target)
|
||||
if (player && player.seerView == dynamicObject)
|
||||
SendPacket(player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1663,15 +1663,21 @@ namespace Game
|
||||
|
||||
public override void Visit(IList<Creature> objs)
|
||||
{
|
||||
foreach (var creature in objs)
|
||||
for (var i = 0; i < objs.Count; ++i)
|
||||
{
|
||||
Creature creature = objs[i];
|
||||
if (creature.IsInWorld && creature.IsAIEnabled)
|
||||
creature.GetAI().OnGameEvent(_activate, _eventId);
|
||||
}
|
||||
}
|
||||
public override void Visit(IList<GameObject> objs)
|
||||
{
|
||||
foreach (var gameobject in objs)
|
||||
if (gameobject.IsInWorld)
|
||||
gameobject.GetAI().OnGameEvent(_activate, _eventId);
|
||||
for (var i = 0; i < objs.Count; ++i)
|
||||
{
|
||||
GameObject gameObject = objs[i];
|
||||
if (gameObject.IsInWorld)
|
||||
gameObject.GetAI().OnGameEvent(_activate, _eventId);
|
||||
}
|
||||
}
|
||||
|
||||
ushort _eventId;
|
||||
|
||||
@@ -293,7 +293,7 @@ namespace Game.Maps
|
||||
visitor.Visit(_container.corpses);
|
||||
visitor.Visit(_container.areaTriggers);
|
||||
visitor.Visit(_container.conversations);
|
||||
visitor.Visit(_container.worldObjects.ToArray());
|
||||
visitor.Visit(_container.worldObjects);
|
||||
break;
|
||||
case GridMapTypeMask.AllWorld:
|
||||
visitor.Visit(_objects.players);
|
||||
|
||||
+278
-181
File diff suppressed because it is too large
Load Diff
@@ -248,8 +248,8 @@ namespace Game.Entities
|
||||
{
|
||||
GridCoord p = GridDefines.ComputeGridCoord(x, y);
|
||||
|
||||
uint gx = 63 - p.X_coord;
|
||||
uint gy = 63 - p.Y_coord;
|
||||
uint gx = (MapConst.MaxGrids - 1) - p.X_coord;
|
||||
uint gy = (MapConst.MaxGrids - 1) - p.Y_coord;
|
||||
|
||||
return Map.ExistMap(mapid, gx, gy) && Map.ExistVMap(mapid, gx, gy);
|
||||
}
|
||||
|
||||
@@ -202,10 +202,10 @@ namespace Game.Maps
|
||||
class ObjectGridStoper : Notifier
|
||||
{
|
||||
public override void Visit(IList<Creature> objs)
|
||||
{
|
||||
{
|
||||
// stop any fights at grid de-activation and remove dynobjects/areatriggers created at cast by creatures
|
||||
for (var i = 0; i < objs.Count; ++i)
|
||||
{
|
||||
{
|
||||
Creature creature = objs[i];
|
||||
creature.RemoveAllDynObjects();
|
||||
creature.RemoveAllAreaTriggers();
|
||||
@@ -240,11 +240,11 @@ namespace Game.Maps
|
||||
{
|
||||
for (var i = 0; i < objs.Count; ++i)
|
||||
{
|
||||
GameObject go = objs[i];
|
||||
GameObject gameObject = objs[i];
|
||||
// gameobject in unloading grid can have respawn point in another grid
|
||||
// if it will be unloaded then it will not respawn in original grid until unload/load original grid
|
||||
// move to respawn point to prevent this case. For player view in respawn grid this will be normal respawn.
|
||||
go.GetMap().GameObjectRespawnRelocation(go, true);
|
||||
gameObject.GetMap().GameObjectRespawnRelocation(gameObject, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -254,8 +254,10 @@ namespace Game.Maps
|
||||
{
|
||||
public override void Visit(IList<WorldObject> objs)
|
||||
{
|
||||
foreach (var obj in objs)
|
||||
for (var i = 0; i < objs.Count; ++i)
|
||||
{
|
||||
WorldObject obj = objs[i];
|
||||
|
||||
if (obj.IsTypeId(TypeId.Player))
|
||||
continue;
|
||||
|
||||
@@ -269,8 +271,10 @@ namespace Game.Maps
|
||||
{
|
||||
public override void Visit(IList<WorldObject> objs)
|
||||
{
|
||||
foreach (var obj in objs)
|
||||
for (var i = 0; i < objs.Count; ++i)
|
||||
{
|
||||
WorldObject obj = objs[i];
|
||||
|
||||
if (obj.IsTypeId(TypeId.Corpse))
|
||||
continue;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user