mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
v3 client: fix casting spells
This commit is contained in:
@@ -199,7 +199,7 @@ User (prototype wrapper to give it ops, helper funcs, and virtuals
|
||||
|
||||
/*
|
||||
User is now wrapped (both on client and server), adding a few new properties:
|
||||
* getters (_statsComputed, tasks, etc)
|
||||
* getters (_statsComputed)
|
||||
* user.fns, which is a bunch of helper functions
|
||||
These were originally up above, but they make more sense belonging to the user object so we don't have to pass
|
||||
the user object all over the place. In fact, we should pull in more functions such as cron(), updateStats(), etc.
|
||||
|
||||
@@ -281,29 +281,47 @@ habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$
|
||||
.then(function (party) {
|
||||
party = (_.isArray(party) ? party : []).concat(User.user);
|
||||
$scope.castEnd(party, 'party');
|
||||
})
|
||||
.catch(function (party) { // not in a party, act as a solo party
|
||||
if (party && party.type === 'party') {
|
||||
party = [User.user];
|
||||
$scope.castEnd(party, 'party');
|
||||
}
|
||||
});
|
||||
} else if (spell.target == 'tasks') {
|
||||
var tasks = User.user.habits.concat(User.user.dailys).concat(User.user.rewards);
|
||||
// exclude challenge tasks
|
||||
tasks = tasks.filter(function (t) {
|
||||
if (!t.challenge) return true;
|
||||
return (!task.challenge.id || task.challenge.broken);
|
||||
});
|
||||
$scope.castEnd(tasks, 'tasks');
|
||||
}
|
||||
}
|
||||
|
||||
$scope.castEnd = function(target, type, $event){
|
||||
if (!$rootScope.applyingAction) return 'No applying action';
|
||||
$event && ($event.stopPropagation(),$event.preventDefault());
|
||||
|
||||
if ($scope.spell.target != type) return Notification.text(window.env.t('invalidTarget'));
|
||||
$scope.spell.cast(User.user, target);
|
||||
User.save();
|
||||
|
||||
var spell = $scope.spell;
|
||||
var targetId = target._id;
|
||||
var targetId = target ? target._id : null;
|
||||
$scope.spell = null;
|
||||
$rootScope.applyingAction = false;
|
||||
|
||||
$http.post(ApiUrl.get() + '/api/v3/user/class/cast/'+spell.key+'?targetType='+type+'&targetId='+targetId)
|
||||
var spellUrl = ApiUrl.get() + '/api/v3/user/class/cast/' + spell.key;
|
||||
if (targetId) spellUrl += '?targetId=' + targetId;
|
||||
|
||||
$http.post(spellUrl)
|
||||
.success(function(){
|
||||
var msg = window.env.t('youCast', {spell: spell.text()});
|
||||
switch (type) {
|
||||
case 'task': msg = window.env.t('youCastTarget', {spell: spell.text(), target: target.text});break;
|
||||
case 'user': msg = window.env.t('youCastTarget', {spell: spell.text(), target: target.profile.name});break;
|
||||
case 'party': msg = window.env.t('youCastParty', {spell: spell.text()});break;
|
||||
case 'task': msg = window.env.t('youCastTarget', {spell: spell.text(), target: target.text});break;
|
||||
case 'user': msg = window.env.t('youCastTarget', {spell: spell.text(), target: target.profile.name});break;
|
||||
case 'party': msg = window.env.t('youCastParty', {spell: spell.text()});break;
|
||||
}
|
||||
Notification.markdown(msg);
|
||||
User.sync();
|
||||
|
||||
@@ -365,13 +365,12 @@ api.castSpell = {
|
||||
spell.cast(user, null, req);
|
||||
await user.save();
|
||||
res.respond(200, user);
|
||||
} else if (targetType === 'tasks') { // new target type when all the user's tasks are necessary
|
||||
} else if (targetType === 'tasks') { // new target type in v3: when all the user's tasks are necessary
|
||||
let tasks = await Tasks.Task.find({
|
||||
userId: user._id,
|
||||
'challenge.id': {$exists: false}, // exclude challenge tasks
|
||||
$or: [ // Exclude completed todos
|
||||
{type: 'todo', completed: false},
|
||||
{type: {$in: ['habit', 'daily', 'reward']}},
|
||||
$or: [ // exclude challenge tasks
|
||||
{'challenge.id': {$exists: false}},
|
||||
{'challenge.broken': {$exists: true}},
|
||||
],
|
||||
}).exec();
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ export function cron (options = {}) {
|
||||
task.completed = false;
|
||||
|
||||
if (completed || scheduleMisses > 0) {
|
||||
task.checklist.forEach(i => i.completed = false); // FIXME this should not happen for grey tasks unless they are completed
|
||||
task.checklist.forEach(i => i.completed = false); // TODO this should not happen for grey tasks unless they are completed
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ export function preenHistory (history, isSubscribed, timezoneOffset) {
|
||||
return newHistory;
|
||||
}
|
||||
|
||||
// Preen history for users and tasks. This code runs only on the server.
|
||||
// Preen history for users and tasks.
|
||||
export function preenUserHistory (user, tasksByType) {
|
||||
let isSubscribed = user.isSubscribed();
|
||||
let timezoneOffset = user.preferences.timezoneOffset;
|
||||
|
||||
Reference in New Issue
Block a user