feat: wire nerve check and deduction into crime attempts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Doar Mihai
2026-06-28 16:25:32 +03:00
co-authored by Claude Sonnet 4.6
parent 0e8ece64c3
commit 310dfd4129
2 changed files with 18 additions and 4 deletions
+10 -1
View File
@@ -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(),
]);