using Content.Server.Light.EntitySystems;
using Content.Server.Popups;
using Content.Server.Stunnable;
-using Content.Shared.Examine;
+using Content.Shared.Charges.Components;
+using Content.Shared.Charges.Systems;
using Content.Shared.Eye.Blinding.Components;
using Content.Shared.Flash;
using Content.Shared.IdentityManagement;
{
internal sealed class FlashSystem : SharedFlashSystem
{
- [Dependency] private readonly EntityLookupSystem _entityLookup = default!;
- [Dependency] private readonly IGameTiming _gameTiming = default!;
- [Dependency] private readonly StunSystem _stunSystem = default!;
- [Dependency] private readonly InventorySystem _inventorySystem = default!;
+ [Dependency] private readonly AppearanceSystem _appearance = default!;
[Dependency] private readonly AudioSystem _audio = default!;
- [Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
- [Dependency] private readonly TagSystem _tagSystem = default!;
+ [Dependency] private readonly SharedChargesSystem _charges = default!;
+ [Dependency] private readonly EntityLookupSystem _entityLookup = default!;
+ [Dependency] private readonly IGameTiming _timing = default!;
+ [Dependency] private readonly SharedInteractionSystem _interaction = default!;
+ [Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly PopupSystem _popup = default!;
- [Dependency] private readonly AppearanceSystem _appearance = default!;
+ [Dependency] private readonly StunSystem _stun = default!;
+ [Dependency] private readonly TagSystem _tag = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<FlashComponent, MeleeHitEvent>(OnFlashMeleeHit);
+ // ran before toggling light for extra-bright lantern
SubscribeLocalEvent<FlashComponent, UseInHandEvent>(OnFlashUseInHand, before: new []{ typeof(HandheldLightSystem) });
- SubscribeLocalEvent<FlashComponent, ExaminedEvent>(OnFlashExamined);
SubscribeLocalEvent<InventoryComponent, FlashAttemptEvent>(OnInventoryFlashAttempt);
private bool UseFlash(EntityUid uid, FlashComponent comp, EntityUid user)
{
- if (!comp.HasUses || comp.Flashing)
+ if (comp.Flashing)
return false;
- comp.Uses--;
+ TryComp<LimitedChargesComponent>(uid, out var charges);
+ if (_charges.IsEmpty(uid, charges))
+ return false;
+
+ _charges.UseCharge(uid, charges);
_audio.PlayPvs(comp.Sound, uid);
comp.Flashing = true;
_appearance.SetData(uid, FlashVisuals.Flashing, true);
- if (comp.Uses == 0)
+ if (_charges.IsEmpty(uid, charges))
{
_appearance.SetData(uid, FlashVisuals.Burnt, true);
- _tagSystem.AddTag(uid, "Trash");
+ _tag.AddTag(uid, "Trash");
_popup.PopupEntity(Loc.GetString("flash-component-becomes-empty"), user);
}
if (attempt.Cancelled)
return;
- flashable.LastFlash = _gameTiming.CurTime;
+ flashable.LastFlash = _timing.CurTime;
flashable.Duration = flashDuration / 1000f; // TODO: Make this sane...
Dirty(flashable);
- _stunSystem.TrySlowdown(target, TimeSpan.FromSeconds(flashDuration/1000f), true,
+ _stun.TrySlowdown(target, TimeSpan.FromSeconds(flashDuration/1000f), true,
slowTo, slowTo);
if (displayPopup && user != null && target != user && EntityManager.EntityExists(user.Value))
foreach (var entity in flashableEntities)
{
// Check for unobstructed entities while ignoring the mobs with flashable components.
- if (!_interactionSystem.InRangeUnobstructed(entity, mapPosition, range, CollisionGroup.Opaque, (e) => flashableEntities.Contains(e) || e == source))
+ if (!_interaction.InRangeUnobstructed(entity, mapPosition, range, CollisionGroup.Opaque, (e) => flashableEntities.Contains(e) || e == source))
continue;
// They shouldn't have flash removed in between right?
}
}
- 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)
{
foreach (var slot in new[] { "head", "eyes", "mask" })
{
if (args.Cancelled)
break;
- if (_inventorySystem.TryGetSlotEntity(uid, slot, out var item, component))
+ if (_inventory.TryGetSlotEntity(uid, slot, out var item, component))
RaiseLocalEvent(item.Value, args, true);
}
}