calculate XPs for Questgroups
This commit is contained in:
parent
def8b192e1
commit
3307df0789
5 changed files with 112 additions and 7 deletions
|
|
@ -83,15 +83,26 @@
|
||||||
// Get Questgroups
|
// Get Questgroups
|
||||||
$hierarchy['questgroups'] = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id'], $questgroup['id']);
|
$hierarchy['questgroups'] = $this->Questgroups->getQuestgroupsForHierarchy($hierarchy['id'], $questgroup['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
|
// Check permission of Questgroups
|
||||||
for($i=1; $i<count($hierarchy['questgroups']); $i++) {
|
if($i >= 1) {
|
||||||
$hierarchy['questgroups'][$i]['access'] = $this->Questgroups->hasCharacterSolvedQuestgroup($hierarchy['questgroups'][$i-1]['id'], $character['id']);
|
$hierarchy['questgroups'][$i]['access'] = $this->Questgroups->hasCharacterSolvedQuestgroup($hierarchy['questgroups'][$i-1]['id'], $character['id']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get texts
|
// Get texts
|
||||||
$questgroupTexts = $this->Questgroups->getQuestgroupTexts($questgroup['id']);
|
$questgroupTexts = $this->Questgroups->getQuestgroupTexts($questgroup['id']);
|
||||||
|
|
||||||
|
// Get Character XPs
|
||||||
|
$questgroup['character_xps'] = $this->Questgroups->getAchievedXPsForQuestgroup($questgroup['id'], $character['id']);
|
||||||
|
|
||||||
|
|
||||||
// Get Quests
|
// Get Quests
|
||||||
$quests = null;
|
$quests = null;
|
||||||
if(count($childQuestgroupshierarchy) == 0)
|
if(count($childQuestgroupshierarchy) == 0)
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,9 @@
|
||||||
$hierarchy['questgroups'][$i]['text'] = $text;
|
$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
|
// Check permission of Questgroups
|
||||||
if($i >= 1) {
|
if($i >= 1) {
|
||||||
$hierarchy['questgroups'][$i]['access'] = $this->Questgroups->hasCharacterSolvedQuestgroup($hierarchy['questgroups'][$i-1]['id'], $character['id']);
|
$hierarchy['questgroups'][$i]['access'] = $this->Questgroups->hasCharacterSolvedQuestgroup($hierarchy['questgroups'][$i-1]['id'], $character['id']);
|
||||||
|
|
|
||||||
|
|
@ -49,9 +49,11 @@
|
||||||
*/
|
*/
|
||||||
public function getQuestgroupsForHierarchy($hierarchyId, $parentQuestgroupId=null)
|
public function getQuestgroupsForHierarchy($hierarchyId, $parentQuestgroupId=null)
|
||||||
{
|
{
|
||||||
|
// Get Questgroups
|
||||||
|
$questgroups = array();
|
||||||
if(is_null($parentQuestgroupId))
|
if(is_null($parentQuestgroupId))
|
||||||
{
|
{
|
||||||
return $this->db->query(
|
$questgroups = $this->db->query(
|
||||||
'SELECT id, questgroupshierarchy_id, pos, title, url '.
|
'SELECT id, questgroupshierarchy_id, pos, title, url '.
|
||||||
'FROM questgroups '.
|
'FROM questgroups '.
|
||||||
'WHERE questgroups.questgroupshierarchy_id = ? AND parent_questgroup_id IS NULL '.
|
'WHERE questgroups.questgroupshierarchy_id = ? AND parent_questgroup_id IS NULL '.
|
||||||
|
|
@ -62,7 +64,7 @@
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return $this->db->query(
|
$questgroups = $this->db->query(
|
||||||
'SELECT id, questgroupshierarchy_id, pos, title, url '.
|
'SELECT id, questgroupshierarchy_id, pos, title, url '.
|
||||||
'FROM questgroups '.
|
'FROM questgroups '.
|
||||||
'WHERE questgroups.questgroupshierarchy_id = ? AND parent_questgroup_id = ? '.
|
'WHERE questgroups.questgroupshierarchy_id = ? AND parent_questgroup_id = ? '.
|
||||||
|
|
@ -71,6 +73,17 @@
|
||||||
$hierarchyId, $parentQuestgroupId
|
$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">
|
<div class="xpbar">
|
||||||
<span style="width:25%"></span>
|
<span style="width:25%"></span>
|
||||||
</div>
|
</div>
|
||||||
<p class="xpnumeric">50 / 200 XP</p>
|
<p class="xpnumeric"><?=$group['character_xps']?> / <?=$group['xps']?> XP</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="qghidden">
|
<div class="qghidden">
|
||||||
<p>Versteckte Questline gefunden:</p>
|
<p>Versteckte Questline gefunden:</p>
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
<div class="xpbar">
|
<div class="xpbar">
|
||||||
<span style="width:25%"></span>
|
<span style="width:25%"></span>
|
||||||
</div>
|
</div>
|
||||||
<p class="xpnumeric">350 / 450 XP</p>
|
<p class="xpnumeric"><?=$group['character_xps']?> / <?=$group['xps']?> XP</p>
|
||||||
</div>
|
</div>
|
||||||
<?php if(array_key_exists('text', $group)) : ?>
|
<?php if(array_key_exists('text', $group)) : ?>
|
||||||
<p><?=$group['text']?></p>
|
<p><?=$group['text']?></p>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue