Skip to content

Commit

Permalink
GH-230 Move colonization task handling to an util
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jul 6, 2022
1 parent ccf1db0 commit 97b485b
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 19 deletions.
2 changes: 2 additions & 0 deletions modules/overview/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

$includePath = $_EnginePath . 'modules/overview/';

include($includePath . './screens/AbandonPlanet/utils/effects/triggerUserTasksUpdates.effect.php');

include($includePath . './screens/FirstLogin/FirstLogin.screen.php');
include($includePath . './screens/FirstLogin/FirstLogin.utils.php');
include($includePath . './screens/FirstLogin/utils/effects/createUserDevLogDump.effect.php');
Expand Down
5 changes: 5 additions & 0 deletions modules/overview/screens/AbandonPlanet/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace UniEngine\Engine\Modules\Overview\Screens\AbandonPlanet\Utils\Effects;

/**
* @param array $params
* @param arrayRef $params['user']
*/
function triggerUserTasksUpdates($props) {
$user = &$props['user'];

// Prevent abandoning Planet to make mission faster
Tasks_TriggerTask(
$user,
'COLONIZE_PLANET',
[
'mainCheck' => function ($JobArray, $ThisCat, $TaskID, $JobID) use ($user) {
global $UserTasksUpdate;

$userId = $user['id'];

if (!empty($UserTasksUpdate[$userId]['status'][$ThisCat][$TaskID][$JobID])) {
$user['tasks_done_parsed']['status'][$ThisCat][$TaskID][$JobID] = $UserTasksUpdate[$userId]['status'][$ThisCat][$TaskID][$JobID];
}
if ($user['tasks_done_parsed']['status'][$ThisCat][$TaskID][$JobID] <= 0) {
return true;
}

$user['tasks_done_parsed']['status'][$ThisCat][$TaskID][$JobID] -= 1;
$UserTasksUpdate[$userId]['status'][$ThisCat][$TaskID][$JobID] = $user['tasks_done_parsed']['status'][$ThisCat][$TaskID][$JobID];

return true;
}
]
);
}

?>
5 changes: 5 additions & 0 deletions modules/overview/screens/AbandonPlanet/utils/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>
22 changes: 3 additions & 19 deletions overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,9 @@
$DeleteResult = DeleteSelectedPlanetorMoon();
if($DeleteResult['result'] === true)
{
// Prevent abandoning Planet to make mission faster
Tasks_TriggerTask($_User, 'COLONIZE_PLANET', array
(
'mainCheck' => function($JobArray, $ThisCat, $TaskID, $JobID) use ($_User)
{
global $UserTasksUpdate;
if(!empty($UserTasksUpdate[$_User['id']]['status'][$ThisCat][$TaskID][$JobID]))
{
$_User['tasks_done_parsed']['status'][$ThisCat][$TaskID][$JobID] = $UserTasksUpdate[$_User['id']]['status'][$ThisCat][$TaskID][$JobID];
}
if($_User['tasks_done_parsed']['status'][$ThisCat][$TaskID][$JobID] <= 0)
{
return true;
}
$_User['tasks_done_parsed']['status'][$ThisCat][$TaskID][$JobID] -= 1;
$UserTasksUpdate[$_User['id']]['status'][$ThisCat][$TaskID][$JobID] = $_User['tasks_done_parsed']['status'][$ThisCat][$TaskID][$JobID];
return true;
}
));
Overview\Screens\AbandonPlanet\Utils\Effects\triggerUserTasksUpdates([
'user' => &$_User,
]);

// User Development Log
$UserDev_Log[] = array('PlanetID' => $_Planet['id'], 'Date' => $Now, 'Place' => 25, 'Code' => '0', 'ElementID' => '0');
Expand Down

0 comments on commit 97b485b

Please sign in to comment.