Better damage handling + cactus damage

This commit is contained in:
Shoghi Cervantes Pueyo 2013-01-26 12:53:37 +01:00
parent 061faaa410
commit 09385daf60
2 changed files with 48 additions and 29 deletions

View File

@ -50,7 +50,7 @@ class PlayerAPI{
if($player->dead === true){ if($player->dead === true){
continue; continue;
} }
$player->setHealth(min(20, $player->entity->getHealth() + $data), "regeneration"); $player->setHealth(min(20, $player->getHealth() + $data), "regeneration");
} }
} }
} }

View File

@ -86,31 +86,41 @@ class Entity extends stdClass{
if($this->closed === true){ if($this->closed === true){
return false; return false;
} }
$down = $this->server->api->level->getBlock(round($this->x + 0.5), round($this->y), round($this->z + 0.5)); $startX = (int) (round($this->x - 0.5) - 1);
$up = $this->server->api->level->getBlock(round($this->x + 0.5), round($this->y + 1), round($this->z + 0.5)); $startY = (int) (round($this->y) - 1);
switch($down[0]){ $startZ = (int) (round($this->z - 0.5) - 1);
case 10: //Lava damage $endX = $startX + 2;
case 11: $endY = $startY + 2;
$this->harm(5, "lava"); $endZ = $startZ + 2;
break; for($y = $startY; $y <= $endY; ++$y){
case 51: //Fire block damage for($x = $startX; $x <= $endX; ++$x){
$this->harm(1, "fire"); for($z = $startZ; $z <= $endZ; ++$z){
break; $b = $this->server->api->level->getBlock($x, $y, $z);
} switch($b[0]){
case 10: //Lava damage
switch($up[0]){ case 11:
case 10: //Lava damage if($this->inBlock($x, $y, $z)){
case 11: $this->harm(5, "lava");
$this->harm(5, "lava"); }
break; break;
case 51: //Fire block damage case 51: //Fire block damage
$this->harm(1, "fire"); if($this->inBlock($x, $y, $z)){
break; $this->harm(1, "fire");
default: }
if(!isset(Material::$transparent[$up[0]])){ break;
$this->harm(1, "suffocation"); case 81: //Cactus damage
if($this->touchingBlock($x, $y, $z)){
$this->harm(1, "cactus");
}
break;
default:
if($this->inBlock($x, $y, $z) and !isset(Material::$transparent[$b[0]])){
$this->harm(1, "suffocation"); //Suffocation
}
break;
}
} }
break; }
} }
} }
@ -265,10 +275,19 @@ class Entity extends stdClass{
$this->server->query("UPDATE entities SET x = ".$this->x.", y = ".$this->y.", z = ".$this->z.", pitch = ".$this->pitch.", yaw = ".$this->yaw." WHERE EID = ".$this->eid.";"); $this->server->query("UPDATE entities SET x = ".$this->x.", y = ".$this->y.", z = ".$this->z.", pitch = ".$this->pitch.", yaw = ".$this->yaw." WHERE EID = ".$this->eid.";");
} }
public function inBlock($x, $y, $z){ public function inBlock($x, $y, $z, $radius = 0.8){
$block = new Vector3($x + 0.5, $y, $z + 0.5); $block = new Vector3($x, $y, $z);
$me = new Vector3($this->x, $this->y, $this->z); $me = new Vector3($this->x - 0.5, $this->y, $this->z - 0.5);
if(($y == ((int) $this->y) or $y == (((int) $this->y) + 1)) and $block->maxPlainDistance($me) < 0.8){ if(($y == ((int) $this->y) or $y == (((int) $this->y) + 1)) and $block->maxPlainDistance($me) < $radius){
return true;
}
return false;
}
public function touchingBlock($x, $y, $z, $radius = 0.9){
$block = new Vector3($x, $y, $z);
$me = new Vector3($this->x - 0.5, $this->y, $this->z - 0.5);
if(($y == (((int) $this->y) - 1) or $y == ((int) $this->y)) and $block->maxPlainDistance($me) < $radius){
return true; return true;
} }
return false; return false;