1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Ship\Lib\Interaction; |
6
|
|
|
|
7
|
|
|
use Stu\Module\Control\GameControllerInterface; |
8
|
|
|
use Stu\Orm\Entity\ColonyInterface; |
9
|
|
|
use Stu\Orm\Entity\ShipInterface; |
10
|
|
|
|
11
|
|
|
final class InteractionChecker implements InteractionCheckerInterface |
12
|
|
|
{ |
13
|
|
|
public function checkPosition(ShipInterface $shipa, ShipInterface $shipb): bool |
14
|
|
|
{ |
15
|
|
|
return $shipa->getMap() === $shipb->getMap() && $shipa->getStarsystemMap() === $shipb->getStarsystemMap(); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function checkColonyPosition(ColonyInterface $col, ShipInterface $ship): bool |
19
|
|
|
{ |
20
|
|
|
return $col->getStarsystemMap() === $ship->getStarsystemMap(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
//TODO intercept script attacks, e.g. beam from cloaked or warped ship |
24
|
|
|
public static function canInteractWith( |
25
|
|
|
ShipInterface $ship, |
26
|
|
|
ShipInterface|ColonyInterface $target, |
27
|
|
|
GameControllerInterface $game, |
28
|
|
|
bool $doCloakCheck = false |
29
|
|
|
): bool { |
30
|
|
|
if ($target->getUser()->isVacationRequestOldEnough()) { |
31
|
|
|
$game->addInformation(_('Aktion nicht möglich, der Spieler befindet sich im Urlaubsmodus!')); |
32
|
|
|
|
33
|
|
|
return false; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
if ($ship->getCloakState()) { |
37
|
|
|
return false; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$interactionChecker = new InteractionChecker(); |
41
|
|
|
if ($target instanceof ColonyInterface) { |
42
|
|
|
return $interactionChecker->checkColonyPosition($target, $ship) && $target->getId() != $ship->getId(); |
43
|
|
|
} elseif (!$interactionChecker->checkPosition($ship, $target)) { |
44
|
|
|
return false; |
45
|
|
|
} |
46
|
|
|
if ($target->getShieldState() && $target->getUserId() != $ship->getUser()->getId()) { |
|
|
|
|
47
|
|
|
return false; |
48
|
|
|
} |
49
|
|
|
return !($doCloakCheck && $target->getCloakState()); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|