Files
tbd-station-14/Content.Server/GameObjects/Components/Interactable/WelderComponent.cs
DrSmugleaf b051261485 Bodysystem and damagesystem rework (#1544)
* Things and stuff with grids, unfinished w/ code debug changes.

* Updated submodule and also lost some progress cause I fucked it up xd

* First unfinished draft of the BodySystem. Doesn't compile.

* More changes to make it compile, but still just a framework. Doesn't do anything at the moment.

* Many cleanup changes.

* Revert "Merge branch 'master' of https://github.com/GlassEclipse/space-station-14 into body_system"

This reverts commit ddd4aebbc76cf2a0b7b102f72b93d55a0816c88c, reversing
changes made to 12d0dd752706bdda8879393bd8191a1199a0c978.

* Commit human.yml

* Updated a lot of things to be more classy, more progress overall, etc. etc.

* Latest update with many changes

* Minor changes

* Fixed Travis build bug

* Adds first draft of Body Scanner console, apparently I also forgot to tie Mechanisms into body parts so now a heart just sits in the Torso like a good boy :)

* Commit rest of stuff

* Latest changes

* Latest changes again

* 14 naked cowboys

* Yay!

* Latest changes (probably doesnt compile)

* Surgery!!!!!!!!!~1116y

* Cleaned some stuff up

* More cleanup

* Refactoring of code. Basic surgery path now done.

* Removed readme, has been added to HackMD

* Fixes typo (and thus test errors)

* WIP changes, committing so I can pull latest master changes

* Still working on that god awful merge

* Latest changes

* Latest changes!!

* Beginning of refactor to BoundUserInterface

* Surgery!

* Latest changes - fixes pr change requests and random fixes

* oops

* Fixes bodypart recursion

* Beginning of work on revamping the damage system.

* More latest changes

* Latest changes

* Finished merge

* Commit before removing old healthcode

* Almost done with removing speciescomponent...

* It compiles!!!

* yahoo more work

* Fixes to make it work

* Merge conflict fixes

* Deleting species visualizer was a mistake

* IDE warnings are VERBOTEN

