energyService = $energyService; } /** * Handle an incoming request. * * @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next */ public function handle(Request $request, Closure $next, string $action = 'default'): Response { $character = $request->user()->character; // Check if character can act if (!$character->canAct()) { return redirect()->route('game.dashboard') ->with('error', 'You cannot perform actions right now.'); } // Get energy cost for this action type $cost = $this->energyService->getCostFor($action); // Check if character has enough energy if (!$character->hasEnergy($cost)) { return redirect()->route('game.dashboard') ->with('error', "You don't have enough energy ({$cost} required) for this action."); } return $next($request); } }