support power impl pretty much done
This commit is contained in:
@@ -3,6 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRa.Game.GameRules;
|
||||
using OpenRa.Game.Traits;
|
||||
using OpenRa.Game.SupportPowers;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
@@ -10,15 +12,25 @@ namespace OpenRa.Game
|
||||
{
|
||||
public readonly SupportPowerInfo Info;
|
||||
public readonly Player Owner;
|
||||
readonly ISupportPowerImpl Impl;
|
||||
|
||||
static ISupportPowerImpl ConstructPowerImpl(string implName)
|
||||
{
|
||||
var type = typeof(ISupportPowerImpl).Assembly.GetType(
|
||||
typeof(ISupportPowerImpl).Namespace + "." + implName, true, false);
|
||||
var ctor = type.GetConstructor(Type.EmptyTypes);
|
||||
return (ISupportPowerImpl)ctor.Invoke(new object[] { });
|
||||
}
|
||||
|
||||
public SupportPower(SupportPowerInfo info, Player owner)
|
||||
{
|
||||
Info = info;
|
||||
Owner = owner;
|
||||
|
||||
RemainingTime = TotalTime = (int)info.ChargeTime * 60 * 25;
|
||||
Impl = ConstructPowerImpl(info.Impl);
|
||||
}
|
||||
|
||||
public bool IsUsed;
|
||||
public bool IsAvailable { get; private set; }
|
||||
public bool IsDone { get { return RemainingTime == 0; } }
|
||||
public int RemainingTime { get; private set; }
|
||||
@@ -26,6 +38,9 @@ namespace OpenRa.Game
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
if (Info.OneShot && IsUsed)
|
||||
return;
|
||||
|
||||
if (Info.GivenAuto)
|
||||
{
|
||||
var buildings = Rules.TechTree.GatherBuildings(Owner);
|
||||
@@ -47,6 +62,25 @@ namespace OpenRa.Game
|
||||
|
||||
public void Activate()
|
||||
{
|
||||
if (Impl != null)
|
||||
Impl.Activate(this);
|
||||
}
|
||||
|
||||
public void FinishActivate()
|
||||
{
|
||||
if (Info.OneShot)
|
||||
{
|
||||
IsUsed = true;
|
||||
IsAvailable = false;
|
||||
}
|
||||
RemainingTime = TotalTime;
|
||||
}
|
||||
|
||||
public void Give(bool requireCharge) // called by crate/spy/etc code
|
||||
{
|
||||
IsAvailable = true;
|
||||
IsUsed = false;
|
||||
RemainingTime = requireCharge ? TotalTime : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user