|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace cyberinferno\Cabal\Helpers; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class Item |
|
7
|
|
|
* |
|
8
|
|
|
* Contains methods helpful to generate item code as well as item option |
|
9
|
|
|
* |
|
10
|
|
|
* @package cyberinferno\Cabal\Helpers |
|
11
|
|
|
* @author Karthik P |
|
12
|
|
|
*/ |
|
13
|
|
|
class Item |
|
14
|
|
|
{ |
|
15
|
|
|
const ITEM_GRADE_CONSTANT = 8192; |
|
16
|
|
|
const ITEM_BIND_ACCOUNT_CONSTANT = 4096; |
|
17
|
|
|
const ITEM_BIND_CHARACTER_CONSTANT = 524288; |
|
18
|
|
|
const ITEM_BIND_CHARACTER_ON_USAGE_CONSTANT = 1572864; |
|
19
|
|
|
|
|
20
|
|
|
const MIN_GRADE = 0; |
|
21
|
|
|
const MAX_GRADE = 15; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var int |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $_itemCode; |
|
27
|
|
|
protected $_itemGrade = 0; |
|
28
|
|
|
protected $_itemBinding = 0; |
|
29
|
|
|
protected $_itemOption = 0; |
|
30
|
|
|
protected $_itemDuration = 0; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Item constructor. |
|
34
|
|
|
* |
|
35
|
|
|
* @param $itemCode |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct($itemCode) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->_itemCode = $itemCode; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Returns the item code |
|
44
|
|
|
* |
|
45
|
|
|
* @return int |
|
46
|
|
|
*/ |
|
47
|
|
|
public function getItemCode() |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->_itemCode; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Returns the current grade of the item |
|
54
|
|
|
* |
|
55
|
|
|
* @return int |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getGrade() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->_itemGrade; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Sets the grade of the item to generated |
|
64
|
|
|
* |
|
65
|
|
|
* @param int $value |
|
66
|
|
|
* @return Item $this |
|
67
|
|
|
*/ |
|
68
|
|
|
public function setGrade($value) |
|
69
|
|
|
{ |
|
70
|
|
|
$value = (int)$value; |
|
71
|
|
|
if ($value < self::MIN_GRADE) { |
|
72
|
|
|
$value = self::MIN_GRADE; |
|
73
|
|
|
} |
|
74
|
|
|
if ($value > self::MAX_GRADE) { |
|
75
|
|
|
$value = self::MAX_GRADE; |
|
76
|
|
|
} |
|
77
|
|
|
$this->_itemGrade = $value; |
|
78
|
|
|
return $this; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Returns current item binding |
|
83
|
|
|
* |
|
84
|
|
|
* @return int |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getBinding() |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->_itemBinding; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Sets the item binding to account |
|
93
|
|
|
* |
|
94
|
|
|
* @return Item $this |
|
95
|
|
|
*/ |
|
96
|
|
|
public function setAccountBinding() |
|
97
|
|
|
{ |
|
98
|
|
|
$this->_itemBinding = self::ITEM_BIND_ACCOUNT_CONSTANT; |
|
99
|
|
|
return $this; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Sets the item binding to character |
|
104
|
|
|
* |
|
105
|
|
|
* @return Item $this |
|
106
|
|
|
*/ |
|
107
|
|
|
public function setCharacterBinding() |
|
108
|
|
|
{ |
|
109
|
|
|
$this->_itemBinding = self::ITEM_BIND_CHARACTER_CONSTANT; |
|
110
|
|
|
return $this; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Sets the item binding to character binding on usage |
|
115
|
|
|
* |
|
116
|
|
|
* @return Item $this |
|
117
|
|
|
*/ |
|
118
|
|
|
public function setCharacterBindingOnUsage() |
|
119
|
|
|
{ |
|
120
|
|
|
$this->_itemBinding = self::ITEM_BIND_CHARACTER_ON_USAGE_CONSTANT; |
|
121
|
|
|
return $this; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Returns the generated item code based up on the criteria set |
|
126
|
|
|
* |
|
127
|
|
|
* @return int |
|
128
|
|
|
*/ |
|
129
|
|
|
public function generateItemCode() |
|
130
|
|
|
{ |
|
131
|
|
|
return $this->_itemCode + $this->_itemBinding + $this->_itemGrade * self::ITEM_GRADE_CONSTANT; |
|
132
|
|
|
} |
|
133
|
|
|
} |