Refactor more power and infiltration stuff. Create new power sabotage ability for spies in ra and ts.

This commit is contained in:
ScottNZ
2014-08-07 00:52:23 +12:00
parent 4fa199fb10
commit b70395e27c
31 changed files with 292 additions and 109 deletions

View File

@@ -0,0 +1,50 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using OpenRA.Mods.RA.Effects;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Infiltration
{
[Desc("This structure can be infiltrated causing funds to be stolen.")]
class InfiltrateForCashInfo : ITraitInfo
{
public readonly int Percentage = 50;
public readonly int Minimum = 500;
public readonly string SoundToVictim = "credit1.aud";
public object Create(ActorInitializer init) { return new InfiltrateForCash(this); }
}
class InfiltrateForCash : INotifyInfiltrated
{
readonly InfiltrateForCashInfo info;
public InfiltrateForCash(InfiltrateForCashInfo info) { this.info = info; }
public void Infiltrated(Actor self, Actor infiltrator)
{
var targetResources = self.Owner.PlayerActor.Trait<PlayerResources>();
var spyResources = infiltrator.Owner.PlayerActor.Trait<PlayerResources>();
var toTake = (targetResources.Cash + targetResources.Resources) * info.Percentage / 100;
var toGive = Math.Max(toTake, info.Minimum);
targetResources.TakeCash(toTake);
spyResources.GiveCash(toGive);
Sound.PlayToPlayer(self.Owner, info.SoundToVictim);
self.World.AddFrameEndTask(w => w.Add(new CashTick(self.CenterPosition, infiltrator.Owner.Color.RGB, toGive)));
}
}
}

View File

@@ -0,0 +1,27 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Infiltration
{
class InfiltrateForExplorationInfo : TraitInfo<InfiltrateForExploration> { }
class InfiltrateForExploration : INotifyInfiltrated
{
public void Infiltrated(Actor self, Actor infiltrator)
{
// Steal and reset the owners exploration
infiltrator.Owner.Shroud.Explore(self.Owner.Shroud);
if (!self.Owner.Shroud.HasFogVisibility())
self.Owner.Shroud.ResetExploration();
}
}
}

View File

@@ -0,0 +1,45 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Linq;
using OpenRA.Mods.RA.Power;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Infiltration
{
class InfiltrateForPowerOutageInfo : ITraitInfo
{
public readonly int Duration = 25 * 30;
public object Create(ActorInitializer init) { return new InfiltrateForPowerOutage(init.self, this); }
}
class InfiltrateForPowerOutage : INotifyCapture, INotifyInfiltrated
{
readonly InfiltrateForPowerOutageInfo info;
PowerManager playerPower;
public InfiltrateForPowerOutage(Actor self, InfiltrateForPowerOutageInfo info)
{
this.info = info;
playerPower = self.Owner.PlayerActor.Trait<PowerManager>();
}
public void Infiltrated(Actor self, Actor infiltrator)
{
playerPower.TriggerPowerOutage(info.Duration);
}
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
{
playerPower = self.Owner.PlayerActor.Trait<PowerManager>();
}
}
}

View File

@@ -0,0 +1,40 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Infiltration
{
class InfiltrateForSupportPowerInfo : ITraitInfo
{
[ActorReference] public readonly string Proxy = null;
public object Create(ActorInitializer init) { return new InfiltrateForSupportPower(this); }
}
class InfiltrateForSupportPower : INotifyInfiltrated
{
readonly InfiltrateForSupportPowerInfo info;
public InfiltrateForSupportPower(InfiltrateForSupportPowerInfo info)
{
this.info = info;
}
public void Infiltrated(Actor self, Actor infiltrator)
{
infiltrator.World.AddFrameEndTask(w => w.CreateActor(info.Proxy, new TypeDictionary
{
new OwnerInit(infiltrator.Owner)
}));
}
}
}

View File

@@ -0,0 +1,102 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Orders;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Infiltration
{
class InfiltratesInfo : ITraitInfo
{
public readonly string[] Types = { };
public object Create(ActorInitializer init) { return new Infiltrates(this); }
}
class Infiltrates : IIssueOrder, IResolveOrder, IOrderVoice
{
readonly InfiltratesInfo info;
public Infiltrates(InfiltratesInfo info)
{
this.info = info;
}
public IEnumerable<IOrderTargeter> Orders
{
get { yield return new TargetTypeOrderTargeter(info.Types, "Infiltrate", 7, "enter", true, false); }
}
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
{
if (order.OrderID != "Infiltrate")
return null;
if (target.Type == TargetType.FrozenActor)
return new Order(order.OrderID, self, queued) { ExtraData = target.FrozenActor.ID };
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
}
bool IsValidOrder(Actor self, Order order)
{
// Not targeting an actor
if (order.ExtraData == 0 && order.TargetActor == null)
return false;
ActorInfo ai;
if (order.ExtraData != 0)
{
// Targeted an actor under the fog
var frozenLayer = self.Owner.PlayerActor.TraitOrDefault<FrozenActorLayer>();
if (frozenLayer == null)
return false;
var frozen = frozenLayer.FromID(order.ExtraData);
if (frozen == null)
return false;
ai = frozen.Info;
}
else
ai = order.TargetActor.Info;
var i = ai.Traits.GetOrDefault<ITargetableInfo>();
return i != null && i.GetTargetTypes().Intersect(info.Types).Any();
}
public string VoicePhraseForOrder(Actor self, Order order)
{
return order.OrderString == "Infiltrate" && IsValidOrder(self, order)
? "Attack" : null;
}
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString != "Infiltrate" || !IsValidOrder(self, order))
return;
var target = self.ResolveFrozenActorOrder(order, Color.Red);
if (target.Type != TargetType.Actor)
return;
if (!order.Queued)
self.CancelActivity();
self.SetTargetLine(target, Color.Red);
self.QueueActivity(new Enter(target.Actor, new Infiltrate(target.Actor)));
}
}
}