0 days without buckle breaking (#1366)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.GameObjects.Components.Buckle;
|
||||
using Content.Server.Interfaces.GameObjects.Components.Interaction;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Strap;
|
||||
@@ -17,30 +17,34 @@ namespace Content.Server.GameObjects.Components.Strap
|
||||
[RegisterComponent]
|
||||
public class StrapComponent : SharedStrapComponent, IInteractHand
|
||||
{
|
||||
private HashSet<IEntity> _buckledEntities;
|
||||
private StrapPosition _position;
|
||||
private string _buckleSound;
|
||||
private string _unbuckleSound;
|
||||
private string _buckledIcon;
|
||||
|
||||
/// <summary>
|
||||
/// The angle in degrees to rotate the player by when they get strapped
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
private int _rotation;
|
||||
|
||||
/// <summary>
|
||||
/// The size of the strap which is compared against when buckling entities
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
private int _size;
|
||||
private int _occupiedSize;
|
||||
|
||||
/// <summary>
|
||||
/// The entity that is currently buckled here, synced from <see cref="BuckleComponent.BuckledTo"/>
|
||||
/// </summary>
|
||||
private HashSet<IEntity> BuckledEntities { get; set; }
|
||||
public IReadOnlyCollection<IEntity> BuckledEntities => _buckledEntities;
|
||||
|
||||
/// <summary>
|
||||
/// The change in position to the strapped mob
|
||||
/// </summary>
|
||||
public override StrapPosition Position
|
||||
{
|
||||
get => _position;
|
||||
protected set
|
||||
{
|
||||
_position = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
public StrapPosition Position => _position;
|
||||
|
||||
/// <summary>
|
||||
/// The sound to be played when a mob is buckled
|
||||
@@ -60,34 +64,29 @@ namespace Content.Server.GameObjects.Components.Strap
|
||||
[ViewVariables]
|
||||
public string BuckledIcon => _buckledIcon;
|
||||
|
||||
/// <summary>
|
||||
/// The angle in degrees to rotate the player by when they get strapped
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public int Rotation => _rotation;
|
||||
|
||||
/// <summary>
|
||||
/// The size of the strap which is compared against when buckling entities
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public int Size => _size;
|
||||
|
||||
/// <summary>
|
||||
/// The sum of the sizes of all the buckled entities in this strap
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
private int OccupiedSize { get; set; }
|
||||
public int OccupiedSize => _occupiedSize;
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this strap has enough space for a new occupant.
|
||||
/// </summary>
|
||||
/// <param name="buckle">The new occupant</param>
|
||||
/// <returns>true if there is enough space, false otherwise</returns>
|
||||
public bool HasSpace(BuckleComponent buckle)
|
||||
{
|
||||
return OccupiedSize + buckle.Size <= _size;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a buckled entity. Called from <see cref="BuckleComponent.TryBuckle"/>
|
||||
/// Adds a buckled entity. Called from <see cref="BuckleComponent.TryBuckle"/>
|
||||
/// </summary>
|
||||
/// <param name="buckle">The component to add</param>
|
||||
/// <param name="force">Whether or not to check if the strap has enough space</param>
|
||||
/// <param name="force">
|
||||
/// Whether or not to check if the strap has enough space
|
||||
/// </param>
|
||||
/// <returns>True if added, false otherwise</returns>
|
||||
public bool TryAdd(BuckleComponent buckle, bool force = false)
|
||||
{
|
||||
@@ -96,12 +95,12 @@ namespace Content.Server.GameObjects.Components.Strap
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!BuckledEntities.Add(buckle.Owner))
|
||||
if (!_buckledEntities.Add(buckle.Owner))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
OccupiedSize += buckle.Size;
|
||||
_occupiedSize += buckle.Size;
|
||||
|
||||
if (buckle.Owner.TryGetComponent(out AppearanceComponent appearance))
|
||||
{
|
||||
@@ -112,14 +111,15 @@ namespace Content.Server.GameObjects.Components.Strap
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a buckled entity. Called from <see cref="BuckleComponent.TryUnbuckle"/>
|
||||
/// Removes a buckled entity.
|
||||
/// Called from <see cref="BuckleComponent.TryUnbuckle"/>
|
||||
/// </summary>
|
||||
/// <param name="buckle">The component to remove</param>
|
||||
public void Remove(BuckleComponent buckle)
|
||||
{
|
||||
if (BuckledEntities.Remove(buckle.Owner))
|
||||
if (_buckledEntities.Remove(buckle.Owner))
|
||||
{
|
||||
OccupiedSize -= buckle.Size;
|
||||
_occupiedSize -= buckle.Size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,16 +136,16 @@ namespace Content.Server.GameObjects.Components.Strap
|
||||
var defaultSize = 100;
|
||||
|
||||
serializer.DataField(ref _size, "size", defaultSize);
|
||||
BuckledEntities = new HashSet<IEntity>(_size / defaultSize);
|
||||
_buckledEntities = new HashSet<IEntity>(_size / defaultSize);
|
||||
|
||||
OccupiedSize = 0;
|
||||
_occupiedSize = 0;
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
base.OnRemove();
|
||||
|
||||
foreach (var entity in BuckledEntities)
|
||||
foreach (var entity in _buckledEntities)
|
||||
{
|
||||
if (entity.TryGetComponent(out BuckleComponent buckle))
|
||||
{
|
||||
@@ -153,13 +153,8 @@ namespace Content.Server.GameObjects.Components.Strap
|
||||
}
|
||||
}
|
||||
|
||||
BuckledEntities.Clear();
|
||||
OccupiedSize = 0;
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
return new StrapComponentState(Position);
|
||||
_buckledEntities.Clear();
|
||||
_occupiedSize = 0;
|
||||
}
|
||||
|
||||
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
||||
|
||||
Reference in New Issue
Block a user