Refactor slip dropping to use throwing (#5476)
* Refactor slip dropping to use throwing * Update Content.Server/Fluids/EntitySystems/SpillableSystem.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Uncringe * Update Content.Server/Fluids/EntitySystems/SpillableSystem.cs Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
This commit is contained in:
@@ -3,25 +3,13 @@ using Content.Shared.Interaction;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Fluids.Components
|
||||
namespace Content.Server.Fluids.Components;
|
||||
|
||||
[RegisterComponent]
|
||||
public class SpillableComponent : Component
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class SpillableComponent : Component, IDropped
|
||||
{
|
||||
public override string Name => "Spillable";
|
||||
public override string Name => "Spillable";
|
||||
|
||||
[DataField("solution")]
|
||||
public string SolutionName = "puddle";
|
||||
|
||||
void IDropped.Dropped(DroppedEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.Intentional
|
||||
&& EntitySystem.Get<SolutionContainerSystem>().TryGetSolution(Owner.Uid, SolutionName, out var solutionComponent))
|
||||
{
|
||||
EntitySystem.Get<SolutionContainerSystem>()
|
||||
.Drain(Owner.Uid, solutionComponent, solutionComponent.DrainAvailable)
|
||||
.SpillAt(Owner.Transform.Coordinates, "PuddleSmear");
|
||||
}
|
||||
}
|
||||
}
|
||||
[DataField("solution")]
|
||||
public string SolutionName = "puddle";
|
||||
}
|
||||
|
||||
33
Content.Server/Fluids/EntitySystems/SpillableSystem.cs
Normal file
33
Content.Server/Fluids/EntitySystems/SpillableSystem.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Construction.Components;
|
||||
using Content.Server.Fluids.Components;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Throwing;
|
||||
using Content.Shared.Verbs;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
|
||||
namespace Content.Server.Fluids.EntitySystems;
|
||||
|
||||
[UsedImplicitly]
|
||||
public class SpillableSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<SpillableComponent, LandEvent>(SpillOnLand);
|
||||
}
|
||||
|
||||
void SpillOnLand(EntityUid uid, SpillableComponent component, LandEvent args) {
|
||||
if (args.User != null && _solutionContainerSystem.TryGetSolution(uid, component.SolutionName, out var solutionComponent))
|
||||
{
|
||||
_solutionContainerSystem
|
||||
.Drain(uid, solutionComponent, solutionComponent.DrainAvailable)
|
||||
.SpillAt(EntityManager.GetComponent<TransformComponent>(uid).Coordinates, "PuddleSmear");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -166,18 +166,6 @@ namespace Content.Server.Hands.Systems
|
||||
hands.ActivateHeldEntity(msg.HandName);
|
||||
}
|
||||
|
||||
protected override void DropAllItemsInHands(IEntity entity, bool doMobChecks = true)
|
||||
{
|
||||
base.DropAllItemsInHands(entity, doMobChecks);
|
||||
|
||||
if (!entity.TryGetComponent(out HandsComponent? hands)) return;
|
||||
|
||||
foreach (var heldItem in hands.GetAllHeldItems())
|
||||
{
|
||||
hands.Drop(heldItem.Owner, doMobChecks, false);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: Actually shows all items/clothing/etc.
|
||||
private void HandleExamined(EntityUid uid, HandsComponent component, ExaminedEvent args)
|
||||
{
|
||||
|
||||
41
Content.Server/Standing/StandingStateSystem.cs
Normal file
41
Content.Server/Standing/StandingStateSystem.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Shared.Standing;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Standing;
|
||||
|
||||
public class StandingStateSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
private void FallOver(EntityUid uid, StandingStateComponent component, DropHandItemsEvent args)
|
||||
{
|
||||
var direction = EntityManager.TryGetComponent(uid, out PhysicsComponent? comp) ? comp.LinearVelocity / 50 : Vector2.Zero;
|
||||
var dropAngle = _random.NextFloat(0.8f, 1.2f);
|
||||
|
||||
if (EntityManager.TryGetComponent(uid, out HandsComponent? hands))
|
||||
{
|
||||
foreach (var heldItem in hands.GetAllHeldItems())
|
||||
{
|
||||
if (hands.Drop(heldItem.Owner))
|
||||
{
|
||||
Throwing.ThrowHelper.TryThrow(heldItem.Owner,
|
||||
_random.NextAngle().RotateVec(direction / dropAngle +
|
||||
EntityManager.GetEntity(uid).Transform.WorldRotation.ToVec() / 50),
|
||||
0.5f * dropAngle * _random.NextFloat(-0.9f, 1.1f),
|
||||
EntityManager.GetEntity(uid), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<StandingStateComponent, DropHandItemsEvent>(FallOver);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,7 +33,6 @@ namespace Content.Server.Throwing
|
||||
internal static void TryThrow(this IEntity entity, Vector2 direction, float strength = 1.0f, IEntity? user = null, float pushbackRatio = 1.0f)
|
||||
{
|
||||
if (entity.Deleted ||
|
||||
direction == Vector2.Zero ||
|
||||
strength <= 0f ||
|
||||
!entity.TryGetComponent(out PhysicsComponent? physicsComponent))
|
||||
{
|
||||
@@ -61,7 +60,7 @@ namespace Content.Server.Throwing
|
||||
{
|
||||
physicsComponent.ApplyAngularImpulse(ThrowAngularImpulse);
|
||||
}
|
||||
else
|
||||
else if(direction != Vector2.Zero)
|
||||
{
|
||||
entity.Transform.LocalRotation = direction.ToWorldAngle() - Math.PI;
|
||||
}
|
||||
@@ -79,6 +78,7 @@ namespace Content.Server.Throwing
|
||||
if (time < FlyTime)
|
||||
{
|
||||
physicsComponent.BodyStatus = BodyStatus.OnGround;
|
||||
EntitySystem.Get<ThrownItemSystem>().LandComponent(comp);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user