Support multiple Power traits

This commit is contained in:
atlimit8
2014-11-29 15:56:25 -06:00
parent 47357addeb
commit 92779cc496
7 changed files with 47 additions and 25 deletions

View File

@@ -9,6 +9,8 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using Eluant;
using OpenRA.Mods.Common.Power;
using OpenRA.Scripting;
@@ -56,18 +58,18 @@ namespace OpenRA.Mods.Common.Scripting
[ScriptPropertyGroup("Power")]
public class ActorPowerProperties : ScriptActorProperties, Requires<PowerInfo>
{
readonly PowerInfo pi;
readonly IEnumerable<Power.Power> power;
public ActorPowerProperties(ScriptContext context, Actor self)
: base(context, self)
{
pi = self.Info.Traits.GetOrDefault<PowerInfo>();
power = self.TraitsImplementing<Power.Power>();
}
[Desc("Returns the power drained/provided by this actor.")]
public int Power
{
get { return pi.Amount; }
get { return power.Sum(p => p.GetEnabledPower()); }
}
}
}