Port GrantUpgradeWarhead to GrantExternalConditionWarhead.

This commit is contained in:
Paul Chote
2016-11-20 16:45:13 +00:00
parent f274522083
commit 764401be10
2 changed files with 9 additions and 22 deletions

View File

@@ -564,7 +564,7 @@
<Compile Include="Warheads\CreateResourceWarhead.cs" /> <Compile Include="Warheads\CreateResourceWarhead.cs" />
<Compile Include="Warheads\DamageWarhead.cs" /> <Compile Include="Warheads\DamageWarhead.cs" />
<Compile Include="Warheads\DestroyResourceWarhead.cs" /> <Compile Include="Warheads\DestroyResourceWarhead.cs" />
<Compile Include="Warheads\GrantUpgradeWarhead.cs" /> <Compile Include="Warheads\GrantExternalConditionWarhead.cs" />
<Compile Include="Warheads\HealthPercentageDamageWarhead.cs" /> <Compile Include="Warheads\HealthPercentageDamageWarhead.cs" />
<Compile Include="Warheads\LeaveSmudgeWarhead.cs" /> <Compile Include="Warheads\LeaveSmudgeWarhead.cs" />
<Compile Include="Warheads\SpreadDamageWarhead.cs" /> <Compile Include="Warheads\SpreadDamageWarhead.cs" />

View File

@@ -10,19 +10,18 @@
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.Common.Warheads namespace OpenRA.Mods.Common.Warheads
{ {
public class GrantUpgradeWarhead : Warhead public class GrantExternalConditionWarhead : Warhead
{ {
[UpgradeGrantedReference] [FieldLoader.Require]
[Desc("The upgrades to apply.")] [Desc("The condition to apply. Must be included in the target actor's ExternalConditions list.")]
public readonly string[] Upgrades = { }; public readonly string Condition = null;
[Desc("Duration of the upgrade (in ticks). Set to 0 for a permanent upgrade.")] [Desc("Duration of the condition (in ticks). Set to 0 for a permanent condition.")]
public readonly int Duration = 0; public readonly int Duration = 0;
public readonly WDist Range = WDist.FromCells(1); public readonly WDist Range = WDist.FromCells(1);
@@ -38,22 +37,10 @@ namespace OpenRA.Mods.Common.Warheads
continue; continue;
var um = a.TraitOrDefault<UpgradeManager>(); var um = a.TraitOrDefault<UpgradeManager>();
if (um == null)
continue;
foreach (var u in Upgrades) // Condition token is ignored because we never revoke this condition.
{ if (um != null && um.AcceptsExternalCondition(a, Condition))
if (Duration > 0) um.GrantCondition(a, Condition, true, Duration);
{
if (um.AcknowledgesUpgrade(a, u))
um.GrantTimedUpgrade(a, u, Duration, firedBy, Upgrades.Count(upg => upg == u));
}
else
{
if (um.AcceptsUpgrade(a, u))
um.GrantUpgrade(a, u, this);
}
}
} }
} }
} }