Skip to content

Commit

Permalink
Merge pull request #148 from dnqbob/rv-new-cloakeff
Browse files Browse the repository at this point in the history
Berserkable fix and New cloak effect
  • Loading branch information
MustaphaTR authored Jan 12, 2024
2 parents 153fe1d + fc9ce01 commit 642ce93
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
6 changes: 3 additions & 3 deletions OpenRA.Mods.AS/Traits/Berserkable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
*/
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;

namespace OpenRA.Mods.AS.Traits
Expand All @@ -21,7 +21,7 @@ namespace OpenRA.Mods.AS.Traits
public class BerserkableInfo : ConditionalTraitInfo
{
[Desc("Do not attack this type of actors when berserked.")]
public readonly string[] ActorsToIgnore = Array.Empty<string>();
public readonly BitSet<TargetableType> TargetTypesToIgnore;

public override object Create(ActorInitializer init) { return new Berserkable(this); }
}
Expand Down Expand Up @@ -108,7 +108,7 @@ void INotifyIdle.TickIdle(Actor self)
var range = GetScanRange(atbs);

var targets = self.World.FindActorsInCircle(self.CenterPosition, range)
.Where(a => a != self && a.IsTargetableBy(self) && !Info.ActorsToIgnore.Contains(a.Info.Name)).ToArray();
.Where(a => a != self && a.IsTargetableBy(self) && !Info.TargetTypesToIgnore.Overlaps(a.GetEnabledTargetTypes())).ToArray();

var preferredtargets = targets.Where(a => a.Owner.IsAlliedWith(self.Owner));

Expand Down
32 changes: 29 additions & 3 deletions OpenRA.Mods.Common/Traits/Cloak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,14 @@ public class CloakInfo : PausableConditionalTraitInfo
[Desc("Render effect to use when cloaked.")]
public readonly CloakStyle CloakStyle = CloakStyle.Alpha;

[Desc("The alpha level to use when cloaked when using Alpha CloakStyle.")]
public readonly float CloakedAlpha = 0.55f;
[Desc("The minimum alpha level to use when cloaked when using Alpha CloakStyle.")]
public readonly float MinCloakedAlpha = 0.55f;

[Desc("The maximum alpha level to use when cloaked when using Alpha CloakStyle.")]
public readonly float MaxCloakedAlpha = 0.55f;

[Desc("Time to to change from maximum alpha level to minimum alpha level when using Alpha CloakStyle.")]
public readonly int CloakAlphaChangeInterval = 10;

[Desc("The color to use when cloaked when using Color CloakStyle.")]
public readonly Color CloakedColor = Color.FromArgb(140, 0, 0, 0);
Expand Down Expand Up @@ -134,13 +140,16 @@ public class Cloak : PausableConditionalTrait<CloakInfo>, IRenderModifier, INoti
bool wasCloaked = false;
bool firstTick = true;
int cloakedToken = Actor.InvalidConditionToken;
float currentAlpha;
float alphaChange;

public Cloak(CloakInfo info)
: base(info)
{
remainingTime = info.InitialDelay;
cloakedColor = new float3(info.CloakedColor.R, info.CloakedColor.G, info.CloakedColor.B) / 255f;
cloakedColorAlpha = info.CloakedColor.A / 255f;
alphaChange = (info.MaxCloakedAlpha - info.MinCloakedAlpha) / Math.Max(1, info.CloakAlphaChangeInterval);
}

protected override void Created(Actor self)
Expand All @@ -161,6 +170,8 @@ protected override void Created(Actor self)
cloakedToken = self.GrantCondition(Info.CloakedCondition);
}

currentAlpha = Info.MinCloakedAlpha + alphaChange * Game.CosmeticRandom.Next(Info.CloakAlphaChangeInterval);

base.Created(self);
}

Expand Down Expand Up @@ -196,7 +207,7 @@ IEnumerable<IRenderable> IRenderModifier.ModifyRender(Actor self, WorldRenderer
switch (Info.CloakStyle)
{
case CloakStyle.Alpha:
return r.Select(a => !a.IsDecoration && a is IModifyableRenderable mr ? mr.WithAlpha(Info.CloakedAlpha) : a);
return r.Select(a => !a.IsDecoration && a is IModifyableRenderable mr ? mr.WithAlpha(currentAlpha) : a);

case CloakStyle.Color:
return r.Select(a => !a.IsDecoration && a is IModifyableRenderable mr ?
Expand Down Expand Up @@ -291,6 +302,21 @@ void ITick.Tick(Actor self)
}
}

if (isCloaked)
{
currentAlpha += alphaChange;
if (alphaChange > 0 && currentAlpha > Info.MaxCloakedAlpha)
{
alphaChange = -alphaChange;
currentAlpha = Info.MaxCloakedAlpha;
}
else if (alphaChange < 0 && currentAlpha < Info.MinCloakedAlpha)
{
alphaChange = -alphaChange;
currentAlpha = Info.MinCloakedAlpha;
}
}

wasCloaked = isCloaked;
firstTick = false;
}
Expand Down

0 comments on commit 642ce93

Please sign in to comment.