Skip to content

Commit

Permalink
Merge pull request #186 from Chewbaka69/feature/applications-tab
Browse files Browse the repository at this point in the history
Implement the application tab in the ? pop-up
  • Loading branch information
lanedirt authored May 21, 2024
2 parents 76fa6e1 + 4a43b2e commit c4aade4
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 51 deletions.
2 changes: 1 addition & 1 deletion app/GameObjects/BuildingObjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static function get(): array
$fusionReactor->price = new GameObjectPrice(900, 360, 180, 0, 1.8);
$fusionReactor->requirements = [
new GameObjectRequirement('deuterium_synthesizer', 5),
new GameObjectRequirement('research_lab', 5),
new GameObjectRequirement('energy_technology', 3),
];
$fusionReactor->production = new GameObjectProduction();
$fusionReactor->production->deuterium = 'return - (10 * $building_level * pow(1.1, $building_level));';
Expand Down
2 changes: 1 addition & 1 deletion app/GameObjects/CivilShipObjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static function get(): array
$recycler->requirements = [
new GameObjectRequirement('shipyard', 4),
new GameObjectRequirement('combustion_drive', 6),
new GameObjectRequirement('shield_technology', 2),
new GameObjectRequirement('shielding_technology', 2),
];
$recycler->price = new GameObjectPrice(10000, 6000, 2000, 0);
$recycler->rapidfire = [
Expand Down
8 changes: 5 additions & 3 deletions app/GameObjects/DefenseObjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static function get(): array
$gaussCannon->requirements = [
new GameObjectRequirement('shipyard', 6),
new GameObjectRequirement('weapon_technology', 3),
new GameObjectRequirement('shield_technology', 1),
new GameObjectRequirement('shielding_technology', 1),
new GameObjectRequirement('energy_technology', 6),
];
$gaussCannon->price = new GameObjectPrice(20000, 15000, 2000, 0);
Expand Down Expand Up @@ -165,7 +165,7 @@ public static function get(): array
After a battle, there is up to a 70 % chance that failed defensive facilities can be returned to use.';
$smallShieldDome->requirements = [
new GameObjectRequirement('shipyard', 1),
new GameObjectRequirement('shield_technology', 2),
new GameObjectRequirement('shielding_technology', 2),
];
$smallShieldDome->price = new GameObjectPrice(10000, 10000, 0, 0);
$smallShieldDome->properties = new GameObjectProperties($smallShieldDome, 20000, 2000, 1, 0, 0, 0);
Expand All @@ -187,7 +187,7 @@ public static function get(): array
After a battle, there is up to a 70 % chance that failed defensive facilities can be returned to use.';
$largeShieldDome->requirements = [
new GameObjectRequirement('shipyard', 6),
new GameObjectRequirement('shield_technology', 6),
new GameObjectRequirement('shielding_technology', 6),
];
$largeShieldDome->price = new GameObjectPrice(50000, 50000, 0, 0);
$largeShieldDome->properties = new GameObjectProperties($largeShieldDome, 100000, 10000, 1, 0, 0, 0);
Expand All @@ -208,6 +208,7 @@ public static function get(): array
$antiBallisticMissile->description_long = 'Anti Ballistic Missiles (ABM) are your only line of defense when attacked by Interplanetary Missiles (IPM) on your planet or moon. When a launch of IPMs is detected, these missiles automatically arm, process a launch code in their flight computers, target the inbound IPM, and launch to intercept. During the flight, the target IPM is constantly tracked and course corrections are applied until the ABM reaches the target and destroys the attacking IPM. Each ABM destroys one incoming IPM.';
$antiBallisticMissile->requirements = [
new GameObjectRequirement('missile_silo', 2),
new GameObjectRequirement('shipyard', 1),
];
$antiBallisticMissile->price = new GameObjectPrice(8000, 2000, 0, 0);
$antiBallisticMissile->properties = new GameObjectProperties($antiBallisticMissile, 8000, 1, 1, 0, 0, 0);
Expand All @@ -227,6 +228,7 @@ public static function get(): array

$interplanetaryMissile->description_long = 'Interplanetary Missiles (IPM) are your offensive weapon to destroy the defenses of your target. Using state of the art tracking technology, each missile targets a certain number of defenses for destruction. Tipped with an anti-matter bomb, they deliver a destructive force so severe that destroyed shields and defenses cannot be repaired. The only way to counter these missiles is with ABMs.';
$interplanetaryMissile->requirements = [
new GameObjectRequirement('shipyard', 1),
new GameObjectRequirement('missile_silo', 4),
new GameObjectRequirement('impulse_drive', 1),
];
Expand Down
8 changes: 4 additions & 4 deletions app/GameObjects/ResearchObjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public static function get(): array
$ionTechnology->description = 'The concentration of ions allows for the construction of cannons, which can inflict enormous damage and reduce the deconstruction costs per level by 4%.';
$ionTechnology->description_long = 'Ions can be concentrated and accelerated into a deadly beam. These beams can then inflict enormous damage. Our scientists have also developed a technique that will clearly reduce the deconstruction costs for buildings and systems. For each research level, the deconstruction costs will sink by 4%.';
$ionTechnology->requirements = [
new GameObjectRequirement('research_lab', 4),
new GameObjectRequirement('energy_technology', 4),
new GameObjectRequirement('laser_technology', 4),
new GameObjectRequirement('energy_technology', 5),
new GameObjectRequirement('laser_technology', 5),
];
$ionTechnology->price = new GameObjectPrice(1000, 300, 100, 0, 2);
$ionTechnology->assets = new GameObjectAssets();
Expand Down Expand Up @@ -302,10 +302,10 @@ public static function get(): array
// --- Shielding Technology ---
$shieldingTechnology = new ResearchObject();
$shieldingTechnology->id = 110;
$shieldingTechnology->title = 'Shielding Technology';
$shieldingTechnology->title = 'Shield Technology';
$shieldingTechnology->machine_name = 'shielding_technology';
$shieldingTechnology->class_name = 'shieldingTechnology';
$shieldingTechnology->description = 'Shielding technology makes the shields on ships and defensive facilities more efficient. Each level of shield technology increases the strength of the shields by 10 % of the base value.';
$shieldingTechnology->description = 'Shield technology makes the shields on ships and defensive facilities more efficient. Each level of shield technology increases the strength of the shields by 10 % of the base value.';
$shieldingTechnology->description_long = 'With the invention of the magnetosphere generator, scientists learned that an artificial shield could be produced to protect the crew in space ships not only from the harsh solar radiation environment in deep space, but also provide protection from enemy fire during an attack. Once scientists finally perfected the technology, a magnetosphere generator was installed on all ships and defense systems.
As the technology is advanced to each level, the magnetosphere generator is upgraded which provides an additional 10% strength to the shields base value.';
Expand Down
2 changes: 1 addition & 1 deletion app/GameObjects/StationObjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public static function get(): array
Wreckage only appears if more than 150,000 units have been destroyed including one’s own ships which took part in the combat with a value of at least 5% of the ship points.
Since the Space Dock floats in orbit, it does not require a planet field.';
$terraformer->requirements = [
$spaceDock->requirements = [
new GameObjectRequirement('shipyard', 2),
];
$spaceDock->price = new GameObjectPrice(200, 0, 50, 50, 2);
Expand Down
51 changes: 51 additions & 0 deletions app/Http/Controllers/TechtreeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
use Exception;
use Illuminate\Http\Request;
use Illuminate\View\View;
use OGame\GameObjects\Models\Fields\GameObjectAssets;
use OGame\GameObjects\Models\Fields\GameObjectPrice;
use OGame\GameObjects\Models\Fields\GameObjectRequirement;
use OGame\GameObjects\Models\GameObject;
use OGame\Services\ObjectService;
use OGame\Services\PlanetService;
use OGame\Services\PlayerService;

class TechtreeController extends OGameController
Expand Down Expand Up @@ -59,6 +63,7 @@ public function ajax(Request $request, ObjectService $objects, PlayerService $pl
'object' => $object,
'object_id' => $object_id,
'planet' => $planet,
'required_by' => $this->getRequiredBy($object, $player, $objects, $planet)
]);
}

