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

Cloning Refactor #735

Merged
merged 34 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b8952ec
Cloning Refactor
VMSolidus Aug 15, 2024
206d51a
Update CloningSystem.cs
VMSolidus Aug 15, 2024
3057750
Migrate Metem out of Nyano
VMSolidus Aug 15, 2024
f01d950
Update CloningSystem.cs
VMSolidus Aug 15, 2024
b22b1b8
GO
VMSolidus Aug 15, 2024
ece2b0a
Update meta.json
VMSolidus Aug 15, 2024
2e80c82
Update meta.json
VMSolidus Aug 15, 2024
728107d
Last update I swear
VMSolidus Aug 15, 2024
218c593
Update CCVars.cs
VMSolidus Aug 15, 2024
fbc8c53
Update CloningSystem.cs
VMSolidus Aug 15, 2024
89080c1
Metem Machine Biomass Discount
VMSolidus Aug 15, 2024
37243b4
Genetic damage to clone scales with genetic damage to original.
VMSolidus Aug 15, 2024
463edb7
Update CloningSystem.cs
VMSolidus Aug 15, 2024
e669b0f
Wall of CCVars.
VMSolidus Aug 15, 2024
ab6b49c
now correctly modifies gender if configured to do so.
VMSolidus Aug 15, 2024
0e76d9a
Update Content.Server/Medical/BiomassReclaimer/BiomassReclaimerSystem.cs
VMSolidus Aug 15, 2024
5f40c86
Update BiomassReclaimerSystem.cs
VMSolidus Aug 15, 2024
9ed6f79
Apply suggestions from code review
VMSolidus Aug 15, 2024
0a688d8
Apply suggestions from code review
VMSolidus Aug 18, 2024
8127adf
Last updates per Feedback
VMSolidus Aug 18, 2024
675da4c
Refactor Uncloneable
VMSolidus Aug 18, 2024
fdbcf14
Rename the dumb states to things more sensible
VMSolidus Aug 18, 2024
05b18c6
Update experimental.yml
VMSolidus Aug 18, 2024
b6c06ef
Update UncloneableSystem.cs
VMSolidus Aug 18, 2024
2181bfb
Merge branch 'master' into Cloning-Code-Cleanup
VMSolidus Aug 20, 2024
9c60e01
Update CloningSystem.cs
VMSolidus Aug 30, 2024
e962955
Update CloningSystem.cs
VMSolidus Aug 30, 2024
7d17cb5
Update CloningSystem.cs
VMSolidus Aug 30, 2024
1c78ad5
Update cloning system further
VMSolidus Aug 30, 2024
c9b4924
Unhardcode crit threshold
VMSolidus Aug 30, 2024
a6687d6
Update CloningSystem.cs
VMSolidus Aug 30, 2024
0cad6d2
Split Cloning System into Utility
VMSolidus Sep 1, 2024
a5aabbb
Apply suggestions from code review
VMSolidus Sep 1, 2024
de49b2b
Bunch of fixes
VMSolidus Sep 2, 2024
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

This file was deleted.

90 changes: 44 additions & 46 deletions Content.Server/Cloning/CloningConsoleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public sealed class CloningConsoleSystem : EntitySystem
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
[Dependency] private readonly PowerReceiverSystem _powerReceiverSystem = default!;
[Dependency] private readonly SharedMindSystem _mindSystem = default!;

