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 }
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); } }
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); }