fish-station/Content.Server/Chemistry/EntitySystems/HypospraySystem.cs
Rinary b6920aec99
Рефактор мехов, правки в системе медицины (#507)
* mech system, fix hands, fix fraction

* fix

* fix fake hypo

* fix triple airlocks big sizing

* fix

* upd clown hulk

* xd fix 2

* bigger exit delay

* mechs reflect changes

* guns changes

* draike up

* mechs in another category

* add equipment

* Revert "upd clown hulk"

This reverts commit b8084967040be5d442b2d4770cf7fdece1daa2a8.

* SPIN MY MECH ASS

* mech no rot

* some resprite

* no injections in hardsuits

* some species can not be injectable

* medipans can ignore armor, admeme hypospray ignore armor

* fix

* fix admeme hypo

* mob fraction fix

* rover + nt gygax add

* fix description

* fix id

* some better dome effects

* если пустая гильза в стволе -> Кнопки "казнь" не будет

* phazon added

* fix server crashes

* full rework mechs on mobstates, coils fix mechs, diagnostic hud show health bar for mechs, mechs fastest repair, add mech analyzer

* some fixes

* configure health of all mechs

* upd

* add rover to uplink

* translate bundle

* change price

* phazon construction

* fix

* fix

* Finish phazon construction

* add phazon research and recipes

* phazon construction translate

* fix

* Mech lights

* fix

* translate light action

* Mech sounds, fix damage

* fix

* fix hello sound

* upd

* fix linter

* change damagePercentage

* fix

* fix hello sound

* temp disable damage sounds

* fix battery needed on construct

* some changes

* add mech painting system as DEBUG(in dev)

* Fix yaml, durand paintings

* mech spray cans textures

* change sprite

* fix

* ripley, clarke new textures

* ripley,clarke paints

* fix

* sec pod texture

---------

Co-authored-by: Vigers Ray <60344369+VigersRay@users.noreply.github.com>
2024-10-30 10:53:00 +03:00

217 lines
8.8 KiB
C#

using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Components.SolutionManager;
using Content.Shared.Chemistry;
using Content.Shared.Database;
using Content.Shared.FixedPoint;
using Content.Shared.Forensics;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Mobs.Components;
using Content.Shared.Timing;
using Content.Shared.Weapons.Melee.Events;
using Content.Shared.Inventory;
using Content.Shared.Tag;
using Content.Shared.Popups;
using Content.Server.Interaction;
using Content.Server.Body.Components;
using Content.Server.Popups;
using Robust.Shared.GameStates;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Robust.Server.Audio;
namespace Content.Server.Chemistry.EntitySystems;
public sealed class HypospraySystem : SharedHypospraySystem
{
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly InventorySystem _inventorySystem = default!;
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly InteractionSystem _interaction = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<HyposprayComponent, AfterInteractEvent>(OnAfterInteract);
SubscribeLocalEvent<HyposprayComponent, MeleeHitEvent>(OnAttack);
SubscribeLocalEvent<HyposprayComponent, UseInHandEvent>(OnUseInHand);
}
private bool TryUseHypospray(Entity<HyposprayComponent> entity, EntityUid target, EntityUid user)
{
// if target is ineligible but is a container, try to draw from the container
if (!EligibleEntity(target, EntityManager, entity)
&& _solutionContainers.TryGetDrawableSolution(target, out var drawableSolution, out _))
{
return TryDraw(entity, target, drawableSolution.Value, user);
}
return TryDoInject(entity, target, user);
}
private void OnUseInHand(Entity<HyposprayComponent> entity, ref UseInHandEvent args)
{
if (args.Handled)
return;
args.Handled = TryDoInject(entity, args.User, args.User);
}
public void OnAfterInteract(Entity<HyposprayComponent> entity, ref AfterInteractEvent args)
{
if (args.Handled || !args.CanReach || args.Target == null)
return;
args.Handled = TryUseHypospray(entity, args.Target.Value, args.User);
}
public void OnAttack(Entity<HyposprayComponent> entity, ref MeleeHitEvent args)
{
if (!args.HitEntities.Any())
return;
TryDoInject(entity, args.HitEntities.First(), args.User);
}
public bool TryDoInject(Entity<HyposprayComponent> entity, EntityUid target, EntityUid user)
{
var (uid, component) = entity;
if (!EligibleEntity(target, EntityManager, component))
return false;
if (TryComp(uid, out UseDelayComponent? delayComp))
{
if (_useDelay.IsDelayed((uid, delayComp)))
return false;
}
string? msgFormat = null;
if (!component.PierceArmor && _inventorySystem.TryGetSlotEntity(target, "outerClothing", out var suit))
{
if (TryComp<TagComponent>(suit, out var tag) && tag.Tags.Contains("Hardsuit"))
{
if (target == null) return false;
var taget = (EntityUid) target;
_popup.PopupEntity(Loc.GetString("hypospay-component-failure-hardsuit"), target, user, PopupType.MediumCaution);
return false;
}
}
else if (!component.PierceArmor && TryComp<TagComponent>(target, out var tag) && tag.Tags.Contains("NoInjectable"))
{
_popup.PopupEntity(Loc.GetString("hypospay-component-failure-hardsuit"), target, user, PopupType.MediumCaution);
return false;
}
if (target == user)
msgFormat = "hypospray-component-inject-self-message";
else if (EligibleEntity(user, EntityManager, component) && _interaction.TryRollClumsy(user, component.ClumsyFailChance))
{
msgFormat = "hypospray-component-inject-self-clumsy-message";
target = user;
}
if (!_solutionContainers.TryGetSolution(uid, component.SolutionName, out var hypoSpraySoln, out var hypoSpraySolution) || hypoSpraySolution.Volume == 0)
{
_popup.PopupEntity(Loc.GetString("hypospray-component-empty-message"), target, user);
return true;
}
if (!_solutionContainers.TryGetInjectableSolution(target, out var targetSoln, out var targetSolution))
{
_popup.PopupEntity(Loc.GetString("hypospray-cant-inject", ("target", Identity.Entity(target, EntityManager))), target, user);
return false;
}
_popup.PopupEntity(Loc.GetString(msgFormat ?? "hypospray-component-inject-other-message", ("other", target)), target, user);
if (target != user)
{
_popup.PopupEntity(Loc.GetString("hypospray-component-feel-prick-message"), target, target);
// TODO: This should just be using melee attacks...
// meleeSys.SendLunge(angle, user);
}
_audio.PlayPvs(component.InjectSound, user);
// Medipens and such use this system and don't have a delay, requiring extra checks
// BeginDelay function returns if item is already on delay
if (delayComp != null)
_useDelay.TryResetDelay((uid, delayComp));
// Get transfer amount. May be smaller than component.TransferAmount if not enough room
var realTransferAmount = FixedPoint2.Min(component.TransferAmount, targetSolution.AvailableVolume);
if (realTransferAmount <= 0)
{
_popup.PopupEntity(Loc.GetString("hypospray-component-transfer-already-full-message", ("owner", target)), target, user);
return true;
}
// Move units from attackSolution to targetSolution
var removedSolution = _solutionContainers.SplitSolution(hypoSpraySoln.Value, realTransferAmount);
if (!targetSolution.CanAddSolution(removedSolution))
return true;
_reactiveSystem.DoEntityReaction(target, removedSolution, ReactionMethod.Injection);
_solutionContainers.TryAddSolution(targetSoln.Value, removedSolution);
var ev = new TransferDnaEvent { Donor = target, Recipient = uid };
RaiseLocalEvent(target, ref ev);
// same LogType as syringes...
_adminLogger.Add(LogType.ForceFeed, $"{EntityManager.ToPrettyString(user):user} injected {EntityManager.ToPrettyString(target):target} with a solution {SharedSolutionContainerSystem.ToPrettyString(removedSolution):removedSolution} using a {EntityManager.ToPrettyString(uid):using}");
return true;
}
private bool TryDraw(Entity<HyposprayComponent> entity, Entity<BloodstreamComponent?> target, Entity<SolutionComponent> targetSolution, EntityUid user)
{
if (!_solutionContainers.TryGetSolution(entity.Owner, entity.Comp.SolutionName, out var soln,
out var solution) || solution.AvailableVolume == 0)
{
return false;
}
// Get transfer amount. May be smaller than _transferAmount if not enough room, also make sure there's room in the injector
var realTransferAmount = FixedPoint2.Min(entity.Comp.TransferAmount, targetSolution.Comp.Solution.Volume,
solution.AvailableVolume);
if (realTransferAmount <= 0)
{
_popup.PopupEntity(
Loc.GetString("injector-component-target-is-empty-message",
("target", Identity.Entity(target, EntityManager))),
entity.Owner, user);
return false;
}
var removedSolution = _solutionContainers.Draw(target.Owner, targetSolution, realTransferAmount);
if (!_solutionContainers.TryAddSolution(soln.Value, removedSolution))
{
return false;
}
_popup.PopupEntity(Loc.GetString("injector-component-draw-success-message",
("amount", removedSolution.Volume),
("target", Identity.Entity(target, EntityManager))), entity.Owner, user);
return true;
}
private bool EligibleEntity(EntityUid entity, IEntityManager entMan, HyposprayComponent component)
{
// TODO: Does checking for BodyComponent make sense as a "can be hypospray'd" tag?
// In SS13 the hypospray ONLY works on mobs, NOT beakers or anything else.
// But this is 14, we dont do what SS13 does just because SS13 does it.
return component.OnlyAffectsMobs
? entMan.HasComponent<SolutionContainerManagerComponent>(entity) &&
entMan.HasComponent<MobStateComponent>(entity)
: entMan.HasComponent<SolutionContainerManagerComponent>(entity);
}
}