mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-20 07:39:42 +00:00
Removed pocketmine subdirectory, map PSR-4 style
This commit is contained in:
358
src/item/enchantment/Enchantment.php
Normal file
358
src/item/enchantment/Enchantment.php
Normal file
@@ -0,0 +1,358 @@
|
||||
<?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\item\enchantment;
|
||||
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
use function constant;
|
||||
use function defined;
|
||||
use function strtoupper;
|
||||
|
||||
/**
|
||||
* Manages enchantment type data.
|
||||
*/
|
||||
class Enchantment{
|
||||
|
||||
public const PROTECTION = 0;
|
||||
public const FIRE_PROTECTION = 1;
|
||||
public const FEATHER_FALLING = 2;
|
||||
public const BLAST_PROTECTION = 3;
|
||||
public const PROJECTILE_PROTECTION = 4;
|
||||
public const THORNS = 5;
|
||||
public const RESPIRATION = 6;
|
||||
public const DEPTH_STRIDER = 7;
|
||||
public const AQUA_AFFINITY = 8;
|
||||
public const SHARPNESS = 9;
|
||||
public const SMITE = 10;
|
||||
public const BANE_OF_ARTHROPODS = 11;
|
||||
public const KNOCKBACK = 12;
|
||||
public const FIRE_ASPECT = 13;
|
||||
public const LOOTING = 14;
|
||||
public const EFFICIENCY = 15;
|
||||
public const SILK_TOUCH = 16;
|
||||
public const UNBREAKING = 17;
|
||||
public const FORTUNE = 18;
|
||||
public const POWER = 19;
|
||||
public const PUNCH = 20;
|
||||
public const FLAME = 21;
|
||||
public const INFINITY = 22;
|
||||
public const LUCK_OF_THE_SEA = 23;
|
||||
public const LURE = 24;
|
||||
public const FROST_WALKER = 25;
|
||||
public const MENDING = 26;
|
||||
public const BINDING = 27;
|
||||
public const VANISHING = 28;
|
||||
public const IMPALING = 29;
|
||||
public const RIPTIDE = 30;
|
||||
public const LOYALTY = 31;
|
||||
public const CHANNELING = 32;
|
||||
|
||||
public const RARITY_COMMON = 10;
|
||||
public const RARITY_UNCOMMON = 5;
|
||||
public const RARITY_RARE = 2;
|
||||
public const RARITY_MYTHIC = 1;
|
||||
|
||||
public const SLOT_NONE = 0x0;
|
||||
public const SLOT_ALL = 0xffff;
|
||||
public const SLOT_ARMOR = self::SLOT_HEAD | self::SLOT_TORSO | self::SLOT_LEGS | self::SLOT_FEET;
|
||||
public const SLOT_HEAD = 0x1;
|
||||
public const SLOT_TORSO = 0x2;
|
||||
public const SLOT_LEGS = 0x4;
|
||||
public const SLOT_FEET = 0x8;
|
||||
public const SLOT_SWORD = 0x10;
|
||||
public const SLOT_BOW = 0x20;
|
||||
public const SLOT_TOOL = self::SLOT_HOE | self::SLOT_SHEARS | self::SLOT_FLINT_AND_STEEL;
|
||||
public const SLOT_HOE = 0x40;
|
||||
public const SLOT_SHEARS = 0x80;
|
||||
public const SLOT_FLINT_AND_STEEL = 0x100;
|
||||
public const SLOT_DIG = self::SLOT_AXE | self::SLOT_PICKAXE | self::SLOT_SHOVEL;
|
||||
public const SLOT_AXE = 0x200;
|
||||
public const SLOT_PICKAXE = 0x400;
|
||||
public const SLOT_SHOVEL = 0x800;
|
||||
public const SLOT_FISHING_ROD = 0x1000;
|
||||
public const SLOT_CARROT_STICK = 0x2000;
|
||||
public const SLOT_ELYTRA = 0x4000;
|
||||
public const SLOT_TRIDENT = 0x8000;
|
||||
|
||||
/** @var Enchantment[] */
|
||||
protected static $enchantments;
|
||||
|
||||
public static function init() : void{
|
||||
self::$enchantments = new \SplFixedArray(256);
|
||||
|
||||
self::register(new ProtectionEnchantment(self::PROTECTION, "%enchantment.protect.all", self::RARITY_COMMON, self::SLOT_ARMOR, self::SLOT_NONE, 4, 0.75, null));
|
||||
self::register(new ProtectionEnchantment(self::FIRE_PROTECTION, "%enchantment.protect.fire", self::RARITY_UNCOMMON, self::SLOT_ARMOR, self::SLOT_NONE, 4, 1.25, [
|
||||
EntityDamageEvent::CAUSE_FIRE,
|
||||
EntityDamageEvent::CAUSE_FIRE_TICK,
|
||||
EntityDamageEvent::CAUSE_LAVA
|
||||
//TODO: check fireballs
|
||||
]));
|
||||
self::register(new ProtectionEnchantment(self::FEATHER_FALLING, "%enchantment.protect.fall", self::RARITY_UNCOMMON, self::SLOT_FEET, self::SLOT_NONE, 4, 2.5, [
|
||||
EntityDamageEvent::CAUSE_FALL
|
||||
]));
|
||||
self::register(new ProtectionEnchantment(self::BLAST_PROTECTION, "%enchantment.protect.explosion", self::RARITY_RARE, self::SLOT_ARMOR, self::SLOT_NONE, 4, 1.5, [
|
||||
EntityDamageEvent::CAUSE_BLOCK_EXPLOSION,
|
||||
EntityDamageEvent::CAUSE_ENTITY_EXPLOSION
|
||||
]));
|
||||
self::register(new ProtectionEnchantment(self::PROJECTILE_PROTECTION, "%enchantment.protect.projectile", self::RARITY_UNCOMMON, self::SLOT_ARMOR, self::SLOT_NONE, 4, 1.5, [
|
||||
EntityDamageEvent::CAUSE_PROJECTILE
|
||||
]));
|
||||
self::register(new Enchantment(self::THORNS, "%enchantment.thorns", self::RARITY_MYTHIC, self::SLOT_TORSO, self::SLOT_HEAD | self::SLOT_LEGS | self::SLOT_FEET, 3));
|
||||
self::register(new Enchantment(self::RESPIRATION, "%enchantment.oxygen", self::RARITY_RARE, self::SLOT_HEAD, self::SLOT_NONE, 3));
|
||||
|
||||
self::register(new SharpnessEnchantment(self::SHARPNESS, "%enchantment.damage.all", self::RARITY_COMMON, self::SLOT_SWORD, self::SLOT_AXE, 5));
|
||||
//TODO: smite, bane of arthropods (these don't make sense now because their applicable mobs don't exist yet)
|
||||
|
||||
self::register(new KnockbackEnchantment(self::KNOCKBACK, "%enchantment.knockback", self::RARITY_UNCOMMON, self::SLOT_SWORD, self::SLOT_NONE, 2));
|
||||
self::register(new FireAspectEnchantment(self::FIRE_ASPECT, "%enchantment.fire", self::RARITY_RARE, self::SLOT_SWORD, self::SLOT_NONE, 2));
|
||||
|
||||
self::register(new Enchantment(self::EFFICIENCY, "%enchantment.digging", self::RARITY_COMMON, self::SLOT_DIG, self::SLOT_SHEARS, 5));
|
||||
self::register(new Enchantment(self::SILK_TOUCH, "%enchantment.untouching", self::RARITY_MYTHIC, self::SLOT_DIG, self::SLOT_SHEARS, 1));
|
||||
self::register(new Enchantment(self::UNBREAKING, "%enchantment.durability", self::RARITY_UNCOMMON, self::SLOT_DIG | self::SLOT_ARMOR | self::SLOT_FISHING_ROD | self::SLOT_BOW, self::SLOT_TOOL | self::SLOT_CARROT_STICK | self::SLOT_ELYTRA, 3));
|
||||
|
||||
self::register(new Enchantment(self::POWER, "%enchantment.arrowDamage", self::RARITY_COMMON, self::SLOT_BOW, self::SLOT_NONE, 5));
|
||||
self::register(new Enchantment(self::PUNCH, "%enchantment.arrowKnockback", self::RARITY_RARE, self::SLOT_BOW, self::SLOT_NONE, 2));
|
||||
self::register(new Enchantment(self::FLAME, "%enchantment.arrowFire", self::RARITY_RARE, self::SLOT_BOW, self::SLOT_NONE, 1));
|
||||
self::register(new Enchantment(self::INFINITY, "%enchantment.arrowInfinite", self::RARITY_MYTHIC, self::SLOT_BOW, self::SLOT_NONE, 1));
|
||||
|
||||
self::register(new Enchantment(self::MENDING, "%enchantment.mending", self::RARITY_RARE, self::SLOT_NONE, self::SLOT_ALL, 1));
|
||||
|
||||
self::register(new Enchantment(self::VANISHING, "%enchantment.curse.vanishing", self::RARITY_MYTHIC, self::SLOT_NONE, self::SLOT_ALL, 1));
|
||||
}
|
||||
|
||||
//region --- auto-generated code ---
|
||||
|
||||
public static function BLAST_PROTECTION() : Enchantment{
|
||||
return self::get(self::BLAST_PROTECTION);
|
||||
}
|
||||
|
||||
public static function EFFICIENCY() : Enchantment{
|
||||
return self::get(self::EFFICIENCY);
|
||||
}
|
||||
|
||||
public static function FEATHER_FALLING() : Enchantment{
|
||||
return self::get(self::FEATHER_FALLING);
|
||||
}
|
||||
|
||||
public static function FIRE_ASPECT() : Enchantment{
|
||||
return self::get(self::FIRE_ASPECT);
|
||||
}
|
||||
|
||||
public static function FIRE_PROTECTION() : Enchantment{
|
||||
return self::get(self::FIRE_PROTECTION);
|
||||
}
|
||||
|
||||
public static function FLAME() : Enchantment{
|
||||
return self::get(self::FLAME);
|
||||
}
|
||||
|
||||
public static function INFINITY() : Enchantment{
|
||||
return self::get(self::INFINITY);
|
||||
}
|
||||
|
||||
public static function KNOCKBACK() : Enchantment{
|
||||
return self::get(self::KNOCKBACK);
|
||||
}
|
||||
|
||||
public static function MENDING() : Enchantment{
|
||||
return self::get(self::MENDING);
|
||||
}
|
||||
|
||||
public static function POWER() : Enchantment{
|
||||
return self::get(self::POWER);
|
||||
}
|
||||
|
||||
public static function PROJECTILE_PROTECTION() : Enchantment{
|
||||
return self::get(self::PROJECTILE_PROTECTION);
|
||||
}
|
||||
|
||||
public static function PROTECTION() : Enchantment{
|
||||
return self::get(self::PROTECTION);
|
||||
}
|
||||
|
||||
public static function PUNCH() : Enchantment{
|
||||
return self::get(self::PUNCH);
|
||||
}
|
||||
|
||||
public static function RESPIRATION() : Enchantment{
|
||||
return self::get(self::RESPIRATION);
|
||||
}
|
||||
|
||||
public static function SHARPNESS() : Enchantment{
|
||||
return self::get(self::SHARPNESS);
|
||||
}
|
||||
|
||||
public static function SILK_TOUCH() : Enchantment{
|
||||
return self::get(self::SILK_TOUCH);
|
||||
}
|
||||
|
||||
public static function THORNS() : Enchantment{
|
||||
return self::get(self::THORNS);
|
||||
}
|
||||
|
||||
public static function UNBREAKING() : Enchantment{
|
||||
return self::get(self::UNBREAKING);
|
||||
}
|
||||
|
||||
public static function VANISHING() : Enchantment{
|
||||
return self::get(self::VANISHING);
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
/**
|
||||
* Registers an enchantment type.
|
||||
*
|
||||
* @param Enchantment $enchantment
|
||||
*/
|
||||
public static function register(Enchantment $enchantment) : void{
|
||||
self::$enchantments[$enchantment->getId()] = clone $enchantment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return Enchantment|null
|
||||
*/
|
||||
public static function get(int $id) : ?Enchantment{
|
||||
return self::$enchantments[$id] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return Enchantment|null
|
||||
*/
|
||||
public static function fromString(string $name) : ?Enchantment{
|
||||
$const = Enchantment::class . "::" . strtoupper($name);
|
||||
if(defined($const)){
|
||||
return self::get(constant($const));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var int */
|
||||
private $id;
|
||||
/** @var string */
|
||||
private $name;
|
||||
/** @var int */
|
||||
private $rarity;
|
||||
/** @var int */
|
||||
private $primaryItemFlags;
|
||||
/** @var int */
|
||||
private $secondaryItemFlags;
|
||||
/** @var int */
|
||||
private $maxLevel;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param string $name
|
||||
* @param int $rarity
|
||||
* @param int $primaryItemFlags
|
||||
* @param int $secondaryItemFlags
|
||||
* @param int $maxLevel
|
||||
*/
|
||||
public function __construct(int $id, string $name, int $rarity, int $primaryItemFlags, int $secondaryItemFlags, int $maxLevel){
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
$this->rarity = $rarity;
|
||||
$this->primaryItemFlags = $primaryItemFlags;
|
||||
$this->secondaryItemFlags = $secondaryItemFlags;
|
||||
$this->maxLevel = $maxLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID of this enchantment as per Minecraft PE
|
||||
* @return int
|
||||
*/
|
||||
public function getId() : int{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a translation key for this enchantment's name.
|
||||
* @return string
|
||||
*/
|
||||
public function getName() : string{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an int constant indicating how rare this enchantment type is.
|
||||
* @return int
|
||||
*/
|
||||
public function getRarity() : int{
|
||||
return $this->rarity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a bitset indicating what item types can have this item applied from an enchanting table.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPrimaryItemFlags() : int{
|
||||
return $this->primaryItemFlags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a bitset indicating what item types cannot have this item applied from an enchanting table, but can from
|
||||
* an anvil.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getSecondaryItemFlags() : int{
|
||||
return $this->secondaryItemFlags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this enchantment can apply to the item type from an enchanting table.
|
||||
*
|
||||
* @param int $flag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPrimaryItemType(int $flag) : bool{
|
||||
return ($this->primaryItemFlags & $flag) !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this enchantment can apply to the item type from an anvil, if it is not a primary item.
|
||||
*
|
||||
* @param int $flag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasSecondaryItemType(int $flag) : bool{
|
||||
return ($this->secondaryItemFlags & $flag) !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum level of this enchantment that can be found on an enchantment table.
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxLevel() : int{
|
||||
return $this->maxLevel;
|
||||
}
|
||||
|
||||
//TODO: methods for min/max XP cost bounds based on enchantment level (not needed yet - enchanting is client-side)
|
||||
}
|
58
src/item/enchantment/EnchantmentEntry.php
Normal file
58
src/item/enchantment/EnchantmentEntry.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?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\item\enchantment;
|
||||
|
||||
|
||||
class EnchantmentEntry{
|
||||
|
||||
/** @var Enchantment[] */
|
||||
private $enchantments;
|
||||
/** @var int */
|
||||
private $cost;
|
||||
/** @var string */
|
||||
private $randomName;
|
||||
|
||||
/**
|
||||
* @param Enchantment[] $enchantments
|
||||
* @param int $cost
|
||||
* @param string $randomName
|
||||
*/
|
||||
public function __construct(array $enchantments, int $cost, string $randomName){
|
||||
$this->enchantments = $enchantments;
|
||||
$this->cost = $cost;
|
||||
$this->randomName = $randomName;
|
||||
}
|
||||
|
||||
public function getEnchantments() : array{
|
||||
return $this->enchantments;
|
||||
}
|
||||
|
||||
public function getCost() : int{
|
||||
return $this->cost;
|
||||
}
|
||||
|
||||
public function getRandomName() : string{
|
||||
return $this->randomName;
|
||||
}
|
||||
}
|
71
src/item/enchantment/EnchantmentInstance.php
Normal file
71
src/item/enchantment/EnchantmentInstance.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?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\item\enchantment;
|
||||
|
||||
/**
|
||||
* Container for enchantment data applied to items.
|
||||
*
|
||||
* Note: This class is assumed to be immutable. Consider this before making alterations.
|
||||
*/
|
||||
final class EnchantmentInstance{
|
||||
/** @var Enchantment */
|
||||
private $enchantment;
|
||||
/** @var int */
|
||||
private $level;
|
||||
|
||||
/**
|
||||
* EnchantmentInstance constructor.
|
||||
*
|
||||
* @param Enchantment $enchantment Enchantment type
|
||||
* @param int $level Level of enchantment
|
||||
*/
|
||||
public function __construct(Enchantment $enchantment, int $level = 1){
|
||||
$this->enchantment = $enchantment;
|
||||
$this->level = $level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of this enchantment.
|
||||
* @return Enchantment
|
||||
*/
|
||||
public function getType() : Enchantment{
|
||||
return $this->enchantment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type identifier of this enchantment instance.
|
||||
* @return int
|
||||
*/
|
||||
public function getId() : int{
|
||||
return $this->enchantment->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the level of the enchantment.
|
||||
* @return int
|
||||
*/
|
||||
public function getLevel() : int{
|
||||
return $this->level;
|
||||
}
|
||||
}
|
56
src/item/enchantment/EnchantmentList.php
Normal file
56
src/item/enchantment/EnchantmentList.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?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\item\enchantment;
|
||||
|
||||
|
||||
class EnchantmentList{
|
||||
|
||||
/** @var \SplFixedArray|EnchantmentEntry[] */
|
||||
private $enchantments;
|
||||
|
||||
public function __construct(int $size){
|
||||
$this->enchantments = new \SplFixedArray($size);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $slot
|
||||
* @param EnchantmentEntry $entry
|
||||
*/
|
||||
public function setSlot(int $slot, EnchantmentEntry $entry) : void{
|
||||
$this->enchantments[$slot] = $entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $slot
|
||||
*
|
||||
* @return EnchantmentEntry
|
||||
*/
|
||||
public function getSlot(int $slot) : EnchantmentEntry{
|
||||
return $this->enchantments[$slot];
|
||||
}
|
||||
|
||||
public function getSize() : int{
|
||||
return $this->enchantments->getSize();
|
||||
}
|
||||
}
|
41
src/item/enchantment/FireAspectEnchantment.php
Normal file
41
src/item/enchantment/FireAspectEnchantment.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?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\item\enchantment;
|
||||
|
||||
use pocketmine\entity\Entity;
|
||||
|
||||
class FireAspectEnchantment extends MeleeWeaponEnchantment{
|
||||
|
||||
public function isApplicableTo(Entity $victim) : bool{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getDamageBonus(int $enchantmentLevel) : float{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function onPostAttack(Entity $attacker, Entity $victim, int $enchantmentLevel) : void{
|
||||
$victim->setOnFire($enchantmentLevel * 4);
|
||||
}
|
||||
}
|
44
src/item/enchantment/KnockbackEnchantment.php
Normal file
44
src/item/enchantment/KnockbackEnchantment.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?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\item\enchantment;
|
||||
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\entity\Living;
|
||||
|
||||
class KnockbackEnchantment extends MeleeWeaponEnchantment{
|
||||
|
||||
public function isApplicableTo(Entity $victim) : bool{
|
||||
return $victim instanceof Living;
|
||||
}
|
||||
|
||||
public function getDamageBonus(int $enchantmentLevel) : float{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function onPostAttack(Entity $attacker, Entity $victim, int $enchantmentLevel) : void{
|
||||
if($victim instanceof Living){
|
||||
$victim->knockBack($victim->x - $attacker->x, $victim->z - $attacker->z, $enchantmentLevel * 0.5);
|
||||
}
|
||||
}
|
||||
}
|
63
src/item/enchantment/MeleeWeaponEnchantment.php
Normal file
63
src/item/enchantment/MeleeWeaponEnchantment.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?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\item\enchantment;
|
||||
|
||||
use pocketmine\entity\Entity;
|
||||
|
||||
/**
|
||||
* Classes extending this class can be applied to weapons and activate when used by a mob to attack another mob in melee
|
||||
* combat.
|
||||
*/
|
||||
abstract class MeleeWeaponEnchantment extends Enchantment{
|
||||
|
||||
/**
|
||||
* Returns whether this melee enchantment has an effect on the target entity. For example, Smite only applies to
|
||||
* undead mobs.
|
||||
*
|
||||
* @param Entity $victim
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract public function isApplicableTo(Entity $victim) : bool;
|
||||
|
||||
/**
|
||||
* Returns the amount of additional damage caused by this enchantment to applicable targets.
|
||||
*
|
||||
* @param int $enchantmentLevel
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
abstract public function getDamageBonus(int $enchantmentLevel) : float;
|
||||
|
||||
/**
|
||||
* Called after damaging the entity to apply any post damage effects to the target.
|
||||
*
|
||||
* @param Entity $attacker
|
||||
* @param Entity $victim
|
||||
* @param int $enchantmentLevel
|
||||
*/
|
||||
public function onPostAttack(Entity $attacker, Entity $victim, int $enchantmentLevel) : void{
|
||||
|
||||
}
|
||||
}
|
86
src/item/enchantment/ProtectionEnchantment.php
Normal file
86
src/item/enchantment/ProtectionEnchantment.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?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\item\enchantment;
|
||||
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
use function array_flip;
|
||||
use function floor;
|
||||
|
||||
class ProtectionEnchantment extends Enchantment{
|
||||
/** @var float */
|
||||
protected $typeModifier;
|
||||
/** @var int[]|null */
|
||||
protected $applicableDamageTypes = null;
|
||||
|
||||
/**
|
||||
* ProtectionEnchantment constructor.
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $name
|
||||
* @param int $rarity
|
||||
* @param int $primaryItemFlags
|
||||
* @param int $secondaryItemFlags
|
||||
* @param int $maxLevel
|
||||
* @param float $typeModifier
|
||||
* @param int[]|null $applicableDamageTypes EntityDamageEvent::CAUSE_* constants which this enchantment type applies to, or null if it applies to all types of damage.
|
||||
*/
|
||||
public function __construct(int $id, string $name, int $rarity, int $primaryItemFlags, int $secondaryItemFlags, int $maxLevel, float $typeModifier, ?array $applicableDamageTypes){
|
||||
parent::__construct($id, $name, $rarity, $primaryItemFlags, $secondaryItemFlags, $maxLevel);
|
||||
|
||||
$this->typeModifier = $typeModifier;
|
||||
if($applicableDamageTypes !== null){
|
||||
$this->applicableDamageTypes = array_flip($applicableDamageTypes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the multiplier by which this enchantment type's EPF increases with each enchantment level.
|
||||
* @return float
|
||||
*/
|
||||
public function getTypeModifier() : float{
|
||||
return $this->typeModifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the base EPF this enchantment type offers for the given enchantment level.
|
||||
*
|
||||
* @param int $level
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getProtectionFactor(int $level) : int{
|
||||
return (int) floor((6 + $level ** 2) * $this->typeModifier / 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this enchantment type offers protection from the specified damage source's cause.
|
||||
*
|
||||
* @param EntityDamageEvent $event
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isApplicable(EntityDamageEvent $event) : bool{
|
||||
return $this->applicableDamageTypes === null or isset($this->applicableDamageTypes[$event->getCause()]);
|
||||
}
|
||||
}
|
37
src/item/enchantment/SharpnessEnchantment.php
Normal file
37
src/item/enchantment/SharpnessEnchantment.php
Normal 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\item\enchantment;
|
||||
|
||||
use pocketmine\entity\Entity;
|
||||
|
||||
class SharpnessEnchantment extends MeleeWeaponEnchantment{
|
||||
|
||||
public function isApplicableTo(Entity $victim) : bool{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getDamageBonus(int $enchantmentLevel) : float{
|
||||
return 0.5 * ($enchantmentLevel + 1);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user