Files
thecrimesynticate/app/Models/Location.php
T
2026-06-27 14:38:18 +03:00

85 lines
1.9 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* @property int $id
* @property string $name
* @property string $slug
* @property string|null $description
* @property int $travel_cost
* @property int|null $requires_level
* @property int|null $faction_control
* @property \Illuminate\Support\Carbon $created_at
* @property \Illuminate\Support\Carbon $updated_at
*/
class Location extends Model
{
use HasFactory;
protected $fillable = [
'name',
'slug',
'description',
'travel_cost',
'requires_level',
'faction_control',
];
/**
* Get the characters at this location.
*/
public function characters(): HasMany
{
return $this->hasMany(Character::class);
}
/**
* Get the shops at this location.
*/
public function shops(): HasMany
{
return $this->hasMany(Shop::class);
}
/**
* Get the crimes available at this location.
*/
public function crimes(): HasMany
{
return $this->hasMany(Crime::class);
}
/**
* Check if a character can travel to this location
*/
public function canTravel(Character $character): bool
{
// Check level requirement
if ($this->requires_level && $character->level < $this->requires_level) {
return false;
}
// Check if character has enough money
if ($character->money < $this->travel_cost) {
return false;
}
return true;
}
/**
* Get the travel cost from another location to this one
*/
public function getTravelCostFrom(Location $from): int
{
// For now, just use this location's travel cost
// In a more advanced system, we'd calculate based on distance
return $this->travel_cost;
}
}