Fix gun clumsy (#11246)

This commit is contained in:
metalgearsloth
2022-09-13 23:52:36 +10:00
committed by GitHub
parent 6596534390
commit fed0c0c108
7 changed files with 64 additions and 29 deletions

View File

@@ -11,6 +11,7 @@ using Content.Shared.Popups;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.Player; using Robust.Shared.Player;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Content.Server.Interaction;
namespace Content.Server.Chemistry.Components namespace Content.Server.Chemistry.Components
{ {
@@ -48,7 +49,7 @@ namespace Content.Server.Chemistry.Components
{ {
msgFormat = "hypospray-component-inject-self-message"; msgFormat = "hypospray-component-inject-self-message";
} }
else if (EligibleEntity(user, _entMan) && ClumsyComponent.TryRollClumsy(user, ClumsyFailChance)) else if (EligibleEntity(user, _entMan) && _entMan.EntitySysManager.GetEntitySystem<InteractionSystem>().TryRollClumsy(user, ClumsyFailChance))
{ {
msgFormat = "hypospray-component-inject-self-clumsy-message"; msgFormat = "hypospray-component-inject-self-clumsy-message";
target = user; target = user;

View File

@@ -1,5 +1,6 @@
using Content.Server.Climbing.Components; using Content.Server.Climbing.Components;
using Content.Server.DoAfter; using Content.Server.DoAfter;
using Content.Server.Interaction;
using Content.Server.Interaction.Components; using Content.Server.Interaction.Components;
using Content.Server.Popups; using Content.Server.Popups;
using Content.Server.Stunnable; using Content.Server.Stunnable;
@@ -39,7 +40,7 @@ public sealed class ClimbSystem : SharedClimbSystem
[Dependency] private readonly DoAfterSystem _doAfterSystem = default!; [Dependency] private readonly DoAfterSystem _doAfterSystem = default!;
[Dependency] private readonly FixtureSystem _fixtureSystem = default!; [Dependency] private readonly FixtureSystem _fixtureSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!; [Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!; [Dependency] private readonly InteractionSystem _interactionSystem = default!;
[Dependency] private readonly StunSystem _stunSystem = default!; [Dependency] private readonly StunSystem _stunSystem = default!;
[Dependency] private readonly AudioSystem _audioSystem = default!; [Dependency] private readonly AudioSystem _audioSystem = default!;
@@ -134,10 +135,7 @@ public sealed class ClimbSystem : SharedClimbSystem
if (!_cfg.GetCVar(CCVars.GameTableBonk)) if (!_cfg.GetCVar(CCVars.GameTableBonk))
{ {
// Not set to always bonk, try clumsy roll. // Not set to always bonk, try clumsy roll.
if (!TryComp(user, out ClumsyComponent? clumsy)) if (!_interactionSystem.TryRollClumsy(user, component.BonkClumsyChance))
return false;
if (!clumsy.RollClumsy(component.BonkClumsyChance))
return false; return false;
} }

View File

@@ -1,5 +1,4 @@
using Content.Shared.Damage; using Content.Shared.Damage;
using Robust.Shared.Random;
namespace Content.Server.Interaction.Components namespace Content.Server.Interaction.Components
{ {
@@ -9,28 +8,8 @@ namespace Content.Server.Interaction.Components
[RegisterComponent] [RegisterComponent]
public sealed class ClumsyComponent : Component public sealed class ClumsyComponent : Component
{ {
[Dependency] private readonly IRobustRandom _random = default!;
[DataField("clumsyDamage", required: true)] [DataField("clumsyDamage", required: true)]
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public DamageSpecifier ClumsyDamage = default!; public DamageSpecifier ClumsyDamage = default!;
public bool RollClumsy(float chance)
{
return Running && _random.Prob(chance);
}
/// <summary>
/// Rolls a probability chance for a "bad action" if the target entity is clumsy.
/// </summary>
/// <param name="entity">The entity that the clumsy check is happening for.</param>
/// <param name="chance">
/// The chance that a "bad action" happens if the user is clumsy, between 0 and 1 inclusive.
/// </param>
/// <returns>True if a "bad action" happened, false if the normal action should happen.</returns>
public static bool TryRollClumsy(EntityUid entity, float chance)
{
return IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ClumsyComponent? clumsy)
&& clumsy.RollClumsy(chance);
}
} }
} }

View File

@@ -0,0 +1,25 @@
using Content.Server.Interaction.Components;
using Robust.Shared.Random;
namespace Content.Server.Interaction;
public sealed partial class InteractionSystem
{
public bool RollClumsy(ClumsyComponent component, float chance)
{
return component.Running && _random.Prob(chance);
}
/// <summary>
/// Rolls a probability chance for a "bad action" if the target entity is clumsy.
/// </summary>
/// <param name="entity">The entity that the clumsy check is happening for.</param>
/// <param name="chance">
/// The chance that a "bad action" happens if the user is clumsy, between 0 and 1 inclusive.
/// </param>
/// <returns>True if a "bad action" happened, false if the normal action should happen.</returns>
public bool TryRollClumsy(EntityUid entity, float chance, ClumsyComponent? component = null)
{
return Resolve(entity, ref component, false) && RollClumsy(component, chance);
}
}

View File

@@ -19,6 +19,7 @@ using Robust.Shared.Containers;
using Robust.Shared.Input.Binding; using Robust.Shared.Input.Binding;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Players; using Robust.Shared.Players;
using Robust.Shared.Random;
using static Content.Shared.Storage.SharedStorageComponent; using static Content.Shared.Storage.SharedStorageComponent;
namespace Content.Server.Interaction namespace Content.Server.Interaction
@@ -27,11 +28,12 @@ namespace Content.Server.Interaction
/// Governs interactions during clicking on entities /// Governs interactions during clicking on entities
/// </summary> /// </summary>
[UsedImplicitly] [UsedImplicitly]
public sealed class InteractionSystem : SharedInteractionSystem public sealed partial class InteractionSystem : SharedInteractionSystem
{ {
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!; [Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
[Dependency] private readonly PullingSystem _pullSystem = default!; [Dependency] private readonly PullingSystem _pullSystem = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!; [Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
[Dependency] private readonly InventorySystem _inventory = default!; [Dependency] private readonly InventorySystem _inventory = default!;

View File

@@ -1,13 +1,17 @@
using System.Linq; using System.Linq;
using Content.Server.Damage.Systems; using Content.Server.Damage.Systems;
using Content.Server.Examine; using Content.Server.Examine;
using Content.Server.Interaction;
using Content.Server.Interaction.Components;
using Content.Server.Projectiles.Components; using Content.Server.Projectiles.Components;
using Content.Server.Stunnable;
using Content.Server.Weapon.Melee; using Content.Server.Weapon.Melee;
using Content.Server.Weapon.Ranged.Components; using Content.Server.Weapon.Ranged.Components;
using Content.Shared.Audio; using Content.Shared.Audio;
using Content.Shared.Damage; using Content.Shared.Damage;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.FixedPoint; using Content.Shared.FixedPoint;
using Content.Shared.StatusEffect;
using Content.Shared.Weapons.Melee; using Content.Shared.Weapons.Melee;
using Content.Shared.Weapons.Ranged; using Content.Shared.Weapons.Ranged;
using Content.Shared.Weapons.Ranged.Components; using Content.Shared.Weapons.Ranged.Components;
@@ -26,12 +30,37 @@ public sealed partial class GunSystem : SharedGunSystem
{ {
[Dependency] private readonly IComponentFactory _factory = default!; [Dependency] private readonly IComponentFactory _factory = default!;
[Dependency] private readonly ExamineSystem _examine = default!; [Dependency] private readonly ExamineSystem _examine = default!;
[Dependency] private readonly InteractionSystem _interaction = default!;
[Dependency] private readonly StaminaSystem _stamina = default!; [Dependency] private readonly StaminaSystem _stamina = default!;
[Dependency] private readonly StunSystem _stun = default!;
public const float DamagePitchVariation = MeleeWeaponSystem.DamagePitchVariation; public const float DamagePitchVariation = MeleeWeaponSystem.DamagePitchVariation;
public const float GunClumsyChance = 0.5f;
public override void Shoot(GunComponent gun, List<IShootable> ammo, EntityCoordinates fromCoordinates, EntityCoordinates toCoordinates, EntityUid? user = null) public override void Shoot(GunComponent gun, List<IShootable> ammo, EntityCoordinates fromCoordinates, EntityCoordinates toCoordinates, EntityUid? user = null)
{ {
// Try a clumsy roll
if (TryComp<ClumsyComponent>(user, out var clumsy))
{
for (var i = 0; i < ammo.Count; i++)
{
if (_interaction.TryRollClumsy(user.Value, GunClumsyChance, clumsy))
{
// Wound them
Damageable.TryChangeDamage(user, clumsy.ClumsyDamage);
_stun.TryParalyze(user.Value, TimeSpan.FromSeconds(3f), true);
// Apply salt to the wound ("Honk!")
Audio.PlayPvs(new SoundPathSpecifier("/Audio/Weapons/Guns/Gunshots/bang.ogg"), gun.Owner);
Audio.PlayPvs(new SoundPathSpecifier("/Audio/Items/bikehorn.ogg"), gun.Owner);
PopupSystem.PopupEntity(Loc.GetString("gun-clumsy"), user.Value, Filter.Pvs(user.Value, entityManager: EntityManager));
Del(gun.Owner);
return;
}
}
}
var fromMap = fromCoordinates.ToMap(EntityManager); var fromMap = fromCoordinates.ToMap(EntityManager);
var toMap = toCoordinates.ToMapPos(EntityManager); var toMap = toCoordinates.ToMapPos(EntityManager);
var mapDirection = toMap - fromMap.Position; var mapDirection = toMap - fromMap.Position;

View File

@@ -4,6 +4,7 @@ gun-fire-rate-examine = Fire rate is [color={$color}]{$fireRate}[/color] per sec
gun-selector-verb = Change to {$mode} gun-selector-verb = Change to {$mode}
gun-selected-mode = Selected {$mode} gun-selected-mode = Selected {$mode}
gun-disabled = You can't use guns! gun-disabled = You can't use guns!
gun-clumsy = The gun blows up in your face!
# SelectiveFire # SelectiveFire
gun-SemiAuto = semi-auto gun-SemiAuto = semi-auto