*/ class CharacterFactory extends Factory { /** * Define the model's default state. * * @return array */ public function definition(): array { $genders = ['male', 'female', 'other']; return [ 'name' => $this->faker->unique()->firstName() . ' ' . $this->faker->lastName(), 'gender' => $genders[array_rand($genders)], 'level' => $this->faker->numberBetween(1, 10), 'experience' => $this->faker->numberBetween(0, 5000), 'money' => $this->faker->numberBetween(1000, 50000), 'bank' => $this->faker->numberBetween(0, 100000), 'energy' => $this->faker->numberBetween(50, 100), 'max_energy' => 100, 'health' => $this->faker->numberBetween(50, 100), 'max_health' => 100, 'strength' => $this->faker->numberBetween(5, 20), 'defense' => $this->faker->numberBetween(5, 20), 'speed' => $this->faker->numberBetween(5, 20), 'dexterity' => $this->faker->numberBetween(5, 20), 'location_id' => Location::factory(), 'faction_id' => null, 'in_hospital_until' => null, 'in_jail_until' => null, 'last_action_at' => now(), 'status' => CharacterStatus::ACTIVE, ]; } /** * Create a character with specific stats. */ public function withStats(int $strength, int $defense, int $speed, int $dexterity): static { return $this->state(fn (array $attributes) => [ 'strength' => $strength, 'defense' => $defense, 'speed' => $speed, 'dexterity' => $dexterity, ]); } /** * Create a character at a specific level. */ public function atLevel(int $level): static { $experience = 0; if ($level > 1) { $base = config('game.leveling.exp_per_level', 1000); $multiplier = config('game.leveling.exp_multiplier', 1.20); for ($i = 2; $i <= $level; $i++) { $experience += (int) ($base * pow($multiplier, $i - 2)); } // Add some extra to be in the middle of the level $experience += (int) ($base * pow($multiplier, $level - 1) * 0.5); } return $this->state(fn (array $attributes) => [ 'level' => $level, 'experience' => $experience, 'max_health' => 100 + (($level - 1) * 5), 'max_energy' => 100 + (($level - 1) * 5), ]); } /** * Create a character with full health and energy. */ public function fresh(): static { return $this->state(fn (array $attributes) => [ 'health' => $attributes['max_health'] ?? 100, 'energy' => $attributes['max_energy'] ?? 100, ]); } /** * Create a character in hospital. */ public function inHospital(): static { return $this->state(fn (array $attributes) => [ 'health' => 1, 'status' => CharacterStatus::IN_HOSPITAL, 'in_hospital_until' => now()->addHours(1), ]); } /** * Create a dead character. */ public function dead(): static { return $this->state(fn (array $attributes) => [ 'health' => 0, 'status' => CharacterStatus::DEAD, ]); } /** * Create a character in jail. */ public function inJail(): static { return $this->state(fn (array $attributes) => [ 'status' => CharacterStatus::IN_JAIL, 'in_jail_until' => now()->addHours(1), ]); } }