|
1
|
|
|
<?php namespace FreedomCore\TrinityCore\Support\Classes; |
|
2
|
|
|
|
|
3
|
|
|
use FreedomCore\TrinityCore\Character\Models\Character; |
|
4
|
|
|
use FreedomCore\TrinityCore\Support\Common\Helper; |
|
5
|
|
|
use FreedomCore\TrinityCore\Support\DB2Reader; |
|
6
|
|
|
use Illuminate\Support\Collection; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class Profession |
|
10
|
|
|
* @package FreedomCore\TrinityCore\Support\Classes |
|
11
|
|
|
*/ |
|
12
|
|
|
class Profession |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* ID of the profession |
|
17
|
|
|
* @var int |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $professionID = 0; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Skill level of the profession |
|
23
|
|
|
* @var int |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $professionLevel = 0; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Min ID for the SkillLine DB2 file to extract professions |
|
29
|
|
|
* @var int |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $minID = 129; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Max ID for the SkillLine DB2 file to extract professions |
|
35
|
|
|
* @var int |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $maxID = 773; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Array of available professions |
|
41
|
|
|
* @var array |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $professions = []; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Character professions collection |
|
47
|
|
|
* @var \Illuminate\Support\Collection |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $characterProfessions = []; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Profession constructor. |
|
53
|
|
|
* @param int $profession |
|
54
|
|
|
* @param int $level |
|
55
|
|
|
*/ |
|
56
|
|
|
public function __construct(int $profession = 0, int $level = 0) |
|
57
|
|
|
{ |
|
58
|
|
|
$this->professionID = $profession; |
|
59
|
|
|
$this->professionLevel = $level; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Set profession id |
|
64
|
|
|
* @param int $profession |
|
65
|
|
|
* @return Profession |
|
66
|
|
|
*/ |
|
67
|
|
|
public function setProfessionID(int $profession) : Profession |
|
68
|
|
|
{ |
|
69
|
|
|
$this->professionID = $profession; |
|
70
|
|
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Set profession level |
|
75
|
|
|
* @param int $level |
|
76
|
|
|
* @return Profession |
|
77
|
|
|
*/ |
|
78
|
|
|
public function setProfessionLevel(int $level) : Profession |
|
79
|
|
|
{ |
|
80
|
|
|
$this->professionLevel = $level; |
|
81
|
|
|
return $this; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Get profession id |
|
86
|
|
|
* @return int |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getProfessionID() : int |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->professionID; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Get profession level |
|
95
|
|
|
* @return int |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getProfessionLevel() : int |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->professionLevel; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Load professions from SkillLine |
|
104
|
|
|
* @param DB2Reader $reader |
|
105
|
|
|
* @return Profession |
|
106
|
|
|
* @throws \Exception |
|
107
|
|
|
*/ |
|
108
|
|
|
public function loadProfessions(DB2Reader $reader) : Profession |
|
109
|
|
|
{ |
|
110
|
|
|
$reader->openFile('SkillLine'); |
|
111
|
|
|
$professions = []; |
|
112
|
|
|
foreach ($reader->generateRecords() as $index => $record) { |
|
113
|
|
|
if ($record['can_link'] && $index >= $this->minID && $index <= $this->maxID) { |
|
114
|
|
|
$record = array_merge(['id' => $index], $record); |
|
115
|
|
|
$professions[] = $record; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
$this->professions = $professions; |
|
119
|
|
|
return $this; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Load character professions |
|
124
|
|
|
* @param Character $character |
|
125
|
|
|
*/ |
|
126
|
|
|
public function loadCharacterProfessions(Character $character) |
|
127
|
|
|
{ |
|
128
|
|
|
if (empty($this->professions)) { |
|
129
|
|
|
throw new \RuntimeException('You have to call the loadProfessions() method before loading the professions for the character!'); |
|
130
|
|
|
} |
|
131
|
|
|
$skills = $character->skills; |
|
132
|
|
|
$professions = []; |
|
133
|
|
|
foreach ($skills as $skill) { |
|
134
|
|
|
$searchResults = Helper::arrayMultiSearch($this->professions, 'id', $skill->skill); |
|
135
|
|
|
if (!empty($searchResults)) { |
|
136
|
|
|
$professions[] = $skill; |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
$this->characterProfessions = collect($professions); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Get list of available professions |
|
144
|
|
|
* @return array |
|
145
|
|
|
*/ |
|
146
|
|
|
public function getAvailableProfessions() : array |
|
147
|
|
|
{ |
|
148
|
|
|
return $this->professions; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Get character professions |
|
153
|
|
|
* @return \Illuminate\Support\Collection |
|
154
|
|
|
*/ |
|
155
|
|
|
public function getCharacterProfessions() : Collection |
|
156
|
|
|
{ |
|
157
|
|
|
return $this->characterProfessions; |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|