本文整理汇总了PHP中Server::broadcastPacket方法的典型用法代码示例。如果您正苦于以下问题:PHP Server::broadcastPacket方法的具体用法?PHP Server::broadcastPacket怎么用?PHP Server::broadcastPacket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server
的用法示例。
在下文中一共展示了Server::broadcastPacket方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: attack
public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC)
{
echo __METHOD__ . __LINE__ . "\n";
if ($this->attackTime > 0 or $this->noDamageTicks > 0) {
$lastCause = $this->getLastDamageCause();
if ($lastCause instanceof EntityDamageEvent and $lastCause->getDamage() >= $damage) {
if ($source instanceof EntityDamageEvent) {
$source->setCancelled();
$this->server->getPluginManager()->callEvent($source);
$damage = $source->getFinalDamage();
if ($source->isCancelled()) {
return;
}
} else {
return;
}
} else {
return;
}
} elseif ($source instanceof EntityDamageEvent) {
$this->server->getPluginManager()->callEvent($source);
$damage = $source->getFinalDamage();
if ($source->isCancelled()) {
return;
}
}
$this->setLastDamageCause($source);
if ($source instanceof EntityDamageByEntityEvent) {
$e = $source->getDamager();
$deltaX = $this->x - $e->x;
$deltaZ = $this->z - $e->z;
$yaw = atan2($deltaX, $deltaZ);
$this->knockBack($e, $damage, sin($yaw), cos($yaw), $source->getKnockBack());
}
$this->setHealth($this->getHealth() - $damage);
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->event = $this->getHealth() <= 0 ? 3 : 2;
//Ouch!
Server::broadcastPacket($this->hasSpawned, $pk);
$this->attackTime = 10;
//0.5 seconds cooldown
}
示例2: sendPosition
public function sendPosition(Vector3 $pos, $yaw = null, $pitch = null, $mode = 0, array $targets = null)
{
$yaw = $yaw === null ? $this->yaw : $yaw;
$pitch = $pitch === null ? $this->pitch : $pitch;
$pk = new MovePlayerPacket();
$pk->eid = $this->getId();
$pk->x = $pos->x;
$pk->y = $pos->y + $this->getEyeHeight();
$pk->z = $pos->z;
$pk->bodyYaw = $yaw;
$pk->pitch = $pitch;
$pk->yaw = $yaw;
$pk->mode = $mode;
if ($targets !== null) {
Server::broadcastPacket($targets, $pk);
} else {
$pk->eid = 0;
$this->dataPacket($pk);
}
}
示例3: onClose
public function onClose(Player $who)
{
if (count($this->getViewers()) === 1) {
$pk = new TileEventPacket();
$pk->x = $this->right->getHolder()->getX();
$pk->y = $this->right->getHolder()->getY();
$pk->z = $this->right->getHolder()->getZ();
$pk->case1 = 1;
$pk->case2 = 0;
if (($level = $this->right->getHolder()->getLevel()) instanceof Level) {
Server::broadcastPacket($level->getUsingChunk($this->right->getHolder()->getX() >> 4, $this->right->getHolder()->getZ() >> 4), $pk);
}
}
parent::onClose($who);
}