From d5ba2a72a56708581f13efeec38043a9fdac9401 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 29 Mar 2015 14:49:47 +0200 Subject: [PATCH] Added strength, weakness, resistance effects, fixed entity area --- src/pocketmine/entity/Effect.php | 12 ++++++------ src/pocketmine/entity/Entity.php | 13 ++++--------- src/pocketmine/entity/FallingSand.php | 4 ---- src/pocketmine/entity/Item.php | 9 --------- src/pocketmine/entity/PrimedTNT.php | 6 ------ .../event/entity/EntityDamageByEntityEvent.php | 12 ++++++++++++ .../event/entity/EntityDamageEvent.php | 11 ++++++++--- src/pocketmine/level/Level.php | 18 +++++++++--------- src/pocketmine/math/Math.php | 5 +++++ 9 files changed, 44 insertions(+), 46 deletions(-) diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index 76858ad2c..63f9e9064 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -33,20 +33,20 @@ class Effect{ const SWIFTNESS = 3; const FATIGUE = 4; const MINING_FATIGUE = 4; - //TODO: const STRENGTH = 5; + const STRENGTH = 5; //TODO: const HEALING = 6; //TODO: const HARMING = 7; const JUMP = 8; //const CONFUSION = 9; const REGENERATION = 10; - //TODO: const DAMAGE_RESISTANCE = 11; + const DAMAGE_RESISTANCE = 11; const FIRE_RESISTANCE = 12; const WATER_BREATHING = 13; const INVISIBILITY = 14; //const BLINDNESS = 15; //const NIGHT_VISION = 16; //const HUNGER = 17; - //TODO: const WEAKNESS = 18; + const WEAKNESS = 18; const POISON = 19; const WITHER = 20; //const HEALTH_BOOST = 21; @@ -63,16 +63,16 @@ class Effect{ 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::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::STRENGTH] = new Effect(Effect::STRENGTH, "Strength", 147, 36, 35); //self::$effects[Effect::HEALING] = new InstantEffect(Effect::HEALING, "Healing", 248, 36, 35); //self::$effects[Effect::HARMING] = new InstantEffect(Effect::HARMING, "Harming", 67, 10, 9, true); self::$effects[Effect::JUMP] = new Effect(Effect::JUMP, "Jump", 34, 255, 76); self::$effects[Effect::REGENERATION] = new Effect(Effect::REGENERATION, "Regeneration", 205, 92, 171); - //self::$effects[Effect::DAMAGE_RESISTANCE] = new Effect(Effect::DAMAGE_RESISTANCE, "Damage Resistance", 153, 69, 58); + self::$effects[Effect::DAMAGE_RESISTANCE] = new Effect(Effect::DAMAGE_RESISTANCE, "Damage Resistance", 153, 69, 58); self::$effects[Effect::FIRE_RESISTANCE] = new Effect(Effect::FIRE_RESISTANCE, "Fire Resistance", 228, 154, 58); self::$effects[Effect::WATER_BREATHING] = new Effect(Effect::WATER_BREATHING, "Water Breathing", 46, 82, 153); self::$effects[Effect::INVISIBILITY] = new Effect(Effect::INVISIBILITY, "Invisibility", 127, 131, 146); - //self::$effects[Effect::WEAKNESS] = new Effect(Effect::WEAKNESS, "Weakness", 72, 77, 72 , true); + self::$effects[Effect::WEAKNESS] = new Effect(Effect::WEAKNESS, "Weakness", 72, 77, 72 , true); self::$effects[Effect::POISON] = new Effect(Effect::POISON, "Poison", 78, 147, 49, true); self::$effects[Effect::WITHER] = new Effect(Effect::WITHER, "Wither", 53, 42, 39, true); } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index de93c80a8..54c7734c2 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -323,10 +323,10 @@ abstract class Entity extends Location implements Metadatable{ foreach($this->effects as $effect){ if($effect->isVisible()){ $c = $effect->getColor(); - $color[0] += $c[0]; - $color[1] += $c[1]; - $color[2] += $c[2]; - ++$count; + $color[0] += $c[0] * ($effect->getAmplifier() + 1); + $color[1] += $c[1] * ($effect->getAmplifier() + 1); + $color[2] += $c[2] * ($effect->getAmplifier() + 1); + $count += $effect->getAmplifier() + 1; if(!$effect->isAmbient()){ $ambient = false; } @@ -1541,11 +1541,6 @@ abstract class Entity extends Location implements Metadatable{ return (((int) $this->getDataProperty($propertyId)) & (1 << $id)) > 0; } - /** - * @deprecated - */ - public function getData(){} - public function __destruct(){ $this->close(); } diff --git a/src/pocketmine/entity/FallingSand.php b/src/pocketmine/entity/FallingSand.php index 7b9c8170a..09af1e1ef 100644 --- a/src/pocketmine/entity/FallingSand.php +++ b/src/pocketmine/entity/FallingSand.php @@ -71,10 +71,6 @@ class FallingSand extends Entity{ return false; } - public function getData(){ - return []; - } - public function onUpdate($currentTick){ if($this->closed){ diff --git a/src/pocketmine/entity/Item.php b/src/pocketmine/entity/Item.php index 8ac5e4efc..b311951b8 100644 --- a/src/pocketmine/entity/Item.php +++ b/src/pocketmine/entity/Item.php @@ -148,15 +148,6 @@ class Item extends Entity{ } } - public function getData(){ - $flags = 0; - $flags |= $this->fireTicks > 0 ? 1 : 0; - - return [ - 0 => ["type" => 0, "value" => $flags] - ]; - } - /** * @return ItemItem */ diff --git a/src/pocketmine/entity/PrimedTNT.php b/src/pocketmine/entity/PrimedTNT.php index 4a135f861..5087e4c64 100644 --- a/src/pocketmine/entity/PrimedTNT.php +++ b/src/pocketmine/entity/PrimedTNT.php @@ -59,12 +59,6 @@ class PrimedTNT extends Entity implements Explosive{ return false; } - public function getData(){ - return [ - 16 => ["type" => 0, "value" => $this->fuse], - ]; - } - public function saveNBT(){ parent::saveNBT(); $this->namedtag->Fuse = new Byte("Fuse", $this->fuse); diff --git a/src/pocketmine/event/entity/EntityDamageByEntityEvent.php b/src/pocketmine/event/entity/EntityDamageByEntityEvent.php index 6d27ff289..2ee816d20 100644 --- a/src/pocketmine/event/entity/EntityDamageByEntityEvent.php +++ b/src/pocketmine/event/entity/EntityDamageByEntityEvent.php @@ -21,6 +21,7 @@ namespace pocketmine\event\entity; +use pocketmine\entity\Effect; use pocketmine\entity\Entity; class EntityDamageByEntityEvent extends EntityDamageEvent{ @@ -41,6 +42,17 @@ class EntityDamageByEntityEvent extends EntityDamageEvent{ $this->damager = $damager; $this->knockBack = $knockBack; parent::__construct($entity, $cause, $damage); + $this->addAttackerModifiers($damager); + } + + protected function addAttackerModifiers(Entity $damager){ + if($damager->hasEffect(Effect::STRENGTH)){ + $this->setDamage($this->getDamage(self::MODIFIER_BASE) * 0.3 * ($damager->getEffect(Effect::STRENGTH)->getAmplifier() + 1), self::MODIFIER_STRENGTH); + } + + if($damager->hasEffect(Effect::WEAKNESS)){ + $this->setDamage(-($this->getDamage(self::MODIFIER_BASE) * 0.2 * ($damager->getEffect(Effect::WEAKNESS)->getAmplifier() + 1)), self::MODIFIER_WEAKNESS); + } } /** diff --git a/src/pocketmine/event/entity/EntityDamageEvent.php b/src/pocketmine/event/entity/EntityDamageEvent.php index 79d689b9e..f792f6bda 100644 --- a/src/pocketmine/event/entity/EntityDamageEvent.php +++ b/src/pocketmine/event/entity/EntityDamageEvent.php @@ -21,6 +21,7 @@ namespace pocketmine\event\entity; +use pocketmine\entity\Effect; use pocketmine\entity\Entity; use pocketmine\event\Cancellable; @@ -29,6 +30,9 @@ class EntityDamageEvent extends EntityEvent implements Cancellable{ const MODIFIER_BASE = 0; const MODIFIER_ARMOR = 1; + const MODIFIER_STRENGTH = 2; + const MODIFIER_WEAKNESS = 3; + const MODIFIER_RESISTANCE = 4; const CAUSE_CONTACT = 0; const CAUSE_ENTITY_ATTACK = 1; @@ -76,6 +80,10 @@ class EntityDamageEvent extends EntityEvent implements Cancellable{ if(!isset($this->modifiers[self::MODIFIER_BASE])){ throw new \InvalidArgumentException("BASE Damage modifier missing"); } + + if($entity->hasEffect(Effect::DAMAGE_RESISTANCE)){ + $this->setDamage(-($this->getDamage(self::MODIFIER_BASE) * 0.20 * ($entity->getEffect(Effect::DAMAGE_RESISTANCE)->getAmplifier() + 1)), self::MODIFIER_RESISTANCE); + } } /** @@ -118,9 +126,6 @@ class EntityDamageEvent extends EntityEvent implements Cancellable{ * @throws \UnexpectedValueException */ public function setDamage($damage, $type = self::MODIFIER_BASE){ - if(!isset($this->modifiers[$type])){ - throw new \UnexpectedValueException($type . " is not applicable to " . $this->getEntity()); - } $this->modifiers[$type] = $damage; } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 20126082b..3cc6fdde4 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1492,10 +1492,10 @@ class Level implements ChunkManager, Metadatable{ $nearby = []; if($entity === null or $entity->canCollide){ - $minX = Math::floorFloat(($bb->minX - 2) / 16); - $maxX = Math::floorFloat(($bb->maxX + 2) / 16); - $minZ = Math::floorFloat(($bb->minZ - 2) / 16); - $maxZ = Math::floorFloat(($bb->maxZ + 2) / 16); + $minX = Math::ceilFloat(($bb->minX - 2) / 16); + $maxX = Math::ceilFloat(($bb->maxX + 2) / 16); + $minZ = Math::ceilFloat(($bb->minZ - 2) / 16); + $maxZ = Math::ceilFloat(($bb->maxZ + 2) / 16); for($x = $minX; $x <= $maxX; ++$x){ for($z = $minZ; $z <= $maxZ; ++$z){ @@ -1522,10 +1522,10 @@ class Level implements ChunkManager, Metadatable{ public function getNearbyEntities(AxisAlignedBB $bb, Entity $entity = null){ $nearby = []; - $minX = Math::floorFloat(($bb->minX - 2) / 16); - $maxX = Math::floorFloat(($bb->maxX + 2) / 16); - $minZ = Math::floorFloat(($bb->minZ - 2) / 16); - $maxZ = Math::floorFloat(($bb->maxZ + 2) / 16); + $minX = Math::ceilFloat(($bb->minX - 2) / 16); + $maxX = Math::ceilFloat(($bb->maxX + 2) / 16); + $minZ = Math::ceilFloat(($bb->minZ - 2) / 16); + $maxZ = Math::ceilFloat(($bb->maxZ + 2) / 16); for($x = $minX; $x <= $maxX; ++$x){ for($z = $minZ; $z <= $maxZ; ++$z){ @@ -2197,7 +2197,7 @@ class Level implements ChunkManager, Metadatable{ for(; $v->y >= 0 and $v->y < 128; ++$v->y){ if(!Block::$solid[$chunk->getBlockId($x, $v->y + 1, $z)]){ if(!Block::$solid[$chunk->getBlockId($x, $v->y, $z)]){ - return new Position($spawn->x, $v->y === Math::floorFloat($spawn->y) ? $spawn->y : $v->y, $spawn->z, $this); + return new Position($spawn->x, $v->y === (int) $spawn->y ? $spawn->y : $v->y, $spawn->z, $this); } }else{ ++$v->y; diff --git a/src/pocketmine/math/Math.php b/src/pocketmine/math/Math.php index 7efdf6070..8d10e2b24 100644 --- a/src/pocketmine/math/Math.php +++ b/src/pocketmine/math/Math.php @@ -31,4 +31,9 @@ abstract class Math{ $i = (int) $n; return $n >= $i ? $i : $i - 1; } + + public static function ceilFloat($n){ + $i = (int) ($n + 1); + return $n >= $i ? $i : $i - 1; + } } \ No newline at end of file