Files
thecrimesynticate/app/Http/Controllers/Game/GymController.php
T

51 lines
1.6 KiB
PHP

<?php
namespace App\Http\Controllers\Game;
use App\Http\Controllers\Controller;
use App\Services\Game\TrainingService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class GymController extends Controller
{
protected TrainingService $trainingService;
public function __construct()
{
$this->trainingService = new TrainingService();
}
public function index(Request $request): View
{
$character = $request->user()->character;
$dailyCap = config('game.gym.daily_cap', 5);
$energyCost = config('game.gym.energy_cost', 20);
$stats = [];
foreach (['strength', 'defense', 'speed', 'dexterity'] as $stat) {
$stats[$stat] = [
'value' => $character->$stat,
'sessions_today' => $this->trainingService->getSessionsToday($character, $stat),
'sessions_remaining'=> $this->trainingService->getSessionsRemaining($character, $stat),
];
}
return view('game.gym.index', compact('character', 'stats', 'energyCost', 'dailyCap'));
}
public function train(Request $request): RedirectResponse
{
$request->validate(['stat' => 'required|in:strength,defense,speed,dexterity']);
$character = $request->user()->character;
$result = $this->trainingService->train($character, $request->stat);
if ($result['success']) {
return redirect()->route('game.gym.index')->with('success', $result['message']);
}
return redirect()->route('game.gym.index')->with('error', $result['message']);
}
}