Finish theif logic. TODO: Determine amount to steal

This commit is contained in:
Paul Chote
2010-01-08 21:59:28 +13:00
parent d03ee4c0c5
commit fc2b671b2c
6 changed files with 35 additions and 25 deletions

View File

@@ -165,7 +165,7 @@
<Compile Include="Traits\Activities\Repair.cs" />
<Compile Include="Traits\Activities\ReturnToBase.cs" />
<Compile Include="Traits\Activities\Sell.cs" />
<Compile Include="Traits\Activities\StealOre.cs" />
<Compile Include="Traits\Activities\Steal.cs" />
<Compile Include="Traits\Activities\Teleport.cs" />
<Compile Include="BuildingInfluenceMap.cs" />
<Compile Include="Orders\IOrderGenerator.cs" />
@@ -260,7 +260,7 @@
<Compile Include="Traits\StoresOre.cs" />
<Compile Include="Traits\Submarine.cs" />
<Compile Include="Traits\TakeCover.cs" />
<Compile Include="Traits\ThiefSteal.cs" />
<Compile Include="Traits\Thief.cs" />
<Compile Include="Traits\TraitsInterfaces.cs" />
<Compile Include="Traits\Tree.cs" />
<Compile Include="Traits\Turreted.cs" />

View File

@@ -5,27 +5,21 @@ using System.Text;
namespace OpenRa.Game.Traits.Activities
{
class StealOre : IActivity
class Steal : IActivity
{
Actor target;
public const int CashStolen = 100; //todo: push this out to Rules
public StealOre(Actor target) { this.target = target; }
public Steal(Actor target) { this.target = target; }
public IActivity NextActivity { get; set; }
public IActivity Tick(Actor self)
{
if (target == null || target.IsDead) return NextActivity;
if (target.Owner == self.Owner) return NextActivity;
target.Owner.TakeCash(CashStolen);
self.Owner.GiveCash(CashStolen);
// the thief is sacrificed.
self.Health = 0;
Game.world.AddFrameEndTask(w => w.Remove(self));
foreach (var t in target.traits.WithInterface<IAcceptThief>())
t.OnSteal(target, self);
return NextActivity;
}

View File

@@ -1,9 +1,11 @@
using System.Collections.Generic;
using System;
namespace OpenRa.Game.Traits
{
class StoresOre : IPips
class StoresOre : IPips, IAcceptThief
{
public const int MaxStealAmount = 100; //todo: How is cash stolen determined?
readonly Actor self;
public StoresOre(Actor self)
@@ -11,6 +13,20 @@ namespace OpenRa.Game.Traits
this.self = self;
}
public void OnSteal(Actor self, Actor thief)
{
var cashStolen = Math.Min(MaxStealAmount, self.Owner.Cash);
self.Owner.TakeCash(cashStolen);
thief.Owner.GiveCash(cashStolen);
if (Game.LocalPlayer == thief.Owner)
Sound.Play("credit1.aud");
// the thief is sacrificed.
thief.Health = 0;
Game.world.AddFrameEndTask(w => w.Remove(thief));
}
public IEnumerable<PipType> GetPips(Actor self)
{
for (int i = 0; i < self.Info.OrePips; i++)

View File

@@ -1,19 +1,18 @@
using OpenRa.Game.Traits.Activities;
using System.Collections.Generic;
using System.Linq;
namespace OpenRa.Game.Traits
{
class ThiefSteal : IOrder
class Thief : IOrder
{
public ThiefSteal(Actor self) { }
public Thief(Actor self) { }
public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
{
if (mi.Button != MouseButton.Right) return null;
if (underCursor == null) return null;
if (!underCursor.traits.Contains<Building>()) return null;
// todo: other bits
if (!underCursor.traits.WithInterface<IAcceptThief>().Any()) return null;
return new Order("Steal", self, underCursor, int2.Zero, null);
}
@@ -23,7 +22,7 @@ namespace OpenRa.Game.Traits
{
self.CancelActivity();
self.QueueActivity(new Move(order.TargetActor, 1));
self.QueueActivity(new StealOre(order.TargetActor));
self.QueueActivity(new Steal(order.TargetActor));
}
}
}

View File

@@ -17,6 +17,7 @@ namespace OpenRa.Game.Traits
interface INotifyDamage { void Damaged(Actor self, AttackInfo e); }
interface INotifyBuildComplete { void BuildingComplete (Actor self); }
interface INotifyProduction { void UnitProduced(Actor self, Actor other); }
interface IAcceptThief { void OnSteal(Actor self, Actor thief); }
interface IOrder
{
Order IssueOrder( Actor self, int2 xy, MouseInput mi, Actor underCursor );

View File

@@ -594,7 +594,7 @@ SelectionSize=12,17,0,-9
[THF]
Description=Thief
Voice=ThiefVoice
Traits=Unit, Mobile, RenderInfantry, TakeCover, SquishByTank, Passenger
Traits=Unit, Mobile, RenderInfantry, TakeCover, SquishByTank, Passenger, Thief
LongDesc=Infiltrates enemy refineries & \nsilos, and steals money stored there.\n Unarmed
SelectionSize=12,17,0,-9
[E7]