Changes to ExternalCondition.TryRevokeCondition

This commit is contained in:
atlimit8
2017-07-18 13:34:05 -05:00
committed by Paul Chote
parent 72236b66f6
commit c7d3c3ec73
4 changed files with 19 additions and 6 deletions

View File

@@ -50,7 +50,8 @@ namespace OpenRA.Mods.Common.Scripting
public void RevokeCondition(int token) public void RevokeCondition(int token)
{ {
foreach (var external in externalConditions) foreach (var external in externalConditions)
external.TryRevokeCondition(Self, this, token); if (external.TryRevokeCondition(Self, this, token))
break;
} }
[Desc("Check whether this actor accepts a specific external condition.")] [Desc("Check whether this actor accepts a specific external condition.")]

View File

@@ -130,10 +130,20 @@ namespace OpenRA.Mods.Common.Traits
if (conditionManager == null || source == null) if (conditionManager == null || source == null)
return false; return false;
var removed = permanentTokens.GetOrAdd(source).Remove(token) || HashSet<int> permanentTokensForSource;
timedTokens.GetOrAdd(source).RemoveWhere(t => t.Token == token) > 0; if (permanentTokens.TryGetValue(source, out permanentTokensForSource))
{
if (!permanentTokensForSource.Remove(token))
return false;
}
else
{
HashSet<TimedToken> timedTokensForSource = null;
if (timedTokens.TryGetValue(source, out timedTokensForSource) && timedTokensForSource.RemoveWhere(t => t.Token == token) == 0)
return false;
}
if (removed && conditionManager.TokenValid(self, token)) if (conditionManager.TokenValid(self, token))
conditionManager.RevokeCondition(self, token); conditionManager.RevokeCondition(self, token);
return true; return true;

View File

@@ -56,7 +56,8 @@ namespace OpenRA.Mods.Common.Traits
return; return;
foreach (var external in segment.TraitsImplementing<ExternalCondition>()) foreach (var external in segment.TraitsImplementing<ExternalCondition>())
external.TryRevokeCondition(segment, self, token); if (external.TryRevokeCondition(segment, self, token))
break;
} }
void INotifyLineBuildSegmentsChanged.SegmentAdded(Actor self, Actor segment) void INotifyLineBuildSegmentsChanged.SegmentAdded(Actor self, Actor segment)

View File

@@ -156,7 +156,8 @@ namespace OpenRA.Mods.Common.Traits
tokens.Remove(a); tokens.Remove(a);
foreach (var external in a.TraitsImplementing<ExternalCondition>()) foreach (var external in a.TraitsImplementing<ExternalCondition>())
external.TryRevokeCondition(a, self, token); if (external.TryRevokeCondition(a, self, token))
break;
} }
} }
} }