diff --git a/OpenRA.Mods.Cnc/Scripting/Properties/ChronosphereProperties.cs b/OpenRA.Mods.Cnc/Scripting/Properties/ChronosphereProperties.cs index 7577a8b882..fa42ea3a61 100644 --- a/OpenRA.Mods.Cnc/Scripting/Properties/ChronosphereProperties.cs +++ b/OpenRA.Mods.Cnc/Scripting/Properties/ChronosphereProperties.cs @@ -37,7 +37,9 @@ namespace OpenRA.Mods.Cnc.Scripting kv.Key.WrappedClrType().Name, kv.Value.WrappedClrType().Name)); } - var cs = actor.TraitOrDefault(); + var cs = actor.TraitsImplementing() + .FirstEnabledTraitOrDefault(); + if (cs != null && cs.CanChronoshiftTo(actor, cell)) cs.Teleport(actor, cell, duration, killCargo, Self); } diff --git a/OpenRA.Mods.Cnc/Traits/Chronoshiftable.cs b/OpenRA.Mods.Cnc/Traits/Chronoshiftable.cs index bf5c20880b..9fd43bdb50 100644 --- a/OpenRA.Mods.Cnc/Traits/Chronoshiftable.cs +++ b/OpenRA.Mods.Cnc/Traits/Chronoshiftable.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.Cnc.Traits [Desc("The color the bar of the 'return-to-origin' logic has.")] public readonly Color TimeBarColor = Color.White; - public object Create(ActorInitializer init) { return new Chronoshiftable(init, this); } + public override object Create(ActorInitializer init) { return new Chronoshiftable(init, this); } } public class Chronoshiftable : ConditionalTrait, ITick, ISync, ISelectionBar, @@ -78,7 +78,7 @@ namespace OpenRA.Mods.Cnc.Traits if (--ReturnTicks == 0) { self.CancelActivity(); - self.QueueActivity(new Teleport(chronosphere, Origin, null, killCargo, true, info.ChronoshiftSound)); + self.QueueActivity(new Teleport(chronosphere, Origin, null, killCargo, true, Info.ChronoshiftSound)); } } @@ -91,19 +91,22 @@ namespace OpenRA.Mods.Cnc.Traits public virtual bool CanChronoshiftTo(Actor self, CPos targetLocation) { // TODO: Allow enemy units to be chronoshifted into bad terrain to kill them - return iPositionable != null && iPositionable.CanEnterCell(targetLocation); + return !IsTraitDisabled && iPositionable != null && iPositionable.CanEnterCell(targetLocation); } public virtual bool Teleport(Actor self, CPos targetLocation, int duration, bool killCargo, Actor chronosphere) { + if (IsTraitDisabled) + return false; + // Some things appear chronoshiftable, but instead they just die. - if (info.ExplodeInstead) + if (Info.ExplodeInstead) { self.World.AddFrameEndTask(w => { // Damage is inflicted by the chronosphere if (!self.Disposed) - self.Kill(chronosphere, info.DamageTypes); + self.Kill(chronosphere, Info.DamageTypes); }); return true; } @@ -123,7 +126,7 @@ namespace OpenRA.Mods.Cnc.Traits // Set up the teleport self.CancelActivity(); - self.QueueActivity(new Teleport(chronosphere, targetLocation, null, killCargo, true, info.ChronoshiftSound)); + self.QueueActivity(new Teleport(chronosphere, targetLocation, null, killCargo, true, Info.ChronoshiftSound)); return true; } @@ -131,7 +134,7 @@ namespace OpenRA.Mods.Cnc.Traits // Show the remaining time as a bar float ISelectionBar.GetValue() { - if (!info.ReturnToOrigin) + if (IsTraitDisabled || !Info.ReturnToOrigin) return 0f; // Otherwise an empty bar is rendered all the time @@ -141,12 +144,12 @@ namespace OpenRA.Mods.Cnc.Traits return (float)ReturnTicks / duration; } - Color ISelectionBar.GetColor() { return info.TimeBarColor; } + Color ISelectionBar.GetColor() { return Info.TimeBarColor; } bool ISelectionBar.DisplayWhenEmpty { get { return false; } } void ModifyActorInit(TypeDictionary init) { - if (!info.ReturnToOrigin || ReturnTicks <= 0) + if (IsTraitDisabled || !Info.ReturnToOrigin || ReturnTicks <= 0) return; init.Add(new ChronoshiftOriginInit(Origin)); diff --git a/OpenRA.Mods.Cnc/Traits/SupportPowers/ChronoshiftPower.cs b/OpenRA.Mods.Cnc/Traits/SupportPowers/ChronoshiftPower.cs index 7349298854..8b7bb37690 100644 --- a/OpenRA.Mods.Cnc/Traits/SupportPowers/ChronoshiftPower.cs +++ b/OpenRA.Mods.Cnc/Traits/SupportPowers/ChronoshiftPower.cs @@ -65,7 +65,12 @@ namespace OpenRA.Mods.Cnc.Traits foreach (var target in UnitsInRange(order.ExtraLocation)) { - var cs = target.Trait(); + var cs = target.TraitsImplementing() + .FirstEnabledTraitOrDefault(); + + if (cs == null) + continue; + var targetCell = target.Location + (order.TargetLocation - order.ExtraLocation); var cpi = Info as ChronoshiftPowerInfo; @@ -82,7 +87,7 @@ namespace OpenRA.Mods.Cnc.Traits foreach (var t in tiles) units.UnionWith(Self.World.ActorMap.GetActorsAt(t)); - return units.Where(a => a.Info.HasTraitInfo() && + return units.Where(a => a.TraitsImplementing().Any(cs => !cs.IsTraitDisabled) && !a.TraitsImplementing().Any(condition => condition.PreventsTeleport(a))); }