Replace CloakCrateAction with upgrades.

This commit is contained in:
Paul Chote
2014-07-30 21:38:44 +12:00
parent 2d062b790b
commit 1a4f476ffa
10 changed files with 43 additions and 91 deletions

View File

@@ -1,71 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Linq;
namespace OpenRA.Mods.RA.Crates
{
[Desc("Grants the collector the ability to cloak.")]
public class CloakCrateActionInfo : CrateActionInfo
{
[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.")]
public readonly int MaxExtraCollectors = 4;
public override object Create(ActorInitializer init) { return new CloakCrateAction(init.self, this); }
}
public class CloakCrateAction : CrateAction
{
CloakCrateActionInfo Info;
public CloakCrateAction(Actor self, CloakCrateActionInfo info)
: base(self, info)
{
Info = info;
}
public override int GetSelectionShares(Actor collector)
{
var cloak = collector.TraitOrDefault<Cloak>();
if (cloak == null || !cloak.AcceptsCloakCrate)
return 0;
return base.GetSelectionShares(collector);
}
public override void Activate(Actor collector)
{
collector.Trait<Cloak>().ReceivedCloakCrate(collector);
var inRange = self.World.FindActorsInCircle(self.CenterPosition, Info.Range);
inRange = inRange.Where(a =>
(a.Owner == collector.Owner) &&
(a != collector) &&
(a.TraitOrDefault<Cloak>() != null) &&
(a.TraitOrDefault<Cloak>().AcceptsCloakCrate));
if (inRange.Any())
{
if (Info.MaxExtraCollectors > -1)
inRange = inRange.Take(Info.MaxExtraCollectors);
if (inRange.Any())
foreach (Actor actor in inRange)
{
actor.Trait<Cloak>().ReceivedCloakCrate(actor);
}
}
base.Activate(collector);
}
}
}