Change air tank regeneration to match UA (#2396)

This commit is contained in:
Dylan K. Taylor 2018-08-22 19:10:53 +01:00 committed by GitHub
parent 8daf3dc8b4
commit bea634a9b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -665,13 +665,8 @@ abstract class Living extends Entity implements Damageable{
$this->attack($ev); $this->attack($ev);
} }
if(!$this->canBreathe()){ if($this->doAirSupplyTick($tickDiff)){
$this->setBreathing(false);
$this->doAirSupplyTick($tickDiff);
$hasUpdate = true; $hasUpdate = true;
}elseif(!$this->isBreathing()){
$this->setBreathing(true);
$this->setAirSupplyTicks($this->getMaxAirSupplyTicks());
} }
} }
@ -700,22 +695,42 @@ abstract class Living extends Entity implements Damageable{
} }
/** /**
* Ticks the entity's air supply when it cannot breathe. * Ticks the entity's air supply, consuming it when underwater and regenerating it when out of water.
*
* @param int $tickDiff * @param int $tickDiff
*
* @return bool
*/ */
protected function doAirSupplyTick(int $tickDiff) : void{ protected function doAirSupplyTick(int $tickDiff) : bool{
if(($respirationLevel = $this->armorInventory->getHelmet()->getEnchantmentLevel(Enchantment::RESPIRATION)) <= 0 or $ticks = $this->getAirSupplyTicks();
lcg_value() <= (1 / ($respirationLevel + 1)) $oldTicks = $ticks;
){ if(!$this->canBreathe()){
$ticks = $this->getAirSupplyTicks() - $tickDiff; $this->setBreathing(false);
if($ticks <= -20){ if(($respirationLevel = $this->armorInventory->getHelmet()->getEnchantmentLevel(Enchantment::RESPIRATION)) <= 0 or
$this->setAirSupplyTicks(0); lcg_value() <= (1 / ($respirationLevel + 1))
$this->onAirExpired(); ){
}else{ $ticks -= $tickDiff;
$this->setAirSupplyTicks($ticks); if($ticks <= -20){
$ticks = 0;
$this->onAirExpired();
}
}
}elseif(!$this->isBreathing()){
if($ticks < ($max = $this->getMaxAirSupplyTicks())){
$ticks += $tickDiff * 5;
}
if($ticks >= $max){
$ticks = $max;
$this->setBreathing(true);
} }
} }
if($ticks !== $oldTicks){
$this->setAirSupplyTicks($ticks);
}
return $ticks !== $oldTicks;
} }
/** /**