Merge ConditionManager trait directly into Actor
This commit is contained in:
@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
[Desc("Allows a condition to be granted from an external source (Lua, warheads, etc).")]
|
||||
public class ExternalConditionInfo : ITraitInfo, Requires<ConditionManagerInfo>
|
||||
public class ExternalConditionInfo : ITraitInfo
|
||||
{
|
||||
[GrantedConditionReference]
|
||||
[FieldLoader.Require]
|
||||
@@ -55,7 +55,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
public readonly ExternalConditionInfo Info;
|
||||
readonly ConditionManager conditionManager;
|
||||
readonly Dictionary<object, HashSet<int>> permanentTokens = new Dictionary<object, HashSet<int>>();
|
||||
|
||||
// Tokens are sorted on insert/remove by ascending expiry time
|
||||
@@ -67,12 +66,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public ExternalCondition(Actor self, ExternalConditionInfo info)
|
||||
{
|
||||
Info = info;
|
||||
conditionManager = self.Trait<ConditionManager>();
|
||||
}
|
||||
|
||||
public bool CanGrantCondition(Actor self, object source)
|
||||
{
|
||||
if (conditionManager == null || source == null)
|
||||
if (source == null)
|
||||
return false;
|
||||
|
||||
// Timed tokens do not count towards the source cap: the condition with the shortest
|
||||
@@ -93,9 +91,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public int GrantCondition(Actor self, object source, int duration = 0, int remaining = 0)
|
||||
{
|
||||
if (!CanGrantCondition(self, source))
|
||||
return ConditionManager.InvalidConditionToken;
|
||||
return Actor.InvalidConditionToken;
|
||||
|
||||
var token = conditionManager.GrantCondition(self, Info.Condition);
|
||||
var token = self.GrantCondition(Info.Condition);
|
||||
HashSet<int> permanent;
|
||||
permanentTokens.TryGetValue(source, out permanent);
|
||||
|
||||
@@ -118,8 +116,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var expireToken = timedTokens[expireIndex].Token;
|
||||
timedTokens.RemoveAt(expireIndex);
|
||||
if (conditionManager.TokenValid(self, expireToken))
|
||||
conditionManager.RevokeCondition(self, expireToken);
|
||||
if (self.TokenValid(expireToken))
|
||||
self.RevokeCondition(expireToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,8 +131,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (timedTokens.Count > 0)
|
||||
{
|
||||
var expire = timedTokens[0].Token;
|
||||
if (conditionManager.TokenValid(self, expire))
|
||||
conditionManager.RevokeCondition(self, expire);
|
||||
if (self.TokenValid(expire))
|
||||
self.RevokeCondition(expire);
|
||||
|
||||
timedTokens.RemoveAt(0);
|
||||
}
|
||||
@@ -166,7 +164,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
/// <returns><c>true</c> if the now-revoked condition was originally granted by this trait.</returns>
|
||||
public bool TryRevokeCondition(Actor self, object source, int token)
|
||||
{
|
||||
if (conditionManager == null || source == null)
|
||||
if (source == null)
|
||||
return false;
|
||||
|
||||
HashSet<int> permanentTokensForSource;
|
||||
@@ -184,8 +182,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return false;
|
||||
}
|
||||
|
||||
if (conditionManager.TokenValid(self, token))
|
||||
conditionManager.RevokeCondition(self, token);
|
||||
if (self.TokenValid(token))
|
||||
self.RevokeCondition(token);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -201,8 +199,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
while (count < timedTokens.Count && timedTokens[count].Expires < worldTick)
|
||||
{
|
||||
var token = timedTokens[count].Token;
|
||||
if (conditionManager.TokenValid(self, token))
|
||||
conditionManager.RevokeCondition(self, token);
|
||||
if (self.TokenValid(token))
|
||||
self.RevokeCondition(token);
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user