Separated Bonk functionality and component from ClimbSystem and ClimbComponent (#13635)

This commit is contained in:
Ilya Chvilyov
2023-02-01 00:33:00 +03:00
committed by GitHub
parent f81a25e585
commit eae58211e1
12 changed files with 141 additions and 90 deletions

View File

@@ -0,0 +1,63 @@
using Content.Shared.Interaction;
using Content.Shared.Stunnable;
using Content.Shared.CCVar;
using Content.Shared.Damage;
using Content.Shared.DragDrop;
using Robust.Shared.Configuration;
using Content.Shared.Popups;
using Content.Shared.IdentityManagement;
using Robust.Shared.Player;
namespace Content.Shared.Climbing;
public sealed class BonkSystem : EntitySystem
{
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
[Dependency] private readonly SharedStunSystem _stunSystem = default!;
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BonkableComponent, DragDropEvent>(OnDragDrop);
}
public bool TryBonk(EntityUid user, EntityUid bonkableUid, BonkableComponent? bonkableComponent = null)
{
if (Resolve(bonkableUid, ref bonkableComponent))
{
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);
_popupSystem.PopupEntity(Loc.GetString("bonkable-success-message-user", ("user", userName), ("bonkable", bonkableName)), user, user);
_audioSystem.PlayPvs(bonkableComponent.BonkSound, bonkableComponent.Owner);
_stunSystem.TryParalyze(user, TimeSpan.FromSeconds(bonkableComponent.BonkTime), true);
if (bonkableComponent.BonkDamage is { } bonkDmg)
_damageableSystem.TryChangeDamage(user, bonkDmg, true, origin: user);
return true;
}
return false;
}
private void OnDragDrop(EntityUid user, BonkableComponent bonkableComponent, DragDropEvent args)
{
TryBonk(args.Dragged, args.Target);
}
}