Initial commit: OpenRA game engine
Fork from OpenRA/OpenRA with one-click launch script (start-ra.cmd) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
157
OpenRA.Mods.Cnc/Traits/SupportPowers/AttackOrderPower.cs
Normal file
157
OpenRA.Mods.Cnc/Traits/SupportPowers/AttackOrderPower.cs
Normal file
@@ -0,0 +1,157 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* 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.Graphics;
|
||||
using OpenRA.Mods.Common.Graphics;
|
||||
using OpenRA.Mods.Common.Orders;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Traits
|
||||
{
|
||||
sealed class AttackOrderPowerInfo : SupportPowerInfo, Requires<AttackBaseInfo>
|
||||
{
|
||||
[Desc("Range circle color.")]
|
||||
public readonly Color CircleColor = Color.Red;
|
||||
|
||||
[Desc("Range circle line width.")]
|
||||
public readonly float CircleWidth = 1;
|
||||
|
||||
[Desc("Range circle border color.")]
|
||||
public readonly Color CircleBorderColor = Color.FromArgb(96, Color.Black);
|
||||
|
||||
[Desc("Range circle border width.")]
|
||||
public readonly float CircleBorderWidth = 3;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new AttackOrderPower(init.Self, this); }
|
||||
}
|
||||
|
||||
sealed class AttackOrderPower : SupportPower, INotifyCreated, INotifyBurstComplete
|
||||
{
|
||||
readonly AttackOrderPowerInfo info;
|
||||
AttackBase attack;
|
||||
|
||||
public AttackOrderPower(Actor self, AttackOrderPowerInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public override void SelectTarget(Actor self, string order, SupportPowerManager manager)
|
||||
{
|
||||
self.World.OrderGenerator = new SelectAttackPowerTarget(self, order, manager, info.Cursor, attack);
|
||||
}
|
||||
|
||||
public override void Activate(Actor self, Order order, SupportPowerManager manager)
|
||||
{
|
||||
base.Activate(self, order, manager);
|
||||
PlayLaunchSounds();
|
||||
|
||||
attack.AttackTarget(order.Target, AttackSource.Default, false, false, true);
|
||||
}
|
||||
|
||||
protected override void Created(Actor self)
|
||||
{
|
||||
attack = self.Trait<AttackBase>();
|
||||
|
||||
base.Created(self);
|
||||
}
|
||||
|
||||
void INotifyBurstComplete.FiredBurst(Actor self, in Target target, Armament a)
|
||||
{
|
||||
self.World.IssueOrder(new Order("Stop", self, false));
|
||||
}
|
||||
}
|
||||
|
||||
public class SelectAttackPowerTarget : OrderGenerator
|
||||
{
|
||||
readonly SupportPowerManager manager;
|
||||
readonly SupportPowerInstance instance;
|
||||
readonly string order;
|
||||
readonly string cursor;
|
||||
readonly string cursorBlocked;
|
||||
readonly AttackBase attack;
|
||||
|
||||
protected override MouseActionType ActionType => MouseActionType.SupportPower;
|
||||
|
||||
public SelectAttackPowerTarget(Actor self, string order, SupportPowerManager manager, string cursor, AttackBase attack)
|
||||
: base(self.World)
|
||||
{
|
||||
instance = manager.GetPowersForActor(self).FirstOrDefault();
|
||||
this.manager = manager;
|
||||
this.order = order;
|
||||
this.cursor = cursor;
|
||||
this.attack = attack;
|
||||
cursorBlocked = cursor + "-blocked";
|
||||
}
|
||||
|
||||
bool IsValidTarget(World world, CPos cell)
|
||||
{
|
||||
var pos = world.Map.CenterOfCell(cell);
|
||||
var range = attack.GetMaximumRange().LengthSquared;
|
||||
|
||||
return world.Map.Contains(cell) && instance.Instances.Any(a => !a.IsTraitPaused && (a.Self.CenterPosition - pos).HorizontalLengthSquared < range);
|
||||
}
|
||||
|
||||
protected override IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
world.CancelInputMode();
|
||||
if (IsValidTarget(world, cell))
|
||||
yield return new Order(order, manager.Self, Target.FromCell(world, cell), false)
|
||||
{
|
||||
SuppressVisualFeedback = true
|
||||
};
|
||||
}
|
||||
|
||||
protected override void Tick(World world)
|
||||
{
|
||||
// Cancel the OG if we can't use the power
|
||||
if (!manager.Powers.TryGetValue(order, out var p) || !p.Active || !p.Ready)
|
||||
world.CancelInputMode();
|
||||
}
|
||||
|
||||
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world) { yield break; }
|
||||
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world) { yield break; }
|
||||
|
||||
protected override IEnumerable<IRenderable> RenderAnnotations(WorldRenderer wr, World world)
|
||||
{
|
||||
var info = instance.Info as AttackOrderPowerInfo;
|
||||
foreach (var a in instance.Instances.Where(i => !i.IsTraitPaused))
|
||||
{
|
||||
yield return new RangeCircleAnnotationRenderable(
|
||||
a.Self.CenterPosition,
|
||||
attack.GetMinimumRange(),
|
||||
0,
|
||||
info.CircleColor,
|
||||
info.CircleWidth,
|
||||
info.CircleBorderColor,
|
||||
info.CircleBorderWidth);
|
||||
|
||||
yield return new RangeCircleAnnotationRenderable(
|
||||
a.Self.CenterPosition,
|
||||
attack.GetMaximumRange(),
|
||||
0,
|
||||
info.CircleColor,
|
||||
info.CircleWidth,
|
||||
info.CircleBorderColor,
|
||||
info.CircleBorderWidth);
|
||||
}
|
||||
}
|
||||
|
||||
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
return IsValidTarget(world, cell) ? cursor : cursorBlocked;
|
||||
}
|
||||
}
|
||||
}
|
||||
394
OpenRA.Mods.Cnc/Traits/SupportPowers/ChronoshiftPower.cs
Normal file
394
OpenRA.Mods.Cnc/Traits/SupportPowers/ChronoshiftPower.cs
Normal file
@@ -0,0 +1,394 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* 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.Graphics;
|
||||
using OpenRA.Mods.Common.Orders;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Traits
|
||||
{
|
||||
sealed class ChronoshiftPowerInfo : SupportPowerInfo
|
||||
{
|
||||
[FieldLoader.Require]
|
||||
[Desc("Size of the footprint of the affected area.")]
|
||||
public readonly CVec Dimensions = CVec.Zero;
|
||||
|
||||
[FieldLoader.Require]
|
||||
[Desc("Actual footprint. Cells marked as x will be affected.")]
|
||||
public readonly string Footprint = string.Empty;
|
||||
|
||||
[Desc("Ticks until returning after teleportation.")]
|
||||
public readonly int Duration = 750;
|
||||
|
||||
[PaletteReference]
|
||||
public readonly string TargetOverlayPalette = TileSet.TerrainPaletteInternalName;
|
||||
|
||||
public readonly string FootprintImage = "overlay";
|
||||
|
||||
[SequenceReference(nameof(FootprintImage), prefix: true)]
|
||||
public readonly string ValidFootprintSequence = "target-valid";
|
||||
|
||||
[SequenceReference(nameof(FootprintImage))]
|
||||
public readonly string InvalidFootprintSequence = "target-invalid";
|
||||
|
||||
[SequenceReference(nameof(FootprintImage))]
|
||||
public readonly string SourceFootprintSequence = "target-select";
|
||||
|
||||
public readonly bool KillCargo = true;
|
||||
|
||||
[CursorReference]
|
||||
[Desc("Cursor to display when selecting targets for the chronoshift.")]
|
||||
public readonly string SelectionCursor = "chrono-select";
|
||||
|
||||
[CursorReference]
|
||||
[Desc("Cursor to display when targeting an area for the chronoshift.")]
|
||||
public readonly string TargetCursor = "chrono-target";
|
||||
|
||||
[CursorReference]
|
||||
[Desc("Cursor to display when the targeted area is blocked.")]
|
||||
public readonly string TargetBlockedCursor = "move-blocked";
|
||||
|
||||
public override object Create(ActorInitializer init) { return new ChronoshiftPower(init.Self, this); }
|
||||
}
|
||||
|
||||
sealed class ChronoshiftPower : SupportPower
|
||||
{
|
||||
readonly char[] footprint;
|
||||
readonly CVec dimensions;
|
||||
|
||||
public ChronoshiftPower(Actor self, ChronoshiftPowerInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
footprint = info.Footprint.Where(c => !char.IsWhiteSpace(c)).ToArray();
|
||||
dimensions = info.Dimensions;
|
||||
}
|
||||
|
||||
public override void SelectTarget(Actor self, string order, SupportPowerManager manager)
|
||||
{
|
||||
self.World.OrderGenerator = new SelectChronoshiftTarget(Self.World, order, manager, this);
|
||||
}
|
||||
|
||||
public override void Activate(Actor self, Order order, SupportPowerManager manager)
|
||||
{
|
||||
base.Activate(self, order, manager);
|
||||
PlayLaunchSounds();
|
||||
|
||||
var info = (ChronoshiftPowerInfo)Info;
|
||||
var targetDelta = self.World.Map.CellContaining(order.Target.CenterPosition) - order.ExtraLocation;
|
||||
foreach (var target in UnitsInRange(order.ExtraLocation))
|
||||
{
|
||||
var cs = target.TraitsImplementing<Chronoshiftable>()
|
||||
.FirstEnabledConditionalTraitOrDefault();
|
||||
|
||||
if (cs == null)
|
||||
continue;
|
||||
|
||||
var targetCell = target.Location + targetDelta;
|
||||
|
||||
if (self.Owner.Shroud.IsExplored(targetCell) && cs.CanChronoshiftTo(target, targetCell))
|
||||
cs.Teleport(target, targetCell, info.Duration, info.KillCargo, self);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Actor> UnitsInRange(CPos xy)
|
||||
{
|
||||
var tiles = CellsMatching(xy, footprint, dimensions);
|
||||
var units = new HashSet<Actor>();
|
||||
foreach (var t in tiles)
|
||||
units.UnionWith(Self.World.ActorMap.GetActorsAt(t));
|
||||
|
||||
return units.Where(a => a.TraitsImplementing<Chronoshiftable>().Any(cs => !cs.IsTraitDisabled));
|
||||
}
|
||||
|
||||
public bool SimilarTerrain(CPos xy, CPos sourceLocation)
|
||||
{
|
||||
if (!Self.Owner.Shroud.IsExplored(xy))
|
||||
return false;
|
||||
|
||||
var sourceTiles = CellsMatching(xy, footprint, dimensions);
|
||||
var destTiles = CellsMatching(sourceLocation, footprint, dimensions);
|
||||
|
||||
if (!sourceTiles.Any() || !destTiles.Any())
|
||||
return false;
|
||||
|
||||
using (var se = sourceTiles.GetEnumerator())
|
||||
using (var de = destTiles.GetEnumerator())
|
||||
while (se.MoveNext() && de.MoveNext())
|
||||
{
|
||||
var a = se.Current;
|
||||
var b = de.Current;
|
||||
|
||||
if (!Self.Owner.Shroud.IsExplored(a) || !Self.Owner.Shroud.IsExplored(b))
|
||||
return false;
|
||||
|
||||
if (Self.World.Map.GetTerrainIndex(a) != Self.World.Map.GetTerrainIndex(b))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
sealed class SelectChronoshiftTarget : OrderGenerator
|
||||
{
|
||||
readonly ChronoshiftPower power;
|
||||
readonly char[] footprint;
|
||||
readonly CVec dimensions;
|
||||
readonly Sprite tile;
|
||||
readonly float alpha;
|
||||
readonly SupportPowerManager manager;
|
||||
readonly string order;
|
||||
|
||||
protected override MouseActionType ActionType => MouseActionType.SupportPower;
|
||||
|
||||
public SelectChronoshiftTarget(World world, string order, SupportPowerManager manager, ChronoshiftPower power)
|
||||
: base(world)
|
||||
{
|
||||
this.manager = manager;
|
||||
this.order = order;
|
||||
this.power = power;
|
||||
|
||||
var info = (ChronoshiftPowerInfo)power.Info;
|
||||
var s = world.Map.Sequences.GetSequence(info.FootprintImage, info.SourceFootprintSequence);
|
||||
footprint = info.Footprint.Where(c => !char.IsWhiteSpace(c)).ToArray();
|
||||
dimensions = info.Dimensions;
|
||||
tile = s.GetSprite(0);
|
||||
alpha = s.GetAlpha(0);
|
||||
}
|
||||
|
||||
protected override IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
world.CancelInputMode();
|
||||
world.OrderGenerator = new SelectDestination(world, order, manager, power, cell);
|
||||
yield break;
|
||||
}
|
||||
|
||||
protected override void Tick(World world)
|
||||
{
|
||||
// Cancel the OG if we can't use the power
|
||||
if (!manager.Powers.TryGetValue(order, out var p) || !p.Active || !p.Ready)
|
||||
world.CancelInputMode();
|
||||
}
|
||||
|
||||
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world) { yield break; }
|
||||
|
||||
protected override IEnumerable<IRenderable> RenderAnnotations(WorldRenderer wr, World world)
|
||||
{
|
||||
var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
|
||||
var targetUnits = power.UnitsInRange(xy).Where(a => !world.FogObscures(a));
|
||||
|
||||
foreach (var unit in targetUnits)
|
||||
{
|
||||
if (unit.CanBeViewedByPlayer(manager.Self.Owner))
|
||||
{
|
||||
var decorations = unit.TraitsImplementing<ISelectionDecorations>().FirstEnabledTraitOrDefault();
|
||||
if (decorations != null)
|
||||
foreach (var d in decorations.RenderSelectionAnnotations(unit, wr, Color.Red))
|
||||
yield return d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world)
|
||||
{
|
||||
var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
|
||||
var tiles = power.CellsMatching(xy, footprint, dimensions);
|
||||
var palette = wr.Palette(((ChronoshiftPowerInfo)power.Info).TargetOverlayPalette);
|
||||
foreach (var t in tiles)
|
||||
yield return new SpriteRenderable(
|
||||
tile, wr.World.Map.CenterOfCell(t), WVec.Zero, -511, palette, 1f, alpha, float3.Ones, TintModifiers.IgnoreWorldTint, true);
|
||||
}
|
||||
|
||||
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
return ((ChronoshiftPowerInfo)power.Info).SelectionCursor;
|
||||
}
|
||||
}
|
||||
|
||||
sealed class SelectDestination : OrderGenerator
|
||||
{
|
||||
readonly ChronoshiftPower power;
|
||||
readonly CPos sourceLocation;
|
||||
readonly char[] footprint;
|
||||
readonly CVec dimensions;
|
||||
readonly Sprite validTile, invalidTile, sourceTile;
|
||||
readonly float validAlpha, invalidAlpha, sourceAlpha;
|
||||
readonly SupportPowerManager manager;
|
||||
readonly string order;
|
||||
|
||||
protected override MouseActionType ActionType => MouseActionType.SupportPower;
|
||||
|
||||
public SelectDestination(World world, string order, SupportPowerManager manager, ChronoshiftPower power, CPos sourceLocation)
|
||||
: base(world)
|
||||
{
|
||||
this.manager = manager;
|
||||
this.order = order;
|
||||
this.power = power;
|
||||
this.sourceLocation = sourceLocation;
|
||||
|
||||
var info = (ChronoshiftPowerInfo)power.Info;
|
||||
footprint = info.Footprint.Where(c => !char.IsWhiteSpace(c)).ToArray();
|
||||
dimensions = info.Dimensions;
|
||||
|
||||
var sequences = world.Map.Sequences;
|
||||
var tilesetValid = info.ValidFootprintSequence + "-" + world.Map.Tileset.ToLowerInvariant();
|
||||
if (sequences.HasSequence(info.FootprintImage, tilesetValid))
|
||||
{
|
||||
var validSequence = sequences.GetSequence(info.FootprintImage, tilesetValid);
|
||||
validTile = validSequence.GetSprite(0);
|
||||
validAlpha = validSequence.GetAlpha(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
var validSequence = sequences.GetSequence(info.FootprintImage, info.ValidFootprintSequence);
|
||||
validTile = validSequence.GetSprite(0);
|
||||
validAlpha = validSequence.GetAlpha(0);
|
||||
}
|
||||
|
||||
var invalidSequence = sequences.GetSequence(info.FootprintImage, info.InvalidFootprintSequence);
|
||||
invalidTile = invalidSequence.GetSprite(0);
|
||||
invalidAlpha = invalidSequence.GetAlpha(0);
|
||||
|
||||
var sourceSequence = sequences.GetSequence(info.FootprintImage, info.SourceFootprintSequence);
|
||||
sourceTile = sourceSequence.GetSprite(0);
|
||||
sourceAlpha = sourceSequence.GetAlpha(0);
|
||||
}
|
||||
|
||||
protected override IEnumerable<Order> OrderInner(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
var ret = OrderInner(cell).FirstOrDefault();
|
||||
if (ret == null)
|
||||
yield break;
|
||||
|
||||
world.CancelInputMode();
|
||||
yield return ret;
|
||||
}
|
||||
|
||||
IEnumerable<Order> OrderInner(CPos xy)
|
||||
{
|
||||
// Cannot chronoshift into unexplored location
|
||||
if (IsValidTarget(xy))
|
||||
yield return new Order(order, manager.Self, Target.FromCell(manager.Self.World, xy), false)
|
||||
{
|
||||
ExtraLocation = sourceLocation,
|
||||
SuppressVisualFeedback = true
|
||||
};
|
||||
}
|
||||
|
||||
protected override void Tick(World world)
|
||||
{
|
||||
// Cancel the OG if we can't use the power
|
||||
if (!manager.Powers.TryGetValue(order, out var p) || !p.Active || !p.Ready)
|
||||
world.CancelInputMode();
|
||||
}
|
||||
|
||||
protected override IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
|
||||
{
|
||||
var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
|
||||
var palette = wr.Palette(power.Info.IconPalette);
|
||||
|
||||
// Destination tiles
|
||||
var delta = xy - sourceLocation;
|
||||
foreach (var t in power.CellsMatching(sourceLocation, footprint, dimensions))
|
||||
{
|
||||
var isValid = manager.Self.Owner.Shroud.IsExplored(t + delta);
|
||||
var tile = isValid ? validTile : invalidTile;
|
||||
var alpha = isValid ? validAlpha : invalidAlpha;
|
||||
yield return new SpriteRenderable(
|
||||
tile, wr.World.Map.CenterOfCell(t + delta), WVec.Zero, -511, palette, 1f, alpha, float3.Ones, TintModifiers.IgnoreWorldTint, true);
|
||||
}
|
||||
|
||||
// Unit previews
|
||||
foreach (var unit in power.UnitsInRange(sourceLocation))
|
||||
{
|
||||
if (unit.CanBeViewedByPlayer(manager.Self.Owner))
|
||||
{
|
||||
var targetCell = unit.Location + (xy - sourceLocation);
|
||||
var canEnter = manager.Self.Owner.Shroud.IsExplored(targetCell) &&
|
||||
unit.Trait<Chronoshiftable>().CanChronoshiftTo(unit, targetCell);
|
||||
var tile = canEnter ? validTile : invalidTile;
|
||||
var alpha = canEnter ? validAlpha : invalidAlpha;
|
||||
yield return new SpriteRenderable(
|
||||
tile, wr.World.Map.CenterOfCell(targetCell), WVec.Zero, -511, palette, 1f, alpha, float3.Ones, TintModifiers.IgnoreWorldTint, true);
|
||||
}
|
||||
|
||||
var offset = world.Map.CenterOfCell(xy) - world.Map.CenterOfCell(sourceLocation);
|
||||
if (unit.CanBeViewedByPlayer(manager.Self.Owner))
|
||||
foreach (var r in unit.Render(wr))
|
||||
yield return r.OffsetBy(offset);
|
||||
}
|
||||
}
|
||||
|
||||
protected override IEnumerable<IRenderable> RenderAnnotations(WorldRenderer wr, World world)
|
||||
{
|
||||
foreach (var unit in power.UnitsInRange(sourceLocation))
|
||||
{
|
||||
if (unit.CanBeViewedByPlayer(manager.Self.Owner))
|
||||
{
|
||||
var decorations = unit.TraitsImplementing<ISelectionDecorations>().FirstEnabledTraitOrDefault();
|
||||
if (decorations != null)
|
||||
foreach (var d in decorations.RenderSelectionAnnotations(unit, wr, Color.Red))
|
||||
yield return d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override IEnumerable<IRenderable> Render(WorldRenderer wr, World world)
|
||||
{
|
||||
var palette = wr.Palette(power.Info.IconPalette);
|
||||
|
||||
// Source tiles
|
||||
foreach (var t in power.CellsMatching(sourceLocation, footprint, dimensions))
|
||||
yield return new SpriteRenderable(
|
||||
sourceTile, wr.World.Map.CenterOfCell(t), WVec.Zero, -511, palette, 1f, sourceAlpha, float3.Ones, TintModifiers.IgnoreWorldTint, true);
|
||||
}
|
||||
|
||||
bool IsValidTarget(CPos xy)
|
||||
{
|
||||
var canTeleport = false;
|
||||
var anyUnitsInRange = false;
|
||||
foreach (var unit in power.UnitsInRange(sourceLocation))
|
||||
{
|
||||
anyUnitsInRange = true;
|
||||
var targetCell = unit.Location + (xy - sourceLocation);
|
||||
if (manager.Self.Owner.Shroud.IsExplored(targetCell) && unit.Trait<Chronoshiftable>().CanChronoshiftTo(unit, targetCell))
|
||||
{
|
||||
canTeleport = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Don't teleport if there are no units in range (either all moved out of range, or none yet moved into range)
|
||||
if (!anyUnitsInRange)
|
||||
return false;
|
||||
|
||||
if (!canTeleport)
|
||||
{
|
||||
// Check the terrain types. This will allow chronoshifts to occur on empty terrain to terrain of
|
||||
// a similar type. This also keeps the cursor from changing in non-visible property, alerting the
|
||||
// chronoshifter of enemy unit presence
|
||||
canTeleport = power.SimilarTerrain(sourceLocation, xy);
|
||||
}
|
||||
|
||||
return canTeleport;
|
||||
}
|
||||
|
||||
protected override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi)
|
||||
{
|
||||
var powerInfo = (ChronoshiftPowerInfo)power.Info;
|
||||
return IsValidTarget(cell) ? powerInfo.TargetCursor : powerInfo.TargetBlockedCursor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
191
OpenRA.Mods.Cnc/Traits/SupportPowers/DropPodsPower.cs
Normal file
191
OpenRA.Mods.Cnc/Traits/SupportPowers/DropPodsPower.cs
Normal file
@@ -0,0 +1,191 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* 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 System.Collections.Frozen;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Mods.Cnc.Effects;
|
||||
using OpenRA.Mods.Common;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Traits
|
||||
{
|
||||
public class DropPodsPowerInfo : SupportPowerInfo, IRulesetLoaded
|
||||
{
|
||||
[FieldLoader.Require]
|
||||
[Desc("Drop pod unit")]
|
||||
[ActorReference([typeof(AircraftInfo), typeof(FallsToEarthInfo)])]
|
||||
public readonly ImmutableArray<string> UnitTypes = default;
|
||||
|
||||
[Desc("Number of drop pods spawned.")]
|
||||
public readonly int2 Drops = new(5, 8);
|
||||
|
||||
[Desc("Sets the approach direction.")]
|
||||
public readonly WAngle PodFacing = new(128);
|
||||
|
||||
[Desc("Maximum offset from targetLocation")]
|
||||
public readonly int PodScatter = 3;
|
||||
|
||||
[Desc("Effect sequence sprite image")]
|
||||
public readonly string EntryEffect = "podring";
|
||||
|
||||
[Desc("Effect sequence to display in the air.")]
|
||||
[SequenceReference(nameof(EntryEffect))]
|
||||
public readonly string EntryEffectSequence = "idle";
|
||||
|
||||
[PaletteReference]
|
||||
public readonly string EntryEffectPalette = "effect";
|
||||
|
||||
[ActorReference]
|
||||
[Desc("Actor to spawn when the attack starts")]
|
||||
public readonly string CameraActor = null;
|
||||
|
||||
[Desc("Number of ticks to keep the camera alive")]
|
||||
public readonly int CameraRemoveDelay = 25;
|
||||
|
||||
[Desc("Which weapon to fire")]
|
||||
[WeaponReference]
|
||||
public readonly string Weapon = "Vulcan2";
|
||||
|
||||
public WeaponInfo WeaponInfo { get; private set; }
|
||||
|
||||
[Desc("Apply the weapon impact this many ticks into the effect")]
|
||||
public readonly int WeaponDelay = 0;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new DropPodsPower(init.Self, this); }
|
||||
|
||||
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
||||
{
|
||||
var weaponToLower = (Weapon ?? string.Empty).ToLowerInvariant();
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out var weapon))
|
||||
throw new YamlException($"Weapons Ruleset does not contain an entry '{weaponToLower}'");
|
||||
|
||||
WeaponInfo = weapon;
|
||||
|
||||
base.RulesetLoaded(rules, ai);
|
||||
}
|
||||
}
|
||||
|
||||
public class DropPodsPower : SupportPower
|
||||
{
|
||||
readonly DropPodsPowerInfo info;
|
||||
readonly string[] unitTypes;
|
||||
readonly Dictionary<string, Func<CPos, WPos>> getLaunchLocation = [];
|
||||
readonly Dictionary<string, FrozenSet<string>> landableTerrainTypes = [];
|
||||
|
||||
public DropPodsPower(Actor self, DropPodsPowerInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
this.info = info;
|
||||
|
||||
unitTypes = info.UnitTypes.Select(unit => unit.ToLowerInvariant()).ToArray();
|
||||
|
||||
foreach (var unitType in unitTypes)
|
||||
{
|
||||
if (!self.World.Map.Rules.Actors.TryGetValue(unitType, out var actorInfo))
|
||||
throw new NotImplementedException("No rules definition for unit " + unitType);
|
||||
|
||||
var aircraftInfo = actorInfo.TraitInfo<AircraftInfo>();
|
||||
var altitude = aircraftInfo.CruiseAltitude.Length;
|
||||
|
||||
var delta =
|
||||
new WVec(0, -altitude * aircraftInfo.Speed / actorInfo.TraitInfo<FallsToEarthInfo>().Velocity.Length, 0)
|
||||
.Rotate(WRot.FromYaw(info.PodFacing));
|
||||
|
||||
// PERF: Cache constant values.
|
||||
getLaunchLocation[unitType] = pos => self.World.Map.CenterOfCell(pos) - delta + new WVec(0, 0, altitude);
|
||||
landableTerrainTypes[unitType] = aircraftInfo.LandableTerrainTypes;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Activate(Actor self, Order order, SupportPowerManager manager)
|
||||
{
|
||||
SendDropPods(self, self.World.Map.CellContaining(order.Target.CenterPosition), () => base.Activate(self, order, manager));
|
||||
}
|
||||
|
||||
public bool CanActivate(World world, CPos cell)
|
||||
{
|
||||
return world.Map.Contains(cell) && world.Map.FindTilesInCircle(cell, info.PodScatter)
|
||||
.Any(c => landableTerrainTypes.Any(ltr => ltr.Value.Contains(world.Map.GetTerrainInfo(c).Type))
|
||||
&& !world.ActorMap.GetActorsAt(c).Any());
|
||||
}
|
||||
|
||||
public void SendDropPods(Actor self, CPos targetCell, Action onSuccess)
|
||||
{
|
||||
self.World.AddFrameEndTask(world =>
|
||||
{
|
||||
if (!CanActivate(self.World, targetCell))
|
||||
return;
|
||||
|
||||
PlayLaunchSounds();
|
||||
onSuccess();
|
||||
|
||||
if (info.CameraActor != null)
|
||||
{
|
||||
var camera = world.CreateActor(info.CameraActor,
|
||||
[
|
||||
new LocationInit(targetCell),
|
||||
new OwnerInit(self.Owner),
|
||||
]);
|
||||
|
||||
camera.QueueActivity(new Wait(info.CameraRemoveDelay));
|
||||
camera.QueueActivity(new RemoveSelf());
|
||||
}
|
||||
|
||||
var dropAmount = world.SharedRandom.Next(info.Drops.X, info.Drops.Y);
|
||||
var validUnitTypes = unitTypes.ToList();
|
||||
for (var i = 0; i < dropAmount; i++)
|
||||
{
|
||||
if (validUnitTypes.Count == 0)
|
||||
return;
|
||||
|
||||
var unitType = validUnitTypes.Random(world.SharedRandom);
|
||||
var validDropLocations = world.Map.FindTilesInCircle(targetCell, info.PodScatter)
|
||||
.Where(c => landableTerrainTypes[unitType].Contains(world.Map.GetTerrainInfo(c).Type)
|
||||
&& !world.ActorMap.GetActorsAt(c).Any());
|
||||
|
||||
if (!validDropLocations.Any())
|
||||
{
|
||||
validUnitTypes.Remove(unitType);
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
|
||||
var dropLocation = validDropLocations.Random(world.SharedRandom);
|
||||
var launchLocation = getLaunchLocation[unitType](dropLocation);
|
||||
|
||||
var pod = world.CreateActor(false, unitType,
|
||||
[
|
||||
new CenterPositionInit(launchLocation),
|
||||
new OwnerInit(self.Owner),
|
||||
new FacingInit(info.PodFacing)
|
||||
]);
|
||||
|
||||
var aircraft = pod.Trait<Aircraft>();
|
||||
if (!aircraft.CanLand(dropLocation))
|
||||
pod.Dispose();
|
||||
else
|
||||
{
|
||||
world.Add(new DropPodImpact(self.Owner, info.WeaponInfo, world, launchLocation, Target.FromCell(world, dropLocation),
|
||||
info.WeaponDelay, info.EntryEffect, info.EntryEffectSequence, info.EntryEffectPalette));
|
||||
|
||||
world.Add(pod);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
123
OpenRA.Mods.Cnc/Traits/SupportPowers/GpsPower.cs
Normal file
123
OpenRA.Mods.Cnc/Traits/SupportPowers/GpsPower.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* 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.Linq;
|
||||
using OpenRA.Mods.Cnc.Effects;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Mods.Common.Traits.Radar;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Traits
|
||||
{
|
||||
[Desc("Requires `GpsWatcher` on the player actor.")]
|
||||
sealed class GpsPowerInfo : SupportPowerInfo
|
||||
{
|
||||
[Desc("Delay in ticks between launching and revealing the map.")]
|
||||
public readonly int RevealDelay = 0;
|
||||
|
||||
public readonly string DoorImage = "atek";
|
||||
|
||||
[SequenceReference(nameof(DoorImage))]
|
||||
public readonly string DoorSequence = "active";
|
||||
|
||||
[PaletteReference(nameof(DoorPaletteIsPlayerPalette))]
|
||||
[Desc("Palette to use for rendering the launch animation")]
|
||||
public readonly string DoorPalette = "player";
|
||||
|
||||
[Desc("Custom palette is a player palette BaseName")]
|
||||
public readonly bool DoorPaletteIsPlayerPalette = true;
|
||||
|
||||
public readonly string SatelliteImage = "sputnik";
|
||||
|
||||
[SequenceReference(nameof(SatelliteImage))]
|
||||
public readonly string SatelliteSequence = "idle";
|
||||
|
||||
[PaletteReference(nameof(SatellitePaletteIsPlayerPalette))]
|
||||
[Desc("Palette to use for rendering the satellite projectile")]
|
||||
public readonly string SatellitePalette = "player";
|
||||
|
||||
[Desc("Custom palette is a player palette BaseName")]
|
||||
public readonly bool SatellitePaletteIsPlayerPalette = true;
|
||||
|
||||
[Desc("Requires an actor with an online `ProvidesRadar` to show GPS dots.")]
|
||||
public readonly bool RequiresActiveRadar = true;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new GpsPower(init.Self, this); }
|
||||
}
|
||||
|
||||
sealed class GpsPower : SupportPower, INotifyKilled, INotifySold, INotifyOwnerChanged, ITick
|
||||
{
|
||||
readonly Actor self;
|
||||
readonly GpsPowerInfo info;
|
||||
GpsWatcher owner;
|
||||
|
||||
public GpsPower(Actor self, GpsPowerInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
this.self = self;
|
||||
this.info = info;
|
||||
owner = self.Owner.PlayerActor.Trait<GpsWatcher>();
|
||||
owner.GpsAdd(self);
|
||||
}
|
||||
|
||||
public override void Charged(Actor self, string key)
|
||||
{
|
||||
self.Owner.PlayerActor.Trait<SupportPowerManager>().Powers[key].Activate(new Order());
|
||||
}
|
||||
|
||||
public override void Activate(Actor self, Order order, SupportPowerManager manager)
|
||||
{
|
||||
base.Activate(self, order, manager);
|
||||
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
PlayLaunchSounds();
|
||||
|
||||
w.Add(new SatelliteLaunch(self, info));
|
||||
});
|
||||
}
|
||||
|
||||
void INotifyKilled.Killed(Actor self, AttackInfo e) { RemoveGps(self); }
|
||||
|
||||
void INotifySold.Selling(Actor self) { }
|
||||
void INotifySold.Sold(Actor self) { RemoveGps(self); }
|
||||
|
||||
void RemoveGps(Actor self)
|
||||
{
|
||||
// Extra function just in case something needs to be added later
|
||||
owner.GpsRemove(self);
|
||||
}
|
||||
|
||||
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||
{
|
||||
RemoveGps(self);
|
||||
owner = newOwner.PlayerActor.Trait<GpsWatcher>();
|
||||
owner.GpsAdd(self);
|
||||
}
|
||||
|
||||
bool NoActiveRadar { get { return !self.World.ActorsHavingTrait<ProvidesRadar>(r => !r.IsTraitDisabled).Any(a => a.Owner == self.Owner); } }
|
||||
bool wasPaused;
|
||||
|
||||
void ITick.Tick(Actor self)
|
||||
{
|
||||
if (!wasPaused && (IsTraitPaused || (info.RequiresActiveRadar && NoActiveRadar)))
|
||||
{
|
||||
wasPaused = true;
|
||||
RemoveGps(self);
|
||||
}
|
||||
else if (wasPaused && !IsTraitPaused && !(info.RequiresActiveRadar && NoActiveRadar))
|
||||
{
|
||||
wasPaused = false;
|
||||
owner.GpsAdd(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* 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.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Traits
|
||||
{
|
||||
[Desc("Grants a prerequisite while discharging at a configurable rate.")]
|
||||
public class GrantPrerequisiteChargeDrainPowerInfo : SupportPowerInfo, ITechTreePrerequisiteInfo
|
||||
{
|
||||
[Desc("Rate at which the power discharges compared to charging")]
|
||||
public readonly int DischargeModifier = 300;
|
||||
|
||||
[FieldLoader.Require]
|
||||
[Desc("The prerequisite type that this provides.")]
|
||||
public readonly string Prerequisite = null;
|
||||
|
||||
[Desc("Label to display over the support power icon and in its tooltip while the power is active.")]
|
||||
public readonly string ActiveText = "ACTIVE";
|
||||
|
||||
[Desc("Label to display over the support power icon and in its tooltip while the power is available but not active.")]
|
||||
public readonly string AvailableText = "READY";
|
||||
|
||||
IEnumerable<string> ITechTreePrerequisiteInfo.Prerequisites(ActorInfo info)
|
||||
{
|
||||
yield return Prerequisite;
|
||||
}
|
||||
|
||||
public override object Create(ActorInitializer init) { return new GrantPrerequisiteChargeDrainPower(init.Self, this); }
|
||||
}
|
||||
|
||||
public class GrantPrerequisiteChargeDrainPower : SupportPower, ITechTreePrerequisite, INotifyOwnerChanged
|
||||
{
|
||||
readonly GrantPrerequisiteChargeDrainPowerInfo info;
|
||||
readonly string[] prerequisites;
|
||||
TechTree techTree;
|
||||
bool active;
|
||||
|
||||
public GrantPrerequisiteChargeDrainPower(Actor self, GrantPrerequisiteChargeDrainPowerInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
this.info = info;
|
||||
prerequisites = [info.Prerequisite];
|
||||
}
|
||||
|
||||
protected override void Created(Actor self)
|
||||
{
|
||||
techTree = self.Owner.PlayerActor.Trait<TechTree>();
|
||||
|
||||
base.Created(self);
|
||||
}
|
||||
|
||||
void INotifyOwnerChanged.OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||
{
|
||||
techTree = newOwner.PlayerActor.Trait<TechTree>();
|
||||
active = false;
|
||||
}
|
||||
|
||||
public override DischargeableSupportPowerInstance CreateInstance(string key, SupportPowerManager manager)
|
||||
{
|
||||
return new DischargeableSupportPowerInstance(key, info, manager);
|
||||
}
|
||||
|
||||
public void Activate(Actor self)
|
||||
{
|
||||
active = true;
|
||||
techTree.ActorChanged(self);
|
||||
}
|
||||
|
||||
public void Deactivate(Actor self)
|
||||
{
|
||||
active = false;
|
||||
techTree.ActorChanged(self);
|
||||
}
|
||||
|
||||
IEnumerable<string> ITechTreePrerequisite.ProvidesPrerequisites => active ? prerequisites : Enumerable.Empty<string>();
|
||||
|
||||
public class DischargeableSupportPowerInstance : SupportPowerInstance
|
||||
{
|
||||
// Whether the power is available to activate (even if not fully charged)
|
||||
bool available;
|
||||
|
||||
// Whether the power is active right now
|
||||
// Note that this is fundamentally different to SupportPowerInstance.Active
|
||||
// which has a much closer meaning to available above.
|
||||
bool active;
|
||||
|
||||
// Additional discharge rate accrued from damage
|
||||
int additionalDischargeSubTicks = 0;
|
||||
|
||||
public DischargeableSupportPowerInstance(string key, GrantPrerequisiteChargeDrainPowerInfo info, SupportPowerManager manager)
|
||||
: base(key, info, manager) { }
|
||||
|
||||
void Deactivate()
|
||||
{
|
||||
active = false;
|
||||
notifiedCharging = false;
|
||||
|
||||
// Fully depleting the charge disables the power until it is again fully charged
|
||||
if (!Active || remainingSubTicks >= TotalTicks * 100)
|
||||
available = false;
|
||||
|
||||
foreach (var p in Instances)
|
||||
((GrantPrerequisiteChargeDrainPower)p).Deactivate(p.Self);
|
||||
}
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
var orig = remainingSubTicks;
|
||||
base.Tick();
|
||||
|
||||
if (Ready)
|
||||
available = true;
|
||||
|
||||
if (active && !Active)
|
||||
Deactivate();
|
||||
|
||||
if (active)
|
||||
{
|
||||
remainingSubTicks = orig + ((GrantPrerequisiteChargeDrainPowerInfo)Info).DischargeModifier + additionalDischargeSubTicks;
|
||||
additionalDischargeSubTicks = 0;
|
||||
|
||||
if (remainingSubTicks > TotalTicks * 100)
|
||||
{
|
||||
remainingSubTicks = TotalTicks * 100;
|
||||
Deactivate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Discharge(int subTicks)
|
||||
{
|
||||
additionalDischargeSubTicks += subTicks;
|
||||
}
|
||||
|
||||
public override void Target()
|
||||
{
|
||||
if (available && Active)
|
||||
Manager.Self.World.IssueOrder(new Order(Key, Manager.Self, false) { ExtraData = active ? 0U : 1U });
|
||||
}
|
||||
|
||||
public override void Activate(Order order)
|
||||
{
|
||||
if (active && order.ExtraData == 0)
|
||||
{
|
||||
Deactivate();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!available || order.ExtraData != 1)
|
||||
return;
|
||||
|
||||
var power = Instances.FirstOrDefault(i => !i.IsTraitPaused);
|
||||
if (power == null)
|
||||
return;
|
||||
|
||||
active = true;
|
||||
|
||||
// Only play the activation sound once!
|
||||
power.PlayLaunchSounds();
|
||||
|
||||
foreach (var p in Instances)
|
||||
((GrantPrerequisiteChargeDrainPower)p).Activate(p.Self);
|
||||
}
|
||||
|
||||
public override string IconOverlayTextOverride()
|
||||
{
|
||||
return GetTextOverride();
|
||||
}
|
||||
|
||||
public override string TooltipTimeTextOverride()
|
||||
{
|
||||
return GetTextOverride();
|
||||
}
|
||||
|
||||
string GetTextOverride()
|
||||
{
|
||||
// NB: Info might return null if there are no instances
|
||||
if (!Active || Info is not GrantPrerequisiteChargeDrainPowerInfo info)
|
||||
return null;
|
||||
|
||||
return active ? info.ActiveText : available ? info.AvailableText : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
104
OpenRA.Mods.Cnc/Traits/SupportPowers/IonCannonPower.cs
Normal file
104
OpenRA.Mods.Cnc/Traits/SupportPowers/IonCannonPower.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* 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.GameRules;
|
||||
using OpenRA.Mods.Cnc.Effects;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Traits
|
||||
{
|
||||
sealed class IonCannonPowerInfo : SupportPowerInfo, IRulesetLoaded
|
||||
{
|
||||
[ActorReference]
|
||||
[Desc("Actor to spawn when the attack starts")]
|
||||
public readonly string CameraActor = null;
|
||||
|
||||
[Desc("Number of ticks to keep the camera alive")]
|
||||
public readonly int CameraRemoveDelay = 25;
|
||||
|
||||
[Desc("Effect sequence sprite image")]
|
||||
public readonly string Effect = "ionsfx";
|
||||
|
||||
[SequenceReference(nameof(Effect))]
|
||||
[Desc("Effect sequence to display")]
|
||||
public readonly string EffectSequence = "idle";
|
||||
|
||||
[PaletteReference]
|
||||
public readonly string EffectPalette = "effect";
|
||||
|
||||
[WeaponReference]
|
||||
[Desc("Which weapon to fire")]
|
||||
public readonly string Weapon = "IonCannon";
|
||||
|
||||
public WeaponInfo WeaponInfo { get; private set; }
|
||||
|
||||
[Desc("Apply the weapon impact this many ticks into the effect")]
|
||||
public readonly int WeaponDelay = 7;
|
||||
|
||||
[Desc("Sound to instantly play at the targeted area.")]
|
||||
public readonly string OnFireSound = null;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new IonCannonPower(init.Self, this); }
|
||||
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
||||
{
|
||||
var weaponToLower = (Weapon ?? string.Empty).ToLowerInvariant();
|
||||
if (!rules.Weapons.TryGetValue(weaponToLower, out var weapon))
|
||||
throw new YamlException($"Weapons Ruleset does not contain an entry '{weaponToLower}'");
|
||||
|
||||
WeaponInfo = weapon;
|
||||
|
||||
base.RulesetLoaded(rules, ai);
|
||||
}
|
||||
}
|
||||
|
||||
sealed class IonCannonPower : SupportPower
|
||||
{
|
||||
readonly IonCannonPowerInfo info;
|
||||
|
||||
public IonCannonPower(Actor self, IonCannonPowerInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public override void Activate(Actor self, Order order, SupportPowerManager manager)
|
||||
{
|
||||
base.Activate(self, order, manager);
|
||||
|
||||
Activate(self, order.Target);
|
||||
}
|
||||
|
||||
public void Activate(Actor self, Target target)
|
||||
{
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
PlayLaunchSounds();
|
||||
Game.Sound.Play(SoundType.World, info.OnFireSound, target.CenterPosition);
|
||||
w.Add(new IonCannon(self.Owner, info.WeaponInfo, w, self.CenterPosition, target,
|
||||
info.Effect, info.EffectSequence, info.EffectPalette, info.WeaponDelay));
|
||||
|
||||
if (info.CameraActor == null)
|
||||
return;
|
||||
|
||||
var camera = w.CreateActor(info.CameraActor,
|
||||
[
|
||||
new LocationInit(self.World.Map.CellContaining(target.CenterPosition)),
|
||||
new OwnerInit(self.Owner),
|
||||
]);
|
||||
|
||||
camera.QueueActivity(new Wait(info.CameraRemoveDelay));
|
||||
camera.QueueActivity(new RemoveSelf());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user