Skip to content

Commit

Permalink
Added Medical Patches (Goob-Station#452)
Browse files Browse the repository at this point in the history
* init

* commit

* typo's

* component summary and changed patch white list

* fixed the used medical patch

* sprites and cleanups

* added prefilled and added to nanomed

* moved prefilled patches to own file

* new patch sprite and working chem level indicator

* base change, sprite border

* popup changes

* added Tag and a Bounty

* better border sprite

* added localisation, bounties shud work now

* New Sprite for Prefilled

* new sprites for makeshift and used

* commit

* commit

* removed unused sprites

* unused sprite was still in use.

* final commit

---------

Co-authored-by: unknown <Administrator@DESKTOP-PMRIVVA.kommune.indresogn.no>
Co-authored-by: Fishbait <Fishbait@git.ml>
  • Loading branch information
3 people authored Aug 10, 2024
1 parent 72f08cb commit e40a34c
Show file tree
Hide file tree
Showing 32 changed files with 539 additions and 1 deletion.
42 changes: 42 additions & 0 deletions Content.Server/Goobstation/MedicalPatch/MedicalPatchComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Content.Shared.FixedPoint;

namespace Content.Server.Medical.Components;

[RegisterComponent]
public sealed partial class MedicalPatchComponent : Component
{
[DataField]
public string SolutionName = "drink";
[DataField]
public FixedPoint2 TransferAmount = FixedPoint2.New(1);
/// <summary>
/// if this is a single use patch, gets destroyed or replaced when empty or removed.
/// </summary>
[DataField]
public bool SingleUse = false;
/// <summary>
/// if single use what the Entity shud be replaced whit
/// </summary>
[DataField]
public string? TrashObject = "UsedMedicalPatch";
/// <summary>
/// how often the patch shud transfer sulution
/// </summary>
[DataField]
public float UpdateTime = 1f;

[DataField]
public TimeSpan NextUpdate = TimeSpan.Zero;
/// <summary>
/// if any set ammount shud be transfered when the patch is attatched,
/// </summary>
[DataField]
public FixedPoint2 InjectAmmountOnAttatch = FixedPoint2.New(0);
/// <summary>
/// if a Percentage of the remaining soulution shud be transfered when attatched, use 0 - 100
/// </summary>
[DataField]
public FixedPoint2 InjectPercentageOnAttatch = FixedPoint2.New(0);
}


138 changes: 138 additions & 0 deletions Content.Server/Goobstation/MedicalPatch/MedicalPatchSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
using Content.Shared.Administration.Logs;
using Content.Server.Medical.Components;
using Content.Server.Popups;
using Content.Shared.FixedPoint;
using Content.Server.Sticky.Systems;
using Content.Server.Sticky.Events;
using Content.Server.Sticky.Components;
using Robust.Shared.Timing;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Chemistry;
using Content.Server.Polymorph.Systems;
using Content.Shared.Database;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;

namespace Content.Server.Medical;

public sealed class MedicalPatchSystem : EntitySystem
{
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly StickySystem _stickySystem = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly SharedSolutionContainerSystem _solutionContainers = default!;
[Dependency] private readonly ReactiveSystem _reactiveSystem = default!;
[Dependency] private readonly PolymorphSystem _polymorph = default!;
[Dependency] protected readonly ISharedAdminLogManager _adminLogger = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MedicalPatchComponent, EntityUnstuckEvent>(OnUnstuck);
SubscribeLocalEvent<MedicalPatchComponent, EntityStuckEvent>(OnStuck);
}
public override void Update(float frameTime)
{
base.Update(frameTime);

if (!_timing.IsFirstTimePredicted)
return;

foreach (var comp in EntityManager.EntityQuery<MedicalPatchComponent>())
{
if (_timing.CurTime < comp.NextUpdate)
continue;
var uid = comp.Owner; // TODO update thsi to the

if (!TryComp<StickyComponent>(uid, out var stickycomp))
continue;
if (stickycomp.StuckTo == null)
continue;
comp.NextUpdate = _timing.CurTime + TimeSpan.FromSeconds(comp.UpdateTime);

Cycle(uid, comp);
}
}
public void Cycle(EntityUid uid, MedicalPatchComponent component)
{
if (!TryInject(uid, component, component.TransferAmount))
{
_stickySystem.UnstickFromEntity(uid, uid);
}
}
public bool TryInject(EntityUid uid, MedicalPatchComponent component, FixedPoint2 transferAmount)
{
if (!TryComp<StickyComponent>(uid, out var stickycomp))
return false;

if (stickycomp.StuckTo == null)
return false;
var target = (EntityUid) stickycomp.StuckTo;

if (!_solutionContainers.TryGetSolution(uid, component.SolutionName, out var medicalPatchSoln, out var medicalPatchSolution) || medicalPatchSolution.Volume == 0)
{
//Solution Empty
return false;
}
if (!_solutionContainers.TryGetInjectableSolution(target, out var targetSoln, out var targetSolution))
{
//_popupSystem.PopupEntity(Loc.GetString("Medical Patch cant find a bloodsystem"), target);
return false;
}
var realTransferAmount = FixedPoint2.Min(transferAmount, targetSolution.AvailableVolume);
if (realTransferAmount <= 0)
{
_popupSystem.PopupEntity(Loc.GetString("No room to inject"), target);
return true;
}
var removedSolution = _solutionContainers.SplitSolution(medicalPatchSoln.Value, realTransferAmount);
if (!targetSolution.CanAddSolution(removedSolution))
return true;
_reactiveSystem.DoEntityReaction(target, removedSolution, ReactionMethod.Injection);
_solutionContainers.TryAddSolution(targetSoln.Value, removedSolution);
return true;
}
public void OnStuck(EntityUid uid, MedicalPatchComponent component, EntityStuckEvent args)
{
if (!_solutionContainers.TryGetSolution(uid, component.SolutionName, out var medicalPatchSoln, out var medicalPatchSolution))
return;

//Logg the Patch stick to.
_adminLogger.Add(LogType.ForceFeed, $"{EntityManager.ToPrettyString(args.User):user} stuck a patch on {EntityManager.ToPrettyString(args.Target):target} using {EntityManager.ToPrettyString(uid):using} containing {SharedSolutionContainerSystem.ToPrettyString(medicalPatchSolution):medicalPatchSolution}");

if (component.InjectAmmountOnAttatch > 0)
{
if (!TryInject(uid, component, component.InjectAmmountOnAttatch))
return;
}
if (component.InjectPercentageOnAttatch > 0)
{
if (medicalPatchSolution.Volume == 0)
return;
if (!TryInject(uid, component, medicalPatchSolution.Volume * (component.InjectPercentageOnAttatch / 100)))
return;
}
}
public void OnUnstuck(EntityUid uid, MedicalPatchComponent component, EntityUnstuckEvent args)
{
if (component.SingleUse)
{
if (component.TrashObject!=null)
{
var coordinates = Transform(uid).Coordinates;
var finisher = Spawn(component.TrashObject, coordinates);
// If the user is holding the item
if (_hands.IsHolding(args.User, uid, out var hand))
{
Del(uid);

// Put the Medicalpatch in the user's hand
_hands.TryPickup(args.User, finisher, hand);
return;
}
}
QueueDel(uid);
}
}
}
5 changes: 4 additions & 1 deletion Content.Server/Sticky/Systems/StickySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Content.Shared.Whitelist;
using Robust.Shared.Containers;
using Robust.Shared.Utility;
using Content.Shared.Interaction.Components;

