2013-09-17 15:43:05 +00:00
|
|
|
/**
|
|
|
|
|
Set up "+1 Exp", "Level Up", etc notifications
|
|
|
|
|
*/
|
|
|
|
|
angular.module("notificationServices", [])
|
2013-12-15 04:58:53 +00:00
|
|
|
.factory("Notification", [function() {
|
2014-04-08 17:16:06 +00:00
|
|
|
function notify(html, type, icon) {
|
|
|
|
|
var notice = $.pnotify({
|
2014-02-05 18:05:42 +00:00
|
|
|
type: type || 'warning', //('info', 'text', 'warning', 'success', 'gp', 'xp', 'hp', 'lvl', 'death', 'mp', 'crit')
|
2014-04-08 17:16:06 +00:00
|
|
|
text: html,
|
|
|
|
|
opacity: 1,
|
|
|
|
|
addclass: 'alert-' + type,
|
|
|
|
|
icon: icon || false
|
|
|
|
|
}).click(function() { notice.pnotify_remove() });
|
2013-09-17 15:43:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Show "+ 5 {gold_coin} 3 {silver_coin}"
|
|
|
|
|
*/
|
|
|
|
|
function coins(money) {
|
|
|
|
|
var absolute, gold, silver;
|
|
|
|
|
absolute = Math.abs(money);
|
|
|
|
|
gold = Math.floor(absolute);
|
|
|
|
|
silver = Math.floor((absolute - gold) * 100);
|
|
|
|
|
if (gold && silver > 0) {
|
2014-02-12 14:10:22 +00:00
|
|
|
return "" + gold + " <span class='notification-icon shop_gold'></span> " + silver + " <span class='notification-icon shop_silver'></span>";
|
2013-09-17 15:43:05 +00:00
|
|
|
} else if (gold > 0) {
|
2014-02-12 14:10:22 +00:00
|
|
|
return "" + gold + " <span class='notification-icon shop_gold'></span>";
|
2013-09-17 15:43:05 +00:00
|
|
|
} else if (silver > 0) {
|
2014-02-12 14:10:22 +00:00
|
|
|
return "" + silver + " <span class='notification-icon shop_silver'></span>";
|
2013-08-28 00:07:28 +00:00
|
|
|
}
|
2013-09-17 15:43:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var sign = function(number){
|
|
|
|
|
return number?number<0?'-':'+':'+';
|
2013-08-28 00:07:28 +00:00
|
|
|
}
|
2013-09-17 15:43:05 +00:00
|
|
|
|
|
|
|
|
var round = function(number){
|
|
|
|
|
return Math.abs(number.toFixed(1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
coins: coins,
|
|
|
|
|
hp: function(val) {
|
|
|
|
|
// don't show notifications if user dead
|
2014-04-08 17:16:06 +00:00
|
|
|
notify(sign(val) + " " + round(val) + " " + window.env.t('hp'), 'hp', 'glyphicon glyphicon-heart');
|
2013-09-17 15:43:05 +00:00
|
|
|
},
|
|
|
|
|
exp: function(val) {
|
|
|
|
|
if (val < -50) return; // don't show when they level up (resetting their exp)
|
2014-04-08 17:16:06 +00:00
|
|
|
notify(sign(val) + " " + round(val) + " " + window.env.t('xp'), 'xp', 'glyphicon glyphicon-star');
|
2013-09-17 15:43:05 +00:00
|
|
|
},
|
2014-01-07 17:14:34 +00:00
|
|
|
gp: function(val, bonus) {
|
2014-04-08 17:16:06 +00:00
|
|
|
notify(sign(val) + " " + coins(val - bonus), 'gp');
|
2013-09-17 15:43:05 +00:00
|
|
|
},
|
|
|
|
|
text: function(val){
|
2014-04-08 17:16:06 +00:00
|
|
|
notify(val, 'info');
|
2013-09-17 15:43:05 +00:00
|
|
|
},
|
|
|
|
|
lvl: function(){
|
2014-04-08 17:16:06 +00:00
|
|
|
notify(window.env.t('levelUp'), 'lvl', 'glyphicon glyphicon-chevron-up');
|
2013-09-17 15:43:05 +00:00
|
|
|
},
|
2013-10-30 18:29:46 +00:00
|
|
|
error: function(error){
|
2014-04-08 17:16:06 +00:00
|
|
|
notify(error, "danger", 'glyphicon glyphicon-exclamation-sign');
|
2013-12-26 13:31:00 +00:00
|
|
|
},
|
|
|
|
|
mp: function(val) {
|
2014-04-08 17:16:06 +00:00
|
|
|
notify(sign(val) + " " + round(val) + " " + window.env.t('mp'), 'mp', 'glyphicon glyphicon-fire');
|
2014-01-07 18:03:07 +00:00
|
|
|
},
|
|
|
|
|
crit: function(val) {
|
2014-04-08 17:16:06 +00:00
|
|
|
notify(window.env.t('critBonus') + Math.round(val) + "%", 'crit', 'glyphicon glyphicon-certificate');
|
2014-01-15 04:02:22 +00:00
|
|
|
},
|
|
|
|
|
drop: function(val) {
|
2014-04-08 17:16:06 +00:00
|
|
|
notify(val, 'drop', 'glyphicon glyphicon-gift');
|
2013-09-17 15:43:05 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
]);
|