Rebased. (+1 squashed commits)
Squashed commits: [43010a0] Fixes. (+1 squashed commits) Squashed commits: [94ee90e] Fixes. (+1 squashed commits) Squashed commits: [ef827c7] Style cop updates. Updates to LevelUp, Cloak, and UnitUpgrade to allow multiple units within range, plus maximum extra unit limit. (+1 squashed commits) Squashed commits: [2103b01] Dupe crate action updates and fixes. (+2 squashed commit) Squashed commit: [0f4df4a] Added DuplicateUnitCrateAction. [2787fa1] Clarity update. (+1 squashed commits) Squashed commits: [93ddc3b] Crate updates. +Multiple units per crate allowed. +Allow time delay on crate actions.
This commit is contained in:
@@ -8,30 +8,42 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenRA.Mods.RA.Crates
|
||||
{
|
||||
[Desc("Grants an upgrade to the collector.")]
|
||||
public class UnitUpgradeCrateActionInfo : CrateActionInfo
|
||||
{
|
||||
[Desc("The upgrade to grant.")]
|
||||
public readonly UnitUpgrade? Upgrade = null;
|
||||
|
||||
[Desc("The number of levels of the upgrade to grant.")]
|
||||
public readonly int Levels = 1;
|
||||
|
||||
[Desc("The range to search for extra collectors in.","Extra collectors will also be granted the crate action.")]
|
||||
public readonly WRange Range = new WRange(3);
|
||||
|
||||
[Desc("The maximum number of extra collectors to grant the crate action to.","-1 = no limit")]
|
||||
public readonly int MaxExtraCollectors = 4;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new UnitUpgradeCrateAction(init.self, this); }
|
||||
}
|
||||
|
||||
public class UnitUpgradeCrateAction : CrateAction
|
||||
{
|
||||
UnitUpgradeCrateActionInfo crateInfo;
|
||||
UnitUpgradeCrateActionInfo Info;
|
||||
|
||||
public UnitUpgradeCrateAction(Actor self, UnitUpgradeCrateActionInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
crateInfo = info;
|
||||
Info = info;
|
||||
}
|
||||
|
||||
public override int GetSelectionShares(Actor collector)
|
||||
{
|
||||
var up = collector.TraitOrDefault<GainsUnitUpgrades>();
|
||||
return up != null && up.CanGainUnitUpgrade(crateInfo.Upgrade) ? info.SelectionShares : 0;
|
||||
return up != null && up.CanGainUnitUpgrade(Info.Upgrade) ? info.SelectionShares : 0;
|
||||
}
|
||||
|
||||
public override void Activate(Actor collector)
|
||||
@@ -40,9 +52,32 @@ namespace OpenRA.Mods.RA.Crates
|
||||
{
|
||||
var gainsStatBonuses = collector.TraitOrDefault<GainsUnitUpgrades>();
|
||||
if (gainsStatBonuses != null)
|
||||
gainsStatBonuses.GiveUnitUpgrade(crateInfo.Upgrade, crateInfo.Levels);
|
||||
gainsStatBonuses.GiveUnitUpgrade(Info.Upgrade, Info.Levels);
|
||||
});
|
||||
|
||||
var inRange = self.World.FindActorsInCircle(self.CenterPosition, Info.Range);
|
||||
inRange = inRange.Where(a =>
|
||||
(a.Owner == collector.Owner) &&
|
||||
(a != collector) &&
|
||||
(a.TraitOrDefault<GainsUnitUpgrades>() != null) &&
|
||||
(a.TraitOrDefault<GainsUnitUpgrades>().CanGainUnitUpgrade(Info.Upgrade)));
|
||||
if (inRange.Any())
|
||||
{
|
||||
if (Info.MaxExtraCollectors > -1)
|
||||
inRange = inRange.Take(Info.MaxExtraCollectors);
|
||||
|
||||
if (inRange.Any())
|
||||
foreach (Actor actor in inRange)
|
||||
{
|
||||
actor.World.AddFrameEndTask(w =>
|
||||
{
|
||||
var gainsStatBonuses = actor.TraitOrDefault<GainsUnitUpgrades>();
|
||||
if (gainsStatBonuses != null)
|
||||
gainsStatBonuses.GiveUnitUpgrade(Info.Upgrade, Info.Levels);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
base.Activate(collector);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user