More fixes :D

This commit is contained in:
Shoghi Cervantes Pueyo 2013-05-14 21:54:01 +02:00
parent 7236f4aad6
commit c27cca6741
9 changed files with 56 additions and 44 deletions

View file

@ -49,7 +49,7 @@ class EntityAPI{
public function getAll($level = null){
if($level instanceof Level){
$entities = array();
$l = $this->server->query("SELECT EID FROM entities WHERE level = '".$this->level->getName()."';");
$l = $this->server->query("SELECT EID FROM entities WHERE level = '".$level->getName()."';");
if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->get($e["EID"]);
@ -90,20 +90,43 @@ class EntityAPI{
$e->spawn($player);
}
public function spawnToAll($eid){
public function spawnToAll(Level $level, $eid){
$e = $this->get($eid);
if($e === false){
return false;
}
foreach($this->server->api->player->getAll() as $player){
foreach($this->server->api->player->getAll($level) as $player){
if($player->eid !== false and $player->eid !== $eid){
$e->spawn($player);
}
}
}
public function drop(Position $pos, Item $item){
if($item->getID() === AIR or $item->count <= 0){
return;
}
$data = array(
"x" => $pos->x + mt_rand(2, 8) / 10,
"y" => $pos->y + 0.19,
"z" => $pos->z + mt_rand(2, 8) / 10,
"item" => $item,
);
if($this->server->api->handle("item.drop", $data) !== false){
for($count = $item->count; $count > 0; ){
$item->count = min($item->getMaxStackSize(), $count);
$count -= $item->count;
$e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data);
//$e->speedX = mt_rand(-10, 10) / 100;
//$e->speedY = mt_rand(0, 5) / 100;
//$e->speedZ = mt_rand(-10, 10) / 100;
$this->spawnToAll($pos->level, $e->eid);
}
}
}
public function spawnAll($player){
foreach($this->getAll() as $e){
public function spawnAll(Player $player){
foreach($this->getAll($player->level) as $e){
$e->spawn($player);
}
}