implement Achievements
This commit is contained in:
parent
396c61586c
commit
4153b526e6
11 changed files with 914 additions and 39 deletions
162
controllers/AchievementsController.inc
Normal file
162
controllers/AchievementsController.inc
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* The Legend of Z
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
|
||||
* @license http://www.gnu.org/licenses/gpl.html
|
||||
* @link https://bitbucket.org/coderkun/the-legend-of-z
|
||||
*/
|
||||
|
||||
namespace hhu\z\controllers;
|
||||
|
||||
|
||||
/**
|
||||
* Controller of the Agent to list Achievements.
|
||||
*
|
||||
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
|
||||
*/
|
||||
class AchievementsController extends \hhu\z\controllers\SeminaryRoleController
|
||||
{
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('achievements', 'seminaries', 'media');
|
||||
/**
|
||||
* User permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $permissions = array(
|
||||
'index' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
/**
|
||||
* User seminary permissions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $seminaryPermissions = array(
|
||||
'index' => array('admin', 'moderator', 'user')
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Action: index.
|
||||
*
|
||||
* List Achievements of a Seminary.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-Title of Seminary
|
||||
*/
|
||||
public function index($seminaryUrl)
|
||||
{
|
||||
// Get Seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Character
|
||||
$character = IntermediateController::$character;
|
||||
|
||||
// Get Achievements
|
||||
$achievements = $this->Achievements->getAchievementsForSeminary($seminary['id']);
|
||||
foreach($achievements as &$achievement)
|
||||
{
|
||||
// Get status for Character
|
||||
$achieved = $this->Achievements->hasCharacterAchievedAchievement($achievement['id'], $character['id']);
|
||||
|
||||
// Get Character progress
|
||||
if(!$achieved && $achievement['progress'])
|
||||
{
|
||||
$conditions = array();
|
||||
switch($achievement['condition'])
|
||||
{
|
||||
// Character conditions
|
||||
case 'character':
|
||||
$conditionsCharacter = $this->Achievements->getAchievementConditionsCharacter($achievement['id']);
|
||||
foreach($conditionsCharacter as &$condition)
|
||||
{
|
||||
$conditions[] = array(
|
||||
'func' => 'getAchievementConditionCharacterProgress',
|
||||
'params' => array(
|
||||
$condition['field'],
|
||||
$condition['value'],
|
||||
$character['id']
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
// Quest conditions
|
||||
case 'quest':
|
||||
$conditionsQuest = $this->Achievements->getAchievementConditionsQuest($achievement['id']);
|
||||
foreach($conditionsQuest as &$condition)
|
||||
{
|
||||
$conditions[] = array(
|
||||
'func' => 'getAchievementConditionQuestProgress',
|
||||
'params' => array(
|
||||
$condition['field'],
|
||||
$condition['count'],
|
||||
$condition['value'],
|
||||
$condition['status'],
|
||||
$condition['groupby'],
|
||||
$condition['quest_id'],
|
||||
$character['id']
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
// Achievement conditions
|
||||
case 'achievement':
|
||||
$conditionsAchievement = $this->Achievements->getAchievementConditionsAchievement($achievement['id']);
|
||||
foreach($conditionsAchievement as &$condition)
|
||||
{
|
||||
$conditions[] = array(
|
||||
'func' => 'getAchievementConditionAchievementProgress',
|
||||
'params' => array(
|
||||
$condition['field'],
|
||||
$condition['count'],
|
||||
$condition['value'],
|
||||
$condition['groupby'],
|
||||
$condition['meta_achievement_id'],
|
||||
$character['id']
|
||||
)
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$characterProgresses = array();
|
||||
foreach($conditions as &$condition)
|
||||
{
|
||||
// Calculate progress of condition
|
||||
$characterProgresses[] = call_user_func_array(
|
||||
array(
|
||||
$this->Achievements,
|
||||
$condition['func']
|
||||
),
|
||||
$condition['params']
|
||||
);
|
||||
}
|
||||
|
||||
$achievement['characterProgress'] = array_sum($characterProgresses) / count($characterProgresses);
|
||||
}
|
||||
|
||||
// Get media
|
||||
$achievement['media_index'] = 'unachieved_achievementsmedia_id';
|
||||
if($achieved) {
|
||||
$achievement['media_index'] = 'achieved_achievementsmedia_id';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('achievements', $achievements);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -120,6 +120,9 @@
|
|||
// Get Character groups
|
||||
$groups = $this->Charactergroups->getGroupsForCharacter($character['id']);
|
||||
|
||||
// Get Achievements
|
||||
$achievements = $this->Achievements->getAchievedAchievementsForCharacter($character['id']);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
|
|
@ -127,6 +130,7 @@
|
|||
$this->set('characterfields', $characterfields);
|
||||
$this->set('user', $user);
|
||||
$this->set('groups', $groups);
|
||||
$this->set('achievements', $achievements);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
'index' => array('admin', 'moderator', 'user', 'guest'),
|
||||
'seminaryheader' => array('admin', 'moderator', 'user', 'guest'),
|
||||
'seminary' => array('admin', 'moderator', 'user', 'guest'),
|
||||
'avatar' => array('admin', 'moderator', 'user')
|
||||
'achievement' => array('admin', 'moderator', 'user', 'guest')
|
||||
);
|
||||
/**
|
||||
* User seminary permissions
|
||||
|
|
@ -36,14 +36,15 @@
|
|||
* @var array
|
||||
*/
|
||||
public $seminaryPermissions = array(
|
||||
'seminary' => array('admin', 'moderator', 'user', 'guest')
|
||||
'seminary' => array('admin', 'moderator', 'user', 'guest'),
|
||||
'achievement' => array('admin', 'moderator', 'user', 'guest')
|
||||
);
|
||||
/**
|
||||
* Required models
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('seminaries', 'media');
|
||||
public $models = array('seminaries', 'achievements', 'media');
|
||||
|
||||
|
||||
|
||||
|
|
@ -153,6 +154,53 @@
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Action: achievement
|
||||
*
|
||||
* Display the achievement of a Seminary.
|
||||
*
|
||||
* @throws IdNotFoundException
|
||||
* @param string $seminaryUrl URL-title of the Seminary
|
||||
* @param string $achievementUrl URL-title of the Achievement
|
||||
* @param string $action Action for processing the media
|
||||
*/
|
||||
public function achievement($seminaryUrl, $achievementUrl)
|
||||
{
|
||||
// Get Seminary
|
||||
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
|
||||
|
||||
// Get Character
|
||||
$character = IntermediateController::$character;
|
||||
|
||||
// Get Achievement
|
||||
$achievement = $this->Achievements->getAchievementByUrl($seminary['id'], $achievementUrl);
|
||||
|
||||
// Get media
|
||||
$index = '';
|
||||
if(is_null($character) || !$this->Achievements->hasCharacterAchievedAchievement($achievement['id'], $character['id'])) {
|
||||
$index = 'unachieved_achievementsmedia_id';
|
||||
}
|
||||
else {
|
||||
$index = 'achieved_achievementsmedia_id';
|
||||
}
|
||||
if(is_null($achievement[$index])) {
|
||||
throw new \nre\exceptions\IdNotFoundException($achievementUrl);
|
||||
}
|
||||
$media = $this->Media->getSeminaryMediaById($achievement[$index]);
|
||||
|
||||
// Get file
|
||||
$file = $this->getMediaFile($media, null);
|
||||
if(is_null($file)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('media', $media);
|
||||
$this->set('file', $file);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public $models = array('characters', 'quests', 'questgroups');
|
||||
public $models = array('characters', 'quests', 'questgroups', 'achievements');
|
||||
|
||||
|
||||
|
||||
|
|
@ -53,11 +53,16 @@
|
|||
$lastQuest['questgroup'] = $this->Questgroups->getQuestgroupById($lastQuest['questgroup_id']);
|
||||
}
|
||||
|
||||
// Get last achieved Achievement
|
||||
$achievements = $this->Achievements->getAchievedAchievementsForCharacter($character['id']);
|
||||
$lastAchievement = array_shift($achievements);
|
||||
|
||||
|
||||
// Pass data to view
|
||||
$this->set('seminary', $seminary);
|
||||
$this->set('character', $character);
|
||||
$this->set('lastQuest', $lastQuest);
|
||||
$this->set('lastAchievement', $lastAchievement);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue