2013-08-25 01:06:37 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
habitrpg.controller('NotificationCtrl',
|
2014-02-01 15:46:48 +00:00
|
|
|
['$scope', '$rootScope', 'Shared', 'User', 'Guide', 'Notification', '$modal',
|
|
|
|
|
function ($scope, $rootScope, Shared, User, Guide, Notification, $modal) {
|
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){
|
|
|
|
|
$modal.open({
|
|
|
|
|
templateUrl: 'modals/death.html',
|
|
|
|
|
keyboard: false,
|
|
|
|
|
backdrop: 'static'
|
|
|
|
|
});
|
|
|
|
|
}
|
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;
|
2013-09-17 15:43:05 +00:00
|
|
|
Notification.text("+ " + Notification.coins(bonus) + " Streak Bonus!");
|
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-01 16:04:21 +00:00
|
|
|
$modal.open({
|
|
|
|
|
templateUrl: 'modals/achievements/streak.html'
|
|
|
|
|
});
|
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-01 16:04:21 +00:00
|
|
|
$modal.open({
|
|
|
|
|
templateUrl: 'modals/achievements/ultimateGear.html'
|
|
|
|
|
});
|
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-01 16:04:21 +00:00
|
|
|
$modal.open({
|
|
|
|
|
templateUrl: 'modals/achievements/beastMaster.html'
|
|
|
|
|
});
|
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-01 16:04:21 +00:00
|
|
|
$modal.open({
|
|
|
|
|
templateUrl: 'modals/achievements/rebirth.html'
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$rootScope.$watch('user.flags.contributor', function(after, before){
|
|
|
|
|
if (after === before || after !== true) return;
|
|
|
|
|
$modal.open({
|
|
|
|
|
templateUrl: 'modals/achievements/contributor.html'
|
|
|
|
|
});
|
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-01 18:19:48 +00:00
|
|
|
$rootScope.$watch('!user.flags.classSelected && user.stats.lvl >= 10', function(after, before){
|
|
|
|
|
if(after){
|
|
|
|
|
$modal.open({
|
|
|
|
|
templateUrl: 'modals/chooseClass.html',
|
|
|
|
|
controller: 'UserCtrl'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
$rootScope.$on('responseError', function(ev, error){
|
|
|
|
|
Notification.error(error);
|
|
|
|
|
});
|
2013-08-25 01:06:37 +00:00
|
|
|
}
|
|
|
|
|
]);
|