Body code cleanup (#24946)
* Fix test * Kill float accumulators * Use entity proxy methods * DataField auto name generation where possible * Kill comp properties * Clean up server comps * Make events record structs * Clean up shared body code * Clean up server body code * Rename organ events to be same names as in med refactor
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Events;
|
||||
@@ -23,52 +23,52 @@ public partial class SharedBodySystem
|
||||
SubscribeLocalEvent<BodyPartComponent, EntRemovedFromContainerMessage>(OnBodyPartRemoved);
|
||||
}
|
||||
|
||||
private void OnBodyPartInserted(EntityUid uid, BodyPartComponent component, EntInsertedIntoContainerMessage args)
|
||||
private void OnBodyPartInserted(Entity<BodyPartComponent> ent, ref EntInsertedIntoContainerMessage args)
|
||||
{
|
||||
// Body part inserted into another body part.
|
||||
var entity = args.Entity;
|
||||
var insertedUid = args.Entity;
|
||||
var slotId = args.Container.ID;
|
||||
|
||||
if (component.Body == null)
|
||||
if (ent.Comp.Body is null)
|
||||
return;
|
||||
|
||||
if (TryComp(entity, out BodyPartComponent? childPart))
|
||||
if (TryComp(insertedUid, out BodyPartComponent? part))
|
||||
{
|
||||
AddPart(component.Body.Value, entity, slotId, childPart);
|
||||
RecursiveBodyUpdate(entity, component.Body.Value, childPart);
|
||||
AddPart(ent.Comp.Body.Value, (insertedUid, part), slotId);
|
||||
RecursiveBodyUpdate((insertedUid, part), ent.Comp.Body.Value);
|
||||
}
|
||||
|
||||
if (TryComp(entity, out OrganComponent? organ))
|
||||
AddOrgan(entity, component.Body.Value, uid, organ);
|
||||
if (TryComp(insertedUid, out OrganComponent? organ))
|
||||
AddOrgan((insertedUid, organ), ent.Comp.Body.Value, ent);
|
||||
}
|
||||
|
||||
private void OnBodyPartRemoved(EntityUid uid, BodyPartComponent component, EntRemovedFromContainerMessage args)
|
||||
private void OnBodyPartRemoved(Entity<BodyPartComponent> ent, ref EntRemovedFromContainerMessage args)
|
||||
{
|
||||
// Body part removed from another body part.
|
||||
var entity = args.Entity;
|
||||
var removedUid = args.Entity;
|
||||
var slotId = args.Container.ID;
|
||||
|
||||
DebugTools.Assert(!TryComp(entity, out BodyPartComponent? b) || b.Body == component.Body);
|
||||
DebugTools.Assert(!TryComp(entity, out OrganComponent? o) || o.Body == component.Body);
|
||||
DebugTools.Assert(!TryComp(removedUid, out BodyPartComponent? b) || b.Body == ent.Comp.Body);
|
||||
DebugTools.Assert(!TryComp(removedUid, out OrganComponent? o) || o.Body == ent.Comp.Body);
|
||||
|
||||
if (TryComp(entity, out BodyPartComponent? childPart) && childPart.Body != null)
|
||||
if (TryComp(removedUid, out BodyPartComponent? part) && part.Body is not null)
|
||||
{
|
||||
RemovePart(childPart.Body.Value, entity, slotId, childPart);
|
||||
RecursiveBodyUpdate(entity, null, childPart);
|
||||
RemovePart(part.Body.Value, (removedUid, part), slotId);
|
||||
RecursiveBodyUpdate((removedUid, part), null);
|
||||
}
|
||||
|
||||
if (TryComp(entity, out OrganComponent? organ))
|
||||
RemoveOrgan(entity, uid, organ);
|
||||
if (TryComp(removedUid, out OrganComponent? organ))
|
||||
RemoveOrgan((removedUid, organ), ent);
|
||||
}
|
||||
|
||||
private void RecursiveBodyUpdate(EntityUid uid, EntityUid? bodyUid, BodyPartComponent component)
|
||||
private void RecursiveBodyUpdate(Entity<BodyPartComponent> ent, EntityUid? bodyUid)
|
||||
{
|
||||
component.Body = bodyUid;
|
||||
Dirty(uid, component);
|
||||
ent.Comp.Body = bodyUid;
|
||||
Dirty(ent, ent.Comp);
|
||||
|
||||
foreach (var slotId in component.Organs.Keys)
|
||||
foreach (var slotId in ent.Comp.Organs.Keys)
|
||||
{
|
||||
if (!Containers.TryGetContainer(uid, GetOrganContainerId(slotId), out var container))
|
||||
if (!Containers.TryGetContainer(ent, GetOrganContainerId(slotId), out var container))
|
||||
continue;
|
||||
|
||||
foreach (var organ in container.ContainedEntities)
|
||||
@@ -78,105 +78,108 @@ public partial class SharedBodySystem
|
||||
|
||||
Dirty(organ, organComp);
|
||||
|
||||
if (organComp.Body != null)
|
||||
RaiseLocalEvent(organ, new RemovedFromPartInBodyEvent(organComp.Body.Value, uid));
|
||||
if (organComp.Body is { Valid: true } oldBodyUid)
|
||||
{
|
||||
var removedEv = new OrganRemovedFromBodyEvent(oldBodyUid, ent);
|
||||
RaiseLocalEvent(organ, ref removedEv);
|
||||
}
|
||||
|
||||
organComp.Body = bodyUid;
|
||||
if (bodyUid != null)
|
||||
RaiseLocalEvent(organ, new AddedToPartInBodyEvent(bodyUid.Value, uid));
|
||||
if (bodyUid is not null)
|
||||
{
|
||||
var addedEv = new OrganAddedToBodyEvent(bodyUid.Value, ent);
|
||||
RaiseLocalEvent(organ, ref addedEv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var slotId in component.Children.Keys)
|
||||
foreach (var slotId in ent.Comp.Children.Keys)
|
||||
{
|
||||
if (!Containers.TryGetContainer(uid, GetPartSlotContainerId(slotId), out var container))
|
||||
if (!Containers.TryGetContainer(ent, GetPartSlotContainerId(slotId), out var container))
|
||||
continue;
|
||||
|
||||
foreach (var containedEnt in container.ContainedEntities)
|
||||
foreach (var containedUid in container.ContainedEntities)
|
||||
{
|
||||
if (TryComp(containedEnt, out BodyPartComponent? childPart))
|
||||
RecursiveBodyUpdate(containedEnt, bodyUid, childPart);
|
||||
if (TryComp(containedUid, out BodyPartComponent? childPart))
|
||||
RecursiveBodyUpdate((containedUid, childPart), bodyUid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void AddPart(
|
||||
EntityUid bodyUid,
|
||||
EntityUid partUid,
|
||||
string slotId,
|
||||
BodyPartComponent component,
|
||||
BodyComponent? bodyComp = null)
|
||||
Entity<BodyComponent?> bodyEnt,
|
||||
Entity<BodyPartComponent> partEnt,
|
||||
string slotId)
|
||||
{
|
||||
DebugTools.AssertOwner(partUid, component);
|
||||
Dirty(partUid, component);
|
||||
component.Body = bodyUid;
|
||||
Dirty(partEnt, partEnt.Comp);
|
||||
partEnt.Comp.Body = bodyEnt;
|
||||
|
||||
var ev = new BodyPartAddedEvent(slotId, component);
|
||||
RaiseLocalEvent(bodyUid, ref ev);
|
||||
var ev = new BodyPartAddedEvent(slotId, partEnt);
|
||||
RaiseLocalEvent(bodyEnt, ref ev);
|
||||
|
||||
AddLeg(partUid, bodyUid, component, bodyComp);
|
||||
AddLeg(partEnt, bodyEnt);
|
||||
}
|
||||
|
||||
protected virtual void RemovePart(
|
||||
EntityUid bodyUid,
|
||||
EntityUid partUid,
|
||||
string slotId,
|
||||
BodyPartComponent component,
|
||||
BodyComponent? bodyComp = null)
|
||||
Entity<BodyComponent?> bodyEnt,
|
||||
Entity<BodyPartComponent> partEnt,
|
||||
string slotId)
|
||||
{
|
||||
DebugTools.AssertOwner(partUid, component);
|
||||
Resolve(bodyUid, ref bodyComp, false);
|
||||
Dirty(partUid, component);
|
||||
component.Body = null;
|
||||
Resolve(bodyEnt, ref bodyEnt.Comp, logMissing: false);
|
||||
Dirty(partEnt, partEnt.Comp);
|
||||
partEnt.Comp.Body = null;
|
||||
|
||||
var ev = new BodyPartRemovedEvent(slotId, component);
|
||||
RaiseLocalEvent(bodyUid, ref ev);
|
||||
var ev = new BodyPartRemovedEvent(slotId, partEnt);
|
||||
RaiseLocalEvent(bodyEnt, ref ev);
|
||||
|
||||
RemoveLeg(partUid, bodyUid, component);
|
||||
PartRemoveDamage(bodyUid, component, bodyComp);
|
||||
RemoveLeg(partEnt, bodyEnt);
|
||||
PartRemoveDamage(bodyEnt, partEnt);
|
||||
}
|
||||
|
||||
private void AddLeg(EntityUid uid, EntityUid bodyUid, BodyPartComponent component, BodyComponent? bodyComp = null)
|
||||
private void AddLeg(Entity<BodyPartComponent> legEnt, Entity<BodyComponent?> bodyEnt)
|
||||
{
|
||||
if (!Resolve(bodyUid, ref bodyComp, false))
|
||||
if (!Resolve(bodyEnt, ref bodyEnt.Comp, logMissing: false))
|
||||
return;
|
||||
|
||||
if (component.PartType == BodyPartType.Leg)
|
||||
if (legEnt.Comp.PartType == BodyPartType.Leg)
|
||||
{
|
||||
bodyComp.LegEntities.Add(uid);
|
||||
UpdateMovementSpeed(bodyUid);
|
||||
Dirty(bodyUid, bodyComp);
|
||||
bodyEnt.Comp.LegEntities.Add(legEnt);
|
||||
UpdateMovementSpeed(bodyEnt);
|
||||
Dirty(bodyEnt, bodyEnt.Comp);
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveLeg(EntityUid uid, EntityUid bodyUid, BodyPartComponent component, BodyComponent? bodyComp = null)
|
||||
private void RemoveLeg(Entity<BodyPartComponent> legEnt, Entity<BodyComponent?> bodyEnt)
|
||||
{
|
||||
if (!Resolve(bodyUid, ref bodyComp, false))
|
||||
if (!Resolve(bodyEnt, ref bodyEnt.Comp, logMissing: false))
|
||||
return;
|
||||
|
||||
if (component.PartType == BodyPartType.Leg)
|
||||
if (legEnt.Comp.PartType == BodyPartType.Leg)
|
||||
{
|
||||
bodyComp.LegEntities.Remove(uid);
|
||||
UpdateMovementSpeed(bodyUid);
|
||||
Dirty(bodyUid, bodyComp);
|
||||
bodyEnt.Comp.LegEntities.Remove(legEnt);
|
||||
UpdateMovementSpeed(bodyEnt);
|
||||
Dirty(bodyEnt, bodyEnt.Comp);
|
||||
|
||||
if (!bodyComp.LegEntities.Any())
|
||||
if (!bodyEnt.Comp.LegEntities.Any())
|
||||
{
|
||||
Standing.Down(bodyUid);
|
||||
Standing.Down(bodyEnt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void PartRemoveDamage(EntityUid parent, BodyPartComponent component, BodyComponent? bodyComp = null)
|
||||
private void PartRemoveDamage(Entity<BodyComponent?> bodyEnt, Entity<BodyPartComponent> partEnt)
|
||||
{
|
||||
if (!Resolve(parent, ref bodyComp, false))
|
||||
if (!Resolve(bodyEnt, ref bodyEnt.Comp, logMissing: false))
|
||||
return;
|
||||
|
||||
if (!_timing.ApplyingState && component.IsVital && !GetBodyChildrenOfType(parent, component.PartType, bodyComp).Any())
|
||||
if (!_timing.ApplyingState
|
||||
&& partEnt.Comp.IsVital
|
||||
&& !GetBodyChildrenOfType(bodyEnt, partEnt.Comp.PartType, bodyEnt.Comp).Any()
|
||||
)
|
||||
{
|
||||
// TODO BODY SYSTEM KILL : remove this when wounding and required parts are implemented properly
|
||||
var damage = new DamageSpecifier(Prototypes.Index<DamageTypePrototype>("Bloodloss"), 300);
|
||||
Damageable.TryChangeDamage(parent, damage);
|
||||
Damageable.TryChangeDamage(bodyEnt, damage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +215,8 @@ public partial class SharedBodySystem
|
||||
|
||||
var parent = container.Owner;
|
||||
|
||||
if (!TryComp<BodyPartComponent>(parent, out var parentBody) || !parentBody.Children.ContainsKey(slotId))
|
||||
if (!TryComp<BodyPartComponent>(parent, out var parentBody)
|
||||
|| !parentBody.Children.ContainsKey(slotId))
|
||||
return null;
|
||||
|
||||
return (parent, slotId);
|
||||
@@ -252,7 +256,7 @@ public partial class SharedBodySystem
|
||||
BodyPartType partType,
|
||||
BodyPartComponent? part = null)
|
||||
{
|
||||
if (!Resolve(partUid, ref part, false))
|
||||
if (!Resolve(partUid, ref part, logMissing: false))
|
||||
return null;
|
||||
|
||||
Containers.EnsureContainer<ContainerSlot>(partUid, GetPartSlotContainerId(slotId));
|
||||
@@ -275,8 +279,8 @@ public partial class SharedBodySystem
|
||||
{
|
||||
slot = null;
|
||||
|
||||
if (partId == null ||
|
||||
!Resolve(partId.Value, ref part, false))
|
||||
if (partId is null
|
||||
|| !Resolve(partId.Value, ref part, logMissing: false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -310,24 +314,31 @@ public partial class SharedBodySystem
|
||||
/// <summary>
|
||||
/// Returns true if the partId is the root body container for the specified bodyId.
|
||||
/// </summary>
|
||||
public bool IsPartRoot(EntityUid bodyId, EntityUid partId, BodyComponent? body = null, BodyPartComponent? part = null)
|
||||
public bool IsPartRoot(
|
||||
EntityUid bodyId,
|
||||
EntityUid partId,
|
||||
BodyComponent? body = null,
|
||||
BodyPartComponent? part = null)
|
||||
{
|
||||
if (!Resolve(partId, ref part)|| !Resolve(bodyId, ref body))
|
||||
return false;
|
||||
|
||||
return Containers.TryGetContainingContainer(bodyId, partId, out var container) && container.ID == BodyRootContainerId;
|
||||
return Resolve(partId, ref part)
|
||||
&& Resolve(bodyId, ref body)
|
||||
&& Containers.TryGetContainingContainer(bodyId, partId, out var container)
|
||||
&& container.ID == BodyRootContainerId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if we can attach the partId to the bodyId as the root entity.
|
||||
/// </summary>
|
||||
public bool CanAttachToRoot(EntityUid bodyId, EntityUid partId, BodyComponent? body = null,
|
||||
public bool CanAttachToRoot(
|
||||
EntityUid bodyId,
|
||||
EntityUid partId,
|
||||
BodyComponent? body = null,
|
||||
BodyPartComponent? part = null)
|
||||
{
|
||||
return Resolve(bodyId, ref body) &&
|
||||
Resolve(partId, ref part) &&
|
||||
body.RootContainer.ContainedEntity == null &&
|
||||
bodyId != part.Body;
|
||||
return Resolve(bodyId, ref body)
|
||||
&& Resolve(partId, ref part)
|
||||
&& body.RootContainer.ContainedEntity is null
|
||||
&& bodyId != part.Body;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -335,8 +346,11 @@ public partial class SharedBodySystem
|
||||
/// </summary>
|
||||
public (EntityUid Entity, BodyPartComponent BodyPart)? GetRootPartOrNull(EntityUid bodyId, BodyComponent? body = null)
|
||||
{
|
||||
if (!Resolve(bodyId, ref body) || body.RootContainer.ContainedEntity == null)
|
||||
if (!Resolve(bodyId, ref body)
|
||||
|| body.RootContainer.ContainedEntity is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return (body.RootContainer.ContainedEntity.Value,
|
||||
Comp<BodyPartComponent>(body.RootContainer.ContainedEntity.Value));
|
||||
@@ -352,13 +366,9 @@ public partial class SharedBodySystem
|
||||
BodyPartComponent? parentPart = null,
|
||||
BodyPartComponent? part = null)
|
||||
{
|
||||
if (!Resolve(partId, ref part, false) ||
|
||||
!Resolve(parentId, ref parentPart, false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return CanAttachPart(parentId, slot.Id, partId, parentPart, part);
|
||||
return Resolve(partId, ref part, logMissing: false)
|
||||
&& Resolve(parentId, ref parentPart, logMissing: false)
|
||||
&& CanAttachPart(parentId, slot.Id, partId, parentPart, part);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -371,16 +381,12 @@ public partial class SharedBodySystem
|
||||
BodyPartComponent? parentPart = null,
|
||||
BodyPartComponent? part = null)
|
||||
{
|
||||
if (!Resolve(partId, ref part, false) ||
|
||||
!Resolve(parentId, ref parentPart, false) ||
|
||||
!parentPart.Children.TryGetValue(slotId, out var parentSlotData))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return part.PartType == parentSlotData.Type &&
|
||||
Containers.TryGetContainer(parentId, GetPartSlotContainerId(slotId), out var container) &&
|
||||
Containers.CanInsert(partId, container);
|
||||
return Resolve(partId, ref part, logMissing: false)
|
||||
&& Resolve(parentId, ref parentPart, logMissing: false)
|
||||
&& parentPart.Children.TryGetValue(slotId, out var parentSlotData)
|
||||
&& part.PartType == parentSlotData.Type
|
||||
&& Containers.TryGetContainer(parentId, GetPartSlotContainerId(slotId), out var container)
|
||||
&& Containers.CanInsert(partId, container);
|
||||
}
|
||||
|
||||
public bool AttachPartToRoot(
|
||||
@@ -389,14 +395,10 @@ public partial class SharedBodySystem
|
||||
BodyComponent? body = null,
|
||||
BodyPartComponent? part = null)
|
||||
{
|
||||
if (!Resolve(bodyId, ref body) ||
|
||||
!Resolve(partId, ref part) ||
|
||||
!CanAttachToRoot(bodyId, partId, body, part))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return Containers.Insert(partId, body.RootContainer);
|
||||
return Resolve(bodyId, ref body)
|
||||
&& Resolve(partId, ref part)
|
||||
&& CanAttachToRoot(bodyId, partId, body, part)
|
||||
&& Containers.Insert(partId, body.RootContainer);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -406,20 +408,16 @@ public partial class SharedBodySystem
|
||||
/// <summary>
|
||||
/// Attaches a body part to the specified body part parent.
|
||||
/// </summary>
|
||||
public bool AttachPart(
|
||||
EntityUid parentPartId,
|
||||
string slotId,
|
||||
EntityUid partId,
|
||||
BodyPartComponent? parentPart = null,
|
||||
BodyPartComponent? part = null)
|
||||
public bool AttachPart(
|
||||
EntityUid parentPartId,
|
||||
string slotId,
|
||||
EntityUid partId,
|
||||
BodyPartComponent? parentPart = null,
|
||||
BodyPartComponent? part = null)
|
||||
{
|
||||
if (!Resolve(parentPartId, ref parentPart, false) ||
|
||||
!parentPart.Children.TryGetValue(slotId, out var slot))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return AttachPart(parentPartId, slot, partId, parentPart, part);
|
||||
return Resolve(parentPartId, ref parentPart, logMissing: false)
|
||||
&& parentPart.Children.TryGetValue(slotId, out var slot)
|
||||
&& AttachPart(parentPartId, slot, partId, parentPart, part);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -432,10 +430,10 @@ public partial class SharedBodySystem
|
||||
BodyPartComponent? parentPart = null,
|
||||
BodyPartComponent? part = null)
|
||||
{
|
||||
if (!Resolve(parentPartId, ref parentPart, false) ||
|
||||
!Resolve(partId, ref part, false) ||
|
||||
!CanAttachPart(parentPartId, slot.Id, partId, parentPart, part) ||
|
||||
!parentPart.Children.ContainsKey(slot.Id))
|
||||
if (!Resolve(parentPartId, ref parentPart, logMissing: false)
|
||||
|| !Resolve(partId, ref part, logMissing: false)
|
||||
|| !CanAttachPart(parentPartId, slot.Id, partId, parentPart, part)
|
||||
|| !parentPart.Children.ContainsKey(slot.Id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -453,13 +451,16 @@ public partial class SharedBodySystem
|
||||
|
||||
#region Misc
|
||||
|
||||
public void UpdateMovementSpeed(EntityUid bodyId, BodyComponent? body = null, MovementSpeedModifierComponent? movement = null)
|
||||
public void UpdateMovementSpeed(
|
||||
EntityUid bodyId,
|
||||
BodyComponent? body = null,
|
||||
MovementSpeedModifierComponent? movement = null)
|
||||
{
|
||||
if (!Resolve(bodyId, ref body, ref movement, false))
|
||||
return;
|
||||
|
||||
if (body.RequiredLegs <= 0)
|
||||
if (!Resolve(bodyId, ref body, ref movement, logMissing: false)
|
||||
|| body.RequiredLegs <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var walkSpeed = 0f;
|
||||
var sprintSpeed = 0f;
|
||||
@@ -488,7 +489,7 @@ public partial class SharedBodySystem
|
||||
/// </summary>
|
||||
public IEnumerable<(EntityUid Id, OrganComponent Component)> GetPartOrgans(EntityUid partId, BodyPartComponent? part = null)
|
||||
{
|
||||
if (!Resolve(partId, ref part, false))
|
||||
if (!Resolve(partId, ref part, logMissing: false))
|
||||
yield break;
|
||||
|
||||
foreach (var slotId in part.Organs.Keys)
|
||||
@@ -513,7 +514,7 @@ public partial class SharedBodySystem
|
||||
/// </summary>
|
||||
public IEnumerable<BaseContainer> GetPartContainers(EntityUid id, BodyPartComponent? part = null)
|
||||
{
|
||||
if (!Resolve(id, ref part, false) ||
|
||||
if (!Resolve(id, ref part, logMissing: false) ||
|
||||
part.Children.Count == 0)
|
||||
{
|
||||
yield break;
|
||||
@@ -541,9 +542,11 @@ public partial class SharedBodySystem
|
||||
/// <summary>
|
||||
/// Returns all body part components for this entity including itself.
|
||||
/// </summary>
|
||||
public IEnumerable<(EntityUid Id, BodyPartComponent Component)> GetBodyPartChildren(EntityUid partId, BodyPartComponent? part = null)
|
||||
public IEnumerable<(EntityUid Id, BodyPartComponent Component)> GetBodyPartChildren(
|
||||
EntityUid partId,
|
||||
BodyPartComponent? part = null)
|
||||
{
|
||||
if (!Resolve(partId, ref part, false))
|
||||
if (!Resolve(partId, ref part, logMissing: false))
|
||||
yield break;
|
||||
|
||||
yield return (partId, part);
|
||||
@@ -571,9 +574,11 @@ public partial class SharedBodySystem
|
||||
/// <summary>
|
||||
/// Returns all body part slots for this entity.
|
||||
/// </summary>
|
||||
public IEnumerable<BodyPartSlot> GetAllBodyPartSlots(EntityUid partId, BodyPartComponent? part = null)
|
||||
public IEnumerable<BodyPartSlot> GetAllBodyPartSlots(
|
||||
EntityUid partId,
|
||||
BodyPartComponent? part = null)
|
||||
{
|
||||
if (!Resolve(partId, ref part, false))
|
||||
if (!Resolve(partId, ref part, logMissing: false))
|
||||
yield break;
|
||||
|
||||
foreach (var (slotId, slot) in part.Children)
|
||||
@@ -601,7 +606,10 @@ public partial class SharedBodySystem
|
||||
/// <summary>
|
||||
/// Returns true if the bodyId has any parts of this type.
|
||||
/// </summary>
|
||||
public bool BodyHasPartType(EntityUid bodyId, BodyPartType type, BodyComponent? body = null)
|
||||
public bool BodyHasPartType(
|
||||
EntityUid bodyId,
|
||||
BodyPartType type,
|
||||
BodyComponent? body = null)
|
||||
{
|
||||
return GetBodyChildrenOfType(bodyId, type, body).Any();
|
||||
}
|
||||
@@ -615,8 +623,8 @@ public partial class SharedBodySystem
|
||||
BodyPartComponent? parent,
|
||||
BodyPartComponent? child)
|
||||
{
|
||||
if (!Resolve(parentId, ref parent, false) ||
|
||||
!Resolve(childId, ref child, false))
|
||||
if (!Resolve(parentId, ref parent, logMissing: false)
|
||||
|| !Resolve(childId, ref child, logMissing: false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -638,15 +646,11 @@ public partial class SharedBodySystem
|
||||
BodyComponent? body = null,
|
||||
BodyPartComponent? part = null)
|
||||
{
|
||||
if (!Resolve(bodyId, ref body, false) ||
|
||||
body.RootContainer.ContainedEntity == null ||
|
||||
!Resolve(partId, ref part, false) ||
|
||||
!TryComp(body.RootContainer.ContainedEntity, out BodyPartComponent? rootPart))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return PartHasChild(body.RootContainer.ContainedEntity.Value, partId, rootPart, part);
|
||||
return Resolve(bodyId, ref body, logMissing: false)
|
||||
&& body.RootContainer.ContainedEntity is not null
|
||||
&& Resolve(partId, ref part, logMissing: false)
|
||||
&& TryComp(body.RootContainer.ContainedEntity, out BodyPartComponent? rootPart)
|
||||
&& PartHasChild(body.RootContainer.ContainedEntity.Value, partId, rootPart, part);
|
||||
}
|
||||
|
||||
public IEnumerable<(EntityUid Id, BodyPartComponent Component)> GetBodyChildrenOfType(
|
||||
@@ -721,9 +725,11 @@ public partial class SharedBodySystem
|
||||
/// <summary>
|
||||
/// Gets the parent body part and all immediate child body parts for the partId.
|
||||
/// </summary>
|
||||
public IEnumerable<EntityUid> GetBodyPartAdjacentParts(EntityUid partId, BodyPartComponent? part = null)
|
||||
public IEnumerable<EntityUid> GetBodyPartAdjacentParts(
|
||||
EntityUid partId,
|
||||
BodyPartComponent? part = null)
|
||||
{
|
||||
if (!Resolve(partId, ref part, false))
|
||||
if (!Resolve(partId, ref part, logMissing: false))
|
||||
yield break;
|
||||
|
||||
if (TryGetParentBodyPart(partId, out var parentUid, out _))
|
||||
@@ -745,7 +751,7 @@ public partial class SharedBodySystem
|
||||
BodyPartComponent? part = null)
|
||||
where T : IComponent
|
||||
{
|
||||
if (!Resolve(partId, ref part, false))
|
||||
if (!Resolve(partId, ref part, logMissing: false))
|
||||
yield break;
|
||||
|
||||
var query = GetEntityQuery<T>();
|
||||
@@ -762,7 +768,7 @@ public partial class SharedBodySystem
|
||||
BodyPartComponent? part = null)
|
||||
where T : IComponent
|
||||
{
|
||||
if (!Resolve(partId, ref part, false))
|
||||
if (!Resolve(partId, ref part, logMissing: false))
|
||||
{
|
||||
comps = null;
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user