From 6e2ea7bcc7df8ac76629e9c9279484ad400fb075 Mon Sep 17 00:00:00 2001 From: Doar Mihai Date: Sun, 28 Jun 2026 16:10:26 +0300 Subject: [PATCH] feat: add NerveService and nerve regen scheduled commands Co-Authored-By: Claude Sonnet 4.6 --- .../Commands/Game/NerveMidnightRefill.php | 21 +++++++++++ .../Commands/Game/ProcessNerveRegen.php | 31 ++++++++++++++++ app/Services/Game/NerveService.php | 35 +++++++++++++++++++ routes/console.php | 4 +++ 4 files changed, 91 insertions(+) create mode 100644 app/Console/Commands/Game/NerveMidnightRefill.php create mode 100644 app/Console/Commands/Game/ProcessNerveRegen.php create mode 100644 app/Services/Game/NerveService.php diff --git a/app/Console/Commands/Game/NerveMidnightRefill.php b/app/Console/Commands/Game/NerveMidnightRefill.php new file mode 100644 index 0000000..6814e85 --- /dev/null +++ b/app/Console/Commands/Game/NerveMidnightRefill.php @@ -0,0 +1,21 @@ +info('Running midnight nerve refill...'); + + $count = $nerveService->refillAll(); + + $this->info("Nerve refilled for {$count} characters."); + } +} diff --git a/app/Console/Commands/Game/ProcessNerveRegen.php b/app/Console/Commands/Game/ProcessNerveRegen.php new file mode 100644 index 0000000..2f07990 --- /dev/null +++ b/app/Console/Commands/Game/ProcessNerveRegen.php @@ -0,0 +1,31 @@ +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!'); + } +} diff --git a/app/Services/Game/NerveService.php b/app/Services/Game/NerveService.php new file mode 100644 index 0000000..8e5bbaa --- /dev/null +++ b/app/Services/Game/NerveService.php @@ -0,0 +1,35 @@ +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')]); + } +} diff --git a/routes/console.php b/routes/console.php index 3c9adf1..872b817 100644 --- a/routes/console.php +++ b/routes/console.php @@ -2,7 +2,11 @@ use Illuminate\Foundation\Inspiring; use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Schedule; Artisan::command('inspire', function () { $this->comment(Inspiring::quote()); })->purpose('Display an inspiring quote'); + +Schedule::command('game:nerve-regen')->everyFiveMinutes(); +Schedule::command('game:nerve-midnight-refill')->dailyAt('00:00');