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

@@ -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);
}
}
}