Add Type Support for InfiltrateFor* traits
This commit is contained in:
committed by
Paul Chote
parent
f7de5d46be
commit
fc07391c8c
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Cnc.Activities
|
||||
ini.Infiltrating(self);
|
||||
|
||||
foreach (var t in target.TraitsImplementing<INotifyInfiltrated>())
|
||||
t.Infiltrated(target, self);
|
||||
t.Infiltrated(target, self, infiltrates.Info.Types);
|
||||
|
||||
var exp = self.Owner.PlayerActor.TraitOrDefault<PlayerExperience>();
|
||||
if (exp != null)
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Mods.Common.Effects;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
@@ -19,6 +20,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
[Desc("This structure can be infiltrated causing funds to be stolen.")]
|
||||
class InfiltrateForCashInfo : ITraitInfo
|
||||
{
|
||||
public readonly HashSet<string> Types = new HashSet<string>();
|
||||
|
||||
[Desc("Percentage of the victim's resources that will be stolen.")]
|
||||
public readonly int Percentage = 100;
|
||||
|
||||
@@ -44,8 +47,11 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
|
||||
public InfiltrateForCash(InfiltrateForCashInfo info) { this.info = info; }
|
||||
|
||||
void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator)
|
||||
void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator, HashSet<string> types)
|
||||
{
|
||||
if (!info.Types.Overlaps(types))
|
||||
return;
|
||||
|
||||
var targetResources = self.Owner.PlayerActor.Trait<PlayerResources>();
|
||||
var spyResources = infiltrator.Owner.PlayerActor.Trait<PlayerResources>();
|
||||
var spyValue = infiltrator.Info.TraitInfoOrDefault<ValuedInfo>();
|
||||
|
||||
@@ -20,18 +20,27 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
[Desc("Reveals a decoration sprite to the indicated players when infiltrated.")]
|
||||
class InfiltrateForDecorationInfo : WithDecorationInfo
|
||||
{
|
||||
public readonly HashSet<string> Types = new HashSet<string>();
|
||||
|
||||
public override object Create(ActorInitializer init) { return new InfiltrateForDecoration(init.Self, this); }
|
||||
}
|
||||
|
||||
class InfiltrateForDecoration : WithDecoration, INotifyInfiltrated
|
||||
{
|
||||
readonly HashSet<Player> infiltrators = new HashSet<Player>();
|
||||
readonly InfiltrateForDecorationInfo info;
|
||||
|
||||
public InfiltrateForDecoration(Actor self, InfiltrateForDecorationInfo info)
|
||||
: base(self, info) { }
|
||||
|
||||
void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator)
|
||||
: base(self, info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator, HashSet<string> types)
|
||||
{
|
||||
if (!info.Types.Overlaps(types))
|
||||
return;
|
||||
|
||||
infiltrators.Add(infiltrator.Owner);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
@@ -16,12 +17,27 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Cnc.Traits
|
||||
{
|
||||
[Desc("Steal and reset the owner's exploration.")]
|
||||
class InfiltrateForExplorationInfo : TraitInfo<InfiltrateForExploration> { }
|
||||
class InfiltrateForExplorationInfo : ITraitInfo
|
||||
{
|
||||
public readonly HashSet<string> Types = new HashSet<string>();
|
||||
|
||||
public object Create(ActorInitializer init) { return new InfiltrateForExploration(init.Self, this); }
|
||||
}
|
||||
|
||||
class InfiltrateForExploration : INotifyInfiltrated
|
||||
{
|
||||
void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator)
|
||||
readonly InfiltrateForExplorationInfo info;
|
||||
|
||||
public InfiltrateForExploration(Actor self, InfiltrateForExplorationInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator, HashSet<string> types)
|
||||
{
|
||||
if (!info.Types.Overlaps(types))
|
||||
return;
|
||||
|
||||
infiltrator.Owner.Shroud.Explore(self.Owner.Shroud);
|
||||
var preventReset = self.Owner.PlayerActor.TraitsImplementing<IPreventsShroudReset>()
|
||||
.Any(p => p.PreventShroudReset(self));
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
@@ -16,6 +17,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
{
|
||||
class InfiltrateForPowerOutageInfo : ITraitInfo
|
||||
{
|
||||
public readonly HashSet<string> Types = new HashSet<string>();
|
||||
|
||||
public readonly int Duration = 25 * 20;
|
||||
|
||||
public object Create(ActorInitializer init) { return new InfiltrateForPowerOutage(init.Self, this); }
|
||||
@@ -32,8 +35,11 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
playerPower = self.Owner.PlayerActor.Trait<PowerManager>();
|
||||
}
|
||||
|
||||
void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator)
|
||||
void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator, HashSet<string> types)
|
||||
{
|
||||
if (!info.Types.Overlaps(types))
|
||||
return;
|
||||
|
||||
playerPower.TriggerPowerOutage(info.Duration);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
@@ -19,6 +20,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
{
|
||||
[ActorReference, FieldLoader.Require] public readonly string Proxy = null;
|
||||
|
||||
public readonly HashSet<string> Types = new HashSet<string>();
|
||||
|
||||
public object Create(ActorInitializer init) { return new InfiltrateForSupportPower(this); }
|
||||
}
|
||||
|
||||
@@ -31,8 +34,11 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator)
|
||||
void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator, HashSet<string> types)
|
||||
{
|
||||
if (!info.Types.Overlaps(types))
|
||||
return;
|
||||
|
||||
infiltrator.World.AddFrameEndTask(w => w.CreateActor(info.Proxy, new TypeDictionary
|
||||
{
|
||||
new OwnerInit(infiltrator.Owner)
|
||||
|
||||
Reference in New Issue
Block a user