feat: wire nerve check and deduction into crime attempts
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
0e8ece64c3
commit
310dfd4129
@@ -7,16 +7,19 @@ use App\Models\Crime;
|
||||
use App\Models\CrimeAttempt;
|
||||
use App\Models\ActivityLog;
|
||||
use App\Enums\CharacterStatus;
|
||||
use App\Services\Game\NerveService;
|
||||
|
||||
class CrimeService
|
||||
{
|
||||
protected EnergyService $energyService;
|
||||
protected EconomyService $economyService;
|
||||
protected NerveService $nerveService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->energyService = new EnergyService();
|
||||
$this->economyService = new EconomyService();
|
||||
$this->nerveService = new NerveService();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,7 +41,12 @@ class CrimeService
|
||||
if (!$this->energyService->consume($character, $crime->energy_cost, 'crime')) {
|
||||
throw new \Exception('Not enough energy to attempt this crime.');
|
||||
}
|
||||
|
||||
|
||||
// Consume nerve
|
||||
if (!$this->nerveService->consume($character, $crime->nerve_cost)) {
|
||||
throw new \Exception('Not enough nerve to attempt this crime.');
|
||||
}
|
||||
|
||||
// Calculate success rate
|
||||
$successRate = $crime->calculateSuccessRate($character);
|
||||
$isSuccess = random_int(0, 9999) / 10000 <= $successRate;
|
||||
@@ -77,6 +85,7 @@ class CrimeService
|
||||
'success' => $isSuccess,
|
||||
'reward' => $reward,
|
||||
'experience_gained' => $experience,
|
||||
'nerve_cost' => $crime->nerve_cost,
|
||||
'attempted_at' => now(),
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user