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)
|
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;
|
continue;
|
||||||
|
|
||||||
// Send packet to all who are sharing the player's vision
|
// Send packet to all who are sharing the player's vision
|
||||||
if (target.HasSharedVision())
|
if (player.HasSharedVision())
|
||||||
{
|
{
|
||||||
foreach (var visionTarget in target.GetSharedVisionList())
|
foreach (var visionTarget in player.GetSharedVisionList())
|
||||||
if (visionTarget.seerView == target)
|
if (visionTarget.seerView == player)
|
||||||
SendPacket(visionTarget);
|
SendPacket(visionTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target.seerView == target || target.GetVehicle())
|
if (player.seerView == player || player.GetVehicle())
|
||||||
SendPacket(target);
|
SendPacket(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Visit(IList<Creature> objs)
|
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;
|
continue;
|
||||||
|
|
||||||
// Send packet to all who are sharing the creature's vision
|
// Send packet to all who are sharing the creature's vision
|
||||||
if (target.HasSharedVision())
|
if (creature.HasSharedVision())
|
||||||
{
|
{
|
||||||
foreach (var visionTarget in target.GetSharedVisionList())
|
foreach (var visionTarget in creature.GetSharedVisionList())
|
||||||
if (visionTarget.seerView == target)
|
if (visionTarget.seerView == creature)
|
||||||
SendPacket(visionTarget);
|
SendPacket(visionTarget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override void Visit(IList<DynamicObject> objs)
|
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;
|
continue;
|
||||||
|
|
||||||
Unit caster = target.GetCaster();
|
Unit caster = dynamicObject.GetCaster();
|
||||||
if (caster)
|
if (caster)
|
||||||
{
|
{
|
||||||
// Send packet back to the caster if the caster has vision of dynamic object
|
// Send packet back to the caster if the caster has vision of dynamic object
|
||||||
Player player = caster.ToPlayer();
|
Player player = caster.ToPlayer();
|
||||||
if (player && player.seerView == target)
|
if (player && player.seerView == dynamicObject)
|
||||||
SendPacket(player);
|
SendPacket(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1663,15 +1663,21 @@ namespace Game
|
|||||||
|
|
||||||
public override void Visit(IList<Creature> objs)
|
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)
|
if (creature.IsInWorld && creature.IsAIEnabled)
|
||||||
creature.GetAI().OnGameEvent(_activate, _eventId);
|
creature.GetAI().OnGameEvent(_activate, _eventId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public override void Visit(IList<GameObject> objs)
|
public override void Visit(IList<GameObject> objs)
|
||||||
{
|
{
|
||||||
foreach (var gameobject in objs)
|
for (var i = 0; i < objs.Count; ++i)
|
||||||
if (gameobject.IsInWorld)
|
{
|
||||||
gameobject.GetAI().OnGameEvent(_activate, _eventId);
|
GameObject gameObject = objs[i];
|
||||||
|
if (gameObject.IsInWorld)
|
||||||
|
gameObject.GetAI().OnGameEvent(_activate, _eventId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ushort _eventId;
|
ushort _eventId;
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ namespace Game.Maps
|
|||||||
visitor.Visit(_container.corpses);
|
visitor.Visit(_container.corpses);
|
||||||
visitor.Visit(_container.areaTriggers);
|
visitor.Visit(_container.areaTriggers);
|
||||||
visitor.Visit(_container.conversations);
|
visitor.Visit(_container.conversations);
|
||||||
visitor.Visit(_container.worldObjects.ToArray());
|
visitor.Visit(_container.worldObjects);
|
||||||
break;
|
break;
|
||||||
case GridMapTypeMask.AllWorld:
|
case GridMapTypeMask.AllWorld:
|
||||||
visitor.Visit(_objects.players);
|
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);
|
GridCoord p = GridDefines.ComputeGridCoord(x, y);
|
||||||
|
|
||||||
uint gx = 63 - p.X_coord;
|
uint gx = (MapConst.MaxGrids - 1) - p.X_coord;
|
||||||
uint gy = 63 - p.Y_coord;
|
uint gy = (MapConst.MaxGrids - 1) - p.Y_coord;
|
||||||
|
|
||||||
return Map.ExistMap(mapid, gx, gy) && Map.ExistVMap(mapid, gx, gy);
|
return Map.ExistMap(mapid, gx, gy) && Map.ExistVMap(mapid, gx, gy);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -240,11 +240,11 @@ namespace Game.Maps
|
|||||||
{
|
{
|
||||||
for (var i = 0; i < objs.Count; ++i)
|
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
|
// 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
|
// 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.
|
// 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)
|
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))
|
if (obj.IsTypeId(TypeId.Player))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -269,8 +271,10 @@ namespace Game.Maps
|
|||||||
{
|
{
|
||||||
public override void Visit(IList<WorldObject> objs)
|
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))
|
if (obj.IsTypeId(TypeId.Corpse))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user