feat: add NerveService and nerve regen scheduled commands

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Doar Mihai
2026-06-28 16:10:26 +03:00
co-authored by Claude Sonnet 4.6
parent e7940d31f6
commit 6e2ea7bcc7
4 changed files with 91 additions and 0 deletions
@@ -0,0 +1,21 @@
<?php
namespace App\Console\Commands\Game;
use App\Services\Game\NerveService;
use Illuminate\Console\Command;
class NerveMidnightRefill extends Command
{
protected $signature = 'game:nerve-midnight-refill';
protected $description = 'Refill nerve to max for all active characters at midnight';
public function handle(NerveService $nerveService): void
{
$this->info('Running midnight nerve refill...');
$count = $nerveService->refillAll();
$this->info("Nerve refilled for {$count} characters.");
}
}
@@ -0,0 +1,31 @@
<?php
namespace App\Console\Commands\Game;
use App\Models\Character;
use App\Services\Game\NerveService;
use Illuminate\Console\Command;
class ProcessNerveRegen extends Command
{
protected $signature = 'game:nerve-regen';
protected $description = 'Regenerate nerve for all active characters';
public function handle(NerveService $nerveService): void
{
$this->info('Starting nerve regeneration...');
$characters = Character::where('nerve', '<', \DB::raw('max_nerve'))
->where('status', 'active')
->get();
$count = $characters->count();
$this->info("Regenerating nerve for {$count} characters...");
foreach ($characters as $character) {
$nerveService->regenerate($character);
}
$this->info('Nerve regeneration completed!');
}
}
+35
View File
@@ -0,0 +1,35 @@
<?php
namespace App\Services\Game;
use App\Models\Character;
class NerveService
{
public function consume(Character $character, int $amount): bool
{
if (!$character->canAct()) {
return false;
}
return $character->consumeNerve($amount);
}
public function regenerate(Character $character): void
{
$regenRate = config('game.nerve.regen_rate', 1);
if ($character->max_nerve <= 0) {
$character->max_nerve = config('game.nerve.max', 100);
}
$character->addNerve($regenRate);
}
public function refillAll(): int
{
return Character::where('nerve', '<', \DB::raw('max_nerve'))
->where('status', 'active')
->update(['nerve' => \DB::raw('max_nerve')]);
}
}
+4
View File
@@ -2,7 +2,11 @@
use Illuminate\Foundation\Inspiring; use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Schedule;
Artisan::command('inspire', function () { Artisan::command('inspire', function () {
$this->comment(Inspiring::quote()); $this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote'); })->purpose('Display an inspiring quote');
Schedule::command('game:nerve-regen')->everyFiveMinutes();
Schedule::command('game:nerve-midnight-refill')->dailyAt('00:00');