backend support for selling

This commit is contained in:
Chris Forbes
2010-01-02 12:00:37 +13:00
parent 5a7b572cfd
commit acacd99a71
3 changed files with 48 additions and 0 deletions

View File

@@ -146,6 +146,7 @@
<Compile Include="Traits\Activities\Rearm.cs" />
<Compile Include="Traits\Activities\Repair.cs" />
<Compile Include="Traits\Activities\ReturnToBase.cs" />
<Compile Include="Traits\Activities\Sell.cs" />
<Compile Include="Traits\Activities\Teleport.cs" />
<Compile Include="BuildingInfluenceMap.cs" />
<Compile Include="IOrderGenerator.cs" />

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRa.Game.Traits.Activities
{
class Sell : IActivity
{
public IActivity NextActivity { get; set; }
bool started;
void DoSell(Actor self)
{
var refund = Rules.General.RefundPercent
* self.Health * self.Info.Cost / self.Info.Strength;
self.Owner.GiveCash((int)refund);
self.Health = 0;
Game.world.Remove(self);
}
public IActivity Tick(Actor self)
{
if (!started)
{
var rb = self.traits.Get<RenderBuilding>();
rb.PlayCustomAnimBackwards(self, "make",
() => Game.world.AddFrameEndTask(w => DoSell(self)));
Sound.Play("cashturn.aud");
started = true;
}
return this;
}
public void Cancel(Actor self) { /* never gonna give you up.. */ }
}
}

View File

@@ -62,6 +62,12 @@ namespace OpenRa.Game.Traits
() => anim.PlayRepeating(GetPrefix(self) + "idle"));
}
public void PlayCustomAnimBackwards(Actor self, string name, Action a)
{
anim.PlayBackwardsThen(GetPrefix(self) + name,
() => { anim.PlayRepeating(GetPrefix(self) + "idle"); a(); });
}
public virtual void Damaged(Actor self, AttackInfo e)
{
if (!e.DamageStateChanged)