Removed pocketmine subdirectory, map PSR-4 style

This commit is contained in:
Dylan K. Taylor
2019-07-30 19:14:57 +01:00
parent 7a77d3dc30
commit 5499ac620c
1044 changed files with 3 additions and 3 deletions

View File

@ -0,0 +1,40 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\entity\effect;
use pocketmine\entity\Living;
class AbsorptionEffect extends Effect{
public function add(Living $entity, EffectInstance $instance) : void{
$new = (4 * $instance->getEffectLevel());
if($new > $entity->getAbsorption()){
$entity->setAbsorption($new);
}
}
public function remove(Living $entity, EffectInstance $instance) : void{
$entity->setAbsorption(0);
}
}

View File

@ -0,0 +1,150 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\entity\effect;
use pocketmine\entity\Entity;
use pocketmine\entity\Living;
use pocketmine\utils\Color;
class Effect{
/** @var int */
protected $id;
/** @var string */
protected $name;
/** @var Color */
protected $color;
/** @var bool */
protected $bad;
/** @var bool */
protected $hasBubbles;
/**
* @param int $id Effect ID as per Minecraft PE
* @param string $name Translation key used for effect name
* @param Color $color
* @param bool $isBad Whether the effect is harmful
* @param bool $hasBubbles Whether the effect has potion bubbles. Some do not (e.g. Instant Damage has its own particles instead of bubbles)
*/
public function __construct(int $id, string $name, Color $color, bool $isBad = false, bool $hasBubbles = true){
$this->id = $id;
$this->name = $name;
$this->color = $color;
$this->bad = $isBad;
$this->hasBubbles = $hasBubbles;
}
/**
* Returns the effect ID as per Minecraft PE
* @return int
*/
public function getId() : int{
return $this->id;
}
/**
* Returns the translation key used to translate this effect's name.
* @return string
*/
public function getName() : string{
return $this->name;
}
/**
* Returns a Color object representing this effect's particle colour.
* @return Color
*/
public function getColor() : Color{
return $this->color;
}
/**
* Returns whether this effect is harmful.
* TODO: implement inverse effect results for undead mobs
*
* @return bool
*/
public function isBad() : bool{
return $this->bad;
}
/**
* Returns the default duration this effect will apply for if a duration is not specified.
* @return int
*/
public function getDefaultDuration() : int{
return 600;
}
/**
* Returns whether this effect will give the subject potion bubbles.
* @return bool
*/
public function hasBubbles() : bool{
return $this->hasBubbles;
}
/**
* Returns whether the effect will do something on the current tick.
*
* @param EffectInstance $instance
*
* @return bool
*/
public function canTick(EffectInstance $instance) : bool{
return false;
}
/**
* Applies effect results to an entity. This will not be called unless canTick() returns true.
*
* @param Living $entity
* @param EffectInstance $instance
* @param float $potency
* @param null|Entity $source
*/
public function applyEffect(Living $entity, EffectInstance $instance, float $potency = 1.0, ?Entity $source = null) : void{
}
/**
* Applies effects to the entity when the effect is first added.
*
* @param Living $entity
* @param EffectInstance $instance
*/
public function add(Living $entity, EffectInstance $instance) : void{
}
/**
* Removes the effect from the entity, resetting any changed values back to their original defaults.
*
* @param Living $entity
* @param EffectInstance $instance
*/
public function remove(Living $entity, EffectInstance $instance) : void{
}
}

View File

