Durability::getItemDurability()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 0
cts 17
cp 0
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 12
nc 5
nop 0
crap 30
1
<?php namespace FreedomCore\TrinityCore\Support\Classes;
2
3
/**
4
 * Class Durability
5
 * @package FreedomCore\TrinityCore\Support\Classes
6
 * @see http://wowwiki.wikia.com/wiki/Durability
7
 */
8
class Durability
9
{
10
11
    protected $item = null;
12
13
    /**
14
     * Quality Multipliers Variables
15
     * @var array
16
     */
17
    protected $qualityMultipliers = [
18
        0.92,
19
        0.92,
20
        0.92,
21
        1.11,
22
        1.32,
23
        1.61,
24
        0.0,
25
        0.0
26
    ];
27
28
    /**
29
     * Armor Multipliers Variables
30
     * @var array
31
     */
32
    protected $armorMultipliers = [
33
        0.00, // Inventory Type: Non Equip
34
        0.60, // Inventory Type: Head
35
        0.00, // Inventory Type: Neck
36
        0.60, // Inventory Type: Shoulders
37
        0.00, // Inventory Type: Body
38
        1.00, // Inventory Type: Chest
39
        0.33, // Inventory Type: Waist
40
        0.72, // Inventory Type: Legs
41
        0.48, // Inventory Type: Feet
42
        0.33, // Inventory Type: Wrists
43
        0.33, // Inventory Type: Hands
44
        0.00, // Inventory Type: Finger
45
        0.00, // Inventory Type: Trinket
46
        0.00, // Inventory Type: Weapon
47
        0.72, // Inventory Type: Shield
48
        0.00, // Inventory Type: Ranged
49
        0.00, // Inventory Type: Cloack
50
        0.00, // Inventory Type: 2 Handed Weapon
51
        0.00, // Inventory Type: Bag
52
        0.00, // Inventory Type: Tabard
53
        1.00, // Inventory Type: Robe
54
        0.00, // Inventory Type: Weapon Main-hand
55
        0.00, // Inventory Type: Weapon Off-hand
56
        0.00, // Inventory Type: Holdable
57
        0.00, // Inventory Type: Ammo
58
        0.00, // Inventory Type: Thrown
59
        0.00, // Inventory Type: Ranged Right Hand
60
        0.00, // Inventory Type: Quiver
61
        0.00, // Inventory Type: Relic
62
    ];
63
64
    protected $weaponMultipliers = [
65
        0.91, // Weapon Subclass: Axe
66
        1.00, // Weapon Subclass: Axe 2
67
        1.00, // Weapon Subclass: BOW
68
        1.00, // Weapon Subclass: GUN
69
        0.91, // Weapon Subclass: MACE
70
        1.00, // Weapon Subclass: MACE2
71
        1.00, // Weapon Subclass: POLEARM
72
        0.91, // Weapon Subclass: SWORD
73
        1.00, // Weapon Subclass: SWORD2
74
        1.00, // Weapon Subclass: WARGLAIVES
75
        1.00, // Weapon Subclass: STAFF
76
        0.00, // Weapon Subclass: EXOTIC
77
        0.00, // Weapon Subclass: EXOTIC2
78
        0.66, // Weapon Subclass: FIST_WEAPON
79
        0.00, // Weapon Subclass: MISCELLANEOUS
80
        0.66, // Weapon Subclass: DAGGER
81
        0.00, // Weapon Subclass: THROWN
82
        0.00, // Weapon Subclass: SPEAR
83
        1.00, // Weapon Subclass: CROSSBOW
84
        0.66, // Weapon Subclass: WAND
85
        0.66, // Weapon Subclass: FISHING_POLE
86
    ];
87
88
    /**
89
     * Durability constructor.
90
     * @param Item $item
91
     */
92
    public function __construct(Item $item)
93
    {
94
        $this->item = $item;
95
    }
96
97
    /**
98
     * Get item durability
99
     * @return int
100
     */
101
    public function getItemDurability() : int
102
    {
103
        $item = $this->item;
104
        if (!$item->isArmor() && !$item->isWeapon()) {
105
            return 0;
106
        }
107
        $levelPenalty = 1.0;
108
        if ($item->getItemLevel() <= 28) {
109
            $levelPenalty = 0.966 - floatval(28 - $item->getitemLevel()) / 54.0;
110
        }
111
        if ($item->isArmor()) {
112
            $result = 5 * round(25.0 * $this->qualityMultipliers[$item->getQuality()] * $this->armorMultipliers[$item->getInventoryType()] * $levelPenalty);
113
        } else {
114
            $result = 5 * round(18.0 * $this->qualityMultipliers[$item->getQuality()] * $this->weaponMultipliers[$item->getSubClass()] * $levelPenalty);
115
        }
116
        return intval($result);
117
    }
118
}
119