Fix timed external conditions being rejected instead of reset.
This commit is contained in:
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
"If duration > 0 the condition will be automatically revoked after the defined number of ticks")]
|
"If duration > 0 the condition will be automatically revoked after the defined number of ticks")]
|
||||||
public int GrantCondition(string condition, int duration = 0)
|
public int GrantCondition(string condition, int duration = 0)
|
||||||
{
|
{
|
||||||
if (!conditionManager.AcceptsExternalCondition(Self, condition))
|
if (!conditionManager.AcceptsExternalCondition(Self, condition, duration > 0))
|
||||||
throw new InvalidDataException("Condition `{0}` has not been listed on an ExternalConditions trait".F(condition));
|
throw new InvalidDataException("Condition `{0}` has not been listed on an ExternalConditions trait".F(condition));
|
||||||
|
|
||||||
return conditionManager.GrantCondition(Self, condition, true, duration);
|
return conditionManager.GrantCondition(Self, condition, true, duration);
|
||||||
@@ -49,9 +49,9 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Desc("Check whether this actor accepts a specific external condition.")]
|
[Desc("Check whether this actor accepts a specific external condition.")]
|
||||||
public bool AcceptsCondition(string condition)
|
public bool AcceptsCondition(string condition, bool timed = false)
|
||||||
{
|
{
|
||||||
return conditionManager.AcceptsExternalCondition(Self, condition);
|
return conditionManager.AcceptsExternalCondition(Self, condition, timed);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Desc("Grant an upgrade to this actor. DEPRECATED! Will be removed.")]
|
[Desc("Grant an upgrade to this actor. DEPRECATED! Will be removed.")]
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Returns true if the given external condition will have an effect on this actor.</summary>
|
/// <summary>Returns true if the given external condition will have an effect on this actor.</summary>
|
||||||
public bool AcceptsExternalCondition(Actor self, string condition)
|
public bool AcceptsExternalCondition(Actor self, string condition, bool timed = false)
|
||||||
{
|
{
|
||||||
if (state == null)
|
if (state == null)
|
||||||
throw new InvalidOperationException("AcceptsExternalCondition cannot be queried before the actor has been fully created.");
|
throw new InvalidOperationException("AcceptsExternalCondition cannot be queried before the actor has been fully created.");
|
||||||
@@ -219,6 +219,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (!externalConditions.Contains(condition))
|
if (!externalConditions.Contains(condition))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// A timed condition can always replace an existing timed condition (resetting its duration)
|
||||||
|
if (timed && timers.ContainsKey(condition))
|
||||||
|
return true;
|
||||||
|
|
||||||
string[] sc;
|
string[] sc;
|
||||||
if (stackedConditions.TryGetValue(condition, out sc))
|
if (stackedConditions.TryGetValue(condition, out sc))
|
||||||
return stackedTokens[condition].Count < sc.Length;
|
return stackedTokens[condition].Count < sc.Length;
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
bool AcceptsCondition(Actor a)
|
bool AcceptsCondition(Actor a)
|
||||||
{
|
{
|
||||||
var cm = a.TraitOrDefault<ConditionManager>();
|
var cm = a.TraitOrDefault<ConditionManager>();
|
||||||
return cm != null && cm.AcceptsExternalCondition(a, info.Condition);
|
return cm != null && cm.AcceptsExternalCondition(a, info.Condition, info.Duration > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetSelectionShares(Actor collector)
|
public override int GetSelectionShares(Actor collector)
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
var cm = a.TraitOrDefault<ConditionManager>();
|
var cm = a.TraitOrDefault<ConditionManager>();
|
||||||
return cm != null && cm.AcceptsExternalCondition(a, info.Condition);
|
return cm != null && cm.AcceptsExternalCondition(a, info.Condition, info.Duration > 0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Warheads
|
|||||||
var cm = a.TraitOrDefault<ConditionManager>();
|
var cm = a.TraitOrDefault<ConditionManager>();
|
||||||
|
|
||||||
// Condition token is ignored because we never revoke this condition.
|
// Condition token is ignored because we never revoke this condition.
|
||||||
if (cm != null && cm.AcceptsExternalCondition(a, Condition))
|
if (cm != null && cm.AcceptsExternalCondition(a, Condition, Duration > 0))
|
||||||
cm.GrantCondition(a, Condition, true, Duration);
|
cm.GrantCondition(a, Condition, true, Duration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user