Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraformer planet field bonus logic #412

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion app/Services/PlanetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,18 @@ 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));
$extra_fields += $two_level_bonus_count;

jackbayliss marked this conversation as resolved.
Show resolved Hide resolved

}
return $extra_fields + $this->planet->field_max;
}

/**
Expand Down
41 changes: 41 additions & 0 deletions tests/Unit/PlanetServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,48 @@ 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
{

jackbayliss marked this conversation as resolved.
Show resolved Hide resolved
// Test none divisible by 2-- should only add 5.
$this->createAndSetPlanetModel([
'field_max' => 90,
'terraformer' => 1,
]);

$this->assertEquals(95, $this->planetService->getPlanetFieldMax());


jackbayliss marked this conversation as resolved.
Show resolved Hide resolved
// 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,
]);

// each level + 5 max fields - 100 base, plus 20*5 = 200
// every 2 levels + 1 max field- 20/2 = 10, so 200 + 10 = 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());
}
jackbayliss marked this conversation as resolved.
Show resolved Hide resolved
/**
* Tests building count returns valid buildings, and specified levels.
*/
Expand Down
Loading