|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Stu\Lib\Pirate\Component; |
|
4
|
|
|
|
|
5
|
|
|
use Stu\Lib\Information\InformationWrapper; |
|
6
|
|
|
use Stu\Module\Logging\LoggerUtilFactoryInterface; |
|
7
|
|
|
use Stu\Module\Logging\PirateLoggerInterface; |
|
8
|
|
|
use Stu\Module\Ship\Lib\Battle\ShipAttackCoreInterface; |
|
9
|
|
|
use Stu\Module\Ship\Lib\FleetWrapperInterface; |
|
10
|
|
|
use Stu\Module\Ship\Lib\Interaction\InterceptShipCoreInterface; |
|
11
|
|
|
use Stu\Module\Ship\Lib\ShipWrapperFactoryInterface; |
|
12
|
|
|
use Stu\Orm\Entity\ShipInterface; |
|
13
|
|
|
|
|
14
|
|
|
class PirateAttack implements PirateAttackInterface |
|
15
|
|
|
{ |
|
16
|
|
|
private PirateLoggerInterface $logger; |
|
17
|
|
|
|
|
18
|
|
|
public function __construct( |
|
19
|
|
|
private InterceptShipCoreInterface $interceptShipCore, |
|
20
|
|
|
private ShipAttackCoreInterface $shipAttackCore, |
|
21
|
|
|
private ShipWrapperFactoryInterface $shipWrapperFactory, |
|
22
|
|
|
LoggerUtilFactoryInterface $loggerUtilFactory |
|
23
|
|
|
) { |
|
24
|
|
|
$this->logger = $loggerUtilFactory->getPirateLogger(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function attackShip(FleetWrapperInterface $fleetWrapper, ShipInterface $target): void |
|
28
|
|
|
{ |
|
29
|
|
|
$leadWrapper = $fleetWrapper->getLeadWrapper(); |
|
30
|
|
|
|
|
31
|
|
|
$this->interceptIfNeccessary($leadWrapper->get(), $target); |
|
32
|
|
|
|
|
33
|
|
|
if ($fleetWrapper->get()->getShips()->isEmpty()) { |
|
34
|
|
|
$this->logger->log(' cancel attack, no ships left'); |
|
35
|
|
|
return; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$isFleetFight = false; |
|
39
|
|
|
$informations = new InformationWrapper(); |
|
40
|
|
|
|
|
41
|
|
|
$this->logger->logf(' attacking target with shipId: %d', $target->getId()); |
|
42
|
|
|
|
|
43
|
|
|
$this->shipAttackCore->attack( |
|
44
|
|
|
$leadWrapper, |
|
45
|
|
|
$this->shipWrapperFactory->wrapShip($target), |
|
46
|
|
|
$isFleetFight, |
|
47
|
|
|
$informations |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
private function interceptIfNeccessary(ShipInterface $ship, ShipInterface $target): void |
|
53
|
|
|
{ |
|
54
|
|
|
if (!$target->getWarpState()) { |
|
55
|
|
|
return; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$this->logger->logf(' intercepting target with shipId: %d', $target->getId()); |
|
59
|
|
|
$this->interceptShipCore->intercept($ship, $target, new InformationWrapper()); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|