Refactor of health int -> float and fixed armor being useless when

computed damage reduction is less than 1
This commit is contained in:
Dylan K. Taylor
2017-08-30 11:03:07 +01:00
parent ea5bd0348a
commit fd52022065
8 changed files with 61 additions and 71 deletions

View File

@ -300,8 +300,8 @@ abstract class Entity extends Location implements Metadatable{
/** @var float */
protected $baseOffset = 0.0;
/** @var int */
private $health = 20;
/** @var float */
private $health = 20.0;
private $maxHealth = 20;
/** @var float */
@ -921,9 +921,9 @@ abstract class Entity extends Location implements Metadatable{
}
/**
* @return int
* @return float
*/
public function getHealth(){
public function getHealth() : float{
return $this->health;
}
@ -934,11 +934,10 @@ abstract class Entity extends Location implements Metadatable{
/**
* Sets the health of the Entity. This won't send any update to the players
*
* @param int $amount
* @param float $amount
*/
public function setHealth($amount){
$amount = (int) $amount;
if($amount === $this->health){
public function setHealth(float $amount){
if($amount == $this->health){
return;
}
@ -947,7 +946,7 @@ abstract class Entity extends Location implements Metadatable{
$this->kill();
}
}elseif($amount <= $this->getMaxHealth() or $amount < $this->health){
$this->health = (int) $amount;
$this->health = $amount;
}else{
$this->health = $this->getMaxHealth();
}
@ -982,15 +981,15 @@ abstract class Entity extends Location implements Metadatable{
/**
* @return int
*/
public function getMaxHealth(){
public function getMaxHealth() : int{
return $this->maxHealth;
}
/**
* @param int $amount
*/
public function setMaxHealth($amount){
$this->maxHealth = (int) $amount;
public function setMaxHealth(int $amount){
$this->maxHealth = $amount;
}
public function canCollideWith(Entity $entity) : bool{