Adds new different reaction types. (#2114)

* Adds new different reaction types.
- Adds touch, injection and ingestion reactions for entities.
- Adds tile reactions.
- Removes GasSprayerComponent in favor of SprayComponent.
- Gives fire extinguishers a safety.
- Gives spray puffs a sprite.
- Improved spray and fire extinguisher in general.
- Fire extinguisher now ACTUALLY puts out fires. Amazing, eh?
- Fire extinguisher sprays three 'clouds' at once.
- Spraying flammable chemicals at fire makes them worse. Whoops!
- Gives spray and fire extinguisher their classic sounds.
- Most chemicals now don't make puddles. Too bad!
- Space lube now makes a very slippery puddle. Honk.
- Spraying water (or using a fire extinguisher) on existing puddles makes them bigger.

* Fix solution tests

* food base now has solution container with noexamine caps
This commit is contained in:
Víctor Aguilera Puerto
2020-09-21 17:51:07 +02:00
committed by GitHub
parent 37d6ca556f
commit 69059eac80
51 changed files with 1006 additions and 471 deletions

View File

@@ -2,7 +2,6 @@
using Content.Server.Atmos;
using Content.Server.GameObjects.Components.NodeContainer;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Shared.GameObjects.Atmos;
using Content.Shared.GameObjects.Components.Atmos;
using Robust.Server.GameObjects;
using Robust.Shared.Log;

View File

@@ -3,7 +3,7 @@ using Content.Server.Atmos;
using Content.Server.GameObjects.Components.NodeContainer;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Server.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Atmos;
using Content.Shared.GameObjects.Components.Atmos;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;

View File

@@ -3,7 +3,7 @@ using Content.Server.Atmos;
using Content.Server.GameObjects.Components.NodeContainer;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Server.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Atmos;
using Content.Shared.GameObjects.Components.Atmos;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;

View File

@@ -1,31 +1,43 @@
using System.Linq;
using Content.Server.GameObjects.Components.Fluids;
using Content.Shared.Chemistry;
using Content.Shared.GameObjects.Components;
using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Physics;
using Microsoft.DiaSymReader;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Chemistry
{
[RegisterComponent]
class VaporComponent : Component, ICollideBehavior
class VaporComponent : SharedVaporComponent, ICollideBehavior
{
public const float ReactTime = 0.125f;
[Dependency] private readonly IMapManager _mapManager = default!;
public override string Name => "Vapor";
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[ViewVariables]
private ReagentUnit _transferAmount;
private bool _reached;
private float _reactTimer;
private float _timer;
private EntityCoordinates _target;
private bool _running;
private Vector2 _direction;
private float _velocity;
private float _aliveTime;
public override void Initialize()
{
@@ -38,11 +50,13 @@ namespace Content.Server.GameObjects.Components.Chemistry
}
}
public void Start(Vector2 dir, float velocity)
public void Start(Vector2 dir, float velocity, EntityCoordinates target, float aliveTime)
{
_running = true;
_target = target;
_direction = dir;
_velocity = velocity;
_aliveTime = aliveTime;
// Set Move
if (Owner.TryGetComponent(out ICollidableComponent collidable))
{
@@ -57,7 +71,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
serializer.DataField(ref _transferAmount, "transferAmount", ReagentUnit.New(0.5));
}
public void Update()
public void Update(float frameTime)
{
if (!Owner.TryGetComponent(out SolutionContainerComponent contents))
return;
@@ -65,22 +79,36 @@ namespace Content.Server.GameObjects.Components.Chemistry
if (!_running)
return;
// Get all intersecting tiles with the vapor and spray the divided solution on there
if (Owner.TryGetComponent(out ICollidableComponent collidable))
_timer += frameTime;
_reactTimer += frameTime;
if (_reactTimer >= ReactTime && Owner.TryGetComponent(out ICollidableComponent collidable))
{
var worldBounds = collidable.WorldAABB;
_reactTimer = 0;
var mapGrid = _mapManager.GetGrid(Owner.Transform.GridID);
var tiles = mapGrid.GetTilesIntersecting(worldBounds);
var amount = _transferAmount / ReagentUnit.New(tiles.Count());
foreach (var tile in tiles)
var tile = mapGrid.GetTileRef(Owner.Transform.Coordinates.ToMapIndices(Owner.EntityManager, _mapManager));
foreach (var reagentQuantity in contents.ReagentList.ToArray())
{
var pos = tile.GridIndices.ToEntityCoordinates(_mapManager, tile.GridIndex);
contents.SplitSolution(amount).SpillAt(pos, "PuddleSmear", false); // TODO: Make non PuddleSmear?
if (reagentQuantity.Quantity == ReagentUnit.Zero) continue;
var reagent = _prototypeManager.Index<ReagentPrototype>(reagentQuantity.ReagentId);
contents.TryRemoveReagent(reagentQuantity.ReagentId, reagent.ReactionTile(tile, (reagentQuantity.Quantity / _transferAmount) * 0.25f));
}
}
if (contents.CurrentVolume == 0)
// Check if we've reached our target.
if(!_reached && _target.TryDistance(Owner.EntityManager, Owner.Transform.Coordinates, out var distance) && distance <= 0.5f)
{
_reached = true;
if (Owner.TryGetComponent(out ICollidableComponent coll))
{
var controller = coll.EnsureController<VaporController>();
controller.Stop();
}
}
if (contents.CurrentVolume == 0 || _timer > _aliveTime)
{
// Delete this
Owner.Delete();
@@ -111,6 +139,16 @@ namespace Content.Server.GameObjects.Components.Chemistry
void ICollideBehavior.CollideWith(IEntity collidedWith)
{
if (!Owner.TryGetComponent(out SolutionContainerComponent contents))
return;
foreach (var reagentQuantity in contents.ReagentList.ToArray())
{
if (reagentQuantity.Quantity == ReagentUnit.Zero) continue;
var reagent = _prototypeManager.Index<ReagentPrototype>(reagentQuantity.ReagentId);
contents.TryRemoveReagent(reagentQuantity.ReagentId, reagent.ReactionEntity(collidedWith, ReactionMethod.Touch, reagentQuantity.Quantity * 0.125f));
}
// Check for collision with a impassable object (e.g. wall) and stop
if (collidedWith.TryGetComponent(out ICollidableComponent collidable))
{
@@ -121,6 +159,8 @@ namespace Content.Server.GameObjects.Components.Chemistry
var controller = coll.EnsureController<VaporController>();
controller.Stop();
}
Owner.Delete();
}
}
}

View File

@@ -164,6 +164,16 @@ namespace Content.Server.GameObjects.Components.Fluids
}
}
/// <summary>
/// Whether adding this solution to this puddle would overflow.
/// </summary>
/// <param name="solution"></param>
/// <returns></returns>
public bool WouldOverflow(Solution solution)
{
return (CurrentVolume + solution.TotalVolume > _overflowVolume);
}
// Flow rate should probably be controlled globally so this is it for now
internal bool TryAddSolution(Solution solution, bool sound = true, bool checkForEvaporate = true, bool checkForOverflow = true)
{

View File

@@ -1,6 +1,9 @@
#nullable enable
using System.Diagnostics.CodeAnalysis;
using Content.Server.Utility;
using Content.Shared.Chemistry;
using Content.Shared.GameObjects;
using Robust.Server.GameObjects.EntitySystems.TileLookup;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
@@ -125,5 +128,78 @@ namespace Content.Server.GameObjects.Components.Fluids
puddle = solution.SpillAt(coordinates, prototype, sound);
return puddle != null;
}
public static bool TryGetPuddle(this TileRef tileRef, GridTileLookupSystem? gridTileLookupSystem, [NotNullWhen(true)] out PuddleComponent? puddle)
{
foreach (var entity in tileRef.GetEntitiesInTileFast(gridTileLookupSystem))
{
if (entity.TryGetComponent(out PuddleComponent? p))
{
puddle = p;
return true;
}
}
puddle = null;
return false;
}
public static PuddleComponent? SpillAt(this TileRef tileRef, Solution solution, string prototype, bool overflow = true, bool sound = true)
{
if (solution.TotalVolume <= 0)
{
return null;
}
var mapManager = IoCManager.Resolve<IMapManager>();
var entityManager = IoCManager.Resolve<IEntityManager>();
var serverEntityManager = IoCManager.Resolve<IServerEntityManager>();
var gridId = tileRef.GridIndex;
// If space return early, let that spill go out into the void
if (tileRef.Tile.IsEmpty)
{
return null;
}
PuddleComponent? puddle = null;
// Get normalized co-ordinate for spill location and spill it in the centre
// TODO: Does SnapGrid or something else already do this?
var spillTileMapGrid = mapManager.GetGrid(gridId);
var spillGridCoords = spillTileMapGrid.GridTileToLocal(tileRef.GridIndices);
var spilt = false;
foreach (var spillEntity in entityManager.GetEntitiesAt(spillTileMapGrid.ParentMapId, spillGridCoords.Position))
{
if (!spillEntity.TryGetComponent(out PuddleComponent? puddleComponent))
continue;
if (!overflow && puddleComponent.WouldOverflow(solution))
return null;
if (!puddleComponent.TryAddSolution(solution, sound))
continue;
puddle = puddleComponent;
spilt = true;
break;
}
// Did we add to an existing puddle
if (spilt)
{
return puddle;
}
var puddleEnt = serverEntityManager.SpawnEntity(prototype, spillGridCoords);
puddle = puddleEnt.GetComponent<PuddleComponent>();
puddle.TryAddSolution(solution, sound);
return puddle;
}
}
}

