# Conflicts: # Content.Client/Crayon/CrayonDecalVisualizer.cs # Content.Client/Tabletop/TabletopSystem.cs # Content.IntegrationTests/Tests/InventoryHelpersTest.cs # Content.Server/AI/EntitySystems/AiSystem.cs # Content.Server/AI/Utility/AiLogic/UtilityAI.cs # Content.Server/AME/AMENodeGroup.cs # Content.Server/Administration/AdminVerbSystem.cs # Content.Server/Body/Systems/RespiratorSystem.cs # Content.Server/Chemistry/Components/InjectorComponent.cs # Content.Server/Chemistry/TileReactions/CleanTileReaction.cs # Content.Server/Chemistry/TileReactions/SpillTileReaction.cs # Content.Server/Crayon/CrayonComponent.cs # Content.Server/Doors/Components/ServerDoorComponent.cs # Content.Server/Explosion/EntitySystems/TriggerSystem.cs # Content.Server/Fluids/Components/MopComponent.cs # Content.Server/Fluids/Components/SpillExtensions.cs # Content.Server/Fluids/EntitySystems/PuddleSystem.cs # Content.Server/Instruments/InstrumentSystem.cs # Content.Server/Nutrition/EntitySystems/DrinkSystem.cs # Content.Server/Nutrition/EntitySystems/FoodSystem.cs # Content.Server/PneumaticCannon/PneumaticCannonSystem.cs # Content.Server/Storage/Components/EntityStorageComponent.cs # Content.Server/Storage/Components/StorageFillComponent.cs # Content.Server/Stunnable/StunbatonSystem.cs # Content.Server/Throwing/ThrowHelper.cs # Content.Server/Weapon/Ranged/Barrels/BarrelSystem.cs # Content.Server/Weapon/Ranged/Barrels/Components/ServerBatteryBarrelComponent.cs # Content.Server/Weapon/Ranged/ServerRangedWeaponComponent.cs # Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs # Content.Shared/Damage/Components/DamageableComponent.cs # Content.Shared/Damage/Systems/DamageableSystem.cs # Content.Shared/MobState/Components/MobStateComponent.cs # Content.Shared/Slippery/SharedSlipperySystem.cs
212 lines
7.5 KiB
C#
212 lines
7.5 KiB
C#
using System;
|
|
using Content.Server.Flash.Components;
|
|
using Content.Server.Inventory.Components;
|
|
using Content.Server.Items;
|
|
using Content.Server.Stunnable;
|
|
using Content.Server.Weapon.Melee;
|
|
using Content.Shared.Examine;
|
|
using Content.Shared.Flash;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Interaction.Helpers;
|
|
using Content.Shared.Inventory;
|
|
using Content.Shared.Physics;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Sound;
|
|
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.Timing;
|
|
|
|
namespace Content.Server.Flash
|
|
{
|
|
internal sealed class FlashSystem : SharedFlashSystem
|
|
{
|
|
[Dependency] private readonly IEntityLookup _entityLookup = default!;
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
[Dependency] private readonly StunSystem _stunSystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<FlashComponent, MeleeHitEvent>(OnFlashMeleeHit);
|
|
SubscribeLocalEvent<FlashComponent, MeleeInteractEvent>(OnFlashMeleeInteract);
|
|
SubscribeLocalEvent<FlashComponent, UseInHandEvent>(OnFlashUseInHand);
|
|
SubscribeLocalEvent<FlashComponent, ExaminedEvent>(OnFlashExamined);
|
|
SubscribeLocalEvent<InventoryComponent, FlashAttemptEvent>(OnInventoryFlashAttempt);
|
|
SubscribeLocalEvent<FlashImmunityComponent, FlashAttemptEvent>(OnFlashImmunityFlashAttempt);
|
|
}
|
|
|
|
private void OnFlashMeleeHit(EntityUid uid, FlashComponent comp, MeleeHitEvent args)
|
|
{
|
|
if (!UseFlash(comp, args.User))
|
|
{
|
|
return;
|
|
}
|
|
|
|
args.Handled = true;
|
|
foreach (var e in args.HitEntities)
|
|
{
|
|
Flash(e, args.User, uid, comp.FlashDuration, comp.SlowTo);
|
|
}
|
|
}
|
|
|
|
private void OnFlashMeleeInteract(EntityUid uid, FlashComponent comp, MeleeInteractEvent args)
|
|
{
|
|
if (!UseFlash(comp, args.User))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (IoCManager.Resolve<IEntityManager>().HasComponent<FlashableComponent>(args.Entity))
|
|
{
|
|
args.CanInteract = true;
|
|
Flash(args.Entity, args.User, uid, comp.FlashDuration, comp.SlowTo);
|
|
}
|
|
}
|
|
|
|
private void OnFlashUseInHand(EntityUid uid, FlashComponent comp, UseInHandEvent args)
|
|
{
|
|
if (!UseFlash(comp, args.User))
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (var entity in _entityLookup.GetEntitiesInRange(IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(comp.Owner).Coordinates, comp.Range))
|
|
{
|
|
Flash(entity, args.User, uid, comp.AoeFlashDuration, comp.SlowTo);
|
|
}
|
|
}
|
|
|
|
private bool UseFlash(FlashComponent comp, EntityUid user)
|
|
{
|
|
if (comp.HasUses)
|
|
{
|
|
// TODO flash visualizer
|
|
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<SpriteComponent?>(comp.Owner, 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), comp.Sound.GetSound(), comp.Owner, AudioParams.Default);
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public void Flash(EntityUid target, EntityUid? user, EntityUid? used, float flashDuration, float slowTo, bool displayPopup = true)
|
|
{
|
|
var attempt = new FlashAttemptEvent(target, user, used);
|
|
RaiseLocalEvent(target, attempt);
|
|
|
|
if (attempt.Cancelled)
|
|
return;
|
|
|
|
if (EntityManager.TryGetComponent<FlashableComponent>(target, out var flashable))
|
|
{
|
|
flashable.LastFlash = _gameTiming.CurTime;
|
|
flashable.Duration = flashDuration / 1000f; // TODO: Make this sane...
|
|
flashable.Dirty();
|
|
}
|
|
|
|
_stunSystem.TrySlowdown(target, TimeSpan.FromSeconds(flashDuration/1000f), true,
|
|
slowTo, slowTo);
|
|
|
|
if (displayPopup && user != null && target != user)
|
|
{
|
|
// TODO Resolving the EntityUidhere bad.
|
|
if (EntityManager.EntityExists(user.Value) && EntityManager.EntityExists(target))
|
|
{
|
|
user.Value.PopupMessage(target, Loc.GetString("flash-component-user-blinds-you",
|
|
("user", user.Value)));
|
|
}
|
|
}
|
|
}
|
|
|
|
public void FlashArea(EntityUid source, EntityUid? user, float range, float duration, float slowTo = 0f, bool displayPopup = false, SoundSpecifier? sound = null)
|
|
{
|
|
var transform = EntityManager.GetComponent<TransformComponent>(source);
|
|
|
|
foreach (var entity in _entityLookup.GetEntitiesInRange(transform.Coordinates, range))
|
|
{
|
|
if (!IoCManager.Resolve<IEntityManager>().HasComponent<FlashableComponent>(entity) ||
|
|
!transform.InRangeUnobstructed(entity, range, CollisionGroup.Opaque)) continue;
|
|
|
|
Flash(entity, user, source, duration, slowTo, displayPopup);
|
|
}
|
|
|
|
if (sound != null)
|
|
{
|
|
SoundSystem.Play(Filter.Pvs(transform), sound.GetSound(), transform.Coordinates);
|
|
}
|
|
}
|
|
|
|
private void OnFlashExamined(EntityUid uid, FlashComponent comp, ExaminedEvent args)
|
|
{
|
|
if (!comp.HasUses)
|
|
{
|
|
args.PushText(Loc.GetString("flash-component-examine-empty"));
|
|
return;
|
|
}
|
|
|
|
if (args.IsInDetailsRange)
|
|
{
|
|
args.PushMarkup(
|
|
Loc.GetString(
|
|
"flash-component-examine-detail-count",
|
|
("count", comp.Uses),
|
|
("markupCountColor", "green")
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
private void OnInventoryFlashAttempt(EntityUid uid, InventoryComponent component, FlashAttemptEvent args)
|
|
{
|
|
// Forward the event to the glasses, if any.
|
|
if(component.TryGetSlotItem(EquipmentSlotDefines.Slots.EYES, out ItemComponent? glasses))
|
|
RaiseLocalEvent(glasses.Owner, args);
|
|
}
|
|
|
|
private void OnFlashImmunityFlashAttempt(EntityUid uid, FlashImmunityComponent component, FlashAttemptEvent args)
|
|
{
|
|
if(component.Enabled)
|
|
args.Cancel();
|
|
}
|
|
}
|
|
|
|
public class FlashAttemptEvent : CancellableEntityEventArgs
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
}
|