2024-06-03 14:40:03 -07:00
|
|
|
using Content.Shared.Chemistry.Reaction;
|
2021-11-22 18:01:51 -07:00
|
|
|
using Content.Shared.Chemistry.Reagent;
|
|
|
|
|
using Content.Shared.FixedPoint;
|
|
|
|
|
using Content.Shared.Maps;
|
|
|
|
|
using Content.Shared.Whitelist;
|
|
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
using Robust.Shared.Prototypes;
|
2021-11-25 00:06:13 -06:00
|
|
|
using Robust.Shared.Random;
|
2021-11-22 18:01:51 -07:00
|
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
2023-12-29 04:47:43 -08:00
|
|
|
using System.Numerics;
|
2021-11-22 18:01:51 -07:00
|
|
|
|
|
|
|
|
namespace Content.Server.Chemistry.TileReactions;
|
|
|
|
|
|
|
|
|
|
[DataDefinition]
|
2023-08-22 18:14:33 -07:00
|
|
|
public sealed partial class CreateEntityTileReaction : ITileReaction
|
2021-11-22 18:01:51 -07:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
[DataField(required: true, customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
2021-11-22 18:01:51 -07:00
|
|
|
public string Entity = default!;
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
[DataField]
|
2021-11-22 18:01:51 -07:00
|
|
|
public FixedPoint2 Usage = FixedPoint2.New(1);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// How many of the whitelisted entity can fit on one tile?
|
|
|
|
|
/// </summary>
|
2023-12-29 04:47:43 -08:00
|
|
|
[DataField]
|
2021-11-22 18:01:51 -07:00
|
|
|
public int MaxOnTile = 1;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The whitelist to use when determining what counts as "max entities on a tile".0
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("maxOnTileWhitelist")]
|
|
|
|
|
public EntityWhitelist? Whitelist;
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
[DataField]
|
2021-11-25 00:06:13 -06:00
|
|
|
public float RandomOffsetMax = 0.0f;
|
|
|
|
|
|
2024-05-12 17:34:52 -07:00
|
|
|
public FixedPoint2 TileReact(TileRef tile,
|
|
|
|
|
ReagentPrototype reagent,
|
|
|
|
|
FixedPoint2 reactVolume,
|
2024-08-09 01:27:27 +02:00
|
|
|
IEntityManager entityManager,
|
|
|
|
|
List<ReagentData>? data)
|
2021-11-22 18:01:51 -07:00
|
|
|
{
|
|
|
|
|
if (reactVolume >= Usage)
|
|
|
|
|
{
|
|
|
|
|
if (Whitelist != null)
|
|
|
|
|
{
|
|
|
|
|
int acc = 0;
|
|
|
|
|
foreach (var ent in tile.GetEntitiesInTile())
|
|
|
|
|
{
|
2024-06-03 14:40:03 -07:00
|
|
|
var whitelistSystem = entityManager.System<EntityWhitelistSystem>();
|
|
|
|
|
if (whitelistSystem.IsWhitelistPass(Whitelist, ent))
|
2021-11-22 18:01:51 -07:00
|
|
|
acc += 1;
|
|
|
|
|
|
|
|
|
|
if (acc >= MaxOnTile)
|
|
|
|
|
return FixedPoint2.Zero;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-25 00:06:13 -06:00
|
|
|
var random = IoCManager.Resolve<IRobustRandom>();
|
|
|
|
|
var xoffs = random.NextFloat(-RandomOffsetMax, RandomOffsetMax);
|
|
|
|
|
var yoffs = random.NextFloat(-RandomOffsetMax, RandomOffsetMax);
|
|
|
|
|
|
2024-05-12 17:34:52 -07:00
|
|
|
var center = entityManager.System<TurfSystem>().GetTileCenter(tile);
|
2023-07-06 16:43:49 +12:00
|
|
|
var pos = center.Offset(new Vector2(xoffs, yoffs));
|
2024-05-12 17:34:52 -07:00
|
|
|
entityManager.SpawnEntity(Entity, pos);
|
2021-11-25 00:06:13 -06:00
|
|
|
|
2021-11-22 18:01:51 -07:00
|
|
|
return Usage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FixedPoint2.Zero;
|
|
|
|
|
}
|
|
|
|
|
}
|