Skip to content

Commit

Permalink
Fix: issue that would trigger multiple quests
Browse files Browse the repository at this point in the history
  • Loading branch information
glaubinix committed Apr 24, 2019
1 parent f6a9e36 commit dc5895b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Guard/TriggerValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
7 changes: 6 additions & 1 deletion src/Progress/ProgressHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit dc5895b

Please sign in to comment.