Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some necessary functions & fix for AttackOverlay #21411

Merged
merged 5 commits into from
Apr 30, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 14 additions & 4 deletions OpenRA.Mods.Common/Traits/Render/WithAttackOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ namespace OpenRA.Mods.Common.Traits.Render
[Desc("Rendered together with an attack.")]
public class WithAttackOverlayInfo : TraitInfo, Requires<RenderSpritesInfo>
{
[Desc("Armament that will play the animation. Set to null to allow all armaments.")]
public readonly string Armament = null;

[SequenceReference]
[FieldLoader.Require]
[Desc("Sequence name to use")]
Expand All @@ -29,6 +32,8 @@ public class WithAttackOverlayInfo : TraitInfo, Requires<RenderSpritesInfo>
[Desc("Custom palette is a player palette BaseName")]
public readonly bool IsPlayerPalette = false;

public readonly bool IsDecoration = false;

[Desc("Delay in ticks before overlay starts, either relative to attack preparation or attack.")]
public readonly int Delay = 0;

Expand All @@ -52,10 +57,15 @@ public WithAttackOverlay(ActorInitializer init, WithAttackOverlayInfo info)
this.info = info;

renderSprites = init.Self.Trait<RenderSprites>();
var body = init.Self.TraitOrDefault<BodyOrientation>();
var facing = init.Self.TraitOrDefault<IFacing>();

overlay = new Animation(init.World, renderSprites.GetImage(init.Self), RenderSprites.MakeFacingFunc(init.Self));
overlay = new Animation(init.World, renderSprites.GetImage(init.Self), facing == null ? () => WAngle.Zero : (body == null ? () => facing.Facing : () => body.QuantizeFacing(facing.Facing)))
{
IsDecoration = info.IsDecoration
};

renderSprites.Add(new AnimationWithOffset(overlay, null, () => !attacking),
renderSprites.Add(new AnimationWithOffset(overlay, null, () => !attacking, p => RenderUtils.ZOffsetFromCenter(init.Self, p, 1)),
info.Palette, info.IsPlayerPalette);
}

Expand All @@ -67,7 +77,7 @@ void PlayOverlay()

void INotifyAttack.Attacking(Actor self, in Target target, Armament a, Barrel barrel)
{
if (info.DelayRelativeTo == AttackDelayType.Attack)
if (info.DelayRelativeTo == AttackDelayType.Attack && (string.IsNullOrEmpty(info.Armament) || info.Armament == a.Info.Name))
{
if (info.Delay > 0)
tick = info.Delay;
Expand All @@ -78,7 +88,7 @@ void INotifyAttack.Attacking(Actor self, in Target target, Armament a, Barrel ba

void INotifyAttack.PreparingAttack(Actor self, in Target target, Armament a, Barrel barrel)
{
if (info.DelayRelativeTo == AttackDelayType.Preparation)
if (info.DelayRelativeTo == AttackDelayType.Preparation && (string.IsNullOrEmpty(info.Armament) || info.Armament == a.Info.Name))
{
if (info.Delay > 0)
tick = info.Delay;
Expand Down