Inheritance: extends DataPacket
Exemplo n.º 1
0
 public function attack($damage, EntityDamageEvent $source)
 {
     parent::attack($damage, $source);
     if ($source->isCancelled()) {
         return;
     }
     if ($source instanceof EntityDamageByEntityEvent) {
         $this->swimSpeed = mt_rand(150, 350) / 2000;
         $e = $source->getDamager();
         $this->swimDirection = (new Vector3($this->x - $e->x, $this->y - $e->y, $this->z - $e->z))->normalize();
         $pk = new EntityEventPacket();
         $pk->eid = $this->getId();
         $pk->event = 15;
         Server::broadcastPacket($this->hasSpawned, $pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
     }
 }
Exemplo n.º 2
0
 public function attack($damage, EntityDamageEvent $source)
 {
     if ($this->attackTime > 0 or $this->noDamageTicks > 0) {
         $lastCause = $this->getLastDamageCause();
         if ($lastCause !== \null and $lastCause->getDamage() >= $damage) {
             $source->setCancelled();
         }
     }
     parent::attack($damage, $source);
     if ($source->isCancelled()) {
         return;
     }
     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());
     }
     $pk = new EntityEventPacket();
     $pk->eid = $this->getId();
     $pk->event = $this->getHealth() <= 0 ? EntityEventPacket::DEATH_ANIMATION : EntityEventPacket::HURT_ANIMATION;
     //Ouch!
     Server::broadcastPacket($this->hasSpawned, $pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
     $this->attackTime = 10;
     //0.5 seconds cooldown
 }
Exemplo n.º 3
0
 public function attack($damage, EntityDamageEvent $source)
 {
     if (!$this->isAlive()) {
         return;
     }
     if ($this->isCreative() and $source->getCause() !== EntityDamageEvent::CAUSE_MAGIC and $source->getCause() !== EntityDamageEvent::CAUSE_SUICIDE and $source->getCause() !== EntityDamageEvent::CAUSE_VOID) {
         $source->setCancelled();
     } elseif ($this->allowFlight and $source->getCause() === EntityDamageEvent::CAUSE_FALL) {
         $source->setCancelled();
     }
     parent::attack($damage, $source);
     if ($source->isCancelled()) {
         return;
     } elseif ($this->getLastDamageCause() === $source and $this->spawned) {
         $pk = new EntityEventPacket();
         $pk->eid = 0;
         $pk->event = EntityEventPacket::HURT_ANIMATION;
         $this->dataPacket($pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
     }
 }
Exemplo n.º 4
0
 public function attack($damage, EntityDamageEvent $source)
 {
     if ($this->attacker instanceof Entity) {
         return;
     }
     if ($this->attackTime > 0 or $this->noDamageTicks > 0) {
         $lastCause = $this->getLastDamageCause();
         if ($lastCause !== null and $lastCause->getDamage() >= $damage) {
             $source->setCancelled();
         }
     }
     Entity::attack($damage, $source);
     if ($source->isCancelled()) {
         return;
     }
     $this->attackTime = 10;
     if ($source instanceof EntityDamageByEntityEvent) {
         $this->stayTime = 0;
         $this->stayVec = null;
         $this->attackTime = 10;
         $this->attacker = $source->getDamager();
         if ($this instanceof PigZombie) {
             $this->setAngry(1000);
         }
     }
     $pk = new EntityEventPacket();
     $pk->eid = $this->getId();
     $pk->event = $this->isAlive() ? 2 : 3;
     Server::broadcastPacket($this->hasSpawned, $pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
 }