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);
}
}