Fix bypassing vaulting clumsy check with verb action. (#24977)
* Fix bypassing bonking with verb * Revert "Fix bypassing bonking with verb" This reverts commit efa0f0f5777b893bcee5a852994cfa1e3fda3e71. * Properly refactored BonkSystem. * Oh hey, this is redundant now * Better solution * Reduced default bonk chance from 75% to 50% * Also do a little grammar fix * Moved BonkChance from BonkableComponent to ClumsyComponent. * Revert "Moved BonkChance from BonkableComponent to ClumsyComponent." This reverts commit 0acbd9273f20ec478692603781adf15e06e5ed41. * Another little grammar fix * Matched default bonk doAfter length to default climb doAfter length * Fixed duplicate popups * Check CanVault with verb use too. Add granularity to ClimbingComponent and remove Leg/Foot requirement. * Don't show verb if you can't climb * Removed CanForceClimb * byref record struct
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Climbing.Components;
|
||||
using Content.Shared.Climbing.Events;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.DragDrop;
|
||||
@@ -9,7 +10,6 @@ using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Components;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Stunnable;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Player;
|
||||
@@ -30,42 +30,54 @@ public sealed partial class BonkSystem : EntitySystem
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<BonkableComponent, DragDropTargetEvent>(OnDragDrop);
|
||||
SubscribeLocalEvent<BonkableComponent, BonkDoAfterEvent>(OnBonkDoAfter);
|
||||
SubscribeLocalEvent<BonkableComponent, AttemptClimbEvent>(OnAttemptClimb);
|
||||
}
|
||||
|
||||
private void OnBonkDoAfter(EntityUid uid, Components.BonkableComponent component, BonkDoAfterEvent args)
|
||||
private void OnBonkDoAfter(EntityUid uid, BonkableComponent component, BonkDoAfterEvent args)
|
||||
{
|
||||
if (args.Handled || args.Cancelled || args.Args.Target == null)
|
||||
if (args.Handled || args.Cancelled || args.Args.Used == null)
|
||||
return;
|
||||
|
||||
TryBonk(args.Args.User, uid, component);
|
||||
TryBonk(args.Args.Used.Value, uid, component, source: args.Args.User);
|
||||
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
|
||||
public bool TryBonk(EntityUid user, EntityUid bonkableUid, Components.BonkableComponent? bonkableComponent = null)
|
||||
public bool TryBonk(EntityUid user, EntityUid bonkableUid, BonkableComponent? bonkableComponent = null, EntityUid? source = null)
|
||||
{
|
||||
if (!Resolve(bonkableUid, ref bonkableComponent, false))
|
||||
return false;
|
||||
|
||||
if (!_cfg.GetCVar(CCVars.GameTableBonk))
|
||||
{
|
||||
// Not set to always bonk, try clumsy roll.
|
||||
if (!_interactionSystem.TryRollClumsy(user, bonkableComponent.BonkClumsyChance))
|
||||
return false;
|
||||
}
|
||||
|
||||
// BONK!
|
||||
var userName = Identity.Entity(user, EntityManager);
|
||||
var bonkableName = Identity.Entity(bonkableUid, EntityManager);
|
||||
|
||||
_popupSystem.PopupEntity(Loc.GetString("bonkable-success-message-others", ("user", userName), ("bonkable", bonkableName)), user, Filter.PvsExcept(user), true);
|
||||
if (user == source)
|
||||
{
|
||||
// Non-local, non-bonking players
|
||||
_popupSystem.PopupEntity(Loc.GetString("bonkable-success-message-others", ("user", userName), ("bonkable", bonkableName)), user, Filter.PvsExcept(user), true);
|
||||
// Local, bonking player
|
||||
_popupSystem.PopupClient(Loc.GetString("bonkable-success-message-user", ("user", userName), ("bonkable", bonkableName)), user, user);
|
||||
}
|
||||
else if (source != null)
|
||||
{
|
||||
// Local, non-bonking player (dragger)
|
||||
_popupSystem.PopupClient(Loc.GetString("bonkable-success-message-others", ("user", userName), ("bonkable", bonkableName)), user, source.Value);
|
||||
// Non-local, non-bonking players
|
||||
_popupSystem.PopupEntity(Loc.GetString("bonkable-success-message-others", ("user", userName), ("bonkable", bonkableName)), user, Filter.Pvs(user).RemoveWhereAttachedEntity(e => e == user || e == source.Value), true);
|
||||
// Non-local, bonking player
|
||||
_popupSystem.PopupEntity(Loc.GetString("bonkable-success-message-user", ("user", userName), ("bonkable", bonkableName)), user, user);
|
||||
}
|
||||
|
||||
_popupSystem.PopupEntity(Loc.GetString("bonkable-success-message-user", ("user", userName), ("bonkable", bonkableName)), user, user);
|
||||
|
||||
_audioSystem.PlayPvs(bonkableComponent.BonkSound, bonkableUid);
|
||||
|
||||
if (source != null)
|
||||
_audioSystem.PlayPredicted(bonkableComponent.BonkSound, bonkableUid, source);
|
||||
else
|
||||
_audioSystem.PlayPvs(bonkableComponent.BonkSound, bonkableUid);
|
||||
|
||||
_stunSystem.TryParalyze(user, TimeSpan.FromSeconds(bonkableComponent.BonkTime), true);
|
||||
|
||||
if (bonkableComponent.BonkDamage is { } bonkDmg)
|
||||
@@ -75,12 +87,22 @@ public sealed partial class BonkSystem : EntitySystem
|
||||
|
||||
}
|
||||
|
||||
private void OnDragDrop(EntityUid uid, Components.BonkableComponent component, ref DragDropTargetEvent args)
|
||||
private bool TryStartBonk(EntityUid uid, EntityUid user, EntityUid climber, BonkableComponent? bonkableComponent = null)
|
||||
{
|
||||
if (args.Handled || !HasComp<ClumsyComponent>(args.Dragged) || !HasComp<HandsComponent>(args.User))
|
||||
return;
|
||||
if (!Resolve(uid, ref bonkableComponent, false))
|
||||
return false;
|
||||
|
||||
var doAfterArgs = new DoAfterArgs(EntityManager, args.Dragged, component.BonkDelay, new BonkDoAfterEvent(), uid, target: uid)
|
||||
if (!HasComp<ClumsyComponent>(climber) || !HasComp<HandsComponent>(user))
|
||||
return false;
|
||||
|
||||
if (!_cfg.GetCVar(CCVars.GameTableBonk))
|
||||
{
|
||||
// Not set to always bonk, try clumsy roll.
|
||||
if (!_interactionSystem.TryRollClumsy(climber, bonkableComponent.BonkClumsyChance))
|
||||
return false;
|
||||
}
|
||||
|
||||
var doAfterArgs = new DoAfterArgs(EntityManager, user, bonkableComponent.BonkDelay, new BonkDoAfterEvent(), uid, target: uid, used: climber)
|
||||
{
|
||||
BreakOnMove = true,
|
||||
BreakOnDamage = true
|
||||
@@ -88,7 +110,16 @@ public sealed partial class BonkSystem : EntitySystem
|
||||
|
||||
_doAfter.TryStartDoAfter(doAfterArgs);
|
||||
|
||||
args.Handled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnAttemptClimb(EntityUid uid, BonkableComponent component, AttemptClimbEvent args)
|
||||
{
|
||||
if (args.Cancelled || !HasComp<ClumsyComponent>(args.Climber) || !HasComp<HandsComponent>(args.User))
|
||||
return;
|
||||
|
||||
if (TryStartBonk(uid, args.User, args.Climber, component))
|
||||
args.Cancelled = true;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
|
||||
Reference in New Issue
Block a user