namespace Content.Server.Sticky.Systems;

Expand Down Expand Up @@ -187,7 +188,7 @@ public void StickToEntity(EntityUid uid, EntityUid target, EntityUid user, Stick
{
_appearance.SetData(uid, StickyVisuals.IsStuck, true, appearance);
}

EnsureComp<UnremoveableComponent>(uid); //Goobstation - MedicalPatch
component.StuckTo = target;
RaiseLocalEvent(uid, new EntityStuckEvent(target, user), true);
}
Expand All @@ -205,6 +206,8 @@ public void UnstickFromEntity(EntityUid uid, EntityUid user, StickyComponent? co
if (attemptEv.Cancelled)
return;

RemComp<UnremoveableComponent>(uid); //Goobstation - MedicalPatch

// try to remove sticky item from target container
if (!_containerSystem.TryGetContainer(stuckTo, StickerSlotId, out var container) || !_containerSystem.Remove(uid, container))
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
goobstation-medicalpatch-bounty-desc = There is a medical emergency going on. Send some patches to help us out over here
goobstation-medicalpatch-bounty-name = Medical Patches
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
Syringe: 5
ClothingEyesHudMedical: 2
ClothingEyesEyepatchHudMedical: 2
MedicalPatchPrefilledBicaridine: 3 #Goobstation - MedicalPatches
MedicalPatchPrefilledDermaline: 3 #Goobstation - MedicalPatches

3 changes: 3 additions & 0 deletions Resources/Prototypes/Entities/Structures/Machines/lathe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,9 @@
- Hemostat
- ClothingEyesGlassesChemical
- WhiteCane
- MedicalPatchBasic #Goobstation - MedicalPatch
- MedicalPatchRapid #Goobstation - MedicalPatch
- MedicalPatchLarge #Goobstation - MedicalPatch
dynamicRecipes:
- ChemicalPayload
- CryostasisBeaker
Expand Down
10 changes: 10 additions & 0 deletions Resources/Prototypes/Goobstation/Catalog/Bounties/bounties.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- type: cargoBounty
id: BountyMedicalPatch
reward: 4000
description: goobstation-medicalpatch-bounty-desc
entries:
- name: goobstation-medicalpatch-bounty-name
amount: 5
whitelist:
tags:
- MedicalPatch
Loading

0 comments on commit e40a34c

Please sign in to comment.