View File

@@ -1,29 +1,51 @@
using Content.Server.GameObjects.Components.Chemistry;
using System;
using Content.Server.GameObjects.Components.Chemistry;
using Content.Shared.Audio;
using Content.Shared.Chemistry;
using Content.Shared.GameObjects.Components;
using Content.Shared.GameObjects.Components.Fluids;
using Content.Shared.GameObjects.Components.Items;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Fluids
{
[RegisterComponent]
class SprayComponent : Component, IAfterInteract
class SprayComponent : SharedSprayComponent, IAfterInteract, IUse, IActivate
{
[Dependency] private readonly IServerEntityManager _serverEntityManager = default!;
public const float SprayDistance = 3f;
public override string Name => "Spray";
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IServerEntityManager _serverEntityManager = default!;
private ReagentUnit _transferAmount;
private string _spraySound;
private float _sprayVelocity;
private float _sprayAliveTime;
private TimeSpan _lastUseTime;
private TimeSpan _cooldownEnd;
private float _cooldownTime;
private string _vaporPrototype;
private int _vaporAmount;
private float _vaporSpread;
private bool _hasSafety;
private bool _safety;
/// <summary>
/// The amount of solution to be sprayer from this solution when using it
@@ -56,24 +78,50 @@ namespace Content.Server.GameObjects.Components.Fluids
Logger.Warning(
$"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionContainerComponent)}");
}
if (_hasSafety)
{
SetSafety(Owner, _safety);
}
}
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _vaporPrototype, "sprayedPrototype", "Vapor");
serializer.DataField(ref _vaporAmount, "vaporAmount", 1);
serializer.DataField(ref _vaporSpread, "vaporSpread", 90f);
serializer.DataField(ref _cooldownTime, "cooldownTime", 0.5f);
serializer.DataField(ref _transferAmount, "transferAmount", ReagentUnit.New(10));
serializer.DataField(ref _sprayVelocity, "sprayVelocity", 5.0f);
serializer.DataField(ref _sprayVelocity, "sprayVelocity", 1.5f);
serializer.DataField(ref _spraySound, "spraySound", string.Empty);
serializer.DataField(ref _sprayAliveTime, "sprayAliveTime", 0.75f);
serializer.DataField(ref _hasSafety, "hasSafety", false);
serializer.DataField(ref _safety, "safety", true);
}
void IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
{
if (!ActionBlockerSystem.CanInteract(eventArgs.User))
return;
if (_hasSafety && _safety)
{
Owner.PopupMessage(eventArgs.User, Loc.GetString("Its safety is on!"));
return;
}
if (CurrentVolume <= 0)
{
Owner.PopupMessage(eventArgs.User, Loc.GetString("It's empty!"));
return;
}
var curTime = _gameTiming.CurTime;
if(curTime < _cooldownEnd)
return;
var playerPos = eventArgs.User.Transform.Coordinates;
if (eventArgs.ClickLocation.GetGridId(_serverEntityManager) != playerPos.GetGridId(_serverEntityManager))
return;
@@ -82,18 +130,86 @@ namespace Content.Server.GameObjects.Components.Fluids
return;
var direction = (eventArgs.ClickLocation.Position - playerPos.Position).Normalized;
var solution = contents.SplitSolution(_transferAmount);
var threeQuarters = direction * 0.75f;
var quarter = direction * 0.25f;
playerPos = playerPos.Offset(direction); // Move a bit so we don't hit the player
//TODO: check for wall?
var vapor = _serverEntityManager.SpawnEntity("Vapor", playerPos);
// Add the solution to the vapor and actually send the thing
var vaporComponent = vapor.GetComponent<VaporComponent>();
vaporComponent.TryAddSolution(solution);
vaporComponent.Start(direction, _sprayVelocity); //TODO: maybe make the velocity depending on the distance to the click
var amount = Math.Max(Math.Min((contents.CurrentVolume / _transferAmount).Int(), _vaporAmount), 1);
var spread = _vaporSpread / amount;
for (var i = 0; i < amount; i++)
{
var rotation = new Angle(direction.ToAngle() + Angle.FromDegrees(spread * i) - Angle.FromDegrees(spread * (amount-1)/2));
var (_, diffPos) = eventArgs.ClickLocation - playerPos;
var diffNorm = diffPos.Normalized;
var diffLength = diffPos.Length;
var target = eventArgs.User.Transform.Coordinates.Offset((diffNorm + rotation.ToVec()).Normalized * diffLength + quarter);
if (target.TryDistance(Owner.EntityManager, playerPos, out var distance) && distance > SprayDistance)
target = eventArgs.User.Transform.Coordinates.Offset(diffNorm * SprayDistance);
var solution = contents.SplitSolution(_transferAmount);
if (solution.TotalVolume <= ReagentUnit.Zero)
break;
var vapor = _serverEntityManager.SpawnEntity(_vaporPrototype, playerPos.Offset(distance < 1 ? quarter : threeQuarters));
vapor.Transform.LocalRotation = rotation;
if (vapor.TryGetComponent(out AppearanceComponent appearance)) // Vapor sprite should face down.
{
appearance.SetData(VaporVisuals.Rotation, -Angle.South + rotation);
appearance.SetData(VaporVisuals.Color, contents.SubstanceColor.WithAlpha(1f));
appearance.SetData(VaporVisuals.State, true);
}
// Add the solution to the vapor and actually send the thing
var vaporComponent = vapor.GetComponent<VaporComponent>();
vaporComponent.TryAddSolution(solution);
vaporComponent.Start(rotation.ToVec(), _sprayVelocity, target, _sprayAliveTime);
}
//Play sound
EntitySystem.Get<AudioSystem>().PlayFromEntity(_spraySound, Owner);
EntitySystem.Get<AudioSystem>().PlayFromEntity(_spraySound, Owner, AudioHelpers.WithVariation(0.125f));
_lastUseTime = curTime;
_cooldownEnd = _lastUseTime + TimeSpan.FromSeconds(_cooldownTime);
if (Owner.TryGetComponent(out ItemCooldownComponent cooldown))
{
cooldown.CooldownStart = _lastUseTime;
cooldown.CooldownEnd = _cooldownEnd;
}
}
public bool UseEntity(UseEntityEventArgs eventArgs)
{
ToggleSafety(eventArgs.User);
return true;
}
public void Activate(ActivateEventArgs eventArgs)
{
ToggleSafety(eventArgs.User);
}
private void ToggleSafety(IEntity user)
{
SetSafety(user, !_safety);
}
private void SetSafety(IEntity user, bool state)
{
if (!ActionBlockerSystem.CanInteract(user) || !_hasSafety)
return;
_safety = state;
if(Owner.TryGetComponent(out AppearanceComponent appearance))
appearance.SetData(SprayVisuals.Safety, _safety);
}
}
}

