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
+8 -3
View File
@@ -76,17 +76,22 @@ class Crime extends Model
if ($this->requires_level && $character->level < $this->requires_level) { if ($this->requires_level && $character->level < $this->requires_level) {
return false; return false;
} }
// Check energy // Check energy
if ($character->energy < $this->energy_cost) { if ($character->energy < $this->energy_cost) {
return false; return false;
} }
// Check nerve
if ($character->nerve < $this->nerve_cost) {
return false;
}
// Check location (if crime is location-specific) // Check location (if crime is location-specific)
if ($this->location_id && $character->location_id !== $this->location_id) { if ($this->location_id && $character->location_id !== $this->location_id) {
return false; return false;
} }
return true; return true;
} }
+10 -1
View File
@@ -7,16 +7,19 @@ use App\Models\Crime;
use App\Models\CrimeAttempt; use App\Models\CrimeAttempt;
use App\Models\ActivityLog; use App\Models\ActivityLog;
use App\Enums\CharacterStatus; use App\Enums\CharacterStatus;
use App\Services\Game\NerveService;
class CrimeService class CrimeService
{ {
protected EnergyService $energyService; protected EnergyService $energyService;
protected EconomyService $economyService; protected EconomyService $economyService;
protected NerveService $nerveService;
public function __construct() public function __construct()
{ {
$this->energyService = new EnergyService(); $this->energyService = new EnergyService();
$this->economyService = new EconomyService(); $this->economyService = new EconomyService();
$this->nerveService = new NerveService();
} }
/** /**
@@ -38,7 +41,12 @@ class CrimeService
if (!$this->energyService->consume($character, $crime->energy_cost, 'crime')) { if (!$this->energyService->consume($character, $crime->energy_cost, 'crime')) {
throw new \Exception('Not enough energy to attempt this 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 // Calculate success rate
$successRate = $crime->calculateSuccessRate($character); $successRate = $crime->calculateSuccessRate($character);
$isSuccess = random_int(0, 9999) / 10000 <= $successRate; $isSuccess = random_int(0, 9999) / 10000 <= $successRate;
@@ -77,6 +85,7 @@ class CrimeService
'success' => $isSuccess, 'success' => $isSuccess,
'reward' => $reward, 'reward' => $reward,
'experience_gained' => $experience, 'experience_gained' => $experience,
'nerve_cost' => $crime->nerve_cost,
'attempted_at' => now(), 'attempted_at' => now(),
]); ]);