Files
tbd-station-14/Content.Server/Actions/Actions/DisarmAction.cs
Galactic Chimp f531c65a0b Merge branch 'master' into replace-sounds-with-sound-specifier
# Conflicts:
#	Content.Server/Actions/Actions/DisarmAction.cs
#	Content.Server/Actions/Actions/ScreamAction.cs
#	Content.Server/Arcade/Components/SpaceVillainArcadeComponent.cs
#	Content.Server/Damage/Components/DamageOnHighSpeedImpactComponent.cs
#	Content.Server/Explosion/Components/FlashExplosiveComponent.cs
#	Content.Server/Physics/Controllers/MoverController.cs
#	Content.Server/Portal/Components/PortalComponent.cs
#	Content.Server/Portal/Components/TeleporterComponent.cs
#	Content.Server/Projectiles/Components/ProjectileComponent.cs
#	Content.Server/Singularity/Components/EmitterComponent.cs
#	Content.Server/Sound/EmitSoundSystem.cs
#	Content.Server/Stunnable/Components/StunbatonComponent.cs
#	Content.Server/Tools/Components/MultitoolComponent.cs
#	Content.Server/Weapon/Ranged/Barrels/Components/ServerBatteryBarrelComponent.cs
#	Content.Shared/Gravity/GravityComponent.cs
#	Content.Shared/Light/Component/SharedExpendableLightComponent.cs
#	Content.Shared/Maps/ContentTileDefinition.cs
#	Content.Shared/Slippery/SlipperyComponent.cs
#	Content.Shared/Standing/StandingStateComponent.cs
#	Resources/Prototypes/Entities/Objects/Fun/bike_horn.yml
2021-07-25 14:12:00 +02:00

111 lines
4.6 KiB
C#

using Content.Server.Act;
using Content.Server.Interaction;
using Content.Server.Notification;
using Content.Server.Weapon.Melee;
using Content.Shared.ActionBlocker;
using Content.Shared.Actions;
using Content.Shared.Actions.Behaviors;
using Content.Shared.Actions.Components;
using Content.Shared.Audio;
using Content.Shared.Cooldown;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Notification.Managers;
using Content.Shared.Sound;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Player;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
using System;
using System.Linq;
namespace Content.Server.Actions.Actions
{
[UsedImplicitly]
[DataDefinition]
public class DisarmAction : ITargetEntityAction
{
[DataField("failProb")] private float _failProb = 0.4f;
[DataField("pushProb")] private float _pushProb = 0.4f;
[DataField("cooldown")] private float _cooldown = 1.5f;
[ViewVariables]
[DataField("punchMissSound")]
private SoundSpecifier PunchMissSound { get; } = new SoundPathSpecifier("/Audio/Weapons/punchmiss.ogg");
[ViewVariables]
[DataField("disarmSuccessSound")]
private SoundSpecifier DisarmSuccessSound { get; } = new SoundPathSpecifier("/Audio/Effects/thudswoosh.ogg");
public void DoTargetEntityAction(TargetEntityActionEventArgs args)
{
var disarmedActs = args.Target.GetAllComponents<IDisarmedAct>().ToArray();
if (!args.Performer.InRangeUnobstructed(args.Target)) return;
if (disarmedActs.Length == 0)
{
if (args.Performer.TryGetComponent(out ActorComponent? actor))
{
// Fall back to a normal interaction with the entity
var player = actor.PlayerSession;
var coordinates = args.Target.Transform.Coordinates;
var target = args.Target.Uid;
EntitySystem.Get<InteractionSystem>().HandleUseInteraction(player, coordinates, target);
return;
}
return;
}
if (!args.Performer.TryGetComponent<SharedActionsComponent>(out var actions)) return;
if (args.Target == args.Performer || !EntitySystem.Get<ActionBlockerSystem>().CanAttack(args.Performer)) return;
var random = IoCManager.Resolve<IRobustRandom>();
var audio = EntitySystem.Get<AudioSystem>();
var system = EntitySystem.Get<MeleeWeaponSystem>();
var diff = args.Target.Transform.MapPosition.Position - args.Performer.Transform.MapPosition.Position;
var angle = Angle.FromWorldVec(diff);
actions.Cooldown(ActionType.Disarm, Cooldowns.SecondsFromNow(_cooldown));
if (random.Prob(_failProb))
{
if(PunchMissSound.TryGetSound(out var punchMissSound))
SoundSystem.Play(Filter.Pvs(args.Performer), punchMissSound, args.Performer, AudioHelpers.WithVariation(0.025f));
args.Performer.PopupMessageOtherClients(Loc.GetString("disarm-action-popup-message-other-clients",
("performerName", args.Performer.Name),
("targetName", args.Target.Name)));
args.Performer.PopupMessageCursor(Loc.GetString("disarm-action-popup-message-cursor",
("targetName", args.Target.Name)));
system.SendLunge(angle, args.Performer);
return;
}
system.SendAnimation("disarm", angle, args.Performer, args.Performer, new []{ args.Target });
var eventArgs = new DisarmedActEventArgs() {Target = args.Target, Source = args.Performer, PushProbability = _pushProb};
// Sort by priority.
Array.Sort(disarmedActs, (a, b) => a.Priority.CompareTo(b.Priority));
foreach (var disarmedAct in disarmedActs)
{
if (disarmedAct.Disarmed(eventArgs))
return;
}
if(DisarmSuccessSound.TryGetSound(out var disarmSuccessSound))
SoundSystem.Play(Filter.Pvs(args.Performer), disarmSuccessSound, args.Performer.Transform.Coordinates, AudioHelpers.WithVariation(0.025f));
}
}
}