View File

@@ -1,11 +1,15 @@
using Content.Server.GameObjects.EntitySystems;
using Content.Shared.Chemistry;
using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.Interfaces.GameObjects.Components;
using NFluidsynth;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
using Robust.Shared.Timers;
using Logger = Robust.Shared.Log.Logger;
namespace Content.Server.GameObjects.Components.Mobs
{

View File

@@ -12,12 +12,81 @@ namespace Content.Server.GameObjects.Components.Movement
[ComponentReference(typeof(SharedSlipperyComponent))]
public class SlipperyComponent : SharedSlipperyComponent
{
private float _paralyzeTime = 2f;
private float _intersectPercentage = 0.3f;
private float _requiredSlipSpeed = 0f;
private bool _slippery;
private float _launchForwardsMultiplier = 1f;
/// <summary>
/// Path to the sound to be played when a mob slips.
/// </summary>
[ViewVariables]
private string SlipSound { get; set; } = "/Audio/Effects/slip.ogg";
/// <summary>
/// How many seconds the mob will be paralyzed for.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public override float ParalyzeTime
{
get => _paralyzeTime;
set
{
_paralyzeTime = value;
Dirty();
}
}
/// <summary>
/// Percentage of shape intersection for a slip to occur.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public override float IntersectPercentage
{
get => _intersectPercentage;
set
{
_intersectPercentage = value;
Dirty();
}
}
/// <summary>
/// Entities will only be slipped if their speed exceeds this limit.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public override float RequiredSlipSpeed
{
get => _requiredSlipSpeed;
set
{
_requiredSlipSpeed = value;
Dirty();
}
}
/// <summary>
/// Whether or not this component will try to slip entities.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public override bool Slippery
{
get => _slippery;
set
{
_slippery = value;
Dirty();
}
}
[ViewVariables(VVAccess.ReadWrite)]
public override float LaunchForwardsMultiplier
{
get => _launchForwardsMultiplier;
set => _launchForwardsMultiplier = value;
}
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
@@ -33,5 +102,10 @@ namespace Content.Server.GameObjects.Components.Movement
.PlayFromEntity(SlipSound, Owner, AudioHelpers.WithVariation(0.2f));
}
}
public override ComponentState GetComponentState()
{
return new SlipperyComponentState(_paralyzeTime, _intersectPercentage, _requiredSlipSpeed, _launchForwardsMultiplier, _slippery);
}
}
}

View File

@@ -1,20 +0,0 @@
using Content.Server.Atmos;
using Robust.Shared.GameObjects.Systems;
namespace Content.Server.GameObjects.EntitySystems
{
public class GasVaporSystem : EntitySystem
{
/// <inheritdoc />
public override void Update(float frameTime)
{
foreach (var GasVapor in ComponentManager.EntityQuery<GasVaporComponent>())
{
if (GasVapor.Initialized)
{
GasVapor.Update(frameTime);
}
}
}
}
}

View File

@@ -10,7 +10,7 @@ namespace Content.Server.GameObjects.EntitySystems
{
foreach (var vaporComp in ComponentManager.EntityQuery<VaporComponent>())
{
vaporComp.Update();
vaporComp.Update(frameTime);
}
}
}