forked from Goob-Station/Goob-Station
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Medical Patches (Goob-Station#452)
* 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 <[email protected]> Co-authored-by: Fishbait <[email protected]>
- Loading branch information
1 parent
72f08cb
commit e40a34c
Showing
32 changed files
with
539 additions
and
1 deletion.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
Content.Server/Goobstation/MedicalPatch/MedicalPatchComponent.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,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
138
Content.Server/Goobstation/MedicalPatch/MedicalPatchSystem.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,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); | ||
} | ||
} | ||
} |
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
2 changes: 2 additions & 0 deletions
2
Resources/Locale/en-US/Goobstation/medical-patch/medical-patch.ftl
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,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 |
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
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
10 changes: 10 additions & 0 deletions
10
Resources/Prototypes/Goobstation/Catalog/Bounties/bounties.yml
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,10 @@ | ||
- type: cargoBounty | ||
id: BountyMedicalPatch | ||
reward: 4000 | ||
description: goobstation-medicalpatch-bounty-desc | ||
entries: | ||
- name: goobstation-medicalpatch-bounty-name | ||
amount: 5 | ||
whitelist: | ||
tags: | ||
- MedicalPatch |
Oops, something went wrong.