Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE][TWEAK] AccessWeaponBlocker #920

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Content.Shared.Backmen.AccessGunBlockerSystem;

namespace Content.Client.Backmen.AccessWeaponBlockerSystem;

[RegisterComponent]
public sealed partial class AccessWeaponBlockerComponent : SharedAccessWeaponBlockerComponent
{
[ViewVariables(VVAccess.ReadWrite)]
public bool CanUse;

[ViewVariables(VVAccess.ReadWrite)]
public string AlertText = "";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Content.Shared.Interaction.Events;
using Content.Shared.Backmen.AccessGunBlockerSystem;
using Content.Shared.Weapons.Melee.Events;
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Shared.GameStates;

namespace Content.Client.Backmen.AccessWeaponBlockerSystem;

public sealed class AccessWeaponBlockerSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<AccessWeaponBlockerComponent, AttemptShootEvent>(OnShootAttempt);
SubscribeLocalEvent<AccessWeaponBlockerComponent, AttemptMeleeEvent>(OnMeleeAttempt);
SubscribeLocalEvent<AccessWeaponBlockerComponent, UseAttemptEvent>(OnUseAttempt);
SubscribeLocalEvent<AccessWeaponBlockerComponent, InteractionAttemptEvent>(OnInteractAttempt);
SubscribeLocalEvent<AccessWeaponBlockerComponent, ComponentHandleState>(OnAccessWeaponBlockerHandleState);
}

private void OnUseAttempt(EntityUid uid, AccessWeaponBlockerComponent component, ref UseAttemptEvent args)
{
if (component.CanUse)
return;

args.Cancel();
}

private void OnInteractAttempt(EntityUid uid, AccessWeaponBlockerComponent component, ref InteractionAttemptEvent args)
{
if (component.CanUse)
return;

args.Cancelled = true;
}

private void OnAccessWeaponBlockerHandleState(EntityUid uid, AccessWeaponBlockerComponent component, ref ComponentHandleState args)
{
if (args.Current is not AccessWeaponBlockerComponentState state)
return;

component.CanUse = state.CanUse;
component.AlertText = state.AlertText;
}

private void OnMeleeAttempt(EntityUid uid, AccessWeaponBlockerComponent component, ref AttemptMeleeEvent args)
{
if (component.CanUse)
return;

args.Cancelled = true;
args.Message = component.AlertText;
}

private void OnShootAttempt(EntityUid uid, AccessWeaponBlockerComponent component, ref AttemptShootEvent args)
{
if (component.CanUse)
return;

args.Cancelled = true;
args.Message = component.AlertText;
}
CatBackGround marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Content.Shared.Access;
using Content.Shared.Backmen.AccessGunBlockerSystem;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;

namespace Content.Server.Backmen.AccessWeaponBlockerSystem;

[RegisterComponent]
public sealed partial class AccessWeaponBlockerComponent : SharedAccessWeaponBlockerComponent
{
[ViewVariables(VVAccess.ReadWrite)]
public bool CanUse;
CatBackGround marked this conversation as resolved.
Show resolved Hide resolved

[ViewVariables(VVAccess.ReadWrite)]
[DataField("alertText")]
public string AlertText = "";

[ViewVariables(VVAccess.ReadWrite),
DataField("access", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<AccessLevelPrototype>))]
public HashSet<string> Access = new();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using Content.Shared.Hands;
using Content.Shared.Access.Components;
using Content.Shared.Backmen.AccessGunBlockerSystem;
using Content.Shared.Weapons.Melee.Events;
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Shared.GameStates;
using Content.Shared.Inventory;
using Content.Shared.PDA;

namespace Content.Server.Backmen.AccessWeaponBlockerSystem;

public sealed class AccessWeaponBlockerSystem : EntitySystem
{
[Dependency] private readonly InventorySystem _inventorySystem = default!;
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<AccessWeaponBlockerComponent, AttemptShootEvent>(OnShootAttempt);
SubscribeLocalEvent<AccessWeaponBlockerComponent, AttemptMeleeEvent>(OnMeleeAttempt);
SubscribeLocalEvent<AccessWeaponBlockerComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<AccessWeaponBlockerComponent, GotEquippedHandEvent>(OnGotEquippedHand);
}


private void OnGotEquippedHand(Entity<AccessWeaponBlockerComponent> accessBlocker, ref GotEquippedHandEvent args)
{
if (!_inventorySystem.TryGetSlotEntity(args.User, "id", out var slotCardUid))
return;
var accessEntity = TryComp<PdaComponent>(slotCardUid, out var pda) && pda.ContainedId is { } pdaSlot
? pdaSlot
: slotCardUid.Value;
accessBlocker.Comp.CanUse = IsAnyAccess(accessEntity, accessBlocker);
Dirty(accessBlocker);
}
CatBackGround marked this conversation as resolved.
Show resolved Hide resolved

private bool IsAnyAccess(EntityUid accessEntity, Entity<AccessWeaponBlockerComponent> accessBlocker)
{
if (!TryComp<AccessComponent>(accessEntity, out var access))
return false;
foreach (var accessTag in access.Tags)
{
if (accessBlocker.Comp.Access.Contains(accessTag))
return true;
}
return false;
}
CatBackGround marked this conversation as resolved.
Show resolved Hide resolved
private void OnGetState(EntityUid uid, AccessWeaponBlockerComponent component, ref ComponentGetState args)
{
args.State = new AccessWeaponBlockerComponentState()
{
CanUse = component.CanUse,
AlertText = component.AlertText
};
}

private void OnMeleeAttempt(EntityUid uid, AccessWeaponBlockerComponent component, ref AttemptMeleeEvent args)
{
if (component.CanUse)
return;

args.Cancelled = true;
args.Message = component.AlertText;
}

private void OnShootAttempt(EntityUid uid, AccessWeaponBlockerComponent component, ref AttemptShootEvent args)
{
if (component.CanUse)
return;

args.Cancelled = true;
args.Message = component.AlertText;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;

namespace Content.Shared.Backmen.AccessGunBlockerSystem;
CatBackGround marked this conversation as resolved.
Show resolved Hide resolved

[NetworkedComponent]
public abstract partial class SharedAccessWeaponBlockerComponent : Component
{

}
CatBackGround marked this conversation as resolved.
Show resolved Hide resolved

[Serializable, NetSerializable]
public sealed class AccessWeaponBlockerComponentState : ComponentState
{
public bool CanUse;
public string AlertText = "";
}
CatBackGround marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Content.Shared.Backmen.AccessWeaponBlockerSystem;

public sealed class SharedFactionWeaponBlockerSystem : EntitySystem
{

}
Loading