public function getPosList() { $out = []; for ($x = $this->centre->getX() - $this->radius; $x <= $this->centre->getX() + $this->radius; $x++) { for ($y = $this->centre->getY() - $this->radius; $y <= $this->centre->getY() + $this->radius; $x++) { for ($z = $this->centre->getZ() - $this->radius; $z <= $this->centre->getZ() + $this->radius; $x++) { $v = new Position($x, $y, $z, $this->centre->getLevel()); if ($v->distance($this->centre) <= $this->radius) { $out[] = $v; } } } } return $out; }
/** * @param Position $center * @param callable[] $exceptions * @return array */ public static function getNearestPlayers(Position $center, array $exceptions = []) { $currentDistance = PHP_INT_MAX; $nearest = []; foreach ($center->getLevel()->getPlayers() as $player) { foreach ($exceptions as $e) { if (call_user_func($e, $player) === false) { $continue = true; break; } } if (isset($continue)) { continue; } if ($player === $center) { continue; } if ($center->distance($player) === $currentDistance) { $nearest[] = $player; } elseif ($center->distance($player) < $currentDistance) { $nearest = [$player]; } } return $nearest; }
public function fire() { foreach ($this->getServer()->getLevels() as $level) { if (!$level instanceof Level) { continue; } if (!isset($this->db["Sparklers"][$level->getFolderName()])) { continue; } foreach ($this->db["Sparklers"][$level->getFolderName()] as $keyPos => $keyValue) { $explode = explode(".", $keyPos); if (!isset($explode[2])) { break; } // WRONG DATA $pillarPos = new Position($explode[0], $explode[1], $explode[2], $level); $players = []; foreach ($this->getServer()->getOnlinePlayers() as $player) { if ($pillarPos->distance($player) < 25) { $players[] = $player; } } if (count($players) == 0) { continue; } $level->addSound(new PopSound($pillarPos), $players); for ($h = 1; $h <= 11; $h++) { $pillarPos->setComponents($pillarPos->x, ++$pillarPos->y, $pillarPos->z); $level->addParticle(new DustParticle($pillarPos, 255, 255, 255, 255), $players); } $headPos = new Position($pillarPos->x, $pillarPos->y - 10, $pillarPos->z, $level); $r = mt_rand(0, 255); $g = mt_rand(0, 255); $b = mt_rand(0, 255); for ($r = 1; $r <= 5; $r++) { $headPos->setComponents($pillarPos->x + mt_rand(-3, 3), $pillarPos->y + mt_rand(-3, 3), $pillarPos->z + mt_rand(-3, 3)); $level->addParticle(new DustParticle($headPos, $r, $g, $b, 255), $players); // WHITE } $r = mt_rand(0, 255); $g = mt_rand(0, 255); $b = mt_rand(0, 255); for ($r = 1; $r <= 5; $r++) { $headPos->setComponents($pillarPos->x + mt_rand(-3, 3), $pillarPos->y + mt_rand(-3, 3), $pillarPos->z + mt_rand(-3, 3)); $level->addParticle(new DustParticle($headPos, $r, $g, $b, 255), $players); // GREEN } $r = mt_rand(0, 255); $g = mt_rand(0, 255); $b = mt_rand(0, 255); for ($r = 1; $r <= 5; $r++) { $headPos->setComponents($pillarPos->x + mt_rand(-3, 3), $pillarPos->y + mt_rand(-3, 3), $pillarPos->z + mt_rand(-3, 3)); $level->addParticle(new DustParticle($headPos, $r, $g, $b, 255), $players); // PINK } $r = mt_rand(0, 255); $g = mt_rand(0, 255); $b = mt_rand(0, 255); for ($r = 1; $r <= 5; $r++) { $headPos->setComponents($pillarPos->x + mt_rand(-3, 3), $pillarPos->y + mt_rand(-3, 3), $pillarPos->z + mt_rand(-3, 3)); $level->addParticle(new DustParticle($headPos, $r, $g, $b, 255), $players); // ORANGE } $r = mt_rand(0, 255); $g = mt_rand(0, 255); $b = mt_rand(0, 255); for ($r = 1; $r <= 5; $r++) { $headPos->setComponents($pillarPos->x + mt_rand(-3, 3), $pillarPos->y + mt_rand(-3, 3), $pillarPos->z + mt_rand(-3, 3)); $level->addParticle(new DustParticle($headPos, $r, $g, $b, 255), $players); // BLUE } } } }