* makes the server not kill itself on startup, some cleanup (#1)

* Namespaces, comments and exception fixes

* Fix conveyor and conveyor switch serialization

SS14 in reactive when

* Move damage, acts and body to shared

Damage cleanup
Comment cleanup

* Rename SpeciesComponent to RotationComponent and cleanup

Damage cleanup
Comment cleanup

* Fix nullable warnings

* Address old reviews

Fix off welder suicide damage type, deathmatch and suspicion

* Fix new test fail with units being able to accept items when unpowered

* Remove RotationComponent, change references to IBodyManagerComponent

* Add a bloodstream to humans

* More cleanups

* Add body conduits, connections, connectors substances and valves

* Revert "Add body conduits, connections, connectors substances and valves"

This reverts commit 9ab0b50e6b15fe98852d7b0836c0cdbf4bd76d20.

* Implement the heart mechanism behavior with the circulatory network

* Added network property to mechanism behaviors

* Changed human organ sprites and added missing ones

* Fix tests

* Add individual body part sprite rendering

* Fix error where dropped mechanisms are not initialized

* Implement client/server body damage

* Make DamageContainer take care of raising events

* Reimplement medical scanner with the new body system

* Improve the medical scanner ui

* Merge conflict fixes

* Fix crash when colliding with something

* Fix microwave suicides and eyes sprite rendering

* Fix nullable reference error

* Fix up surgery client side

* Fix missing using from merge conflict

* Add breathing

*inhale

* Merge conflict fixes

* Fix accumulatedframetime being reset to 0 instead of decreased by the threshold

https://github.com/space-wizards/space-station-14/pull/1617

* Use and add to the new AtmosHelpers

* Fix feet

* Add proper coloring to dropped body parts

* Fix Urist's lungs being too strong

* Merge conflict fixes

* Merge conflict fixes

* Merge conflict fixes

Co-authored-by: GlassEclipse <tsymall5@gmail.com>
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
Co-authored-by: AJCM-git <60196617+AJCM-git@users.noreply.github.com>
2020-08-16 16:42:42 -07:00

253 lines
8.3 KiB
C#

#nullable enable
using System;
using Content.Server.Atmos;
using Content.Server.GameObjects.Components.Chemistry;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces;
using Content.Server.Interfaces.Chat;
using Content.Server.Interfaces.GameObjects;
using Content.Shared.Chemistry;
using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Interactable;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
using Robust.Shared.Serialization;
using Content.Shared.GameObjects.EntitySystems;
namespace Content.Server.GameObjects.Components.Interactable
{
[RegisterComponent]
[ComponentReference(typeof(ToolComponent))]
[ComponentReference(typeof(IToolComponent))]
public class WelderComponent : ToolComponent, IExamine, IUse, ISuicideAct, ISolutionChange
{
#pragma warning disable 649
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
[Dependency] private readonly IServerNotifyManager _notifyManager = default!;
#pragma warning restore 649
public override string Name => "Welder";
public override uint? NetID => ContentNetIDs.WELDER;
/// <summary>
/// Default Cost of using the welder fuel for an action
/// </summary>
public const float DefaultFuelCost = 10;
/// <summary>
/// Rate at which we expunge fuel from ourselves when activated
/// </summary>
public const float FuelLossRate = 0.5f;
private bool _welderLit;
private WelderSystem _welderSystem = default!;
private SpriteComponent? _spriteComponent;
private SolutionComponent? _solutionComponent;
private PointLightComponent? _pointLightComponent;
public string? WeldSoundCollection { get; set; }
[ViewVariables]
public float Fuel => _solutionComponent?.Solution.GetReagentQuantity("chem.WeldingFuel").Float() ?? 0f;
[ViewVariables]
public float FuelCapacity => _solutionComponent?.MaxVolume.Float() ?? 0f;
/// <summary>
/// Status of welder, whether it is ignited
/// </summary>
[ViewVariables]
public bool WelderLit
{
get => _welderLit;
private set
{
_welderLit = value;
Dirty();
}
}
public override void Initialize()
{
base.Initialize();
AddQuality(ToolQuality.Welding);
_welderSystem = _entitySystemManager.GetEntitySystem<WelderSystem>();
Owner.TryGetComponent(out _solutionComponent);
Owner.TryGetComponent(out _spriteComponent);
Owner.TryGetComponent(out _pointLightComponent);
}
public override void ExposeData(ObjectSerializer serializer)
{
serializer.DataField(this, collection => WeldSoundCollection, "weldSoundCollection", string.Empty);
}
public override ComponentState GetComponentState()
{
return new WelderComponentState(FuelCapacity, Fuel, WelderLit);
}
public override bool UseTool(IEntity user, IEntity target, ToolQuality toolQualityNeeded)
{
var canUse = base.UseTool(user, target, toolQualityNeeded);
return toolQualityNeeded.HasFlag(ToolQuality.Welding) ? canUse && TryWeld(DefaultFuelCost, user) : canUse;
}
public bool UseTool(IEntity user, IEntity target, ToolQuality toolQualityNeeded, float fuelConsumed)
{
return base.UseTool(user, target, toolQualityNeeded) && TryWeld(fuelConsumed, user);
}
private bool TryWeld(float value, IEntity? user = null, bool silent = false)
{
if (!WelderLit)
{
if(!silent) _notifyManager.PopupMessage(Owner, user, Loc.GetString("The welder is turned off!"));
return false;
}
if (!CanWeld(value))
{
if(!silent) _notifyManager.PopupMessage(Owner, user, Loc.GetString("The welder does not have enough fuel for that!"));
return false;
}
if (_solutionComponent == null)
return false;
bool succeeded = _solutionComponent.TryRemoveReagent("chem.WeldingFuel", ReagentUnit.New(value));
if (succeeded && !silent)
{
PlaySoundCollection(WeldSoundCollection);
}
return succeeded;
}
private bool CanWeld(float value)
{
return Fuel > value || Qualities != ToolQuality.Welding;
}
private bool CanLitWelder()
{
return Fuel > 0 || Qualities != ToolQuality.Welding;
}
/// <summary>
/// Deactivates welding tool if active, activates welding tool if possible
/// </summary>
private bool ToggleWelderStatus(IEntity? user = null)
{
var item = Owner.GetComponent<ItemComponent>();
if (WelderLit)
{
WelderLit = false;
// Layer 1 is the flame.
item.EquippedPrefix = "off";
_spriteComponent?.LayerSetVisible(1, false);
if (_pointLightComponent != null) _pointLightComponent.Enabled = false;
PlaySoundCollection("WelderOff", -5);
_welderSystem.Unsubscribe(this);
return true;
}
if (!CanLitWelder())
{
_notifyManager.PopupMessage(Owner, user, Loc.GetString("The welder has no fuel left!"));
return false;
}
WelderLit = true;
item.EquippedPrefix = "on";
_spriteComponent?.LayerSetVisible(1, true);
if (_pointLightComponent != null) _pointLightComponent.Enabled = true;
PlaySoundCollection("WelderOn", -5);
_welderSystem.Subscribe(this);
Owner.Transform.GridPosition
.GetTileAtmosphere()?.HotspotExpose(700f, 50f, true);
return true;
}
public bool UseEntity(UseEntityEventArgs eventArgs)
{
return ToggleWelderStatus(eventArgs.User);
}
public void Examine(FormattedMessage message, bool inDetailsRange)
{
if (WelderLit)
{
message.AddMarkup(Loc.GetString("[color=orange]Lit[/color]\n"));
}
else
{
message.AddText(Loc.GetString("Not lit\n"));
}
if (inDetailsRange)
{
message.AddMarkup(Loc.GetString("Fuel: [color={0}]{1}/{2}[/color].",
Fuel < FuelCapacity / 4f ? "darkorange" : "orange", Math.Round(Fuel), FuelCapacity));
}
}
protected override void Shutdown()
{
base.Shutdown();
_welderSystem.Unsubscribe(this);
}
public void OnUpdate(float frameTime)
{
if (!HasQuality(ToolQuality.Welding) || !WelderLit || Owner.Deleted)
return;
_solutionComponent?.TryRemoveReagent("chem.WeldingFuel", ReagentUnit.New(FuelLossRate * frameTime));
Owner.Transform.GridPosition
.GetTileAtmosphere()?.HotspotExpose(700f, 50f, true);
if (Fuel == 0)
ToggleWelderStatus();
}
public SuicideKind Suicide(IEntity victim, IChatManager chat)
{
if (TryWeld(5, victim, silent: true))
{
PlaySoundCollection(WeldSoundCollection);
chat.EntityMe(victim, Loc.GetString("welds {0:their} every orifice closed! It looks like {0:theyre} trying to commit suicide!", victim)); //TODO: theyre macro
return SuicideKind.Heat;
}
chat.EntityMe(victim, Loc.GetString("bashes {0:themselves} with the {1}!", victim, Owner.Name));
return SuicideKind.Blunt;
}
public void SolutionChanged(SolutionChangeEventArgs eventArgs)
{
Dirty();
}
}
}