2021-07-10 17:35:33 +02:00
|
|
|
using Content.Server.Flash.Components;
|
2022-07-14 19:39:42 -07:00
|
|
|
using Content.Server.Light.EntitySystems;
|
2021-10-10 12:47:26 +02:00
|
|
|
using Content.Server.Stunnable;
|
2022-09-29 15:51:59 +10:00
|
|
|
using Content.Server.Weapons.Melee.Events;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Examine;
|
2021-09-09 16:20:41 +02:00
|
|
|
using Content.Shared.Flash;
|
2022-07-10 18:36:53 -07:00
|
|
|
using Content.Shared.IdentityManagement;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Interaction;
|
2022-03-13 01:33:23 +13:00
|
|
|
using Content.Shared.Interaction.Events;
|
2021-09-09 16:20:41 +02:00
|
|
|
using Content.Shared.Inventory;
|
|
|
|
|
using Content.Shared.Physics;
|
2021-09-26 15:18:45 +02:00
|
|
|
using Content.Shared.Popups;
|
2022-08-13 22:14:49 -07:00
|
|
|
using Content.Shared.Tag;
|
2021-06-05 00:20:52 -07:00
|
|
|
using Robust.Server.GameObjects;
|
|
|
|
|
using Robust.Shared.Audio;
|
|
|
|
|
using Robust.Shared.Player;
|
2021-09-09 16:20:41 +02:00
|
|
|
using Robust.Shared.Timing;
|
2021-12-30 22:56:10 +01:00
|
|
|
using InventoryComponent = Content.Shared.Inventory.InventoryComponent;
|
2021-06-05 00:20:52 -07:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Flash
|
2021-06-05 00:20:52 -07:00
|
|
|
{
|
2021-09-09 16:20:41 +02:00
|
|
|
internal sealed class FlashSystem : SharedFlashSystem
|
2021-06-05 00:20:52 -07:00
|
|
|
{
|
2022-03-03 21:18:35 +11:00
|
|
|
[Dependency] private readonly EntityLookupSystem _entityLookup = default!;
|
2021-09-09 16:20:41 +02:00
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
2021-10-10 12:47:26 +02:00
|
|
|
[Dependency] private readonly StunSystem _stunSystem = default!;
|
2021-12-30 22:56:10 +01:00
|
|
|
[Dependency] private readonly InventorySystem _inventorySystem = default!;
|
2022-02-28 00:46:38 +11:00
|
|
|
[Dependency] private readonly MetaDataSystem _metaSystem = default!;
|
2022-02-17 15:40:03 +13:00
|
|
|
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
2022-08-13 22:14:49 -07:00
|
|
|
[Dependency] private readonly TagSystem _tagSystem = default!;
|
2021-09-09 16:20:41 +02:00
|
|
|
|
2021-06-05 00:20:52 -07:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2021-09-09 16:20:41 +02:00
|
|
|
SubscribeLocalEvent<FlashComponent, MeleeHitEvent>(OnFlashMeleeHit);
|
2022-07-14 19:39:42 -07:00
|
|
|
SubscribeLocalEvent<FlashComponent, UseInHandEvent>(OnFlashUseInHand, before: new []{ typeof(HandheldLightSystem) });
|
2021-09-09 16:20:41 +02:00
|
|
|
SubscribeLocalEvent<FlashComponent, ExaminedEvent>(OnFlashExamined);
|
2022-02-28 00:46:38 +11:00
|
|
|
|
2021-09-09 16:20:41 +02:00
|
|
|
SubscribeLocalEvent<InventoryComponent, FlashAttemptEvent>(OnInventoryFlashAttempt);
|
2022-02-28 00:46:38 +11:00
|
|
|
|
2021-09-09 16:20:41 +02:00
|
|
|
SubscribeLocalEvent<FlashImmunityComponent, FlashAttemptEvent>(OnFlashImmunityFlashAttempt);
|
2021-06-05 00:20:52 -07:00
|
|
|
}
|
|
|
|
|
|
2021-09-09 16:20:41 +02:00
|
|
|
private void OnFlashMeleeHit(EntityUid uid, FlashComponent comp, MeleeHitEvent args)
|
2021-06-05 00:20:52 -07:00
|
|
|
{
|
2022-11-03 13:01:08 +01:00
|
|
|
if (!args.IsHit)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-06-05 00:20:52 -07:00
|
|
|
if (!UseFlash(comp, args.User))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
args.Handled = true;
|
2021-12-05 21:02:04 +01:00
|
|
|
foreach (var e in args.HitEntities)
|
2021-06-05 00:20:52 -07:00
|
|
|
{
|
2021-12-03 15:53:09 +01:00
|
|
|
Flash(e, args.User, uid, comp.FlashDuration, comp.SlowTo);
|
2021-06-05 00:20:52 -07:00
|
|
|
}
|
|
|
|
|
}
|
2022-08-13 22:14:49 -07:00
|
|
|
|
2022-07-14 19:39:42 -07:00
|
|
|
private void OnFlashUseInHand(EntityUid uid, FlashComponent comp, UseInHandEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Handled || !UseFlash(comp, args.User))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
args.Handled = true;
|
|
|
|
|
FlashArea(uid, args.User, comp.Range, comp.AoeFlashDuration, comp.SlowTo, true);
|
|
|
|
|
}
|
2021-06-05 00:20:52 -07:00
|
|
|
|
2021-12-05 21:02:04 +01:00
|
|
|
private bool UseFlash(FlashComponent comp, EntityUid user)
|
2021-06-05 00:20:52 -07:00
|
|
|
{
|
|
|
|
|
if (comp.HasUses)
|
|
|
|
|
{
|
|
|
|
|
// TODO flash visualizer
|
2021-12-08 13:00:43 +01:00
|
|
|
if (!EntityManager.TryGetComponent<SpriteComponent?>(comp.Owner, out var sprite))
|
2021-06-05 00:20:52 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (--comp.Uses == 0)
|
|
|
|
|
{
|
|
|
|
|
sprite.LayerSetState(0, "burnt");
|
2022-08-13 22:14:49 -07:00
|
|
|
|
|
|
|
|
_tagSystem.AddTag(comp.Owner, "Trash");
|
2021-06-05 00:20:52 -07:00
|
|
|
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;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-12 19:45:47 -04:00
|
|
|
SoundSystem.Play(comp.Sound.GetSound(), Filter.Pvs(comp.Owner), comp.Owner, AudioParams.Default);
|
2021-06-05 00:20:52 -07:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 18:06:12 +10:00
|
|
|
public void Flash(EntityUid target, EntityUid? user, EntityUid? used, float flashDuration, float slowTo, bool displayPopup = true, FlashableComponent? flashable = null)
|
2021-06-05 00:20:52 -07:00
|
|
|
{
|
2022-07-06 18:06:12 +10:00
|
|
|
if (!Resolve(target, ref flashable, false)) return;
|
|
|
|
|
|
2021-09-09 16:20:41 +02:00
|
|
|
var attempt = new FlashAttemptEvent(target, user, used);
|
2022-06-22 09:53:41 +10:00
|
|
|
RaiseLocalEvent(target, attempt, true);
|
2021-09-09 16:20:41 +02:00
|
|
|
|
|
|
|
|
if (attempt.Cancelled)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-07-06 18:06:12 +10:00
|
|
|
flashable.LastFlash = _gameTiming.CurTime;
|
|
|
|
|
flashable.Duration = flashDuration / 1000f; // TODO: Make this sane...
|
|
|
|
|
Dirty(flashable);
|
2021-06-05 00:20:52 -07:00
|
|
|
|
2022-07-06 18:06:12 +10:00
|
|
|
_stunSystem.TrySlowdown(target, TimeSpan.FromSeconds(flashDuration/1000f), true,
|
|
|
|
|
slowTo, slowTo);
|
2021-06-05 00:20:52 -07:00
|
|
|
|
2022-07-06 18:06:12 +10:00
|
|
|
if (displayPopup && user != null && target != user && EntityManager.EntityExists(user.Value))
|
|
|
|
|
{
|
|
|
|
|
user.Value.PopupMessage(target, Loc.GetString("flash-component-user-blinds-you",
|
2022-07-10 18:36:53 -07:00
|
|
|
("user", Identity.Entity(user.Value, EntityManager))));
|
2021-06-05 00:20:52 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-06 18:06:12 +10:00
|
|
|
public void FlashArea(EntityUid source, EntityUid? user, float range, float duration, float slowTo = 0.8f, bool displayPopup = false, SoundSpecifier? sound = null)
|
2021-09-09 16:20:41 +02:00
|
|
|
{
|
2021-11-08 12:37:32 +01:00
|
|
|
var transform = EntityManager.GetComponent<TransformComponent>(source);
|
2022-07-06 18:06:12 +10:00
|
|
|
var mapPosition = transform.MapPosition;
|
2021-12-27 09:51:12 -07:00
|
|
|
var flashableEntities = new List<EntityUid>();
|
2022-07-06 18:06:12 +10:00
|
|
|
var flashableQuery = GetEntityQuery<FlashableComponent>();
|
2021-09-09 16:20:41 +02:00
|
|
|
|
|
|
|
|
foreach (var entity in _entityLookup.GetEntitiesInRange(transform.Coordinates, range))
|
|
|
|
|
{
|
2022-07-06 18:06:12 +10:00
|
|
|
if (!flashableQuery.HasComponent(entity))
|
2021-12-27 09:51:12 -07:00
|
|
|
continue;
|
2021-09-09 16:20:41 +02:00
|
|
|
|
2021-12-27 09:51:12 -07:00
|
|
|
flashableEntities.Add(entity);
|
2021-09-09 16:20:41 +02:00
|
|
|
}
|
|
|
|
|
|
2021-12-27 09:51:12 -07:00
|
|
|
foreach (var entity in flashableEntities)
|
|
|
|
|
{
|
|
|
|
|
// Check for unobstructed entities while ignoring the mobs with flashable components.
|
2022-08-31 13:27:30 +01:00
|
|
|
if (!_interactionSystem.InRangeUnobstructed(entity, mapPosition, range, CollisionGroup.Opaque, (e) => flashableEntities.Contains(e) || e == source))
|
2021-12-27 09:51:12 -07:00
|
|
|
continue;
|
|
|
|
|
|
2022-07-06 18:06:12 +10:00
|
|
|
// They shouldn't have flash removed in between right?
|
|
|
|
|
Flash(entity, user, source, duration, slowTo, displayPopup, flashableQuery.GetComponent(entity));
|
2021-12-27 09:51:12 -07:00
|
|
|
}
|
2021-09-09 16:20:41 +02:00
|
|
|
if (sound != null)
|
|
|
|
|
{
|
2022-07-06 18:06:12 +10:00
|
|
|
SoundSystem.Play(sound.GetSound(), Filter.Pvs(transform), source);
|
2021-09-09 16:20:41 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnFlashExamined(EntityUid uid, FlashComponent comp, ExaminedEvent args)
|
2021-06-05 00:20:52 -07:00
|
|
|
{
|
|
|
|
|
if (!comp.HasUses)
|
|
|
|
|
{
|
2021-09-15 16:58:15 +02:00
|
|
|
args.PushText(Loc.GetString("flash-component-examine-empty"));
|
2021-06-05 00:20:52 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (args.IsInDetailsRange)
|
|
|
|
|
{
|
2021-09-15 16:58:15 +02:00
|
|
|
args.PushMarkup(
|
2021-06-05 00:20:52 -07:00
|
|
|
Loc.GetString(
|
|
|
|
|
"flash-component-examine-detail-count",
|
|
|
|
|
("count", comp.Uses),
|
|
|
|
|
("markupCountColor", "green")
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-09 16:20:41 +02:00
|
|
|
|
|
|
|
|
private void OnInventoryFlashAttempt(EntityUid uid, InventoryComponent component, FlashAttemptEvent args)
|
|
|
|
|
{
|
2022-06-15 03:04:52 -04:00
|
|
|
foreach (var slot in new string[]{"head", "eyes", "mask"})
|
|
|
|
|
{
|
|
|
|
|
if (args.Cancelled)
|
|
|
|
|
break;
|
|
|
|
|
if (_inventorySystem.TryGetSlotEntity(uid, slot, out var item, component))
|
2022-06-22 09:53:41 +10:00
|
|
|
RaiseLocalEvent(item.Value, args, true);
|
2022-06-15 03:04:52 -04:00
|
|
|
}
|
2021-09-09 16:20:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnFlashImmunityFlashAttempt(EntityUid uid, FlashImmunityComponent component, FlashAttemptEvent args)
|
|
|
|
|
{
|
|
|
|
|
if(component.Enabled)
|
|
|
|
|
args.Cancel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class FlashAttemptEvent : CancellableEntityEventArgs
|
2021-09-09 16:20:41 +02:00
|
|
|
{
|
|
|
|
|
public readonly EntityUid Target;
|
|
|
|
|
public readonly EntityUid? User;
|
|
|
|
|
public readonly EntityUid? Used;
|
|
|
|
|
|
|
|
|
|
public FlashAttemptEvent(EntityUid target, EntityUid? user, EntityUid? used)
|
|
|
|
|
{
|
|
|
|
|
Target = target;
|
|
|
|
|
User = user;
|
|
|
|
|
Used = used;
|
|
|
|
|
}
|
2021-06-05 00:20:52 -07:00
|
|
|
}
|
|
|
|
|
}
|