Remove redundant TryGetComponent call in buckle initialize (#3164)

This commit is contained in:
DrSmugleaf
2021-02-12 13:04:19 +01:00
committed by GitHub
parent 3a372c1b1c
commit 6eb0dd4f50
3 changed files with 24 additions and 28 deletions

View File

@@ -33,10 +33,10 @@ namespace Content.Server.GameObjects.Components.Buckle
{ {
[Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IGameTiming _gameTiming = default!;
[ComponentDependency] public readonly AppearanceComponent? AppearanceComponent = null; [ComponentDependency] public readonly AppearanceComponent? Appearance = null;
[ComponentDependency] private readonly ServerAlertsComponent? _serverAlertsComponent = null; [ComponentDependency] private readonly ServerAlertsComponent? _serverAlerts = null;
[ComponentDependency] private readonly StunnableComponent? _stunnableComponent = null; [ComponentDependency] private readonly StunnableComponent? _stunnable = null;
[ComponentDependency] private readonly MobStateComponent? _mobStateComponent = null; [ComponentDependency] private readonly MobStateComponent? _mobState = null;
private int _size; private int _size;
@@ -60,7 +60,6 @@ namespace Content.Server.GameObjects.Components.Buckle
private StrapComponent? _buckledTo; private StrapComponent? _buckledTo;
/// <summary> /// <summary>
/// The strap that this component is buckled to. /// The strap that this component is buckled to.
/// </summary> /// </summary>
@@ -92,22 +91,21 @@ namespace Content.Server.GameObjects.Components.Buckle
/// </summary> /// </summary>
private void UpdateBuckleStatus() private void UpdateBuckleStatus()
{ {
if (_serverAlertsComponent == null) if (_serverAlerts == null)
{ {
return; return;
} }
if (Buckled) if (Buckled)
{ {
_serverAlertsComponent.ShowAlert(BuckledTo?.BuckledAlertType ?? AlertType.Buckled); _serverAlerts.ShowAlert(BuckledTo?.BuckledAlertType ?? AlertType.Buckled);
} }
else else
{ {
_serverAlertsComponent.ClearAlertCategory(AlertCategory.Buckled); _serverAlerts.ClearAlertCategory(AlertCategory.Buckled);
} }
} }
/// <summary> /// <summary>
/// Reattaches this entity to the strap, modifying its position and rotation. /// Reattaches this entity to the strap, modifying its position and rotation.
/// </summary> /// </summary>
@@ -254,7 +252,7 @@ namespace Content.Server.GameObjects.Components.Buckle
return false; return false;
} }
AppearanceComponent?.SetData(BuckleVisuals.Buckled, true); Appearance?.SetData(BuckleVisuals.Buckled, true);
BuckledTo = strap; BuckledTo = strap;
LastEntityBuckledTo = BuckledTo.Owner.Uid; LastEntityBuckledTo = BuckledTo.Owner.Uid;
@@ -324,9 +322,9 @@ namespace Content.Server.GameObjects.Components.Buckle
Owner.Transform.WorldRotation = oldBuckledTo.Owner.Transform.WorldRotation; 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); EntitySystem.Get<StandingStateSystem>().Down(Owner);
} }
@@ -335,7 +333,7 @@ namespace Content.Server.GameObjects.Components.Buckle
EntitySystem.Get<StandingStateSystem>().Standing(Owner); EntitySystem.Get<StandingStateSystem>().Standing(Owner);
} }
_mobStateComponent?.CurrentState?.EnterState(Owner); _mobState?.CurrentState?.EnterState(Owner);
UpdateBuckleStatus(); UpdateBuckleStatus();
@@ -411,7 +409,6 @@ namespace Content.Server.GameObjects.Components.Buckle
drawDepth = BuckledTo.SpriteComponent.DrawDepth - 1; drawDepth = BuckledTo.SpriteComponent.DrawDepth - 1;
} }
return new BuckleComponentState(Buckled, drawDepth, LastEntityBuckledTo, DontCollide); return new BuckleComponentState(Buckled, drawDepth, LastEntityBuckledTo, DontCollide);
} }
@@ -420,13 +417,12 @@ namespace Content.Server.GameObjects.Components.Buckle
return TryUnbuckle(eventArgs.User); return TryUnbuckle(eventArgs.User);
} }
public void Update() public void Update()
{ {
if (!DontCollide || Body == null) if (!DontCollide || Physics == null)
return; return;
Body.WakeBody(); Physics.WakeBody();
if (!IsOnStrapEntityThisFrame && DontCollide) if (!IsOnStrapEntityThisFrame && DontCollide)
{ {

View File

@@ -108,7 +108,7 @@ namespace Content.Server.GameObjects.Components.Strap
_occupiedSize += buckle.Size; _occupiedSize += buckle.Size;
buckle.AppearanceComponent?.SetData(StrapVisuals.RotationAngle, _rotation); buckle.Appearance?.SetData(StrapVisuals.RotationAngle, _rotation);
SendMessage(new StrapMessage(buckle.Owner, Owner)); SendMessage(new StrapMessage(buckle.Owner, Owner));

View File

@@ -17,8 +17,11 @@ namespace Content.Shared.GameObjects.Components.Buckle
public sealed override string Name => "Buckle"; public sealed override string Name => "Buckle";
public sealed override uint? NetID => ContentNetIDs.BUCKLE; public sealed override uint? NetID => ContentNetIDs.BUCKLE;
[ComponentDependency] protected readonly IPhysicsComponent? Physics;
/// <summary> /// <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> /// </summary>
[ViewVariables] [ViewVariables]
public float Range { get; protected set; } public float Range { get; protected set; }
@@ -26,20 +29,22 @@ namespace Content.Shared.GameObjects.Components.Buckle
public override void ExposeData(ObjectSerializer serializer) public override void ExposeData(ObjectSerializer serializer)
{ {
base.ExposeData(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> /// <summary>
/// True if the entity is buckled, false otherwise. /// True if the entity is buckled, false otherwise.
/// </summary> /// </summary>
public abstract bool Buckled { get; } public abstract bool Buckled { get; }
public EntityUid? LastEntityBuckledTo { get; set; } public EntityUid? LastEntityBuckledTo { get; set; }
public bool IsOnStrapEntityThisFrame { 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) bool ICollideSpecial.PreventCollide(IPhysBody collidedwith)
{ {
@@ -56,11 +61,6 @@ namespace Content.Shared.GameObjects.Components.Buckle
{ {
return !Buckled; return !Buckled;
} }
public override void Initialize()
{
base.Initialize();
Owner.TryGetComponent(out Body);
}
bool IActionBlocker.CanChangeDirection() bool IActionBlocker.CanChangeDirection()
{ {