31 lines
989 B
PHP
31 lines
989 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware\Game;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class CheckInHospital
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
|
*/
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
$character = $request->user()->character;
|
|
|
|
if ($character->isInHospital() || $character->isDead()) {
|
|
$releaseTime = $character->in_hospital_until ? $character->in_hospital_until->diffForHumans() : 'unknown';
|
|
$reviveCost = config('game.health.hospital_cost', 1000);
|
|
|
|
return redirect()->route('game.hospital')
|
|
->with('error', "You are in hospital and cannot perform actions. You will be released {$releaseTime} or can revive for \${$reviveCost}.");
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|