Expand Down Expand Up @@ -368,4 +373,50 @@ public function getAstrophysicsTable(GameObject $object, PlayerService $player):
'current_level' => $current_level,
]);
}

/**
* @param GameObject $object
* @param PlayerService $player
* @param ObjectService $objects
* @param PlanetService $planet
* @return array<int<0, max>, array<string, array<GameObjectRequirement>|int|GameObjectAssets|GameObjectPrice|string>>
*/
private function getRequiredBy(GameObject $object, PlayerService $player, ObjectService $objects, PlanetService $planet): array
{
$all_objects = $objects->getObjects();
$required_by = [];

$require_objects = array_filter($all_objects, function ($a_object) use ($object) {
$has_object_required = false;
foreach ($a_object->requirements as $requirement) {
if($requirement->object_machine_name === $object->machine_name) {
$has_object_required = true;
}
}

return $has_object_required;
});

foreach ($require_objects as $r_object) {
$met_all_requirement = 'true';

foreach ($r_object->requirements as $requirement) {
$n_requirement = $objects->getObjectByMachineName($requirement->object_machine_name);

if($n_requirement->type === 'research') {
$user_object_level = $player->getResearchLevel($n_requirement->machine_name);
} else {
$user_object_level = $planet->getObjectLevel($n_requirement->machine_name);
}

if ($requirement->level > $user_object_level) {
$met_all_requirement = 'false';
}
}

$required_by[] = [...(array)$r_object, 'met_requirements' => $met_all_requirement];
}

return $required_by;
}
}
84 changes: 46 additions & 38 deletions resources/views/ingame/techtree/applications.blade.php
Original file line number Diff line number Diff line change
@@ -1,41 +1,49 @@

