From fc1f849f071638c65930b56374cd41fb5a0a63d9 Mon Sep 17 00:00:00 2001 From: Tinydetoon Date: Thu, 27 Jul 2017 23:19:45 +0200 Subject: [PATCH 01/14] Fix incoming attacks detection --- .../Modules/Ares/Manager/CommanderManager.php | 23 +++++++++++++ system/views/components/fleet/listFleet.php | 32 ++++++------------- system/views/pages/desktop/fleet.php | 9 ++++-- .../desktop/mapElement/layer/attacks.php | 2 +- system/views/templates/desktop/toolbar.php | 19 +---------- 5 files changed, 40 insertions(+), 45 deletions(-) diff --git a/system/Modules/Ares/Manager/CommanderManager.php b/system/Modules/Ares/Manager/CommanderManager.php index ebd2dd944..9bf15b8e1 100644 --- a/system/Modules/Ares/Manager/CommanderManager.php +++ b/system/Modules/Ares/Manager/CommanderManager.php @@ -180,6 +180,29 @@ public function getIncomingAttacks($playerId) return $this->entityManager->getRepository(Commander::class)->getIncomingAttacks($playerId); } + /** + * @param int $playerId + * @return array + */ + public function getVisibleIncomingAttacks($playerId) + { + $attackingCommanders = $this->getIncomingAttacks($playerId) ; + $incomingCommanders = [] ; + + foreach ($attackingCommanders as $commander) { + # va chercher les heures auxquelles il rentre dans les cercles d'espionnage + $startPlace = $this->placeManager->get($commander->getRBase()); + $destinationPlace = $this->placeManager->get($commander->getRPlaceDestination()); + $times = Game::getAntiSpyEntryTime($startPlace, $destinationPlace, $commander->getArrivalDate()); + + if (strtotime(Utils::now()) >= strtotime($times[0])) { + # ajout de l'événement + $incomingCommanders[] = $commander; + } + } + return $incomingCommanders; + } + /** * @param int $playerId * @return array diff --git a/system/views/components/fleet/listFleet.php b/system/views/components/fleet/listFleet.php index 747e8a8d4..1ba97f37a 100755 --- a/system/views/components/fleet/listFleet.php +++ b/system/views/components/fleet/listFleet.php @@ -38,22 +38,12 @@ echo $base['info']['name']; echo ' (affecter un officier)'; echo ''; - + foreach ($base['fleets'] as $commander) { - $step = 0; - $reversed = $commander->rPlayer != $session->get('playerId') || $commander->travelType == Commander::BACK; - if ($commander->rPlayer != $session->get('playerId')) { - for ($i = 0; $i < $session->get('playerEvent')->size(); $i++) { - $event = $session->get('playerEvent')->get($i); - if ($event->get('eventId') == $commander->getId() && $event->exist('eventInfo')) { - foreach ($event->get('eventInfo')->get('inCircle') as $date) { - if (strtotime(Utils::now()) >= strtotime($date)) { $step++; } else { break; } - } - } - } - } + $reversed = $commander->rPlayer != $session->get('playerId') || $commander->travelType == Commander::BACK; + echo '
'; echo '
'; if ($commander->rPlayer != $session->get('playerId')) { @@ -70,20 +60,16 @@ } } echo ''; - echo (($commander->rPlayer == $session->get('playerId')) || ($commander->rPlayer != $session->get('playerId') && $step >= 2)) - ? CommanderResources::getInfo($commander->level, 'grade') . ' ' . $commander->name . ', ' - : 'Officier inconnu, '; + echo CommanderResources::getInfo($commander->level, 'grade') . ' ' . $commander->name . ', ' ; if ($commander->rPlayer != $session->get('playerId')) { - if ($step >= 2) { - switch ($commander->getTravelType()) { + + switch ($commander->travelType) { case Commander::LOOT: $type = 'tente de vous piller'; break; case Commander::COLO: $type = 'tente de vous conquérir'; break; default: $type = 'erreur'; break; } - } else { - echo 's\'approche de vous'; - } + echo $type; } elseif ($commander->statement == Commander::AFFECTED) { echo 'à quai'; } elseif ($commander->statement == Commander::MOVING) { @@ -96,9 +82,9 @@ } } - echo (($commander->rPlayer == $session->get('playerId')) || ($commander->rPlayer != $session->get('playerId') && $step >= 3)) + echo (($commander->rPlayer == $session->get('playerId')) ) ? ' | ' . Format::number($commander->getPev()) . ' pev' - : ' | ??? pev'; + : ' '; if ($commander->rPlayer == $session->get('playerId') && $commander->statement == Commander::MOVING && $commander->travelType != Commander::BACK) { echo ' annuler la mission'; diff --git a/system/views/pages/desktop/fleet.php b/system/views/pages/desktop/fleet.php index fd826f6cc..2bae5fa61 100755 --- a/system/views/pages/desktop/fleet.php +++ b/system/views/pages/desktop/fleet.php @@ -4,6 +4,10 @@ use Asylamba\Modules\Ares\Model\Commander; use Asylamba\Modules\Ares\Model\Report; use Asylamba\Classes\Exception\ErrorException; +use Asylamba\Classes\Library\Utils; +use Asylamba\Classes\Library\Chronos; +use Asylamba\Classes\Library\Format; +use Asylamba\Classes\Library\Game; $request = $this->getContainer()->get('app.request'); $response = $this->getContainer()->get('app.response'); @@ -55,9 +59,8 @@ } } } - - $attackingCommanders = $commanderManager->getCommandersByIds($commandersId); - + + $attackingCommanders = $commanderManager->getVisibleIncomingAttacks($session->get('playerId')); for ($i = 0; $i < count($obsets); $i++) { foreach ($attackingCommanders as $commander) { if ($commander->rDestinationPlace == $obsets[$i]['info']['id']) { diff --git a/system/views/pages/desktop/mapElement/layer/attacks.php b/system/views/pages/desktop/mapElement/layer/attacks.php index 0d75f7921..b73178bfe 100755 --- a/system/views/pages/desktop/mapElement/layer/attacks.php +++ b/system/views/pages/desktop/mapElement/layer/attacks.php @@ -12,7 +12,7 @@ # chargement des commandants attaquants $attackingCommanders = array_merge( - $commanderManager->getIncomingAttacks($session->get('playerId')), + $commanderManager->getVisibleIncomingAttacks($session->get('playerId')), $commanderManager->getOutcomingAttacks($session->get('playerId')) ); diff --git a/system/views/templates/desktop/toolbar.php b/system/views/templates/desktop/toolbar.php index a3fe9b31b..b5eedfdcd 100755 --- a/system/views/templates/desktop/toolbar.php +++ b/system/views/templates/desktop/toolbar.php @@ -21,24 +21,7 @@ $currentBase = $orbitalBaseManager->get($session->get('playerParams')->get('base')); - -$commanders = $commanderManager->getIncomingAttacks($session->get('playerId')); -$incomingCommanders = []; - -foreach ($commanders as $commander) { - # va chercher les heures auxquelles il rentre dans les cercles d'espionnage - $startPlace = $placeManager->get($commander->getRBase()); - $destinationPlace = $placeManager->get($commander->getRPlaceDestination()); - $times = Game::getAntiSpyEntryTime($startPlace, $destinationPlace, $commander->getArrivalDate()); - - if (strtotime(Utils::now()) >= strtotime($times[0])) { - //$info = $commanderManager->getEventInfo($commander); - //$info->add('inCircle', $times); - - # ajout de l'événement - $incomingCommanders[] = $commander; - } -} +$incomingCommanders = $commanderManager->getVisibleIncomingAttacks($session->get('playerId'));; $nbIncomingCommanders = count($incomingCommanders); $outcomingCommanders = $commanderManager->getPlayerCommanders($session->get('playerId'), [Commander::MOVING]); From e3baef061b5d3aa684d3cdff65891a8a024a4c83 Mon Sep 17 00:00:00 2001 From: Tinydetoon Date: Thu, 27 Jul 2017 23:19:45 +0200 Subject: [PATCH 02/14] Fix incoming attacks detection --- .../Modules/Ares/Manager/CommanderManager.php | 23 +++++++++++++ system/views/components/fleet/listFleet.php | 32 ++++++------------- system/views/pages/desktop/fleet.php | 5 ++- .../desktop/mapElement/layer/attacks.php | 2 +- system/views/templates/desktop/toolbar.php | 19 +---------- 5 files changed, 36 insertions(+), 45 deletions(-) diff --git a/system/Modules/Ares/Manager/CommanderManager.php b/system/Modules/Ares/Manager/CommanderManager.php index ebd2dd944..9bf15b8e1 100644 --- a/system/Modules/Ares/Manager/CommanderManager.php +++ b/system/Modules/Ares/Manager/CommanderManager.php @@ -180,6 +180,29 @@ public function getIncomingAttacks($playerId) return $this->entityManager->getRepository(Commander::class)->getIncomingAttacks($playerId); } + /** + * @param int $playerId + * @return array + */ + public function getVisibleIncomingAttacks($playerId) + { + $attackingCommanders = $this->getIncomingAttacks($playerId) ; + $incomingCommanders = [] ; + + foreach ($attackingCommanders as $commander) { + # va chercher les heures auxquelles il rentre dans les cercles d'espionnage + $startPlace = $this->placeManager->get($commander->getRBase()); + $destinationPlace = $this->placeManager->get($commander->getRPlaceDestination()); + $times = Game::getAntiSpyEntryTime($startPlace, $destinationPlace, $commander->getArrivalDate()); + + if (strtotime(Utils::now()) >= strtotime($times[0])) { + # ajout de l'événement + $incomingCommanders[] = $commander; + } + } + return $incomingCommanders; + } + /** * @param int $playerId * @return array diff --git a/system/views/components/fleet/listFleet.php b/system/views/components/fleet/listFleet.php index 747e8a8d4..1ba97f37a 100755 --- a/system/views/components/fleet/listFleet.php +++ b/system/views/components/fleet/listFleet.php @@ -38,22 +38,12 @@ echo $base['info']['name']; echo ' (affecter un officier)'; echo ''; - + foreach ($base['fleets'] as $commander) { - $step = 0; - $reversed = $commander->rPlayer != $session->get('playerId') || $commander->travelType == Commander::BACK; - if ($commander->rPlayer != $session->get('playerId')) { - for ($i = 0; $i < $session->get('playerEvent')->size(); $i++) { - $event = $session->get('playerEvent')->get($i); - if ($event->get('eventId') == $commander->getId() && $event->exist('eventInfo')) { - foreach ($event->get('eventInfo')->get('inCircle') as $date) { - if (strtotime(Utils::now()) >= strtotime($date)) { $step++; } else { break; } - } - } - } - } + $reversed = $commander->rPlayer != $session->get('playerId') || $commander->travelType == Commander::BACK; + echo '
'; echo '
'; if ($commander->rPlayer != $session->get('playerId')) { @@ -70,20 +60,16 @@ } } echo ''; - echo (($commander->rPlayer == $session->get('playerId')) || ($commander->rPlayer != $session->get('playerId') && $step >= 2)) - ? CommanderResources::getInfo($commander->level, 'grade') . ' ' . $commander->name . ', ' - : 'Officier inconnu, '; + echo CommanderResources::getInfo($commander->level, 'grade') . ' ' . $commander->name . ', ' ; if ($commander->rPlayer != $session->get('playerId')) { - if ($step >= 2) { - switch ($commander->getTravelType()) { + + switch ($commander->travelType) { case Commander::LOOT: $type = 'tente de vous piller'; break; case Commander::COLO: $type = 'tente de vous conquérir'; break; default: $type = 'erreur'; break; } - } else { - echo 's\'approche de vous'; - } + echo $type; } elseif ($commander->statement == Commander::AFFECTED) { echo 'à quai'; } elseif ($commander->statement == Commander::MOVING) { @@ -96,9 +82,9 @@ } } - echo (($commander->rPlayer == $session->get('playerId')) || ($commander->rPlayer != $session->get('playerId') && $step >= 3)) + echo (($commander->rPlayer == $session->get('playerId')) ) ? ' | ' . Format::number($commander->getPev()) . ' pev' - : ' | ??? pev'; + : ' '; if ($commander->rPlayer == $session->get('playerId') && $commander->statement == Commander::MOVING && $commander->travelType != Commander::BACK) { echo ' annuler la mission'; diff --git a/system/views/pages/desktop/fleet.php b/system/views/pages/desktop/fleet.php index fd826f6cc..9f2286a60 100755 --- a/system/views/pages/desktop/fleet.php +++ b/system/views/pages/desktop/fleet.php @@ -55,9 +55,8 @@ } } } - - $attackingCommanders = $commanderManager->getCommandersByIds($commandersId); - + + $attackingCommanders = $commanderManager->getVisibleIncomingAttacks($session->get('playerId')); for ($i = 0; $i < count($obsets); $i++) { foreach ($attackingCommanders as $commander) { if ($commander->rDestinationPlace == $obsets[$i]['info']['id']) { diff --git a/system/views/pages/desktop/mapElement/layer/attacks.php b/system/views/pages/desktop/mapElement/layer/attacks.php index 0d75f7921..b73178bfe 100755 --- a/system/views/pages/desktop/mapElement/layer/attacks.php +++ b/system/views/pages/desktop/mapElement/layer/attacks.php @@ -12,7 +12,7 @@ # chargement des commandants attaquants $attackingCommanders = array_merge( - $commanderManager->getIncomingAttacks($session->get('playerId')), + $commanderManager->getVisibleIncomingAttacks($session->get('playerId')), $commanderManager->getOutcomingAttacks($session->get('playerId')) ); diff --git a/system/views/templates/desktop/toolbar.php b/system/views/templates/desktop/toolbar.php index a3fe9b31b..b5eedfdcd 100755 --- a/system/views/templates/desktop/toolbar.php +++ b/system/views/templates/desktop/toolbar.php @@ -21,24 +21,7 @@ $currentBase = $orbitalBaseManager->get($session->get('playerParams')->get('base')); - -$commanders = $commanderManager->getIncomingAttacks($session->get('playerId')); -$incomingCommanders = []; - -foreach ($commanders as $commander) { - # va chercher les heures auxquelles il rentre dans les cercles d'espionnage - $startPlace = $placeManager->get($commander->getRBase()); - $destinationPlace = $placeManager->get($commander->getRPlaceDestination()); - $times = Game::getAntiSpyEntryTime($startPlace, $destinationPlace, $commander->getArrivalDate()); - - if (strtotime(Utils::now()) >= strtotime($times[0])) { - //$info = $commanderManager->getEventInfo($commander); - //$info->add('inCircle', $times); - - # ajout de l'événement - $incomingCommanders[] = $commander; - } -} +$incomingCommanders = $commanderManager->getVisibleIncomingAttacks($session->get('playerId'));; $nbIncomingCommanders = count($incomingCommanders); $outcomingCommanders = $commanderManager->getPlayerCommanders($session->get('playerId'), [Commander::MOVING]); From 72e231065efe71e0485b46d66bd260d3907765b9 Mon Sep 17 00:00:00 2001 From: Tinydetoon Date: Thu, 27 Jul 2017 23:58:10 +0200 Subject: [PATCH 03/14] Fix incoming attacks detection --- system/views/pages/desktop/fleet.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/system/views/pages/desktop/fleet.php b/system/views/pages/desktop/fleet.php index 2bae5fa61..9f2286a60 100755 --- a/system/views/pages/desktop/fleet.php +++ b/system/views/pages/desktop/fleet.php @@ -4,10 +4,6 @@ use Asylamba\Modules\Ares\Model\Commander; use Asylamba\Modules\Ares\Model\Report; use Asylamba\Classes\Exception\ErrorException; -use Asylamba\Classes\Library\Utils; -use Asylamba\Classes\Library\Chronos; -use Asylamba\Classes\Library\Format; -use Asylamba\Classes\Library\Game; $request = $this->getContainer()->get('app.request'); $response = $this->getContainer()->get('app.response'); From 90e54255c0ebe8a863fb037bca6ef1f659f07451 Mon Sep 17 00:00:00 2001 From: Tinydetoon Date: Thu, 27 Jul 2017 23:19:45 +0200 Subject: [PATCH 04/14] Fix incoming attacks detection --- .../Modules/Ares/Manager/CommanderManager.php | 23 +++++++++++++ system/views/components/fleet/listFleet.php | 32 ++++++------------- system/views/pages/desktop/fleet.php | 9 ++++-- .../desktop/mapElement/layer/attacks.php | 2 +- system/views/templates/desktop/toolbar.php | 19 +---------- 5 files changed, 40 insertions(+), 45 deletions(-) diff --git a/system/Modules/Ares/Manager/CommanderManager.php b/system/Modules/Ares/Manager/CommanderManager.php index ebd2dd944..9bf15b8e1 100644 --- a/system/Modules/Ares/Manager/CommanderManager.php +++ b/system/Modules/Ares/Manager/CommanderManager.php @@ -180,6 +180,29 @@ public function getIncomingAttacks($playerId) return $this->entityManager->getRepository(Commander::class)->getIncomingAttacks($playerId); } + /** + * @param int $playerId + * @return array + */ + public function getVisibleIncomingAttacks($playerId) + { + $attackingCommanders = $this->getIncomingAttacks($playerId) ; + $incomingCommanders = [] ; + + foreach ($attackingCommanders as $commander) { + # va chercher les heures auxquelles il rentre dans les cercles d'espionnage + $startPlace = $this->placeManager->get($commander->getRBase()); + $destinationPlace = $this->placeManager->get($commander->getRPlaceDestination()); + $times = Game::getAntiSpyEntryTime($startPlace, $destinationPlace, $commander->getArrivalDate()); + + if (strtotime(Utils::now()) >= strtotime($times[0])) { + # ajout de l'événement + $incomingCommanders[] = $commander; + } + } + return $incomingCommanders; + } + /** * @param int $playerId * @return array diff --git a/system/views/components/fleet/listFleet.php b/system/views/components/fleet/listFleet.php index 747e8a8d4..1ba97f37a 100755 --- a/system/views/components/fleet/listFleet.php +++ b/system/views/components/fleet/listFleet.php @@ -38,22 +38,12 @@ echo $base['info']['name']; echo ' (affecter un officier)'; echo ''; - + foreach ($base['fleets'] as $commander) { - $step = 0; - $reversed = $commander->rPlayer != $session->get('playerId') || $commander->travelType == Commander::BACK; - if ($commander->rPlayer != $session->get('playerId')) { - for ($i = 0; $i < $session->get('playerEvent')->size(); $i++) { - $event = $session->get('playerEvent')->get($i); - if ($event->get('eventId') == $commander->getId() && $event->exist('eventInfo')) { - foreach ($event->get('eventInfo')->get('inCircle') as $date) { - if (strtotime(Utils::now()) >= strtotime($date)) { $step++; } else { break; } - } - } - } - } + $reversed = $commander->rPlayer != $session->get('playerId') || $commander->travelType == Commander::BACK; + echo '
'; echo '
'; if ($commander->rPlayer != $session->get('playerId')) { @@ -70,20 +60,16 @@ } } echo ''; - echo (($commander->rPlayer == $session->get('playerId')) || ($commander->rPlayer != $session->get('playerId') && $step >= 2)) - ? CommanderResources::getInfo($commander->level, 'grade') . ' ' . $commander->name . ', ' - : 'Officier inconnu, '; + echo CommanderResources::getInfo($commander->level, 'grade') . ' ' . $commander->name . ', ' ; if ($commander->rPlayer != $session->get('playerId')) { - if ($step >= 2) { - switch ($commander->getTravelType()) { + + switch ($commander->travelType) { case Commander::LOOT: $type = 'tente de vous piller'; break; case Commander::COLO: $type = 'tente de vous conquérir'; break; default: $type = 'erreur'; break; } - } else { - echo 's\'approche de vous'; - } + echo $type; } elseif ($commander->statement == Commander::AFFECTED) { echo 'à quai'; } elseif ($commander->statement == Commander::MOVING) { @@ -96,9 +82,9 @@ } } - echo (($commander->rPlayer == $session->get('playerId')) || ($commander->rPlayer != $session->get('playerId') && $step >= 3)) + echo (($commander->rPlayer == $session->get('playerId')) ) ? ' | ' . Format::number($commander->getPev()) . ' pev' - : ' | ??? pev'; + : ' '; if ($commander->rPlayer == $session->get('playerId') && $commander->statement == Commander::MOVING && $commander->travelType != Commander::BACK) { echo ' annuler la mission'; diff --git a/system/views/pages/desktop/fleet.php b/system/views/pages/desktop/fleet.php index fd826f6cc..2bae5fa61 100755 --- a/system/views/pages/desktop/fleet.php +++ b/system/views/pages/desktop/fleet.php @@ -4,6 +4,10 @@ use Asylamba\Modules\Ares\Model\Commander; use Asylamba\Modules\Ares\Model\Report; use Asylamba\Classes\Exception\ErrorException; +use Asylamba\Classes\Library\Utils; +use Asylamba\Classes\Library\Chronos; +use Asylamba\Classes\Library\Format; +use Asylamba\Classes\Library\Game; $request = $this->getContainer()->get('app.request'); $response = $this->getContainer()->get('app.response'); @@ -55,9 +59,8 @@ } } } - - $attackingCommanders = $commanderManager->getCommandersByIds($commandersId); - + + $attackingCommanders = $commanderManager->getVisibleIncomingAttacks($session->get('playerId')); for ($i = 0; $i < count($obsets); $i++) { foreach ($attackingCommanders as $commander) { if ($commander->rDestinationPlace == $obsets[$i]['info']['id']) { diff --git a/system/views/pages/desktop/mapElement/layer/attacks.php b/system/views/pages/desktop/mapElement/layer/attacks.php index 0d75f7921..b73178bfe 100755 --- a/system/views/pages/desktop/mapElement/layer/attacks.php +++ b/system/views/pages/desktop/mapElement/layer/attacks.php @@ -12,7 +12,7 @@ # chargement des commandants attaquants $attackingCommanders = array_merge( - $commanderManager->getIncomingAttacks($session->get('playerId')), + $commanderManager->getVisibleIncomingAttacks($session->get('playerId')), $commanderManager->getOutcomingAttacks($session->get('playerId')) ); diff --git a/system/views/templates/desktop/toolbar.php b/system/views/templates/desktop/toolbar.php index a3fe9b31b..b5eedfdcd 100755 --- a/system/views/templates/desktop/toolbar.php +++ b/system/views/templates/desktop/toolbar.php @@ -21,24 +21,7 @@ $currentBase = $orbitalBaseManager->get($session->get('playerParams')->get('base')); - -$commanders = $commanderManager->getIncomingAttacks($session->get('playerId')); -$incomingCommanders = []; - -foreach ($commanders as $commander) { - # va chercher les heures auxquelles il rentre dans les cercles d'espionnage - $startPlace = $placeManager->get($commander->getRBase()); - $destinationPlace = $placeManager->get($commander->getRPlaceDestination()); - $times = Game::getAntiSpyEntryTime($startPlace, $destinationPlace, $commander->getArrivalDate()); - - if (strtotime(Utils::now()) >= strtotime($times[0])) { - //$info = $commanderManager->getEventInfo($commander); - //$info->add('inCircle', $times); - - # ajout de l'événement - $incomingCommanders[] = $commander; - } -} +$incomingCommanders = $commanderManager->getVisibleIncomingAttacks($session->get('playerId'));; $nbIncomingCommanders = count($incomingCommanders); $outcomingCommanders = $commanderManager->getPlayerCommanders($session->get('playerId'), [Commander::MOVING]); From 4fab54b598cf09d5043878d6bfa740fd52fbcb63 Mon Sep 17 00:00:00 2001 From: Tinydetoon Date: Thu, 27 Jul 2017 23:58:10 +0200 Subject: [PATCH 05/14] Fix incoming attacks detection --- system/views/pages/desktop/fleet.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/system/views/pages/desktop/fleet.php b/system/views/pages/desktop/fleet.php index 2bae5fa61..9f2286a60 100755 --- a/system/views/pages/desktop/fleet.php +++ b/system/views/pages/desktop/fleet.php @@ -4,10 +4,6 @@ use Asylamba\Modules\Ares\Model\Commander; use Asylamba\Modules\Ares\Model\Report; use Asylamba\Classes\Exception\ErrorException; -use Asylamba\Classes\Library\Utils; -use Asylamba\Classes\Library\Chronos; -use Asylamba\Classes\Library\Format; -use Asylamba\Classes\Library\Game; $request = $this->getContainer()->get('app.request'); $response = $this->getContainer()->get('app.response'); From 0269ab67d32e837f08a8843a57412e6096a06200 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 9 Aug 2017 12:22:42 +0200 Subject: [PATCH 06/14] Fix recycling places conversion to empty places --- .../Modules/Athena/Manager/OrbitalBaseManager.php | 9 +++++---- system/Modules/Gaia/Manager/PlaceManager.php | 9 +++++++++ .../Modules/Gaia/Repository/PlaceRepository.php | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/system/Modules/Athena/Manager/OrbitalBaseManager.php b/system/Modules/Athena/Manager/OrbitalBaseManager.php index 2f85354fe..a195a7df4 100644 --- a/system/Modules/Athena/Manager/OrbitalBaseManager.php +++ b/system/Modules/Athena/Manager/OrbitalBaseManager.php @@ -716,8 +716,7 @@ public function uRecycling($missionId) { # if there is no more resource if ($targetPlace->resources <= 0) { # the place become an empty place - $targetPlace->resources = 0; - $targetPlace->typeOfPlace = Place::EMPTYZONE; + $this->placeManager->turnAsEmptyPlace($targetPlace); # stop the mission $mission->statement = RecyclingMission::ST_DELETED; @@ -860,8 +859,10 @@ public function uRecycling($missionId) { # update u $mission->uRecycling = Utils::addSecondsToDate($mission->uRecycling, $mission->cycleTime); - // Schedule the next mission - $this->realtimeActionScheduler->schedule('athena.orbital_base_manager', 'uRecycling', $mission, $mission->uRecycling); + // Schedule the next mission if there is still resources + if ($mission->getStatement() !== RecyclingMission::ST_DELETED) { + $this->realtimeActionScheduler->schedule('athena.orbital_base_manager', 'uRecycling', $mission, $mission->uRecycling); + } } else { # the place become an empty place $targetPlace->resources = 0; diff --git a/system/Modules/Gaia/Manager/PlaceManager.php b/system/Modules/Gaia/Manager/PlaceManager.php index f648d2c50..26906b27b 100644 --- a/system/Modules/Gaia/Manager/PlaceManager.php +++ b/system/Modules/Gaia/Manager/PlaceManager.php @@ -162,6 +162,15 @@ public function updatePlayerPlaces() { $this->entityManager->commit(); $this->entityManager->clear(Place::class); } + + /** + * @param Place $place + * @return bool + */ + public function turnAsEmptyPlace(Place $place) + { + return $this->entityManager->getRepository(Place::class)->turnAsEmptyPlace($place->getId()); + } public function turnAsSpawnPlace($placeId, $playerId) { diff --git a/system/Modules/Gaia/Repository/PlaceRepository.php b/system/Modules/Gaia/Repository/PlaceRepository.php index 5ec863414..071a8272e 100644 --- a/system/Modules/Gaia/Repository/PlaceRepository.php +++ b/system/Modules/Gaia/Repository/PlaceRepository.php @@ -232,6 +232,21 @@ public function updatePlace($place, $updateDanger = false) ]); } + /** + * @param int $placeId + * @return bool + */ + public function turnAsEmptyPlace($placeId) + { + $statement = $this->connection->prepare( + 'UPDATE place SET typeOfPlace = :place_type WHERE id = :id' + ); + return $statement->execute([ + 'place_type' => Place::EMPTYZONE, + 'id' => $placeId + ]); + } + /** * @param int $placeId * @param int $playerId From 25b07adbcfb4f34e94e2bd08e4f5b25425050b7e Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 9 Aug 2017 14:40:43 +0200 Subject: [PATCH 07/14] Fix player reborn method --- system/Modules/Zeus/Manager/PlayerManager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/Modules/Zeus/Manager/PlayerManager.php b/system/Modules/Zeus/Manager/PlayerManager.php index 5137bc782..7a0706b0f 100644 --- a/system/Modules/Zeus/Manager/PlayerManager.php +++ b/system/Modules/Zeus/Manager/PlayerManager.php @@ -396,7 +396,7 @@ public function reborn($playerId) { $placeId = NULL; foreach ($sectors as $sector) { # place choice - $qr = $this->entityManager->getConnection()->prepare('SELECT * FROM place AS p + $qr = $this->entityManager->getConnection()->prepare('SELECT p.id FROM place AS p INNER JOIN system AS sy ON p.rSystem = sy.id INNER JOIN sector AS se ON sy.rSector = se.id WHERE p.typeOfPlace = 1 @@ -409,7 +409,7 @@ public function reborn($playerId) { $aw = $qr->fetchAll(); if ($aw !== NULL) { $placeFound = TRUE; - $placeId = $aw[rand(0, (count($aw) - 1))][0]; + $placeId = $aw[rand(0, (count($aw) - 1))]['id']; break; } } From c512672d2bef04e0fe35955fb245e4055e4918e2 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 9 Aug 2017 14:41:44 +0200 Subject: [PATCH 08/14] Remove the dumping methods for the process gateway --- system/Classes/Process/ProcessGateway.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/system/Classes/Process/ProcessGateway.php b/system/Classes/Process/ProcessGateway.php index e16c5dba0..2167ffbaa 100644 --- a/system/Classes/Process/ProcessGateway.php +++ b/system/Classes/Process/ProcessGateway.php @@ -14,7 +14,6 @@ class ProcessGateway */ public function writeTo(Process $process, $data) { - \Asylamba\Classes\Daemon\Server::debug('Writing to Process : ' . json_encode($data)); fwrite($process->getOutput(), json_encode($data) . "\n"); } @@ -23,7 +22,6 @@ public function writeTo(Process $process, $data) */ public function writeToMaster($data) { - \Asylamba\Classes\Daemon\Server::debug('Writing to master: ' . json_encode($data)); fwrite(STDOUT, json_encode($data) . "\n"); } From bf8fa167075569d94253f31536652289cf213603 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 9 Aug 2017 15:17:39 +0200 Subject: [PATCH 09/14] Enable scheduled actions cancellation from process tasks --- system/Classes/Daemon/Server.php | 7 ++++++ .../Scheduler/RealTimeActionScheduler.php | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/system/Classes/Daemon/Server.php b/system/Classes/Daemon/Server.php index 0e82944b6..9b56a977d 100644 --- a/system/Classes/Daemon/Server.php +++ b/system/Classes/Daemon/Server.php @@ -195,6 +195,13 @@ public function treatCommand($data) $data['data']['date'] ); break; + case 'cancel': + $this->realTimeActionScheduler->cancelFromProcess( + $data['data']['object_class'], + $data['data']['object_id'], + $data['data']['date'] + ); + break; } } diff --git a/system/Classes/Scheduler/RealTimeActionScheduler.php b/system/Classes/Scheduler/RealTimeActionScheduler.php index 2253feda8..7d29cf4b8 100644 --- a/system/Classes/Scheduler/RealTimeActionScheduler.php +++ b/system/Classes/Scheduler/RealTimeActionScheduler.php @@ -138,12 +138,36 @@ public function reschedule($object, $date, $oldDate) { */ public function cancel($object, $date) { + if (P_TYPE === 'worker') { + return $this->processGateway->writeToMaster([ + 'command' => 'cancel', + 'data' => [ + 'object_class' => get_class($object), + 'object_id' => $object->id, + 'date' => $date + ] + ]); + } unset($this->queue[$date][get_class($object) . '-' . $object->id]); if (empty($this->queue[$date])) { unset($this->queue[$date]); } } + + /** + * @param string $class + * @param int $id + * @param string $date + */ + public function cancelFromProcess($class, $id, $date) + { + unset($this->queue[$date][$class . '-' . $id]); + + if (empty($this->queue[$date])) { + unset($this->queue[$date]); + } + } /** * @return array From a4887c5a591ca9653f013afbf52a44d78d7dfd35 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 9 Aug 2017 15:17:52 +0200 Subject: [PATCH 10/14] Fix moving commanders when their base is taken --- system/Modules/Athena/Manager/OrbitalBaseManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Modules/Athena/Manager/OrbitalBaseManager.php b/system/Modules/Athena/Manager/OrbitalBaseManager.php index a195a7df4..3347b42b4 100644 --- a/system/Modules/Athena/Manager/OrbitalBaseManager.php +++ b/system/Modules/Athena/Manager/OrbitalBaseManager.php @@ -420,7 +420,7 @@ public function changeOwnerById($id, $base, $newOwner, $baseCommanders) { if (in_array($commander->statement, [Commander::INSCHOOL, Commander::ONSALE, Commander::RESERVE])) { $commander->rPlayer = $newOwner; } else if ($commander->statement == Commander::MOVING) { - $commander->statement = Commander::RETIRED; + $this->commanderManager->endTravel($commander, Commander::RETIRED); $this->realtimeActionScheduler->cancel($commander, $commander->getArrivalDate()); } else { $commander->statement = Commander::DEAD; From ceae636165fdc802c8dd65cb7ffbac5b4d3bc181 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 9 Aug 2017 22:29:08 +0200 Subject: [PATCH 11/14] Refactor sector ownership calcul in sector manager and store results in Redis --- .../Gaia/EventListener/SectorListener.php | 41 +------- system/Modules/Gaia/Manager/SectorManager.php | 97 ++++++++++++++++++- .../Modules/Gaia/Resource/config/config.yml | 10 +- 3 files changed, 106 insertions(+), 42 deletions(-) diff --git a/system/Modules/Gaia/EventListener/SectorListener.php b/system/Modules/Gaia/EventListener/SectorListener.php index b0a103479..24d5957af 100644 --- a/system/Modules/Gaia/EventListener/SectorListener.php +++ b/system/Modules/Gaia/EventListener/SectorListener.php @@ -16,42 +16,29 @@ class SectorListener protected $sectorManager; /** @var SystemManager **/ protected $systemManager; - /** @var OrbitalBaseManager **/ - protected $orbitalBaseManager; - /** @var PlayerManager **/ - protected $playerManager; /** @var EntityManager **/ protected $entityManager; - /** @var array **/ - protected $scores; /** @var int **/ protected $minimalScore; /** * @param SectorManager $sectorManager * @param SystemManager $systemManager - * @param OrbitalBaseManager $orbitalBaseManager - * @param PlayerManager $playerManager * @param EntityManager $entityManager + * @param RedisManager $redisManager * @param array $scores * @param int $minimalScore */ public function __construct( SectorManager $sectorManager, SystemManager $systemManager, - OrbitalBaseManager $orbitalBaseManager, - PlayerManager $playerManager, EntityManager $entityManager, - $scores, $minimalScore ) { $this->sectorManager = $sectorManager; $this->systemManager = $systemManager; - $this->orbitalBaseManager = $orbitalBaseManager; - $this->playerManager = $playerManager; $this->entityManager = $entityManager; - $this->scores = $scores; $this->minimalScore = $minimalScore; } @@ -61,31 +48,9 @@ public function __construct( public function onPlaceOwnerChange(PlaceOwnerChangeEvent $event) { $system = $this->systemManager->get($event->getPlace()->rSystem); - $systems = $this->systemManager->getSectorSystems($system->rSector); $sector = $this->sectorManager->get($system->rSector); - $bases = $this->orbitalBaseManager->getSectorBases($system->rSector); - $scores = []; - - foreach ($bases as $base) - { - $player = $this->playerManager->get($base->rPlayer); - - $scores[$player->rColor] = - (!empty($scores[$player->rColor])) - ? $scores[$player->rColor] + $this->scores[$base->typeOfBase] - : $this->scores[$base->typeOfBase] - ; - } - // For each system, the owning faction gains two points - foreach ($systems as $system) { - if ($system->rColor === 0) { - continue; - } - $scores[$system->rColor] = (!empty($scores[$system->rColor])) ? $scores[$system->rColor] + 2 : 2; - } - $scores[0] = 0; - arsort($scores); - reset($scores); + $scores = $this->sectorManager->calculateOwnership($sector); + $newColor = key($scores); $hasEnoughPoints = false; foreach ($scores as $factionId => $score) { diff --git a/system/Modules/Gaia/Manager/SectorManager.php b/system/Modules/Gaia/Manager/SectorManager.php index d04dc211c..2d700fbcd 100644 --- a/system/Modules/Gaia/Manager/SectorManager.php +++ b/system/Modules/Gaia/Manager/SectorManager.php @@ -12,20 +12,71 @@ namespace Asylamba\Modules\Gaia\Manager; use Asylamba\Classes\Entity\EntityManager; +use Asylamba\Classes\Redis\RedisManager; +use Asylamba\Classes\Process\LoadBalancer; +use Asylamba\Classes\Task\TaskManager; + +use Asylamba\Modules\Athena\Manager\OrbitalBaseManager; +use Asylamba\Modules\Zeus\Manager\PlayerManager; +use Asylamba\Modules\Gaia\Manager\SystemManager; use Asylamba\Modules\Gaia\Model\Sector; class SectorManager { /** @var EntityManager **/ protected $entityManager; + /** @var RedisManager **/ + protected $redisManager; + /** @var LoadBalancer **/ + protected $loadBalancer; + /** @var TaskManager **/ + protected $taskManager; + /** @var OrbitalBaseManager **/ + protected $orbitalBaseManager; + /** @var PlayerManager **/ + protected $playerManager; + /** @var SystemManager **/ + protected $systemManager; + /** @var array **/ + protected $scores = []; /** * @param EntityManager $entityManager + * @param RedisManager $redisManager + * @param LoadBalancer $loadBalancer + * @param TaskManager $taskManager + * @param OrbitalBaseManager $orbitalBaseManager + * @param PlayerManager $playerManager + * @param SystemManager $systemManager + * @param array $scores */ - public function __construct(EntityManager $entityManager) + public function __construct( + EntityManager $entityManager, + RedisManager $redisManager, + LoadBalancer $loadBalancer, + TaskManager $taskManager, + OrbitalBaseManager $orbitalBaseManager, + PlayerManager $playerManager, + SystemManager $systemManager, + $scores + ) { $this->entityManager = $entityManager; + $this->redisManager = $redisManager; + $this->loadBalancer = $loadBalancer; + $this->taskManager = $taskManager; + $this->orbitalBaseManager = $orbitalBaseManager; + $this->playerManager = $playerManager; + $this->systemManager = $systemManager; + $this->scores = $scores; } + + public function initOwnershipData() + { + $this->loadBalancer->affectTask( + $this->taskManager->createTechnicalTask('gaia.sector_manager', 'calculateAllOwnerships') + ); + } /** * @param int $id @@ -59,4 +110,48 @@ public function changeOwnership(Sector $sector) { $this->entityManager->getRepository(Sector::class)->changeOwnership($sector); } + + public function calculateAllOwnerships() + { + \Asylamba\Classes\Daemon\Server::debug('sectors'); + foreach ($this->getAll() as $sector) { + $this->calculateOwnership($sector); + } + } + + /** + * @param Sector $sector + * @return array + */ + public function calculateOwnership(Sector $sector) + { + $systems = $this->systemManager->getSectorSystems($sector->getId()); + $bases = $this->orbitalBaseManager->getSectorBases($sector->getId()); + $scores = []; + + foreach ($bases as $base) + { + $player = $this->playerManager->get($base->rPlayer); + + $scores[$player->rColor] = + (!empty($scores[$player->rColor])) + ? $scores[$player->rColor] + $this->scores[$base->typeOfBase] + : $this->scores[$base->typeOfBase] + ; + } + // For each system, the owning faction gains two points + foreach ($systems as $system) { + if ($system->rColor === 0) { + continue; + } + $scores[$system->rColor] = (!empty($scores[$system->rColor])) ? $scores[$system->rColor] + 2 : 2; + } + $scores[0] = 0; + arsort($scores); + reset($scores); + + $this->redisManager->getConnection()->set('sector:' . $sector->getId(), serialize($scores)); + + return $scores; + } } \ No newline at end of file diff --git a/system/Modules/Gaia/Resource/config/config.yml b/system/Modules/Gaia/Resource/config/config.yml index 9fc04b0e2..3f777fc7f 100644 --- a/system/Modules/Gaia/Resource/config/config.yml +++ b/system/Modules/Gaia/Resource/config/config.yml @@ -39,6 +39,13 @@ services: class: Asylamba\Modules\Gaia\Manager\SectorManager arguments: - "@entity_manager" + - "@redis_manager" + - "@load_balancer" + - "@task_manager" + - "@athena.orbital_base_manager" + - "@zeus.player_manager" + - "@gaia.system_manager" + - "%gaia.scores" gaia.system_manager: class: Asylamba\Modules\Gaia\Manager\SystemManager @@ -53,10 +60,7 @@ services: arguments: - "@gaia.sector_manager" - "@gaia.system_manager" - - "@athena.orbital_base_manager" - - "@zeus.player_manager" - "@entity_manager" - - "%gaia.scores" - "%gaia.sector_minimal_score" tags: - {type: "event_listener", event: "gaia.place_owner_change", method: "onPlaceOwnerChange", order: 2} From 7469ca94e7053026a31b81be1f14125f500370bb Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 9 Aug 2017 22:29:37 +0200 Subject: [PATCH 12/14] Configure technical task to initialize sectors ownership data at server boot --- system/Classes/Task/TechnicalTask.php | 2 ++ system/Classes/Worker/Application.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/system/Classes/Task/TechnicalTask.php b/system/Classes/Task/TechnicalTask.php index 7daa7a368..bfe97c0ba 100644 --- a/system/Classes/Task/TechnicalTask.php +++ b/system/Classes/Task/TechnicalTask.php @@ -4,6 +4,8 @@ class TechnicalTask extends Task { + const DEFAULT_ESTIMATED_TIME = 10.00; + /** * {@inheritdoc} */ diff --git a/system/Classes/Worker/Application.php b/system/Classes/Worker/Application.php index 3a870a78b..199539125 100644 --- a/system/Classes/Worker/Application.php +++ b/system/Classes/Worker/Application.php @@ -90,6 +90,8 @@ public function init() $this->container->get('process_manager')->launchProcesses(); $this->container->get('realtime_action_scheduler')->init(); $this->container->get('cyclic_action_scheduler')->init(); + $this->container->get('gaia.sector_manager')->initOwnershipData(); + $server = $this->container->get('server'); $server->createHttpServer(); $server->listen(); From 4a1e97a9f7757e217400b309b1e3e84421076cb4 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 9 Aug 2017 22:29:53 +0200 Subject: [PATCH 13/14] Update tactical view in faction registry --- .../faction/data/tactical/sectors.php | 79 +++++++++---------- 1 file changed, 39 insertions(+), 40 deletions(-) diff --git a/system/views/components/faction/data/tactical/sectors.php b/system/views/components/faction/data/tactical/sectors.php index c99bd9848..ff0a04bf4 100755 --- a/system/views/components/faction/data/tactical/sectors.php +++ b/system/views/components/faction/data/tactical/sectors.php @@ -1,41 +1,14 @@ getContainer()->get('demeter.color_manager'); -$database = $this->getContainer()->get('database'); - -$qr = 'SELECT - se.id AS id, - se.rColor AS color, - se.name AS name, - se.points AS points, - (SELECT COUNT(sy.id) FROM system AS sy WHERE sy.rSector = se.id) AS nbc0,'; +$sectorManager = $this->getContainer()->get('gaia.sector_manager'); +$redisManager = $this->getContainer()->get('redis_manager'); +$sectors = $sectorManager->getAll(); $factions = $colorManager->getAll(); -foreach ($factions as $f) { - $qr .= '(SELECT COUNT(sy.id) FROM system AS sy WHERE sy.rColor = ' . $f->id . ' AND sy.rSector = se.id) AS nbc' . $f->id .','; -} - -$qr = substr($qr, 0, -1) . ' FROM sector AS se ORDER BY (nbc' . $faction->id . ' / nbc0) DESC'; - -$qr = $database->prepare($qr); -$qr->execute(); -$aw = $qr->fetchAll(); $qr->closeCursor(); - - -$sectort = array( - 'Secteurs conquis' => array(), - 'Secteurs en balance' => array() -); - -for ($i = 0; $i < count($aw); $i++) { - if ($aw[$i]['color'] == $faction->id) { - $sectort['Secteurs conquis'][] = $aw[$i]; - } else { - $sectort['Secteurs en balance'][] = $aw[$i]; - } -} echo '
'; echo '
'; @@ -43,29 +16,50 @@ echo '
'; echo '
'; echo '
'; - foreach ($sectort as $type => $sectors) { + foreach (['Secteurs conquis', 'Secteurs en balance'] as $type) { $displayed = 0; echo '

' . $type . '

'; echo '
    '; - foreach ($sectors as $sector) { - $percents = array(); + foreach ($sectors as $key => $sector) { + $treated = false; + $percents = ['color' . $faction->getId() => 0]; + $scores = unserialize($redisManager->getConnection()->get('sector:' . $sector->getId())); + + if (!isset($scores[$faction->getId()]) && $sector->getRColor() !== $faction->getId()) { + unset($sectors[$key]); + continue; + } + if ($type === 'Secteurs conquis' && $sector->getRColor() !== $faction->getId()) { + continue; + } foreach ($factions as $f) { - if ($f->id === 0) { + if ($f->id === 0 || !isset($scores[$f->id])) { continue; } - $percents['color' . $f->id] = Format::percent($sector['nbc' . $f->id], $sector['nbc0']); + $percents['color' . $f->id] = round(Format::percent($scores[$f->id], array_sum($scores), false)); } arsort($percents); - if ($sector['color'] == $faction->id || ($sector['nbc' . $faction->id] > 0)) { + if ($sector->getRColor() == $faction->getId() || ($scores[$faction->getId()] > 0)) { echo '
  • '; - echo '' . $sector['id'] . ''; - echo '' . $sector['name'] . ' (' . $sector['points'] . ' point' . Format::plural($sector['points']). ')'; - echo '' . Format::percent($sector['nbc' . $faction->id], $sector['nbc0']) . ' %'; + echo '' . $sector->getId() . ''; + echo '' . + $sector->getName() . + ' (' . $sector->getPoints() . ' point' . Format::plural($sector->getPoints()). ')' . + ''; + foreach ($scores as $factionId => $points) { + if ($points === 0) { + continue; + } + echo '' . + ColorResource::getInfo($factionId, 'popularName') . ' : ' . $points . ' point' . Format::plural($points) . ' de contrôle' . + ''; + } + echo '' . $percents['color' . $faction->getId()] . ' %'; echo ''; foreach ($percents as $color => $percent) { echo ''; @@ -74,7 +68,12 @@ echo '
  • '; $displayed++; + $treated = true; } + // If the sector has been displayed, we remove it for the second loop round + if ($treated === true) { + unset($sectors[$key]); + } } echo '
'; From 276633e076ba9c4b282be2460dd3f42553ca7013 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 9 Aug 2017 22:37:45 +0200 Subject: [PATCH 14/14] Release v2.1.2 --- CHANGELOG.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85c2d456d..21e95e644 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,15 @@ -## [2.1.1] - 2017-17-23 +## [2.1.2] - 2017-08-09 +### Added +- Storage of the sectors ownership data in Redis + +### Fixed +- Commanders defection when their base is taken +- Display of the incoming attacks in the admiralty +- Sectors ownership data in faction tactical registry +- Ending of recycling missions +- Conversion of the recycling places when there is no resources left + +## [2.1.1] - 2017-07-23 ### Added - Spy and combat active report highlighting in the list - Daily scheduling for notifications cleaning and inactive accounts management