Removed damage-table mess and added API methods Item->getAttackPoints() and Item->getDefensePoints()

This commit is contained in:
Dylan K. Taylor 2017-08-26 12:58:20 +01:00
parent 7c212d3d53
commit 13187e1749
42 changed files with 183 additions and 57 deletions

View File

@ -2232,35 +2232,10 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
break;
}
$item = $this->inventory->getItemInHand();
$damageTable = [
Item::WOODEN_SWORD => 4,
Item::GOLDEN_SWORD => 4,
Item::STONE_SWORD => 5,
Item::IRON_SWORD => 6,
Item::DIAMOND_SWORD => 7,
Item::WOODEN_AXE => 3,
Item::GOLDEN_AXE => 3,
Item::STONE_AXE => 3,
Item::IRON_AXE => 5,
Item::DIAMOND_AXE => 6,
Item::WOODEN_PICKAXE => 2,
Item::GOLDEN_PICKAXE => 2,
Item::STONE_PICKAXE => 3,
Item::IRON_PICKAXE => 4,
Item::DIAMOND_PICKAXE => 5,
Item::WOODEN_SHOVEL => 1,
Item::GOLDEN_SHOVEL => 1,
Item::STONE_SHOVEL => 2,
Item::IRON_SHOVEL => 3,
Item::DIAMOND_SHOVEL => 4,
];
$heldItem = $this->inventory->getItemInHand();
$damage = [
EntityDamageEvent::MODIFIER_BASE => $damageTable[$item->getId()] ?? 1,
EntityDamageEvent::MODIFIER_BASE => $heldItem->getAttackPoints(),
];
if(!$this->canInteract($target, 8)){
@ -2272,33 +2247,9 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$cancelled = true;
}
$armorValues = [
Item::LEATHER_CAP => 1,
Item::LEATHER_TUNIC => 3,
Item::LEATHER_PANTS => 2,
Item::LEATHER_BOOTS => 1,
Item::CHAINMAIL_HELMET => 1,
Item::CHAINMAIL_CHESTPLATE => 5,
Item::CHAINMAIL_LEGGINGS => 4,
Item::CHAINMAIL_BOOTS => 1,
Item::GOLDEN_HELMET => 1,
Item::GOLDEN_CHESTPLATE => 5,
Item::GOLDEN_LEGGINGS => 3,
Item::GOLDEN_BOOTS => 1,
Item::IRON_HELMET => 2,
Item::IRON_CHESTPLATE => 6,
Item::IRON_LEGGINGS => 5,
Item::IRON_BOOTS => 2,
Item::DIAMOND_HELMET => 3,
Item::DIAMOND_CHESTPLATE => 8,
Item::DIAMOND_LEGGINGS => 6,
Item::DIAMOND_BOOTS => 3,
];
$points = 0;
foreach($target->getInventory()->getArmorContents() as $index => $i){
if(isset($armorValues[$i->getId()])){
$points += $armorValues[$i->getId()];
}
foreach($target->getInventory()->getArmorContents() as $armorItem){
$points += $armorItem->getDefensePoints();
}
$damage[EntityDamageEvent::MODIFIER_ARMOR] = -floor($damage[EntityDamageEvent::MODIFIER_BASE] * $points * 0.04);
@ -2312,18 +2263,18 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$target->attack($ev);
if($ev->isCancelled()){
if($item->isTool() and $this->isSurvival()){
if($heldItem->isTool() and $this->isSurvival()){
$this->inventory->sendContents($this);
}
break;
}
if($this->isSurvival()){
if($item->isTool()){
if($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()){
if($heldItem->isTool()){
if($heldItem->useOn($target) and $heldItem->getDamage() >= $heldItem->getMaxDurability()){
$this->inventory->setItemInHand(ItemFactory::get(Item::AIR, 0, 1));
}else{
$this->inventory->setItemInHand($item);
$this->inventory->setItemInHand($heldItem);
}
}

View File

@ -28,4 +28,8 @@ class ChainBoots extends Armor{
public function __construct(int $meta = 0){
parent::__construct(self::CHAIN_BOOTS, $meta, "Chainmail Boots");
}
public function getDefensePoints() : int{
return 1;
}
}

View File

@ -28,4 +28,8 @@ class ChainChestplate extends Armor{
public function __construct(int $meta = 0){
parent::__construct(self::CHAIN_CHESTPLATE, $meta, "Chain Chestplate");
}
public function getDefensePoints() : int{
return 5;
}
}

View File

@ -28,4 +28,8 @@ class ChainHelmet extends Armor{
public function __construct(int $meta = 0){
parent::__construct(self::CHAIN_HELMET, $meta, "Chainmail Helmet");
}
public function getDefensePoints() : int{
return 2;
}
}

View File

@ -28,4 +28,8 @@ class ChainLeggings extends Armor{
public function __construct(int $meta = 0){
parent::__construct(self::CHAIN_LEGGINGS, $meta, "Chain Leggings");
}
public function getDefensePoints() : int{
return 4;
}
}

View File

@ -33,4 +33,7 @@ class DiamondAxe extends Tool{
return Tool::TIER_DIAMOND;
}
public function getAttackPoints() : int{
return 7;
}
}

View File

@ -28,4 +28,8 @@ class DiamondBoots extends Armor{
public function __construct(int $meta = 0){
parent::__construct(self::DIAMOND_BOOTS, $meta, "Diamond Boots");
}
public function getDefensePoints() : int{
return 3;
}
}

View File

@ -28,4 +28,8 @@ class DiamondChestplate extends Armor{
public function __construct(int $meta = 0){
parent::__construct(self::DIAMOND_CHESTPLATE, $meta, "Diamond Chestplate");
}
public function getDefensePoints() : int{
return 8;
}
}

View File

@ -28,4 +28,8 @@ class DiamondHelmet extends Armor{
public function __construct(int $meta = 0){
parent::__construct(self::DIAMOND_HELMET, $meta, "Diamond Helmet");
}
public function getDefensePoints() : int{
return 3;
}
}

View File

@ -28,4 +28,8 @@ class DiamondLeggings extends Armor{
public function __construct(int $meta = 0){
parent::__construct(self::DIAMOND_LEGGINGS, $meta, "Diamond Leggings");
}
public function getDefensePoints() : int{
return 6;
}
}

View File

@ -32,4 +32,8 @@ class DiamondPickaxe extends Tool{
public function isPickaxe(){
return Tool::TIER_DIAMOND;
}
public function getAttackPoints() : int{
return 6;
}
}

View File

@ -32,4 +32,8 @@ class DiamondShovel extends Tool{
public function isShovel(){
return Tool::TIER_DIAMOND;
}
public function getAttackPoints() : int{
return 5;
}
}

View File

@ -32,4 +32,8 @@ class DiamondSword extends Tool{
public function isSword(){
return Tool::TIER_DIAMOND;
}
public function getAttackPoints() : int{
return 8;
}
}

View File

@ -32,4 +32,8 @@ class GoldAxe extends Tool{
public function isAxe(){
return Tool::TIER_GOLD;
}
public function getAttackPoints() : int{
return 4;
}
}

View File

@ -28,4 +28,8 @@ class GoldBoots extends Armor{
public function __construct(int $meta = 0){
parent::__construct(self::GOLD_BOOTS, $meta, "Gold Boots");
}
public function getDefensePoints() : int{
return 1;
}
}

View File

@ -28,4 +28,8 @@ class GoldChestplate extends Armor{
public function __construct(int $meta = 0){
parent::__construct(self::GOLD_CHESTPLATE, $meta, "Gold Chestplate");
}
public function getDefensePoints() : int{
return 5;
}
}

View File

@ -28,4 +28,8 @@ class GoldHelmet extends Armor{
public function __construct(int $meta = 0){
parent::__construct(self::GOLD_HELMET, $meta, "Gold Helmet");
}
public function getDefensePoints() : int{
return 2;
}
}

View File

@ -28,4 +28,8 @@ class GoldLeggings extends Armor{
public function __construct(int $meta = 0){
parent::__construct(self::GOLD_LEGGINGS, $meta, "Gold Leggings");
}
public function getDefensePoints() : int{
return 3;
}
}

View File

@ -32,4 +32,8 @@ class GoldPickaxe extends Tool{
public function isPickaxe(){
return Tool::TIER_GOLD;
}
public function getAttackPoints() : int{
return 3;
}
}

View File

@ -32,4 +32,8 @@ class GoldShovel extends Tool{
public function isShovel(){
return Tool::TIER_GOLD;
}
public function getAttackPoints() : int{
return 2;
}
}

View File

@ -32,4 +32,8 @@ class GoldSword extends Tool{
public function isSword(){
return Tool::TIER_GOLD;
}
public function getAttackPoints() : int{
return 5;
}
}

View File

@ -32,4 +32,8 @@ class IronAxe extends Tool{
public function isAxe(){
return Tool::TIER_IRON;
}
public function getAttackPoints() : int{
return 6;
}
}

View File

@ -28,4 +28,8 @@ class IronBoots extends Armor{
public function __construct(int $meta = 0){
parent::__construct(self::IRON_BOOTS, $meta, "Iron Boots");
}
public function getDefensePoints() : int{
return 2;
}
}

View File

@ -28,4 +28,8 @@ class IronChestplate extends Armor{
public function __construct(int $meta = 0){
parent::__construct(self::IRON_CHESTPLATE, $meta, "Iron Chestplate");
}
public function getDefensePoints() : int{
return 6;
}
}

View File

@ -28,4 +28,8 @@ class IronHelmet extends Armor{
public function __construct(int $meta = 0){
parent::__construct(self::IRON_HELMET, $meta, "Iron Helmet");
}
public function getDefensePoints() : int{
return 2;
}
}

View File

@ -28,4 +28,8 @@ class IronLeggings extends Armor{
public function __construct(int $meta = 0){
parent::__construct(self::IRON_LEGGINGS, $meta, "Iron Leggings");
}
public function getDefensePoints() : int{
return 5;
}
}

View File

@ -32,4 +32,8 @@ class IronPickaxe extends Tool{
public function isPickaxe(){
return Tool::TIER_IRON;
}
public function getAttackPoints() : int{
return 5;
}
}

View File

@ -32,4 +32,8 @@ class IronShovel extends Tool{
public function isShovel(){
return Tool::TIER_IRON;
}
public function getAttackPoints() : int{
return 4;
}
}

View File

@ -32,4 +32,8 @@ class IronSword extends Tool{
public function isSword(){
return Tool::TIER_IRON;
}
public function getAttackPoints() : int{
return 7;
}
}

View File

@ -746,6 +746,22 @@ class Item implements ItemIds, \JsonSerializable{
return 0;
}
/**
* Returns how many points of damage this item will deal to an entity when used as a weapon.
* @return int
*/
public function getAttackPoints() : int{
return 1;
}
/**
* Returns how many armor points can be gained by wearing this item.
* @return int
*/
public function getDefensePoints() : int{
return 0;
}
/**
* @param Entity|Block $object
*

View File

@ -28,4 +28,8 @@ class LeatherBoots extends Armor{
public function __construct(int $meta = 0){
parent::__construct(self::LEATHER_BOOTS, $meta, "Leather Boots");
}
public function getDefensePoints() : int{
return 1;
}
}

View File

@ -28,4 +28,8 @@ class LeatherCap extends Armor{
public function __construct(int $meta = 0){
parent::__construct(self::LEATHER_CAP, $meta, "Leather Cap");
}
public function getDefensePoints() : int{
return 1;
}
}

View File

@ -28,4 +28,8 @@ class LeatherPants extends Armor{
public function __construct(int $meta = 0){
parent::__construct(self::LEATHER_PANTS, $meta, "Leather Pants");
}
public function getDefensePoints() : int{
return 2;
}
}

View File

@ -28,4 +28,8 @@ class LeatherTunic extends Armor{
public function __construct(int $meta = 0){
parent::__construct(self::LEATHER_TUNIC, $meta, "Leather Tunic");
}
public function getDefensePoints() : int{
return 3;
}
}

View File

@ -33,4 +33,8 @@ class StoneAxe extends Tool{
public function isAxe(){
return Tool::TIER_STONE;
}
public function getAttackPoints() : int{
return 5;
}
}

View File

@ -32,4 +32,8 @@ class StonePickaxe extends Tool{
public function isPickaxe(){
return Tool::TIER_STONE;
}
public function getAttackPoints() : int{
return 4;
}
}

View File

@ -32,4 +32,8 @@ class StoneShovel extends Tool{
public function isShovel(){
return Tool::TIER_STONE;
}
public function getAttackPoints() : int{
return 3;
}
}

View File

@ -32,4 +32,8 @@ class StoneSword extends Tool{
public function isSword(){
return Tool::TIER_STONE;
}
public function getAttackPoints() : int{
return 6;
}
}

View File

@ -36,4 +36,8 @@ class WoodenAxe extends Tool{
public function getFuelTime() : int{
return 200;
}
public function getAttackPoints() : int{
return 4;
}
}

View File

@ -36,4 +36,8 @@ class WoodenPickaxe extends Tool{
public function getFuelTime() : int{
return 200;
}
public function getAttackPoints() : int{
return 3;
}
}

View File

@ -36,4 +36,8 @@ class WoodenShovel extends Tool{
public function getFuelTime() : int{
return 200;
}
public function getAttackPoints() : int{
return 2;
}
}

View File

@ -36,4 +36,8 @@ class WoodenSword extends Tool{
public function getFuelTime() : int{
return 200;
}
public function getAttackPoints() : int{
return 5;
}
}