Skip to content

Commit

Permalink
Merge branch 'impstation:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
formlessnameless authored Sep 20, 2024
2 parents d77429b + 8bb7d5e commit 4702986
Show file tree
Hide file tree
Showing 36 changed files with 571 additions and 28 deletions.
56 changes: 56 additions & 0 deletions Content.Client/Revenant/RevenantRegenModifierSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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)
{
if (args.Alert.ID != ent.Comp.Alert)
return;

var sprite = args.SpriteViewEnt.Comp;
var witnesses = Math.Clamp(ent.Comp.Witnesses.Count, 0, 99);
sprite.LayerSetState(RevenantVisualLayers.Digit1, $"{witnesses / 10}");
sprite.LayerSetState(RevenantVisualLayers.Digit2, $"{witnesses % 10}");
}
}
3 changes: 3 additions & 0 deletions Content.Server/Revenant/EntitySystems/RevenantStasisSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ private void OnCrafted(EntityUid uid, RevenantStasisComponent comp, Construction

private void OnGrindAttempt(EntityUid uid, RevenantStasisComponent comp, GrindAttemptEvent args)
{
if (!comp.Revenant.Comp.GrindingRequiresSalt)
return;

foreach (var reagent in args.Reagents)
{
if (_tags.HasAnyTag(reagent, "Salt", "Holy"))
Expand Down
65 changes: 65 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,10 @@
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction.Components;
using Robust.Shared.Player;
using Content.Shared.StatusEffect;
using Content.Shared.Flash.Components;
using Robust.Shared.Audio.Systems;

namespace Content.Server.Revenant.EntitySystems;

Expand All @@ -48,6 +52,13 @@ 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 SharedAudioSystem _audioSystem = default!;

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

[ValidatePrototypeId<StatusEffectPrototype>]
private const string FlashedId = "Flashed";

private void InitializeAbilities()
{
Expand All @@ -61,6 +72,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 +232,59 @@ 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 witnessAndRevenantFilter = Filter.Pvs(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;

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)));

// Give the witnesses a spook!
_audioSystem.PlayGlobal(comp.HauntSound, witnessAndRevenantFilter, true);

foreach (var witness in witnesses)
{
_statusEffects.TryAddStatusEffect<FlashedComponent>(GetEntity(witness),
FlashedId,
comp.HauntFlashDuration,
false
);
}

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);
}
}

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
39 changes: 38 additions & 1 deletion Content.Shared/Eye/Blinding/Systems/BlurryVisionSystem.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Eye.Blinding.Components;
using Content.Shared.Inventory.Events;
using Content.Shared.Inventory;
using Content.Shared.Inventory.Events;
using Content.Shared.Lens;

namespace Content.Shared.Eye.Blinding.Systems;

public sealed class BlurryVisionSystem : EntitySystem
{

[Dependency] private readonly ItemSlotsSystem _itemSlots = default!;

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

SubscribeLocalEvent<VisionCorrectionComponent, GotEquippedEvent>(OnGlassesEquipped);
SubscribeLocalEvent<VisionCorrectionComponent, GotUnequippedEvent>(OnGlassesUnequipped);
SubscribeLocalEvent<VisionCorrectionComponent, InventoryRelayedEvent<GetBlurEvent>>(OnGetBlur);

SubscribeLocalEvent<LensSlotComponent, GotEquippedEvent>(OnLensEquipped);
SubscribeLocalEvent<LensSlotComponent, GotUnequippedEvent>(OnLensUnequipped);
SubscribeLocalEvent<LensSlotComponent, LensChangedEvent>(OnLensChanged);
SubscribeLocalEvent<LensSlotComponent, InventoryRelayedEvent<GetBlurEvent>>(OnGetBlurLens);
}

private void OnGetBlur(Entity<VisionCorrectionComponent> glasses, ref InventoryRelayedEvent<GetBlurEvent> args)
Expand All @@ -21,6 +31,18 @@ private void OnGetBlur(Entity<VisionCorrectionComponent> glasses, ref InventoryR
args.Args.CorrectionPower *= glasses.Comp.CorrectionPower;
}

