Misc implant fixes (#17172)

This commit is contained in:
Leon Friedrich
2023-06-07 15:53:11 +12:00
committed by GitHub
parent 1a3f8f2c2c
commit 677ef07aa2
8 changed files with 132 additions and 79 deletions

View File

@@ -1,7 +1,7 @@
using Content.Server.Explosion.Components;
using Content.Shared.Implants;
using Content.Shared.Interaction.Events;
using Content.Shared.Mobs;
using Robust.Shared.Player;
namespace Content.Server.Explosion.EntitySystems;
@@ -11,6 +11,9 @@ public sealed partial class TriggerSystem
{
SubscribeLocalEvent<TriggerOnMobstateChangeComponent, MobStateChangedEvent>(OnMobStateChanged);
SubscribeLocalEvent<TriggerOnMobstateChangeComponent, SuicideEvent>(OnSuicide);
SubscribeLocalEvent<TriggerOnMobstateChangeComponent, ImplantRelayEvent<SuicideEvent>>(OnSuicideRelay);
SubscribeLocalEvent<TriggerOnMobstateChangeComponent, ImplantRelayEvent<MobStateChangedEvent>>(OnMobStateRelay);
}
private void OnMobStateChanged(EntityUid uid, TriggerOnMobstateChangeComponent component, MobStateChangedEvent args)
@@ -45,4 +48,14 @@ public sealed partial class TriggerSystem
args.BlockSuicideAttempt(component.PreventSuicide);
}
}
private void OnSuicideRelay(EntityUid uid, TriggerOnMobstateChangeComponent component, ImplantRelayEvent<SuicideEvent> args)
{
OnSuicide(uid, component, args.Event);
}
private void OnMobStateRelay(EntityUid uid, TriggerOnMobstateChangeComponent component, ImplantRelayEvent<MobStateChangedEvent> args)
{
OnMobStateChanged(uid, component, args.Event);
}
}

View File

@@ -48,10 +48,12 @@ public sealed partial class ImplanterSystem : SharedImplanterSystem
}
else
{
if (!CanImplant(args.User, args.Target.Value, uid, component, out _, out _))
return;
//Implant self instantly, otherwise try to inject the target.
if (args.User == args.Target)
Implant(uid, args.Target.Value, component);
Implant(args.User, args.Target.Value, uid, component);
else
TryImplant(component, args.User, args.Target.Value, uid);
}
@@ -117,7 +119,7 @@ public sealed partial class ImplanterSystem : SharedImplanterSystem
if (args.Cancelled || args.Handled || args.Target == null || args.Used == null)
return;
Implant(args.Used.Value, args.Target.Value, component);
Implant(args.User, args.Target.Value, args.Used.Value, component);
args.Handled = true;
}

View File

