Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/ISSUE_TEMPLATE/config.yml
#	.github/ISSUE_TEMPLATE/feature_request.md
#	.github/ISSUE_TEMPLATE/issue_report.md
  • Loading branch information
Evgencheg committed Sep 2, 2024
2 parents 56bcb2b + 7c83878 commit c3163d1
Show file tree
Hide file tree
Showing 37 changed files with 1,158 additions and 760 deletions.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task DeleteAllThenGhost()
Console.WriteLine(pair.Client.EntMan.ToPrettyString(ent));
}

Assert.That(pair.Client.EntMan.EntityCount, Is.EqualTo(0));
Assert.That(pair.Client.EntMan.EntityCount, Is.AtMost(1)); // Tolerate at most one client entity

// Create a new map.
int mapId = 1;
Expand Down

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)
{
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)
|| !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

0 comments on commit c3163d1

Please sign in to comment.