46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
namespace App\Http\Middleware\Game;
|
||
|
|
|
||
|
|
use Closure;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use Symfony\Component\HttpFoundation\Response;
|
||
|
|
|
||
|
|
class CheckAlive
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Handle an incoming request.
|
||
|
|
*
|
||
|
|
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||
|
|
*/
|
||
|
|
public function handle(Request $request, Closure $next): Response
|
||
|
|
{
|
||
|
|
// Check if user is authenticated
|
||
|
|
if (!$request->user()) {
|
||
|
|
return redirect()->route('login');
|
||
|
|
}
|
||
|
|
|
||
|
|
// Check if user has a character
|
||
|
|
$character = $request->user()->character;
|
||
|
|
|
||
|
|
if (!$character) {
|
||
|
|
return redirect()->route('game.character.create');
|
||
|
|
}
|
||
|
|
|
||
|
|
// Check if character is alive and can act
|
||
|
|
if (!$character->isAlive() || !$character->canAct()) {
|
||
|
|
if ($character->isInHospital()) {
|
||
|
|
return redirect()->route('game.hospital');
|
||
|
|
}
|
||
|
|
if ($character->isDead()) {
|
||
|
|
return redirect()->route('game.hospital');
|
||
|
|
}
|
||
|
|
return redirect()->route('game.dashboard')
|
||
|
|
->with('error', 'Your character cannot perform actions right now.');
|
||
|
|
}
|
||
|
|
|
||
|
|
// Character is alive and can act, proceed with request
|
||
|
|
return $next($request);
|
||
|
|
}
|
||
|
|
}
|