From 370ee0841f90a19fb13b07ed1368c8e9a96b1498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 17 Sep 2017 17:45:02 +0200 Subject: [PATCH] Add GrantsCondition to KillsSelf --- OpenRA.Mods.Common/Traits/KillsSelf.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Traits/KillsSelf.cs b/OpenRA.Mods.Common/Traits/KillsSelf.cs index d9bc193970..142ddfd1c5 100644 --- a/OpenRA.Mods.Common/Traits/KillsSelf.cs +++ b/OpenRA.Mods.Common/Traits/KillsSelf.cs @@ -21,12 +21,17 @@ namespace OpenRA.Mods.Common.Traits [Desc("The amount of time (in ticks) before the actor dies. Two values indicate a range between which a random value is chosen.")] public readonly int[] Delay = { 0 }; + [GrantedConditionReference] + [Desc("The condition to grant moments before suiciding.")] + public readonly string GrantsCondition = null; + public override object Create(ActorInitializer init) { return new KillsSelf(init.Self, this); } } - class KillsSelf : ConditionalTrait, INotifyAddedToWorld, ITick + class KillsSelf : ConditionalTrait, INotifyCreated, INotifyAddedToWorld, ITick { int lifetime; + ConditionManager conditionManager; public KillsSelf(Actor self, KillsSelfInfo info) : base(info) @@ -42,6 +47,11 @@ namespace OpenRA.Mods.Common.Traits Kill(self); } + void INotifyCreated.Created(Actor self) + { + conditionManager = self.TraitOrDefault(); + } + void INotifyAddedToWorld.AddedToWorld(Actor self) { if (!IsTraitDisabled) @@ -65,6 +75,9 @@ namespace OpenRA.Mods.Common.Traits if (self.IsDead) return; + if (conditionManager != null && !string.IsNullOrEmpty(Info.GrantsCondition)) + conditionManager.GrantCondition(self, Info.GrantsCondition); + if (Info.RemoveInstead || !self.Info.HasTraitInfo()) self.Dispose(); else