2021-12-01 03:44:34 -07:00
|
|
|
|
using System.Collections.Generic;
|
2021-11-12 23:47:50 -07:00
|
|
|
|
using Content.Shared.Body.Events;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Shared.Body.Part;
|
2020-10-10 15:25:13 +02:00
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
using Robust.Shared.Serialization;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-10-10 15:25:13 +02:00
|
|
|
|
|
2021-11-11 16:10:57 -07:00
|
|
|
|
namespace Content.Shared.Body.Components
|
2020-10-10 15:25:13 +02:00
|
|
|
|
{
|
2021-06-16 16:44:38 +02:00
|
|
|
|
public abstract class SharedMechanismComponent : Component, ISerializationHooks
|
2020-10-10 15:25:13 +02:00
|
|
|
|
{
|
|
|
|
|
|
public override string Name => "Mechanism";
|
|
|
|
|
|
|
2020-11-27 11:00:49 +01:00
|
|
|
|
protected readonly Dictionary<int, object> OptionsCache = new();
|
2021-06-16 16:44:38 +02:00
|
|
|
|
protected SharedBodyComponent? BodyCache;
|
2020-10-10 15:25:13 +02:00
|
|
|
|
protected int IdHash;
|
|
|
|
|
|
protected IEntity? PerformerCache;
|
2021-06-16 16:44:38 +02:00
|
|
|
|
private SharedBodyPartComponent? _part;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
|
2021-06-16 16:44:38 +02:00
|
|
|
|
public SharedBodyComponent? Body => Part?.Body;
|
2020-10-10 15:25:13 +02:00
|
|
|
|
|
2021-06-16 16:44:38 +02:00
|
|
|
|
public SharedBodyPartComponent? Part
|
2020-10-10 15:25:13 +02:00
|
|
|
|
{
|
|
|
|
|
|
get => _part;
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_part == value)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var old = _part;
|
|
|
|
|
|
_part = value;
|
|
|
|
|
|
|
2020-10-16 14:42:33 +02:00
|
|
|
|
if (old != null)
|
2020-10-10 15:25:13 +02:00
|
|
|
|
{
|
2020-10-17 12:26:39 +02:00
|
|
|
|
if (old.Body == null)
|
|
|
|
|
|
{
|
2021-12-01 03:44:34 -07:00
|
|
|
|
Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, new RemovedFromPartEvent(old));
|
2020-10-17 12:26:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-12-01 03:44:34 -07:00
|
|
|
|
Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, new RemovedFromPartInBodyEvent(old.Body, old));
|
2020-10-17 12:26:39 +02:00
|
|
|
|
}
|
2020-10-10 15:25:13 +02:00
|
|
|
|
}
|
2020-10-16 14:42:33 +02:00
|
|
|
|
|
|
|
|
|
|
if (value != null)
|
2020-10-10 15:25:13 +02:00
|
|
|
|
{
|
2020-10-17 12:26:39 +02:00
|
|
|
|
if (value.Body == null)
|
|
|
|
|
|
{
|
2021-12-01 03:44:34 -07:00
|
|
|
|
Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, new AddedToPartEvent(value));
|
2020-10-17 12:26:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-12-01 03:44:34 -07:00
|
|
|
|
Owner.EntityManager.EventBus.RaiseLocalEvent(OwnerUid, new AddedToPartInBodyEvent(value.Body, value));
|
2020-10-17 12:26:39 +02:00
|
|
|
|
}
|
2020-10-10 15:25:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataField("maxDurability")] public int MaxDurability { get; set; } = 10;
|
2020-10-10 15:25:13 +02:00
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataField("currentDurability")] public int CurrentDurability { get; set; } = 10;
|
2020-10-10 15:25:13 +02:00
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataField("destroyThreshold")] public int DestroyThreshold { get; set; } = -10;
|
2020-10-10 15:25:13 +02:00
|
|
|
|
|
2020-11-15 04:22:59 +01:00
|
|
|
|
// TODO BODY: Surgery description and adding a message to the examine tooltip of the entity that owns this mechanism
|
2020-10-10 15:25:13 +02:00
|
|
|
|
// TODO BODY
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataField("resistance")] public int Resistance { get; set; } = 0;
|
2020-10-10 15:25:13 +02:00
|
|
|
|
|
|
|
|
|
|
// TODO BODY OnSizeChanged
|
2021-06-16 16:44:38 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Determines whether this
|
|
|
|
|
|
/// <see cref="SharedMechanismComponent"/> can fit into a <see cref="SharedBodyPartComponent"/>.
|
|
|
|
|
|
/// </summary>
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataField("size")] public int Size { get; set; } = 1;
|
2020-10-10 15:25:13 +02:00
|
|
|
|
|
2021-06-16 16:44:38 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// What kind of <see cref="SharedBodyPartComponent"/> this
|
|
|
|
|
|
/// <see cref="SharedMechanismComponent"/> can be easily installed into.
|
|
|
|
|
|
/// </summary>
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataField("compatibility")]
|
|
|
|
|
|
public BodyPartCompatibility Compatibility { get; set; } = BodyPartCompatibility.Universal;
|
2020-10-10 15:25:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|