Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. <?php
  2.  
  3. namespace twilight\duels\entities;
  4.  
  5. use pocketmine\entity\Effect;
  6. use pocketmine\entity\EffectInstance;
  7. use pocketmine\entity\Human;
  8. use pocketmine\level\particle\GenericParticle;
  9. use pocketmine\level\particle\Particle;
  10. use pocketmine\level\Position;
  11. use pocketmine\math\Vector3;
  12. use twilight\duels\Loader;
  13. use twilight\utilities\ParticleIds;
  14. use twilight\utilities\SoundIds;
  15.  
  16. /**
  17. * Class HealBall
  18. * @package twilight\duels\entities
  19. */
  20. class HealBall extends Human
  21. {
  22.  
  23. public $age = 0;
  24. public $heal = 0;
  25. public $time = 0;
  26.  
  27. public function onUpdate(int $currentTick): bool
  28. {
  29. ++$this->age;
  30. ++$this->heal;
  31. $this->yaw += 15;
  32.  
  33. $this->setPosition(new Position($this->x, $this->namedtag->getInt('yy'), $this->z, $this->level));
  34. $this->getLevel()->addParticle(new DropperParticle($this->asVector3()->add(mt_rand(1, 10) / 10, mt_rand(1, 10) / 10, - mt_rand(1, 10) / 10), 124, 252, 0));
  35. $this->getLevel()->addParticle(new DropperParticle($this->asVector3()->add(- mt_rand(1, 10) / 10, mt_rand(1, 10) / 10, mt_rand(1, 10) / 10), 127, 255, 0));
  36.  
  37. if ($this->heal == 40) {
  38. $this->heal = 0;
  39. foreach ($this->getLevel()->getPlayers() as $player) {
  40. if ($player->getLowerCaseName() == Loader::getInstance()->getServer()->getPlayerExact($this->namedtag->getString('owner'))->getLowerCaseName()) {
  41. if ($player->getX() > ($this->x - 3) && $player->getX() < ($this->x + 3) && $player->getY() > ($this->y - 3) && $player->getY() < ($this->y + 3) && $player->getZ() > ($this->z - 3) && $player->getZ() < ($this->z + 3)) {
  42. $player->addEffect(new EffectInstance(Effect::getEffect(Effect::REGENERATION), 40, 1, false));
  43. }
  44. }
  45. }
  46. }
  47.  
  48. if ($this->age >= 180) {
  49. ++$this->time;
  50.  
  51. if (1 - (($this->time * 100 / (1 * 20)) / 100) > 0) {
  52. $this->setScale(1 - (($this->time * 100 / (1 * 20)) / 100));
  53. }
  54. }
  55.  
  56. if ($this->age == 200) {
  57. $this->flagForDespawn();
  58. addParticle(ParticleIds::MOB_BLOCK_SPAWN, $this->asPosition(), $this->getLevel()->getPlayers());
  59. playSound(SoundIds::RANDOM_TOAST, $this->asVector3(), $this->getLevel()->getPlayers());
  60. }
  61.  
  62. return parent::onUpdate($currentTick);
  63. }
  64. }
  65. class DropperParticle extends GenericParticle
  66. {
  67. public function __construct(Vector3 $pos, int $r, int $g, int $b, int $a = 255)
  68. {
  69. parent::__construct($pos, Particle::TYPE_MOB_SPELL_INSTANTANEOUS, (($a & 0xff) << 24) | (($r & 0xff) << 16) | (($g & 0xff) << 8) | ($b & 0xff));
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement