calculate XPs for Questgroups
This commit is contained in:
parent
e10d1d0650
commit
29cfdee59f
5 changed files with 112 additions and 7 deletions
|
|
@ -83,15 +83,26 @@
|
|||
// Get Questgroups
|
||||
$hierarchy['questgroups'] = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id'], $questgroup['id']);
|
||||
|
||||
// Check permission of Questgroups
|
||||
for($i=1; $i<count($hierarchy['questgroups']); $i++) {
|
||||
$hierarchy['questgroups'][$i]['access'] = $this->Questgroups->hasCharacterSolvedQuestgroup($hierarchy['questgroups'][$i-1]['id'], $character['id']);
|
||||
// Get additional data
|
||||
for($i=0; $i<count($hierarchy['questgroups']); $i++)
|
||||
{
|
||||
// Get Character XPs
|
||||
$hierarchy['questgroups'][$i]['character_xps'] = $this->Questgroups->getAchievedXPsForQuestgroup($hierarchy['questgroups'][$i]['id'], $character['id']);
|
||||
|
||||
// Check permission of Questgroups
|
||||
if($i >= 1) {
|
||||
$hierarchy['questgroups'][$i]['access'] = $this->Questgroups->hasCharacterSolvedQuestgroup($hierarchy['questgroups'][$i-1]['id'], $character['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get texts
|
||||
$questgroupTexts = $this->Questgroups->getQuestgroupTexts($questgroup['id']);
|
||||
|
||||
// Get Character XPs
|
||||
$questgroup['character_xps'] = $this->Questgroups->getAchievedXPsForQuestgroup($questgroup['id'], $character['id']);
|
||||
|
||||
|
||||
// Get Quests
|
||||
$quests = null;
|
||||
if(count($childQuestgroupshierarchy) == 0)
|
||||
|
|
|
|||
|
|
@ -111,6 +111,9 @@
|
|||
$hierarchy['questgroups'][$i]['text'] = $text;
|
||||
}
|
||||
|
||||
// Get Character XPs
|
||||
$hierarchy['questgroups'][$i]['character_xps'] = $this->Questgroups->getAchievedXPsForQuestgroup($hierarchy['questgroups'][$i]['id'], $character['id']);
|
||||
|
||||
// Check permission of Questgroups
|
||||
if($i >= 1) {
|
||||
$hierarchy['questgroups'][$i]['access'] = $this->Questgroups->hasCharacterSolvedQuestgroup($hierarchy['questgroups'][$i-1]['id'], $character['id']);
|
||||
|
|
|
|||
|
|
@ -49,9 +49,11 @@
|
|||
*/
|
||||
public function getQuestgroupsForHierarchy($hierarchyId, $parentQuestgroupId=null)
|
||||
{
|
||||
// Get Questgroups
|
||||
$questgroups = array();
|
||||
if(is_null($parentQuestgroupId))
|
||||
{
|
||||
return $this->db->query(
|
||||
$questgroups = $this->db->query(
|
||||
'SELECT id, questgroupshierarchy_id, pos, title, url '.
|
||||
'FROM questgroups '.
|
||||
'WHERE questgroups.questgroupshierarchy_id = ? AND parent_questgroup_id IS NULL '.
|
||||
|
|
@ -62,7 +64,7 @@
|
|||
}
|
||||
else
|
||||
{
|
||||
return $this->db->query(
|
||||
$questgroups = $this->db->query(
|
||||
'SELECT id, questgroupshierarchy_id, pos, title, url '.
|
||||
'FROM questgroups '.
|
||||
'WHERE questgroups.questgroupshierarchy_id = ? AND parent_questgroup_id = ? '.
|
||||
|
|
@ -71,6 +73,17 @@
|
|||
$hierarchyId, $parentQuestgroupId
|
||||
);
|
||||
}
|
||||
|
||||
// Add additional data
|
||||
foreach($questgroups as &$questgroup)
|
||||
{
|
||||
// Total XPs
|
||||
$questgroup['xps'] = $this->getAchievableXPsForQuestgroup($questgroup['id']);
|
||||
}
|
||||
|
||||
|
||||
// Return Questgroups
|
||||
return $questgroups;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -251,6 +264,84 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Summarize XPs of all Quests for a Questgroup and its
|
||||
* sub-Questgroups.
|
||||
*
|
||||
* @param int $questgroupId ID of Questgroup
|
||||
* @return Sum of XPs
|
||||
*/
|
||||
public function getAchievableXPsForQuestgroup($questgroupId)
|
||||
{
|
||||
// Sum of XPs
|
||||
$xps = 0;
|
||||
|
||||
// Current Questgroup
|
||||
$questgroup = $this->getQuestgroupById($questgroupId);
|
||||
|
||||
// Quests of current Questgroup
|
||||
$quests = $this->Quests->getMainquestsForQuestgroup($questgroup['id']);
|
||||
foreach($quests as &$quest) {
|
||||
$xps += $quest['xps'];
|
||||
}
|
||||
|
||||
// XPs of child Questgroups
|
||||
$childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroup['questgroupshierarchy_id']);
|
||||
foreach($childQuestgroupshierarchy as &$hierarchy)
|
||||
{
|
||||
$questgroups = $this->getQuestgroupsForHierarchy($hierarchy['id'], $questgroup['id']);
|
||||
foreach($questgroups as &$questgroup) {
|
||||
$xps += $this->getAchievableXPsForQuestgroup($questgroup['id']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Return summarized XPs
|
||||
return $xps;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Summarize XPs of all Quests for a Questgroup and its
|
||||
* sub-Questgroups solved by a Character.
|
||||
*
|
||||
* @param int $questgroupId ID of Questgroup
|
||||
* @param int $characterId ID of Character
|
||||
* @return Sum of XPs
|
||||
*/
|
||||
public function getAchievedXPsForQuestgroup($questgroupId, $characterId)
|
||||
{
|
||||
// Sum of XPs
|
||||
$xps = 0;
|
||||
|
||||
// Current Questgroup
|
||||
$questgroup = $this->getQuestgroupById($questgroupId);
|
||||
|
||||
// Quests of current Questgroup
|
||||
$quests = $this->Quests->getMainquestsForQuestgroup($questgroup['id']);
|
||||
foreach($quests as &$quest)
|
||||
{
|
||||
if($this->Quests->hasCharacterSolvedQuest($quest['id'], $characterId)) {
|
||||
$xps += $quest['xps'];
|
||||
}
|
||||
}
|
||||
|
||||
// XPs of child Questgroups
|
||||
$childQuestgroupshierarchy = $this->Questgroupshierarchy->getChildQuestgroupshierarchy($questgroup['questgroupshierarchy_id']);
|
||||
foreach($childQuestgroupshierarchy as &$hierarchy)
|
||||
{
|
||||
$questgroups = $this->getQuestgroupsForHierarchy($hierarchy['id'], $questgroup['id']);
|
||||
foreach($questgroups as &$questgroup) {
|
||||
$xps += $this->getAchievedXPsForQuestgroup($questgroup['id'], $characterId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Return summarized XPs
|
||||
return $xps;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
<div class="xpbar">
|
||||
<span style="width:25%"></span>
|
||||
</div>
|
||||
<p class="xpnumeric">50 / 200 XP</p>
|
||||
<p class="xpnumeric"><?=$group['character_xps']?> / <?=$group['xps']?> XP</p>
|
||||
</div>
|
||||
<div class="qghidden">
|
||||
<p>Versteckte Questline gefunden:</p>
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
<div class="xpbar">
|
||||
<span style="width:25%"></span>
|
||||
</div>
|
||||
<p class="xpnumeric">350 / 450 XP</p>
|
||||
<p class="xpnumeric"><?=$group['character_xps']?> / <?=$group['xps']?> XP</p>
|
||||
</div>
|
||||
<?php if(array_key_exists('text', $group)) : ?>
|
||||
<p><?=$group['text']?></p>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue