From 0b718aa59d3f2eea31a088a307a25d27575f95ba Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 20 Aug 2025 14:26:30 +0200 Subject: [PATCH 1/3] Move game configuration in a dedicated folder --- config/{packages => game}/faction_bonuses.yaml | 0 config/{packages => game}/factions.yaml | 0 config/{packages => game}/ship_categories.yaml | 0 config/services.yaml | 4 ++++ 4 files changed, 4 insertions(+) rename config/{packages => game}/faction_bonuses.yaml (100%) rename config/{packages => game}/factions.yaml (100%) rename config/{packages => game}/ship_categories.yaml (100%) diff --git a/config/packages/faction_bonuses.yaml b/config/game/faction_bonuses.yaml similarity index 100% rename from config/packages/faction_bonuses.yaml rename to config/game/faction_bonuses.yaml diff --git a/config/packages/factions.yaml b/config/game/factions.yaml similarity index 100% rename from config/packages/factions.yaml rename to config/game/factions.yaml diff --git a/config/packages/ship_categories.yaml b/config/game/ship_categories.yaml similarity index 100% rename from config/packages/ship_categories.yaml rename to config/game/ship_categories.yaml diff --git a/config/services.yaml b/config/services.yaml index 46ff8fc68..9d2c00207 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -1,4 +1,8 @@ imports: + - { resource: ./game/faction_bonuses.yaml } + - { resource: ./game/factions.yaml } + - { resource: ./game/ship_categories.yaml } + - { resource: ../src/Modules/Ares/Resource/config/config.yml } - { resource: ../src/Modules/Artemis/Resource/config/config.yml } - { resource: ../src/Modules/Athena/Resource/config/config.yml } From 1f720c655a9aa1e4a635d1fdb9f7cbe933735b59 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 20 Aug 2025 15:50:25 +0200 Subject: [PATCH 2/3] Replace legacy SchoolClassResource class with a proper DI configuration --- config/game/commander_school.yaml | 5 ++ config/services.yaml | 1 + src/Kernel.php | 5 ++ .../Controller/CreateCommander.php | 68 +++++++++---------- .../CommanderSchoolConfiguration.php | 31 +++++++++ .../CommanderSchoolExtension.php | 33 +++++++++ .../Controller/Base/Building/ViewSchool.php | 7 +- .../Athena/Resource/SchoolClassResource.php | 55 --------------- 8 files changed, 111 insertions(+), 94 deletions(-) create mode 100644 config/game/commander_school.yaml create mode 100644 src/Modules/Ares/Infrastructure/DependencyInjection/CommanderSchoolConfiguration.php create mode 100644 src/Modules/Ares/Infrastructure/DependencyInjection/CommanderSchoolExtension.php delete mode 100644 src/Modules/Athena/Resource/SchoolClassResource.php diff --git a/config/game/commander_school.yaml b/config/game/commander_school.yaml new file mode 100644 index 000000000..cd3209740 --- /dev/null +++ b/config/game/commander_school.yaml @@ -0,0 +1,5 @@ +commander_school: + credits_cost: 2500 + minimum_experience: 100 + maximum_experience: 210 + points: 5 diff --git a/config/services.yaml b/config/services.yaml index 9d2c00207..0995273df 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -1,4 +1,5 @@ imports: + - { resource: ./game/commander_school.yaml } - { resource: ./game/faction_bonuses.yaml } - { resource: ./game/factions.yaml } - { resource: ./game/ship_categories.yaml } diff --git a/src/Kernel.php b/src/Kernel.php index 3c7f0384f..677823da0 100644 --- a/src/Kernel.php +++ b/src/Kernel.php @@ -2,6 +2,7 @@ namespace App; +use App\Modules\Ares\Infrastructure\DependencyInjection\CommanderSchoolExtension; use App\Modules\Ares\Infrastructure\DependencyInjection\ShipCategoryExtension; use App\Modules\Demeter\Infrastructure\DependencyInjection\FactionBonusExtension; use App\Modules\Demeter\Infrastructure\DependencyInjection\FactionExtension; @@ -17,6 +18,10 @@ protected function build(ContainerBuilder $container): void { parent::build($container); + $commanderSchoolExtension = new CommanderSchoolExtension(); + $container->registerExtension($commanderSchoolExtension); + $container->loadFromExtension($commanderSchoolExtension->getAlias()); + $factionExtension = new FactionExtension(); $container->registerExtension($factionExtension); $container->loadFromExtension($factionExtension->getAlias()); diff --git a/src/Modules/Ares/Infrastructure/Controller/CreateCommander.php b/src/Modules/Ares/Infrastructure/Controller/CreateCommander.php index 7ededd619..ede9760f0 100644 --- a/src/Modules/Ares/Infrastructure/Controller/CreateCommander.php +++ b/src/Modules/Ares/Infrastructure/Controller/CreateCommander.php @@ -2,19 +2,18 @@ namespace App\Modules\Ares\Infrastructure\Controller; -use App\Classes\Library\Format; use App\Modules\Ares\Application\Handler\CommanderExperienceHandler; use App\Modules\Ares\Domain\Event\Commander\NewCommanderEvent; use App\Modules\Ares\Domain\Repository\CommanderRepositoryInterface; use App\Modules\Ares\Model\Commander; use App\Modules\Athena\Model\OrbitalBase; -use App\Modules\Athena\Resource\SchoolClassResource; use App\Modules\Gaia\Resource\PlaceResource; use App\Modules\Zeus\Helper\CheckName; use App\Modules\Zeus\Manager\PlayerManager; use App\Modules\Zeus\Model\Player; use Psr\EventDispatcher\EventDispatcherInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; @@ -32,8 +31,13 @@ public function __invoke( CommanderRepositoryInterface $commanderRepository, PlayerManager $playerManager, EventDispatcherInterface $eventDispatcher, + #[Autowire('%app.commander_school.credits_cost%')] + int $creditsCost, + #[Autowire('%app.commander_school.minimum_experience%')] + int $minimumExperience, + #[Autowire('%app.commander_school.maximum_experience%')] + int $maximumExperience, ): Response { - $school = 0; $name = $request->request->get('name') ?? throw new BadRequestHttpException('Missing name'); $cn = new CheckName(); @@ -49,48 +53,40 @@ public function __invoke( if (count($reserveCommanders) >= OrbitalBase::MAXCOMMANDERINMESS) { throw new ConflictHttpException('Vous ne pouvez pas créer de nouveaux officiers si vous en avez déjà '.Orbitalbase::MAXCOMMANDERINMESS.' ou plus.'); } - $nbrCommandersToCreate = random_int(SchoolClassResource::getInfo($school, 'minSize'), SchoolClassResource::getInfo($school, 'maxSize')); - // TODO Replace with validator component if (!$cn->checkLength($name) || !$cn->checkChar($name)) { throw new BadRequestHttpException('le nom contient des caractères non autorisé ou trop de caractères.'); } // TODO Replace with specification - if (SchoolClassResource::getInfo($school, 'credit') > $currentPlayer->getCredits()) { + if ($creditsCost > $currentPlayer->getCredits()) { throw new AccessDeniedHttpException('vous n\'avez pas assez de crédit.'); } - // débit des crédits au joueur - $playerManager->decreaseCredit($currentPlayer, SchoolClassResource::getInfo($school, 'credit')); - for ($i = 0; $i < $nbrCommandersToCreate; ++$i) { - $newCommander = new Commander( - id: Uuid::v4(), - name: $name, - avatar: 't'.random_int(1, 21).'-c'.$currentPlayer->faction->identifier, - player: $currentPlayer, - base: $currentBase, - enlistedAt: new \DateTimeImmutable(), - sexe: 1, - age: random_int(40, 70), - updatedAt: new \DateTimeImmutable(), - ); - $commanderExperienceHandler->upExperience( - $newCommander, - random_int( - SchoolClassResource::getInfo($school, 'minExp'), - SchoolClassResource::getInfo($school, 'maxExp'), - ), - ); - $commanderRepository->save($newCommander); + $playerManager->decreaseCredit($currentPlayer, $creditsCost); - $eventDispatcher->dispatch(new NewCommanderEvent($newCommander, $currentPlayer)); - } - $this->addFlash('success', sprintf( - '%s commandant%s inscrit%s au programme d\'entraînement.', - $nbrCommandersToCreate, - Format::addPlural($nbrCommandersToCreate), - Format::addPlural($nbrCommandersToCreate), - )); + $newCommander = new Commander( + id: Uuid::v4(), + name: $name, + avatar: 't'.random_int(1, 21).'-c'.$currentPlayer->faction->identifier, + player: $currentPlayer, + base: $currentBase, + enlistedAt: new \DateTimeImmutable(), + sexe: 1, + age: random_int(40, 70), + updatedAt: new \DateTimeImmutable(), + ); + $commanderExperienceHandler->upExperience( + $newCommander, + random_int( + $minimumExperience, + $maximumExperience, + ), + ); + $commanderRepository->save($newCommander); + + $eventDispatcher->dispatch(new NewCommanderEvent($newCommander, $currentPlayer)); + + $this->addFlash('success', 'Commandant inscrit au programme d\'entraînement.'); return $this->redirectToRoute('school'); } diff --git a/src/Modules/Ares/Infrastructure/DependencyInjection/CommanderSchoolConfiguration.php b/src/Modules/Ares/Infrastructure/DependencyInjection/CommanderSchoolConfiguration.php new file mode 100644 index 000000000..c6ed6c9cc --- /dev/null +++ b/src/Modules/Ares/Infrastructure/DependencyInjection/CommanderSchoolConfiguration.php @@ -0,0 +1,31 @@ +getRootNode() + ->isRequired() + ->validate() + ->ifTrue(static fn ($values) => $values['maximum_experience'] <= $values['minimum_experience']) + ->thenInvalid('Maximum experience must be greater than minimum experience.') + ->end() + ->children() + ->integerNode('credits_cost')->min(0)->isRequired()->end() + ->integerNode('minimum_experience')->min(0)->isRequired()->end() + ->integerNode('maximum_experience')->min(0)->isRequired()->end() + ->integerNode('points')->min(0)->isRequired()->end() + ->end(); + + return $treeBuilder; + } +} diff --git a/src/Modules/Ares/Infrastructure/DependencyInjection/CommanderSchoolExtension.php b/src/Modules/Ares/Infrastructure/DependencyInjection/CommanderSchoolExtension.php new file mode 100644 index 000000000..89a0e800a --- /dev/null +++ b/src/Modules/Ares/Infrastructure/DependencyInjection/CommanderSchoolExtension.php @@ -0,0 +1,33 @@ +getConfiguration($configs, $container); + $config = $this->processConfiguration($configuration, $configs); + + $container->setParameter('app.commander_school.credits_cost', $config['credits_cost']); + $container->setParameter('app.commander_school.minimum_experience', $config['minimum_experience']); + $container->setParameter('app.commander_school.maximum_experience', $config['maximum_experience']); + $container->setParameter('app.commander_school.points', $config['points']); + } + + public function getAlias(): string + { + return 'commander_school'; + } + + public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface + { + return new CommanderSchoolConfiguration(); + } +} diff --git a/src/Modules/Athena/Infrastructure/Controller/Base/Building/ViewSchool.php b/src/Modules/Athena/Infrastructure/Controller/Base/Building/ViewSchool.php index a7dce76dc..954a44013 100644 --- a/src/Modules/Athena/Infrastructure/Controller/Base/Building/ViewSchool.php +++ b/src/Modules/Athena/Infrastructure/Controller/Base/Building/ViewSchool.php @@ -3,15 +3,14 @@ namespace App\Modules\Athena\Infrastructure\Controller\Base\Building; use App\Modules\Ares\Domain\Repository\CommanderRepositoryInterface; -use App\Modules\Ares\Manager\CommanderManager; use App\Modules\Ares\Model\Commander; use App\Modules\Athena\Model\OrbitalBase; -use App\Modules\Athena\Resource\SchoolClassResource; use App\Modules\Gaia\Resource\PlaceResource; use App\Modules\Zeus\Application\Registry\CurrentPlayerBonusRegistry; use App\Modules\Zeus\Helper\CheckName; use App\Modules\Zeus\Model\PlayerBonusId; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -22,6 +21,8 @@ public function __invoke( CurrentPlayerBonusRegistry $currentPlayerBonusRegistry, OrbitalBase $currentBase, CommanderRepositoryInterface $commanderRepository, + #[Autowire('%app.commander_school.credits_cost%')] + int $creditsCost, ): Response { $commanderInvestBonus = $currentPlayerBonusRegistry->getPlayerBonus()->bonuses->get(PlayerBonusId::COMMANDER_INVEST); @@ -41,7 +42,7 @@ public function __invoke( 'earned_experience' => $this->calculateEarnedExperience($invest), 'max_commanders_in_school' => PlaceResource::get($currentBase->typeOfBase, 'school-size'), 'random_name' => CheckName::randomize(), - 'commander_price' => SchoolClassResource::getInfo(0, 'credit'), + 'commander_price' => $creditsCost, 'commander_invest_bonus' => $commanderInvestBonus, ]); } diff --git a/src/Modules/Athena/Resource/SchoolClassResource.php b/src/Modules/Athena/Resource/SchoolClassResource.php deleted file mode 100644 index 233ba53ef..000000000 --- a/src/Modules/Athena/Resource/SchoolClassResource.php +++ /dev/null @@ -1,55 +0,0 @@ -> - */ - private static array $classes = [ - [ - 'credit' => 2500, - 'minSize' => 1, - 'maxSize' => 1, - 'minExp' => 100, - 'maxExp' => 210, - 'point' => 5, - 'title' => 'Engager un officier nul', - ], - [ - 'credit' => 2500, - 'minSize' => 1, - 'maxSize' => 1, - 'minExp' => 100, - 'maxExp' => 210, - 'point' => 5, - 'title' => 'Engager un officier nul', - ], - [ - 'credit' => 2500, - 'minSize' => 1, - 'maxSize' => 1, - 'minExp' => 100, - 'maxExp' => 210, - 'point' => 5, - 'title' => 'Engager un officier nul', - ], - ]; - - public static function getInfo(int $i, string $info): mixed - { - if (!in_array($info, ['credit', 'minSize', 'maxSize', 'minExp', 'maxExp', 'point', 'title'])) { - throw new \LogicException('info inconnue dans getInfo de SchoolClassResource'); - } - if ($i < self::size()) { - return self::$classes[$i][$info]; - } - return false; - } - - public static function size(): int - { - return count(self::$classes); - } -} From 31b2092c104de11f7f675f5031ad0e655839a956 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Thu, 21 Aug 2025 21:34:55 +0200 Subject: [PATCH 3/3] WIP --- config/services.yaml | 4 -- .../Event/Commander/AffectationEvent.php | 6 +-- .../Event/Commander/LineChangeEvent.php | 6 +-- .../Event/Commander/SchoolAssignmentEvent.php | 33 ++++++++++++ .../Event/Fleet/CancelledJourneyEvent.php | 41 ++++++++++++++ .../Ares/Domain/Event/Fleet/LootEvent.php | 10 ++-- .../Event/Fleet/PlannedColonizationEvent.php | 52 ++++++++++++++++++ .../Event/Fleet/PlannedConquestEvent.php | 53 +++++++++++++++++++ .../Domain/Event/Fleet/PlannedLootEvent.php | 11 ++-- .../Event/Fleet/SquadronUpdateEvent.php | 8 +-- .../Controller/Fleet/Cancel.php | 15 +++++- .../EventListener/MixpanelListener.php | 16 ++++-- 12 files changed, 227 insertions(+), 28 deletions(-) create mode 100644 src/Modules/Ares/Domain/Event/Commander/SchoolAssignmentEvent.php create mode 100644 src/Modules/Ares/Domain/Event/Fleet/CancelledJourneyEvent.php create mode 100644 src/Modules/Ares/Domain/Event/Fleet/PlannedColonizationEvent.php create mode 100644 src/Modules/Ares/Domain/Event/Fleet/PlannedConquestEvent.php diff --git a/config/services.yaml b/config/services.yaml index 0995273df..6dff4af4b 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -150,10 +150,6 @@ services: $password: '%env(default::REDIS_PASSWORD)%' $timeout: "%redis_timeout%" - App\Shared\Infrastructure\EventListener\MixpanelListener: - arguments: - $environment: '%kernel.environment%' - App\Modules\Travel\Domain\Service\CalculateTravelTime: App\Modules\Travel\Domain\Service\GetTravelDuration: diff --git a/src/Modules/Ares/Domain/Event/Commander/AffectationEvent.php b/src/Modules/Ares/Domain/Event/Commander/AffectationEvent.php index bcae2450e..204181a4b 100644 --- a/src/Modules/Ares/Domain/Event/Commander/AffectationEvent.php +++ b/src/Modules/Ares/Domain/Event/Commander/AffectationEvent.php @@ -7,11 +7,11 @@ use App\Modules\Zeus\Resource\TutorialResource; use App\Shared\Domain\Event\TutorialEvent; -class AffectationEvent implements TutorialEvent +readonly class AffectationEvent implements TutorialEvent { public function __construct( - public readonly Commander $commander, - public readonly Player $player, + public Commander $commander, + public Player $player, ) { } diff --git a/src/Modules/Ares/Domain/Event/Commander/LineChangeEvent.php b/src/Modules/Ares/Domain/Event/Commander/LineChangeEvent.php index 5396ec956..fcf1467b9 100644 --- a/src/Modules/Ares/Domain/Event/Commander/LineChangeEvent.php +++ b/src/Modules/Ares/Domain/Event/Commander/LineChangeEvent.php @@ -7,11 +7,11 @@ use App\Modules\Zeus\Resource\TutorialResource; use App\Shared\Domain\Event\TutorialEvent; -class LineChangeEvent implements TutorialEvent +readonly class LineChangeEvent implements TutorialEvent { public function __construct( - public readonly Commander $commander, - public readonly Player $player, + public Commander $commander, + public Player $player, ) { } diff --git a/src/Modules/Ares/Domain/Event/Commander/SchoolAssignmentEvent.php b/src/Modules/Ares/Domain/Event/Commander/SchoolAssignmentEvent.php new file mode 100644 index 000000000..06a5a7e1d --- /dev/null +++ b/src/Modules/Ares/Domain/Event/Commander/SchoolAssignmentEvent.php @@ -0,0 +1,33 @@ +commander->player->id; + } + + public function getTrackingEventName(): string + { + return 'School Assignment'; + } + + public function getTrackingData(): array + { + return [ + 'commander_id' => $this->commander->id, + 'base_id' => $this->commander->base->id, + ]; + } +} diff --git a/src/Modules/Ares/Domain/Event/Fleet/CancelledJourneyEvent.php b/src/Modules/Ares/Domain/Event/Fleet/CancelledJourneyEvent.php new file mode 100644 index 000000000..e1c47c000 --- /dev/null +++ b/src/Modules/Ares/Domain/Event/Fleet/CancelledJourneyEvent.php @@ -0,0 +1,41 @@ +commander->player->id; + } + + public function getTrackingEventName(): string + { + return 'Cancelled Journey'; + } + + public function getTrackingData(): array + { + return [ + 'commander_id' => $this->commander->id, + 'mission_type' => $this->mission->value, + 'start_place_id' => $this->commander->startPlace->id, + 'destination_place_id' => $this->commander->destinationPlace->id, + 'start_place_faction_identifier' => $this->commander->startPlace->base?->player->faction->identifier, + 'destination_place_faction_identifier' => $this->commander->destinationPlace->base?->player->faction->identifier, + ]; + } +} diff --git a/src/Modules/Ares/Domain/Event/Fleet/LootEvent.php b/src/Modules/Ares/Domain/Event/Fleet/LootEvent.php index 2f4dfa5a1..ac2095f14 100644 --- a/src/Modules/Ares/Domain/Event/Fleet/LootEvent.php +++ b/src/Modules/Ares/Domain/Event/Fleet/LootEvent.php @@ -6,11 +6,11 @@ use App\Modules\Zeus\Model\Player; use App\Shared\Domain\Event\TrackingEvent; -class LootEvent implements TrackingEvent +readonly class LootEvent implements TrackingEvent { public function __construct( - public readonly Commander $commander, - public readonly Player|null $defender, + public Commander $commander, + public Player|null $defender, ) { } @@ -28,8 +28,8 @@ public function getTrackingData(): array { return [ 'commander_id' => $this->commander->id, - 'origin_place_id' => $this->commander->startPlace, - 'target_place_id' => $this->commander->destinationPlace, + 'origin_place_id' => $this->commander->startPlace->id, + 'target_place_id' => $this->commander->destinationPlace->id, 'is_victorious' => $this->commander->isVictorious(), 'resources' => $this->commander->resources, 'defender_id' => $this->defender?->id, diff --git a/src/Modules/Ares/Domain/Event/Fleet/PlannedColonizationEvent.php b/src/Modules/Ares/Domain/Event/Fleet/PlannedColonizationEvent.php new file mode 100644 index 000000000..8a5adeef9 --- /dev/null +++ b/src/Modules/Ares/Domain/Event/Fleet/PlannedColonizationEvent.php @@ -0,0 +1,52 @@ +attacker; + } + + public function getTutorialStep(): int|null + { + return TutorialResource::LOOT_PLANET; + } + + public function getTrackingPeopleId(): int + { + return $this->attacker->id; + } + + public function getTrackingEventName(): string + { + return 'Planned Loot Mission'; + } + + public function getTrackingData(): array + { + return [ + 'start_place_id' => $this->commander->startPlace, + 'start_place_faction_identifier' => $this->commander->startPlace->base?->player->faction->identifier, + 'destination_place_id' => $this->commander->destinationPlace, + 'destination_place_player_id' => $this->commander->destinationPlace->base?->player->id, + 'destination_place_faction_identifier' => $this->commander->destinationPlace->base?->player->faction->identifier, + 'commander_id' => $this->commander->id, + ]; + } +} diff --git a/src/Modules/Ares/Domain/Event/Fleet/PlannedConquestEvent.php b/src/Modules/Ares/Domain/Event/Fleet/PlannedConquestEvent.php new file mode 100644 index 000000000..e33c87596 --- /dev/null +++ b/src/Modules/Ares/Domain/Event/Fleet/PlannedConquestEvent.php @@ -0,0 +1,53 @@ +attacker; + } + + public function getTutorialStep(): int|null + { + return TutorialResource::LOOT_PLANET; + } + + public function getTrackingPeopleId(): int + { + return $this->attacker->id; + } + + public function getTrackingEventName(): string + { + return 'Planned Loot Mission'; + } + + public function getTrackingData(): array + { + return [ + 'start_place_id' => $this->commander->startPlace, + 'start_place_faction_identifier' => $this->commander->startPlace->base?->player->faction->identifier, + 'destination_place_id' => $this->commander->destinationPlace, + 'destination_place_player_id' => $this->commander->destinationPlace->base?->player->id, + 'destination_place_faction_identifier' => $this->commander->destinationPlace->base?->player->faction->identifier, + 'commander_id' => $this->commander->id, + ]; + } +} diff --git a/src/Modules/Ares/Domain/Event/Fleet/PlannedLootEvent.php b/src/Modules/Ares/Domain/Event/Fleet/PlannedLootEvent.php index 130b1dd06..3a5eed12e 100644 --- a/src/Modules/Ares/Domain/Event/Fleet/PlannedLootEvent.php +++ b/src/Modules/Ares/Domain/Event/Fleet/PlannedLootEvent.php @@ -9,12 +9,12 @@ use App\Shared\Domain\Event\TrackingEvent; use App\Shared\Domain\Event\TutorialEvent; -class PlannedLootEvent implements TutorialEvent, TrackingEvent +readonly class PlannedLootEvent implements TutorialEvent, TrackingEvent { public function __construct( - public readonly Place $place, - public readonly Commander $commander, - public readonly Player $attacker, + public Place $place, + public Commander $commander, + public Player $attacker, ) { } @@ -42,7 +42,10 @@ public function getTrackingData(): array { return [ 'start_place_id' => $this->commander->startPlace, + 'start_place_faction_identifier' => $this->commander->startPlace->base?->player->faction->identifier, 'destination_place_id' => $this->commander->destinationPlace, + 'destination_place_player_id' => $this->commander->destinationPlace->base?->player->id, + 'destination_place_faction_identifier' => $this->commander->destinationPlace->base?->player->faction->identifier, 'commander_id' => $this->commander->id, ]; } diff --git a/src/Modules/Ares/Domain/Event/Fleet/SquadronUpdateEvent.php b/src/Modules/Ares/Domain/Event/Fleet/SquadronUpdateEvent.php index 49f7672c3..d8c72898d 100644 --- a/src/Modules/Ares/Domain/Event/Fleet/SquadronUpdateEvent.php +++ b/src/Modules/Ares/Domain/Event/Fleet/SquadronUpdateEvent.php @@ -8,12 +8,12 @@ use App\Modules\Zeus\Resource\TutorialResource; use App\Shared\Domain\Event\TutorialEvent; -class SquadronUpdateEvent implements TutorialEvent +readonly class SquadronUpdateEvent implements TutorialEvent { public function __construct( - public readonly Commander $commander, - public readonly Squadron $squadron, - public readonly Player $player, + public Commander $commander, + public Squadron $squadron, + public Player $player, ) { } diff --git a/src/Modules/Ares/Infrastructure/Controller/Fleet/Cancel.php b/src/Modules/Ares/Infrastructure/Controller/Fleet/Cancel.php index 36b873739..9fe2c1500 100644 --- a/src/Modules/Ares/Infrastructure/Controller/Fleet/Cancel.php +++ b/src/Modules/Ares/Infrastructure/Controller/Fleet/Cancel.php @@ -2,12 +2,16 @@ namespace App\Modules\Ares\Infrastructure\Controller\Fleet; +use App\Classes\Library\DateTimeConverter; +use App\Modules\Ares\Domain\Event\Fleet\CancelledJourneyEvent; use App\Modules\Ares\Domain\Model\CommanderMission; use App\Modules\Ares\Domain\Repository\CommanderRepositoryInterface; use App\Modules\Ares\Manager\CommanderManager; +use App\Modules\Ares\Message\CommanderTravelMessage; use App\Modules\Ares\Model\Commander; use App\Modules\Zeus\Model\Player; use App\Shared\Application\Handler\DurationHandler; +use Psr\EventDispatcher\EventDispatcherInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -24,6 +28,7 @@ public function __invoke( Player $currentPlayer, CommanderManager $commanderManager, CommanderRepositoryInterface $commanderRepository, + EventDispatcherInterface $eventDispatcher, Uuid $id, ): Response { $commander = $commanderRepository->get($id) ?? throw $this->createNotFoundException('Commander not found'); @@ -36,6 +41,7 @@ public function __invoke( } // @TODO travel cancellation // $scheduler->cancel($commander, $commander->dArrival); + $travelType = $commander->travelType; $interval = $durationHandler->getDiff($commander->getDepartureDate(), new \DateTimeImmutable()); $newArrivalDate = new \DateTimeImmutable(sprintf('-%d seconds', $interval)); @@ -50,11 +56,16 @@ public function __invoke( $this->addFlash('success', 'Déplacement annulé.'); $messageBus->dispatch( - new \App\Modules\Ares\Message\CommanderTravelMessage($commander->id), - [\App\Classes\Library\DateTimeConverter::to_delay_stamp($commander->getArrivalDate())], + new CommanderTravelMessage($commander->id), + [DateTimeConverter::to_delay_stamp($commander->getArrivalDate())], ); $commanderRepository->save($commander); + $eventDispatcher->dispatch(new CancelledJourneyEvent( + $commander, + $travelType, + )); + if ($request->query->has('redirect')) { return $this->redirectToRoute('map', ['place' => $request->query->get('redirect')]); } diff --git a/src/Shared/Infrastructure/EventListener/MixpanelListener.php b/src/Shared/Infrastructure/EventListener/MixpanelListener.php index 5e3f383d4..cd660ca29 100644 --- a/src/Shared/Infrastructure/EventListener/MixpanelListener.php +++ b/src/Shared/Infrastructure/EventListener/MixpanelListener.php @@ -3,19 +3,26 @@ namespace App\Shared\Infrastructure\EventListener; use App\Modules\Ares\Domain\Event\Commander\NewCommanderEvent; +use App\Modules\Ares\Domain\Event\Commander\SchoolAssignmentEvent; +use App\Modules\Ares\Domain\Event\Fleet\CancelledJourneyEvent; use App\Modules\Ares\Domain\Event\Fleet\LootEvent; +use App\Modules\Ares\Domain\Event\Fleet\PlannedLootEvent; use App\Modules\Artemis\Domain\Event\SpyEvent; use App\Modules\Athena\Domain\Event\NewBuildingQueueEvent; use App\Modules\Athena\Domain\Event\NewShipQueueEvent; use App\Modules\Promethee\Domain\Event\NewTechnologyQueueEvent; use App\Modules\Zeus\Domain\Event\PlayerConnectionEvent; use App\Shared\Domain\Event\TrackingEvent; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\EventDispatcher\Attribute\AsEventListener; -class MixpanelListener +readonly class MixpanelListener { - public function __construct(private readonly \Mixpanel $mixpanel, string $environment) - { + public function __construct( + private \Mixpanel $mixpanel, + #[Autowire('%kernel.environment%')] + string $environment, + ) { $this->mixpanel->register('environment', $environment); } @@ -33,7 +40,10 @@ public function onPlayerConnection(PlayerConnectionEvent $event): void #[AsEventListener(NewShipQueueEvent::class)] #[AsEventListener(NewTechnologyQueueEvent::class)] #[AsEventListener(NewCommanderEvent::class)] + #[AsEventListener(SchoolAssignmentEvent::class)] + #[AsEventListener(PlannedLootEvent::class)] #[AsEventListener(LootEvent::class)] + #[AsEventListener(CancelledJourneyEvent::class)] #[AsEventListener(PlayerConnectionEvent::class)] #[AsEventListener(SpyEvent::class)] public function onTrackingEvent(TrackingEvent $event): void