first commit
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Auth\LoginRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class AuthenticatedSessionController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the login view.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming authentication request.
|
||||
*/
|
||||
public function store(LoginRequest $request): RedirectResponse
|
||||
{
|
||||
$request->authenticate();
|
||||
|
||||
$request->session()->regenerate();
|
||||
|
||||
return redirect()->intended(route('dashboard', absolute: false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy an authenticated session.
|
||||
*/
|
||||
public function destroy(Request $request): RedirectResponse
|
||||
{
|
||||
Auth::guard('web')->logout();
|
||||
|
||||
$request->session()->invalidate();
|
||||
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return redirect('/');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ConfirmablePasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show the confirm password view.
|
||||
*/
|
||||
public function show(): View
|
||||
{
|
||||
return view('auth.confirm-password');
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm the user's password.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
if (! Auth::guard('web')->validate([
|
||||
'email' => $request->user()->email,
|
||||
'password' => $request->password,
|
||||
])) {
|
||||
throw ValidationException::withMessages([
|
||||
'password' => __('auth.password'),
|
||||
]);
|
||||
}
|
||||
|
||||
$request->session()->put('auth.password_confirmed_at', time());
|
||||
|
||||
return redirect()->intended(route('dashboard', absolute: false));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EmailVerificationNotificationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Send a new email verification notification.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(route('dashboard', absolute: false));
|
||||
}
|
||||
|
||||
$request->user()->sendEmailVerificationNotification();
|
||||
|
||||
return back()->with('status', 'verification-link-sent');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class EmailVerificationPromptController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the email verification prompt.
|
||||
*/
|
||||
public function __invoke(Request $request): RedirectResponse|View
|
||||
{
|
||||
return $request->user()->hasVerifiedEmail()
|
||||
? redirect()->intended(route('dashboard', absolute: false))
|
||||
: view('auth.verify-email');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Events\PasswordReset;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class NewPasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset view.
|
||||
*/
|
||||
public function create(Request $request): View
|
||||
{
|
||||
return view('auth.reset-password', ['request' => $request]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming new password request.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'token' => ['required'],
|
||||
'email' => ['required', 'email'],
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
// Here we will attempt to reset the user's password. If it is successful we
|
||||
// will update the password on an actual user model and persist it to the
|
||||
// database. Otherwise we will parse the error and return the response.
|
||||
$status = Password::reset(
|
||||
$request->only('email', 'password', 'password_confirmation', 'token'),
|
||||
function (User $user) use ($request) {
|
||||
$user->forceFill([
|
||||
'password' => Hash::make($request->password),
|
||||
'remember_token' => Str::random(60),
|
||||
])->save();
|
||||
|
||||
event(new PasswordReset($user));
|
||||
}
|
||||
);
|
||||
|
||||
// If the password was successfully reset, we will redirect the user back to
|
||||
// the application's home authenticated view. If there is an error we can
|
||||
// redirect them back to where they came from with their error message.
|
||||
return $status == Password::PASSWORD_RESET
|
||||
? redirect()->route('login')->with('status', __($status))
|
||||
: back()->withInput($request->only('email'))
|
||||
->withErrors(['email' => __($status)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class PasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Update the user's password.
|
||||
*/
|
||||
public function update(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validateWithBag('updatePassword', [
|
||||
'current_password' => ['required', 'current_password'],
|
||||
'password' => ['required', Password::defaults(), 'confirmed'],
|
||||
]);
|
||||
|
||||
$request->user()->update([
|
||||
'password' => Hash::make($validated['password']),
|
||||
]);
|
||||
|
||||
return back()->with('status', 'password-updated');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Password;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class PasswordResetLinkController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the password reset link request view.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.forgot-password');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming password reset link request.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'email' => ['required', 'email'],
|
||||
]);
|
||||
|
||||
// We will send the password reset link to this user. Once we have attempted
|
||||
// to send the link, we will examine the response then see the message we
|
||||
// need to show to the user. Finally, we'll send out a proper response.
|
||||
$status = Password::sendResetLink(
|
||||
$request->only('email')
|
||||
);
|
||||
|
||||
return $status == Password::RESET_LINK_SENT
|
||||
? back()->with('status', __($status))
|
||||
: back()->withInput($request->only('email'))
|
||||
->withErrors(['email' => __($status)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class RegisteredUserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the registration view.
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('auth.register');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming registration request.
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
$user = User::create([
|
||||
'name' => $request->name,
|
||||
'email' => $request->email,
|
||||
'password' => Hash::make($request->password),
|
||||
]);
|
||||
|
||||
event(new Registered($user));
|
||||
|
||||
Auth::login($user);
|
||||
|
||||
return redirect(route('dashboard', absolute: false));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Auth\Events\Verified;
|
||||
use Illuminate\Foundation\Auth\EmailVerificationRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
class VerifyEmailController extends Controller
|
||||
{
|
||||
/**
|
||||
* Mark the authenticated user's email address as verified.
|
||||
*/
|
||||
public function __invoke(EmailVerificationRequest $request): RedirectResponse
|
||||
{
|
||||
if ($request->user()->hasVerifiedEmail()) {
|
||||
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
|
||||
}
|
||||
|
||||
if ($request->user()->markEmailAsVerified()) {
|
||||
event(new Verified($request->user()));
|
||||
}
|
||||
|
||||
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Game;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Character;
|
||||
use App\Models\Location;
|
||||
use App\Models\ActivityLog;
|
||||
use App\Services\Game\EconomyService;
|
||||
use App\Services\Game\EnergyService;
|
||||
use App\Services\Game\HealthService;
|
||||
use App\Services\Game\NotificationService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class CharacterController extends Controller
|
||||
{
|
||||
protected EconomyService $economyService;
|
||||
protected EnergyService $energyService;
|
||||
protected HealthService $healthService;
|
||||
protected NotificationService $notificationService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->economyService = new EconomyService();
|
||||
$this->energyService = new EnergyService();
|
||||
$this->healthService = new HealthService();
|
||||
$this->notificationService = new NotificationService();
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the character creation form
|
||||
*/
|
||||
public function create(Request $request): View
|
||||
{
|
||||
$genders = ['male', 'female', 'other'];
|
||||
$locations = Location::orderBy('name')->get();
|
||||
|
||||
return view('game.character.create', compact('genders', 'locations'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created character
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'name' => ['required', 'string', 'max:50', 'unique:characters,name'],
|
||||
'gender' => ['required', 'string', 'in:male,female,other'],
|
||||
'location_id' => ['required', 'exists:locations,id'],
|
||||
]);
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
// Check if user already has a character
|
||||
if ($user->character) {
|
||||
return redirect()->route('game.dashboard')
|
||||
->with('error', 'You already have a character!');
|
||||
}
|
||||
|
||||
// Create the character
|
||||
$character = Character::create([
|
||||
'user_id' => $user->id,
|
||||
'name' => $validated['name'],
|
||||
'gender' => $validated['gender'],
|
||||
'location_id' => $validated['location_id'],
|
||||
'level' => 1,
|
||||
'experience' => 0,
|
||||
'money' => $this->economyService->getStartingMoney(),
|
||||
'bank' => $this->economyService->getStartingBank(),
|
||||
'energy' => config('game.energy.start_amount', 100),
|
||||
'max_energy' => config('game.energy.max', 100),
|
||||
'health' => config('game.health.start_amount', 100),
|
||||
'max_health' => config('game.health.max', 100),
|
||||
'strength' => 5,
|
||||
'defense' => 5,
|
||||
'speed' => 5,
|
||||
'dexterity' => 5,
|
||||
'status' => 'active',
|
||||
'last_action_at' => now(),
|
||||
]);
|
||||
|
||||
// Log character creation
|
||||
ActivityLog::logCharacterCreated($character);
|
||||
|
||||
return redirect()->route('game.dashboard')
|
||||
->with('success', 'Character created successfully! Welcome to the game.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the character profile
|
||||
*/
|
||||
public function show(Request $request): View
|
||||
{
|
||||
$character = $request->user()->character;
|
||||
|
||||
if (!$character) {
|
||||
return redirect()->route('game.character.create');
|
||||
}
|
||||
|
||||
return view('game.character.show', compact('character'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the character edit form
|
||||
*/
|
||||
public function edit(Request $request): View
|
||||
{
|
||||
$character = $request->user()->character;
|
||||
|
||||
if (!$character) {
|
||||
return redirect()->route('game.character.create');
|
||||
}
|
||||
|
||||
return view('game.character.edit', compact('character'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the character
|
||||
*/
|
||||
public function update(Request $request): RedirectResponse
|
||||
{
|
||||
$character = $request->user()->character;
|
||||
|
||||
if (!$character) {
|
||||
return redirect()->route('game.character.create');
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'name' => ['sometimes', 'string', 'max:50', 'unique:characters,name,'.$character->id],
|
||||
'gender' => ['sometimes', 'string', 'in:male,female,other'],
|
||||
]);
|
||||
|
||||
$character->update($validated);
|
||||
|
||||
return redirect()->route('game.character.show')
|
||||
->with('success', 'Character updated successfully!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Deposit money to bank
|
||||
*/
|
||||
public function deposit(Request $request): RedirectResponse
|
||||
{
|
||||
$character = $request->user()->character;
|
||||
|
||||
$validated = $request->validate([
|
||||
'amount' => ['required', 'integer', 'min:1'],
|
||||
]);
|
||||
|
||||
if ($this->economyService->depositToBank($character, $validated['amount'])) {
|
||||
return redirect()->back()
|
||||
->with('success', 'Money deposited to bank successfully!');
|
||||
}
|
||||
|
||||
return redirect()->back()
|
||||
->with('error', 'Failed to deposit money. You may not have enough money or reached the bank limit.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Withdraw money from bank
|
||||
*/
|
||||
public function withdraw(Request $request): RedirectResponse
|
||||
{
|
||||
$character = $request->user()->character;
|
||||
|
||||
$validated = $request->validate([
|
||||
'amount' => ['required', 'integer', 'min:1'],
|
||||
]);
|
||||
|
||||
if ($this->economyService->withdrawFromBank($character, $validated['amount'])) {
|
||||
return redirect()->back()
|
||||
->with('success', 'Money withdrawn from bank successfully!');
|
||||
}
|
||||
|
||||
return redirect()->back()
|
||||
->with('error', 'Failed to withdraw money. You may not have enough in your bank.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Revive character from hospital
|
||||
*/
|
||||
public function revive(Request $request): RedirectResponse
|
||||
{
|
||||
$character = $request->user()->character;
|
||||
|
||||
if (!$character->isDead() && !$character->isInHospital()) {
|
||||
return redirect()->route('game.dashboard')
|
||||
->with('error', 'Your character is not in hospital.');
|
||||
}
|
||||
|
||||
if ($this->healthService->revive($character)) {
|
||||
$this->notificationService->sendCharacterRevived($request->user(), $character);
|
||||
|
||||
return redirect()->route('game.dashboard')
|
||||
->with('success', 'Character revived successfully!');
|
||||
}
|
||||
|
||||
return redirect()->route('game.dashboard')
|
||||
->with('error', 'Failed to revive character. You may not have enough money.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Game;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Crime;
|
||||
use App\Models\CrimeAttempt;
|
||||
use App\Services\Game\CrimeService;
|
||||
use App\Services\Game\EnergyService;
|
||||
use App\Services\Game\NotificationService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class CrimeController extends Controller
|
||||
{
|
||||
protected CrimeService $crimeService;
|
||||
protected EnergyService $energyService;
|
||||
protected NotificationService $notificationService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->crimeService = new CrimeService();
|
||||
$this->energyService = new EnergyService();
|
||||
$this->notificationService = new NotificationService();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of available crimes
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$character = $request->user()->character;
|
||||
|
||||
if (!$character) {
|
||||
return redirect()->route('game.character.create');
|
||||
}
|
||||
|
||||
$availableCrimes = $this->crimeService->getAvailableCrimes($character);
|
||||
$recentAttempts = $this->crimeService->getRecentAttempts($character, 5);
|
||||
|
||||
return view('game.crimes.index', compact('character', 'availableCrimes', 'recentAttempts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to commit a crime
|
||||
*/
|
||||
public function attempt(Request $request, Crime $crime): RedirectResponse
|
||||
{
|
||||
$character = $request->user()->character;
|
||||
|
||||
if (!$character) {
|
||||
return redirect()->route('game.character.create');
|
||||
}
|
||||
|
||||
try {
|
||||
$attempt = $this->crimeService->attemptCrime($character, $crime);
|
||||
|
||||
if ($attempt->isSuccessful()) {
|
||||
$this->notificationService->sendCrimeSuccess($request->user(), $crime, $attempt->reward);
|
||||
return redirect()->route('game.crimes.index')
|
||||
->with('success', 'Crime successful! You earned $'.$attempt->reward);
|
||||
} else {
|
||||
$this->notificationService->sendCrimeFailure($request->user(), $crime);
|
||||
return redirect()->route('game.crimes.index')
|
||||
->with('error', 'Crime failed! You took damage.');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return redirect()->route('game.crimes.index')
|
||||
->with('error', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show crime details
|
||||
*/
|
||||
public function show(Request $request, Crime $crime): View
|
||||
{
|
||||
$character = $request->user()->character;
|
||||
|
||||
if (!$character) {
|
||||
return redirect()->route('game.character.create');
|
||||
}
|
||||
|
||||
// Check if crime is on cooldown
|
||||
$onCooldown = $this->crimeService->isOnCooldown($character, $crime);
|
||||
$cooldownRemaining = $onCooldown ? $this->crimeService->getCooldownRemaining($character, $crime) : 0;
|
||||
|
||||
// Calculate success rate for this character
|
||||
$successRate = $crime->calculateSuccessRate($character);
|
||||
|
||||
return view('game.crimes.show', compact('character', 'crime', 'onCooldown', 'cooldownRemaining', 'successRate'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Game;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ActivityLog;
|
||||
use App\Models\Notification;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the game dashboard
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$character = $request->user()->character;
|
||||
|
||||
if (!$character) {
|
||||
return redirect()->route('game.character.create');
|
||||
}
|
||||
|
||||
// Get recent activity logs
|
||||
$recentActivity = ActivityLog::where('character_id', $character->id)
|
||||
->latest()
|
||||
->take(10)
|
||||
->get();
|
||||
|
||||
// Get unread notifications
|
||||
$unreadNotifications = $request->user()->notifications()
|
||||
->whereNull('read_at')
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
|
||||
return view('game.dashboard', compact('character', 'recentActivity', 'unreadNotifications'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Game;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Inventory;
|
||||
use App\Models\Item;
|
||||
use App\Services\Game\EconomyService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class InventoryController extends Controller
|
||||
{
|
||||
protected EconomyService $economyService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->economyService = new EconomyService();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the character's inventory
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$character = $request->user()->character;
|
||||
|
||||
if (!$character) {
|
||||
return redirect()->route('game.character.create');
|
||||
}
|
||||
|
||||
$inventory = $character->inventory()->with('item')->get();
|
||||
|
||||
return view('game.inventory.index', compact('character', 'inventory'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Equip an item
|
||||
*/
|
||||
public function equip(Request $request, Inventory $inventory): RedirectResponse
|
||||
{
|
||||
$character = $request->user()->character;
|
||||
|
||||
if (!$character || $inventory->character_id !== $character->id) {
|
||||
return redirect()->route('game.inventory.index')
|
||||
->with('error', 'Unauthorized action.');
|
||||
}
|
||||
|
||||
if ($inventory->equip()) {
|
||||
return redirect()->route('game.inventory.index')
|
||||
->with('success', 'Item equipped successfully!');
|
||||
}
|
||||
|
||||
return redirect()->route('game.inventory.index')
|
||||
->with('error', 'Cannot equip this item.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Unequip an item
|
||||
*/
|
||||
public function unequip(Request $request, Inventory $inventory): RedirectResponse
|
||||
{
|
||||
$character = $request->user()->character;
|
||||
|
||||
if (!$character || $inventory->character_id !== $character->id) {
|
||||
return redirect()->route('game.inventory.index')
|
||||
->with('error', 'Unauthorized action.');
|
||||
}
|
||||
|
||||
$inventory->unequip();
|
||||
|
||||
return redirect()->route('game.inventory.index')
|
||||
->with('success', 'Item unequipped successfully!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Use an item
|
||||
*/
|
||||
public function use(Request $request, Inventory $inventory): RedirectResponse
|
||||
{
|
||||
$character = $request->user()->character;
|
||||
|
||||
if (!$character || $inventory->character_id !== $character->id) {
|
||||
return redirect()->route('game.inventory.index')
|
||||
->with('error', 'Unauthorized action.');
|
||||
}
|
||||
|
||||
if ($inventory->use($character)) {
|
||||
return redirect()->route('game.inventory.index')
|
||||
->with('success', 'Item used successfully!');
|
||||
}
|
||||
|
||||
return redirect()->route('game.inventory.index')
|
||||
->with('error', 'Cannot use this item.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop an item
|
||||
*/
|
||||
public function drop(Request $request, Inventory $inventory): RedirectResponse
|
||||
{
|
||||
$character = $request->user()->character;
|
||||
|
||||
if (!$character || $inventory->character_id !== $character->id) {
|
||||
return redirect()->route('game.inventory.index')
|
||||
->with('error', 'Unauthorized action.');
|
||||
}
|
||||
|
||||
$validated = $request->validate([
|
||||
'quantity' => ['required', 'integer', 'min:1', 'max:'.$inventory->quantity],
|
||||
]);
|
||||
|
||||
if ($inventory->remove($validated['quantity'])) {
|
||||
return redirect()->route('game.inventory.index')
|
||||
->with('success', 'Item dropped successfully!');
|
||||
}
|
||||
|
||||
return redirect()->route('game.inventory.index')
|
||||
->with('error', 'Failed to drop item.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\ProfileUpdateRequest;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display the user's profile form.
|
||||
*/
|
||||
public function edit(Request $request): View
|
||||
{
|
||||
return view('profile.edit', [
|
||||
'user' => $request->user(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the user's profile information.
|
||||
*/
|
||||
public function update(ProfileUpdateRequest $request): RedirectResponse
|
||||
{
|
||||
$request->user()->fill($request->validated());
|
||||
|
||||
if ($request->user()->isDirty('email')) {
|
||||
$request->user()->email_verified_at = null;
|
||||
}
|
||||
|
||||
$request->user()->save();
|
||||
|
||||
return Redirect::route('profile.edit')->with('status', 'profile-updated');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the user's account.
|
||||
*/
|
||||
public function destroy(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validateWithBag('userDeletion', [
|
||||
'password' => ['required', 'current_password'],
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
|
||||
Auth::logout();
|
||||
|
||||
$user->delete();
|
||||
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return Redirect::to('/');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user