2013-08-25 01:06:37 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
habitrpg.controller('NotificationCtrl',
|
2014-02-03 18:24:37 +00:00
|
|
|
['$scope', '$rootScope', 'Shared', 'User', 'Guide', 'Notification',
|
|
|
|
|
function ($scope, $rootScope, Shared, User, Guide, Notification) {
|
2013-09-10 22:06:16 +00:00
|
|
|
|
2013-09-17 15:43:05 +00:00
|
|
|
$rootScope.$watch('user.stats.hp', function(after, before) {
|
2014-02-01 15:46:48 +00:00
|
|
|
if (after <= 0){
|
2014-02-03 18:24:37 +00:00
|
|
|
$rootScope.openModal('death', undefined, undefined, false, 'static');
|
2014-02-01 15:46:48 +00:00
|
|
|
}
|
2013-09-17 15:43:05 +00:00
|
|
|
if (after == before) return;
|
2013-12-15 04:58:53 +00:00
|
|
|
if (User.user.stats.lvl == 0) return;
|
2013-09-17 15:43:05 +00:00
|
|
|
Notification.hp(after - before, 'hp');
|
|
|
|
|
});
|
2013-08-28 20:48:27 +00:00
|
|
|
|
2013-09-17 15:43:05 +00:00
|
|
|
$rootScope.$watch('user.stats.exp', function(after, before) {
|
|
|
|
|
if (after == before) return;
|
2013-12-15 04:58:53 +00:00
|
|
|
if (User.user.stats.lvl == 0) return;
|
2013-09-17 15:43:05 +00:00
|
|
|
Notification.exp(after - before);
|
|
|
|
|
});
|
2013-08-28 20:48:27 +00:00
|
|
|
|
2013-09-17 15:43:05 +00:00
|
|
|
$rootScope.$watch('user.stats.gp', function(after, before) {
|
|
|
|
|
if (after == before) return;
|
2013-12-15 04:58:53 +00:00
|
|
|
if (User.user.stats.lvl == 0) return;
|
2013-09-17 15:43:05 +00:00
|
|
|
var money = after - before;
|
2014-01-07 17:14:34 +00:00
|
|
|
var bonus = User.user._tmp.streakBonus;
|
|
|
|
|
Notification.gp(money, bonus || 0);
|
2013-08-28 20:48:27 +00:00
|
|
|
|
2013-09-17 15:43:05 +00:00
|
|
|
//Append Bonus
|
2013-08-28 20:48:27 +00:00
|
|
|
|
2013-09-17 15:43:05 +00:00
|
|
|
if ((money > 0) && !!bonus) {
|
2013-09-17 16:52:51 +00:00
|
|
|
if (bonus < 0.01) bonus = 0.01;
|
2014-02-05 22:43:49 +00:00
|
|
|
Notification.text("+ " + Notification.coins(bonus) + window.env.t('streakCoins'));
|
2013-10-27 12:44:04 +00:00
|
|
|
delete User.user._tmp.streakBonus;
|
2013-09-17 15:43:05 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2013-12-26 13:31:00 +00:00
|
|
|
$rootScope.$watch('user.stats.mp', function(after,before) {
|
|
|
|
|
if (after == before) return;
|
2013-12-31 16:29:13 +00:00
|
|
|
if (!User.user.flags.classSelected || User.user.preferences.disableClasses) return;
|
2013-12-26 13:31:00 +00:00
|
|
|
var mana = after - before;
|
|
|
|
|
Notification.mp(mana);
|
|
|
|
|
});
|
|
|
|
|
|
2014-01-02 19:41:50 +00:00
|
|
|
$rootScope.$watch('user._tmp.crit', function(after, before){
|
|
|
|
|
if (after == before || !after) return;
|
|
|
|
|
var amount = User.user._tmp.crit * 100 - 100;
|
|
|
|
|
// reset the crit counter
|
|
|
|
|
User.user._tmp.crit = undefined;
|
2014-01-07 18:03:07 +00:00
|
|
|
Notification.crit(amount);
|
2014-01-02 19:41:50 +00:00
|
|
|
});
|
|
|
|
|
|
2013-09-17 16:16:16 +00:00
|
|
|
$rootScope.$watch('user._tmp.drop', function(after, before){
|
2013-11-22 19:11:35 +00:00
|
|
|
// won't work when getting the same item twice?
|
|
|
|
|
if (after == before || !after) return;
|
2013-12-07 19:17:03 +00:00
|
|
|
var type = (after.type == 'Food') ? 'food' :
|
|
|
|
|
(after.type == 'HatchingPotion') ? 'hatchingPotions' : // can we use camelcase and remove this line?
|
|
|
|
|
(after.type.toLowerCase() + 's');
|
2013-12-20 22:43:10 +00:00
|
|
|
if(!User.user.items[type][after.key]){
|
|
|
|
|
User.user.items[type][after.key] = 0;
|
2013-11-22 18:21:34 +00:00
|
|
|
}
|
2013-12-20 22:43:10 +00:00
|
|
|
User.user.items[type][after.key]++;
|
2014-01-15 04:02:22 +00:00
|
|
|
Notification.drop(User.user._tmp.drop.dialog);
|
2013-09-17 16:16:16 +00:00
|
|
|
});
|
|
|
|
|
|
2013-10-23 15:57:02 +00:00
|
|
|
$rootScope.$watch('user.achievements.streak', function(after, before){
|
2014-01-06 22:43:56 +00:00
|
|
|
if(before == undefined || after == before || after < before) return;
|
2014-02-03 18:24:37 +00:00
|
|
|
$rootScope.openModal('achievements/streak');
|
2013-10-23 15:57:02 +00:00
|
|
|
});
|
|
|
|
|
|
2013-11-08 21:33:48 +00:00
|
|
|
$rootScope.$watch('user.achievements.ultimateGear', function(after, before){
|
2013-10-27 11:11:59 +00:00
|
|
|
if (after === before || after !== true) return;
|
2014-02-03 18:24:37 +00:00
|
|
|
$rootScope.openModal('achievements/ultimateGear');
|
2013-10-27 11:11:59 +00:00
|
|
|
});
|
|
|
|
|
|
2013-11-10 04:15:55 +00:00
|
|
|
$rootScope.$watch('user.items.pets', function(after, before){
|
2013-11-18 15:18:57 +00:00
|
|
|
if(_.size(after) === _.size(before) ||
|
2014-01-12 23:05:15 +00:00
|
|
|
Shared.countPets(null, after) < 90) return;
|
2013-11-08 21:33:48 +00:00
|
|
|
User.user.achievements.beastMaster = true;
|
2014-02-03 18:24:37 +00:00
|
|
|
$rootScope.openModal('achievements/beastMaster');
|
2013-11-18 15:18:57 +00:00
|
|
|
}, true);
|
2013-11-08 21:33:48 +00:00
|
|
|
|
2013-12-25 23:56:55 +00:00
|
|
|
$rootScope.$watch('user.achievements.rebirths', function(after, before){
|
|
|
|
|
if(after === before) return;
|
2014-02-03 18:24:37 +00:00
|
|
|
$rootScope.openModal('achievements/rebirth');
|
2014-02-01 16:04:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$rootScope.$watch('user.flags.contributor', function(after, before){
|
|
|
|
|
if (after === before || after !== true) return;
|
2014-02-03 18:24:37 +00:00
|
|
|
$rootScope.openModal('achievements/contributor');
|
2013-12-25 23:56:55 +00:00
|
|
|
});
|
|
|
|
|
|
2013-09-17 15:43:05 +00:00
|
|
|
/*_.each(['weapon', 'head', 'chest', 'shield'], function(watched){
|
|
|
|
|
$rootScope.$watch('user.items.' + watched, function(before, after){
|
2013-08-28 20:48:27 +00:00
|
|
|
if (after == before) return;
|
2013-09-17 15:43:05 +00:00
|
|
|
if (+after < +before) {
|
|
|
|
|
Notification.death();
|
|
|
|
|
//don't want to day "lost a head"
|
|
|
|
|
if (watched === 'head') watched = 'helm';
|
|
|
|
|
Notification.text('Lost GP, 1 LVL, ' + watched);
|
2013-08-28 20:48:27 +00:00
|
|
|
}
|
2013-09-17 15:43:05 +00:00
|
|
|
})
|
|
|
|
|
});*/
|
|
|
|
|
|
2014-02-02 14:46:46 +00:00
|
|
|
// Classes modal
|
2014-02-01 18:19:48 +00:00
|
|
|
$rootScope.$watch('!user.flags.classSelected && user.stats.lvl >= 10', function(after, before){
|
|
|
|
|
if(after){
|
2014-02-05 15:51:35 +00:00
|
|
|
$rootScope.openModal('chooseClass', 'UserCtrl', undefined, false, 'static');
|
2014-02-01 18:19:48 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2013-09-17 15:43:05 +00:00
|
|
|
$rootScope.$watch('user.stats.lvl', function(after, before) {
|
|
|
|
|
if (after == before) return;
|
|
|
|
|
if (after > before) {
|
|
|
|
|
Notification.lvl();
|
|
|
|
|
}
|
|
|
|
|
});
|
2013-10-30 18:29:46 +00:00
|
|
|
|
2014-02-02 15:43:58 +00:00
|
|
|
// Math updates modal
|
2014-02-02 14:46:46 +00:00
|
|
|
$rootScope.$watch('!user.flags.mathUpdates', function(after, before){
|
2014-02-02 15:43:58 +00:00
|
|
|
if (after == before || after != true) return;
|
2014-02-03 18:24:37 +00:00
|
|
|
$rootScope.openModal('mathUpdates');
|
2014-02-02 14:46:46 +00:00
|
|
|
});
|
|
|
|
|
|
2014-02-02 15:43:58 +00:00
|
|
|
// Completed quest modal
|
|
|
|
|
$rootScope.$watch('user.party.quest.completed', function(after, before){
|
|
|
|
|
if (after == before || after != true) return;
|
2014-02-03 18:24:37 +00:00
|
|
|
$rootScope.openModal('questCompleted', 'InventoryCtrl');
|
2014-02-02 15:43:58 +00:00
|
|
|
});
|
|
|
|
|
|
2014-02-04 19:53:09 +00:00
|
|
|
// Quest invitation modal
|
|
|
|
|
$rootScope.$watch('party.quest.key && !party.quest.active && party.quest.members[user._id] == undefined', function(after, before){
|
2014-02-02 15:43:58 +00:00
|
|
|
if (after == before || after != true) return;
|
2014-02-03 18:24:37 +00:00
|
|
|
$rootScope.openModal('questInvitation');
|
2014-02-02 15:43:58 +00:00
|
|
|
});
|
|
|
|
|
|
2013-10-30 18:29:46 +00:00
|
|
|
$rootScope.$on('responseError', function(ev, error){
|
|
|
|
|
Notification.error(error);
|
|
|
|
|
});
|
2013-08-25 01:06:37 +00:00
|
|
|
}
|
|
|
|
|
]);
|