@ -0,0 +1,227 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\entity\effect;
use pocketmine\utils\Color;
use function max;
use const INT32_MAX;
class EffectInstance{
/** @var Effect */
private $effectType;
/** @var int */
private $duration;
/** @var int */
private $amplifier;
/** @var bool */
private $visible;
/** @var bool */
private $ambient;
/** @var Color */
private $color;
/**
* @param Effect $effectType
* @param int|null $duration Passing null will use the effect type's default duration
* @param int $amplifier
* @param bool $visible
* @param bool $ambient
* @param null|Color $overrideColor
*/
public function __construct(Effect $effectType, ?int $duration = null, int $amplifier = 0, bool $visible = true, bool $ambient = false, ?Color $overrideColor = null){
$this->effectType = $effectType;
$this->setDuration($duration ?? $effectType->getDefaultDuration());
$this->setAmplifier($amplifier);
$this->visible = $visible;
$this->ambient = $ambient;
$this->color = $overrideColor ?? $effectType->getColor();
}
public function getId() : int{
return $this->effectType->getId();
}
/**
* @return Effect
*/
public function getType() : Effect{
return $this->effectType;
}
/**
* @return int
*/
public function getDuration() : int{
return $this->duration;
}
/**
* @param int $duration
*
* @throws \InvalidArgumentException
*
* @return $this
*/
public function setDuration(int $duration) : EffectInstance{
if($duration < 0 or $duration > INT32_MAX){
throw new \InvalidArgumentException("Effect duration must be in range 0 - " . INT32_MAX . ", got $duration");
}
$this->duration = $duration;
return $this;
}
/**
* Decreases the duration by the given number of ticks, without dropping below zero.
*
* @param int $ticks
*
* @return $this
*/
public function decreaseDuration(int $ticks) : EffectInstance{
$this->duration = max(0, $this->duration - $ticks);
return $this;
}
/**
* Returns whether the duration has run out.
*
* @return bool
*/
public function hasExpired() : bool{
return $this->duration <= 0;
}
/**
* @return int
*/
public function getAmplifier() : int{
return $this->amplifier;
}
/**
* Returns the level of this effect, which is always one higher than the amplifier.
*
* @return int
*/
public function getEffectLevel() : int{
return $this->amplifier + 1;
}
/**
* @param int $amplifier
*
* @return $this
*/
public function setAmplifier(int $amplifier) : EffectInstance{
if($amplifier < 0 or $amplifier > 255){
throw new \InvalidArgumentException("Amplifier must be in range 0 - 255, got $amplifier");
}
$this->amplifier = $amplifier;
return $this;
}
/**
* Returns whether this effect will produce some visible effect, such as bubbles or particles.
*
* @return bool
*/
public function isVisible() : bool{
return $this->visible;
}
/**
* @param bool $visible
*
* @return $this
*/
public function setVisible(bool $visible = true) : EffectInstance{
$this->visible = $visible;
return $this;
}
/**
* Returns whether the effect originated from the ambient environment.
* Ambient effects can originate from things such as a Beacon's area of effect radius.
* If this flag is set, the amount of visible particles will be reduced by a factor of 5.
*
* @return bool
*/
public function isAmbient() : bool{
return $this->ambient;
}
/**
* @param bool $ambient
*
* @return $this
*/
public function setAmbient(bool $ambient = true) : EffectInstance{
$this->ambient = $ambient;
return $this;
}
/**
* Returns the particle colour of this effect instance. This can be overridden on a per-EffectInstance basis, so it
* is not reflective of the default colour of the effect.
*
* @return Color
*/
public function getColor() : Color{
return $this->color;
}
/**
* Sets the colour of this EffectInstance.
*
* @param Color $color
*
* @return EffectInstance
*/
public function setColor(Color $color) : EffectInstance{
$this->color = $color;
return $this;
}
/**
* Resets the colour of this EffectInstance to the default specified by its type.
*
* @return EffectInstance
*/
public function resetColor() : EffectInstance{
$this->color = $this->effectType->getColor();
return $this;
}
}

View File

