Files
habitica/website/server/controllers/api-v3/world.js
2018-03-20 21:30:43 +00:00

47 lines
1.4 KiB
JavaScript

import {
model as Group,
TAVERN_ID as tavernId,
} from '../../models/group';
let api = {};
async function getWorldBoss () {
let tavern = await Group
.findById(tavernId)
.select('quest.progress quest.key quest.active quest.extra')
.exec();
if (tavern && tavern.quest && tavern.quest.active) {
return tavern.quest;
}
return {};
}
/**
* @api {get} /api/v3/world-state Get the state for the game world
* @apiDescription Does not require authentication.
* @apiName WorldStateGet
* @apiGroup WorldState
*
* @apiSuccess {Object} data.worldBoss.active Boolean, true if world boss quest is underway
* @apiSuccess {Object} data.worldBoss.extra.worldDmg Object with NPC names as Boolean properties, true if they are affected by Rage Strike
* @apiSuccess {Object} data.worldBoss.key String, Quest content key for the world boss
* @apiSuccess {Object} data.worldBoss.progress.hp Number, Current Health of the world boss
* @apiSuccess {Object} data.worldBoss.progress.rage Number, Current Rage of the world boss
* @apiSuccess {Object} data.npcImageSuffix String, trailing component of NPC image filenames
*
*/
api.getWorldState = {
method: 'GET',
url: '/world-state',
async handler (req, res) {
let worldState = {};
worldState.worldBoss = await getWorldBoss();
worldState.npcImageSuffix = 'spring';
res.respond(200, worldState);
},
};
module.exports = api;