mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
Lava, fire and suffocation damage
This commit is contained in:
parent
f06f1d81c1
commit
5101391c29
@ -33,7 +33,7 @@ define("ENTITY_ITEM", 3);
|
|||||||
define("ENTITY_PAINTING", 4);
|
define("ENTITY_PAINTING", 4);
|
||||||
|
|
||||||
class Entity extends stdClass{
|
class Entity extends stdClass{
|
||||||
var $invincible = false, $eid, $type, $name, $x, $y, $z, $speedX, $speedY, $speedZ, $speed, $last = array(0, 0, 0, 0), $yaw, $pitch, $dead, $data, $class, $attach, $metadata, $closed, $player, $onTick;
|
var $invincible, $dmgcounter, $eid, $type, $name, $x, $y, $z, $speedX, $speedY, $speedZ, $speed, $last = array(0, 0, 0, 0), $yaw, $pitch, $dead, $data, $class, $attach, $metadata, $closed, $player, $onTick;
|
||||||
private $server;
|
private $server;
|
||||||
function __construct($server, $eid, $class, $type = 0, $data = array()){
|
function __construct($server, $eid, $class, $type = 0, $data = array()){
|
||||||
$this->server = $server;
|
$this->server = $server;
|
||||||
@ -45,11 +45,14 @@ class Entity extends stdClass{
|
|||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
$this->status = 0;
|
$this->status = 0;
|
||||||
$this->health = 20;
|
$this->health = 20;
|
||||||
|
$this->dmgcounter = array(0, 0);
|
||||||
|
$this->invincible = false;
|
||||||
$this->dead = false;
|
$this->dead = false;
|
||||||
$this->closed = false;
|
$this->closed = false;
|
||||||
$this->name = "";
|
$this->name = "";
|
||||||
$this->server->query("INSERT OR REPLACE INTO entities (EID, type, class, health) VALUES (".$this->eid.", ".$this->type.", ".$this->class.", ".$this->health.");");
|
$this->server->query("INSERT OR REPLACE INTO entities (EID, type, class, health) VALUES (".$this->eid.", ".$this->type.", ".$this->class.", ".$this->health.");");
|
||||||
$this->server->schedule(4, array($this, "update"), array(), true);
|
$this->server->schedule(4, array($this, "update"), array(), true);
|
||||||
|
$this->server->schedule(10, array($this, "environmentUpdate"), array(), true);
|
||||||
$this->metadata = array();
|
$this->metadata = array();
|
||||||
$this->x = isset($this->data["x"]) ? $this->data["x"]:0;
|
$this->x = isset($this->data["x"]) ? $this->data["x"]:0;
|
||||||
$this->y = isset($this->data["y"]) ? $this->data["y"]:0;
|
$this->y = isset($this->data["y"]) ? $this->data["y"]:0;
|
||||||
@ -79,6 +82,38 @@ class Entity extends stdClass{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function environmentUpdate(){
|
||||||
|
if($this->closed === true){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$down = $this->server->api->level->getBlock(round($this->x + 0.5), round($this->y), round($this->z + 0.5));
|
||||||
|
$up = $this->server->api->level->getBlock(round($this->x + 0.5), round($this->y + 1), round($this->z + 0.5));
|
||||||
|
switch($down[0]){
|
||||||
|
case 10: //Lava damage
|
||||||
|
case 11:
|
||||||
|
$this->harm(5, "lava");
|
||||||
|
break;
|
||||||
|
case 51: //Fire block damage
|
||||||
|
$this->harm(1, "fire");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch($up[0]){
|
||||||
|
case 10: //Lava damage
|
||||||
|
case 11:
|
||||||
|
$this->harm(5, "lava");
|
||||||
|
break;
|
||||||
|
case 51: //Fire block damage
|
||||||
|
$this->harm(1, "fire");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if(!isset(Material::$transparent[$up[0]])){
|
||||||
|
$this->harm(1, "suffocation");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function update(){
|
public function update(){
|
||||||
if($this->closed === true){
|
if($this->closed === true){
|
||||||
return false;
|
return false;
|
||||||
@ -260,23 +295,41 @@ class Entity extends stdClass{
|
|||||||
return !isset($this->position) ? false:($round === true ? array_map("floor", $this->position):$this->position);
|
return !isset($this->position) ? false:($round === true ? array_map("floor", $this->position):$this->position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function harm($dmg, $cause = ""){
|
||||||
|
return $this->setHealth($this->getHealth() - ((int) $dmg), $cause);
|
||||||
|
}
|
||||||
|
|
||||||
public function setHealth($health, $cause = ""){
|
public function setHealth($health, $cause = ""){
|
||||||
$this->health = (int) $health;
|
$health = min(127, max(-128, (int) $health));
|
||||||
$this->server->query("UPDATE entities SET health = ".$this->health." WHERE EID = ".$this->eid.";");
|
if($health < $this->health){
|
||||||
$this->server->api->dhandle("entity.health.change", array("eid" => $this->eid, "health" => $health, "cause" => $cause));
|
$dmg = $this->health - $health;
|
||||||
if($this->player !== false){
|
if($this->dmgcounter[0] < microtime(true) or $this->dmgcounter[1] < $dmg and !$this->dead){
|
||||||
$this->player->dataPacket(MC_SET_HEALTH, array(
|
$this->dmgcounter = array(microtime(true) + 0.5, $dmg);
|
||||||
"health" => $this->health,
|
}else{
|
||||||
));
|
return false; //Entity inmunity
|
||||||
}
|
|
||||||
if($this->health <= 0 and $this->dead === false){
|
|
||||||
$this->dead = true;
|
|
||||||
if($this->player !== false){
|
|
||||||
$this->server->api->dhandle("player.death", array("name" => $this->name, "cause" => $cause));
|
|
||||||
}
|
}
|
||||||
}elseif($this->health > 0){
|
}elseif($health === $this->health){
|
||||||
$this->dead = false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if($this->server->api->dhandle("entity.health.change", array("entity" => $this, "eid" => $this->eid, "health" => $health, "cause" => $cause)) !== false){
|
||||||
|
$this->health = $health;
|
||||||
|
$this->server->query("UPDATE entities SET health = ".$this->health." WHERE EID = ".$this->eid.";");
|
||||||
|
if($this->player !== false){
|
||||||
|
$this->player->dataPacket(MC_SET_HEALTH, array(
|
||||||
|
"health" => $this->health,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if($this->health <= 0 and $this->dead === false){
|
||||||
|
$this->dead = true;
|
||||||
|
if($this->player !== false){
|
||||||
|
$this->server->api->dhandle("player.death", array("name" => $this->name, "cause" => $cause));
|
||||||
|
}
|
||||||
|
}elseif($this->health > 0){
|
||||||
|
$this->dead = false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHealth(){
|
public function getHealth(){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user