Skip to content

Commit a7ec8b5

Browse files
committed
introduce ion storm intensity
1 parent 2b6bbf0 commit a7ec8b5

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

src/Component/Anomaly/Type/IonStorm/IonStormData.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class IonStormData
1111
public function __construct(
1212
public int $directionInDegrees = 0,
1313
public int $velocity = 0,
14-
public IonStormMovementType $movementType = IonStormMovementType::STATIC
14+
public IonStormMovementType $movementType = IonStormMovementType::STATIC,
15+
public bool $isPositivePolarity = true,
16+
public int $intensity = 100
1517
) {}
1618

1719
public function getHorizontalMovement(): int
@@ -24,6 +26,11 @@ public function getVerticalMovement(): int
2426
return (int)round(cos(deg2rad($this->directionInDegrees)) * $this->velocity);
2527
}
2628

29+
public function getIntensity(): int
30+
{
31+
return $this->intensity;
32+
}
33+
2734
public function changeMovement(StuRandom $stuRandom): IonStormData
2835
{
2936
$this->directionInDegrees = $stuRandom->rand(1, 360);
@@ -36,6 +43,8 @@ public static function createRandomInstance(StuRandom $stuRandom): IonStormData
3643
{
3744
$instance = new IonStormData();
3845
$instance->movementType = $stuRandom->rand(1, 10) === 10 ? IonStormMovementType::VARIABLE : IonStormMovementType::STATIC;
46+
$instance->isPositivePolarity = $stuRandom->rand(0, 1) === 1;
47+
$instance->intensity = $stuRandom->rand(50, 200);
3948

4049
return $instance->changeMovement($stuRandom);
4150
}

src/Component/Anomaly/Type/IonStorm/IonStormHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,10 @@ private function deactivateDrive(SpacecraftWrapperInterface $wrapper, Informatio
222222
private function damageSpacecraft(SpacecraftWrapperInterface $wrapper, Anomaly $anomaly, InformationInterface $informations, int $damagePercentage): void
223223
{
224224
$spacecraft = $wrapper->get();
225+
$ionStormData = $this->getIonStormData($anomaly->getRoot());
225226

226227
$damageWrapper = new DamageWrapper(
227-
(int)ceil($this->stuRandom->rand(1, $damagePercentage, true) * $wrapper->get()->getMaxHull() / 100)
228+
(int)ceil($this->stuRandom->rand(1, $damagePercentage, true) * $wrapper->get()->getMaxHull() * $ionStormData->getIntensity() / 10000)
228229
);
229230

230231
$shield = $spacecraft->getSystems()[SpacecraftSystemTypeEnum::SHIELDS->value] ?? null;

tests/unit/Component/Anomaly/AnomalyCreationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function testCreateExpectNewEntityWithMapLocationAndDataObject(): void
8282
->once()
8383
->andReturnSelf();
8484
$anomaly->shouldReceive('setData')
85-
->with('{"directionInDegrees":42,"velocity":17,"movementType":1}')
85+
->with('{"directionInDegrees":42,"velocity":17,"movementType":1,"isPositivePolarity":true,"intensity":100}')
8686
->once();
8787

8888
$this->anomalyTypeRepository->shouldReceive('find')

tests/unit/Component/Anomaly/Type/IonStorm/IonStormMovementTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function testMoveStormExpectMovementChangeWhenTypeVariable(): void
5252
->once()
5353
->andReturn(new ArrayCollection());
5454
$root->shouldReceive('setData')
55-
->with('{"directionInDegrees":180,"velocity":3,"movementType":2}')
55+
->with('{"directionInDegrees":180,"velocity":3,"movementType":2,"isPositivePolarity":true,"intensity":100}')
5656
->once();
5757

5858
$this->stuRandom->shouldReceive('rand')

0 commit comments

Comments
 (0)