backend support for selling
This commit is contained in:
41
OpenRa.Game/Traits/Activities/Sell.cs
Normal file
41
OpenRa.Game/Traits/Activities/Sell.cs
Normal 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.. */ }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user