Add enter-cloak & exit-cloak effect for Cloak

This commit is contained in:
dnqbob
2022-01-14 13:51:43 +08:00
committed by Matthias Mailänder
parent d67f696bd0
commit 831bed2c4d
11 changed files with 89 additions and 25 deletions

View File

@@ -13,6 +13,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Mods.Common.Effects;
using OpenRA.Primitives; using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;
@@ -33,8 +34,8 @@ namespace OpenRA.Mods.Common.Traits
Dock = 256 Dock = 256
} }
// Type tag for cloaktypes // Type tag for DetectionTypes
public class CloakType { } public class DetectionType { }
[Desc("This unit can cloak and uncloak in specific situations.")] [Desc("This unit can cloak and uncloak in specific situations.")]
public class CloakInfo : PausableConditionalTraitInfo public class CloakInfo : PausableConditionalTraitInfo
@@ -57,12 +58,36 @@ namespace OpenRA.Mods.Common.Traits
public readonly string Palette = "cloak"; public readonly string Palette = "cloak";
public readonly bool IsPlayerPalette = false; public readonly bool IsPlayerPalette = false;
public readonly BitSet<CloakType> CloakTypes = new BitSet<CloakType>("Cloak"); public readonly BitSet<DetectionType> DetectionTypes = new BitSet<DetectionType>("Cloak");
[GrantedConditionReference] [GrantedConditionReference]
[Desc("The condition to grant to self while cloaked.")] [Desc("The condition to grant to self while cloaked.")]
public readonly string CloakedCondition = null; public readonly string CloakedCondition = null;
[Desc("The type of cloak. Same type of cloaks won't trigger cloaking and uncloaking sound and effect.")]
public readonly string CloakType = null;
[Desc("Which image to use for the effect played when cloaking or uncloaking.")]
public readonly string EffectImage = null;
[Desc("Which effect sequence to play when cloaking.")]
[SequenceReference(nameof(EffectImage), allowNullImage: true)]
public readonly string CloakEffectSequence = null;
[Desc("Which effect sequence to play when uncloaking.")]
[SequenceReference(nameof(EffectImage), allowNullImage: true)]
public readonly string UncloakEffectSequence = null;
[PaletteReference(nameof(EffectPaletteIsPlayerPalette))]
public readonly string EffectPalette = "effect";
public readonly bool EffectPaletteIsPlayerPalette = false;
[Desc("Offset for the effect played when cloaking or uncloaking.")]
public readonly WVec EffectOffset = WVec.Zero;
[Desc("Should the effect track the actor.")]
public readonly bool EffectTracksActor = true;
public override object Create(ActorInitializer init) { return new Cloak(this); } public override object Create(ActorInitializer init) { return new Cloak(this); }
} }
@@ -88,9 +113,12 @@ namespace OpenRA.Mods.Common.Traits
protected override void Created(Actor self) protected override void Created(Actor self)
{ {
otherCloaks = self.TraitsImplementing<Cloak>() if (Info.CloakType != null)
.Where(c => c != this) {
.ToArray(); otherCloaks = self.TraitsImplementing<Cloak>()
.Where(c => c != this && c.Info.CloakType == Info.CloakType)
.ToArray();
}
if (Cloaked) if (Cloaked)
{ {
@@ -167,16 +195,50 @@ namespace OpenRA.Mods.Common.Traits
cloakedToken = self.GrantCondition(Info.CloakedCondition); cloakedToken = self.GrantCondition(Info.CloakedCondition);
// Sounds shouldn't play if the actor starts cloaked // Sounds shouldn't play if the actor starts cloaked
if (!(firstTick && Info.InitialDelay == 0) && !otherCloaks.Any(a => a.Cloaked)) if (!(firstTick && Info.InitialDelay == 0) && (otherCloaks == null || !otherCloaks.Any(a => a.Cloaked)))
{
var pos = self.CenterPosition;
Game.Sound.Play(SoundType.World, Info.CloakSound, self.CenterPosition); Game.Sound.Play(SoundType.World, Info.CloakSound, self.CenterPosition);
Func<WPos> posfunc = () => self.CenterPosition + Info.EffectOffset;
if (!Info.EffectTracksActor)
posfunc = () => pos + Info.EffectOffset;
if (Info.EffectImage != null && Info.CloakEffectSequence != null)
{
var palette = Info.EffectPalette;
if (Info.EffectPaletteIsPlayerPalette)
palette += self.Owner.InternalName;
self.World.AddFrameEndTask(w => w.Add(new SpriteEffect(
posfunc, () => WAngle.Zero, w, Info.EffectImage, Info.CloakEffectSequence, palette)));
}
}
} }
else if (!isCloaked && wasCloaked) else if (!isCloaked && wasCloaked)
{ {
if (cloakedToken != Actor.InvalidConditionToken) if (cloakedToken != Actor.InvalidConditionToken)
cloakedToken = self.RevokeCondition(cloakedToken); cloakedToken = self.RevokeCondition(cloakedToken);
if (!(firstTick && Info.InitialDelay == 0) && !otherCloaks.Any(a => a.Cloaked)) if (!(firstTick && Info.InitialDelay == 0) && (otherCloaks == null || !otherCloaks.Any(a => a.Cloaked)))
Game.Sound.Play(SoundType.World, Info.UncloakSound, self.CenterPosition); {
var pos = self.CenterPosition;
Game.Sound.Play(SoundType.World, Info.CloakSound, pos);
Func<WPos> posfunc = () => self.CenterPosition + Info.EffectOffset;
if (!Info.EffectTracksActor)
posfunc = () => pos + Info.EffectOffset;
if (Info.EffectImage != null && Info.UncloakEffectSequence != null)
{
var palette = Info.EffectPalette;
if (Info.EffectPaletteIsPlayerPalette)
palette += self.Owner.InternalName;
self.World.AddFrameEndTask(w => w.Add(new SpriteEffect(
posfunc, () => WAngle.Zero, w, Info.EffectImage, Info.UncloakEffectSequence, palette)));
}
}
} }
wasCloaked = isCloaked; wasCloaked = isCloaked;
@@ -196,7 +258,7 @@ namespace OpenRA.Mods.Common.Traits
return true; return true;
return self.World.ActorsWithTrait<DetectCloaked>().Any(a => a.Actor.Owner.IsAlliedWith(viewer) return self.World.ActorsWithTrait<DetectCloaked>().Any(a => a.Actor.Owner.IsAlliedWith(viewer)
&& Info.CloakTypes.Overlaps(a.Trait.Info.CloakTypes) && Info.DetectionTypes.Overlaps(a.Trait.Info.DetectionTypes)
&& (self.CenterPosition - a.Actor.CenterPosition).LengthSquared <= a.Trait.Range.LengthSquared); && (self.CenterPosition - a.Actor.CenterPosition).LengthSquared <= a.Trait.Range.LengthSquared);
} }

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Traits
public class DetectCloakedInfo : ConditionalTraitInfo public class DetectCloakedInfo : ConditionalTraitInfo
{ {
[Desc("Specific cloak classifications I can reveal.")] [Desc("Specific cloak classifications I can reveal.")]
public readonly BitSet<CloakType> CloakTypes = new BitSet<CloakType>("Cloak"); public readonly BitSet<DetectionType> DetectionTypes = new BitSet<DetectionType>("Cloak");
public readonly WDist Range = WDist.FromCells(5); public readonly WDist Range = WDist.FromCells(5);

View File

@@ -208,7 +208,7 @@ C17:
Cloak: Cloak:
InitialDelay: 0 InitialDelay: 0
CloakDelay: 0 CloakDelay: 0
CloakTypes: C17 DetectionTypes: C17
RequiresCondition: global-C17-stealth RequiresCondition: global-C17-stealth
Contrail@1: Contrail@1:
Offset: -261,-650,0 Offset: -261,-650,0

View File

@@ -433,7 +433,7 @@
Categories: Infantry Categories: Infantry
EdibleByLeap: EdibleByLeap:
DetectCloaked: DetectCloaked:
CloakTypes: Cloak DetectionTypes: Cloak
Range: 1c0 Range: 1c0
^Soldier: ^Soldier:
@@ -1190,7 +1190,7 @@
CloakSound: CloakSound:
UncloakSound: UncloakSound:
Palette: Palette:
CloakTypes: Mine DetectionTypes: Mine
InitialDelay: 0 InitialDelay: 0
Tooltip: Tooltip:
Name: Mine Name: Mine

View File

@@ -641,7 +641,7 @@ THF:
InitialDelay: 250 InitialDelay: 250
CloakDelay: 120 CloakDelay: 120
UncloakOn: Attack, Unload, Infiltrate, Demolish, Move UncloakOn: Attack, Unload, Infiltrate, Demolish, Move
CloakTypes: Cloak DetectionTypes: Cloak
IsPlayerPalette: true IsPlayerPalette: true
PauseOnCondition: cloak-force-disabled PauseOnCondition: cloak-force-disabled
GrantConditionOnDamageState@UNCLOAK: GrantConditionOnDamageState@UNCLOAK:

View File

@@ -213,7 +213,7 @@ SONAR:
Name: (support power proxy camera) Name: (support power proxy camera)
-RevealsShroud: -RevealsShroud:
DetectCloaked: DetectCloaked:
CloakTypes: Underwater DetectionTypes: Underwater
Range: 10c0 Range: 10c0
FLARE: FLARE:

View File

@@ -33,7 +33,7 @@ SS:
TargetTypes: Underwater, Submarine TargetTypes: Underwater, Submarine
RequiresCondition: underwater RequiresCondition: underwater
Cloak: Cloak:
CloakTypes: Underwater DetectionTypes: Underwater
InitialDelay: 0 InitialDelay: 0
CloakDelay: 50 CloakDelay: 50
CloakSound: subshow1.aud CloakSound: subshow1.aud
@@ -55,7 +55,7 @@ SS:
AutoTargetPriority@ATTACKANYTHING: AutoTargetPriority@ATTACKANYTHING:
ValidTargets: WaterActor, Underwater ValidTargets: WaterActor, Underwater
DetectCloaked: DetectCloaked:
CloakTypes: Underwater DetectionTypes: Underwater
Range: 4c0 Range: 4c0
RenderDetectionCircle: RenderDetectionCircle:
Explodes: Explodes:
@@ -100,7 +100,7 @@ MSUB:
TargetTypes: Underwater, Submarine TargetTypes: Underwater, Submarine
RequiresCondition: underwater RequiresCondition: underwater
Cloak: Cloak:
CloakTypes: Underwater DetectionTypes: Underwater
InitialDelay: 0 InitialDelay: 0
CloakDelay: 100 CloakDelay: 100
CloakSound: subshow1.aud CloakSound: subshow1.aud
@@ -126,7 +126,7 @@ MSUB:
InitialStance: HoldFire InitialStance: HoldFire
InitialStanceAI: ReturnFire InitialStanceAI: ReturnFire
DetectCloaked: DetectCloaked:
CloakTypes: Underwater DetectionTypes: Underwater
Range: 4c0 Range: 4c0
RenderDetectionCircle: RenderDetectionCircle:
Explodes: Explodes:
@@ -182,7 +182,7 @@ DD:
AttackTurreted: AttackTurreted:
WithSpriteTurret: WithSpriteTurret:
DetectCloaked: DetectCloaked:
CloakTypes: Underwater DetectionTypes: Underwater
Range: 4c0 Range: 4c0
RenderDetectionCircle: RenderDetectionCircle:
Selectable: Selectable:
@@ -333,7 +333,7 @@ PT:
WithMuzzleOverlay: WithMuzzleOverlay:
WithSpriteTurret: WithSpriteTurret:
DetectCloaked: DetectCloaked:
CloakTypes: Underwater DetectionTypes: Underwater
Range: 4c0 Range: 4c0
RenderDetectionCircle: RenderDetectionCircle:
Selectable: Selectable:

View File

@@ -214,7 +214,7 @@ SPEN:
Power: Power:
Amount: -30 Amount: -30
DetectCloaked: DetectCloaked:
CloakTypes: Underwater DetectionTypes: Underwater
Range: 10c0 Range: 10c0
RenderDetectionCircle: RenderDetectionCircle:
ProvidesPrerequisite@soviet: ProvidesPrerequisite@soviet:
@@ -329,7 +329,7 @@ SYRD:
Power: Power:
Amount: -30 Amount: -30
DetectCloaked: DetectCloaked:
CloakTypes: Underwater DetectionTypes: Underwater
Range: 10c0 Range: 10c0
RenderDetectionCircle: RenderDetectionCircle:
ProvidesPrerequisite@allies: ProvidesPrerequisite@allies:

View File

@@ -508,7 +508,7 @@ MNLY:
RearmSound: minelay1.aud RearmSound: minelay1.aud
DetectCloaked: DetectCloaked:
Range: 5c0 Range: 5c0
CloakTypes: Mine DetectionTypes: Mine
RenderDetectionCircle: RenderDetectionCircle:
Explodes: Explodes:
Weapon: ATMine Weapon: ATMine

View File

@@ -130,6 +130,7 @@
CloakSound: cloak5.aud CloakSound: cloak5.aud
UncloakSound: cloak5.aud UncloakSound: cloak5.aud
UncloakOn: Attack, Unload, Infiltrate, Demolish, Damage, Heal UncloakOn: Attack, Unload, Infiltrate, Demolish, Damage, Heal
CloakType: nod-stealth
ExternalCondition@CLOAKGENERATOR: ExternalCondition@CLOAKGENERATOR:
Condition: cloakgenerator Condition: cloakgenerator
ExternalCondition@CRATE-CLOAK: ExternalCondition@CRATE-CLOAK:

View File

@@ -520,6 +520,7 @@ STNK:
IsPlayerPalette: true IsPlayerPalette: true
UncloakOn: Attack, Unload, Infiltrate, Demolish, Damage, Heal UncloakOn: Attack, Unload, Infiltrate, Demolish, Damage, Heal
PauseOnCondition: cloak-force-disabled || empdisable PauseOnCondition: cloak-force-disabled || empdisable
CloakType: nod-stealth
GrantConditionOnDamageState@UNCLOAK: GrantConditionOnDamageState@UNCLOAK:
Condition: cloak-force-disabled Condition: cloak-force-disabled
ValidDamageStates: Critical ValidDamageStates: Critical