Add door interaction system with state management and event publishing
This commit is contained in:
37
GameCore/Interaction/RequiresAttributeRequirement.cs
Normal file
37
GameCore/Interaction/RequiresAttributeRequirement.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using GameCore.Attributes;
|
||||
using GameCore.ECS;
|
||||
using GameCore.Interaction.Interfaces;
|
||||
using Attribute = GameCore.Attributes.Attribute;
|
||||
|
||||
namespace GameCore.Interaction;
|
||||
|
||||
public enum ComparisonType
|
||||
{
|
||||
GreaterOrEqual = 0,
|
||||
LessThan = 1,
|
||||
Equal = 2,
|
||||
}
|
||||
|
||||
public class RequiresAttributeRequirement(Attribute attribute, float value, ComparisonType comparison)
|
||||
: IInteractionRequirement
|
||||
{
|
||||
public bool IsMet(Entity interactor, World world)
|
||||
{
|
||||
var attributes = world.GetComponent<AttributeComponent>(interactor);
|
||||
if (attributes == null) return false;
|
||||
|
||||
var actualValue = attributes.GetValue(attribute);
|
||||
|
||||
return comparison switch
|
||||
{
|
||||
ComparisonType.GreaterOrEqual => actualValue >= value,
|
||||
ComparisonType.LessThan => actualValue < value,
|
||||
ComparisonType.Equal => System.Math.Abs(actualValue - value) < 0.0001f,
|
||||
_ => false
|
||||
};
|
||||
}
|
||||
|
||||
public void ApplySideEffects(Entity interactor, World world)
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user