@ -0,0 +1,221 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\entity\effect;
use pocketmine\entity\Living;
use pocketmine\event\entity\EntityEffectAddEvent;
use pocketmine\event\entity\EntityEffectRemoveEvent;
use pocketmine\utils\Color;
use function abs;
class EffectManager{
/** @var Living */
private $entity;
/** @var EffectInstance[] */
protected $effects = [];
/** @var Color */
protected $bubbleColor;
/** @var bool */
protected $onlyAmbientEffects = false;
public function __construct(Living $entity){
$this->entity = $entity;
$this->bubbleColor = new Color(0, 0, 0, 0);
}
/**
* Returns an array of Effects currently active on the mob.
* @return EffectInstance[]
*/
public function all() : array{
return $this->effects;
}
/**
* Removes all effects from the mob.
*/
public function clear() : void{
foreach($this->effects as $effect){
$this->remove($effect->getType());
}
}
/**
* Removes the effect with the specified ID from the mob.
*
* @param Effect $effectType
*/
public function remove(Effect $effectType) : void{
$index = $effectType->getId();
if(isset($this->effects[$index])){
$effect = $this->effects[$index];
$hasExpired = $effect->hasExpired();
$ev = new EntityEffectRemoveEvent($this->entity, $effect);
$ev->call();
if($ev->isCancelled()){
if($hasExpired and !$ev->getEffect()->hasExpired()){ //altered duration of an expired effect to make it not get removed
$this->entity->onEffectAdded($ev->getEffect(), true);
}
return;
}
unset($this->effects[$index]);
$effect->getType()->remove($this->entity, $effect);
$this->entity->onEffectRemoved($effect);
$this->recalculateEffectColor();
}
}
/**
* Returns the effect instance active on this entity with the specified ID, or null if the mob does not have the
* effect.
*
* @param Effect $effect
*
* @return EffectInstance|null
*/
public function get(Effect $effect) : ?EffectInstance{
return $this->effects[$effect->getId()] ?? null;
}
/**
* Returns whether the specified effect is active on the mob.
*
* @param Effect $effect
*
* @return bool
*/
public function has(Effect $effect) : bool{
return isset($this->effects[$effect->getId()]);
}
/**
* Adds an effect to the mob.
* If a weaker effect of the same type is already applied, it will be replaced.
* If a weaker or equal-strength effect is already applied but has a shorter duration, it will be replaced.
*
* @param EffectInstance $effect
*
* @return bool whether the effect has been successfully applied.
*/
public function add(EffectInstance $effect) : bool{
$oldEffect = null;
$cancelled = false;
$index = $effect->getType()->getId();
if(isset($this->effects[$index])){
$oldEffect = $this->effects[$index];
if(
abs($effect->getAmplifier()) < $oldEffect->getAmplifier()
or (abs($effect->getAmplifier()) === abs($oldEffect->getAmplifier()) and $effect->getDuration() < $oldEffect->getDuration())
){
$cancelled = true;
}
}
$ev = new EntityEffectAddEvent($this->entity, $effect, $oldEffect);
$ev->setCancelled($cancelled);
$ev->call();
if($ev->isCancelled()){
return false;
}
if($oldEffect !== null){
$oldEffect->getType()->remove($this->entity, $oldEffect);
}
$effect->getType()->add($this->entity, $effect);
$this->entity->onEffectAdded($effect, $oldEffect !== null);
$this->effects[$index] = $effect;
$this->recalculateEffectColor();
return true;
}
/**
* Recalculates the mob's potion bubbles colour based on the active effects.
*/
protected function recalculateEffectColor() : void{
/** @var Color[] $colors */
$colors = [];
$ambient = true;
foreach($this->effects as $effect){
if($effect->isVisible() and $effect->getType()->hasBubbles()){
$level = $effect->getEffectLevel();
$color = $effect->getColor();
for($i = 0; $i < $level; ++$i){
$colors[] = $color;
}
if(!$effect->isAmbient()){
$ambient = false;
}
}
}
if(!empty($colors)){
$this->bubbleColor = Color::mix(...$colors);
$this->onlyAmbientEffects = $ambient;
}else{
$this->bubbleColor = new Color(0, 0, 0, 0);
$this->onlyAmbientEffects = false;
}
}
/**
* @return Color
*/
public function getBubbleColor() : Color{
return $this->bubbleColor;
}
/**
* @return bool
*/
public function hasOnlyAmbientEffects() : bool{
return $this->onlyAmbientEffects;
}
public function tick(int $tickDiff = 1) : bool{
foreach($this->effects as $instance){
$type = $instance->getType();
if($type->canTick($instance)){
$type->applyEffect($this->entity, $instance);
}
$instance->decreaseDuration($tickDiff);
if($instance->hasExpired()){
$this->remove($instance->getType());
}
}
return !empty($this->effects);
}
}

View File

@ -0,0 +1,37 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\entity\effect;
use pocketmine\entity\Living;
class HealthBoostEffect extends Effect{
public function add(Living $entity, EffectInstance $instance) : void{
$entity->setMaxHealth($entity->getMaxHealth() + 4 * $instance->getEffectLevel());
}
public function remove(Living $entity, EffectInstance $instance) : void{
$entity->setMaxHealth($entity->getMaxHealth() - 4 * $instance->getEffectLevel());
}
}

View File

@ -0,0 +1,42 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\entity\effect;
use pocketmine\entity\Entity;
use pocketmine\entity\Human;
use pocketmine\entity\Living;
use pocketmine\event\player\PlayerExhaustEvent;
class HungerEffect extends Effect{
public function canTick(EffectInstance $instance) : bool{
return true;
}
public function applyEffect(Living $entity, EffectInstance $instance, float $potency = 1.0, ?Entity $source = null) : void{
if($entity instanceof Human){
$entity->getHungerManager()->exhaust(0.025 * $instance->getEffectLevel(), PlayerExhaustEvent::CAUSE_POTION);
}
}
}

View File

@ -0,0 +1,49 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\entity\effect;
use pocketmine\entity\Entity;
use pocketmine\entity\Living;
use pocketmine\event\entity\EntityDamageByChildEntityEvent;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\entity\EntityDamageEvent;
class InstantDamageEffect extends InstantEffect{
public function applyEffect(Living $entity, EffectInstance $instance, float $potency = 1.0, ?Entity $source = null) : void{
//TODO: add particles (witch spell)
$damage = (4 << $instance->getAmplifier()) * $potency;
if($source !== null){
$sourceOwner = $source->getOwningEntity();
if($sourceOwner !== null){
$ev = new EntityDamageByChildEntityEvent($sourceOwner, $source, $entity, EntityDamageEvent::CAUSE_MAGIC, $damage);
}else{
$ev = new EntityDamageByEntityEvent($source, $entity, EntityDamageEvent::CAUSE_MAGIC, $damage);
}
}else{
$ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, $damage);
}
$entity->attack($ev);
}
}

View File

@ -0,0 +1,35 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\entity\effect;
abstract class InstantEffect extends Effect{
public function getDefaultDuration() : int{
return 1;
}
public function canTick(EffectInstance $instance) : bool{
return true; //If forced to last longer than 1 tick, these apply every tick.
}
}

View File

@ -0,0 +1,38 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\entity\effect;
use pocketmine\entity\Entity;
use pocketmine\entity\Living;
use pocketmine\event\entity\EntityRegainHealthEvent;
class InstantHealthEffect extends InstantEffect{
public function applyEffect(Living $entity, EffectInstance $instance, float $potency = 1.0, ?Entity $source = null) : void{
if($entity->getHealth() < $entity->getMaxHealth()){
$entity->heal(new EntityRegainHealthEvent($entity, (4 << $instance->getAmplifier()) * $potency, EntityRegainHealthEvent::CAUSE_MAGIC));
}
}
}

View File

@ -0,0 +1,39 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\entity\effect;
use pocketmine\entity\Living;
class InvisibilityEffect extends Effect{
public function add(Living $entity, EffectInstance $instance) : void{
$entity->setInvisible();
$entity->setNameTagVisible(false);
}
public function remove(Living $entity, EffectInstance $instance) : void{
$entity->setInvisible(false);
$entity->setNameTagVisible();
}
}

View File

@ -0,0 +1,49 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\entity\effect;
use pocketmine\entity\Entity;
use pocketmine\entity\Living;
use pocketmine\player\Player;
class LevitationEffect extends Effect{
public function canTick(EffectInstance $instance) : bool{
return true;
}
public function applyEffect(Living $entity, EffectInstance $instance, float $potency = 1.0, ?Entity $source = null) : void{
if(!($entity instanceof Player)){ //TODO: ugly hack, player motion isn't updated properly by the server yet :(
$entity->addMotion(0, ($instance->getEffectLevel() / 20 - $entity->getMotion()->y) / 5, 0);
}
}
public function add(Living $entity, EffectInstance $instance) : void{
$entity->setHasGravity(false);
}
public function remove(Living $entity, EffectInstance $instance) : void{
$entity->setHasGravity();
}
}

View File

@ -0,0 +1,54 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\entity\effect;
use pocketmine\entity\Entity;
use pocketmine\entity\Living;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\utils\Color;
class PoisonEffect extends Effect{
/** @var bool */
private $fatal;
public function __construct(int $id, string $name, Color $color, bool $isBad = false, bool $hasBubbles = true, bool $fatal = false){
parent::__construct($id, $name, $color, $isBad, $hasBubbles);
$this->fatal = $fatal;
}
public function canTick(EffectInstance $instance) : bool{
if(($interval = (25 >> $instance->getAmplifier())) > 0){
return ($instance->getDuration() % $interval) === 0;
}
return true;
}
public function applyEffect(Living $entity, EffectInstance $instance, float $potency = 1.0, ?Entity $source = null) : void{
if($entity->getHealth() > 1 or $this->fatal){
$ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 1);
$entity->attack($ev);
}
}
}

View File

@ -0,0 +1,45 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\entity\effect;
use pocketmine\entity\Entity;
use pocketmine\entity\Living;
use pocketmine\event\entity\EntityRegainHealthEvent;
class RegenerationEffect extends Effect{
public function canTick(EffectInstance $instance) : bool{
if(($interval = (40 >> $instance->getAmplifier())) > 0){
return ($instance->getDuration() % $interval) === 0;
}
return true;
}
public function applyEffect(Living $entity, EffectInstance $instance, float $potency = 1.0, ?Entity $source = null) : void{
if($entity->getHealth() < $entity->getMaxHealth()){
$ev = new EntityRegainHealthEvent($entity, 1, EntityRegainHealthEvent::CAUSE_MAGIC);
$entity->heal($ev);
}
}
}

View File

@ -0,0 +1,39 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\entity\effect;
use pocketmine\entity\Entity;
use pocketmine\entity\Human;
use pocketmine\entity\Living;
class SaturationEffect extends InstantEffect{
public function applyEffect(Living $entity, EffectInstance $instance, float $potency = 1.0, ?Entity $source = null) : void{
if($entity instanceof Human){
$manager = $entity->getHungerManager();
$manager->addFood($instance->getEffectLevel());
$manager->addSaturation($instance->getEffectLevel() * 2);
}
}
}

View File

@ -0,0 +1,40 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\entity\effect;
use pocketmine\entity\Attribute;
use pocketmine\entity\Living;
class SlownessEffect extends Effect{
public function add(Living $entity, EffectInstance $instance) : void{
$attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
$attr->setValue($attr->getValue() * (1 - 0.15 * $instance->getEffectLevel()), true);
}
public function remove(Living $entity, EffectInstance $instance) : void{
$attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
$attr->setValue($attr->getValue() / (1 - 0.15 * $instance->getEffectLevel()));
}
}

View File

@ -0,0 +1,40 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\entity\effect;
use pocketmine\entity\Attribute;
use pocketmine\entity\Living;
class SpeedEffect extends Effect{
public function add(Living $entity, EffectInstance $instance) : void{
$attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
$attr->setValue($attr->getValue() * (1 + 0.2 * $instance->getEffectLevel()));
}
public function remove(Living $entity, EffectInstance $instance) : void{
$attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED);
$attr->setValue($attr->getValue() / (1 + 0.2 * $instance->getEffectLevel()));
}
}

View File

@ -0,0 +1,134 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\entity\effect;
use pocketmine\utils\Color;
use pocketmine\utils\RegistryTrait;
use function assert;
/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever registry members are added, removed or changed.
* @see RegistryTrait::_generateMethodAnnotations()
*
* @method static AbsorptionEffect ABSORPTION()
* @method static Effect BLINDNESS()
* @method static Effect CONDUIT_POWER()
* @method static PoisonEffect FATAL_POISON()
* @method static Effect FIRE_RESISTANCE()
* @method static Effect HASTE()
* @method static HealthBoostEffect HEALTH_BOOST()
* @method static HungerEffect HUNGER()
* @method static InstantDamageEffect INSTANT_DAMAGE()
* @method static InstantHealthEffect INSTANT_HEALTH()
* @method static InvisibilityEffect INVISIBILITY()
* @method static Effect JUMP_BOOST()
* @method static LevitationEffect LEVITATION()
* @method static Effect MINING_FATIGUE()
* @method static Effect NAUSEA()
* @method static Effect NIGHT_VISION()
* @method static PoisonEffect POISON()
* @method static RegenerationEffect REGENERATION()
* @method static Effect RESISTANCE()
* @method static SaturationEffect SATURATION()
* @method static SlownessEffect SLOWNESS()
* @method static SpeedEffect SPEED()
* @method static Effect STRENGTH()
* @method static Effect WATER_BREATHING()
* @method static Effect WEAKNESS()
* @method static WitherEffect WITHER()
*/
final class VanillaEffects{
use RegistryTrait;
/** @var Effect[] */
private static $mcpeIdMap = [];
protected static function setup() : void{
self::register("absorption", new AbsorptionEffect(22, "%potion.absorption", new Color(0x25, 0x52, 0xa5)));
self::register("blindness", new Effect(15, "%potion.blindness", new Color(0x1f, 0x1f, 0x23), true));
self::register("conduit_power", new Effect(26, "%potion.conduitPower", new Color(0x1d, 0xc2, 0xd1)));
self::register("fatal_poison", new PoisonEffect(25, "%potion.poison", new Color(0x4e, 0x93, 0x31), true, true, true));
self::register("fire_resistance", new Effect(12, "%potion.fireResistance", new Color(0xe4, 0x9a, 0x3a)));
self::register("haste", new Effect(3, "%potion.digSpeed", new Color(0xd9, 0xc0, 0x43)));
self::register("health_boost", new HealthBoostEffect(21, "%potion.healthBoost", new Color(0xf8, 0x7d, 0x23)));
self::register("hunger", new HungerEffect(17, "%potion.hunger", new Color(0x58, 0x76, 0x53), true));
self::register("instant_damage", new InstantDamageEffect(7, "%potion.harm", new Color(0x43, 0x0a, 0x09), true, false));
self::register("instant_health", new InstantHealthEffect(6, "%potion.heal", new Color(0xf8, 0x24, 0x23), false, false));
self::register("invisibility", new InvisibilityEffect(14, "%potion.invisibility", new Color(0x7f, 0x83, 0x92)));
self::register("jump_boost", new Effect(8, "%potion.jump", new Color(0x22, 0xff, 0x4c)));
self::register("levitation", new LevitationEffect(24, "%potion.levitation", new Color(0xce, 0xff, 0xff)));
self::register("mining_fatigue", new Effect(4, "%potion.digSlowDown", new Color(0x4a, 0x42, 0x17), true));
self::register("nausea", new Effect(9, "%potion.confusion", new Color(0x55, 0x1d, 0x4a), true));
self::register("night_vision", new Effect(16, "%potion.nightVision", new Color(0x1f, 0x1f, 0xa1)));
self::register("poison", new PoisonEffect(19, "%potion.poison", new Color(0x4e, 0x93, 0x31), true));
self::register("regeneration", new RegenerationEffect(10, "%potion.regeneration", new Color(0xcd, 0x5c, 0xab)));
self::register("resistance", new Effect(11, "%potion.resistance", new Color(0x99, 0x45, 0x3a)));
self::register("saturation", new SaturationEffect(23, "%potion.saturation", new Color(0xf8, 0x24, 0x23), false));
self::register("slowness", new SlownessEffect(2, "%potion.moveSlowdown", new Color(0x5a, 0x6c, 0x81), true));
self::register("speed", new SpeedEffect(1, "%potion.moveSpeed", new Color(0x7c, 0xaf, 0xc6)));
self::register("strength", new Effect(5, "%potion.damageBoost", new Color(0x93, 0x24, 0x23)));
self::register("water_breathing", new Effect(13, "%potion.waterBreathing", new Color(0x2e, 0x52, 0x99)));
self::register("weakness", new Effect(18, "%potion.weakness", new Color(0x48, 0x4d, 0x48), true));
self::register("wither", new WitherEffect(20, "%potion.wither", new Color(0x35, 0x2a, 0x27), true));
}
protected static function register(string $name, Effect $member) : void{
self::_registryRegister($name, $member);
assert(!isset(self::$mcpeIdMap[$member->getId()]));
self::$mcpeIdMap[$member->getId()] = $member;
}
/**
* @param int $id
*
* @return Effect
*/
public static function byMcpeId(int $id) : Effect{
self::checkInit();
if(!isset(self::$mcpeIdMap[$id])){
throw new \InvalidArgumentException("No such effect with MCPE ID $id");
}
return self::$mcpeIdMap[$id];
}
/**
* @return Effect[]
*/
public static function getAll() : array{
return self::_registryGetAll();
}
/**
* @param string $name
*
* @return Effect
*/
public static function fromString(string $name) : Effect{
$result = self::_registryFromString($name);
assert($result instanceof Effect);
return $result;
}
}

View File

@ -0,0 +1,43 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\entity\effect;
use pocketmine\entity\Entity;
use pocketmine\entity\Living;
use pocketmine\event\entity\EntityDamageEvent;
class WitherEffect extends Effect{
public function canTick(EffectInstance $instance) : bool{
if(($interval = (50 >> $instance->getAmplifier())) > 0){
return ($instance->getDuration() % $interval) === 0;
}
return true;
}
public function applyEffect(Living $entity, EffectInstance $instance, float $potency = 1.0, ?Entity $source = null) : void{
$ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 1);
$entity->attack($ev);
}
}