Fix lasso buckle (#1246)

Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
DrSmugleaf
2020-07-02 23:36:06 +02:00
committed by GitHub
parent bc24a852f9
commit 0a8a383019
9 changed files with 86 additions and 30 deletions

View File

@@ -1,13 +1,44 @@
using System;
using Content.Shared.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Shared.GameObjects.Components.Mobs
{
public class SharedBuckleComponent : Component
public abstract class SharedBuckleComponent : Component, IActionBlocker, IEffectBlocker
{
public sealed override string Name => "Buckle";
public sealed override uint? NetID => ContentNetIDs.BUCKLE;
protected abstract bool Buckled { get; }
bool IActionBlocker.CanMove()
{
return !Buckled;
}
bool IActionBlocker.CanChangeDirection()
{
return !Buckled;
}
bool IEffectBlocker.CanFall()
{
return !Buckled;
}
[Serializable, NetSerializable]
protected sealed class BuckleComponentState : ComponentState
{
public BuckleComponentState(bool buckled) : base(ContentNetIDs.BUCKLE)
{
Buckled = buckled;
}
public bool Buckled { get; }
}
[Serializable, NetSerializable]
public enum BuckleVisuals
{

View File

@@ -56,8 +56,9 @@
public const uint THIRST = 1050;
public const uint FLASHABLE = 1051;
public const uint PROJECTILE = 1052;
public const uint THROWN_ITEM = 1053;
public const uint BUCKLE = 1052;
public const uint PROJECTILE = 1053;
public const uint THROWN_ITEM = 1054;
// Net IDs for integration tests.
public const uint PREDICTION_TEST = 10001;

View File

@@ -0,0 +1,32 @@
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
namespace Content.Shared.GameObjects.EntitySystems
{
/// <summary>
/// This interface gives components the ability to block certain effects
/// from affecting the owning entity. For actions see <see cref="IActionBlocker"/>
/// </summary>
public interface IEffectBlocker
{
bool CanFall() => true;
}
/// <summary>
/// Utility methods to check if an effect is allowed to affect a specific entity.
/// For actions see <see cref="ActionBlockerSystem"/>
/// </summary>
public class EffectBlockerSystem : EntitySystem
{
public static bool CanFall(IEntity entity)
{
var canFall = true;
foreach (var blocker in entity.GetAllComponents<IEffectBlocker>())
{
canFall &= blocker.CanFall(); // Sets var to false if false
}
return canFall;
}
}
}