Fixed issue with unit ready when capturing

This commit is contained in:
Andrii Yukhymchak
2018-01-01 11:08:38 +00:00
committed by Paul Chote
parent dec11f4fa0
commit 11db40a2b3
2 changed files with 24 additions and 18 deletions

View File

@@ -276,27 +276,33 @@ namespace OpenRA
// TODO: move elsewhere.
public void ChangeOwner(Player newOwner)
{
World.AddFrameEndTask(w =>
{
if (Disposed)
return;
World.AddFrameEndTask(_ => ChangeOwnerSync(newOwner));
}
var oldOwner = Owner;
var wasInWorld = IsInWorld;
/// <summary>
/// Change the actors owner without queuing a FrameEndTask.
/// This must only be called from inside an existing FrameEndTask.
/// </summary>
public void ChangeOwnerSync(Player newOwner)
{
if (Disposed)
return;
// momentarily remove from world so the ownership queries don't get confused
if (wasInWorld)
w.Remove(this);
var oldOwner = Owner;
var wasInWorld = IsInWorld;
Owner = newOwner;
Generation++;
// momentarily remove from world so the ownership queries don't get confused
if (wasInWorld)
World.Remove(this);
foreach (var t in TraitsImplementing<INotifyOwnerChanged>())
t.OnOwnerChanged(this, oldOwner, newOwner);
Owner = newOwner;
Generation++;
if (wasInWorld)
w.Add(this);
});
foreach (var t in TraitsImplementing<INotifyOwnerChanged>())
t.OnOwnerChanged(this, oldOwner, newOwner);
if (wasInWorld)
World.Add(this);
}
public DamageState GetDamageState()