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

View File

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

View File

@@ -1,9 +1,11 @@
using System.Collections.Generic; using System.Collections.Generic;
using System;
namespace OpenRa.Game.Traits 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; readonly Actor self;
public StoresOre(Actor self) public StoresOre(Actor self)
@@ -11,6 +13,20 @@ namespace OpenRa.Game.Traits
this.self = self; 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) public IEnumerable<PipType> GetPips(Actor self)
{ {
for (int i = 0; i < self.Info.OrePips; i++) for (int i = 0; i < self.Info.OrePips; i++)

View File

@@ -1,19 +1,18 @@
using OpenRa.Game.Traits.Activities; using OpenRa.Game.Traits.Activities;
using System.Collections.Generic;
using System.Linq;
namespace OpenRa.Game.Traits 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) public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor)
{ {
if (mi.Button != MouseButton.Right) return null; if (mi.Button != MouseButton.Right) return null;
if (underCursor == null) return null; if (underCursor == null) return null;
if (!underCursor.traits.Contains<Building>()) return null; if (!underCursor.traits.WithInterface<IAcceptThief>().Any()) return null;
// todo: other bits
return new Order("Steal", self, underCursor, int2.Zero, null); return new Order("Steal", self, underCursor, int2.Zero, null);
} }
@@ -23,7 +22,7 @@ namespace OpenRa.Game.Traits
{ {
self.CancelActivity(); self.CancelActivity();
self.QueueActivity(new Move(order.TargetActor, 1)); 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 INotifyDamage { void Damaged(Actor self, AttackInfo e); }
interface INotifyBuildComplete { void BuildingComplete (Actor self); } interface INotifyBuildComplete { void BuildingComplete (Actor self); }
interface INotifyProduction { void UnitProduced(Actor self, Actor other); } interface INotifyProduction { void UnitProduced(Actor self, Actor other); }
interface IAcceptThief { void OnSteal(Actor self, Actor thief); }
interface IOrder interface IOrder
{ {
Order IssueOrder( Actor self, int2 xy, MouseInput mi, Actor underCursor ); Order IssueOrder( Actor self, int2 xy, MouseInput mi, Actor underCursor );

View File

@@ -594,7 +594,7 @@ SelectionSize=12,17,0,-9
[THF] [THF]
Description=Thief Description=Thief
Voice=ThiefVoice 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 LongDesc=Infiltrates enemy refineries & \nsilos, and steals money stored there.\n Unarmed
SelectionSize=12,17,0,-9 SelectionSize=12,17,0,-9
[E7] [E7]