Re-organize all projects (#4166)
This commit is contained in:
42
Content.Server/Throwing/EmitSoundOnThrowComponent.cs
Normal file
42
Content.Server/Throwing/EmitSoundOnThrowComponent.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Throwing;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Throwing
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple sound emitter that emits sound on use in hand
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class EmitSoundOnThrowComponent : Component, ILand
|
||||
{
|
||||
/// <inheritdoc />
|
||||
///
|
||||
public override string Name => "EmitSoundOnThrow";
|
||||
|
||||
[DataField("sound")]
|
||||
public string? _soundName;
|
||||
[DataField("variation")]
|
||||
public float _pitchVariation;
|
||||
|
||||
public void PlaySoundEffect()
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(_soundName))
|
||||
{
|
||||
if (_pitchVariation > 0.0)
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(Owner), _soundName, Owner, AudioHelpers.WithVariation(_pitchVariation).WithVolume(-2f));
|
||||
}
|
||||
SoundSystem.Play(Filter.Pvs(Owner), _soundName, Owner, AudioParams.Default.WithVolume(-2f));
|
||||
}
|
||||
}
|
||||
|
||||
void ILand.Land(LandEventArgs eventArgs)
|
||||
{
|
||||
PlaySoundEffect();
|
||||
}
|
||||
}
|
||||
}
|
||||
61
Content.Server/Throwing/ThrowHelper.cs
Normal file
61
Content.Server/Throwing/ThrowHelper.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
#nullable enable
|
||||
using Content.Server.Interaction;
|
||||
using Content.Server.Items;
|
||||
using Content.Shared.MobState;
|
||||
using Content.Shared.Throwing;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
|
||||
namespace Content.Server.Throwing
|
||||
{
|
||||
internal static class ThrowHelper
|
||||
{
|
||||
private const float ThrowAngularImpulse = 3.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Tries to throw the entity if it has a physics component, otherwise does nothing.
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="direction">Will use the vector's magnitude as the strength of the impulse</param>
|
||||
/// <param name="user"></param>
|
||||
/// <param name="pushbackRatio">The ratio of impulse applied to the thrower</param>
|
||||
internal static void TryThrow(this IEntity entity, Vector2 direction, IEntity? user = null, float pushbackRatio = 1.0f)
|
||||
{
|
||||
if (entity.Deleted || direction == Vector2.Zero || !entity.TryGetComponent(out PhysicsComponent? physicsComponent))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (physicsComponent.BodyType == BodyType.Static)
|
||||
{
|
||||
Logger.Warning("Tried to throw entity {entity} but can't throw static bodies!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity.HasComponent<IMobStateComponent>())
|
||||
{
|
||||
Logger.Warning("Throwing not supported for mobs!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity.HasComponent<ItemComponent>())
|
||||
{
|
||||
entity.EnsureComponent<ThrownItemComponent>().Thrower = user;
|
||||
// Give it a l'il spin.
|
||||
physicsComponent.ApplyAngularImpulse(ThrowAngularImpulse);
|
||||
|
||||
if (user != null)
|
||||
EntitySystem.Get<InteractionSystem>().ThrownInteraction(user, entity);
|
||||
}
|
||||
|
||||
physicsComponent.ApplyLinearImpulse(direction);
|
||||
// Give thrower an impulse in the other direction
|
||||
if (user != null && pushbackRatio > 0.0f && user.TryGetComponent(out IPhysBody? body))
|
||||
{
|
||||
body.ApplyLinearImpulse(-direction * pushbackRatio);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user