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:
committed by
GitHub
parent
37d6ca556f
commit
69059eac80
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user