-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Remuchi <[email protected]>
- Loading branch information
Showing
15 changed files
with
192 additions
and
173 deletions.
There are no files selected for viewing
56 changes: 32 additions & 24 deletions
56
Content.Server/Stunnable/Components/StunOnCollideComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,40 @@ | ||
namespace Content.Server.Stunnable.Components | ||
using Content.Server.Stunnable.Systems; | ||
using Content.Shared.Whitelist; | ||
|
||
namespace Content.Server.Stunnable.Components; | ||
|
||
/// <summary> | ||
/// Adds stun when it collides with an entity | ||
/// </summary> | ||
[RegisterComponent, Access(typeof(StunOnCollideSystem))] | ||
public sealed partial class StunOnCollideComponent : Component | ||
{ | ||
/// <summary> | ||
/// Adds stun when it collides with an entity | ||
/// </summary> | ||
[RegisterComponent, Access(typeof(StunOnCollideSystem))] | ||
public sealed partial class StunOnCollideComponent : Component | ||
{ | ||
// TODO: Can probably predict this. | ||
// TODO: Can probably predict this. | ||
|
||
// See stunsystem for what these do | ||
[DataField("stunAmount")] | ||
public int StunAmount; | ||
[DataField] | ||
public TimeSpan StunAmount = TimeSpan.FromSeconds(5); | ||
|
||
[DataField("knockdownAmount")] | ||
public int KnockdownAmount; | ||
[DataField] | ||
public TimeSpan KnockdownAmount = TimeSpan.FromSeconds(5); | ||
|
||
[DataField("slowdownAmount")] | ||
public int SlowdownAmount; | ||
[DataField] | ||
public TimeSpan SlowdownAmount = TimeSpan.FromSeconds(10); | ||
|
||
[DataField("walkSpeedMultiplier")] | ||
public float WalkSpeedMultiplier = 1f; | ||
[DataField] | ||
public float WalkSpeedMultiplier = 1f; | ||
|
||
[DataField("runSpeedMultiplier")] | ||
public float RunSpeedMultiplier = 1f; | ||
[DataField] | ||
public float RunSpeedMultiplier = 1f; | ||
|
||
/// <summary> | ||
/// Fixture we track for the collision. | ||
/// </summary> | ||
[DataField("fixture")] public string FixtureID = "projectile"; | ||
} | ||
/// <summary> | ||
/// Fixture we track for the collision. | ||
/// </summary> | ||
[DataField] | ||
public string FixtureId = "projectile"; | ||
|
||
/// <summary> | ||
/// Entities excluded from collision check. | ||
/// </summary> | ||
[DataField] | ||
public EntityWhitelist? Blacklist; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,51 @@ | ||
using Content.Server.Stunnable.Components; | ||
using Content.Shared.Standing; | ||
using Content.Shared.StatusEffect; | ||
using JetBrains.Annotations; | ||
using Robust.Shared.Physics.Dynamics; | ||
using Content.Shared.Throwing; | ||
using Content.Shared.Whitelist; | ||
using Robust.Shared.Physics.Events; | ||
|
||
namespace Content.Server.Stunnable | ||
namespace Content.Server.Stunnable.Systems; | ||
|
||
[UsedImplicitly] | ||
internal sealed class StunOnCollideSystem : EntitySystem | ||
{ | ||
[UsedImplicitly] | ||
internal sealed class StunOnCollideSystem : EntitySystem | ||
[Dependency] private readonly StunSystem _stunSystem = default!; | ||
[Dependency] private readonly EntityWhitelistSystem _entityWhitelist = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
SubscribeLocalEvent<StunOnCollideComponent, StartCollideEvent>(HandleCollide); | ||
SubscribeLocalEvent<StunOnCollideComponent, ThrowDoHitEvent>(HandleThrow); | ||
} | ||
|
||
private void TryDoCollideStun(Entity<StunOnCollideComponent> ent, EntityUid target) | ||
{ | ||
[Dependency] private readonly StunSystem _stunSystem = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
SubscribeLocalEvent<StunOnCollideComponent, StartCollideEvent>(HandleCollide); | ||
SubscribeLocalEvent<StunOnCollideComponent, ThrowDoHitEvent>(HandleThrow); | ||
} | ||
|
||
private void TryDoCollideStun(EntityUid uid, StunOnCollideComponent component, EntityUid target) | ||
{ | ||
|
||
if (EntityManager.TryGetComponent<StatusEffectsComponent>(target, out var status)) | ||
{ | ||
_stunSystem.TryStun(target, TimeSpan.FromSeconds(component.StunAmount), true, status); | ||
|
||
_stunSystem.TryKnockdown(target, TimeSpan.FromSeconds(component.KnockdownAmount), true, | ||
status); | ||
|
||
_stunSystem.TrySlowdown(target, TimeSpan.FromSeconds(component.SlowdownAmount), true, | ||
component.WalkSpeedMultiplier, component.RunSpeedMultiplier, status); | ||
} | ||
} | ||
private void HandleCollide(EntityUid uid, StunOnCollideComponent component, ref StartCollideEvent args) | ||
{ | ||
if (args.OurFixtureId != component.FixtureID) | ||
return; | ||
|
||
TryDoCollideStun(uid, component, args.OtherEntity); | ||
} | ||
|
||
private void HandleThrow(EntityUid uid, StunOnCollideComponent component, ThrowDoHitEvent args) | ||
{ | ||
TryDoCollideStun(uid, component, args.Target); | ||
} | ||
if (!EntityManager.TryGetComponent<StatusEffectsComponent>(target, out var status) || | ||
ent.Comp.Blacklist is { } blacklist && _entityWhitelist.IsValid(blacklist, target)) | ||
return; | ||
|
||
_stunSystem.TryStun(target, ent.Comp.StunAmount, true, status); | ||
_stunSystem.TryKnockdown(target, ent.Comp.KnockdownAmount, true, status); | ||
|
||
_stunSystem.TrySlowdown( | ||
target, | ||
ent.Comp.SlowdownAmount, | ||
true, | ||
ent.Comp.WalkSpeedMultiplier, | ||
ent.Comp.RunSpeedMultiplier, | ||
status); | ||
} | ||
|
||
private void HandleCollide(Entity<StunOnCollideComponent> ent, ref StartCollideEvent args) | ||
{ | ||
if (args.OurFixtureId != ent.Comp.FixtureId) | ||
return; | ||
|
||
TryDoCollideStun(ent, args.OtherEntity); | ||
} | ||
|
||
private void HandleThrow(Entity<StunOnCollideComponent> ent, ref ThrowDoHitEvent args) => | ||
TryDoCollideStun(ent, args.Target); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.