Deathweapon capability, refactoring, and Pip polishing on Silo, Proc, Harv. Lose ore on silo death.
This commit is contained in:
@@ -22,35 +22,58 @@ using System.Collections.Generic;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
class StoresOreInfo : TraitInfo<StoresOre>
|
||||
class StoresOreInfo : ITraitInfo
|
||||
{
|
||||
public readonly int Pips = 0;
|
||||
public readonly int PipCount = 0;
|
||||
public readonly PipType PipColor = PipType.Yellow;
|
||||
public readonly int Capacity = 0;
|
||||
public readonly string DeathWeapon = null;
|
||||
public object Create(Actor self) { return new StoresOre(self, this); }
|
||||
}
|
||||
|
||||
class StoresOre : IPips, INotifyCapture
|
||||
class StoresOre : IPips, INotifyCapture, INotifyDamage
|
||||
{
|
||||
readonly PlayerResources Player;
|
||||
readonly StoresOreInfo Info;
|
||||
|
||||
public StoresOre(Actor self, StoresOreInfo info)
|
||||
{
|
||||
Player = self.Owner.PlayerActor.traits.Get<PlayerResources>();
|
||||
Info = info;
|
||||
}
|
||||
|
||||
public void OnCapture(Actor self, Actor captor)
|
||||
{
|
||||
var ore = Stored(self);
|
||||
self.Owner.PlayerActor.traits.Get<PlayerResources>().TakeOre(ore);
|
||||
captor.Owner.PlayerActor.traits.Get<PlayerResources>().GiveOre(ore);
|
||||
Player.TakeOre(ore);
|
||||
Player.GiveOre(ore);
|
||||
}
|
||||
|
||||
int Stored(Actor self)
|
||||
{
|
||||
var use = self.Owner.PlayerActor.traits.Get<PlayerResources>().GetSiloFullness();
|
||||
var capacity = self.Info.Traits.Get<StoresOreInfo>().Capacity;
|
||||
return (int)use*capacity;
|
||||
return (int)(Player.GetSiloFullness() * Info.Capacity);
|
||||
}
|
||||
|
||||
public void Damaged(Actor self, AttackInfo e)
|
||||
{
|
||||
if (self.IsDead && Player.GetSiloFullness() > 0)
|
||||
{
|
||||
if (Info.DeathWeapon != null)
|
||||
{
|
||||
Combat.DoExplosion(e.Attacker, Info.DeathWeapon,
|
||||
self.CenterLocation.ToInt2(), 0);
|
||||
}
|
||||
|
||||
// Lose the stored ore
|
||||
Player.TakeOre(Stored(self));
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<PipType> GetPips(Actor self)
|
||||
{
|
||||
var numPips = self.Info.Traits.Get<StoresOreInfo>().Pips;
|
||||
|
||||
return Graphics.Util.MakeArray( numPips,
|
||||
i => (self.Owner.PlayerActor.traits.Get<PlayerResources>().GetSiloFullness() > i * 1.0f / numPips)
|
||||
? PipType.Yellow : PipType.Transparent );
|
||||
return Graphics.Util.MakeArray( Info.PipCount,
|
||||
i => (Player.GetSiloFullness() > i * 1.0f / Info.PipCount)
|
||||
? Info.PipColor : PipType.Transparent );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user