refactor: restructure interaction system into clean layers
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
using Game.Features.Interactions.Contracts;
|
||||
|
||||
namespace Game.Features.Interactions.Application;
|
||||
|
||||
public sealed class Interact(IInteractionRegistry registry) : IInteractionHandler
|
||||
{
|
||||
public InteractionResult TryInteract(InteractionRequest request)
|
||||
{
|
||||
if (!registry.TryGetTarget(request.TargetId, out IInteractionTarget target))
|
||||
{
|
||||
return InteractionResult.Fail(InteractionStatus.TargetNotFound, $"Target {request.TargetId} was not found.");
|
||||
}
|
||||
|
||||
if (!target.CanInteract)
|
||||
{
|
||||
return InteractionResult.Fail(InteractionStatus.Unavailable, "The target is not currently available.");
|
||||
}
|
||||
|
||||
return target.Execute(request.PlayerId);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
using Game.Features.Interactions.Contracts;
|
||||
|
||||
namespace Game.Features.Interactions.Application;
|
||||
|
||||
public sealed class InteractionService(IInteractionWorld world) : IInteractionService
|
||||
{
|
||||
public InteractionResult TryInteract(InteractionRequest request) => world.TryInteract(request);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Game.Features.Items.Contracts;
|
||||
|
||||
namespace Game.Features.Interactions.Application;
|
||||
|
||||
public readonly record struct PickupAvailability(bool LeftHand, bool RightHand, bool RequiresBoth);
|
||||
|
||||
public sealed class ResolvePickupAvailability
|
||||
{
|
||||
public PickupAvailability Resolve(HandRequirement requirement, bool leftHandFree, bool rightHandFree)
|
||||
{
|
||||
if (requirement == HandRequirement.Both)
|
||||
{
|
||||
bool canUseBoth = leftHandFree && rightHandFree;
|
||||
return new PickupAvailability(canUseBoth, canUseBoth, true);
|
||||
}
|
||||
|
||||
return new PickupAvailability(leftHandFree, rightHandFree, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://c6mhpn06a47qu
|
||||
Reference in New Issue
Block a user