Fixed "collection was modified" exceptions when a huskified human is killed while enumerating the character list (e.g. when killed by an explosion)
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
|
||||||
@@ -141,6 +143,15 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
if (GameMain.Client != null) return;
|
if (GameMain.Client != null) return;
|
||||||
|
|
||||||
|
//create the AI husk in a coroutine to ensure that we don't modify the character list while enumerating it
|
||||||
|
CoroutineManager.StartCoroutine(CreateAIHusk(character));
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<object> CreateAIHusk(Character character)
|
||||||
|
{
|
||||||
|
character.Enabled = false;
|
||||||
|
Entity.Spawner.AddToRemoveQueue(character);
|
||||||
|
|
||||||
var husk = Character.Create(
|
var husk = Character.Create(
|
||||||
Path.Combine("Content", "Characters", "Human", "humanhusk.xml"),
|
Path.Combine("Content", "Characters", "Human", "humanhusk.xml"),
|
||||||
character.WorldPosition,
|
character.WorldPosition,
|
||||||
@@ -156,17 +167,20 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
|
|
||||||
var matchingLimb = character.AnimController.GetLimb(limb.type);
|
var matchingLimb = character.AnimController.GetLimb(limb.type);
|
||||||
limb.body.SetTransform(matchingLimb.SimPosition, matchingLimb.Rotation);
|
if (matchingLimb?.body != null)
|
||||||
|
{
|
||||||
|
limb.body.SetTransform(matchingLimb.SimPosition, matchingLimb.Rotation);
|
||||||
|
limb.body.LinearVelocity = matchingLimb.LinearVelocity;
|
||||||
|
limb.body.AngularVelocity = matchingLimb.body.AngularVelocity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < character.Inventory.Items.Length; i++)
|
for (int i = 0; i < character.Inventory.Items.Length; i++)
|
||||||
{
|
{
|
||||||
if (character.Inventory.Items[i] == null) continue;
|
if (character.Inventory.Items[i] == null) continue;
|
||||||
husk.Inventory.TryPutItem(character.Inventory.Items[i], i, true, null);
|
husk.Inventory.TryPutItem(character.Inventory.Items[i], i, true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
character.Enabled = false;
|
yield return CoroutineStatus.Success;
|
||||||
Entity.Spawner.AddToRemoveQueue(character);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user