Skip to content

Commit

Permalink
removed redundant implant check
Browse files Browse the repository at this point in the history
  • Loading branch information
Errant-4 committed Sep 19, 2024
1 parent 81738b6 commit 67cafab
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
18 changes: 5 additions & 13 deletions Content.Server/Traitor/Uplink/UplinkSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void SetUplink(EntityUid user, EntityUid uplink, FixedPoint2 balance, bo
/// </summary>
private bool ImplantUplink(EntityUid user, FixedPoint2 balance, bool giveDiscounts)
{
var implants = new List<string>(){FallbackUplinkImplant};
var implantProto = new string(FallbackUplinkImplant);

if (!_proto.TryIndex<ListingPrototype>(FallbackUplinkCatalog, out var catalog))
return false;
Expand All @@ -99,21 +99,13 @@ private bool ImplantUplink(EntityUid user, FixedPoint2 balance, bool giveDiscoun
else
balance = balance - cost;

_subdermalImplant.AddImplants(user, implants);
var implant = _subdermalImplant.AddImplant(user, implantProto);

if (!_container.TryGetContainer(user, ImplanterComponent.ImplantSlotId, out var implantContainer))
if (!HasComp<StoreComponent>(implant))
return false;

foreach (var implant in implantContainer.ContainedEntities)
{
if (HasComp<StoreComponent>(implant))
{
SetUplink(user, implant, balance, giveDiscounts);
return true;
}
}

return false;
SetUplink(user, implant.Value, balance, giveDiscounts);
return true;
}

/// <summary>
Expand Down
43 changes: 32 additions & 11 deletions Content.Shared/Implants/SharedSubdermalImplantSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,43 @@ private void OnRemove(EntityUid uid, SubdermalImplantComponent component, EntGot
/// </summary>
public void AddImplants(EntityUid uid, IEnumerable<String> implants)
{
var coords = Transform(uid).Coordinates;
foreach (var id in implants)
{
var ent = Spawn(id, coords);
if (TryComp<SubdermalImplantComponent>(ent, out var implant))
{
ForceImplant(uid, ent, implant);
}
else
{
Log.Warning($"Found invalid starting implant '{id}' on {uid} {ToPrettyString(uid):implanted}");
Del(ent);
}
AddImplantDo(uid, id);
}
}

/// <summary>
/// Adds a single implant to a person, and returns the implant.
/// Logs any implant ids that don't have <see cref="SubdermalImplantComponent"/>.
/// </summary>
/// <returns>
/// The implant, if it was successfully created. Otherwise, null.
/// </returns>>
public EntityUid? AddImplant(EntityUid uid, String implantId)
{
return AddImplantDo(uid, implantId);
}

private EntityUid? AddImplantDo(EntityUid uid, String implantId)
{
var coords = Transform(uid).Coordinates;
var ent = Spawn(implantId, coords);

if (TryComp<SubdermalImplantComponent>(ent, out var implant))
{
ForceImplant(uid, ent, implant);
}
else
{
Log.Warning($"Found invalid starting implant '{implantId}' on {uid} {ToPrettyString(uid):implanted}");
Del(ent);
return null;
}

return ent;
}

/// <summary>
/// Forces an implant into a person
/// Good for on spawn related code or admin additions
Expand Down

0 comments on commit 67cafab

Please sign in to comment.