47 lines
1.1 KiB
PHP
47 lines
1.1 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
namespace App\Console\Commands\Game;
|
||
|
|
|
||
|
|
use App\Models\Character;
|
||
|
|
use App\Services\Game\EnergyService;
|
||
|
|
use Illuminate\Console\Command;
|
||
|
|
|
||
|
|
class ProcessEnergyRegen extends Command
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* The name and signature of the console command.
|
||
|
|
*
|
||
|
|
* @var string
|
||
|
|
*/
|
||
|
|
protected $signature = 'game:regen-energy';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The console command description.
|
||
|
|
*
|
||
|
|
* @var string
|
||
|
|
*/
|
||
|
|
protected $description = 'Regenerate energy for all characters';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Execute the console command.
|
||
|
|
*/
|
||
|
|
public function handle(EnergyService $energyService): void
|
||
|
|
{
|
||
|
|
$this->info('Starting energy regeneration...');
|
||
|
|
|
||
|
|
$characters = Character::where('energy', '<', \DB::raw('max_energy'))
|
||
|
|
->where('status', 'active')
|
||
|
|
->get();
|
||
|
|
|
||
|
|
$count = $characters->count();
|
||
|
|
|
||
|
|
$this->info("Regenerating energy for {$count} characters...");
|
||
|
|
|
||
|
|
foreach ($characters as $character) {
|
||
|
|
$energyService->regenerate($character);
|
||
|
|
}
|
||
|
|
|
||
|
|
$this->info('Energy regeneration completed!');
|
||
|
|
}
|
||
|
|
}
|