Remove redundant TryGetComponent call in buckle initialize (#3164)
This commit is contained in:
@@ -33,10 +33,10 @@ namespace Content.Server.GameObjects.Components.Buckle
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
[ComponentDependency] public readonly AppearanceComponent? AppearanceComponent = null;
|
||||
[ComponentDependency] private readonly ServerAlertsComponent? _serverAlertsComponent = null;
|
||||
[ComponentDependency] private readonly StunnableComponent? _stunnableComponent = null;
|
||||
[ComponentDependency] private readonly MobStateComponent? _mobStateComponent = null;
|
||||
[ComponentDependency] public readonly AppearanceComponent? Appearance = null;
|
||||
[ComponentDependency] private readonly ServerAlertsComponent? _serverAlerts = null;
|
||||
[ComponentDependency] private readonly StunnableComponent? _stunnable = null;
|
||||
[ComponentDependency] private readonly MobStateComponent? _mobState = null;
|
||||
|
||||
private int _size;
|
||||
|
||||
@@ -60,7 +60,6 @@ namespace Content.Server.GameObjects.Components.Buckle
|
||||
|
||||
private StrapComponent? _buckledTo;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The strap that this component is buckled to.
|
||||
/// </summary>
|
||||
@@ -92,22 +91,21 @@ namespace Content.Server.GameObjects.Components.Buckle
|
||||
/// </summary>
|
||||
private void UpdateBuckleStatus()
|
||||
{
|
||||
if (_serverAlertsComponent == null)
|
||||
if (_serverAlerts == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Buckled)
|
||||
{
|
||||
_serverAlertsComponent.ShowAlert(BuckledTo?.BuckledAlertType ?? AlertType.Buckled);
|
||||
_serverAlerts.ShowAlert(BuckledTo?.BuckledAlertType ?? AlertType.Buckled);
|
||||
}
|
||||
else
|
||||
{
|
||||
_serverAlertsComponent.ClearAlertCategory(AlertCategory.Buckled);
|
||||
_serverAlerts.ClearAlertCategory(AlertCategory.Buckled);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Reattaches this entity to the strap, modifying its position and rotation.
|
||||
/// </summary>
|
||||
@@ -254,7 +252,7 @@ namespace Content.Server.GameObjects.Components.Buckle
|
||||
return false;
|
||||
}
|
||||
|
||||
AppearanceComponent?.SetData(BuckleVisuals.Buckled, true);
|
||||
Appearance?.SetData(BuckleVisuals.Buckled, true);
|
||||
|
||||
BuckledTo = strap;
|
||||
LastEntityBuckledTo = BuckledTo.Owner.Uid;
|
||||
@@ -324,9 +322,9 @@ namespace Content.Server.GameObjects.Components.Buckle
|
||||
Owner.Transform.WorldRotation = oldBuckledTo.Owner.Transform.WorldRotation;
|
||||
}
|
||||
|
||||
AppearanceComponent?.SetData(BuckleVisuals.Buckled, false);
|
||||
Appearance?.SetData(BuckleVisuals.Buckled, false);
|
||||
|
||||
if (_stunnableComponent != null && _stunnableComponent.KnockedDown)
|
||||
if (_stunnable != null && _stunnable.KnockedDown)
|
||||
{
|
||||
EntitySystem.Get<StandingStateSystem>().Down(Owner);
|
||||
}
|
||||
@@ -335,7 +333,7 @@ namespace Content.Server.GameObjects.Components.Buckle
|
||||
EntitySystem.Get<StandingStateSystem>().Standing(Owner);
|
||||
}
|
||||
|
||||
_mobStateComponent?.CurrentState?.EnterState(Owner);
|
||||
_mobState?.CurrentState?.EnterState(Owner);
|
||||
|
||||
UpdateBuckleStatus();
|
||||
|
||||
@@ -411,7 +409,6 @@ namespace Content.Server.GameObjects.Components.Buckle
|
||||
drawDepth = BuckledTo.SpriteComponent.DrawDepth - 1;
|
||||
}
|
||||
|
||||
|
||||
return new BuckleComponentState(Buckled, drawDepth, LastEntityBuckledTo, DontCollide);
|
||||
}
|
||||
|
||||
@@ -420,13 +417,12 @@ namespace Content.Server.GameObjects.Components.Buckle
|
||||
return TryUnbuckle(eventArgs.User);
|
||||
}
|
||||
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (!DontCollide || Body == null)
|
||||
if (!DontCollide || Physics == null)
|
||||
return;
|
||||
|
||||
Body.WakeBody();
|
||||
Physics.WakeBody();
|
||||
|
||||
if (!IsOnStrapEntityThisFrame && DontCollide)
|
||||
{
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace Content.Server.GameObjects.Components.Strap
|
||||
|
||||
_occupiedSize += buckle.Size;
|
||||
|
||||
buckle.AppearanceComponent?.SetData(StrapVisuals.RotationAngle, _rotation);
|
||||
buckle.Appearance?.SetData(StrapVisuals.RotationAngle, _rotation);
|
||||
|
||||
SendMessage(new StrapMessage(buckle.Owner, Owner));
|
||||
|
||||
|
||||
@@ -17,8 +17,11 @@ namespace Content.Shared.GameObjects.Components.Buckle
|
||||
public sealed override string Name => "Buckle";
|
||||
|
||||
public sealed override uint? NetID => ContentNetIDs.BUCKLE;
|
||||
|
||||
[ComponentDependency] protected readonly IPhysicsComponent? Physics;
|
||||
|
||||
/// <summary>
|
||||
/// The range from which this entity can buckle to a <see cref="StrapComponent"/>.
|
||||
/// The range from which this entity can buckle to a <see cref="SharedStrapComponent"/>.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public float Range { get; protected set; }
|
||||
@@ -26,20 +29,22 @@ namespace Content.Shared.GameObjects.Components.Buckle
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
serializer.DataReadWriteFunction("range", SharedInteractionSystem.InteractionRange / 1.4f, value => Range = value, () => Range);
|
||||
|
||||
serializer.DataField(this, x => x.Range, "range", SharedInteractionSystem.InteractionRange / 1.4f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// True if the entity is buckled, false otherwise.
|
||||
/// </summary>
|
||||
public abstract bool Buckled { get; }
|
||||
|
||||
public EntityUid? LastEntityBuckledTo { get; set; }
|
||||
|
||||
public bool IsOnStrapEntityThisFrame { get; set; }
|
||||
public bool DontCollide { get; set; }
|
||||
public abstract bool TryBuckle(IEntity user, IEntity to);
|
||||
|
||||
[ComponentDependency] protected IPhysicsComponent? Body;
|
||||
public bool DontCollide { get; set; }
|
||||
|
||||
public abstract bool TryBuckle(IEntity user, IEntity to);
|
||||
|
||||
bool ICollideSpecial.PreventCollide(IPhysBody collidedwith)
|
||||
{
|
||||
@@ -56,11 +61,6 @@ namespace Content.Shared.GameObjects.Components.Buckle
|
||||
{
|
||||
return !Buckled;
|
||||
}
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
Owner.TryGetComponent(out Body);
|
||||
}
|
||||
|
||||
bool IActionBlocker.CanChangeDirection()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user