mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Implemented armor durability
This commit is contained in:
parent
74cff89df3
commit
e06b78b0ee
@ -44,6 +44,7 @@ use pocketmine\nbt\tag\FloatTag;
|
||||
use pocketmine\nbt\tag\IntTag;
|
||||
use pocketmine\nbt\tag\ListTag;
|
||||
use pocketmine\network\mcpe\protocol\EntityEventPacket;
|
||||
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
|
||||
use pocketmine\network\mcpe\protocol\MobEffectPacket;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\utils\Binary;
|
||||
@ -466,6 +467,29 @@ abstract class Living extends Entity implements Damageable{
|
||||
*/
|
||||
protected function applyPostDamageEffects(EntityDamageEvent $source) : void{
|
||||
$this->setAbsorption(max(0, $this->getAbsorption() + $source->getDamage(EntityDamageEvent::MODIFIER_ABSORPTION)));
|
||||
$this->damageArmor($source->getDamage(EntityDamageEvent::MODIFIER_BASE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Damages the worn armour according to the amount of damage given. Each 4 points (rounded down) deals 1 damage
|
||||
* point to each armour piece, but never less than 1 total.
|
||||
*
|
||||
* @param float $damage
|
||||
*/
|
||||
public function damageArmor(float $damage) : void{
|
||||
$durabilityRemoved = (int) max(floor($damage / 4), 1);
|
||||
|
||||
$armor = $this->armorInventory->getContents(true);
|
||||
foreach($armor as $item){
|
||||
if($item instanceof Armor){
|
||||
$item->applyDamage($durabilityRemoved);
|
||||
if($item->isBroken()){
|
||||
$this->level->broadcastLevelSoundEvent($this, LevelSoundEventPacket::SOUND_BREAK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->armorInventory->setContents($armor);
|
||||
}
|
||||
|
||||
public function attack(EntityDamageEvent $source){
|
||||
|
@ -25,12 +25,13 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
use pocketmine\item\enchantment\Enchantment;
|
||||
use pocketmine\item\enchantment\ProtectionEnchantment;
|
||||
use pocketmine\nbt\tag\IntTag;
|
||||
use pocketmine\utils\Binary;
|
||||
use pocketmine\utils\Color;
|
||||
|
||||
abstract class Armor extends Item{
|
||||
abstract class Armor extends Durable{
|
||||
|
||||
public const TAG_CUSTOM_COLOR = "customColor"; //TAG_Int
|
||||
|
||||
@ -78,4 +79,21 @@ abstract class Armor extends Item{
|
||||
|
||||
return $epf;
|
||||
}
|
||||
|
||||
protected function getUnbreakingDamageReduction(int $amount) : int{
|
||||
if(($unbreakingLevel = $this->getEnchantmentLevel(Enchantment::UNBREAKING)) > 0){
|
||||
$negated = 0;
|
||||
|
||||
$chance = 1 / ($unbreakingLevel + 1);
|
||||
for($i = 0; $i < $amount; ++$i){
|
||||
if(mt_rand(1, 100) > 60 and lcg_value() > $chance){ //unbreaking only applies to armor 40% of the time at best
|
||||
$negated++;
|
||||
}
|
||||
}
|
||||
|
||||
return $negated;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,8 @@ class ChainBoots extends Armor{
|
||||
public function getDefensePoints() : int{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function getMaxDurability() : int{
|
||||
return 196;
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,8 @@ class ChainChestplate extends Armor{
|
||||
public function getDefensePoints() : int{
|
||||
return 5;
|
||||
}
|
||||
|
||||
public function getMaxDurability() : int{
|
||||
return 241;
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,8 @@ class ChainHelmet extends Armor{
|
||||
public function getDefensePoints() : int{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function getMaxDurability() : int{
|
||||
return 166;
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,8 @@ class ChainLeggings extends Armor{
|
||||
public function getDefensePoints() : int{
|
||||
return 4;
|
||||
}
|
||||
|
||||
public function getMaxDurability() : int{
|
||||
return 226;
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,8 @@ class DiamondBoots extends Armor{
|
||||
public function getDefensePoints() : int{
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function getMaxDurability() : int{
|
||||
return 430;
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,8 @@ class DiamondChestplate extends Armor{
|
||||
public function getDefensePoints() : int{
|
||||
return 8;
|
||||
}
|
||||
|
||||
public function getMaxDurability() : int{
|
||||
return 529;
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,8 @@ class DiamondHelmet extends Armor{
|
||||
public function getDefensePoints() : int{
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function getMaxDurability() : int{
|
||||
return 364;
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,8 @@ class DiamondLeggings extends Armor{
|
||||
public function getDefensePoints() : int{
|
||||
return 6;
|
||||
}
|
||||
|
||||
public function getMaxDurability() : int{
|
||||
return 496;
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,8 @@ class GoldBoots extends Armor{
|
||||
public function getDefensePoints() : int{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function getMaxDurability() : int{
|
||||
return 92;
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,8 @@ class GoldChestplate extends Armor{
|
||||
public function getDefensePoints() : int{
|
||||
return 5;
|
||||
}
|
||||
|
||||
public function getMaxDurability() : int{
|
||||
return 113;
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,8 @@ class GoldHelmet extends Armor{
|
||||
public function getDefensePoints() : int{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function getMaxDurability() : int{
|
||||
return 78;
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,8 @@ class GoldLeggings extends Armor{
|
||||
public function getDefensePoints() : int{
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function getMaxDurability() : int{
|
||||
return 106;
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,8 @@ class IronBoots extends Armor{
|
||||
public function getDefensePoints() : int{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function getMaxDurability() : int{
|
||||
return 196;
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,8 @@ class IronChestplate extends Armor{
|
||||
public function getDefensePoints() : int{
|
||||
return 6;
|
||||
}
|
||||
|
||||
public function getMaxDurability() : int{
|
||||
return 241;
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,8 @@ class IronHelmet extends Armor{
|
||||
public function getDefensePoints() : int{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function getMaxDurability() : int{
|
||||
return 166;
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,8 @@ class IronLeggings extends Armor{
|
||||
public function getDefensePoints() : int{
|
||||
return 5;
|
||||
}
|
||||
|
||||
public function getMaxDurability() : int{
|
||||
return 226;
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,8 @@ class LeatherBoots extends Armor{
|
||||
public function getDefensePoints() : int{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function getMaxDurability() : int{
|
||||
return 66;
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,8 @@ class LeatherCap extends Armor{
|
||||
public function getDefensePoints() : int{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function getMaxDurability() : int{
|
||||
return 56;
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,8 @@ class LeatherPants extends Armor{
|
||||
public function getDefensePoints() : int{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public function getMaxDurability() : int{
|
||||
return 76;
|
||||
}
|
||||
}
|
||||
|
@ -32,4 +32,8 @@ class LeatherTunic extends Armor{
|
||||
public function getDefensePoints() : int{
|
||||
return 3;
|
||||
}
|
||||
|
||||
public function getMaxDurability() : int{
|
||||
return 81;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user