Re-organize all projects (#4166)
This commit is contained in:
35
Content.Server/Stunnable/Components/StunbatonComponent.cs
Normal file
35
Content.Server/Stunnable/Components/StunbatonComponent.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
#nullable enable
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Stunnable.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class StunbatonComponent : Component
|
||||
{
|
||||
public override string Name => "Stunbaton";
|
||||
|
||||
public bool Activated = false;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("paralyzeChanceNoSlowdown")]
|
||||
public float ParalyzeChanceNoSlowdown { get; set; } = 0.35f;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("paralyzeChanceWithSlowdown")]
|
||||
public float ParalyzeChanceWithSlowdown { get; set; } = 0.85f;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("paralyzeTime")]
|
||||
public float ParalyzeTime { get; set; } = 10f;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("slowdownTime")]
|
||||
public float SlowdownTime { get; set; } = 5f;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("energyPerUse")]
|
||||
public float EnergyPerUse { get; set; } = 50;
|
||||
}
|
||||
}
|
||||
84
Content.Server/Stunnable/Components/StunnableComponent.cs
Normal file
84
Content.Server/Stunnable/Components/StunnableComponent.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
#nullable enable
|
||||
using Content.Server.Act;
|
||||
using Content.Server.Notification;
|
||||
using Content.Server.Standing;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.MobState;
|
||||
using Content.Shared.Notification;
|
||||
using Content.Shared.Stunnable;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Stunnable.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedStunnableComponent))]
|
||||
public class StunnableComponent : SharedStunnableComponent, IDisarmedAct
|
||||
{
|
||||
protected override void OnKnockdown()
|
||||
{
|
||||
EntitySystem.Get<StandingStateSystem>().Down(Owner);
|
||||
}
|
||||
|
||||
protected override void OnKnockdownEnd()
|
||||
{
|
||||
if(Owner.TryGetComponent(out IMobStateComponent? mobState) && !mobState.IsIncapacitated())
|
||||
EntitySystem.Get<StandingStateSystem>().Standing(Owner);
|
||||
}
|
||||
|
||||
public void CancelAll()
|
||||
{
|
||||
KnockdownTimer = null;
|
||||
StunnedTimer = null;
|
||||
Dirty();
|
||||
}
|
||||
|
||||
public void ResetStuns()
|
||||
{
|
||||
StunnedTimer = null;
|
||||
SlowdownTimer = null;
|
||||
|
||||
if (KnockedDown &&
|
||||
Owner.TryGetComponent(out IMobStateComponent? mobState) && !mobState.IsIncapacitated())
|
||||
{
|
||||
EntitySystem.Get<StandingStateSystem>().Standing(Owner);
|
||||
}
|
||||
|
||||
KnockdownTimer = null;
|
||||
Dirty();
|
||||
}
|
||||
|
||||
protected override void OnInteractHand()
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(Owner), "/Audio/Effects/thudswoosh.ogg", Owner, AudioHelpers.WithVariation(0.05f));
|
||||
}
|
||||
|
||||
bool IDisarmedAct.Disarmed(DisarmedActEventArgs eventArgs)
|
||||
{
|
||||
if (!IoCManager.Resolve<IRobustRandom>().Prob(eventArgs.PushProbability))
|
||||
return false;
|
||||
|
||||
Paralyze(4f);
|
||||
|
||||
var source = eventArgs.Source;
|
||||
var target = eventArgs.Target;
|
||||
|
||||
if (source != null)
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(source), "/Audio/Effects/thudswoosh.ogg", source,
|
||||
AudioHelpers.WithVariation(0.025f));
|
||||
if (target != null)
|
||||
{
|
||||
source.PopupMessageOtherClients(Loc.GetString("{0} pushes {1}!", source.Name, target.Name));
|
||||
source.PopupMessageCursor(Loc.GetString("You push {0}!", target.Name));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using Content.Server.Projectiles.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Physics.Collision;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Stunnable.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds stun when it collides with an entity
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class StunnableProjectileComponent : Component, IStartCollide
|
||||
{
|
||||
public override string Name => "StunnableProjectile";
|
||||
|
||||
// See stunnable for what these do
|
||||
[DataField("stunAmount")]
|
||||
private int _stunAmount = default;
|
||||
[DataField("knockdownAmount")]
|
||||
private int _knockdownAmount = default;
|
||||
[DataField("slowdownAmount")]
|
||||
private int _slowdownAmount = default;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
Owner.EnsureComponentWarn(out ProjectileComponent _);
|
||||
}
|
||||
|
||||
void IStartCollide.CollideWith(Fixture ourFixture, Fixture otherFixture, in Manifold manifold)
|
||||
{
|
||||
if (otherFixture.Body.Owner.TryGetComponent(out StunnableComponent? stunnableComponent))
|
||||
{
|
||||
stunnableComponent.Stun(_stunAmount);
|
||||
stunnableComponent.Knockdown(_knockdownAmount);
|
||||
stunnableComponent.Slowdown(_slowdownAmount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
192
Content.Server/Stunnable/StunbatonSystem.cs
Normal file
192
Content.Server/Stunnable/StunbatonSystem.cs
Normal file
@@ -0,0 +1,192 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Items;
|
||||
using Content.Server.PowerCell.Components;
|
||||
using Content.Server.Stunnable.Components;
|
||||
using Content.Server.Weapon.Melee;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Notification;
|
||||
using Content.Shared.Throwing;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Stunnable
|
||||
{
|
||||
public class StunbatonSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<StunbatonComponent, MeleeHitEvent>(OnMeleeHit);
|
||||
SubscribeLocalEvent<StunbatonComponent, MeleeInteractEvent>(OnMeleeInteract);
|
||||
SubscribeLocalEvent<StunbatonComponent, UseInHandEvent>(OnUseInHand);
|
||||
SubscribeLocalEvent<StunbatonComponent, ThrowCollideEvent>(OnThrowCollide);
|
||||
SubscribeLocalEvent<StunbatonComponent, PowerCellChangedEvent>(OnPowerCellChanged);
|
||||
SubscribeLocalEvent<StunbatonComponent, InteractUsingEvent>(OnInteractUsing);
|
||||
SubscribeLocalEvent<StunbatonComponent, ExaminedEvent>(OnExamined);
|
||||
}
|
||||
|
||||
private void OnMeleeHit(EntityUid uid, StunbatonComponent comp, MeleeHitEvent args)
|
||||
{
|
||||
if (!comp.Activated || !args.HitEntities.Any())
|
||||
return;
|
||||
|
||||
if (!ComponentManager.TryGetComponent<PowerCellSlotComponent>(uid, out var slot) || slot.Cell == null || !slot.Cell.TryUseCharge(comp.EnergyPerUse))
|
||||
return;
|
||||
|
||||
foreach (IEntity entity in args.HitEntities)
|
||||
{
|
||||
StunEntity(entity, comp);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMeleeInteract(EntityUid uid, StunbatonComponent comp, MeleeInteractEvent args)
|
||||
{
|
||||
if (!comp.Activated)
|
||||
return;
|
||||
|
||||
if (!ComponentManager.TryGetComponent<PowerCellSlotComponent>(uid, out var slot) || slot.Cell == null || !slot.Cell.TryUseCharge(comp.EnergyPerUse))
|
||||
return;
|
||||
|
||||
if (args.Entity.HasComponent<StunnableComponent>())
|
||||
{
|
||||
args.CanInteract = true;
|
||||
StunEntity(args.Entity, comp);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnUseInHand(EntityUid uid, StunbatonComponent comp, UseInHandEvent args)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanUse(args.User)) return;
|
||||
if (comp.Activated)
|
||||
{
|
||||
TurnOff(comp);
|
||||
}
|
||||
else
|
||||
{
|
||||
TurnOn(comp, args.User);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnThrowCollide(EntityUid uid, StunbatonComponent comp, ThrowCollideEvent args)
|
||||
{
|
||||
if (!ComponentManager.TryGetComponent<PowerCellSlotComponent>(uid, out var slot)) return;
|
||||
if (!comp.Activated || slot.Cell == null || !slot.Cell.TryUseCharge(comp.EnergyPerUse)) return;
|
||||
|
||||
StunEntity(args.Target, comp);
|
||||
}
|
||||
|
||||
private void OnPowerCellChanged(EntityUid uid, StunbatonComponent comp, PowerCellChangedEvent args)
|
||||
{
|
||||
if (args.Ejected)
|
||||
{
|
||||
TurnOff(comp);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInteractUsing(EntityUid uid, StunbatonComponent comp, InteractUsingEvent args)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanInteract(args.User)) return;
|
||||
if (ComponentManager.TryGetComponent<PowerCellSlotComponent>(uid, out var cellslot))
|
||||
cellslot.InsertCell(args.Used);
|
||||
}
|
||||
|
||||
private void OnExamined(EntityUid uid, StunbatonComponent comp, ExaminedEvent args)
|
||||
{
|
||||
args.Message.AddText("\n");
|
||||
var msg = comp.Activated
|
||||
? Loc.GetString("comp-stunbaton-examined-on")
|
||||
: Loc.GetString("comp-stunbaton-examined-off");
|
||||
args.Message.AddMarkup(msg);
|
||||
}
|
||||
|
||||
private void StunEntity(IEntity entity, StunbatonComponent comp)
|
||||
{
|
||||
if (!entity.TryGetComponent(out StunnableComponent? stunnable) || !comp.Activated) return;
|
||||
|
||||
SoundSystem.Play(Filter.Pvs(comp.Owner), "/Audio/Weapons/egloves.ogg", comp.Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
|
||||
if(!stunnable.SlowedDown)
|
||||
{
|
||||
if(_robustRandom.Prob(comp.ParalyzeChanceNoSlowdown))
|
||||
stunnable.Paralyze(comp.ParalyzeTime);
|
||||
else
|
||||
stunnable.Slowdown(comp.SlowdownTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(_robustRandom.Prob(comp.ParalyzeChanceWithSlowdown))
|
||||
stunnable.Paralyze(comp.ParalyzeTime);
|
||||
else
|
||||
stunnable.Slowdown(comp.SlowdownTime);
|
||||
}
|
||||
|
||||
|
||||
if (!comp.Owner.TryGetComponent<PowerCellSlotComponent>(out var slot) || slot.Cell == null || !(slot.Cell.CurrentCharge < comp.EnergyPerUse)) return;
|
||||
|
||||
SoundSystem.Play(Filter.Pvs(comp.Owner), AudioHelpers.GetRandomFileFromSoundCollection("sparks"), comp.Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
|
||||
TurnOff(comp);
|
||||
}
|
||||
|
||||
private void TurnOff(StunbatonComponent comp)
|
||||
{
|
||||
if (!comp.Activated)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!comp.Owner.TryGetComponent<SpriteComponent>(out var sprite) ||
|
||||
!comp.Owner.TryGetComponent<ItemComponent>(out var item)) return;
|
||||
|
||||
SoundSystem.Play(Filter.Pvs(comp.Owner), AudioHelpers.GetRandomFileFromSoundCollection("sparks"), comp.Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
|
||||
item.EquippedPrefix = "off";
|
||||
// TODO stunbaton visualizer
|
||||
sprite.LayerSetState(0, "stunbaton_off");
|
||||
comp.Activated = false;
|
||||
}
|
||||
|
||||
private void TurnOn(StunbatonComponent comp, IEntity user)
|
||||
{
|
||||
if (comp.Activated)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!comp.Owner.TryGetComponent<SpriteComponent>(out var sprite) ||
|
||||
!comp.Owner.TryGetComponent<ItemComponent>(out var item)) return;
|
||||
|
||||
var playerFilter = Filter.Pvs(comp.Owner);
|
||||
if (!comp.Owner.TryGetComponent<PowerCellSlotComponent>(out var slot))
|
||||
return;
|
||||
|
||||
if (slot.Cell == null)
|
||||
{
|
||||
SoundSystem.Play(playerFilter, "/Audio/Machines/button.ogg", comp.Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
|
||||
user.PopupMessage(Loc.GetString("comp-stunbaton-activated-missing-cell"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (slot.Cell != null && slot.Cell.CurrentCharge < comp.EnergyPerUse)
|
||||
{
|
||||
SoundSystem.Play(playerFilter, "/Audio/Machines/button.ogg", comp.Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
|
||||
user.PopupMessage(Loc.GetString("comp-stunbaton-activated-dead-cell"));
|
||||
return;
|
||||
}
|
||||
|
||||
SoundSystem.Play(playerFilter, AudioHelpers.GetRandomFileFromSoundCollection("sparks"), comp.Owner.Transform.Coordinates, AudioHelpers.WithVariation(0.25f));
|
||||
|
||||
item.EquippedPrefix = "on";
|
||||
sprite.LayerSetState(0, "stunbaton_on");
|
||||
comp.Activated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user