From dc5895b8635c7d53cc68ee20a0458dd09338e55a Mon Sep 17 00:00:00 2001 From: Stephan Vock Date: Wed, 24 Apr 2019 20:27:02 +0100 Subject: [PATCH] Fix: issue that would trigger multiple quests --- src/Guard/TriggerValidator.php | 2 +- src/Progress/ProgressHandler.php | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Guard/TriggerValidator.php b/src/Guard/TriggerValidator.php index 0b8878b..bb068ae 100644 --- a/src/Guard/TriggerValidator.php +++ b/src/Guard/TriggerValidator.php @@ -39,7 +39,7 @@ public function canTrigger(Quest $questData, Slot $slot, int $user): bool throw new \InvalidArgumentException('Invalid trigger handler provided. Can only use instances of: ' . InitProgressHandlerFunctionInterface::class); } - $this->questProgressHandler->initProgress($quest, $taskId, $handlerFunction); + $this->questProgressHandler->fetchInitialProgress($quest, $taskId, $handlerFunction); } return $questData->getTrigger()->isFinished($quest->getProgressMap()); diff --git a/src/Progress/ProgressHandler.php b/src/Progress/ProgressHandler.php index c44f84c..ddd1896 100644 --- a/src/Progress/ProgressHandler.php +++ b/src/Progress/ProgressHandler.php @@ -35,11 +35,16 @@ public function handle(QuestInterface $quest, int $taskId, callable $handler, Ev $this->questStorage->save($quest); } - public function initProgress(QuestInterface $quest, int $taskId, InitProgressHandlerFunctionInterface $handler): void + public function fetchInitialProgress(QuestInterface $quest, int $taskId, InitProgressHandlerFunctionInterface $handler): void { $task = $quest->getTask($taskId); $progress = $handler->initProgress($quest, $task); $task->updateProgress($progress); + } + + public function initProgress(QuestInterface $quest, int $taskId, InitProgressHandlerFunctionInterface $handler): void + { + $this->fetchInitialProgress($quest, $taskId, $handler); if ($this->worfkflow->can($quest, QuestDefinitionInterface::TRANSITION_COMPLETE)) { $this->worfkflow->apply($quest, QuestDefinitionInterface::TRANSITION_COMPLETE);