Skip to content

Commit da4fa9b

Browse files
Clumsy system refactor (space-wizards#31147)
* First commit * Fixes * Added the noise * Renames * Timespan * Fixed space * entity -> ent * This shouldn't work * opps.... * Datafield name change * Better comments * small comment * Personal skill issue * Event renames and stuff * Couple fixes * Defib ref fixes (Silly me) * Added clumsy back! * no hard code clumsy! * Identity fix * Event name change * Comment change * Function name change * opp * Update names * Damage stuff! * Fixes! * Fixes * opps * This was hidden away!! * negative diff feeds me
1 parent 09d0565 commit da4fa9b

File tree

25 files changed

+484
-281
lines changed

25 files changed

+484
-281
lines changed

Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using Content.Shared.Administration.Components;
2323
using Content.Shared.Body.Components;
2424
using Content.Shared.Body.Part;
25+
using Content.Shared.Clumsy;
2526
using Content.Shared.Clothing.Components;
2627
using Content.Shared.Cluwne;
2728
using Content.Shared.Damage;

Content.Server/Administration/Systems/SuperBonkSystem.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
using Content.Server.Administration.Components;
22
using Content.Shared.Climbing.Components;
3-
using Content.Shared.Climbing.Events;
4-
using Content.Shared.Climbing.Systems;
5-
using Content.Shared.Interaction.Components;
3+
using Content.Shared.Clumsy;
64
using Content.Shared.Mobs;
75
using Content.Shared.Mobs.Components;
6+
using Robust.Shared.Audio.Systems;
87

98
namespace Content.Server.Administration.Systems;
109

11-
public sealed class SuperBonkSystem: EntitySystem
10+
public sealed class SuperBonkSystem : EntitySystem
1211
{
1312
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;
14-
[Dependency] private readonly BonkSystem _bonkSystem = default!;
13+
[Dependency] private readonly ClumsySystem _clumsySystem = default!;
14+
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
1515

1616
public override void Initialize()
1717
{
1818
base.Initialize();
1919

20-
SubscribeLocalEvent<SuperBonkComponent, ComponentShutdown>(OnBonkShutdown);
2120
SubscribeLocalEvent<SuperBonkComponent, MobStateChangedEvent>(OnMobStateChanged);
21+
SubscribeLocalEvent<SuperBonkComponent, ComponentShutdown>(OnBonkShutdown);
2222
}
2323

24-
public void StartSuperBonk(EntityUid target, float delay = 0.1f, bool stopWhenDead = false )
24+
public void StartSuperBonk(EntityUid target, float delay = 0.1f, bool stopWhenDead = false)
2525
{
2626

2727
//The other check in the code to stop when the target dies does not work if the target is already dead.
@@ -31,7 +31,6 @@ public void StartSuperBonk(EntityUid target, float delay = 0.1f, bool stopWhenDe
3131
return;
3232
}
3333

34-
3534
var hadClumsy = EnsureComp<ClumsyComponent>(target, out _);
3635

3736
var tables = EntityQueryEnumerator<BonkableComponent>();
@@ -79,16 +78,17 @@ public override void Update(float frameTime)
7978
private void Bonk(SuperBonkComponent comp)
8079
{
8180
var uid = comp.Tables.Current.Key;
82-
var bonkComp = comp.Tables.Current.Value;
8381

8482
// It would be very weird for something without a transform component to have a bonk component
8583
// but just in case because I don't want to crash the server.
86-
if (!HasComp<TransformComponent>(uid))
84+
if (!HasComp<TransformComponent>(uid) || !TryComp<ClumsyComponent>(comp.Target, out var clumsyComp))
8785
return;
8886

8987
_transformSystem.SetCoordinates(comp.Target, Transform(uid).Coordinates);
9088

91-
_bonkSystem.TryBonk(comp.Target, uid, bonkComp);
89+
_clumsySystem.HitHeadClumsy((comp.Target, clumsyComp), uid);
90+
91+
_audioSystem.PlayPvs(clumsyComp.TableBonkSound, comp.Target);
9292
}
9393

9494
private void OnMobStateChanged(EntityUid uid, SuperBonkComponent comp, MobStateChangedEvent args)

Content.Server/Chemistry/EntitySystems/HypospraySystem.cs

+36-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Content.Shared.Chemistry.EntitySystems;
22
using Content.Shared.Chemistry.Components;
33
using Content.Shared.Chemistry.Components.SolutionManager;
4+
using Content.Shared.Chemistry.Hypospray.Events;
45
using Content.Shared.Chemistry;
56
using Content.Shared.Database;
67
using Content.Shared.FixedPoint;
@@ -85,14 +86,44 @@ public bool TryDoInject(Entity<HyposprayComponent> entity, EntityUid target, Ent
8586

8687
string? msgFormat = null;
8788

88-
if (target == user)
89-
msgFormat = "hypospray-component-inject-self-message";
90-
else if (EligibleEntity(user, EntityManager, component) && _interaction.TryRollClumsy(user, component.ClumsyFailChance))
89+
// Self event
90+
var selfEvent = new SelfBeforeHyposprayInjectsEvent(user, entity.Owner, target);
91+
RaiseLocalEvent(user, selfEvent);
92+
93+
if (selfEvent.Cancelled)
94+
{
95+
_popup.PopupEntity(Loc.GetString(selfEvent.InjectMessageOverride ?? "hypospray-cant-inject", ("owner", Identity.Entity(target, EntityManager))), target, user);
96+
return false;
97+
}
98+
99+
target = selfEvent.TargetGettingInjected;
100+
101+
if (!EligibleEntity(target, EntityManager, component))
102+
return false;
103+
104+
// Target event
105+
var targetEvent = new TargetBeforeHyposprayInjectsEvent(user, entity.Owner, target);
106+
RaiseLocalEvent(target, targetEvent);
107+
108+
if (targetEvent.Cancelled)
91109
{
92-
msgFormat = "hypospray-component-inject-self-clumsy-message";
93-
target = user;
110+
_popup.PopupEntity(Loc.GetString(targetEvent.InjectMessageOverride ?? "hypospray-cant-inject", ("owner", Identity.Entity(target, EntityManager))), target, user);
111+
return false;
94112
}
95113

114+
target = targetEvent.TargetGettingInjected;
115+
116+
if (!EligibleEntity(target, EntityManager, component))
117+
return false;
118+
119+
// The target event gets priority for the overriden message.
120+
if (targetEvent.InjectMessageOverride != null)
121+
msgFormat = targetEvent.InjectMessageOverride;
122+
else if (selfEvent.InjectMessageOverride != null)
123+
msgFormat = selfEvent.InjectMessageOverride;
124+
else if (target == user)
125+
msgFormat = "hypospray-component-inject-self-message";
126+
96127
if (!_solutionContainers.TryGetSolution(uid, component.SolutionName, out var hypoSpraySoln, out var hypoSpraySolution) || hypoSpraySolution.Volume == 0)
97128
{
98129
_popup.PopupEntity(Loc.GetString("hypospray-component-empty-message"), target, user);

Content.Server/Cluwne/CluwneSystem.cs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Content.Shared.Interaction.Components;
1717
using Robust.Shared.Audio.Systems;
1818
using Content.Shared.NameModifier.EntitySystems;
19+
using Content.Shared.Clumsy;
1920

2021
namespace Content.Server.Cluwne;
2122

Content.Server/Medical/DefibrillatorSystem.cs

+55-15
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,20 @@ private void OnDoAfter(EntityUid uid, DefibrillatorComponent component, Defibril
7777
Zap(uid, target, args.User, component);
7878
}
7979

80-
public bool CanZap(EntityUid uid, EntityUid target, EntityUid? user = null, DefibrillatorComponent? component = null)
80+
/// <summary>
81+
/// Checks if you can actually defib a target.
82+
/// </summary>
83+
/// <param name="uid">Uid of the defib</param>
84+
/// <param name="target">Uid of the target getting defibbed</param>
85+
/// <param name="user">Uid of the entity using the defibrillator</param>
86+
/// <param name="component">Defib component</param>
87+
/// <param name="targetCanBeAlive">
88+
/// If true, the target can be alive. If false, the function will check if the target is alive and will return false if they are.
89+
/// </param>
90+
/// <returns>
91+
/// Returns true if the target is valid to be defibed, false otherwise.
92+
/// </returns>
93+
public bool CanZap(EntityUid uid, EntityUid target, EntityUid? user = null, DefibrillatorComponent? component = null, bool targetCanBeAlive = false)
8194
{
8295
if (!Resolve(uid, ref component))
8396
return false;
@@ -98,15 +111,25 @@ public bool CanZap(EntityUid uid, EntityUid target, EntityUid? user = null, Defi
98111
if (!_powerCell.HasActivatableCharge(uid, user: user))
99112
return false;
100113

101-
if (_mobState.IsAlive(target, mobState))
114+
if (!targetCanBeAlive && _mobState.IsAlive(target, mobState))
102115
return false;
103116

104-
if (!component.CanDefibCrit && _mobState.IsCritical(target, mobState))
117+
if (!targetCanBeAlive && !component.CanDefibCrit && _mobState.IsCritical(target, mobState))
105118
return false;
106119

107120
return true;
108121
}
109122

123+
/// <summary>
124+
/// Tries to start defibrillating the target. If the target is valid, will start the defib do-after.
125+
/// </summary>
126+
/// <param name="uid">Uid of the defib</param>
127+
/// <param name="target">Uid of the target getting defibbed</param>
128+
/// <param name="user">Uid of the entity using the defibrillator</param>
129+
/// <param name="component">Defib component</param>
130+
/// <returns>
131+
/// Returns true if the defibrillation do-after started, otherwise false.
132+
/// </returns>
110133
public bool TryStartZap(EntityUid uid, EntityUid target, EntityUid user, DefibrillatorComponent? component = null)
111134
{
112135
if (!Resolve(uid, ref component))
@@ -118,25 +141,42 @@ public bool TryStartZap(EntityUid uid, EntityUid target, EntityUid user, Defibri
118141
_audio.PlayPvs(component.ChargeSound, uid);
119142
return _doAfter.TryStartDoAfter(new DoAfterArgs(EntityManager, user, component.DoAfterDuration, new DefibrillatorZapDoAfterEvent(),
120143
uid, target, uid)
121-
{
122-
NeedHand = true,
123-
BreakOnMove = !component.AllowDoAfterMovement
124-
});
144+
{
145+
NeedHand = true,
146+
BreakOnMove = !component.AllowDoAfterMovement
147+
});
125148
}
126149

127-
public void Zap(EntityUid uid, EntityUid target, EntityUid user, DefibrillatorComponent? component = null, MobStateComponent? mob = null, MobThresholdsComponent? thresholds = null)
150+
/// <summary>
151+
/// Tries to defibrillate the target with the given defibrillator.
152+
/// </summary>
153+
public void Zap(EntityUid uid, EntityUid target, EntityUid user, DefibrillatorComponent? component = null)
128154
{
129-
if (!Resolve(uid, ref component) || !Resolve(target, ref mob, ref thresholds, false))
155+
if (!Resolve(uid, ref component))
130156
return;
131157

132-
// clowns zap themselves
133-
if (HasComp<ClumsyComponent>(user) && user != target)
134-
{
135-
Zap(uid, user, user, component);
158+
if (!_powerCell.TryUseActivatableCharge(uid, user: user))
136159
return;
137-
}
138160

139-
if (!_powerCell.TryUseActivatableCharge(uid, user: user))
161+
var selfEvent = new SelfBeforeDefibrillatorZapsEvent(user, uid, target);
162+
RaiseLocalEvent(user, selfEvent);
163+
164+
target = selfEvent.DefibTarget;
165+
166+
// Ensure thet new target is still valid.
167+
if (selfEvent.Cancelled || !CanZap(uid, target, user, component, true))
168+
return;
169+
170+
var targetEvent = new TargetBeforeDefibrillatorZapsEvent(user, uid, target);
171+
RaiseLocalEvent(target, targetEvent);
172+
173+
target = targetEvent.DefibTarget;
174+
175+
if (targetEvent.Cancelled || !CanZap(uid, target, user, component, true))
176+
return;
177+
178+
if (!TryComp<MobStateComponent>(target, out var mob) ||
179+
!TryComp<MobThresholdsComponent>(target, out var thresholds))
140180
return;
141181

142182
_audio.PlayPvs(component.ZapSound, uid);

Content.Server/Weapons/Ranged/Systems/GunSystem.cs

+6-24
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
using System.Linq;
22
using System.Numerics;
33
using Content.Server.Cargo.Systems;
4-
using Content.Server.Interaction;
54
using Content.Server.Power.EntitySystems;
6-
using Content.Server.Stunnable;
75
using Content.Server.Weapons.Ranged.Components;
86
using Content.Shared.Damage;
97
using Content.Shared.Damage.Systems;
108
using Content.Shared.Database;
119
using Content.Shared.Effects;
12-
using Content.Shared.Interaction.Components;
1310
using Content.Shared.Projectiles;
1411
using Content.Shared.Weapons.Melee;
1512
using Content.Shared.Weapons.Ranged;
@@ -33,16 +30,13 @@ public sealed partial class GunSystem : SharedGunSystem
3330
[Dependency] private readonly IComponentFactory _factory = default!;
3431
[Dependency] private readonly BatterySystem _battery = default!;
3532
[Dependency] private readonly DamageExamineSystem _damageExamine = default!;
36-
[Dependency] private readonly InteractionSystem _interaction = default!;
3733
[Dependency] private readonly PricingSystem _pricing = default!;
3834
[Dependency] private readonly SharedColorFlashEffectSystem _color = default!;
3935
[Dependency] private readonly SharedTransformSystem _transform = default!;
4036
[Dependency] private readonly StaminaSystem _stamina = default!;
41-
[Dependency] private readonly StunSystem _stun = default!;
4237
[Dependency] private readonly SharedContainerSystem _container = default!;
4338

4439
private const float DamagePitchVariation = 0.05f;
45-
public const float GunClumsyChance = 0.5f;
4640

4741
public override void Initialize()
4842
{
@@ -71,26 +65,14 @@ public override void Shoot(EntityUid gunUid, GunComponent gun, List<(EntityUid?
7165
{
7266
userImpulse = true;
7367

74-
// Try a clumsy roll
75-
// TODO: Who put this here
76-
if (TryComp<ClumsyComponent>(user, out var clumsy) && gun.ClumsyProof == false)
68+
if (user != null)
7769
{
78-
for (var i = 0; i < ammo.Count; i++)
70+
var selfEvent = new SelfBeforeGunShotEvent(user.Value, (gunUid, gun), ammo);
71+
RaiseLocalEvent(user.Value, selfEvent);
72+
if (selfEvent.Cancelled)
7973
{
80-
if (_interaction.TryRollClumsy(user.Value, GunClumsyChance, clumsy))
81-
{
82-
// Wound them
83-
Damageable.TryChangeDamage(user, clumsy.ClumsyDamage, origin: user);
84-
_stun.TryParalyze(user.Value, TimeSpan.FromSeconds(3f), true);
85-
86-
// Apply salt to the wound ("Honk!")
87-
Audio.PlayPvs(new SoundPathSpecifier("/Audio/Weapons/Guns/Gunshots/bang.ogg"), gunUid);
88-
Audio.PlayPvs(clumsy.ClumsySound, gunUid);
89-
90-
PopupSystem.PopupEntity(Loc.GetString("gun-clumsy"), user.Value);
91-
userImpulse = false;
92-
return;
93-
}
74+
userImpulse = false;
75+
return;
9476
}
9577
}
9678

Content.Shared/Chemistry/Components/HyposprayComponent.cs

-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ public sealed partial class HyposprayComponent : Component
1111
[DataField]
1212
public string SolutionName = "hypospray";
1313

14-
// TODO: This should be on clumsycomponent.
15-
[DataField]
16-
[ViewVariables(VVAccess.ReadWrite)]
17-
public float ClumsyFailChance = 0.5f;
18-
1914
[DataField]
2015
[ViewVariables(VVAccess.ReadWrite)]
2116
public FixedPoint2 TransferAmount = FixedPoint2.New(5);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Content.Shared.Inventory;
2+
3+
namespace Content.Shared.Chemistry.Hypospray.Events;
4+
5+
public abstract partial class BeforeHyposprayInjectsTargetEvent : CancellableEntityEventArgs, IInventoryRelayEvent
6+
{
7+
public SlotFlags TargetSlots { get; } = SlotFlags.WITHOUT_POCKET;
8+
public EntityUid EntityUsingHypospray;
9+
public readonly EntityUid Hypospray;
10+
public EntityUid TargetGettingInjected;
11+
public string? InjectMessageOverride;
12+
13+
public BeforeHyposprayInjectsTargetEvent(EntityUid user, EntityUid hypospray, EntityUid target)
14+
{
15+
EntityUsingHypospray = user;
16+
Hypospray = hypospray;
17+
TargetGettingInjected = target;
18+
InjectMessageOverride = null;
19+
}
20+
}
21+
22+
/// <summary>
23+
/// This event is raised on the user using the hypospray before the hypospray is injected.
24+
/// The event is triggered on the user and all their clothing.
25+
/// </summary>
26+
public sealed class SelfBeforeHyposprayInjectsEvent : BeforeHyposprayInjectsTargetEvent
27+
{
28+
public SelfBeforeHyposprayInjectsEvent(EntityUid user, EntityUid hypospray, EntityUid target) : base(user, hypospray, target) { }
29+
}
30+
31+
/// <summary>
32+
/// This event is raised on the target before the hypospray is injected.
33+
/// The event is triggered on the target itself and all its clothing.
34+
/// </summary>
35+
public sealed class TargetBeforeHyposprayInjectsEvent : BeforeHyposprayInjectsTargetEvent
36+
{
37+
public TargetBeforeHyposprayInjectsEvent (EntityUid user, EntityUid hypospray, EntityUid target) : base(user, hypospray, target) { }
38+
}

0 commit comments

Comments
 (0)