first commit

This commit is contained in:
Doar Mihai
2026-06-27 14:38:18 +03:00
commit 96d317480b
165 changed files with 20061 additions and 0 deletions
+111
View File
@@ -0,0 +1,111 @@
<?php
namespace App\Services\Game;
use App\Models\Character;
class HealthService
{
/**
* Regenerate health for a character
*/
public function regenerate(Character $character): void
{
if ($character->isDead()) {
return;
}
$regenRate = config('game.health.regen_rate', 2);
$character->heal($regenRate);
}
/**
* Get the health regen rate
*/
public function getRegenRate(): int
{
return config('game.health.regen_rate', 2);
}
/**
* Get the health regen interval in seconds
*/
public function getRegenInterval(): int
{
return config('game.health.regen_interval', 600);
}
/**
* Heal a character
*/
public function heal(Character $character, int $amount): void
{
$character->heal($amount);
}
/**
* Deal damage to a character
*/
public function damage(Character $character, int $amount): int
{
return $character->takeDamage($amount);
}
/**
* Revive a character from hospital
*/
public function revive(Character $character): bool
{
if (!$character->isDead() && !$character->isInHospital()) {
return false;
}
$cost = config('game.health.hospital_cost', 1000);
if ($character->money < $cost) {
return false;
}
$character->money -= $cost;
$character->health = $character->max_health;
$character->status = 'active';
$character->in_hospital_until = null;
$character->save();
return true;
}
/**
* Send character to hospital
*/
public function sendToHospital(Character $character): void
{
$character->health = 0;
$character->status = 'in_hospital';
$character->in_hospital_until = now()->addSeconds(config('game.health.regen_interval', 600) * 5); // 5 intervals
$character->save();
}
/**
* Restore all health for a character
*/
public function restoreAll(Character $character): void
{
$character->health = $character->max_health;
if ($character->status !== 'active') {
$character->status = 'active';
}
$character->in_hospital_until = null;
$character->save();
}
/**
* Check if character needs hospital
*/
public function needsHospital(Character $character): bool
{
return $character->isDead() || $character->isInHospital();
}
}