feat: add NerveService and nerve regen scheduled commands
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
e7940d31f6
commit
6e2ea7bcc7
@@ -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')]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user