mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +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:
|
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
|
* 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
|
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.
|
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) {
|
.then(function (party) {
|
||||||
party = (_.isArray(party) ? party : []).concat(User.user);
|
party = (_.isArray(party) ? party : []).concat(User.user);
|
||||||
$scope.castEnd(party, 'party');
|
$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){
|
$scope.castEnd = function(target, type, $event){
|
||||||
if (!$rootScope.applyingAction) return 'No applying action';
|
if (!$rootScope.applyingAction) return 'No applying action';
|
||||||
$event && ($event.stopPropagation(),$event.preventDefault());
|
$event && ($event.stopPropagation(),$event.preventDefault());
|
||||||
|
|
||||||
if ($scope.spell.target != type) return Notification.text(window.env.t('invalidTarget'));
|
if ($scope.spell.target != type) return Notification.text(window.env.t('invalidTarget'));
|
||||||
$scope.spell.cast(User.user, target);
|
$scope.spell.cast(User.user, target);
|
||||||
User.save();
|
User.save();
|
||||||
|
|
||||||
var spell = $scope.spell;
|
var spell = $scope.spell;
|
||||||
var targetId = target._id;
|
var targetId = target ? target._id : null;
|
||||||
$scope.spell = null;
|
$scope.spell = null;
|
||||||
$rootScope.applyingAction = false;
|
$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(){
|
.success(function(){
|
||||||
var msg = window.env.t('youCast', {spell: spell.text()});
|
var msg = window.env.t('youCast', {spell: spell.text()});
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'task': msg = window.env.t('youCastTarget', {spell: spell.text(), target: target.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 '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 'party': msg = window.env.t('youCastParty', {spell: spell.text()});break;
|
||||||
}
|
}
|
||||||
Notification.markdown(msg);
|
Notification.markdown(msg);
|
||||||
User.sync();
|
User.sync();
|
||||||
|
|||||||
@@ -365,13 +365,12 @@ api.castSpell = {
|
|||||||
spell.cast(user, null, req);
|
spell.cast(user, null, req);
|
||||||
await user.save();
|
await user.save();
|
||||||
res.respond(200, user);
|
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({
|
let tasks = await Tasks.Task.find({
|
||||||
userId: user._id,
|
userId: user._id,
|
||||||
'challenge.id': {$exists: false}, // exclude challenge tasks
|
$or: [ // exclude challenge tasks
|
||||||
$or: [ // Exclude completed todos
|
{'challenge.id': {$exists: false}},
|
||||||
{type: 'todo', completed: false},
|
{'challenge.broken': {$exists: true}},
|
||||||
{type: {$in: ['habit', 'daily', 'reward']}},
|
|
||||||
],
|
],
|
||||||
}).exec();
|
}).exec();
|
||||||
|
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ export function cron (options = {}) {
|
|||||||
task.completed = false;
|
task.completed = false;
|
||||||
|
|
||||||
if (completed || scheduleMisses > 0) {
|
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;
|
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) {
|
export function preenUserHistory (user, tasksByType) {
|
||||||
let isSubscribed = user.isSubscribed();
|
let isSubscribed = user.isSubscribed();
|
||||||
let timezoneOffset = user.preferences.timezoneOffset;
|
let timezoneOffset = user.preferences.timezoneOffset;
|
||||||
|
|||||||
Reference in New Issue
Block a user