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
@@ -82,6 +82,11 @@ class Crime extends Model
|
|||||||
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;
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,6 +42,11 @@ class CrimeService
|
|||||||
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(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user