Crates: Part 2

This commit is contained in:
Paul Chote
2010-01-27 20:55:11 +13:00
parent abe1b3c1ea
commit cc4c137038
8 changed files with 114 additions and 3 deletions

View File

@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRa.Traits;
using OpenRa.Mods.RA.Effects;
namespace OpenRa.Mods.RA
{
class SpeedUpgradeCrateActionInfo : ITraitInfo
{
public float Multiplier = 1.7f;
public int SelectionShares = 10;
public object Create(Actor self) { return new SpeedUpgradeCrateAction(self); }
}
class SpeedUpgradeCrateAction : ICrateAction
{
Actor self;
public SpeedUpgradeCrateAction(Actor self)
{
this.self = self;
}
public int SelectionShares
{
get { return self.Info.Traits.Get<SpeedUpgradeCrateActionInfo>().SelectionShares; }
}
public void Activate(Actor collector)
{
Sound.PlayToPlayer(collector.Owner, "unitspd1.aud");
collector.World.AddFrameEndTask(w =>
{
float multiplier = self.Info.Traits.Get<SpeedUpgradeCrateActionInfo>().Multiplier;
collector.traits.Add(new SpeedUpgrade(multiplier));
w.Add(new CrateEffectSpeedUpgrade(collector));
});
}
}
class SpeedUpgrade : ISpeedModifier
{
float multiplier;
public SpeedUpgrade(float multiplier) { this.multiplier = multiplier; }
public float GetSpeedModifier() { return multiplier; }
}
}

View File

@@ -0,0 +1,32 @@
using System.Collections.Generic;
using OpenRa.Graphics;
using OpenRa.Traits;
using OpenRa.Effects;
namespace OpenRa.Mods.RA.Effects
{
class CrateEffectSpeedUpgrade : IEffect
{
Actor a;
Animation anim = new Animation("crate-effects");
float2 doorOffset = new float2(-4,0);
public CrateEffectSpeedUpgrade(Actor a)
{
this.a = a;
anim.PlayThen("speed",
() => a.World.AddFrameEndTask(w => w.Remove(this)));
}
public void Tick( World world )
{
anim.Tick();
}
public IEnumerable<Renderable> Render()
{
yield return new Renderable(anim.Image,
a.CenterLocation - .5f * anim.Image.size + doorOffset, PaletteType.Gold);
}
}
}

View File

@@ -52,6 +52,7 @@
<Compile Include="Activities\LayMine.cs" />
<Compile Include="Activities\Steal.cs" />
<Compile Include="C4Demolition.cs" />
<Compile Include="Effects\CrateEffectSpeedUpgrade.cs" />
<Compile Include="EngineerCapture.cs" />
<Compile Include="InfiltrateForSonarPulse.cs" />
<Compile Include="RequiresPower.cs" />
@@ -61,6 +62,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RenderSpy.cs" />
<Compile Include="RepairableNear.cs" />
<Compile Include="Crate Actions\SpeedUpgrade.cs" />
<Compile Include="Spy.cs" />
<Compile Include="Thief.cs" />
</ItemGroup>