Skip to content

Commit c6c9022

Browse files
authored
Merge pull request lanedirt#1108 from nguyenthanhan/fix/crawlers-energy-display-overlay-1011
fix: display energy needed for Crawlers in building overlay lanedirt#1011 lanedirt#1012
2 parents b948b8a + ba1fbca commit c6c9022

File tree

8 files changed

+60
-6
lines changed

8 files changed

+60
-6
lines changed

app/GameMissions/BattleEngine/Models/DefenderFleet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace OGame\GameMissions\BattleEngine\Models;
44

5-
use OGame\Services\ObjectService;
65
use OGame\Factories\PlayerServiceFactory;
76
use OGame\GameObjects\Models\Units\UnitCollection;
87
use OGame\Models\FleetMission;
98
use OGame\Services\FleetMissionService;
9+
use OGame\Services\ObjectService;
1010
use OGame\Services\PlanetService;
1111
use OGame\Services\PlayerService;
1212

app/GameObjects/CivilShipObjects.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public static function get(): array
190190
$crawler->title = 'Crawler';
191191
$crawler->machine_name = 'crawler';
192192
$crawler->class_name = 'resbuggy'; // CSS uses 'resbuggy' for Crawler sprite
193-
$crawler->description = 'Crawlers are resource drones that support the mines and increase production.';
193+
$crawler->description = 'Crawlers increase the production of metal, crystal and Deuterium on their tasked planet each by 0.02%, 0.02% and 0.02% respectively. As a collector, production also increases. The maximum total bonus depends on the overall level of your mines.';
194194
$crawler->description_long = 'Crawlers are state-of-the-art mining machines which can considerably increase the production of raw materials in the mines. However, they can only be built by members of the Collector class. Crawlers move across the planet`s surface and enter the shafts where they help to increase the mine`s production. The maximum number of Crawlers that can be used is limited by the level of the planet`s mines. The maximum overcharge is 100%. Collectors will be able to upgrade their Crawlers to an overcharge of 150%.';
195195
$crawler->requirements = [
196196
new GameObjectRequirement('shipyard', 4),

app/Http/Middleware/ServerTiming.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
namespace OGame\Http\Middleware;
44

55
use Closure;
6+
7+
use function defined;
8+
69
use Illuminate\Http\Request;
710
use Symfony\Component\HttpFoundation\Response;
811

@@ -20,7 +23,7 @@ public function handle(Request $request, Closure $next): Response
2023
$response = $next($request);
2124

2225
// Add server timing metrics for performance monitoring.
23-
$processingTime = \defined('LARAVEL_START') ? round((microtime(true) - LARAVEL_START) * 1000, 2) : 0;
26+
$processingTime = defined('LARAVEL_START') ? round((microtime(true) - LARAVEL_START) * 1000, 2) : 0;
2427
$response->headers->set('Server-Timing', 'app;dur=' . $processingTime . ', cdn;desc="miss", origin;desc="local"');
2528

2629
return $response;

app/Http/Traits/ObjectAjaxTrait.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,19 @@ public function ajaxHandler(Request $request, PlayerService $player): JsonRespon
111111
if (!empty($production_current->energy->get())) {
112112
$energy_difference = ($production_next->energy->get() - $production_current->energy->get()) * -1;
113113
}
114+
} elseif ($object->machine_name === 'crawler') {
115+
// Special handling for Crawlers: they consume energy but don't have production property
116+
// Each crawler consumes 50 energy at 100%, with additional cost for overcharge
117+
$crawlerPercentage = $planet->getBuildingPercent('crawler') / 10; // Convert to decimal (0-1.5)
118+
$baseEnergy = 50;
119+
$energyConsumption = $baseEnergy * $crawlerPercentage;
120+
121+
// Add extra energy cost for overload (>100%)
122+
if ($crawlerPercentage > 1.0) {
123+
$energyConsumption += $baseEnergy * ($crawlerPercentage - 1.0);
124+
}
125+
126+
$energy_difference = floor($energyConsumption);
114127
}
115128

116129
$enough_resources = $planet->hasResources($price);

app/Models/FleetTemplate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace OGame\Models;
44

5-
use Illuminate\Support\Carbon;
65
use Illuminate\Database\Eloquent\Factories\HasFactory;
76
use Illuminate\Database\Eloquent\Model;
87
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8+
use Illuminate\Support\Carbon;
99

1010
/**
1111
*

tests/Feature/FleetDispatch/FleetDispatchEspionageTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Exception;
66
use Illuminate\Support\Carbon;
7-
use Illuminate\Support\Facades\DB;
87
use OGame\GameMissions\EspionageMission;
98
use OGame\GameObjects\Models\Units\UnitCollection;
109
use OGame\Models\EspionageReport;

tests/Feature/MissilesDoNotParticipateInCombatTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace Tests\Feature;
44

5-
use OGame\Models\Message;
65
use OGame\Factories\PlanetServiceFactory;
76
use OGame\GameMissions\AttackMission;
87
use OGame\GameObjects\Models\Units\UnitCollection;
98
use OGame\Models\BattleReport;
9+
use OGame\Models\Message;
1010
use OGame\Models\Resources;
1111
use OGame\Services\FleetMissionService;
1212
use OGame\Services\ObjectService;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Tests\Unit;
4+
5+
use OGame\Services\ObjectService;
6+
use Tests\UnitTestCase;
7+
8+
/**
9+
* Test that the Crawler energy consumption is displayed correctly in building overlay.
10+
*/
11+
class CrawlerEnergyDisplayTest extends UnitTestCase
12+
{
13+
/**
14+
* Test that crawlers display energy consumption correctly in building overlay.
15+
*/
16+
public function test_crawler_energy_display_in_overlay(): void
17+
{
18+
// Create a planet with some mines to allow crawlers to work
19+
$this->createAndSetPlanetModel([
20+
'metal_mine' => 10,
21+
'crystal_mine' => 10,
22+
'deuterium_synthesizer' => 10,
23+
'crawler' => 0, // Starting with 0 crawlers
24+
]);
25+
26+
// Get crawler object
27+
$object = ObjectService::getObjectById(217); // Crawler ID
28+
29+
// Simulate the energy calculation from ObjectAjaxTrait for 100% production
30+
$crawlerPercentage = 10 / 10; // Convert to decimal (0-1.5)
31+
$baseEnergy = 50;
32+
$energyConsumption = $baseEnergy * $crawlerPercentage;
33+
34+
$energy_difference = floor($energyConsumption);
35+
36+
// Assert that energy consumption is calculated correctly
37+
$this->assertEquals(50, $energy_difference, 'Crawler should consume 50 energy at 100% production');
38+
}
39+
}

0 commit comments

Comments
 (0)