<ul class="subsection_tabs">
<li>
<a class="overlay reiter"
data-overlay-same="true"
href="{{ route('techtree.ajax', ['tab' => 1, 'object_id' => $object->object->id]) }}">
<span>
Techtree </span>
</a>
</li>
<li>
<a class="overlay reiter active"
data-overlay-same="true"
href="{{ route('techtree.ajax', ['tab' => 4, 'object_id' => $object->object->id]) }}">
<span>
Applications </span>
</a>
</li>
<li>
<a class="overlay reiter"
data-overlay-same="true"
href="{{ route('techtree.ajax', ['tab' => 2, 'object_id' => $object->object->id]) }}">
<span>
Techinfo </span>
</a>
</li>
<li>
<a class="overlay reiter"
data-overlay-same="true"
href="{{ route('techtree.ajax', ['tab' => 3, 'object_id' => $object->object->id]) }}">
<span>
Technology </span>
</a>
</li>
</ul>
<div id="technologytree" data-title="@lang('Technology') - {{ $object->title }}">
<nav data-current-action="applications">
<ul>
<li>
<a class="overlay" data-action="technologytree" data-overlay-same="true" href="{{ route('techtree.ajax', ['tab' => 1, 'object_id' => $object->id]) }}">
@lang('Techtree')
</a>
</li>
<li>
<a class="overlay" data-action="applications" data-overlay-same="true" href="{{ route('techtree.ajax', ['tab' => 4, 'object_id' => $object->id]) }}">
@lang('Applications')
</a>
</li>
<li>
<a class="overlay" data-action="technologyinformation" data-overlay-same="true" href="{{ route('techtree.ajax', ['tab' => 2, 'object_id' => $object->id]) }}">
@lang('Techinfo')
</a>
</li>
<li>
<a class="overlay" data-action="technologies" data-overlay-same="true" href="{{ route('techtree.ajax', ['tab' => 3, 'object_id' => $object->id]) }}">
@lang('Technology')
</a>
</li>
</ul>
</nav>

<div class="content applications">
<p class="hint">{{$object->title}} is a requirement for:</p>
<ul class="applications">
@foreach ($required_by as $required)
<li class="tooltipHTML" title="{{ $required['title'] }}|{{ $required['description'] }}" aria-label="{{ $required['title'] }}" data-prerequisites-met="{{ $required['met_requirements'] }}">
<a href="{{ route('techtree.ajax', ['tab' => 1, 'object_id' => $object->id]) }}" class="sprite sprite_small {{ $required['class_name'] }} overlay" data-overlay-same="true">
</a>
</li>
@endforeach
</ul>
</div>
<script>
</script>
</div>

<div class="techtree" data-id="5752c611e29741257f3cf67e060afb27" data-title="Applications - {{ $object->object->title }}">
<div class="advice">{{ $object->object->title }} is a prerequisite of:</div>
There are no such technologies. </div>
<script type="text/javascript">
$(document).ready(function(){initOverlayName();});</script>
$(
function(){
initOverlayName();
}
);
</script>
6 changes: 3 additions & 3 deletions resources/views/ingame/techtree/techinfo.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
</a>
</li>
<li>
<a class="overlay" data-action="applications" data-overlay-same="true" href="{{ route('techtree.ajax', ['tab' => 2, 'object_id' => $object->id]) }}">
<a class="overlay" data-action="applications" data-overlay-same="true" href="{{ route('techtree.ajax', ['tab' => 4, 'object_id' => $object->id]) }}">
@lang('Applications')
</a>
</li>
<li>
<a class="overlay" data-action="technologyinformation" data-overlay-same="true" href="{{ route('techtree.ajax', ['tab' => 3, 'object_id' => $object->id]) }}">
<a class="overlay" data-action="technologyinformation" data-overlay-same="true" href="{{ route('techtree.ajax', ['tab' => 2, 'object_id' => $object->id]) }}">
@lang('Techinfo')
</a>
</li>
<li>
<a class="overlay" data-action="technologies" data-overlay-same="true" href="{{ route('techtree.ajax', ['tab' => 4, 'object_id' => $object->id]) }}">
<a class="overlay" data-action="technologies" data-overlay-same="true" href="{{ route('techtree.ajax', ['tab' => 3, 'object_id' => $object->id]) }}">
@lang('Technology')
</a>
</li>
Expand Down

0 comments on commit c4aade4

Please sign in to comment.