@@ -5,44 +5,31 @@ using Content.Shared.Cuffs.Components;
using Content.Shared.Implants;
using Content.Shared.Implants.Components;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Mobs;
using Content.Shared.Popups;
using Robust.Shared.Containers;
namespace Content.Server.Implants;
public sealed class SubdermalImplantSystem : SharedSubdermalImplantSystem
{
[Dependency] private readonly CuffableSystem _cuffable = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly StoreSystem _store = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SubdermalImplantComponent, UseFreedomImplantEvent>(OnFreedomImplant);
SubscribeLocalEvent<StoreComponent, AfterInteractUsingEvent>(OnUplinkInteractUsing);
SubscribeLocalEvent<ImplantedComponent, MobStateChangedEvent>(RelayToImplantEvent);
SubscribeLocalEvent<ImplantedComponent, AfterInteractUsingEvent>(RelayToImplantEvent);
SubscribeLocalEvent<ImplantedComponent, SuicideEvent>(RelayToImplantEvent);
SubscribeLocalEvent<StoreComponent, ImplantRelayEvent<AfterInteractUsingEvent>>(OnStoreRelay);
}
private void OnFreedomImplant(EntityUid uid, SubdermalImplantComponent component, UseFreedomImplantEvent args)
private void OnStoreRelay(EntityUid uid, StoreComponent store, ImplantRelayEvent<AfterInteractUsingEvent> implantRelay)
{
if (!TryComp<CuffableComponent>(component.ImplantedEntity, out var cuffs) || cuffs.Container.ContainedEntities.Count < 1)
var args = implantRelay.Event;
if (args.Handled)
return;
_cuffable.Uncuff(component.ImplantedEntity.Value, cuffs.LastAddedCuffs, cuffs.LastAddedCuffs);
args.Handled = true;
}
private void OnUplinkInteractUsing(EntityUid uid, StoreComponent store, AfterInteractUsingEvent args)
{
// can only insert into yourself to prevent uplink checking with renault
if (args.Target != args.User)
return;
@@ -61,46 +48,12 @@ public sealed class SubdermalImplantSystem : SharedSubdermalImplantSystem
QueueDel(args.Used);
}
#region Relays
//Relays from the implanted to the implant
private void RelayToImplantEvent<T>(EntityUid uid, ImplantedComponent component, T args) where T: notnull
private void OnFreedomImplant(EntityUid uid, SubdermalImplantComponent component, UseFreedomImplantEvent args)
{
if (!_container.TryGetContainer(uid, ImplanterComponent.ImplantSlotId, out var implantContainer))
if (!TryComp<CuffableComponent>(component.ImplantedEntity, out var cuffs) || cuffs.Container.ContainedEntities.Count < 1)
return;
foreach (var implant in implantContainer.ContainedEntities)
{
RaiseLocalEvent(implant, args);
}
}
//Relays from the implanted to the implant
private void RelayToImplantEventByRef<T>(EntityUid uid, ImplantedComponent component, ref T args) where T: notnull
{
if (!_container.TryGetContainer(uid, ImplanterComponent.ImplantSlotId, out var implantContainer))
return;
foreach (var implant in implantContainer.ContainedEntities)
{
RaiseLocalEvent(implant,ref args);
}
_cuffable.Uncuff(component.ImplantedEntity.Value, cuffs.LastAddedCuffs, cuffs.LastAddedCuffs);
args.Handled = true;
}
//Relays from the implant to the implanted
private void RelayToImplantedEvent<T>(EntityUid uid, SubdermalImplantComponent component, T args) where T : EntityEventArgs
{
if (component.ImplantedEntity != null)
{
RaiseLocalEvent(component.ImplantedEntity.Value, args);
}
}
private void RelayToImplantedEventByRef<T>(EntityUid uid, SubdermalImplantComponent component, ref T args) where T : EntityEventArgs
{
if (component.ImplantedEntity != null)
{
RaiseLocalEvent(component.ImplantedEntity.Value, ref args);
}
}
#endregion
}

View File

@@ -34,10 +34,18 @@ namespace Content.Server.PDA.Ringer
SubscribeLocalEvent<RingerComponent, RingerPlayRingtoneMessage>(RingerPlayRingtone);
SubscribeLocalEvent<RingerComponent, RingerRequestUpdateInterfaceMessage>(UpdateRingerUserInterfaceDriver);
SubscribeLocalEvent<RingerUplinkComponent, CurrencyInsertAttemptEvent>(OnCurrencyInsert);
}
//Event Functions
private void OnCurrencyInsert(EntityUid uid, RingerUplinkComponent uplink, CurrencyInsertAttemptEvent args)
{
// if the store can be locked, it must be unlocked first before inserting currency. Stops traitor checking.
if (!uplink.Unlocked)
args.Cancel();
}
private void RingerPlayRingtone(EntityUid uid, RingerComponent ringer, RingerPlayRingtoneMessage args)
{
EnsureComp<ActiveRingerComponent>(uid);

View File

@@ -70,12 +70,12 @@ public sealed partial class StoreSystem : EntitySystem
if (args.Handled || !args.CanReach)
return;
if (args.Target == null || !TryComp<StoreComponent>(args.Target, out var store))
if (!TryComp<StoreComponent>(args.Target, out var store))
return;
// if the store can be locked, it must be unlocked first before inserting currency
var user = args.User;
if (TryComp<RingerUplinkComponent>(args.Target, out var uplink) && !uplink.Unlocked)
var ev = new CurrencyInsertAttemptEvent(args.User, args.Target.Value, args.Used, store);
RaiseLocalEvent(args.Target.Value, ev);
if (ev.Cancelled)
return;
args.Handled = TryAddCurrency(GetCurrencyValue(uid, component), args.Target.Value, store);
@@ -189,3 +189,19 @@ public sealed partial class StoreSystem : EntitySystem
}
}
}
public sealed class CurrencyInsertAttemptEvent : CancellableEntityEventArgs
{
public readonly EntityUid User;
public readonly EntityUid Target;
public readonly EntityUid Used;
public readonly StoreComponent Store;
public CurrencyInsertAttemptEvent(EntityUid user, EntityUid target, EntityUid used, StoreComponent store)
{
User = user;
Target = target;
Used = used;
Store = store;
}
}