Skip to content

Commit

Permalink
GH-91 Use the newly created moon chance roll util in MissionCaseDestr…
Browse files Browse the repository at this point in the history
…uction
  • Loading branch information
mdziekon committed May 17, 2020
1 parent 6b1f202 commit f2295f2
Showing 1 changed file with 26 additions and 31 deletions.
57 changes: 26 additions & 31 deletions includes/functions/MissionCaseDestruction.php
Expand Up @@ -15,7 +15,6 @@ function MissionCaseDestruction($FleetRow, &$_FleetCache)
$FleetDestroyedByMoon = false;
$FleetHasBeenDestroyed = false;
$DestructionDone = false;
$MoonHasBeenCreated = false;

$MoonHasBeenDestroyed = 0;

Expand Down Expand Up @@ -235,7 +234,7 @@ function MissionCaseDestruction($FleetRow, &$_FleetCache)
$DebrisMetalDef = 0;
$DebrisCrystalDef = 0;

$MoonHasBeenCreated = false;
$moonHasBeenCreated = false;
$postCombatDeathstarsCount = 0;

$RoundsData = $Combat['rounds'];
Expand Down Expand Up @@ -730,37 +729,33 @@ function MissionCaseDestruction($FleetRow, &$_FleetCache)
}

// Check if Moon has been created
$FleetDebris = $TotalLostCrystal + $TotalLostMetal;
$moonCreationRollResult = Flights\Utils\Calculations\calculateMoonCreationRoll([
'totalDebris' => ($TotalLostCrystal + $TotalLostMetal),
]);

$MoonChance = floor($FleetDebris / COMBAT_MOONPERCENT_RESOURCES);
if($MoonChance > 20)
{
$TotalMoonChance = $MoonChance;
$MoonChance = 20;
}
if($MoonChance < 1)
{
$UserChance = 0;
}
elseif($MoonChance >= 1)
{
$UserChance = mt_rand(1, 100);
}
$TotalMoonChance = $moonCreationRollResult['totalMoonChance'];

if (
$moonCreationRollResult['hasMoonBeenCreated'] &&
$MoonHasBeenDestroyed === 1
) {
$newMoonID = CreateOneMoonRecord(
$FleetRow['fleet_end_galaxy'],
$FleetRow['fleet_end_system'],
$FleetRow['fleet_end_planet'],
$TargetUserID,
'',
$moonCreationRollResult['boundedMoonChance']
);

if($UserChance > 0 AND $UserChance <= $MoonChance AND $MoonHasBeenDestroyed === 1)
{
$CreatedMoonID = CreateOneMoonRecord($FleetRow['fleet_end_galaxy'], $FleetRow['fleet_end_system'], $FleetRow['fleet_end_planet'], $TargetUserID, '', $MoonChance);
if($CreatedMoonID !== false)
{
if ($newMoonID !== false) {
$TriggerTasksCheck['atk']['CREATE_MOON'] = true;
$GalaxyMoonID_NeedsUpdate = false;
$MoonHasBeenCreated = true;
$moonHasBeenCreated = true;

$UserDev_UpPl[] = "L,{$CreatedMoonID}";
$UserDev_UpPl[] = "L,{$newMoonID}";

// Update User Stats
foreach($AttackersIDs as $UserID)
{
foreach ($AttackersIDs as $UserID) {
$UserStatsData[$UserID]['moons_created'] += 1;
}
}
Expand Down Expand Up @@ -812,9 +807,9 @@ function MissionCaseDestruction($FleetRow, &$_FleetCache)
'defenders' => $defendersResourceLosses,
],
'moonCreationData' => [
'hasBeenCreated' => $MoonHasBeenCreated,
'normalizedChance' => $MoonChance,
'totalChance' => $TotalMoonChance,
'hasBeenCreated' => $moonHasBeenCreated,
'normalizedChance' => $moonCreationRollResult['boundedMoonChance'],
'totalChance' => $moonCreationRollResult['totalMoonChance'],
],
'moonDestructionData' => [
'hasDestroyedMoon' => $MoonHasBeenDestroyed,
Expand Down Expand Up @@ -921,7 +916,7 @@ function MissionCaseDestruction($FleetRow, &$_FleetCache)
}
else
{
if($MoonHasBeenCreated)
if($moonHasBeenCreated)
{
$TriggerTasksCheck['atk']['CREATE_MOON_FRIENDLY'] = true;
}
Expand Down

0 comments on commit f2295f2

Please sign in to comment.