Skip to content

Commit 71e3c03

Browse files
Pacification Prevents Throwing Weapons (#1433)
# Description Prevents entities who are Pacified (through the Pacifist trait or being a thief) from throwing items that deal damage on hit or embed. ## Technical Details Two components will prevent throwing if they deal any damage: `DamageOtherOnHitComponent` and `EmbedPassiveComponent`. The pacifist check on `EmbeddableProjectileComponent` has been removed, because just because an item is embeddable does not mean they deal damage. ## Media **Throw attempt with the Pacifist trait** ![image](https://github.com/user-attachments/assets/6c439bb3-b41b-4f30-975d-4fa15c2cfa6d) # Changelog :cl: Skubman - fix: Pacified characters (Pacifist trait and thieves) can no longer throw items that deal throwing damage. --------- Signed-off-by: VMSolidus <[email protected]> Co-authored-by: VMSolidus <[email protected]>
1 parent d2875c9 commit 71e3c03

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

Content.Server/Damage/Systems/DamageOtherOnHitSystem.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Content.Shared.Camera;
2+
using Content.Shared.CombatMode.Pacification;
23
using Content.Shared.Damage;
34
using Content.Shared.Damage.Components;
45
using Content.Shared.Damage.Events;
@@ -31,13 +32,13 @@ public override void Initialize()
3132
{
3233
base.Initialize();
3334

34-
SubscribeLocalEvent<StaminaComponent, BeforeThrowEvent>(OnBeforeThrow);
35+
SubscribeLocalEvent<StaminaComponent, BeforeThrowEvent>(OnBeforeThrow, after: [typeof(PacificationSystem)]);
3536
SubscribeLocalEvent<DamageOtherOnHitComponent, DamageExamineEvent>(OnDamageExamine, after: [typeof(MeleeWeaponSystem)]);
3637
}
3738

3839
private void OnBeforeThrow(EntityUid uid, StaminaComponent component, ref BeforeThrowEvent args)
3940
{
40-
if (!TryComp<DamageOtherOnHitComponent>(args.ItemUid, out var damage))
41+
if (args.Cancelled || !TryComp<DamageOtherOnHitComponent>(args.ItemUid, out var damage))
4142
return;
4243

4344
if (component.CritThreshold - component.StaminaDamage <= damage.StaminaCost)

Content.Shared/Damage/Systems/SharedDamageOtherOnHitSystem.cs

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Content.Shared.Administration.Logs;
22
using Content.Shared.Camera;
3+
using Content.Shared.CombatMode.Pacification;
34
using Content.Shared.Contests;
45
using Content.Shared.Damage;
56
using Content.Shared.Damage.Components;
@@ -39,6 +40,7 @@ public override void Initialize()
3940
SubscribeLocalEvent<DamageOtherOnHitComponent, MapInitEvent>(OnMapInit);
4041
SubscribeLocalEvent<DamageOtherOnHitComponent, ThrowDoHitEvent>(OnDoHit);
4142
SubscribeLocalEvent<DamageOtherOnHitComponent, ThrownEvent>(OnThrown);
43+
SubscribeLocalEvent<DamageOtherOnHitComponent, AttemptPacifiedThrowEvent>(OnAttemptPacifiedThrow);
4244

4345
SubscribeLocalEvent<ItemToggleDamageOtherOnHitComponent, MapInitEvent>(OnItemToggleMapInit);
4446
SubscribeLocalEvent<DamageOtherOnHitComponent, ItemToggledEvent>(OnItemToggle);
@@ -181,6 +183,16 @@ private void OnThrown(EntityUid uid, DamageOtherOnHitComponent component, Thrown
181183
component.HitQuantity = 0;
182184
}
183185

186+
/// <summary>
187+
/// Prevent Pacified entities from throwing damaging items.
188+
/// </summary>
189+
private void OnAttemptPacifiedThrow(EntityUid uid, DamageOtherOnHitComponent comp, ref AttemptPacifiedThrowEvent args)
190+
{
191+
// Allow healing projectiles, forbid any that do damage
192+
if (comp.Damage.AnyPositive())
193+
args.Cancel("pacified-cannot-throw");
194+
}
195+
184196
/// <summary>
185197
/// Gets the total damage a throwing weapon does.
186198
/// </summary>

Content.Shared/Projectiles/EmbedPassiveDamageSystem.cs

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Content.Shared.CombatMode.Pacification;
12
using Content.Shared.Damage;
23
using Content.Shared.Damage.Components;
34
using Content.Shared.Damage.Events;
@@ -24,6 +25,7 @@ public override void Initialize()
2425
SubscribeLocalEvent<EmbedPassiveDamageComponent, EmbedEvent>(OnEmbed);
2526
SubscribeLocalEvent<EmbedPassiveDamageComponent, RemoveEmbedEvent>(OnRemoveEmbed);
2627
SubscribeLocalEvent<EmbedPassiveDamageComponent, ItemToggledEvent>(OnItemToggle);
28+
SubscribeLocalEvent<EmbedPassiveDamageComponent, AttemptPacifiedThrowEvent>(OnAttemptPacifiedThrow);
2729
}
2830

2931
/// <summary>
@@ -92,6 +94,16 @@ private void OnItemToggle(EntityUid uid, EmbedPassiveDamageComponent component,
9294
component.Damage = deactivatedDamage;
9395
}
9496

97+
/// <summary>
98+
/// Prevent Pacified entities from throwing items that deal passive damage when embedded.
99+
/// </summary>
100+
private void OnAttemptPacifiedThrow(EntityUid uid, EmbedPassiveDamageComponent comp, ref AttemptPacifiedThrowEvent args)
101+
{
102+
// Allow healing projectiles, forbid any that do damage
103+
if (comp.Damage.AnyPositive())
104+
args.Cancel("pacified-cannot-throw");
105+
}
106+
95107
public override void Update(float frameTime)
96108
{
97109
base.Update(frameTime);

Content.Shared/Projectiles/SharedProjectileSystem.cs

-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Numerics;
22
using Content.Shared.Body.Systems;
3-
using Content.Shared.CombatMode.Pacification;
43
using Content.Shared.Damage;
54
using Content.Shared.DoAfter;
65
using Content.Shared.Examine;
@@ -47,7 +46,6 @@ public override void Initialize()
4746
SubscribeLocalEvent<EmbeddableProjectileComponent, ThrowDoHitEvent>(OnEmbedThrowDoHit);
4847
SubscribeLocalEvent<EmbeddableProjectileComponent, ActivateInWorldEvent>(OnEmbedActivate);
4948
SubscribeLocalEvent<EmbeddableProjectileComponent, RemoveEmbeddedProjectileEvent>(OnEmbedRemove);
50-
SubscribeLocalEvent<EmbeddableProjectileComponent, AttemptPacifiedThrowEvent>(OnAttemptPacifiedThrow);
5149
SubscribeLocalEvent<EmbeddableProjectileComponent, ExaminedEvent>(OnExamined);
5250
}
5351

@@ -211,14 +209,6 @@ public void SetShooter(EntityUid id, ProjectileComponent component, EntityUid sh
211209
Dirty(id, component);
212210
}
213211

214-
/// <summary>
215-
/// Prevent players with the Pacified status effect from throwing embeddable projectiles.
216-
/// </summary>
217-
private void OnAttemptPacifiedThrow(Entity<EmbeddableProjectileComponent> ent, ref AttemptPacifiedThrowEvent args)
218-
{
219-
args.Cancel("pacified-cannot-throw-embed");
220-
}
221-
222212
private void OnExamined(EntityUid uid, EmbeddableProjectileComponent component, ExaminedEvent args)
223213
{
224214
if (!(component.Target is {} target))

0 commit comments

Comments
 (0)