mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-21 07:28:31 +03:00
## Mirror of PR #26250: [Make all implants unable to be implanted more than once](https://github.com/space-wizards/space-station-14/pull/26250) from <img src="https://avatars.githubusercontent.com/u/10567778?v=4" alt="space-wizards" width="22"/> [space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14) ###### `771390bb6741074935e5f24c0aa9c87bc7b5ad09` PR opened by <img src="https://avatars.githubusercontent.com/u/63975668?v=4" width="16"/><a href="https://github.com/Simyon264"> Simyon264</a> at 2024-03-19 00:44:21 UTC - merged at 2024-03-26 00:16:19 UTC --- PR changed 3 files with 28 additions and 0 deletions. The PR had the following labels: - Status: Needs Review --- <details open="true"><summary><h1>Original Body</h1></summary> > <!-- Please read these guidelines before opening your PR: https://docs.spacestation14.io/en/getting-started/pr-guideline --> > <!-- The text between the arrows are comments - they will not be visible on your PR. --> > > ## About the PR > This PR makes mind shields unable to be implanted more than once. > ## Why / Balance > <!-- Why was it changed? Link any discussions or issues here. Please discuss how this would affect game balance. --> > PJB complained and people waste implants by injecting already injected people. > > ## Technical details > <!-- If this is a code change, summarize at high level how your new code works. This makes it easier to review. --> > Adds a new datafield to the Implanter component which is checked in implanter system. > > ## Media > <!-- > PRs which make ingame changes (adding clothing, items, new features, etc) are required to have media attached that showcase the changes. > Small fixes/refactors are exempt. > Any media may be used in SS14 progress reports, with clear credit given. > > If you're unsure whether your PR will require media, ask a maintainer. > > Check the box below to confirm that you have in fact seen this (put an X in the brackets, like [X]): > --> >  > > - [x] I have added screenshots/videos to this PR showcasing its changes ingame, **or** this PR does not require an ingame showcase > > ## Breaking changes > <!-- > List any breaking changes, including namespace, public class/method/field changes, prototype renames; and provide instructions for fixing them. This will be pasted in #codebase-changes. > --> > N/A > > **Changelog** > <!-- > Make players aware of new features and changes that could affect how they play the game by adding a Changelog entry. Please read the Changelog guidelines located at: https://docs.spacestation14.io/en/getting-started/pr-guideline#changelog > --> > > 🆑 Simyon > - tweak: All implants are now unable to be implanted more than once. > </details> Co-authored-by: SimpleStation14 <Unknown>
160 lines
6.0 KiB
C#
160 lines
6.0 KiB
C#
using System.Linq;
|
|
using Content.Server.Popups;
|
|
using Content.Shared.DoAfter;
|
|
using Content.Shared.IdentityManagement;
|
|
using Content.Shared.Implants;
|
|
using Content.Shared.Implants.Components;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Popups;
|
|
using Robust.Shared.Containers;
|
|
|
|
namespace Content.Server.Implants;
|
|
|
|
public sealed partial class ImplanterSystem : SharedImplanterSystem
|
|
{
|
|
[Dependency] private readonly PopupSystem _popup = default!;
|
|
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
|
|
[Dependency] private readonly SharedContainerSystem _container = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
InitializeImplanted();
|
|
|
|
SubscribeLocalEvent<ImplanterComponent, AfterInteractEvent>(OnImplanterAfterInteract);
|
|
|
|
SubscribeLocalEvent<ImplanterComponent, ImplantEvent>(OnImplant);
|
|
SubscribeLocalEvent<ImplanterComponent, DrawEvent>(OnDraw);
|
|
}
|
|
|
|
private void OnImplanterAfterInteract(EntityUid uid, ImplanterComponent component, AfterInteractEvent args)
|
|
{
|
|
if (args.Target == null || !args.CanReach || args.Handled)
|
|
return;
|
|
|
|
var target = args.Target.Value;
|
|
if (!CheckTarget(target, component.Whitelist, component.Blacklist))
|
|
return;
|
|
|
|
//TODO: Rework when surgery is in for implant cases
|
|
if (component.CurrentMode == ImplanterToggleMode.Draw && !component.ImplantOnly)
|
|
{
|
|
TryDraw(component, args.User, target, uid);
|
|
}
|
|
else
|
|
{
|
|
if (!CanImplant(args.User, target, uid, component, out var implant, out _))
|
|
{
|
|
// no popup if implant doesn't exist
|
|
if (implant == null)
|
|
return;
|
|
|
|
// show popup to the user saying implant failed
|
|
var name = Identity.Name(target, EntityManager, args.User);
|
|
var msg = Loc.GetString("implanter-component-implant-failed", ("implant", implant), ("target", name));
|
|
_popup.PopupEntity(msg, target, args.User);
|
|
// prevent further interaction since popup was shown
|
|
args.Handled = true;
|
|
return;
|
|
}
|
|
|
|
// Check if we are trying to implant a implant which is already implanted
|
|
if (implant.HasValue && !component.AllowMultipleImplants && CheckSameImplant(target, implant.Value))
|
|
{
|
|
var name = Identity.Name(target, EntityManager, args.User);
|
|
var msg = Loc.GetString("implanter-component-implant-already", ("implant", implant), ("target", name));
|
|
_popup.PopupEntity(msg, target, args.User);
|
|
args.Handled = true;
|
|
return;
|
|
}
|
|
|
|
|
|
//Implant self instantly, otherwise try to inject the target.
|
|
if (args.User == target)
|
|
Implant(target, target, uid, component);
|
|
else
|
|
TryImplant(component, args.User, target, uid);
|
|
}
|
|
|
|
args.Handled = true;
|
|
}
|
|
|
|
public bool CheckSameImplant(EntityUid target, EntityUid implant)
|
|
{
|
|
if (!TryComp<ImplantedComponent>(target, out var implanted))
|
|
return false;
|
|
|
|
var implantPrototype = Prototype(implant);
|
|
return implanted.ImplantContainer.ContainedEntities.Any(entity => Prototype(entity) == implantPrototype);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attempt to implant someone else.
|
|
/// </summary>
|
|
/// <param name="component">Implanter component</param>
|
|
/// <param name="user">The entity using the implanter</param>
|
|
/// <param name="target">The entity being implanted</param>
|
|
/// <param name="implanter">The implanter being used</param>
|
|
public void TryImplant(ImplanterComponent component, EntityUid user, EntityUid target, EntityUid implanter)
|
|
{
|
|
var args = new DoAfterArgs(EntityManager, user, component.ImplantTime, new ImplantEvent(), implanter, target: target, used: implanter)
|
|
{
|
|
BreakOnUserMove = true,
|
|
BreakOnTargetMove = true,
|
|
BreakOnDamage = true,
|
|
NeedHand = true,
|
|
};
|
|
|
|
if (!_doAfter.TryStartDoAfter(args))
|
|
return;
|
|
|
|
_popup.PopupEntity(Loc.GetString("injector-component-injecting-user"), target, user);
|
|
|
|
var userName = Identity.Entity(user, EntityManager);
|
|
_popup.PopupEntity(Loc.GetString("implanter-component-implanting-target", ("user", userName)), user, target, PopupType.LargeCaution);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Try to remove an implant and store it in an implanter
|
|
/// </summary>
|
|
/// <param name="component">Implanter component</param>
|
|
/// <param name="user">The entity using the implanter</param>
|
|
/// <param name="target">The entity getting their implant removed</param>
|
|
/// <param name="implanter">The implanter being used</param>
|
|
//TODO: Remove when surgery is in
|
|
public void TryDraw(ImplanterComponent component, EntityUid user, EntityUid target, EntityUid implanter)
|
|
{
|
|
var args = new DoAfterArgs(EntityManager, user, component.DrawTime, new DrawEvent(), implanter, target: target, used: implanter)
|
|
{
|
|
BreakOnUserMove = true,
|
|
BreakOnTargetMove = true,
|
|
BreakOnDamage = true,
|
|
NeedHand = true,
|
|
};
|
|
|
|
if (_doAfter.TryStartDoAfter(args))
|
|
_popup.PopupEntity(Loc.GetString("injector-component-injecting-user"), target, user);
|
|
|
|
}
|
|
|
|
private void OnImplant(EntityUid uid, ImplanterComponent component, ImplantEvent args)
|
|
{
|
|
if (args.Cancelled || args.Handled || args.Target == null || args.Used == null)
|
|
return;
|
|
|
|
Implant(args.User, args.Target.Value, args.Used.Value, component);
|
|
|
|
args.Handled = true;
|
|
}
|
|
|
|
private void OnDraw(EntityUid uid, ImplanterComponent component, DrawEvent args)
|
|
{
|
|
if (args.Cancelled || args.Handled || args.Used == null || args.Target == null)
|
|
return;
|
|
|
|
Draw(args.Used.Value, args.User, args.Target.Value, component);
|
|
|
|
args.Handled = true;
|
|
}
|
|
}
|