Skip to content

Commit 85fec13

Browse files
committed
fix ticket-0679
1 parent b7c603f commit 85fec13

File tree

3 files changed

+132
-12
lines changed

3 files changed

+132
-12
lines changed

src/Lib/Pirate/PirateReaction.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Stu\Module\Logging\PirateLoggerInterface;
1212
use Stu\Module\PlayerSetting\Lib\UserEnum;
1313
use Stu\Module\Ship\Lib\FleetWrapperInterface;
14+
use Stu\Module\Ship\Lib\ShipWrapperInterface;
1415
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperFactoryInterface;
1516
use Stu\Orm\Entity\FleetInterface;
1617
use Stu\Orm\Entity\ShipInterface;
@@ -119,13 +120,7 @@ public function react(
119120

120121
private function canAnyoneFire(FleetWrapperInterface $fleetWrapper): bool
121122
{
122-
foreach ($fleetWrapper->getShipWrappers() as $wrapper) {
123-
if ($wrapper->canFire()) {
124-
return true;
125-
}
126-
}
127-
128-
return false;
123+
return $fleetWrapper->getShipWrappers()->exists(fn(int $key, ShipWrapperInterface $wrapper): bool => $wrapper->canFire());
129124
}
130125

131126
private function getRandomBehaviourType(PirateReactionTriggerEnum $reactionTrigger): PirateBehaviourEnum

src/Module/Spacecraft/Lib/Movement/ShipMover.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,13 @@ private function travelFlightRoute(
157157
$hasTravelled = true;
158158

159159
// alert reaction check
160-
$this->alertReactionCheck(
161-
$leadWrapper,
162-
$movedTractoredShipWrappers,
163-
$messages
164-
);
160+
if (!$this->areAllShipsDestroyed($activeWrappers)) {
161+
$this->alertReactionCheck(
162+
$leadWrapper,
163+
$movedTractoredShipWrappers,
164+
$messages
165+
);
166+
}
165167

166168
if ($this->areAllShipsDestroyed($activeWrappers)) {
167169
$flightRoute->abortFlight();

tests/unit/Module/Spacecraft/Lib/Movement/ShipMoverTest.php

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,127 @@ public function testCheckAndMoveExpectLossOfEmptyShipIfNotFixed(): void
304304

305305
$this->subject->checkAndMove($wrapper, $flightRoute);
306306
}
307+
308+
public function testCheckAndMoveExpectNoAlertCheckIfDestroyedOnEntrance(): void
309+
{
310+
$ship = $this->mock(ShipInterface::class);
311+
$wrapper = $this->mock(ShipWrapperInterface::class);
312+
$flightRoute = $this->mock(FlightRouteInterface::class);
313+
$map = $this->mock(MapInterface::class);
314+
$conditionCheckResult = $this->mock(ConditionCheckResult::class);
315+
$messageCollection = $this->mock(MessageCollectionInterface::class);
316+
$emptyMessage = $this->mock(MessageInterface::class);
317+
318+
$shipId = 12345;
319+
320+
$ship->shouldReceive('getId')
321+
->withNoArgs()
322+
->once()
323+
->andReturn($shipId);
324+
$ship->shouldReceive('getName')
325+
->withNoArgs()
326+
->once()
327+
->andReturn("SHIP");
328+
$ship->shouldReceive('isFleetLeader')
329+
->withNoArgs()
330+
->once()
331+
->andReturn(false);
332+
$ship->shouldReceive('getTractoredShip')
333+
->withNoArgs()
334+
->andReturn(null);
335+
$ship->shouldReceive('isDestroyed')
336+
->withNoArgs()
337+
->times(5)
338+
->andReturn(false, true, true, true, true);
339+
$ship->shouldReceive('getLocation')
340+
->withNoArgs()
341+
->once()
342+
->andReturn($map);
343+
344+
$map->shouldReceive('getAnomalies')
345+
->withNoArgs()
346+
->once()
347+
->andReturn(new ArrayCollection());
348+
$map->shouldReceive('getBuoys')
349+
->withNoArgs()
350+
->once()
351+
->andReturn(new ArrayCollection());
352+
353+
$wrapper->shouldReceive('get')
354+
->withNoArgs()
355+
->andReturn($ship);
356+
$wrapper->shouldReceive('getFleetWrapper')
357+
->withNoArgs()
358+
->andReturn(null);
359+
$wrapper->shouldReceive('getTractoredShipWrapper')
360+
->withNoArgs()
361+
->once()
362+
->andReturn(null);
363+
364+
$map->shouldReceive('getFieldType->getPassable')
365+
->withNoArgs()
366+
->once()
367+
->andReturn(true);
368+
369+
$flightRoute->shouldReceive('isDestinationArrived')
370+
->withNoArgs()
371+
->times(2)
372+
->andReturn(false, true);
373+
$flightRoute->shouldReceive('getNextWaypoint')
374+
->withNoArgs()
375+
->once()
376+
->andReturn($map);
377+
$flightRoute->shouldReceive('enterNextWaypoint')
378+
->with(
379+
Mockery::on(fn(ArrayCollection $coll) => $coll->toArray() === [$shipId => $wrapper]),
380+
$messageCollection
381+
)
382+
->once();
383+
$flightRoute->shouldReceive('getRouteMode')
384+
->withNoArgs()
385+
->once()
386+
->andReturn(RouteModeEnum::FLIGHT);
387+
$flightRoute->shouldReceive('abortFlight')
388+
->withNoArgs()
389+
->once();
390+
391+
$conditionCheckResult->shouldReceive('isFlightPossible')
392+
->withNoArgs()
393+
->once()
394+
->andReturn(true);
395+
$conditionCheckResult->shouldReceive('getBlockedIds')
396+
->withNoArgs()
397+
->once()
398+
->andReturn([]);
399+
$conditionCheckResult->shouldReceive('getInformations')
400+
->withNoArgs()
401+
->once()
402+
->andReturn([]);
403+
404+
$this->preFlightConditionsCheck->shouldReceive('checkPreconditions')
405+
->with($wrapper, [$shipId => $wrapper], $flightRoute, false)
406+
->once()
407+
->andReturn($conditionCheckResult);
408+
409+
$this->messageFactory->shouldReceive('createMessageCollection')
410+
->withNoArgs()
411+
->once()
412+
->andReturn($messageCollection);
413+
$messageCollection->shouldReceive('add')
414+
->with($emptyMessage)
415+
->once();
416+
$messageCollection->shouldReceive('addInformation')
417+
->with('Es wurden alle Schiffe zerstört')
418+
->once();
419+
$this->messageFactory->shouldReceive('createMessage')
420+
->with(UserEnum::USER_NOONE, null, [])
421+
->once()
422+
->andReturn($emptyMessage);
423+
424+
$this->shipMovementInformationAdder->shouldReceive('reachedDestinationDestroyed')
425+
->with($ship, 'SHIP', false, RouteModeEnum::FLIGHT, $messageCollection)
426+
->once();
427+
428+
$this->subject->checkAndMove($wrapper, $flightRoute);
429+
}
307430
}

0 commit comments

Comments
 (0)