Skip to content

Commit

Permalink
Added the revenant Haunt action
Browse files Browse the repository at this point in the history
  • Loading branch information
TGRCdev committed Sep 19, 2024
1 parent d132b22 commit fb692c4
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 3 deletions.
47 changes: 47 additions & 0 deletions Content.Server/Revenant/EntitySystems/RevenantSystem.Abilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction.Components;
using Robust.Shared.Player;
using Content.Shared.StatusEffect;

namespace Content.Server.Revenant.EntitySystems;

Expand All @@ -48,6 +50,10 @@ public sealed partial class RevenantSystem
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly RevenantAnimatedSystem _revenantAnimated = default!;
[Dependency] private readonly EntityLookupSystem _entityLookup = default!;

[ValidatePrototypeId<StatusEffectPrototype>]
private const string RevenantEssenceRegen = "EssenceRegen";

private void InitializeAbilities()
{
Expand All @@ -61,6 +67,7 @@ private void InitializeAbilities()
SubscribeLocalEvent<RevenantComponent, RevenantMalfunctionActionEvent>(OnMalfunctionAction);
SubscribeLocalEvent<RevenantComponent, RevenantBloodWritingEvent>(OnBloodWritingAction);
SubscribeLocalEvent<RevenantComponent, RevenantAnimateEvent>(OnAnimateAction);
SubscribeLocalEvent<RevenantComponent, RevenantHauntActionEvent>(OnHauntAction);
}

private void OnInteract(EntityUid uid, RevenantComponent component, UserActivateInWorldEvent args)
Expand Down Expand Up @@ -220,6 +227,46 @@ private void OnHarvest(EntityUid uid, RevenantComponent component, HarvestEvent
args.Handled = true;
}