public override void Initialize()
{
base.Initialize();
Expand All @@ -52,14 +52,16 @@ private void OnInit(EntityUid uid, CloningConsoleComponent component, ComponentI
}
private void OnButtonPressed(EntityUid uid, CloningConsoleComponent consoleComponent, UiButtonPressedMessage args)
{
if (!_powerReceiverSystem.IsPowered(uid))
if (!_powerReceiverSystem.IsPowered(uid)
|| consoleComponent.GeneticScanner is null
|| consoleComponent.CloningPod is null
|| !TryComp<CloningPodComponent>(consoleComponent.CloningPod.Value, out var cloningPod))
return;

switch (args.Button)
{
case UiButton.Clone:
if (consoleComponent.GeneticScanner != null && consoleComponent.CloningPod != null)
TryClone(uid, consoleComponent.CloningPod.Value, consoleComponent.GeneticScanner.Value, consoleComponent: consoleComponent);
TryClone(uid, consoleComponent.CloningPod.Value, consoleComponent.GeneticScanner.Value, cloningPod, consoleComponent: consoleComponent);
break;
}
UpdateUserInterface(uid, consoleComponent);
Expand Down Expand Up @@ -93,13 +95,15 @@ private void OnMapInit(EntityUid uid, CloningConsoleComponent component, MapInit

private void OnNewLink(EntityUid uid, CloningConsoleComponent component, NewLinkEvent args)
{
if (TryComp<MedicalScannerComponent>(args.Sink, out var scanner) && args.SourcePort == CloningConsoleComponent.ScannerPort)
if (TryComp<MedicalScannerComponent>(args.Sink, out var scanner)
&& args.SourcePort == CloningConsoleComponent.ScannerPort)
{
component.GeneticScanner = args.Sink;
scanner.ConnectedConsole = uid;
}

if (TryComp<CloningPodComponent>(args.Sink, out var pod) && args.SourcePort == CloningConsoleComponent.PodPort)
if (TryComp<CloningPodComponent>(args.Sink, out var pod)
&& args.SourcePort == CloningConsoleComponent.PodPort)
{
component.CloningPod = args.Sink;
pod.ConnectedConsole = uid;
Expand All @@ -125,11 +129,10 @@ private void OnUIOpen(EntityUid uid, CloningConsoleComponent component, AfterAct

private void OnAnchorChanged(EntityUid uid, CloningConsoleComponent component, ref AnchorStateChangedEvent args)
{
if (args.Anchored)
{
RecheckConnections(uid, component.CloningPod, component.GeneticScanner, component);
if (!args.Anchored
|| !RecheckConnections(uid, component.CloningPod, component.GeneticScanner, component))
return;
}

UpdateUserInterface(uid, component);
}

Expand All @@ -148,49 +151,52 @@ public void UpdateUserInterface(EntityUid consoleUid, CloningConsoleComponent co
_uiSystem.SetUiState(ui, newState);
}

public void TryClone(EntityUid uid, EntityUid cloningPodUid, EntityUid scannerUid, CloningPodComponent? cloningPod = null, MedicalScannerComponent? scannerComp = null, CloningConsoleComponent? consoleComponent = null)
public void TryClone(EntityUid uid, EntityUid cloningPodUid, EntityUid scannerUid, CloningPodComponent cloningPod, MedicalScannerComponent? scannerComp = null, CloningConsoleComponent? consoleComponent = null)
DEATHB4DEFEAT marked this conversation as resolved.
Show resolved Hide resolved
{
if (!Resolve(uid, ref consoleComponent) || !Resolve(cloningPodUid, ref cloningPod) || !Resolve(scannerUid, ref scannerComp))
return;

if (!Transform(cloningPodUid).Anchored || !Transform(scannerUid).Anchored)
return;

if (!consoleComponent.CloningPodInRange || !consoleComponent.GeneticScannerInRange)
if (!Resolve(uid, ref consoleComponent)
|| !Resolve(scannerUid, ref scannerComp)
VMSolidus marked this conversation as resolved.
Show resolved Hide resolved
|| !Transform(cloningPodUid).Anchored
|| !Transform(scannerUid).Anchored
|| !consoleComponent.CloningPodInRange
|| !consoleComponent.GeneticScannerInRange)
return;

var body = scannerComp.BodyContainer.ContainedEntity;

if (body is null)
if (body is null
|| !_mindSystem.TryGetMind(body.Value, out var mindId, out var mind)
|| mind.UserId.HasValue == false
|| mind.Session == null)
return;

if (!_mindSystem.TryGetMind(body.Value, out var mindId, out var mind))
return;

if (mind.UserId.HasValue == false || mind.Session == null)
return;
// Nyano: Adds scannerComp.MetemKarmaBonus
if (_cloningSystem.TryCloning(cloningPodUid, body.Value, (mindId, mind), cloningPod, scannerComp.CloningFailChanceMultiplier, scannerComp.MetemKarmaBonus))
_adminLogger.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(uid)} successfully cloned {ToPrettyString(body.Value)}.");
if (_cloningSystem.TryCloning(cloningPodUid, body.Value, (mindId, mind), cloningPod, scannerComp.CloningFailChanceMultiplier))
{
_adminLogger.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(uid)} started cloning {ToPrettyString(body.Value)}.");
_cloningSystem.AttemptCloning(cloningPodUid, cloningPod);
}
}

public void RecheckConnections(EntityUid console, EntityUid? cloningPod, EntityUid? scanner, CloningConsoleComponent? consoleComp = null)
public bool RecheckConnections(EntityUid console, EntityUid? cloningPod, EntityUid? scanner, CloningConsoleComponent? consoleComp = null)
{
if (!Resolve(console, ref consoleComp))
return;
return false;

var connected = true;
if (scanner != null)
{
Transform(scanner.Value).Coordinates.TryDistance(EntityManager, Transform((console)).Coordinates, out float scannerDistance);
Transform(scanner.Value).Coordinates.TryDistance(EntityManager, Transform(console).Coordinates, out float scannerDistance);
consoleComp.GeneticScannerInRange = scannerDistance <= consoleComp.MaxDistance;
connected = false;
}
if (cloningPod != null)
{
Transform(cloningPod.Value).Coordinates.TryDistance(EntityManager, Transform((console)).Coordinates, out float podDistance);
Transform(cloningPod.Value).Coordinates.TryDistance(EntityManager, Transform(console).Coordinates, out float podDistance);
consoleComp.CloningPodInRange = podDistance <= consoleComp.MaxDistance;
connected = false;
}

UpdateUserInterface(console, consoleComp);
return connected;
}
private CloningConsoleBoundUserInterfaceState GetUserInterfaceState(CloningConsoleComponent consoleComponent)
{
Expand All @@ -206,25 +212,19 @@ private CloningConsoleBoundUserInterfaceState GetUserInterfaceState(CloningConso
EntityUid? scanBody = scanner.BodyContainer.ContainedEntity;

// GET STATE
if (scanBody == null || !HasComp<MobStateComponent>(scanBody))
if (scanBody == null
|| !HasComp<MobStateComponent>(scanBody))
clonerStatus = ClonerStatus.ScannerEmpty;
else
{
scanBodyInfo = MetaData(scanBody.Value).EntityName;

if (!_mobStateSystem.IsDead(scanBody.Value))
{
clonerStatus = ClonerStatus.ScannerOccupantAlive;
}
else
{
if (!_mindSystem.TryGetMind(scanBody.Value, out _, out var mind) ||
mind.UserId == null ||
!_playerManager.TryGetSessionById(mind.UserId.Value, out _))
{
clonerStatus = ClonerStatus.NoMindDetected;
}
}
else if (!_mindSystem.TryGetMind(scanBody.Value, out _, out var mind)
|| mind.UserId == null
|| !_playerManager.TryGetSessionById(mind.UserId.Value, out _))
clonerStatus = ClonerStatus.NoMindDetected;
}
}

Expand All @@ -240,17 +240,15 @@ private CloningConsoleBoundUserInterfaceState GetUserInterfaceState(CloningConso
EntityUid? cloneBody = clonePod.BodyContainer.ContainedEntity;

clonerMindPresent = clonePod.Status == CloningPodStatus.Cloning;
if (HasComp<ActiveCloningPodComponent>(consoleComponent.CloningPod))
if (clonePod.ActivelyCloning)
{
if (cloneBody != null)
cloneBodyInfo = Identity.Name(cloneBody.Value, EntityManager);
clonerStatus = ClonerStatus.ClonerOccupied;
}
}
else
{
clonerStatus = ClonerStatus.NoClonerDetected;
}

return new CloningConsoleBoundUserInterfaceState(
scanBodyInfo,
Expand Down
Loading
Loading