Fix GrantConditionOnPrerequisite not refreshing when the actor's owner changes

This commit is contained in:
abcdefg30
2016-10-15 18:14:24 +02:00
parent b2b3390bc0
commit e1dda2bf54

View File

@@ -29,15 +29,14 @@ namespace OpenRA.Mods.Common.Traits
public object Create(ActorInitializer init) { return new GrantConditionOnPrerequisite(init.Self, this); }
}
public class GrantConditionOnPrerequisite : INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld
public class GrantConditionOnPrerequisite : INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyOwnerChanged
{
readonly GrantConditionOnPrerequisiteInfo info;
readonly GrantConditionOnPrerequisiteManager globalManager;
ConditionManager conditionManager;
int conditionToken = ConditionManager.InvalidConditionToken;
bool wasAvailable;
ConditionManager conditionManager;
GrantConditionOnPrerequisiteManager globalManager;
int conditionToken = ConditionManager.InvalidConditionToken;
public GrantConditionOnPrerequisite(Actor self, GrantConditionOnPrerequisiteInfo info)
{
@@ -62,6 +61,11 @@ namespace OpenRA.Mods.Common.Traits
globalManager.Unregister(self, this, info.Prerequisites);
}
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
{
globalManager = newOwner.PlayerActor.Trait<GrantConditionOnPrerequisiteManager>();
}
public void PrerequisitesUpdated(Actor self, bool available)
{
if (available == wasAvailable || conditionManager == null)