only check last Quest(s) of a Questgroup for determining if Character has solved this Questgroup
This commit is contained in:
parent
775c93947f
commit
beb165c192
2 changed files with 35 additions and 31 deletions
|
|
@ -318,8 +318,7 @@
|
|||
|
||||
|
||||
/**
|
||||
* Determine if the given Character has solved the Quests form
|
||||
* this Questgroup.
|
||||
* Determine if the given Character has solved a Questgroup.
|
||||
*
|
||||
* @param int $questgroupId ID of Questgroup to check
|
||||
* @param int $characterId ID of Character to check
|
||||
|
|
@ -330,39 +329,20 @@
|
|||
// Get data of Questgroup
|
||||
$questgroup = $this->getQuestgroupById($questgroupId);
|
||||
|
||||
// Chack all Quests
|
||||
$currentQuest = $this->Quests->getFirstQuestOfQuestgroup($questgroup['id']);
|
||||
if(!is_null($currentQuest))
|
||||
// Check last Quest(s)
|
||||
$solvedLastQuest = false;
|
||||
$lastQuests = $this->Quests->getLastQuestsOfQuestgroup($questgroup['id']);
|
||||
foreach($lastQuests as &$lastQuest)
|
||||
{
|
||||
if(!$this->Quests->hasCharacterSolvedQuest($currentQuest['id'], $characterId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get next Quests
|
||||
$nextQuests = !is_null($currentQuest) ? $this->Quests->getNextQuests($currentQuest['id']) : null;
|
||||
while(!is_null($currentQuest) && !empty($nextQuests))
|
||||
if($this->Quests->hasCharacterSolvedQuest($lastQuest['id'], $characterId))
|
||||
{
|
||||
// Get choosed Quest
|
||||
$currentQuest = null;
|
||||
foreach($nextQuests as &$nextQuest) {
|
||||
if($this->Quests->hasCharacterEnteredQuest($nextQuest['id'], $characterId)) {
|
||||
$currentQuest = $nextQuest;
|
||||
}
|
||||
}
|
||||
|
||||
// Check Quest
|
||||
if(is_null($currentQuest)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check status
|
||||
if(!$this->Quests->hasCharacterSolvedQuest($currentQuest['id'], $characterId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$nextQuests = !is_null($currentQuest) ? $this->Quests->getNextQuests($currentQuest['id']) : null;
|
||||
$solvedLastQuest = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!$solvedLastQuest) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check all child Questgroups
|
||||
$questgroup['hierarchy'] = $this->Questgroupshierarchy->getHierarchyForQuestgroup($questgroup['id']);
|
||||
|
|
|
|||
|
|
@ -137,6 +137,29 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Quests a Qusetgroup that do not have a following
|
||||
* Quest.
|
||||
*
|
||||
* @param int $questId ID of Questgroup
|
||||
* @return array List of last Quests
|
||||
*/
|
||||
public function getLastQuestsOfQuestgroup($questgroupId)
|
||||
{
|
||||
return $this->db->query(
|
||||
'SELECT id, questtype_id, title, url, xps, task '.
|
||||
'FROM quests '.
|
||||
'WHERE questgroup_id = ? AND NOT EXISTS ('.
|
||||
'SELECT quest_id '.
|
||||
'FROM quests_previousquests '.
|
||||
'WHERE quests_previousquests.previous_quest_id = quests.id'.
|
||||
')',
|
||||
'i',
|
||||
$questgroupId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Quests that follow-up a Quest.
|
||||
*
|
||||
|
|
@ -243,6 +266,7 @@
|
|||
$characterId,
|
||||
self::QUEST_STATUS_ENTERED, self::QUEST_STATUS_SOLVED, self::QUEST_STATUS_UNSOLVED
|
||||
);
|
||||
//debug_print_backtrace();
|
||||
|
||||
|
||||
return (!empty($count) && intval($count[0]['c']) > 0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue