CrimeDifficulty::class, 'success_rate' => 'float', ]; /** * Get the location where this crime can be committed. */ public function location(): BelongsTo { return $this->belongsTo(Location::class); } /** * Get the crime attempts for this crime. */ public function attempts(): HasMany { return $this->hasMany(CrimeAttempt::class); } /** * Check if a character can attempt this crime */ public function canBeAttemptedBy(Character $character): bool { // Check level requirement if ($this->requires_level && $character->level < $this->requires_level) { return false; } // Check energy if ($character->energy < $this->energy_cost) { return false; } // Check nerve if ($character->nerve < $this->nerve_cost) { return false; } // Check location (if crime is location-specific) if ($this->location_id && $character->location_id !== $this->location_id) { return false; } return true; } /** * Calculate the success rate for a specific character */ public function calculateSuccessRate(Character $character): float { $baseRate = $this->success_rate; $difficultyModifier = $this->difficulty->successModifier(); $levelModifier = $character->level * 0.01; // +1% per level $rate = $baseRate + $difficultyModifier + $levelModifier; // Clamp between 10% and 95% return max(0.10, min(0.95, $rate)); } /** * Calculate the reward for a successful crime */ public function calculateReward(Character $character): int { $baseReward = random_int($this->reward_min, $this->reward_max); $difficultyMultiplier = $this->difficulty->rewardMultiplier(); $levelMultiplier = 1 + ($character->level * 0.01); // +1% per level return (int) ($baseReward * $difficultyMultiplier * $levelMultiplier); } /** * Calculate the experience reward */ public function calculateExperience(Character $character): int { $baseExp = $this->experience; $levelMultiplier = 1 + ($character->level * 0.01); return (int) ($baseExp * $levelMultiplier); } /** * Get the display name for the difficulty */ public function getDifficultyLabelAttribute(): string { return $this->difficulty->label(); } /** * Get the color class for the difficulty badge */ public function getDifficultyColorAttribute(): string { return $this->difficulty->color(); } }