Запретить активацию и автоматически отключать энергетический щит в контейнерах (#2997)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: VigersRay <60344369+VigersRay@users.noreply.github.com> Co-authored-by: Vigers Ray <vigersray@gmail.com>
This commit is contained in:
parent
f2b639c516
commit
5c5900f367
3 changed files with 47 additions and 11 deletions
|
|
@ -59,11 +59,10 @@ public sealed partial class EnergyDomeSystem : EntitySystem
|
|||
|
||||
SubscribeLocalEvent<EnergyDomeGeneratorComponent, ComponentRemove>(OnComponentRemove);
|
||||
|
||||
//Dome events
|
||||
SubscribeLocalEvent<EnergyDomeComponent, DamageChangedEvent>(OnDomeDamaged);
|
||||
SubscribeLocalEvent<EnergyDomeProtectedUserComponent, EntParentChangedMessage>(OnProtectedEntityParentChanged);
|
||||
}
|
||||
|
||||
|
||||
private void OnInit(Entity<EnergyDomeGeneratorComponent> generator, ref MapInitEvent args)
|
||||
{
|
||||
if (generator.Comp.CanDeviceNetworkUse)
|
||||
|
|
@ -159,7 +158,6 @@ public sealed partial class EnergyDomeSystem : EntitySystem
|
|||
if (args.Handled)
|
||||
return;
|
||||
|
||||
// Sunrise-Start
|
||||
if (!_containerSystem.ContainsEntity(args.Performer, generator.Owner))
|
||||
return;
|
||||
|
||||
|
|
@ -168,7 +166,6 @@ public sealed partial class EnergyDomeSystem : EntitySystem
|
|||
if (!_biocodeSystem.CanUse(args.Performer, biocodedComponent.Factions))
|
||||
return;
|
||||
}
|
||||
// Sunrise-End
|
||||
|
||||
AttemptToggle(generator, !generator.Comp.Enabled);
|
||||
|
||||
|
|
@ -251,6 +248,12 @@ public sealed partial class EnergyDomeSystem : EntitySystem
|
|||
|
||||
public bool AttemptToggle(Entity<EnergyDomeGeneratorComponent> generator, bool status)
|
||||
{
|
||||
var parent = Transform(generator.Owner).ParentUid;
|
||||
if (HasComp<ContainerManagerComponent>(Transform(parent).ParentUid))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TryComp<UseDelayComponent>(generator, out var useDelay) && _useDelay.IsDelayed(new (generator, useDelay)))
|
||||
{
|
||||
_audio.PlayPvs(generator.Comp.TurnOffSound, generator);
|
||||
|
|
@ -321,6 +324,9 @@ public sealed partial class EnergyDomeSystem : EntitySystem
|
|||
domeComp.Generator = generator;
|
||||
}
|
||||
|
||||
var protectedComp = EnsureComp<EnergyDomeProtectedUserComponent>(protectedEntity);
|
||||
protectedComp.DomeEntity = newDome;
|
||||
|
||||
if (TryComp<PowerCellDrawComponent>(generator.Owner, out var powerCellDrawComponent))
|
||||
{
|
||||
_powerCell.SetDrawEnabled(generator.Owner, true);
|
||||
|
|
@ -335,6 +341,23 @@ public sealed partial class EnergyDomeSystem : EntitySystem
|
|||
generator.Comp.Enabled = true;
|
||||
}
|
||||
|
||||
// Sunrise: обработчик смены парента защищаемой сущности
|
||||
private void OnProtectedEntityParentChanged(Entity<EnergyDomeProtectedUserComponent> ent, ref EntParentChangedMessage args)
|
||||
{
|
||||
if (ent.Comp.DomeEntity == null)
|
||||
return;
|
||||
if (HasComp<ContainerManagerComponent>(Transform(ent).ParentUid))
|
||||
{
|
||||
if (TryComp<EnergyDomeComponent>(ent.Comp.DomeEntity.Value, out var domeComp) && domeComp.Generator != null)
|
||||
{
|
||||
if (TryComp<EnergyDomeGeneratorComponent>(domeComp.Generator.Value, out var genComp))
|
||||
{
|
||||
TurnOff((domeComp.Generator.Value, genComp), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void TurnOff(Entity<EnergyDomeGeneratorComponent> generator, bool startReloading)
|
||||
{
|
||||
if (!generator.Comp.Enabled)
|
||||
|
|
@ -343,6 +366,11 @@ public sealed partial class EnergyDomeSystem : EntitySystem
|
|||
generator.Comp.Enabled = false;
|
||||
QueueDel(generator.Comp.SpawnedDome);
|
||||
|
||||
if (generator.Comp.DomeParentEntity != null && HasComp<EnergyDomeProtectedUserComponent>(generator.Comp.DomeParentEntity.Value))
|
||||
{
|
||||
RemCompDeferred<EnergyDomeProtectedUserComponent>(generator.Comp.DomeParentEntity.Value);
|
||||
}
|
||||
|
||||
if (TryComp<PowerCellDrawComponent>(generator.Owner, out var powerCellDrawComponent))
|
||||
{
|
||||
_powerCell.SetDrawEnabled(generator.Owner, false);
|
||||
|
|
@ -372,3 +400,4 @@ public sealed partial class EnergyDomeSystem : EntitySystem
|
|||
: entity;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,11 @@
|
|||
using Content.Server.Power.Components;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Server.PowerCell;
|
||||
using Content.Server._Sunrise.EnergyShield;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Item.ItemToggle.Components;
|
||||
using Content.Shared.Item.ItemToggle;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Timing;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.PowerCell.Components;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
namespace Content.Server._Sunrise.EnergyShield;
|
||||
|
||||
|
|
@ -21,6 +15,7 @@ public sealed class EnergyShieldSystem : EntitySystem
|
|||
[Dependency] private readonly ItemToggleSystem _itemToggle = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
namespace Content.Shared.EnergyDome;
|
||||
|
||||
/// <summary>
|
||||
/// marker component that allows linking the dome generator with the dome itself
|
||||
/// </summary>
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed partial class EnergyDomeProtectedUserComponent : Component
|
||||
{
|
||||
[DataField]
|
||||
public EntityUid? DomeEntity;
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue