Implemented swiftness, added invisible status to FloatingTextParticle

This commit is contained in:
Shoghi Cervantes 2015-03-20 17:19:06 +01:00
parent b42424eb22
commit 58253be0a0
4 changed files with 39 additions and 19 deletions

View File

@ -30,7 +30,7 @@ use pocketmine\Server;
class Effect{
const SPEED = 1;
const SLOWNESS = 2;
//TODO: const SWIFTNESS = 3;
const SWIFTNESS = 3;
const FATIGUE = 4;
const MINING_FATIGUE = 4;
//TODO: const STRENGTH = 5;
@ -61,7 +61,7 @@ class Effect{
self::$effects[Effect::SPEED] = new Effect(Effect::SPEED, "Speed", 124, 175, 198);
self::$effects[Effect::SLOWNESS] = new Effect(Effect::SLOWNESS, "Slowness", 90, 108, 129, true);
//self::$effects[Effect::SWIFTNESS] = new Effect(Effect::SWIFTNESS, "Swiftness", 217, 192, 67);
self::$effects[Effect::SWIFTNESS] = new Effect(Effect::SWIFTNESS, "Swiftness", 217, 192, 67);
self::$effects[Effect::FATIGUE] = new Effect(Effect::FATIGUE, "Mining Fatigue", 74, 66, 23, true);
//self::$effects[Effect::STRENGTH] = new Effect(Effect::STRENGTH, "Strength", 147, 36, 35);
//self::$effects[Effect::HEALING] = new InstantEffect(Effect::HEALING, "Healing", 248, 36, 35);

View File

@ -285,6 +285,10 @@ abstract class Entity extends Location implements Metadatable{
}
}
public function getEffect($effectId){
return isset($this->effects[$effectId]) ? $this->effects[$effectId] : null;
}
public function hasEffect($effectId){
return isset($this->effects[$effectId]);
}

View File

@ -98,6 +98,7 @@ use pocketmine\utils\ReversePriorityQueue;
use pocketmine\utils\TextFormat;
use pocketmine\level\particle\Particle;
use pocketmine\level\sound\Sound;
use pocketmine\entity\Effect;
use pocketmine\level\particle\DestroyBlockParticle;
#include <rules/Level.h>
@ -1289,6 +1290,9 @@ class Level implements ChunkManager, Metadatable{
}
$breakTime = $player->isCreative() ? 0.15 : $target->getBreakTime($item);
if($player->hasEffect(Effect::SWIFTNESS)){
$breakTime *= pow(0.80, $player->getEffect(Effect::SWIFTNESS)->getAmplifier() + 1);
}
if(!$ev->getInstaBreak() and ($player->lastBreak + $breakTime) >= microtime(true)){
return false;

View File

@ -38,6 +38,7 @@ class FloatingTextParticle extends Particle{
protected $text;
protected $title;
protected $entityId;
protected $invisible = false;
public function __construct(Vector3 $pos, $text, $title = ""){
parent::__construct($pos->x, $pos->y, $pos->z);
@ -53,6 +54,14 @@ class FloatingTextParticle extends Particle{
$this->title = $title;
}
public function isInvisible(){
return $this->invisible;
}
public function setInvisible($value = true){
$this->invisible = (bool) $value;
}
public function encode(){
$p = [];
@ -66,6 +75,8 @@ class FloatingTextParticle extends Particle{
$p[] = $pk0;
}
if(!$this->invisible){
$pk = new AddPlayerPacket();
$pk->eid = $this->entityId;
$pk->username = $this->title . "\n" . $this->text;
@ -84,6 +95,7 @@ class FloatingTextParticle extends Particle{
];
$p[] = $pk;
}
return $pk;
}