|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Orm\Entity; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\Mapping\Column; |
|
8
|
|
|
use Doctrine\ORM\Mapping\Entity; |
|
9
|
|
|
use Doctrine\ORM\Mapping\GeneratedValue; |
|
10
|
|
|
use Doctrine\ORM\Mapping\Id; |
|
11
|
|
|
use Doctrine\ORM\Mapping\Table; |
|
12
|
|
|
use Stu\Module\Commodity\CommodityTypeEnum; |
|
13
|
|
|
|
|
14
|
|
|
#[Table(name: 'stu_commodity')] |
|
15
|
|
|
#[Entity(repositoryClass: 'Stu\Orm\Repository\CommodityRepository')] |
|
16
|
|
|
class Commodity implements CommodityInterface |
|
17
|
|
|
{ |
|
18
|
|
|
#[Id] |
|
19
|
|
|
#[Column(type: 'integer')] |
|
20
|
|
|
#[GeneratedValue(strategy: 'IDENTITY')] |
|
21
|
|
|
private int $id; |
|
22
|
|
|
|
|
23
|
|
|
#[Column(type: 'string')] |
|
24
|
|
|
private string $name = ''; |
|
25
|
|
|
|
|
26
|
|
|
#[Column(type: 'smallint')] |
|
27
|
|
|
private int $sort = 0; |
|
28
|
|
|
|
|
29
|
|
|
#[Column(type: 'boolean')] |
|
30
|
|
|
private bool $view = true; |
|
31
|
|
|
|
|
32
|
|
|
#[Column(type: 'smallint')] |
|
33
|
|
|
private int $type = CommodityTypeEnum::COMMODITY_TYPE_STANDARD; |
|
34
|
|
|
|
|
35
|
|
|
#[Column(type: 'boolean')] |
|
36
|
|
|
private bool $npc_commodity = false; |
|
37
|
|
|
|
|
38
|
|
|
#[Column(type: 'boolean')] |
|
39
|
|
|
private bool $bound = false; |
|
40
|
|
|
|
|
41
|
|
|
public function getId(): int |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->id; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function getName(): string |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->name; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function setName(string $name): CommodityInterface |
|
52
|
|
|
{ |
|
53
|
|
|
$this->name = $name; |
|
54
|
|
|
|
|
55
|
|
|
return $this; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function getSort(): int |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->sort; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function setSort(int $sort): CommodityInterface |
|
64
|
|
|
{ |
|
65
|
|
|
$this->sort = $sort; |
|
66
|
|
|
|
|
67
|
|
|
return $this; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getView(): bool |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->view; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function setView(bool $view): CommodityInterface |
|
76
|
|
|
{ |
|
77
|
|
|
$this->view = $view; |
|
78
|
|
|
|
|
79
|
|
|
return $this; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function getType(): int |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->type; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function setType(int $typeId): CommodityInterface |
|
88
|
|
|
{ |
|
89
|
|
|
$this->type = $typeId; |
|
90
|
|
|
|
|
91
|
|
|
return $this; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function isTradeable(): bool |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->isBeamable() && $this->npc_commodity === false; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function isBeamable(UserInterface $user = null, UserInterface $targetUser = null): bool |
|
100
|
|
|
{ |
|
101
|
|
|
$isBound = $user !== null && $targetUser !== null && $this->isBoundToAccount() && $user !== $targetUser; |
|
102
|
|
|
|
|
103
|
|
|
return $this->getType() === CommodityTypeEnum::COMMODITY_TYPE_STANDARD && $this->getView() === true && !$isBound; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function isSaveable(): bool |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->getType() === CommodityTypeEnum::COMMODITY_TYPE_STANDARD; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function isBoundToAccount(): bool |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->bound; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function isShuttle(): bool |
|
117
|
|
|
{ |
|
118
|
|
|
return in_array(intdiv($this->getId(), 10) * 10, CommodityTypeEnum::BASE_IDS_SHUTTLE); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function isWorkbee(): bool |
|
122
|
|
|
{ |
|
123
|
|
|
return intdiv($this->getId(), 10) * 10 === CommodityTypeEnum::BASE_ID_WORKBEE; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
public function isBouy(): bool |
|
127
|
|
|
{ |
|
128
|
|
|
return $this->getId() === CommodityTypeEnum::BASE_ID_BUOY; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @deprecated |
|
133
|
|
|
*/ |
|
134
|
|
|
public function isIllegal(int $network): bool |
|
135
|
|
|
{ |
|
136
|
|
|
// @todo remove |
|
137
|
|
|
return false; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function getTransferCount(): int |
|
141
|
|
|
{ |
|
142
|
|
|
// @todo Anzahl Waren pro Energieeinheit |
|
143
|
|
|
// Möglicherweise einstellbar nach Warentyp |
|
144
|
|
|
return 1; |
|
145
|
|
|
} |
|
146
|
|
|
} |