private void OnHauntAction(EntityUid uid, RevenantComponent comp, RevenantHauntActionEvent args)
{
if (args.Handled)
return;

if (!TryUseAbility(uid, comp, 0, comp.HauntDebuffs))
return;

args.Handled = true;

// This is probably not the right way to do this...
var witnesses = new HashSet<NetEntity>(Filter.PvsExcept(uid).RemoveWhere(player =>
{
if (player.AttachedEntity == null)
return true;

var ent = player.AttachedEntity.Value;

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;
}).Recipients.Select(ply => GetNetEntity(ply.AttachedEntity!.Value)));

// 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))
{
_store.TryAddCurrency(new Dictionary<string, FixedPoint2>
{ {comp.StolenEssenceCurrencyPrototype, comp.HauntStolenEssencePerWitness * witnesses.Count} }, uid);

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

private void OnDefileAction(EntityUid uid, RevenantComponent component, RevenantDefileActionEvent args)
{
if (args.Handled)
Expand Down
13 changes: 11 additions & 2 deletions Content.Server/Revenant/EntitySystems/RevenantSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public sealed partial class RevenantSystem : EntitySystem
[ValidatePrototypeId<EntityPrototype>]
private const string RevenantShopId = "ActionRevenantShop";

[ValidatePrototypeId<EntityPrototype>]
private const string RevenantHauntId = "ActionRevenantHaunt";

public override void Initialize()
{
base.Initialize();
Expand Down Expand Up @@ -98,7 +101,8 @@ private void OnStartup(EntityUid uid, RevenantComponent component, ComponentStar

private void OnMapInit(EntityUid uid, RevenantComponent component, MapInitEvent args)
{
_action.AddAction(uid, ref component.Action, RevenantShopId);
_action.AddAction(uid, ref component.ShopAction, RevenantShopId);
_action.AddAction(uid, ref component.HauntAction, RevenantHauntId);
}

private void OnStatusAdded(EntityUid uid, RevenantComponent component, StatusEffectAddedEvent args)
Expand Down Expand Up @@ -232,7 +236,12 @@ public override void Update(float frameTime)

if (rev.Essence < rev.EssenceRegenCap)
{
ChangeEssenceAmount(uid, rev.EssencePerSecond, rev, regenCap: true);
var essence = rev.EssencePerSecond;

if (TryComp<RevenantRegenModifierComponent>(uid, out var regen))
essence += rev.HauntEssenceRegenPerWitness * regen.Witnesses.Count;

ChangeEssenceAmount(uid, essence, rev, regenCap: true);
}
}
}
Expand Down
21 changes: 20 additions & 1 deletion Content.Shared/Revenant/Components/RevenantComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,24 @@ public sealed partial class RevenantComponent : Component
public float MaxEssenceUpgradeAmount = 10;
#endregion

// When used, the revenant reveals itself temporarily and gains stolen essence and a boost in
// essence regeneration for each crewmate that witnesses it
#region Haunt Ability

[DataField("hauntDebuffs")]
public Vector2 HauntDebuffs = new(2, 6);

[DataField("hauntStolenEssencePerWitness")]
public FixedPoint2 HauntStolenEssencePerWitness = 2.5;

[DataField("hauntEssenceRegenPerWitness")]
public FixedPoint2 HauntEssenceRegenPerWitness = 0.5;

[DataField("hauntEssenceRegenDuration")]
public TimeSpan HauntEssenceRegenDuration = TimeSpan.FromSeconds(10);

#endregion

//In the nearby radius, causes various objects to be thrown, messed with, and containers opened
//Generally just causes a mess
#region Defile Ability
Expand Down Expand Up @@ -260,5 +278,6 @@ public sealed partial class RevenantComponent : Component
public string HarvestingState = "harvesting";
#endregion

[DataField] public EntityUid? Action;
[DataField] public EntityUid? ShopAction;
[DataField] public EntityUid? HauntAction;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@


using Robust.Shared.GameStates;

namespace Content.Shared.Revenant.Components;

[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class RevenantRegenModifierComponent : Component
{
[ViewVariables, AutoNetworkedField]
public HashSet<NetEntity> Witnesses = new();
}
4 changes: 4 additions & 0 deletions Content.Shared/Revenant/SharedRevenant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public sealed partial class RevenantShopActionEvent : InstantActionEvent
{
}

public sealed partial class RevenantHauntActionEvent : InstantActionEvent
{
}

public sealed partial class RevenantDefileActionEvent : InstantActionEvent
{
}
Expand Down
13 changes: 13 additions & 0 deletions Resources/Prototypes/Actions/revenant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
icon: Interface/Actions/shop.png
event: !type:RevenantShopActionEvent

- type: entity
id: ActionRevenantHaunt
name: Haunt
description: Gives essence and stolen essence for every witness.
components:
- type: InstantAction
itemIconStyle: NoItem
icon:
sprite: Mobs/Ghosts/revenant.rsi
state: icon
event: !type:RevenantHauntActionEvent
useDelay: 15

- type: entity
id: ActionRevenantDefile
name: Defile
Expand Down
9 changes: 9 additions & 0 deletions Resources/Prototypes/Alerts/revenant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
name: alerts-revenant-corporeal-name
description: alerts-revenant-corporeal-desc

# TODO: Custom icon
- type: alert
id: EssenceRegen
name: alerts-revenant-essence-regen
description: alerts-revenant-essence-regen
icons:
- sprite: /Textures/Mobs/Ghosts/revenant.rsi
state: icon

- type: alert
id: Stasis
icons:
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Mobs/NPCs/revenant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
allowed:
- Stun
- Corporeal
- EssenceRegen
- type: Hands
showInHands: false
disableExplosionRecursion: true
Expand Down
4 changes: 4 additions & 0 deletions Resources/Prototypes/status_effects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
alert: Stasis
alwaysAllowed: true

- type: statusEffect
id: EssenceRegen
alert: EssenceRegen

- type: statusEffect
id: ForcedSleep #I.e., they will not wake on damage or similar

Expand Down

0 comments on commit fb692c4

Please sign in to comment.