Skip to content

Commit

Permalink
Add initial implementation of combat hypospray mechanics
Browse files Browse the repository at this point in the history
  • Loading branch information
BarryNorfolk committed Jan 11, 2025
1 parent 1a2fda6 commit e15ca6b
Show file tree
Hide file tree
Showing 12 changed files with 237 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Tag;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;

namespace Content.Shared._DV.Chemistry.SolutionCartridge;

[RegisterComponent, NetworkedComponent]
public sealed partial class SolutionCartridgeReceiverComponent : Component
{
public const string CartridgeSlotId = "cartridge-slot";

[DataField("cartridgeSlot")]
public ItemSlot CartridgeSlot = new();

[DataField]
public string HypospraySolution = "hypospray";

[DataField]
public string CartridgeSolution = "cartridge";

[DataField]
public SoundSpecifier InsertSound = new SoundPathSpecifier("/Audio/Weapons/Guns/MagIn/revolver_magin.ogg");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using Content.Shared.Chemistry.Components.SolutionManager;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Containers.ItemSlots;
using Robust.Shared.Containers;

namespace Content.Shared._DV.Chemistry.SolutionCartridge;

public sealed class SolutionCartridgeReceiverSystem : EntitySystem
{
[Dependency] private readonly SharedSolutionContainerSystem _container = default!;

[Dependency] private readonly SharedAppearanceSystem _appearance = default!; // TODO: Use this

[Dependency] private readonly ItemSlotsSystem _itemSlots = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<SolutionCartridgeReceiverComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<SolutionCartridgeReceiverComponent, ComponentRemove>(OnComponentRemove);

SubscribeLocalEvent<SolutionCartridgeReceiverComponent, EntInsertedIntoContainerMessage>(OnItemInserted);
SubscribeLocalEvent<SolutionCartridgeReceiverComponent, EntRemovedFromContainerMessage>(OnItemRemoved);
}

private void OnComponentInit(EntityUid uid, SolutionCartridgeReceiverComponent receiver, ComponentInit args)
{
_itemSlots.AddItemSlot(uid, SolutionCartridgeReceiverComponent.CartridgeSlotId, receiver.CartridgeSlot);
}

private void OnComponentRemove(EntityUid uid, SolutionCartridgeReceiverComponent receiver, ComponentRemove args)
{
_itemSlots.RemoveItemSlot(uid, receiver.CartridgeSlot);
}

private bool DrainInto(EntityUid fromEnt, string fromName, EntityUid toEnt, string toName)
{
if (!TryComp(fromEnt, out SolutionContainerManagerComponent? fromManager))
return false;

if (!_container.TryGetSolution((fromEnt, fromManager),
fromName,
out var _,
out var fromSolution))
return false;

// Get the solution from our hypospray
if (!TryComp(toEnt, out SolutionContainerManagerComponent? toManager))
return false;

if (!_container.TryGetSolution((toEnt, toManager),
toName,
out var toSolutionEnt,
out var _))
return false;

if (!_container.TryAddSolution(toSolutionEnt.Value, fromSolution))
return false;

// Drain the solution completely
fromSolution.RemoveAllSolution();

return true;
}

private void OnItemInserted(Entity<SolutionCartridgeReceiverComponent> entity, ref EntInsertedIntoContainerMessage args)
{
var (uid, receiver) = entity;

// Drain the newly inserted cartridge into the hypospray
if (!DrainInto(args.Entity, receiver.CartridgeSolution,
uid, receiver.HypospraySolution))
{
return;
}

// TODO: Update appearance
}

private void OnItemRemoved(Entity<SolutionCartridgeReceiverComponent> entity, ref EntRemovedFromContainerMessage args)
{
var (uid, receiver) = entity;

// Drain the hypospray into the cartridge that's been removed
if (!DrainInto(uid, receiver.HypospraySolution,
args.Entity, receiver.CartridgeSolution))
{
return;
}

// TODO: Update appearance
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
- type: entity
id: CombatHypospray
name: combat hypospray
parent: [BaseItem, BaseRestrictedContraband]
description: A small hypospray intended for combat and rapid response teams, uses pre-built cartridges
components:
- type: Sprite
sprite: _DV/Objects/Specific/Medical/combathypo.rsi
state: hypo
- type: Item
sprite: _DV/Objects/Specific/Medical/combathypo.rsi
- type: SolutionContainerManager
solutions:
hypospray:
maxVol: 30
reagents: []
- type: ExaminableSolution
solution: hypospray
- type: Hypospray
solutionName: hypospray
transferAmount: 5
onlyAffectsMobs: false
injectOnly: true
- type: HyposprayBlockNonMobInjection
- type: UseDelay
delay: 0.5
- type: SolutionCartridgeReceiver
cartridgeSlot:
whitelist:
tags:
- HyposprayCartridge
- type: ContainerContainer
containers:
cartridge-slot: !type:ContainerSlot {}

- type: entity
id: BaseEmptyHypoCartridge
name: hypo cartridge
parent: [BaseItem, BaseRestrictedContraband]
components:
- type: SolutionContainerManager
solutions:
cartridge:
maxVol: 30
reagents: []
- type: Tag
tags:
- HyposprayCartridge
- type: Sprite
sprite: Objects/Specific/Chemistry/bottle.rsi
layers:
- state: bottle-1
- state: bottle-1-1
map: ["enum.SolutionContainerLayers.Fill"]
visible: false
- type: ExaminableSolution
solution: cartridge
- type: SolutionItemStatus
solution: cartridge
- type: SolutionContainerVisuals
maxFillLevels: 6
fillBaseName: bottle-1-
- type: Item
size: Tiny
sprite: Objects/Specific/Chemistry/bottle.rsi

- type: entity
id: BicaridineHypoCartridge
name: Bicaridine hypo cartridge
parent: BaseEmptyHypoCartridge
components:
- type: SolutionContainerManager
solutions:
cartridge:
maxVol: 30
reagents:
- ReagentId: Bicaridine
Quantity: 30

5 changes: 4 additions & 1 deletion Resources/Prototypes/_DV/tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

- type: Tag
id: HidesHarpyWings

- type: Tag
id: HudMedicalSecurity #Craftable Corpsman Glasses

Expand Down Expand Up @@ -107,3 +107,6 @@

- type: Tag
id: PermissibleForSurgery # Can be worn on the body during surgery

- type: Tag
id: HyposprayCartridge
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Taken from vgstation at commit https://github.com/vgstation-coders/vgstation13/commit/1cdfb0230cc96d0ba751fa002d04f8aa2f25ad7d",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "borghypo"
},
{
"name": "borghypo_s"
},
{
"name": "combat_hypo"
},
{
"name": "hypo"
},
{
"name": "inhand-left",
"directions": 4
},
{
"name": "inhand-right",
"directions": 4
},
{
"name": "equipped-BELT",
"directions": 4
}
]
}

0 comments on commit e15ca6b

Please sign in to comment.