a bit of progress
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware\Game;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class CheckCooldown
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, string $actionType): 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');
|
||||
}
|
||||
|
||||
$cooldownService = app(\App\Services\Game\CooldownService::class);
|
||||
|
||||
if ($cooldownService->isOnCooldown($character, $actionType)) {
|
||||
$remaining = $cooldownService->getRemainingCooldown($character, $actionType);
|
||||
return redirect()->back()
|
||||
->with('error', "You must wait {$remaining} seconds before performing this action again.");
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user