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,10 @@
using System.Collections.Generic;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.Chemistry;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
@@ -13,8 +16,6 @@ namespace Content.Shared.Chemistry
[Prototype("reagent")]
public class ReagentPrototype : IPrototype, IIndexedPrototype
{
private const float CelsiusToKelvin = 273.15f;
[Dependency] private readonly IModuleManager _moduleManager = default!;
private string _id;
@@ -24,6 +25,7 @@ namespace Content.Shared.Chemistry
private Color _substanceColor;
private List<IMetabolizable> _metabolism;
private string _spritePath;
private List<ITileReaction> _tileReactions;
public string ID => _id;
public string Name => _name;
@@ -33,6 +35,7 @@ namespace Content.Shared.Chemistry
//List of metabolism effects this reagent has, should really only be used server-side.
public List<IMetabolizable> Metabolism => _metabolism;
public List<ITileReaction> TileReactions => _tileReactions;
public string SpriteReplacementPath => _spritePath;
public ReagentPrototype()
@@ -54,10 +57,12 @@ namespace Content.Shared.Chemistry
if (_moduleManager.IsServerModule)
{
serializer.DataField(ref _metabolism, "metabolism", new List<IMetabolizable> { new DefaultMetabolizable() });
serializer.DataField(ref _tileReactions, "tileReactions", new List<ITileReaction> { });
}
else
{
_metabolism = new List<IMetabolizable> { new DefaultMetabolizable() };
_tileReactions = new List<ITileReaction>();
}
}
@@ -78,5 +83,55 @@ namespace Content.Shared.Chemistry
return SubstanceColor;
}
public ReagentUnit ReactionEntity(IEntity entity, ReactionMethod method, ReagentUnit reactVolume)
{
var removed = ReagentUnit.Zero;
foreach (var react in entity.GetAllComponents<IReagentReaction>())
{
switch (method)
{
case ReactionMethod.Touch:
removed += react.ReagentReactTouch(this, reactVolume);
break;
case ReactionMethod.Ingestion:
removed += react.ReagentReactIngestion(this, reactVolume);
break;
case ReactionMethod.Injection:
removed += react.ReagentReactInjection(this, reactVolume);
break;
}
if (removed > reactVolume)
throw new Exception("Removed more than we have!");
if (removed == reactVolume)
break;
}
return removed;
}
public ReagentUnit ReactionTile(TileRef tile, ReagentUnit reactVolume)
{
var removed = ReagentUnit.Zero;
if (tile.Tile.IsEmpty)
return removed;
foreach (var reaction in _tileReactions)
{
removed += reaction.TileReact(tile, this, reactVolume - removed);
if (removed > reactVolume)
throw new Exception("Removed more than we have!");
if (removed == reactVolume)
break;
}
return removed;
}
}
}

View File

@@ -110,14 +110,24 @@ namespace Content.Shared.Chemistry
return a.ShiftDown() >= b;
}
public static bool operator <(ReagentUnit a, int b)
{
return a.ShiftDown() < b;
}
public static bool operator >(ReagentUnit a, int b)
{
return a.ShiftDown() > b;
}
public static bool operator ==(ReagentUnit a, int b)
{
return a.ShiftDown() == b;
return a.Int() == b;
}
public static bool operator !=(ReagentUnit a, int b)
{
return a.ShiftDown() != b;
return a.Int() != b;
}
public static bool operator ==(ReagentUnit a, ReagentUnit b)

View File

