From d6738dd205207bf66ea1c388827bebeee2961380 Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 24 Oct 2024 00:43:37 +0100 Subject: [PATCH 1/5] terraformer planet field bonus logic Handles #392 --- app/Services/PlanetService.php | 15 +++++++++++- tests/Unit/PlanetServiceTest.php | 42 ++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/app/Services/PlanetService.php b/app/Services/PlanetService.php index be6f38c..d0edc46 100644 --- a/app/Services/PlanetService.php +++ b/app/Services/PlanetService.php @@ -353,7 +353,20 @@ public function getPlanetImageType(): string */ public function getPlanetFieldMax(): int { - return $this->planet->field_max; + $extra_fields = 0; + if ($this->planet->terraformer != 0) { + // For every level, it increases by 5 + $extra_fields += $this->planet->terraformer * 5; + + // For every 2 levels, it adds another bonus field + $two_level_bonus_count = (int)(floor($this->planet->terraformer / 2)); + if ($two_level_bonus_count != 0) { + $extra_fields += $two_level_bonus_count; + + } + + } + return $extra_fields + $this->planet->field_max; } /** diff --git a/tests/Unit/PlanetServiceTest.php b/tests/Unit/PlanetServiceTest.php index c8a1210..f9f3a6c 100644 --- a/tests/Unit/PlanetServiceTest.php +++ b/tests/Unit/PlanetServiceTest.php @@ -121,7 +121,49 @@ public function testGetPlanetFieldMax(): void ]); $this->assertEquals(14, $this->planetService->getPlanetFieldMax()); } + /** + * Test that the field max function with terraformer returns expected values + */ + public function testGetPlanetFieldMaxWithTerraformer(): void + { + + // Test none divisible by 2-- should only add 5. + $this->createAndSetPlanetModel([ + 'field_max' => 90, + 'terraformer' => 1, + ]); + + $this->assertEquals(95, $this->planetService->getPlanetFieldMax()); + + + // Test a divisible of 2, should add 5, and +1 bonus. + $this->createAndSetPlanetModel([ + 'field_max' => 150, + 'terraformer' => 2, + ]); + + $this->assertEquals(161, $this->planetService->getPlanetFieldMax()); + + // Larger divisible + $this->createAndSetPlanetModel([ + 'field_max' => 100, + 'terraformer' => 20, + ]); + + // 100 base, plus 20*5 = 200 + // - each level + 5 max fields, + // - every 2 levels + 1 max field- 20/2 = 210 + $this->assertEquals(210, $this->planetService->getPlanetFieldMax()); + + // Ensure if it's not built it doesn't alter the max fields. + $this->createAndSetPlanetModel([ + 'field_max' => 100, + 'terraformer' => 0, + ]); + + $this->assertEquals(100, $this->planetService->getPlanetFieldMax()); + } /** * Tests building count returns valid buildings, and specified levels. */ From ed71f9c54bad91472cf1025f434e8b2e7011e3be Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 24 Oct 2024 00:46:16 +0100 Subject: [PATCH 2/5] adjust comment logic --- tests/Unit/PlanetServiceTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/Unit/PlanetServiceTest.php b/tests/Unit/PlanetServiceTest.php index f9f3a6c..3056d77 100644 --- a/tests/Unit/PlanetServiceTest.php +++ b/tests/Unit/PlanetServiceTest.php @@ -150,9 +150,8 @@ public function testGetPlanetFieldMaxWithTerraformer(): void 'terraformer' => 20, ]); - // 100 base, plus 20*5 = 200 - // - each level + 5 max fields, - // - every 2 levels + 1 max field- 20/2 = 210 + // each level + 5 max fields - 100 base, plus 20*5 = 200 + // every 2 levels + 1 max field- 20/2 = 10, so 200 + 100 = 210 $this->assertEquals(210, $this->planetService->getPlanetFieldMax()); From 56bbdb806de1e21f5b5fc0c9429490ec2e68fd4d Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 24 Oct 2024 00:47:54 +0100 Subject: [PATCH 3/5] remove unrequired if --- app/Services/PlanetService.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/Services/PlanetService.php b/app/Services/PlanetService.php index d0edc46..a3ec11a 100644 --- a/app/Services/PlanetService.php +++ b/app/Services/PlanetService.php @@ -360,10 +360,8 @@ public function getPlanetFieldMax(): int // For every 2 levels, it adds another bonus field $two_level_bonus_count = (int)(floor($this->planet->terraformer / 2)); - if ($two_level_bonus_count != 0) { - $extra_fields += $two_level_bonus_count; + $extra_fields += $two_level_bonus_count; - } } return $extra_fields + $this->planet->field_max; From babd54c3ed7e834322c67eb5ba64b6b409c9a32f Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 24 Oct 2024 00:51:41 +0100 Subject: [PATCH 4/5] typo --- tests/Unit/PlanetServiceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/PlanetServiceTest.php b/tests/Unit/PlanetServiceTest.php index 3056d77..758bbe2 100644 --- a/tests/Unit/PlanetServiceTest.php +++ b/tests/Unit/PlanetServiceTest.php @@ -151,7 +151,7 @@ public function testGetPlanetFieldMaxWithTerraformer(): void ]); // each level + 5 max fields - 100 base, plus 20*5 = 200 - // every 2 levels + 1 max field- 20/2 = 10, so 200 + 100 = 210 + // every 2 levels + 1 max field- 20/2 = 10, so 200 + 10 = 210 $this->assertEquals(210, $this->planetService->getPlanetFieldMax()); From d8ef389817f5adf21d0869e22eb03bb6ec1cf233 Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 24 Oct 2024 21:23:52 +0100 Subject: [PATCH 5/5] alter whitespace to conform --- app/Services/PlanetService.php | 1 - tests/Unit/PlanetServiceTest.php | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/Services/PlanetService.php b/app/Services/PlanetService.php index a3ec11a..641e4b2 100644 --- a/app/Services/PlanetService.php +++ b/app/Services/PlanetService.php @@ -362,7 +362,6 @@ public function getPlanetFieldMax(): int $two_level_bonus_count = (int)(floor($this->planet->terraformer / 2)); $extra_fields += $two_level_bonus_count; - } return $extra_fields + $this->planet->field_max; } diff --git a/tests/Unit/PlanetServiceTest.php b/tests/Unit/PlanetServiceTest.php index 758bbe2..1e2dcc4 100644 --- a/tests/Unit/PlanetServiceTest.php +++ b/tests/Unit/PlanetServiceTest.php @@ -115,18 +115,17 @@ public function testGetPlanetFieldMax(): void ]); $this->assertEquals(90, $this->planetService->getPlanetFieldMax()); - $this->createAndSetPlanetModel([ 'field_max' => 14, ]); $this->assertEquals(14, $this->planetService->getPlanetFieldMax()); } + /** * Test that the field max function with terraformer returns expected values */ public function testGetPlanetFieldMaxWithTerraformer(): void { - // Test none divisible by 2-- should only add 5. $this->createAndSetPlanetModel([ 'field_max' => 90, @@ -135,7 +134,6 @@ public function testGetPlanetFieldMaxWithTerraformer(): void $this->assertEquals(95, $this->planetService->getPlanetFieldMax()); - // Test a divisible of 2, should add 5, and +1 bonus. $this->createAndSetPlanetModel([ 'field_max' => 150, @@ -163,6 +161,7 @@ public function testGetPlanetFieldMaxWithTerraformer(): void $this->assertEquals(100, $this->planetService->getPlanetFieldMax()); } + /** * Tests building count returns valid buildings, and specified levels. */