Pettable Animals (#6530)

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: mirrorcult <lunarautomaton6@gmail.com>
This commit is contained in:
Willhelm53
2022-02-13 21:20:47 -06:00
committed by GitHub
parent ac23899a39
commit cd7843028b
20 changed files with 343 additions and 97 deletions

View File

@@ -8,7 +8,6 @@ using Content.Server.NodeContainer.Nodes;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Power.NodeGroups;
using Content.Server.Window;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.Database;
@@ -21,6 +20,7 @@ using Content.Shared.Pulling.Components;
using Content.Shared.Speech.EntitySystems;
using Content.Shared.StatusEffect;
using Content.Shared.Stunnable;
using Content.Shared.Tag;
using Content.Shared.Weapons.Melee;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -166,12 +166,14 @@ namespace Content.Server.Electrocution
if (!electrified.Enabled)
return false;
var tagSystem = EntitySystem.Get<TagSystem>();
if (electrified.NoWindowInTile)
{
foreach (var entity in transform.Coordinates.GetEntitiesInTile(
LookupFlags.Approximate | LookupFlags.IncludeAnchored, _entityLookup))
{
if (EntityManager.HasComponent<WindowComponent>(entity))
if (tagSystem.HasTag(entity, "Window"))
return false;
}
}

View File

@@ -0,0 +1,67 @@
using Content.Shared.Sound;
namespace Content.Server.Interaction.Components;
[RegisterComponent, Friend(typeof(InteractionPopupSystem))]
public sealed class InteractionPopupComponent : Component
{
/// <summary>
/// Time delay between interactions to avoid spam.
/// </summary>
[DataField("interactDelay")]
[ViewVariables(VVAccess.ReadWrite)]
public TimeSpan InteractDelay = TimeSpan.FromSeconds(1.0);
/// <summary>
/// String will be used to fetch the localized message to be played if the interaction succeeds.
/// Nullable in case none is specified on the yaml prototype.
/// </summary>
[DataField("interactSuccessString")]
public string? InteractSuccessString;
/// <summary>
/// String will be used to fetch the localized message to be played if the interaction fails.
/// Nullable in case no message is specified on the yaml prototype.
/// </summary>
[DataField("interactFailureString")]
public string? InteractFailureString;
/// <summary>
/// Sound effect to be played when the interaction succeeds.
/// Nullable in case no path is specified on the yaml prototype.
/// </summary>
[DataField("interactSuccessSound")]
public SoundSpecifier? InteractSuccessSound;
/// <summary>
/// Sound effect to be played when the interaction fails.
/// Nullable in case no path is specified on the yaml prototype.
/// </summary>
[DataField("interactFailureSound")]
public SoundSpecifier? InteractFailureSound;
/// <summary>
/// Chance that an interaction attempt will succeed.
/// 1 = always play "success" popup and sound.
/// 0.5 = 50% chance to play either success or failure popup and sound.
/// 0 = always play "failure" popup and sound.
/// </summary>
[DataField("successChance")]
public float SuccessChance = 1.0f; // Always succeed, unless specified otherwise on the yaml prototype.
/// <summary>
/// Will the popup message be perceived by entities not involved in the interaction?
/// </summary>
[DataField("popupPerceivedByOthers")]
public bool PopupPerceivedByOthers = false;
/// <summary>
/// Will the sound effect be perceived by entities not involved in the interaction?
/// </summary>
[DataField("soundPerceivedByOthers")]
public bool SoundPerceivedByOthers = true;
[ViewVariables(VVAccess.ReadWrite)]
public TimeSpan LastInteractTime;
}

View File

@@ -0,0 +1,72 @@
using Content.Server.Popups;
using Content.Server.Interaction.Components;
using Content.Shared.Interaction;
using Content.Shared.MobState.Components;
using Robust.Shared.Audio;
using Robust.Shared.Player;
using Robust.Shared.Timing;
using Robust.Shared.Random;
namespace Content.Server.Interaction;
public sealed class InteractionPopupSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<InteractionPopupComponent, InteractHandEvent>(OnInteractHand);
}
private void OnInteractHand(EntityUid uid, InteractionPopupComponent component, InteractHandEvent args)
{
if (args.Handled)
return;
var curTime = _gameTiming.CurTime;
if (curTime < component.LastInteractTime + component.InteractDelay)
return;
if (TryComp<MobStateComponent>(uid, out var state) // if it has a MobStateComponent,
&& !state.IsAlive()) // AND if that state is not Alive (e.g. dead/incapacitated/critical)
return;
string msg = ""; // Stores the text to be shown in the popup message
string sfx = ""; // Stores the filepath of the sound to be played
if (_random.Prob(component.SuccessChance))
{
if (component.InteractSuccessString != null)
msg = Loc.GetString(component.InteractSuccessString, ("target", uid)); // Success message (localized).
if (component.InteractSuccessSound != null)
sfx = component.InteractSuccessSound.GetSound();
}
else
{
if (component.InteractFailureString != null)
msg = Loc.GetString(component.InteractFailureString, ("target", uid)); // Failure message (localized).
if (component.InteractFailureSound != null)
sfx = component.InteractFailureSound.GetSound();
}
if (component.PopupPerceivedByOthers)
_popupSystem.PopupEntity(msg, uid, Filter.Pvs(uid)); //play for everyone in range
else
_popupSystem.PopupEntity(msg, uid, Filter.Entities(args.User)); //play only for the initiating entity.
if (component.SoundPerceivedByOthers)
SoundSystem.Play(Filter.Pvs(args.Target), sfx, args.Target); //play for everyone in range
else
SoundSystem.Play(Filter.Entities(args.User, args.Target), sfx, args.Target); //play only for the initiating entity and its target.
component.LastInteractTime = curTime;
args.Handled = true;
}
}

View File

@@ -1,24 +0,0 @@
using System;
using Content.Shared.Sound;
using Content.Shared.Window;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Window
{
[RegisterComponent]
[ComponentReference(typeof(SharedWindowComponent))]
public class WindowComponent : SharedWindowComponent
{
[DataField("knockDelay")]
[ViewVariables(VVAccess.ReadWrite)]
public TimeSpan KnockDelay = TimeSpan.FromSeconds(0.5);
[DataField("knockSound")]
public SoundSpecifier KnockSound = new SoundPathSpecifier("/Audio/Effects/glass_knock.ogg");
[ViewVariables(VVAccess.ReadWrite)]
public TimeSpan LastKnockTime;
}
}

View File

@@ -1,44 +0,0 @@
using Content.Server.Popups;
using Content.Shared.Audio;
using Content.Shared.Interaction;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Player;
using Robust.Shared.Timing;
namespace Content.Server.Window;
public class WindowSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<WindowComponent, InteractHandEvent>(OnInteractHand);
}
private void OnInteractHand(EntityUid uid, WindowComponent component, InteractHandEvent args)
{
if (args.Handled)
return;
if (component.KnockDelay.TotalSeconds <= 0)
return;
if (_gameTiming.CurTime < component.LastKnockTime + component.KnockDelay)
return;
SoundSystem.Play(Filter.Pvs(args.Target), component.KnockSound.GetSound(),
Transform(args.Target).Coordinates, AudioHelpers.WithVariation(0.05f));
var msg = Loc.GetString("comp-window-knock");
_popupSystem.PopupEntity(msg, uid, Filter.Pvs(uid));
component.LastKnockTime = _gameTiming.CurTime;
args.Handled = true;
}
}