addedAt = new \DateTimeImmutable(); } public function isDown(): bool { return $this->currentHp <= 0; } /** 0-100, for the HP bar. */ public function hpPercent(): int { if ($this->maxHp <= 0) { return 0; } return (int) round(max(0, min($this->currentHp, $this->maxHp)) / $this->maxHp * 100); } public function applyDamage(int $amount): void { $this->currentHp = max(0, $this->currentHp - abs($amount)); } public function applyHealing(int $amount): void { $this->currentHp = min($this->maxHp, $this->currentHp + abs($amount)); } public function getId(): ?int { return $this->id; } public function getEncounter(): ?Encounter { return $this->encounter; } public function setEncounter(?Encounter $encounter): static { $this->encounter = $encounter; return $this; } public function getEnemy(): ?Enemy { return $this->enemy; } public function setEnemy(?Enemy $enemy): static { $this->enemy = $enemy; return $this; } public function getLabel(): string { return $this->label; } public function setLabel(string $label): static { $this->label = $label; return $this; } public function getArmorClass(): int { return $this->armorClass; } public function setArmorClass(int $armorClass): static { $this->armorClass = $armorClass; return $this; } public function getMaxHp(): int { return $this->maxHp; } public function setMaxHp(int $maxHp): static { $this->maxHp = $maxHp; return $this; } public function getCurrentHp(): int { return $this->currentHp; } public function setCurrentHp(int $currentHp): static { $this->currentHp = $currentHp; return $this; } public function getPosition(): int { return $this->position; } public function setPosition(int $position): static { $this->position = $position; return $this; } public function getAddedAt(): \DateTimeImmutable { return $this->addedAt; } }