forked from unresolved3169/Altay
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQLite database, Entities, position, health
- Loading branch information
Showing
15 changed files
with
472 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
data/* | ||
*.log | ||
*.bat | ||
server.properties | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
<?php | ||
|
||
/* | ||
- | ||
/ \ | ||
/ \ | ||
/ POCKET \ | ||
/ MINECRAFT PHP \ | ||
|\ @shoghicp /| | ||
|. \ / .| | ||
| .. \ / .. | | ||
| .. | .. | | ||
| .. | .. | | ||
\ | / | ||
\ | / | ||
\ | / | ||
\ | / | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Lesser General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
*/ | ||
|
||
|
||
define("ENTITY_PLAYER", 0); | ||
define("ENTITY_MOB", 1); | ||
define("ENTITY_OBJECT", 2); | ||
define("ENTITY_ITEM", 3); | ||
define("ENTITY_PAINTING", 4); | ||
|
||
class Entity{ | ||
var $eid, $type, $name, $position, $dead, $metadata, $class, $attach; | ||
protected $health, $client; | ||
|
||
function __construct($eid, $class, $type = 0, $server){ //$type = 0 ---> player | ||
$this->server = $server; | ||
$this->eid = (int) $eid; | ||
$this->type = (int) $type; | ||
$this->class = (int) $class; | ||
$this->attach = false; | ||
$this->status = 0; | ||
$this->health = 20; | ||
$this->dead = false; | ||
$this->server->query("INSERT OR REPLACE INTO entities (EID, type, class, health) VALUES (".$this->eid.", ".$this->type.", ".$this->class.", ".$this->health.");"); | ||
$this->metadata = array(); | ||
/*include("misc/entities.php"); | ||
switch($this->class){ | ||
case ENTITY_PLAYER: | ||
case ENTITY_ITEM: | ||
break; | ||
case ENTITY_MOB: | ||
$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type)); | ||
break; | ||
case ENTITY_OBJECT: | ||
$this->setName((isset($objects[$this->type]) ? $objects[$this->type]:$this->type)); | ||
break; | ||
}*/ | ||
} | ||
|
||
public function __destruct(){ | ||
$this->server->query("DELETE FROM entities WHERE EID = ".$this->eid.";"); | ||
$this->server->trigger("onEntityRemove", $this->eid); | ||
} | ||
|
||
public function getEID(){ | ||
return $this->eid; | ||
} | ||
|
||
public function getName(){ | ||
return $this->name; | ||
} | ||
|
||
public function setName($name){ | ||
$this->name = $name; | ||
$this->server->query("UPDATE entities SET name = '".str_replace("'", "", $this->name)."' WHERE EID = ".$this->eid.";"); | ||
} | ||
|
||
public function look($pos2){ | ||
$pos = $this->getPosition(); | ||
$angle = Utils::angle3D($pos2, $pos); | ||
$this->position["yaw"] = $angle["yaw"]; | ||
$this->position["pitch"] = $angle["pitch"]; | ||
$this->server->query("UPDATE entities SET pitch = ".$this->position["pitch"].", yaw = ".$this->position["yaw"]." WHERE EID = ".$this->eid.";"); | ||
} | ||
|
||
public function setCoords($x, $y, $z){ | ||
if(!isset($this->position)){ | ||
$this->position = array( | ||
"x" => 0, | ||
"y" => 0, | ||
"z" => 0, | ||
"yaw" => 0, | ||
"pitch" => 0, | ||
"ground" => 0, | ||
); | ||
} | ||
$this->position["x"] = $x; | ||
$this->position["y"] = $y; | ||
$this->position["z"] = $z; | ||
$this->server->query("UPDATE entities SET x = ".$this->position["x"].", y = ".$this->position["y"].", z = ".$this->position["z"]." WHERE EID = ".$this->eid.";"); | ||
} | ||
|
||
public function move($x, $y, $z, $yaw = 0, $pitch = 0){ | ||
if(!isset($this->position)){ | ||
$this->position = array( | ||
"x" => 0, | ||
"y" => 0, | ||
"z" => 0, | ||
"yaw" => 0, | ||
"pitch" => 0, | ||
"ground" => 0, | ||
); | ||
} | ||
$this->position["x"] += $x; | ||
$this->position["y"] += $y; | ||
$this->position["z"] += $z; | ||
$this->position["yaw"] += $yaw; | ||
$this->position["yaw"] %= 360; | ||
$this->position["pitch"] += $pitch; | ||
$this->position["pitch"] %= 90; | ||
$this->server->query("UPDATE entities SET x = ".$this->position["x"].", y = ".$this->position["y"].", z = ".$this->position["z"].", pitch = ".$this->position["pitch"].", yaw = ".$this->position["yaw"]." WHERE EID = ".$this->eid.";"); | ||
} | ||
|
||
public function setPosition($x, $y, $z, $yaw, $pitch){ | ||
$this->position = array( | ||
"x" => $x, | ||
"y" => $y, | ||
"z" => $z, | ||
"yaw" => $yaw, | ||
"pitch" => $pitch, | ||
"ground" => $ground, | ||
); | ||
$this->server->query("UPDATE entities SET x = ".$this->position["x"].", y = ".$this->position["y"].", z = ".$this->position["z"].", pitch = ".$this->position["pitch"].", yaw = ".$this->position["yaw"]." WHERE EID = ".$this->eid.";"); | ||
return true; | ||
} | ||
|
||
public function getPosition($round = false){ | ||
return !isset($this->position) ? false:($round === true ? array_map("floor", $this->position):$this->position); | ||
} | ||
|
||
public function setHealth($health){ | ||
$this->health = (int) $health; | ||
$this->server->query("UPDATE entities SET health = ".$this->health." WHERE EID = ".$this->eid.";"); | ||
} | ||
|
||
public function getHealth(){ | ||
return $this->health; | ||
} | ||
|
||
} | ||
|
||
?> |
Oops, something went wrong.