Merge Mods.RA into Mods.Cnc

This commit is contained in:
reaperrr
2017-02-12 01:08:31 +01:00
parent cdfa3fddf8
commit 0c3a786d10
47 changed files with 98 additions and 245 deletions

View File

@@ -0,0 +1,62 @@
#region Copyright & License Information
/*
* Copyright 2007-2017 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, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System;
using OpenRA.Mods.Common.Effects;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Traits
{
[Desc("This structure can be infiltrated causing funds to be stolen.")]
class InfiltrateForCashInfo : ITraitInfo
{
[Desc("Percentage of the victim's resources that will be stolen.")]
public readonly int Percentage = 100;
[Desc("Amount of guaranteed funds to claim when the victim does not have enough resources.",
"When negative, the production price of the infiltrating actor will be used instead.")]
public readonly int Minimum = -1;
[Desc("Maximum amount of funds which will be stolen.")]
public readonly int Maximum = int.MaxValue;
[Desc("Sound the victim will hear when they get robbed.")]
public readonly string Notification = null;
public object Create(ActorInitializer init) { return new InfiltrateForCash(this); }
}
class InfiltrateForCash : INotifyInfiltrated
{
readonly InfiltrateForCashInfo info;
public InfiltrateForCash(InfiltrateForCashInfo info) { this.info = info; }
void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator)
{
var targetResources = self.Owner.PlayerActor.Trait<PlayerResources>();
var spyResources = infiltrator.Owner.PlayerActor.Trait<PlayerResources>();
var spyValue = infiltrator.Info.TraitInfoOrDefault<ValuedInfo>();
var toTake = Math.Min(info.Maximum, (targetResources.Cash + targetResources.Resources) * info.Percentage / 100);
var toGive = Math.Max(toTake, info.Minimum >= 0 ? info.Minimum : spyValue != null ? spyValue.Cost : 0);
targetResources.TakeCash(toTake);
spyResources.GiveCash(toGive);
if (info.Notification != null)
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.Notification, self.Owner.Faction.InternalName);
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, infiltrator.Owner.Color.RGB, FloatingText.FormatCashTick(toGive), 30)));
}
}
}

View File

@@ -0,0 +1,44 @@
#region Copyright & License Information
/*
* Copyright 2007-2017 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, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.Common.Traits.Render;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Traits
{
[Desc("Reveals a decoration sprite to the indicated players when infiltrated.")]
class InfiltrateForDecorationInfo : WithDecorationInfo
{
public override object Create(ActorInitializer init) { return new InfiltrateForDecoration(init.Self, this); }
}
class InfiltrateForDecoration : WithDecoration, INotifyInfiltrated
{
readonly HashSet<Player> infiltrators = new HashSet<Player>();
public InfiltrateForDecoration(Actor self, InfiltrateForDecorationInfo info)
: base(self, info) { }
void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator)
{
infiltrators.Add(infiltrator.Owner);
}
protected override bool ShouldRender(Actor self)
{
return self.World.RenderPlayer == null || infiltrators.Any(i =>
Info.ValidStances.HasStance(i.Stances[self.World.RenderPlayer]));
}
}
}

View File

@@ -0,0 +1,29 @@
#region Copyright & License Information
/*
* Copyright 2007-2017 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, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Traits
{
[Desc("Steal and reset the owner's exploration.")]
class InfiltrateForExplorationInfo : TraitInfo<InfiltrateForExploration> { }
class InfiltrateForExploration : INotifyInfiltrated
{
void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator)
{
infiltrator.Owner.Shroud.Explore(self.Owner.Shroud);
if (!self.Owner.HasFogVisibility)
self.Owner.Shroud.ResetExploration();
}
}
}

View File

@@ -0,0 +1,45 @@
#region Copyright & License Information
/*
* Copyright 2007-2017 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, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Traits
{
class InfiltrateForPowerOutageInfo : ITraitInfo
{
public readonly int Duration = 25 * 20;
public object Create(ActorInitializer init) { return new InfiltrateForPowerOutage(init.Self, this); }
}
class InfiltrateForPowerOutage : INotifyOwnerChanged, INotifyInfiltrated
{
readonly InfiltrateForPowerOutageInfo info;
PowerManager playerPower;
public InfiltrateForPowerOutage(Actor self, InfiltrateForPowerOutageInfo info)
{
this.info = info;
playerPower = self.Owner.PlayerActor.Trait<PowerManager>();
}
void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator)
{
playerPower.TriggerPowerOutage(info.Duration);
}
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
{
playerPower = self.Owner.PlayerActor.Trait<PowerManager>();
}
}
}

View File

@@ -0,0 +1,42 @@
#region Copyright & License Information
/*
* Copyright 2007-2017 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, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Traits
{
class InfiltrateForSupportPowerInfo : ITraitInfo
{
[ActorReference, FieldLoader.Require] 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;
}
void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator)
{
infiltrator.World.AddFrameEndTask(w => w.CreateActor(info.Proxy, new TypeDictionary
{
new OwnerInit(infiltrator.Owner)
}));
}
}
}

View File

@@ -0,0 +1,152 @@
#region Copyright & License Information
/*
* Copyright 2007-2017 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, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Mods.Cnc.Activities;
using OpenRA.Mods.Common;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Orders;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Traits
{
class InfiltratesInfo : ITraitInfo
{
public readonly HashSet<string> Types = new HashSet<string>();
[VoiceReference] public readonly string Voice = "Action";
[Desc("What diplomatic stances can be infiltrated by this actor.")]
public readonly Stance ValidStances = Stance.Neutral | Stance.Enemy;
[Desc("Behaviour when entering the structure.",
"Possible values are Exit, Suicide, Dispose.")]
public readonly EnterBehaviour EnterBehaviour = EnterBehaviour.Dispose;
[Desc("Notification to play when a building is infiltrated.")]
public readonly string Notification = "BuildingInfiltrated";
[Desc("Experience to grant to the infiltrating player.")]
public readonly int PlayerExperience = 0;
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 InfiltrationOrderTargeter(info); }
}
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;
IEnumerable<string> targetTypes;
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;
targetTypes = frozen.TargetTypes;
}
else
targetTypes = order.TargetActor.GetEnabledTargetTypes();
return info.Types.Overlaps(targetTypes);
}
public string VoicePhraseForOrder(Actor self, Order order)
{
return order.OrderString == "Infiltrate" && IsValidOrder(self, order)
? info.Voice : 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
|| !info.Types.Overlaps(target.Actor.GetAllTargetTypes()))
return;
if (!order.Queued)
self.CancelActivity();
self.SetTargetLine(target, Color.Red);
self.QueueActivity(new Infiltrate(self, target.Actor, info.EnterBehaviour, info.ValidStances, info.Notification, info.PlayerExperience));
}
}
class InfiltrationOrderTargeter : UnitOrderTargeter
{
readonly InfiltratesInfo info;
public InfiltrationOrderTargeter(InfiltratesInfo info)
: base("Infiltrate", 7, "enter", true, false)
{
this.info = info;
}
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
{
var stance = self.Owner.Stances[target.Owner];
if (!info.ValidStances.HasStance(stance))
return false;
return info.Types.Overlaps(target.GetAllTargetTypes());
}
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{
var stance = self.Owner.Stances[target.Owner];
if (!info.ValidStances.HasStance(stance))
return false;
return info.Types.Overlaps(target.Info.TraitInfos<ITargetableInfo>().SelectMany(ti => ti.GetTargetTypes()));
}
}
}