Files
OpenRA/OpenRA.Mods.RA/GlobalUpgradable.cs
Paul Chote c697a1e7b4 Add a UnitUpgradeManager trait.
This introduces support for timed upgrades, starting with crate buffs.
2014-10-01 21:28:45 +13:00

65 lines
1.7 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2014 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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRA.Mods.RA;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
public class GlobalUpgradableInfo : ITraitInfo, Requires<UpgradeManagerInfo>
{
public readonly string[] Upgrades = { };
public readonly string[] Prerequisites = { };
public object Create(ActorInitializer init) { return new GlobalUpgradable(init.self, this); }
}
public class GlobalUpgradable : INotifyAddedToWorld, INotifyRemovedFromWorld
{
readonly GlobalUpgradableInfo info;
readonly GlobalUpgradeManager globalManager;
readonly UpgradeManager manager;
public GlobalUpgradable(Actor self, GlobalUpgradableInfo info)
{
this.info = info;
globalManager = self.Owner.PlayerActor.Trait<GlobalUpgradeManager>();
manager = self.Trait<UpgradeManager>();
}
public void AddedToWorld(Actor self)
{
if (info.Prerequisites.Any())
globalManager.Register(self, this, info.Prerequisites);
}
public void RemovedFromWorld(Actor self)
{
if (info.Prerequisites.Any())
globalManager.Unregister(self, this, info.Prerequisites);
}
public void PrerequisitesUpdated(Actor self, bool available)
{
foreach (var u in info.Upgrades)
{
if (available)
manager.GrantUpgrade(self, u, this);
else
manager.RevokeUpgrade(self, u, this);
}
}
}
}