Add DisguisedAsCondition
This commit is contained in:
committed by
Paul Chote
parent
3efce265a8
commit
ecdfcda43e
@@ -90,12 +90,20 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
"Unload, Infiltrate, Demolish, Move.")]
|
"Unload, Infiltrate, Demolish, Move.")]
|
||||||
public readonly RevealDisguiseType RevealDisguiseOn = RevealDisguiseType.Attack;
|
public readonly RevealDisguiseType RevealDisguiseOn = RevealDisguiseType.Attack;
|
||||||
|
|
||||||
|
[Desc("Conditions to grant when disguised as specified actor.",
|
||||||
|
"A dictionary of [actor id]: [condition].")]
|
||||||
|
public readonly Dictionary<string, string> DisguisedAsConditions = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
[GrantedConditionReference]
|
||||||
|
public IEnumerable<string> LinterConditions { get { return DisguisedAsConditions.Values; } }
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new Disguise(init.Self, this); }
|
public object Create(ActorInitializer init) { return new Disguise(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class Disguise : INotifyCreated, IEffectiveOwner, IIssueOrder, IResolveOrder, IOrderVoice, IRadarColorModifier, INotifyAttack,
|
class Disguise : INotifyCreated, IEffectiveOwner, IIssueOrder, IResolveOrder, IOrderVoice, IRadarColorModifier, INotifyAttack,
|
||||||
INotifyDamage, INotifyUnload, INotifyDemolition, INotifyInfiltration, ITick
|
INotifyDamage, INotifyUnload, INotifyDemolition, INotifyInfiltration, ITick
|
||||||
{
|
{
|
||||||
|
public ActorInfo AsActor { get; private set; }
|
||||||
public Player AsPlayer { get; private set; }
|
public Player AsPlayer { get; private set; }
|
||||||
public string AsSprite { get; private set; }
|
public string AsSprite { get; private set; }
|
||||||
public ITooltipInfo AsTooltipInfo { get; private set; }
|
public ITooltipInfo AsTooltipInfo { get; private set; }
|
||||||
@@ -108,6 +116,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
|
|
||||||
ConditionManager conditionManager;
|
ConditionManager conditionManager;
|
||||||
int disguisedToken = ConditionManager.InvalidConditionToken;
|
int disguisedToken = ConditionManager.InvalidConditionToken;
|
||||||
|
int disguisedAsToken = ConditionManager.InvalidConditionToken;
|
||||||
CPos? lastPos;
|
CPos? lastPos;
|
||||||
|
|
||||||
public Disguise(Actor self, DisguiseInfo info)
|
public Disguise(Actor self, DisguiseInfo info)
|
||||||
@@ -161,8 +170,9 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
|
|
||||||
public void DisguiseAs(Actor target)
|
public void DisguiseAs(Actor target)
|
||||||
{
|
{
|
||||||
var oldDisguiseSetting = Disguised;
|
var oldEffectiveActor = AsActor;
|
||||||
var oldEffectiveOwner = AsPlayer;
|
var oldEffectiveOwner = AsPlayer;
|
||||||
|
var oldDisguiseSetting = Disguised;
|
||||||
|
|
||||||
if (target != null)
|
if (target != null)
|
||||||
{
|
{
|
||||||
@@ -173,6 +183,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
{
|
{
|
||||||
AsSprite = targetDisguise.AsSprite;
|
AsSprite = targetDisguise.AsSprite;
|
||||||
AsPlayer = targetDisguise.AsPlayer;
|
AsPlayer = targetDisguise.AsPlayer;
|
||||||
|
AsActor = targetDisguise.AsActor;
|
||||||
AsTooltipInfo = targetDisguise.AsTooltipInfo;
|
AsTooltipInfo = targetDisguise.AsTooltipInfo;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -180,6 +191,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
AsSprite = target.Trait<RenderSprites>().GetImage(target);
|
AsSprite = target.Trait<RenderSprites>().GetImage(target);
|
||||||
var tooltip = target.TraitsImplementing<ITooltip>().FirstOrDefault();
|
var tooltip = target.TraitsImplementing<ITooltip>().FirstOrDefault();
|
||||||
AsPlayer = tooltip.Owner;
|
AsPlayer = tooltip.Owner;
|
||||||
|
AsActor = target.Info;
|
||||||
AsTooltipInfo = tooltip.TooltipInfo;
|
AsTooltipInfo = tooltip.TooltipInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -187,36 +199,52 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
{
|
{
|
||||||
AsTooltipInfo = null;
|
AsTooltipInfo = null;
|
||||||
AsPlayer = null;
|
AsPlayer = null;
|
||||||
|
AsActor = self.Info;
|
||||||
AsSprite = null;
|
AsSprite = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
HandleDisguise(oldEffectiveOwner, oldDisguiseSetting);
|
HandleDisguise(oldEffectiveActor, oldEffectiveOwner, oldDisguiseSetting);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DisguiseAs(ActorInfo actorInfo, Player newOwner)
|
public void DisguiseAs(ActorInfo actorInfo, Player newOwner)
|
||||||
{
|
{
|
||||||
var oldDisguiseSetting = Disguised;
|
var oldEffectiveActor = AsActor;
|
||||||
var oldEffectiveOwner = AsPlayer;
|
var oldEffectiveOwner = AsPlayer;
|
||||||
|
var oldDisguiseSetting = Disguised;
|
||||||
|
|
||||||
var renderSprites = actorInfo.TraitInfoOrDefault<RenderSpritesInfo>();
|
var renderSprites = actorInfo.TraitInfoOrDefault<RenderSpritesInfo>();
|
||||||
AsSprite = renderSprites == null ? null : renderSprites.GetImage(actorInfo, self.World.Map.Rules.Sequences, newOwner.Faction.InternalName);
|
AsSprite = renderSprites == null ? null : renderSprites.GetImage(actorInfo, self.World.Map.Rules.Sequences, newOwner.Faction.InternalName);
|
||||||
AsPlayer = newOwner;
|
AsPlayer = newOwner;
|
||||||
|
AsActor = actorInfo;
|
||||||
AsTooltipInfo = actorInfo.TraitInfos<TooltipInfo>().FirstOrDefault();
|
AsTooltipInfo = actorInfo.TraitInfos<TooltipInfo>().FirstOrDefault();
|
||||||
|
|
||||||
HandleDisguise(oldEffectiveOwner, oldDisguiseSetting);
|
HandleDisguise(oldEffectiveActor, oldEffectiveOwner, oldDisguiseSetting);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleDisguise(Player oldEffectiveOwner, bool oldDisguiseSetting)
|
void HandleDisguise(ActorInfo oldEffectiveActor, Player oldEffectiveOwner, bool oldDisguiseSetting)
|
||||||
{
|
{
|
||||||
foreach (var t in self.TraitsImplementing<INotifyEffectiveOwnerChanged>())
|
foreach (var t in self.TraitsImplementing<INotifyEffectiveOwnerChanged>())
|
||||||
t.OnEffectiveOwnerChanged(self, oldEffectiveOwner, AsPlayer);
|
t.OnEffectiveOwnerChanged(self, oldEffectiveOwner, AsPlayer);
|
||||||
|
|
||||||
if (Disguised != oldDisguiseSetting && conditionManager != null)
|
if (conditionManager != null)
|
||||||
{
|
{
|
||||||
if (Disguised && disguisedToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(info.DisguisedCondition))
|
if (Disguised != oldDisguiseSetting)
|
||||||
disguisedToken = conditionManager.GrantCondition(self, info.DisguisedCondition);
|
{
|
||||||
else if (!Disguised && disguisedToken != ConditionManager.InvalidConditionToken)
|
if (Disguised && disguisedToken == ConditionManager.InvalidConditionToken && !string.IsNullOrEmpty(info.DisguisedCondition))
|
||||||
disguisedToken = conditionManager.RevokeCondition(self, disguisedToken);
|
disguisedToken = conditionManager.GrantCondition(self, info.DisguisedCondition);
|
||||||
|
else if (!Disguised && disguisedToken != ConditionManager.InvalidConditionToken)
|
||||||
|
disguisedToken = conditionManager.RevokeCondition(self, disguisedToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (AsActor != oldEffectiveActor)
|
||||||
|
{
|
||||||
|
if (disguisedAsToken != ConditionManager.InvalidConditionToken)
|
||||||
|
disguisedAsToken = conditionManager.RevokeCondition(self, disguisedAsToken);
|
||||||
|
|
||||||
|
string disguisedAsCondition;
|
||||||
|
if (info.DisguisedAsConditions.TryGetValue(AsActor.Name, out disguisedAsCondition))
|
||||||
|
disguisedAsToken = conditionManager.GrantCondition(self, disguisedAsCondition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user