forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADD: DNA Copy Implant for Uplink (#2601)
* ADD: DNA Copy Implant for Uplink * ready for merge * fix fix commit * fix fix fix commit
- Loading branch information
Showing
19 changed files
with
492 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
Content.Client/SS220/PenScrambler/ClientPenScramblerSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using Content.Shared.SS220.PenScrambler; | ||
using Robust.Client.GameObjects; | ||
|
||
namespace Content.Client.SS220.PenScrambler; | ||
|
||
public sealed class ClientPenScramblerSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly SpriteSystem _sprite = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
SubscribeNetworkEvent<SetScaleFromTargetEvent>(OnSetScaleFromTarget); | ||
} | ||
|
||
public override void Update(float frameTime) | ||
{ | ||
base.Update(frameTime); | ||
|
||
var query = EntityManager.EntityQueryEnumerator<SetScaleFromTargetComponent>(); | ||
|
||
while (query.MoveNext(out var uid, out var comp)) | ||
{ | ||
if (comp is { Target: not null, IsUpdated: false }) | ||
{ | ||
TryUpdateSprite((uid, comp)); | ||
} | ||
} | ||
} | ||
|
||
private void OnSetScaleFromTarget(SetScaleFromTargetEvent args) | ||
{ | ||
var owner = GetEntity(args.Owner); | ||
|
||
if (!TryComp<SetScaleFromTargetComponent>(owner, out var comp)) | ||
return; | ||
|
||
comp.Target = args.Target; | ||
Dirty(owner, comp); | ||
|
||
TryUpdateSprite((owner, comp)); | ||
} | ||
|
||
private void TryUpdateSprite(Entity<SetScaleFromTargetComponent> ent) | ||
{ | ||
if (!ent.Comp.Target.HasValue) | ||
return; | ||
|
||
if (!EntityManager.TryGetEntity(ent.Comp.Target.Value, out var target)) | ||
return; | ||
|
||
if (!TryComp<SpriteComponent>(ent.Owner, out var spriteUser)) | ||
return; | ||
|
||
if (!TryComp<SpriteComponent>(target, out var spriteTarget)) | ||
return; | ||
|
||
spriteUser.Scale = spriteTarget.Scale; | ||
ent.Comp.IsUpdated = true; | ||
|
||
_sprite.QueueUpdateInert(ent.Owner, spriteUser); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
Content.Server/SS220/PenScrambler/PenScramblerComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Content.Shared.Humanoid; | ||
|
||
namespace Content.Server.SS220.PenScrambler; | ||
|
||
[RegisterComponent] | ||
public sealed partial class PenScramblerComponent : Component | ||
{ | ||
[DataField] | ||
public EntityUid? Target; | ||
|
||
[DataField] | ||
public HumanoidAppearanceComponent? AppearanceComponent; | ||
|
||
[DataField] | ||
public bool HaveDna = false; | ||
|
||
public TimeSpan DelayForExtractDna = TimeSpan.FromSeconds(5); | ||
public TimeSpan DelayForTransferToImplant = TimeSpan.FromSeconds(3); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using Content.Shared.DoAfter; | ||
using Content.Shared.Humanoid; | ||
using Content.Shared.Implants.Components; | ||
using Content.Shared.Interaction; | ||
using Content.Shared.Popups; | ||
using Content.Shared.SS220.PenScrambler; | ||
|
||
namespace Content.Server.SS220.PenScrambler; | ||
|
||
public sealed class PenScramblerSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!; | ||
[Dependency] private readonly SharedPopupSystem _popup = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
SubscribeLocalEvent<PenScramblerComponent, AfterInteractEvent>(OnInteract); | ||
SubscribeLocalEvent<PenScramblerComponent, CopyDnaToPenEvent>(OnCopyIdentity); | ||
} | ||
|
||
private void OnInteract(Entity<PenScramblerComponent> ent, ref AfterInteractEvent args) | ||
{ | ||
if (!args.CanReach || args.Target == null) | ||
return; | ||
|
||
if (HasComp<HumanoidAppearanceComponent>(args.Target) && !ent.Comp.HaveDna) | ||
{ | ||
_doAfter.TryStartDoAfter(new DoAfterArgs(EntityManager, | ||
args.User, | ||
ent.Comp.DelayForExtractDna, | ||
new CopyDnaToPenEvent(), | ||
ent.Owner, | ||
args.Target) | ||
{ | ||
Hidden = true, | ||
BreakOnMove = true, | ||
BreakOnDamage = true, | ||
BreakOnHandChange = true, | ||
BreakOnDropItem = true, | ||
DuplicateCondition = DuplicateConditions.None, | ||
}); | ||
} | ||
|
||
if (!TryComp<ImplanterComponent>(args.Target, out var implanterComponent)) | ||
return; | ||
|
||
var implantEntity = implanterComponent.ImplanterSlot.ContainerSlot?.ContainedEntity; | ||
|
||
if (HasComp<TransferIdentityComponent>(implantEntity) && ent.Comp.HaveDna) | ||
{ | ||
_doAfter.TryStartDoAfter(new DoAfterArgs(EntityManager, | ||
args.User, | ||
ent.Comp.DelayForTransferToImplant, | ||
new CopyDnaFromPenToImplantEvent(), | ||
implantEntity, | ||
ent.Owner) | ||
{ | ||
BreakOnMove = true, | ||
BreakOnDamage = true, | ||
BreakOnHandChange = true, | ||
BreakOnDropItem = true, | ||
DuplicateCondition = DuplicateConditions.None, | ||
}); | ||
} | ||
} | ||
|
||
private void OnCopyIdentity(Entity<PenScramblerComponent> ent, ref CopyDnaToPenEvent args) | ||
{ | ||
if (args.Cancelled) | ||
return; | ||
|
||
if (!TryComp<HumanoidAppearanceComponent>(args.Target, out var humanoidAppearanceComponent)) | ||
return; | ||
|
||
ent.Comp.AppearanceComponent = humanoidAppearanceComponent; | ||
ent.Comp.Target = args.Target; | ||
ent.Comp.HaveDna = true; | ||
|
||
_popup.PopupEntity(Loc.GetString("pen-scrambler-success-copy", ("identity", MetaData(args.Target.Value).EntityName)), args.User, args.User); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Content.Server/SS220/PenScrambler/TransferIdentityComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Content.Shared.Humanoid; | ||
|
||
namespace Content.Server.SS220.PenScrambler; | ||
|
||
[RegisterComponent] | ||
public sealed partial class TransferIdentityComponent : Component | ||
{ | ||
[DataField] | ||
public EntityUid? Target; | ||
|
||
[DataField] | ||
public HumanoidAppearanceComponent? AppearanceComponent; | ||
} |
35 changes: 35 additions & 0 deletions
35
Content.Server/SS220/PenScrambler/TransferIdentitySystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Content.Shared.Popups; | ||
using Content.Shared.SS220.PenScrambler; | ||
|
||
namespace Content.Server.SS220.PenScrambler; | ||
|
||
public sealed class TransferIdentitySystem : EntitySystem | ||
{ | ||
[Dependency] private readonly SharedPopupSystem _popup = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
SubscribeLocalEvent<TransferIdentityComponent, CopyDnaFromPenToImplantEvent>(OnCopyIdentityToImplant); | ||
} | ||
|
||
private void OnCopyIdentityToImplant(Entity<TransferIdentityComponent> ent, ref CopyDnaFromPenToImplantEvent args) | ||
{ | ||
if (args.Cancelled || args.Target == null) | ||
return; | ||
|
||
if (!TryComp<PenScramblerComponent>(args.Target, out var penComponent)) | ||
return; | ||
|
||
if (penComponent.Target == null) | ||
return; | ||
|
||
ent.Comp.Target = penComponent.Target.Value; | ||
ent.Comp.AppearanceComponent = penComponent.AppearanceComponent; | ||
|
||
_popup.PopupEntity(Loc.GetString("pen-scrambler-success-transfer-to-implant", | ||
("identity", MetaData(penComponent.Target.Value).EntityName)), args.User, args.User); | ||
|
||
Dirty(ent); | ||
QueueDel(args.Target); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
Content.Shared/SS220/PenScrambler/SetScaleFromTargetComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Numerics; | ||
using Robust.Shared.GameStates; | ||
using Robust.Shared.Serialization; | ||
|
||
namespace Content.Shared.SS220.PenScrambler; | ||
|
||
[RegisterComponent] | ||
[NetworkedComponent] | ||
[AutoGenerateComponentState] | ||
public sealed partial class SetScaleFromTargetComponent : Component | ||
{ | ||
[DataField] | ||
[AutoNetworkedField] | ||
public NetEntity? Target; | ||
|
||
[DataField] | ||
public bool IsUpdated; | ||
} | ||
|
||
[Serializable, NetSerializable] | ||
public sealed class SetScaleFromTargetEvent : EntityEventArgs | ||
{ | ||
public NetEntity Owner { get; } | ||
public NetEntity? Target { get; } | ||
|
||
public SetScaleFromTargetEvent(NetEntity owner, NetEntity? target) | ||
{ | ||
Owner = owner; | ||
Target = target; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Content.Shared/SS220/PenScrambler/SharedPenScramblerEvents.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Content.Shared.DoAfter; | ||
using Robust.Shared.Serialization; | ||
|
||
namespace Content.Shared.SS220.PenScrambler; | ||
|
||
[Serializable] | ||
[NetSerializable] | ||
public sealed partial class CopyDnaToPenEvent : DoAfterEvent | ||
{ | ||
public override DoAfterEvent Clone() => this; | ||
} | ||
|
||
[Serializable] | ||
[NetSerializable] | ||
public sealed partial class CopyDnaFromPenToImplantEvent : DoAfterEvent | ||
{ | ||
public override DoAfterEvent Clone() => this; | ||
} |
Oops, something went wrong.