Passed
Push — master ( df16e4...50087e )
by Nico
27:13 queued 16:48
created

User::setFaction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Orm\Entity;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\ORM\Mapping\Column;
10
use Doctrine\ORM\Mapping\Entity;
11
use Doctrine\ORM\Mapping\GeneratedValue;
12
use Doctrine\ORM\Mapping\Id;
13
use Doctrine\ORM\Mapping\Index;
14
use Doctrine\ORM\Mapping\JoinColumn;
15
use Doctrine\ORM\Mapping\ManyToOne;
16
use Doctrine\ORM\Mapping\OneToMany;
17
use Doctrine\ORM\Mapping\OneToOne;
18
use Doctrine\ORM\Mapping\OrderBy;
19
use Doctrine\ORM\Mapping\Table;
20
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use Stu\Component\Game\GameEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Game\GameEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
use Stu\Component\Game\ModuleViewEnum;
23
use Stu\Component\Map\MapEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Map\MapEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
use Stu\Component\Player\UserAwardEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Player\UserAwardEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use Stu\Component\Player\UserCssClassEnum;
26
use Stu\Component\Player\UserRpgBehaviorEnum;
27
use Stu\Module\PlayerSetting\Lib\UserEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Module\PlayerSetting\Lib\UserEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
use Stu\Module\PlayerSetting\Lib\UserSettingEnum;
29
use Stu\Orm\Repository\UserRepository;
30
31
#[Table(name: 'stu_user')]
32
#[Index(name: 'user_alliance_idx', columns: ['allys_id'])]
33
#[Entity(repositoryClass: UserRepository::class)]
34
class User implements UserInterface
35
{
36
    #[Id]
37
    #[Column(type: 'integer')]
38
    #[GeneratedValue(strategy: 'IDENTITY')]
39
    private int $id;
40
41
    #[Column(type: 'string')]
42
    private string $username = '';
43
44
    #[Column(type: 'string', length: 20)]
45
    private string $login = '';
46
47
    #[Column(type: 'string', length: 255)]
48
    private string $pass = '';
49
50
    #[Column(type: 'string', length: 6, nullable: true)]
51
    private ?string $sms_code = null;
52
53
    #[Column(type: 'string', length: 200)]
54
    private string $email = '';
55
56
    #[Column(type: 'string', length: 255, nullable: true)]
57
    private ?string $mobile = null;
58
59
    #[Column(type: 'integer', nullable: true)]
60
    private ?int $allys_id = null;
61
62
    #[Column(type: 'integer')]
63
    private int $race = 9;
64
65
    #[Column(type: 'smallint')]
66
    private int $state = UserEnum::USER_STATE_NEW;
67
68
    #[Column(type: 'integer')]
69
    private int $lastaction = 0;
70
71
    #[Column(type: 'integer')]
72
    private int $creation = 0;
73
74
    #[Column(type: 'integer')]
75
    private int $kn_lez = 0;
76
77
    #[Column(type: 'smallint')]
78
    private int $delmark = 0;
79
80
    #[Column(type: 'boolean')]
81
    private bool $vac_active = false;
82
83
    #[Column(type: 'integer')]
84
    private int $vac_request_date = 0;
85
86
    #[Column(type: 'text')]
87
    private string $description = '';
88
89
    #[Column(type: 'smallint')]
90
    private int $tick = 1;
91
92
    #[Column(type: 'smallint', nullable: true)]
93
    private ?int $maptype = MapEnum::MAPTYPE_INSERT;
0 ignored issues
show
introduced by
The private property $maptype is not used, and could be removed.
Loading history...
94
95
    #[Column(type: 'text')]
96
    private string $sessiondata = '';
97
98
    #[Column(type: 'string', length: 255)]
99
    private string $password_token = '';
100
101
    #[Column(type: 'integer')]
102
    private int $prestige = 0;
103
104
    #[Column(type: 'boolean', options: ['default' => false])]
105
    private bool $deals = false;
106
107
    #[Column(type: 'integer', nullable: true)]
108
    private ?int $last_boarding = null;
109
110
    #[ManyToOne(targetEntity: 'Alliance', inversedBy: 'members')]
111
    #[JoinColumn(name: 'allys_id', referencedColumnName: 'id')]
112
    private ?AllianceInterface $alliance = null;
113
114
    #[ManyToOne(targetEntity: 'Faction')]
115
    #[JoinColumn(name: 'race', referencedColumnName: 'id')]
116
    private FactionInterface $faction;
117
118
    /**
119
     * @var ArrayCollection<int, BuoyInterface>
120
     */
121
    #[OneToMany(targetEntity: 'Buoy', mappedBy: 'user')]
122
    private Collection $buoys;
123
124
    /**
125
     * @var ArrayCollection<int, UserAwardInterface>
126
     */
127
    #[OneToMany(targetEntity: 'UserAward', mappedBy: 'user', indexBy: 'award_id')]
128
    #[OrderBy(['award_id' => 'ASC'])]
129
    private Collection $awards;
130
131
    /**
132
     * @var ArrayCollection<int, ColonyInterface>
133
     */
134
    #[OneToMany(targetEntity: 'Colony', mappedBy: 'user', indexBy: 'id')]
135
    #[OrderBy(['colonies_classes_id' => 'ASC', 'id' => 'ASC'])]
136
    private Collection $colonies;
137
138
    /**
139
     * @var ArrayCollection<int, UserLayerInterface>
140
     */
141
    #[OneToMany(targetEntity: 'UserLayer', mappedBy: 'user', indexBy: 'layer_id')]
142
    private Collection $userLayers;
143
144
    #[OneToOne(targetEntity: 'UserLock', mappedBy: 'user')]
145
    private ?UserLockInterface $userLock = null;
146
147
    /**
148
     * @var ArrayCollection<string, UserSettingInterface>
149
     */
150
    #[OneToMany(targetEntity: 'UserSetting', mappedBy: 'user', indexBy: 'setting')]
151
    private Collection $settings;
152
153
    /**
154
     * @var ArrayCollection<int, UserCharacterInterface>
155
     */
156
    #[OneToMany(targetEntity: 'UserCharacter', mappedBy: 'user')]
157
    private Collection $characters;
158
159
    /**
160
     * @var ArrayCollection<int, ColonyScanInterface>
161
     */
162
    #[OneToMany(targetEntity: 'ColonyScan', mappedBy: 'user', indexBy: 'id', fetch: 'EXTRA_LAZY')]
163
    #[OrderBy(['colony_id' => 'ASC', 'date' => 'ASC'])]
164
    private Collection $colonyScans;
165
166
    #[OneToOne(targetEntity: 'PirateWrath', mappedBy: 'user')]
167
    private ?PirateWrathInterface $pirateWrath = null;
168
169
    /**
170
     * @var ArrayCollection<int, UserTutorialInterface>
171
     */
172
    #[OneToMany(targetEntity: 'UserTutorial', mappedBy: 'user', indexBy: 'tutorial_step_id', fetch: 'EXTRA_LAZY')]
173
    private Collection $tutorials;
174
175
    /** @var null|array<mixed> */
176
    private $sessiondataUnserialized;
177
178
    /**
179
     * @var Collection<int, WormholeRestriction>
180
     */
181
    #[OneToMany(targetEntity: 'WormholeRestriction', mappedBy: 'user')]
182
    private Collection $wormholeRestrictions;
183
184
185
    public function __construct()
186
    {
187
        $this->awards = new ArrayCollection();
188
        $this->colonies = new ArrayCollection();
189
        $this->userLayers = new ArrayCollection();
190
        $this->settings = new ArrayCollection();
191
        $this->characters = new ArrayCollection();
192
        $this->buoys = new ArrayCollection();
193
        $this->colonyScans = new ArrayCollection();
194
        $this->tutorials = new ArrayCollection();
195
        $this->wormholeRestrictions = new ArrayCollection();
196
    }
197
198 131
    #[Override]
199
    public function getId(): int
200
    {
201 131
        return $this->id;
202
    }
203
204 131
    #[Override]
205
    public function getName(): string
206
    {
207
        //if UMODE active, add info to user name
208 131
        if ($this->isVacationRequestOldEnough()) {
209
            return $this->username . '[b][color=red] (UMODE)[/color][/b]';
210
        }
211 131
        return $this->username;
212
    }
213
214
    #[Override]
215
    public function setUsername(string $username): UserInterface
216
    {
217
        $this->username = $username;
218
        return $this;
219
    }
220
221
    #[Override]
222
    public function getLogin(): string
223
    {
224
        return $this->login;
225
    }
226
227
    #[Override]
228
    public function setLogin(string $login): UserInterface
229
    {
230
        $this->login = $login;
231
        return $this;
232
    }
233
234
    #[Override]
235
    public function getPassword(): string
236
    {
237
        return $this->pass;
238
    }
239
240
    #[Override]
241
    public function setPassword(string $password): UserInterface
242
    {
243
        $this->pass = $password;
244
        return $this;
245
    }
246
247
    #[Override]
248
    public function getSmsCode(): ?string
249
    {
250
        return $this->sms_code;
251
    }
252
253
    #[Override]
254
    public function setSmsCode(?string $code): UserInterface
255
    {
256
        $this->sms_code = $code;
257
        return $this;
258
    }
259
260
    #[Override]
261
    public function getEmail(): string
262
    {
263
        return $this->email;
264
    }
265
266
    #[Override]
267
    public function setEmail(string $email): UserInterface
268
    {
269
        $this->email = $email;
270
        return $this;
271
    }
272
273
    #[Override]
274
    public function getMobile(): ?string
275
    {
276
        return $this->mobile;
277
    }
278
279
    #[Override]
280
    public function setMobile(?string $mobile): UserInterface
281
    {
282
        $this->mobile = $mobile;
283
        return $this;
284
    }
285
286
    #[Override]
287
    public function getRgbCode(): string
288
    {
289
        $setting = $this->getSettings()->get(UserSettingEnum::RGB_CODE->value);
290
        if ($setting !== null) {
291
            return $setting->getValue();
292
        }
293
294
        return '';
295
    }
296
297 131
    #[Override]
298
    public function getCss(): string
299
    {
300 131
        $setting = $this->getSettings()->get(UserSettingEnum::CSS_COLOR_SHEET->value);
301 131
        if ($setting !== null) {
302
            return $setting->getValue();
303
        }
304
305 131
        return UserCssClassEnum::BLACK->value;
306
    }
307
308 131
    #[Override]
309
    public function getFactionId(): int
310
    {
311 131
        return $this->race;
312
    }
313
314
    #[Override]
315
    public function setFaction(FactionInterface $faction): UserInterface
316
    {
317
        $this->faction = $faction;
318
        return $this;
319
    }
320
321 7
    #[Override]
322
    public function getFaction(): FactionInterface
323
    {
324 7
        return $this->faction;
325
    }
326
327
    #[Override]
328
    public function getAwards(): Collection
329
    {
330
        return $this->awards;
331
    }
332
333 47
    #[Override]
334
    public function getColonies(): Collection
335
    {
336 47
        return $this->colonies;
337
    }
338
339 1
    #[Override]
340
    public function hasColony(): bool
341
    {
342
        if (
343 1
            $this->getState() === UserEnum::USER_STATE_COLONIZATION_SHIP
344 1
            || $this->getState() === UserEnum::USER_STATE_UNCOLONIZED
345
        ) {
346
            return false;
347
        }
348
349 1
        return !$this->getColonies()->isEmpty();
350
    }
351
352 2
    #[Override]
353
    public function getState(): int
354
    {
355 2
        return $this->state;
356
    }
357
358 1
    #[Override]
359
    public function isLocked(): bool
360
    {
361 1
        return $this->getUserLock() !== null && $this->getUserLock()->getRemainingTicks() > 0;
362
    }
363
364 1
    #[Override]
365
    public function getUserStateDescription(): string
366
    {
367 1
        if ($this->isLocked()) {
368
            return _('GESPERRT');
369
        }
370 1
        return UserEnum::getUserStateDescription($this->getState());
371
    }
372
373
    #[Override]
374
    public function setState(int $state): UserInterface
375
    {
376
        $this->state = $state;
377
        return $this;
378
    }
379
380 131
    #[Override]
381
    public function getAvatar(): string
382
    {
383 131
        $setting = $this->getSettings()->get(UserSettingEnum::AVATAR->value);
384 131
        if ($setting !== null) {
385
            return $setting->getValue();
386
        }
387
388 131
        return '';
389
    }
390
391
    #[Override]
392
    public function isEmailNotification(): bool
393
    {
394
        $setting = $this->getSettings()->get(UserSettingEnum::EMAIL_NOTIFICATION->value);
395
        if ($setting !== null) {
396
            return (bool)$setting->getValue();
397
        }
398
399
        return false;
400
    }
401
402 3
    #[Override]
403
    public function getLastaction(): int
404
    {
405 3
        return $this->lastaction;
406
    }
407
408
    #[Override]
409
    public function setLastaction(int $lastaction): UserInterface
410
    {
411
        $this->lastaction = $lastaction;
412
        return $this;
413
    }
414
415
    #[Override]
416
    public function getCreationDate(): int
417
    {
418
        return $this->creation;
419
    }
420
421
    #[Override]
422
    public function setCreationDate(int $creationDate): UserInterface
423
    {
424
        $this->creation = $creationDate;
425
        return $this;
426
    }
427
428 2
    #[Override]
429
    public function getKnMark(): int
430
    {
431 2
        return $this->kn_lez;
432
    }
433
434
    #[Override]
435
    public function setKnMark(int $knMark): UserInterface
436
    {
437
        $this->kn_lez = $knMark;
438
        return $this;
439
    }
440
441
    #[Override]
442
    public function getDeletionMark(): int
443
    {
444
        return $this->delmark;
445
    }
446
447
    #[Override]
448
    public function setDeletionMark(int $deletionMark): UserInterface
449
    {
450
        $this->delmark = $deletionMark;
451
        return $this;
452
    }
453
454 131
    #[Override]
455
    public function isVacationMode(): bool
456
    {
457 131
        return $this->vac_active;
458
    }
459
460
    #[Override]
461
    public function setVacationMode(bool $vacationMode): UserInterface
462
    {
463
        $this->vac_active = $vacationMode;
464
        return $this;
465
    }
466
467
    #[Override]
468
    public function getVacationRequestDate(): int
469
    {
470
        return $this->vac_request_date;
471
    }
472
473
    #[Override]
474
    public function setVacationRequestDate(int $date): UserInterface
475
    {
476
        $this->vac_request_date = $date;
477
478
        return $this;
479
    }
480
481 131
    #[Override]
482
    public function isVacationRequestOldEnough(): bool
483
    {
484 131
        return $this->isVacationMode() && (time() - $this->getVacationRequestDate() > UserEnum::VACATION_DELAY_IN_SECONDS);
485
    }
486
487
    #[Override]
488
    public function isStorageNotification(): bool
489
    {
490
        $setting = $this->getSettings()->get(UserSettingEnum::STORAGE_NOTIFICATION->value);
491
        if ($setting !== null) {
492
            return (bool)$setting->getValue();
493
        }
494
495
        return false;
496
    }
497
498
    #[Override]
499
    public function getDescription(): string
500
    {
501
        return $this->description;
502
    }
503
504
    #[Override]
505
    public function setDescription(string $description): UserInterface
506
    {
507
        $this->description = $description;
508
        return $this;
509
    }
510
511 2
    #[Override]
512
    public function isShowOnlineState(): bool
513
    {
514 2
        $setting = $this->getSettings()->get(UserSettingEnum::SHOW_ONLINE_STATUS->value);
515 2
        if ($setting !== null) {
516
            return (bool)$setting->getValue();
517
        }
518
519 2
        return false;
520
    }
521
522
    #[Override]
523
    public function isShowPmReadReceipt(): bool
524
    {
525
        $setting = $this->getSettings()->get(UserSettingEnum::SHOW_PM_READ_RECEIPT->value);
526
        if ($setting !== null) {
527
            return (bool)$setting->getValue();
528
        }
529
530
        return false;
531
    }
532
533
    #[Override]
534
    public function isSaveLogin(): bool
535
    {
536
        $setting = $this->getSettings()->get(UserSettingEnum::SAVE_LOGIN->value);
537
        if ($setting !== null) {
538
            return (bool)$setting->getValue();
539
        }
540
541
        return false;
542
    }
543
544
    #[Override]
545
    public function getFleetFixedDefault(): bool
546
    {
547
        $setting = $this->getSettings()->get(UserSettingEnum::FLEET_FIXED_DEFAULT->value);
548
        if ($setting !== null) {
549
            return (bool)$setting->getValue();
550
        }
551
552
        return false;
553
    }
554
555
    #[Override]
556
    public function getWarpsplitAutoCarryoverDefault(): bool
557
    {
558
        $setting = $this->getSettings()->get(UserSettingEnum::WARPSPLIT_AUTO_CARRYOVER_DEFAULT->value);
559
        if ($setting !== null) {
560
            return (bool)$setting->getValue();
561
        }
562
563
        return false;
564
    }
565
566
    #[Override]
567
    public function getTick(): int
568
    {
569
        return $this->tick;
570
    }
571
572
    #[Override]
573
    public function setTick(int $tick): UserInterface
574
    {
575
        $this->tick = $tick;
576
        return $this;
577
    }
578
579 4
    #[Override]
580
    public function getUserLayers(): Collection
581
    {
582 4
        return $this->userLayers;
583
    }
584
585 4
    #[Override]
586
    public function hasSeen(int $layerId): bool
587
    {
588 4
        return $this->getUserLayers()->containsKey($layerId);
589
    }
590
591 4
    #[Override]
592
    public function hasExplored(int $layerId): bool
593
    {
594 4
        return $this->hasSeen($layerId) && $this->getUserLayers()->get($layerId)->isExplored();
595
    }
596
597 131
    #[Override]
598
    public function getSettings(): Collection
599
    {
600 131
        return $this->settings;
601
    }
602
603
    #[Override]
604
    public function getSessiondata(): string
605
    {
606
        return $this->sessiondata;
607
    }
608
609
    #[Override]
610
    public function setSessiondata(string $sessiondata): UserInterface
611
    {
612
        $this->sessiondata = $sessiondata;
613
        $this->sessiondataUnserialized = null;
614
        return $this;
615
    }
616
617 1
    #[Override]
618
    public function getPasswordToken(): string
619
    {
620 1
        return $this->password_token;
621
    }
622
623
    #[Override]
624
    public function setPasswordToken(string $password_token): UserInterface
625
    {
626
        $this->password_token = $password_token;
627
        return $this;
628
    }
629
630 44
    #[Override]
631
    public function getPrestige(): int
632
    {
633 44
        return $this->prestige;
634
    }
635
636
    #[Override]
637
    public function setPrestige(int $prestige): UserInterface
638
    {
639
        $this->prestige = $prestige;
640
        return $this;
641
    }
642
643
    #[Override]
644
    public function getDefaultView(): ModuleViewEnum
645
    {
646
        $setting = $this->getSettings()->get(UserSettingEnum::DEFAULT_VIEW->value);
647
        if ($setting !== null) {
648
            return ModuleViewEnum::from($setting->getValue());
649
        }
650
651
        return ModuleViewEnum::MAINDESK;
652
    }
653
654 2
    #[Override]
655
    public function getRpgBehavior(): UserRpgBehaviorEnum
656
    {
657 2
        $setting = $this->getSettings()->get(UserSettingEnum::RPG_BEHAVIOR->value);
658 2
        if ($setting !== null) {
659
            return UserRpgBehaviorEnum::from((int)$setting->getValue());
660
        }
661
662 2
        return UserRpgBehaviorEnum::RPG_BEHAVIOR_NOT_SET;
663
    }
664
665 131
    #[Override]
666
    public function getDeals(): bool
667
    {
668 131
        return $this->deals;
669
    }
670
671
    #[Override]
672
    public function setDeals(bool $deals): UserInterface
673
    {
674
        $this->deals = $deals;
675
        return $this;
676
    }
677
678
    #[Override]
679
    public function getLastBoarding(): ?int
680
    {
681
        return $this->last_boarding;
682
    }
683
684
    #[Override]
685
    public function setLastBoarding(int $lastBoarding): UserInterface
686
    {
687
        $this->last_boarding = $lastBoarding;
688
        return $this;
689
    }
690
691 1
    #[Override]
692
    public function isOnline(): bool
693
    {
694 1
        return !($this->getLastAction() < time() - GameEnum::USER_ONLINE_PERIOD);
695
    }
696
697 14
    #[Override]
698
    public function getAlliance(): ?AllianceInterface
699
    {
700 14
        return $this->alliance;
701
    }
702
703
    #[Override]
704
    public function setAlliance(?AllianceInterface $alliance): UserInterface
705
    {
706
        $this->alliance = $alliance;
707
        return $this;
708
    }
709
710
    #[Override]
711
    public function setAllianceId(?int $allianceId): UserInterface
712
    {
713
        $this->allys_id = $allianceId;
714
        return $this;
715
    }
716
717
    #[Override]
718
    public function getSessionDataUnserialized(): array
719
    {
720
        if ($this->sessiondataUnserialized === null) {
721
            $this->sessiondataUnserialized = unserialize($this->getSessionData());
722
            if (!is_array($this->sessiondataUnserialized)) {
723
                $this->sessiondataUnserialized = [];
724
            }
725
        }
726
        return $this->sessiondataUnserialized;
727
    }
728
729
    #[Override]
730
    public function isContactable(): bool
731
    {
732
        return $this->getId() != UserEnum::USER_NOONE;
733
    }
734
735 131
    #[Override]
736
    public function hasAward(int $awardId): bool
737
    {
738 131
        return $this->awards->containsKey($awardId) === true;
739
    }
740
741 131
    #[Override]
742
    public function hasStationsNavigation(): bool
743
    {
744 131
        if ($this->isNpc()) {
745
            return true;
746
        }
747
748 131
        return $this->hasAward(UserAwardEnum::RESEARCHED_STATIONS);
749
    }
750
751 137
    public static function isUserNpc(int $userId): bool
752
    {
753 137
        return $userId < UserEnum::USER_FIRST_ID;
754
    }
755
756 131
    #[Override]
757
    public function isNpc(): bool
758
    {
759 131
        return self::isUserNpc($this->getId());
760
    }
761
762 1
    #[Override]
763
    public function getUserLock(): ?UserLockInterface
764
    {
765 1
        return $this->userLock;
766
    }
767
768
    #[Override]
769
    public function __toString(): string
770
    {
771
        return sprintf('userName: %s', $this->getName());
772
    }
773
774
    #[Override]
775
    public function hasTranslation(): bool
776
    {
777
        $text = $this->getDescription();
778
        return strpos($text, '[translate]') !== false && strpos($text, '[/translate]') !== false;
779
    }
780
781
    #[Override]
782
    public function isShowPirateHistoryEntrys(): bool
783
    {
784
        $setting = $this->getSettings()->get(UserSettingEnum::SHOW_PIRATE_HISTORY_ENTRYS->value);
785
        if ($setting !== null) {
786
            return (bool)$setting->getValue();
787
        }
788
789
        return false;
790
    }
791
792
    #[Override]
793
    public function getCharacters(): Collection
794
    {
795
        return $this->characters;
796
    }
797
798
    #[Override]
799
    public function getColonyScans(): Collection
800
    {
801
        return $this->colonyScans;
802
    }
803
804
    /**
805
     * @return Collection<int, BuoyInterface>
806
     */
807
    public function getBuoys(): Collection
808
    {
809
        return $this->buoys;
810
    }
811
812 1
    #[Override]
813
    public function getPirateWrath(): ?PirateWrathInterface
814
    {
815 1
        return $this->pirateWrath;
816
    }
817
818
    #[Override]
819
    public function setPirateWrath(?PirateWrathInterface $wrath): UserInterface
820
    {
821
        $this->pirateWrath = $wrath;
822
823
        return $this;
824
    }
825
826
    #[Override]
827
    public function isProtectedAgainstPirates(): bool
828
    {
829
        $pirateWrath = $this->pirateWrath;
830
        if ($pirateWrath === null) {
831
            return false;
832
        }
833
834
        $timeout = $pirateWrath->getProtectionTimeout();
835
        if ($timeout === null) {
836
            return false;
837
        }
838
839
        return $timeout > time();
840
    }
841
842
    /**
843
     * @return Collection<int, UserTutorialInterface>
844
     */
845
    #[Override]
846
    public function getTutorials(): Collection
847
    {
848
        return $this->tutorials;
849
    }
850
851
    #[Override]
852
    /**
853
     * @return Collection<int, WormholeRestriction>
854
     */
855
    public function getWormholeRestrictions(): iterable
856
    {
857
        return $this->wormholeRestrictions;
858
    }
859
}
860