Re-organize all projects (#4166)
This commit is contained in:
36
Content.Server/Flash/Components/FlashComponent.cs
Normal file
36
Content.Server/Flash/Components/FlashComponent.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Flash.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class FlashComponent : Component
|
||||
{
|
||||
public override string Name => "Flash";
|
||||
|
||||
[DataField("duration")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int FlashDuration { get; set; } = 5000;
|
||||
|
||||
[DataField("uses")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int Uses { get; set; } = 5;
|
||||
|
||||
[DataField("range")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Range { get; set; } = 7f;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("aoeFlashDuration")]
|
||||
public int AoeFlashDuration { get; set; } = 2000;
|
||||
|
||||
[DataField("slowTo")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float SlowTo { get; set; } = 0.5f;
|
||||
|
||||
public bool Flashing;
|
||||
|
||||
public bool HasUses => Uses > 0;
|
||||
}
|
||||
}
|
||||
39
Content.Server/Flash/Components/FlashProjectileComponent.cs
Normal file
39
Content.Server/Flash/Components/FlashProjectileComponent.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
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.Flash.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Upon colliding with an object this will flash in an area around it
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class FlashProjectileComponent : Component, IStartCollide
|
||||
{
|
||||
public override string Name => "FlashProjectile";
|
||||
|
||||
[DataField("range")]
|
||||
private float _range = 1.0f;
|
||||
[DataField("duration")]
|
||||
private float _duration = 8.0f;
|
||||
|
||||
private bool _flashed;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
// Shouldn't be using this without a ProjectileComponent because it will just immediately collide with thrower
|
||||
Owner.EnsureComponent<ProjectileComponent>();
|
||||
}
|
||||
|
||||
void IStartCollide.CollideWith(Fixture ourFixture, Fixture otherFixture, in Manifold manifold)
|
||||
{
|
||||
if (_flashed) return;
|
||||
|
||||
FlashableComponent.FlashAreaHelper(Owner, _range, _duration);
|
||||
_flashed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
50
Content.Server/Flash/Components/FlashableComponent.cs
Normal file
50
Content.Server/Flash/Components/FlashableComponent.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using Content.Shared.Flash;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server.Flash.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class FlashableComponent : SharedFlashableComponent
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
private double _duration;
|
||||
private TimeSpan _lastFlash;
|
||||
|
||||
public void Flash(double duration)
|
||||
{
|
||||
_lastFlash = _gameTiming.CurTime;
|
||||
_duration = duration;
|
||||
Dirty();
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
{
|
||||
return new FlashComponentState(_duration, _lastFlash);
|
||||
}
|
||||
|
||||
public static void FlashAreaHelper(IEntity source, float range, float duration, string? sound = null)
|
||||
{
|
||||
foreach (var entity in IoCManager.Resolve<IEntityLookup>().GetEntitiesInRange(source.Transform.Coordinates, range))
|
||||
{
|
||||
if (!entity.TryGetComponent(out FlashableComponent? flashable) ||
|
||||
!source.InRangeUnobstructed(entity, range, CollisionGroup.Opaque)) continue;
|
||||
|
||||
flashable.Flash(duration);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(sound))
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(source), sound, source.Transform.Coordinates);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
152
Content.Server/Flash/FlashSystem.cs
Normal file
152
Content.Server/Flash/FlashSystem.cs
Normal file
@@ -0,0 +1,152 @@
|
||||
using Content.Server.Flash.Components;
|
||||
using Content.Server.Stunnable.Components;
|
||||
using Content.Server.Weapon.Melee;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Notification;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Flash
|
||||
{
|
||||
public class FlashSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<FlashComponent, MeleeHitEvent>(OnMeleeHit);
|
||||
SubscribeLocalEvent<FlashComponent, MeleeInteractEvent>(OnMeleeInteract);
|
||||
SubscribeLocalEvent<FlashComponent, UseInHandEvent>(OnUseInHand);
|
||||
|
||||
SubscribeLocalEvent<FlashComponent, ExaminedEvent>(OnExamined);
|
||||
}
|
||||
|
||||
public void OnMeleeHit(EntityUid uid, FlashComponent comp, MeleeHitEvent args)
|
||||
{
|
||||
if (!UseFlash(comp, args.User))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
args.Handled = true;
|
||||
foreach (IEntity e in args.HitEntities)
|
||||
{
|
||||
FlashEntity(e, args.User, comp.FlashDuration, comp.SlowTo);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMeleeInteract(EntityUid uid, FlashComponent comp, MeleeInteractEvent args)
|
||||
{
|
||||
if (!UseFlash(comp, args.User))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Entity.HasComponent<FlashableComponent>())
|
||||
{
|
||||
args.CanInteract = true;
|
||||
FlashEntity(args.Entity, args.User, comp.FlashDuration, comp.SlowTo);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnUseInHand(EntityUid uid, FlashComponent comp, UseInHandEvent args)
|
||||
{
|
||||
if (!UseFlash(comp, args.User))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var entity in IoCManager.Resolve<IEntityLookup>().GetEntitiesInRange(comp.Owner.Transform.Coordinates, comp.Range))
|
||||
{
|
||||
FlashEntity(entity, args.User, comp.AoeFlashDuration, comp.SlowTo);
|
||||
}
|
||||
}
|
||||
|
||||
private bool UseFlash(FlashComponent comp, IEntity user)
|
||||
{
|
||||
if (comp.HasUses)
|
||||
{
|
||||
// TODO flash visualizer
|
||||
if (!comp.Owner.TryGetComponent<SpriteComponent>(out var sprite))
|
||||
return false;
|
||||
|
||||
if (--comp.Uses == 0)
|
||||
{
|
||||
sprite.LayerSetState(0, "burnt");
|
||||
comp.Owner.PopupMessage(user, Loc.GetString("flash-component-becomes-empty"));
|
||||
}
|
||||
else if (!comp.Flashing)
|
||||
{
|
||||
int animLayer = sprite.AddLayerWithState("flashing");
|
||||
comp.Flashing = true;
|
||||
|
||||
comp.Owner.SpawnTimer(400, () =>
|
||||
{
|
||||
sprite.RemoveLayer(animLayer);
|
||||
comp.Flashing = false;
|
||||
});
|
||||
}
|
||||
|
||||
SoundSystem.Play(Filter.Pvs(comp.Owner), "/Audio/Weapons/flash.ogg", comp.Owner.Transform.Coordinates,
|
||||
AudioParams.Default);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: Check if target can be flashed (e.g. things like sunglasses would block a flash)
|
||||
// TODO: Merge with the code in FlashableComponent--raise an event on the target, that FlashableComponent or
|
||||
// another comp will catch
|
||||
private void FlashEntity(IEntity target, IEntity user, float flashDuration, float slowTo)
|
||||
{
|
||||
if (target.TryGetComponent<FlashableComponent>(out var flashable))
|
||||
{
|
||||
flashable.Flash(flashDuration / 1000d);
|
||||
}
|
||||
|
||||
if (target.TryGetComponent<StunnableComponent>(out var stunnableComponent))
|
||||
{
|
||||
stunnableComponent.Slowdown(flashDuration / 1000f, slowTo, slowTo);
|
||||
}
|
||||
|
||||
if (target != user)
|
||||
{
|
||||
user.PopupMessage(target,
|
||||
Loc.GetString(
|
||||
"flash-component-user-blinds-you",
|
||||
("user", user)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnExamined(EntityUid uid, FlashComponent comp, ExaminedEvent args)
|
||||
{
|
||||
if (!comp.HasUses)
|
||||
{
|
||||
args.Message.AddText("\n");
|
||||
args.Message.AddText(Loc.GetString("flash-component-examine-empty"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.IsInDetailsRange)
|
||||
{
|
||||
args.Message.AddText("\n");
|
||||
args.Message.AddMarkup(
|
||||
Loc.GetString(
|
||||
"flash-component-examine-detail-count",
|
||||
("count", comp.Uses),
|
||||
("markupCountColor", "green")
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user