Skip to content

Commit

Permalink
Haunt witnesses now have an icon over their head on the revenant's cl…
Browse files Browse the repository at this point in the history
…ient
  • Loading branch information
TGRCdev committed Sep 20, 2024
1 parent 6c0af49 commit 5d1b3c6
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 13 deletions.
30 changes: 30 additions & 0 deletions Content.Client/Revenant/RevenantRegenModifierSystem.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,46 @@
using System.Numerics;
using Content.Client.Alerts;
using Content.Shared.Revenant;
using Content.Shared.Revenant.Components;
using Robust.Client.GameObjects;
using Robust.Client.Player;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
using Timer = Robust.Shared.Timing.Timer;

namespace Content.Client.Revenant;

public sealed class RevenantRegenModifierSystem : EntitySystem
{
[Dependency] private readonly SpriteSystem _sprite = default!;

private readonly SpriteSpecifier _witnessIndicator = new SpriteSpecifier.Texture(new ResPath("Interface/Actions/scream.png"));

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<RevenantRegenModifierComponent, UpdateAlertSpriteEvent>(OnUpdateAlert);
SubscribeNetworkEvent<RevenantHauntWitnessEvent>(OnWitnesses);
}

private void OnWitnesses(RevenantHauntWitnessEvent args)
{
foreach (var witness in args.Witnesses)
{
var ent = GetEntity(witness);
if (TryComp<SpriteComponent>(ent, out var sprite))
{
var layerID = sprite.AddLayer(_witnessIndicator);
if (sprite.TryGetLayer(layerID, out var layer))
{
layer.Offset = new Vector2(0, 0.8f);
layer.Scale = new Vector2(0.65f, 0.65f);
}
Timer.Spawn(TimeSpan.FromSeconds(5), () => sprite.RemoveLayer(layerID));
}
}
}

private void OnUpdateAlert(Entity<RevenantRegenModifierComponent> ent, ref UpdateAlertSpriteEvent args)
Expand Down
24 changes: 12 additions & 12 deletions Content.Server/Revenant/EntitySystems/RevenantSystem.Abilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
using Content.Shared.Flash.Components;
using Content.Shared.Flash;
using Robust.Shared.Audio.Systems;
using Content.Shared.Mind;
using Content.Shared.Mind.Components;

namespace Content.Server.Revenant.EntitySystems;

Expand Down Expand Up @@ -252,9 +254,7 @@ private void OnHauntAction(EntityUid uid, RevenantComponent comp, RevenantHauntA
if (!HasComp<MobStateComponent>(ent) || !HasComp<HumanoidAppearanceComponent>(ent) || HasComp<RevenantComponent>(ent))
return true;

var haunted = _interact.InRangeUnobstructed((uid, Transform(uid)), (ent, Transform(ent)), range: 0, collisionMask: CollisionGroup.Impassable);
Log.Debug($"{ent} haunted: {haunted}");
return !haunted;
return !_interact.InRangeUnobstructed((uid, Transform(uid)), (ent, Transform(ent)), range: 0, collisionMask: CollisionGroup.Impassable);
});

var witnesses = new HashSet<NetEntity>(witnessAndRevenantFilter.RemovePlayerByAttachedEntity(uid).Recipients.Select(ply => GetNetEntity(ply.AttachedEntity!.Value)));
Expand All @@ -271,18 +271,18 @@ private void OnHauntAction(EntityUid uid, RevenantComponent comp, RevenantHauntA
);
}


// TODO: Maybe an eyeball icon above witnesses on the revenant's client

// TODO: Modify TryAddStatusEffect to add a premade instance of the component
if (witnesses.Count > 0 && _statusEffects.TryAddStatusEffect<RevenantRegenModifierComponent>(uid, RevenantEssenceRegen, comp.HauntEssenceRegenDuration, true))
if (witnesses.Count > 0 && _statusEffects.TryAddStatusEffect(uid,
RevenantEssenceRegen,
comp.HauntEssenceRegenDuration,
true,
component: new RevenantRegenModifierComponent(witnesses)
))
{
if (_mind.TryGetMind(uid, out var _, out var mind) && mind.Session != null)
RaiseNetworkEvent(new RevenantHauntWitnessEvent(witnesses), mind.Session);

_store.TryAddCurrency(new Dictionary<string, FixedPoint2>
{ {comp.StolenEssenceCurrencyPrototype, comp.HauntStolenEssencePerWitness * witnesses.Count} }, uid);

var regen = Comp<RevenantRegenModifierComponent>(uid);
regen.Witnesses = witnesses;
Dirty(uid, regen);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ namespace Content.Shared.Revenant.Components;
public sealed partial class RevenantRegenModifierComponent : Component
{
[ViewVariables, AutoNetworkedField]
public HashSet<NetEntity> Witnesses = new();
public HashSet<NetEntity> Witnesses;

[DataField]
public ProtoId<AlertPrototype> Alert = "EssenceRegen";

public RevenantRegenModifierComponent(HashSet<NetEntity> witnesses)
{
Witnesses = witnesses;
}

public RevenantRegenModifierComponent() : this(new())
{
}
}
15 changes: 15 additions & 0 deletions Content.Shared/Revenant/SharedRevenant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ public sealed partial class RevenantAnimateEvent : EntityTargetActionEvent
{
}

[Serializable, NetSerializable]
public sealed partial class RevenantHauntWitnessEvent : EntityEventArgs
{
public HashSet<NetEntity> Witnesses = new();

public RevenantHauntWitnessEvent(HashSet<NetEntity> witnesses)
{
Witnesses = witnesses;
}

public RevenantHauntWitnessEvent() : this(new())
{
}
}

[Serializable, NetSerializable]
public sealed partial class ExorciseRevenantDoAfterEvent : SimpleDoAfterEvent
{
Expand Down
16 changes: 16 additions & 0 deletions Content.Shared/StatusEffect/StatusEffectsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,22 @@ public bool TryAddStatusEffect(EntityUid uid, string key, TimeSpan time, bool re
return false;
}

public bool TryAddStatusEffect(EntityUid uid, string key, TimeSpan time, bool refresh, Component component,
StatusEffectsComponent? status = null)
{
if (!Resolve(uid, ref status, false))
return false;

if (TryAddStatusEffect(uid, key, time, refresh, status))
{
EntityManager.AddComponent(uid, component, true);
status.ActiveEffects[key].RelevantComponent = _componentFactory.GetComponentName(component.GetType());
return true;
}

return false;
}

/// <summary>
/// Tries to add a status effect to an entity with a certain timer.
/// </summary>
Expand Down

0 comments on commit 5d1b3c6

Please sign in to comment.