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

Espionage report visibility based on espionage level #316

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
69 changes: 49 additions & 20 deletions app/GameMissions/EspionageMission.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function processArrival(FleetMission $mission): void
// Trigger target planet update to make sure the espionage report is accurate.
$target_planet->update();

$reportId = $this->createEspionageReport($target_planet);
$reportId = $this->createEspionageReport($mission, $origin_planet, $target_planet);

// Send a message to the player with a reference to the espionage report.
$this->messageService->sendEspionageReportMessageToPlayer(
Expand Down Expand Up @@ -100,54 +100,83 @@ protected function processReturn(FleetMission $mission): void
/**
* Creates an espionage report for the target planet.
*
* @param PlanetService $planet
* @param FleetMission $mission
* @param PlanetService $originPlanet
* @param PlanetService $targetPlanet
* @return int
*/
private function createEspionageReport(PlanetService $planet): int
private function createEspionageReport(FleetMission $mission, PlanetService $originPlanet, PlanetService $targetPlanet): int
{
// TODO: make sure the target planet is updated with the latest resources before creating the report
// to ensure the report is accurate at the current point in time.
// TODO: add planet update call here and add a test to cover this.

// Create new espionage report record.
$report = new EspionageReport();
$report->planet_galaxy = $planet->getPlanetCoordinates()->galaxy;
$report->planet_system = $planet->getPlanetCoordinates()->system;
$report->planet_position = $planet->getPlanetCoordinates()->position;
$report->planet_galaxy = $targetPlanet->getPlanetCoordinates()->galaxy;
$report->planet_system = $targetPlanet->getPlanetCoordinates()->system;
$report->planet_position = $targetPlanet->getPlanetCoordinates()->position;

$report->planet_user_id = $planet->getPlayer()->getId();
$report->planet_user_id = $targetPlanet->getPlayer()->getId();

$report->player_info = [
'player_id' => (string)$planet->getPlayer()->getId(),
'player_name' => $planet->getPlayer()->getUsername(),
'player_id' => (string)$targetPlanet->getPlayer()->getId(),
'player_name' => $targetPlanet->getPlayer()->getUsername(),
];

// Resources
$report->resources = [
'metal' => (int)$planet->metal()->get(),
'crystal' => (int)$planet->crystal()->get(),
'deuterium' => (int)$planet->deuterium()->get(),
'energy' => (int)$planet->energy()->get()
'metal' => (int)$targetPlanet->metal()->get(),
'crystal' => (int)$targetPlanet->crystal()->get(),
'deuterium' => (int)$targetPlanet->deuterium()->get(),
'energy' => (int)$targetPlanet->energy()->get()
];

// TODO: implement logic which determines what to include in the espionage report based on
// the player's espionage technology level. For example, the player can see more details about the
// target planet if the espionage technology level is higher.
//TODO: Validate this does not cause issues when probing slot 16
$attackerEspionnageLevel = $originPlanet->getPlayer()->getResearchLevel('espionage_technology');
$defenderEspionnageLevel = $targetPlanet->getPlayer()->getResearchLevel('espionage_technology');
$techDifference = $defenderEspionnageLevel - $attackerEspionnageLevel;
$levelDifference = max(0, $techDifference);
$extraProbesRequired = pow($levelDifference, 2);
$remainingProbes = max(0, $mission->espionage_probe - $extraProbesRequired);

// Fleets
$report->ships = $planet->getShipUnits()->toArray();
if ($this->canRevealData($remainingProbes, $attackerEspionnageLevel, $defenderEspionnageLevel, 2, 1)) {
$report->ships = $targetPlanet->getShipUnits()->toArray();
}

// Defense
$report->defense = $planet->getDefenseUnits()->toArray();
if ($this->canRevealData($remainingProbes, $attackerEspionnageLevel, $defenderEspionnageLevel, 3, 2)) {
$report->defense = $targetPlanet->getDefenseUnits()->toArray();
}

// Buildings
$report->buildings = $planet->getBuildingArray();
if ($this->canRevealData($remainingProbes, $attackerEspionnageLevel, $defenderEspionnageLevel, 5, 3)) {
$report->buildings = $targetPlanet->getBuildingArray();
}

// Research
$report->research = $planet->getPlayer()->getResearchArray();
if ($this->canRevealData($remainingProbes, $attackerEspionnageLevel, $defenderEspionnageLevel, 7, 4)) {
$report->research = $targetPlanet->getPlayer()->getResearchArray();
}

$report->save();

return $report->id;
}

/**
* Determine if specific data can be revealed in the report based on remaining probes and espionage levels.
*
* @param int $remainingProbes
* @param int $attackerLevel
* @param int $defenderLevel
* @param int $probeThreshold
* @param int $levelThreshold
* @return bool
*/
private function canRevealData(int $remainingProbes, int $attackerLevel, int $defenderLevel, int $probeThreshold, int $levelThreshold): bool
{
return $remainingProbes >= $probeThreshold || $attackerLevel - $levelThreshold >= $defenderLevel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,17 @@ class="icon_nf_link fleft overlay tooltip js_hideTipOnMobile"
</div>
<ul class="detail_list clearfix" data-type="ships">
@php /** @var OGame\ViewModels\UnitViewModel $unit */ @endphp
@foreach ($ships as $unit)
@forelse ($ships as $unit)
<li class="detail_list_el">
<div class="shipImage float_left">
<img class="tech{{ $unit->object->id }}" width="28" height="28" src="/img/icons/3e567d6f16d040326c7a0ea29a4f41.gif">
</div>
<span class="detail_list_txt">{{ $unit->object->title }}</span>
<span class="fright" style="margin-right: 10px;">{{ $unit->amount }}</span>
</li>
@endforeach
@empty
@lang('We were unable to retrieve any reliable information of this type from the scan.')
@endforelse
</ul>

<div class="section_title">
Expand All @@ -134,15 +136,17 @@ class="icon_nf_link fleft overlay tooltip js_hideTipOnMobile"
</div>
<ul class="detail_list clearfix" data-type="defense">
@php /** @var OGame\ViewModels\UnitViewModel $unit */ @endphp
@foreach ($defense as $unit)
@forelse ($defense as $unit)
<li class="detail_list_el">
<div class="defense_image float_left">
<img class="defense{{ $unit->object->id }}" width="28" height="28" src="/img/icons/3e567d6f16d040326c7a0ea29a4f41.gif">
</div>
<span class="detail_list_txt">{{ $unit->object->title }}</span>
<span class="fright" style="margin-right: 10px;">{{ $unit->amount }}</span>
</li>
@endforeach
@empty
@lang('We were unable to retrieve any reliable information of this type from the scan.')
@endforelse
</ul>


Expand All @@ -154,15 +158,17 @@ class="icon_nf_link fleft overlay tooltip js_hideTipOnMobile"

<ul class="detail_list clearfix" data-type="buildings">
@php /** @var OGame\ViewModels\UnitViewModel $unit */ @endphp
@foreach ($buildings as $unit)
@forelse ($buildings as $unit)
<li class="detail_list_el">
<div class="building_image float_left">
<img class="building{{ $unit->object->id }}" width="28" height="28" src="/img/icons/3e567d6f16d040326c7a0ea29a4f41.gif">
</div>
<span class="detail_list_txt">{{ $unit->object->title }}</span>
<span class="fright" style="margin-right: 10px;">{{ $unit->amount }}</span>
</li>
@endforeach
@empty
@lang('We were unable to retrieve any reliable information of this type from the scan.')
@endforelse
</ul>

<!--
Expand Down Expand Up @@ -246,15 +252,17 @@ class="icon_nf_link fleft overlay tooltip js_hideTipOnMobile"
</div>

<ul class="detail_list clearfix" data-type="research">
@foreach ($research as $unit)
@forelse ($research as $unit)
<li class="detail_list_el">
<div class="research_image float_left">
<img class="research{{ $unit->object->id }}" width="28" height="28" src="/img/icons/3e567d6f16d040326c7a0ea29a4f41.gif">
</div>
<span class="detail_list_txt">{{ $unit->object->title }}</span>
<span class="fright" style="margin-right: 10px;">{{ $unit->amount }}</span>
</li>
@endforeach
@empty
@lang('We were unable to retrieve any reliable information of this type from the scan.')
@endforelse
</ul>

<!--
Expand Down
Loading