@@ -1,8 +1,7 @@
using System;
using Content.Shared.GameObjects.Components.Atmos;
using Robust.Shared.Serialization;
namespace Content.Shared.GameObjects.Atmos
namespace Content.Shared.GameObjects.Components.Atmos
{
[Serializable, NetSerializable]
public enum PumpVisuals

View File

@@ -1,7 +1,7 @@
using Robust.Shared.Serialization;
using System;
using System;
using Robust.Shared.Serialization;
namespace Content.Shared.GameObjects.Atmos
namespace Content.Shared.GameObjects.Components.Atmos
{
[Serializable, NetSerializable]
public enum SiphonVisuals

View File

@@ -1,7 +1,7 @@
using Robust.Shared.Serialization;
using System;
using System;
using Robust.Shared.Serialization;
namespace Content.Shared.GameObjects.Atmos
namespace Content.Shared.GameObjects.Components.Atmos
{
[Serializable, NetSerializable]
public enum VentVisuals

View File

@@ -0,0 +1,17 @@
using System;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Shared.GameObjects.Components.Fluids
{
public class SharedSprayComponent : Component
{
public override string Name => "Spray";
}
[Serializable, NetSerializable]
public enum SprayVisuals
{
Safety,
}
}

View File

@@ -29,8 +29,6 @@ namespace Content.Shared.GameObjects.Components.Mobs
: _gameTiming.CurTime +
(TimeSpan.FromSeconds(Math.Max(StunnedTimer, Math.Max(KnockdownTimer, SlowdownTimer))));
private const int StunLevels = 8;
private bool _canHelp = true;
protected float _stunCap = 20f;
protected float _knockdownCap = 20f;

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.EntitySystems;
@@ -29,25 +30,31 @@ namespace Content.Shared.GameObjects.Components.Movement
/// How many seconds the mob will be paralyzed for.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
private float ParalyzeTime { get; set; } = 3f;
public virtual float ParalyzeTime { get; set; } = 2f;
/// <summary>
/// Percentage of shape intersection for a slip to occur.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
private float IntersectPercentage { get; set; } = 0.3f;
public virtual float IntersectPercentage { get; set; } = 0.3f;
/// <summary>
/// Entities will only be slipped if their speed exceeds this limit.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
private float RequiredSlipSpeed { get; set; } = 0f;
public virtual float RequiredSlipSpeed { get; set; } = 0f;
/// <summary>
/// The entity's speed will be multiplied by this to slip it forwards.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public virtual float LaunchForwardsMultiplier { get; set; } = 1f;
/// <summary>
/// Whether or not this component will try to slip entities.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public bool Slippery { get; set; }
public virtual bool Slippery { get; set; }
private bool TrySlip(IEntity entity)
{
@@ -81,7 +88,7 @@ namespace Content.Shared.GameObjects.Components.Movement
if (entity.TryGetComponent(out ICollidableComponent collidable))
{
var controller = collidable.EnsureController<SlipController>();
controller.LinearVelocity = collidable.LinearVelocity;
controller.LinearVelocity = collidable.LinearVelocity * LaunchForwardsMultiplier;
}
stun.Paralyze(5);
@@ -140,10 +147,30 @@ namespace Content.Shared.GameObjects.Components.Movement
{
base.ExposeData(serializer);
serializer.DataField(this, x => ParalyzeTime, "paralyzeTime", 3f);
serializer.DataField(this, x => IntersectPercentage, "intersectPercentage", 0.3f);
serializer.DataField(this, x => RequiredSlipSpeed, "requiredSlipSpeed", 0f);
serializer.DataField(this, x => x.ParalyzeTime, "paralyzeTime", 3f);
serializer.DataField(this, x => x.IntersectPercentage, "intersectPercentage", 0.3f);
serializer.DataField(this, x => x.RequiredSlipSpeed, "requiredSlipSpeed", 0f);
serializer.DataField(this, x => x.LaunchForwardsMultiplier, "launchForwardsMultiplier", 1f);
serializer.DataField(this, x => x.Slippery, "slippery", true);
}
}
[Serializable, NetSerializable]
public class SlipperyComponentState : ComponentState
{
public float ParalyzeTime { get; }
public float IntersectPercentage { get; }
public float RequiredSlipSpeed { get; }
public float LaunchForwardsMultiplier { get; }
public bool Slippery { get; }
public SlipperyComponentState(float paralyzeTime, float intersectPercentage, float requiredSlipSpeed, float launchForwardsMultiplier, bool slippery) : base(ContentNetIDs.SLIP)
{
ParalyzeTime = paralyzeTime;
IntersectPercentage = intersectPercentage;
RequiredSlipSpeed = requiredSlipSpeed;
LaunchForwardsMultiplier = launchForwardsMultiplier;
Slippery = slippery;
}
}
}

View File

@@ -1,17 +0,0 @@
using System;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Shared.GameObjects.Components
{
public class SharedGasSprayerComponent : Component
{
public sealed override string Name => "GasSprayer";
}
[Serializable, NetSerializable]
public enum ExtinguisherVisuals
{
Rotation
}
}

View File

@@ -0,0 +1,20 @@
using System;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Shared.GameObjects.Components
{
public class SharedVaporComponent : Component
{
public override string Name => "Vapor";
}
[Serializable, NetSerializable]
public enum VaporVisuals
{
Rotation,
Color,
State,
}
}

View File

@@ -74,6 +74,7 @@
public const uint SUSPICION_ROLE = 1068;
public const uint ROTATION = 1069;
public const uint MOB_STATE_MANAGER = 1070;
public const uint SLIP = 1071;
// Net IDs for integration tests.
public const uint PREDICTION_TEST = 10001;

View File

@@ -0,0 +1,11 @@
using Content.Shared.Chemistry;
using Robust.Shared.Interfaces.Serialization;
using Robust.Shared.Map;
namespace Content.Shared.Interfaces.Chemistry
{
public interface ITileReaction : IExposeData
{
ReagentUnit TileReact(TileRef tile, ReagentPrototype reagent, ReagentUnit reactVolume);
}
}

View File

@@ -0,0 +1,18 @@
using Content.Shared.Chemistry;
namespace Content.Shared.Interfaces.GameObjects.Components
{
public enum ReactionMethod
{
Touch,
Injection,
Ingestion,
}
public interface IReagentReaction
{
ReagentUnit ReagentReactTouch(ReagentPrototype reagent, ReagentUnit volume) => ReagentUnit.Zero;
ReagentUnit ReagentReactInjection(ReagentPrototype reagent, ReagentUnit volume) => ReagentUnit.Zero;
ReagentUnit ReagentReactIngestion(ReagentPrototype reagent, ReagentUnit volume) => ReagentUnit.Zero;
}
}

View File

@@ -1,13 +0,0 @@
using Robust.Shared.Maths;
using Robust.Shared.Physics;
namespace Content.Shared.Physics
{
public class GasVaporController : VirtualController
{
public void Move(Vector2 velocityDirection, float speed)
{
LinearVelocity = velocityDirection * speed;
}
}
}