private void OnGetBlurLens(Entity<LensSlotComponent> glasses, ref InventoryRelayedEvent<GetBlurEvent> args)
{
if (!_itemSlots.TryGetSlot(glasses.Owner, glasses.Comp.LensSlotId, out var itemSlot))
return;

if (!TryComp<VisionCorrectionComponent>(itemSlot.Item, out var component))
return;

args.Args.Blur += component.VisionBonus;
args.Args.CorrectionPower *= component.CorrectionPower;
}

public void UpdateBlurMagnitude(Entity<BlindableComponent?> ent)
{
if (!Resolve(ent.Owner, ref ent.Comp, false))
Expand Down Expand Up @@ -51,6 +73,21 @@ private void OnGlassesUnequipped(Entity<VisionCorrectionComponent> glasses, ref
{
UpdateBlurMagnitude(args.Equipee);
}

private void OnLensEquipped(Entity<LensSlotComponent> glasses, ref GotEquippedEvent args)
{
UpdateBlurMagnitude(args.Equipee);
}

private void OnLensUnequipped(Entity<LensSlotComponent> glasses, ref GotUnequippedEvent args)
{
UpdateBlurMagnitude(args.Equipee);
}

private void OnLensChanged(Entity<LensSlotComponent> glasses, ref LensChangedEvent args)
{
UpdateBlurMagnitude(Transform(glasses.Owner).ParentUid);
}
}

public sealed class GetBlurEvent : EntityEventArgs, IInventoryRelayEvent
Expand Down
27 changes: 27 additions & 0 deletions Content.Shared/Lens/LensSlotComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Robust.Shared.GameStates;

namespace Content.Shared.Lens;

/// <summary>
/// This component is used alongside <see cref="ItemSlotsComponent"/> to find a specific container.
/// Enables clothing to change functionality based on items inside of it.
/// </summary>
[RegisterComponent]
public sealed partial class LensSlotComponent : Component
{
[DataField("LensSlotId", required: true)]
public string LensSlotId = string.Empty;
}

/// <summary>
/// Raised directed at an entity with a lens slot when the lens is ejected/inserted.
/// </summary>
public sealed class LensChangedEvent : EntityEventArgs
{
public readonly bool Ejected;

public LensChangedEvent(bool ejected)
{
Ejected = ejected;
}
}
59 changes: 59 additions & 0 deletions Content.Shared/Lens/LensSlotSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Examine;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Utility;

namespace Content.Shared.Lens;

public sealed class LensSlotSystem : EntitySystem
{
[Dependency] private readonly ItemSlotsSystem _itemSlots = default!;

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

SubscribeLocalEvent<LensSlotComponent, ExaminedEvent>(OnExamine);

SubscribeLocalEvent<LensSlotComponent, EntInsertedIntoContainerMessage>(OnLensInserted);
SubscribeLocalEvent<LensSlotComponent, EntRemovedFromContainerMessage>(OnLensRemoved);
}

private void OnExamine(EntityUid glasses, LensSlotComponent component, ref ExaminedEvent args)
{
if (!_itemSlots.TryGetSlot(glasses, component.LensSlotId, out var itemSlot))
return;

var msg = new FormattedMessage();

if (itemSlot.Item == null)
msg.AddMarkupOrThrow(Loc.GetString("lens-empty"));
else
{
var metadata = MetaData(itemSlot.Item.Value);
msg.AddMarkupOrThrow(Loc.GetString("lens-filled") + " [color=white]" + metadata.EntityName + "[/color].");
}

args.PushMessage(msg);
}

private void OnLensInserted(EntityUid glasses, LensSlotComponent component, EntInsertedIntoContainerMessage args)
{
if (!component.Initialized)
return;

if (args.Container.ID != component.LensSlotId)
return;

RaiseLocalEvent(glasses, new LensChangedEvent(false));
}

private void OnLensRemoved(EntityUid glasses, LensSlotComponent component, EntRemovedFromContainerMessage args)
{
if (args.Container.ID != component.LensSlotId)
return;

RaiseLocalEvent(glasses, new LensChangedEvent(true));
}
}
Loading

0 comments on commit 4702986

Please sign in to comment.