mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
send growl notifications for points gained/lossed & level up
Conflicts: src/app/scoring.coffee
This commit is contained in:
@@ -1,8 +1,20 @@
|
||||
// Generated by CoffeeScript 1.3.3
|
||||
var content, expModifier, hpModifier, score, updateStats;
|
||||
var content, expModifier, hpModifier, score, statsNotification, updateStats;
|
||||
|
||||
content = require('./content');
|
||||
|
||||
statsNotification = function(html, type, number) {
|
||||
return $.bootstrapGrowl(html, {
|
||||
type: type,
|
||||
top_offset: 20,
|
||||
align: 'center',
|
||||
width: 250,
|
||||
delay: 4000,
|
||||
allow_dismiss: true,
|
||||
stackup_spacing: 10
|
||||
});
|
||||
};
|
||||
|
||||
expModifier = function(user, value) {
|
||||
var dmg, modified;
|
||||
dmg = user.get('items.weapon') * .03;
|
||||
@@ -33,8 +45,9 @@ updateStats = function(user, stats) {
|
||||
if (stats.exp >= tnl) {
|
||||
stats.exp -= tnl;
|
||||
user.set('stats.lvl', user.get('stats.lvl') + 1);
|
||||
statsNotification('<i class="icon-chevron-up"></i> Level Up!', 'info');
|
||||
}
|
||||
if (!user.get('items.itemsEnabled') && stats.exp >= 50) {
|
||||
if (!user.get('items.itemsEnabled') && stats.exp >= 15) {
|
||||
user.set('items.itemsEnabled', true);
|
||||
$('ul.items').popover({
|
||||
title: content.items.unlockedMessage.title,
|
||||
@@ -56,7 +69,7 @@ updateStats = function(user, stats) {
|
||||
};
|
||||
|
||||
module.exports.score = score = function(spec) {
|
||||
var adjustvalue, cron, delta, direction, exp, hp, lvl, modified, money, sign, task, type, user, value, _ref, _ref1, _ref2;
|
||||
var adjustvalue, cron, delta, diff, direction, exp, hp, lvl, modified, money, num, sign, task, type, user, value, _ref, _ref1, _ref2;
|
||||
if (spec == null) {
|
||||
spec = {
|
||||
user: null,
|
||||
@@ -69,14 +82,14 @@ module.exports.score = score = function(spec) {
|
||||
if (!task) {
|
||||
_ref1 = [user.get('stats.money'), user.get('stats.hp'), user.get('stats.exp')], money = _ref1[0], hp = _ref1[1], exp = _ref1[2];
|
||||
if (direction === "up") {
|
||||
money += 1;
|
||||
exp += expModifier(user, 1);
|
||||
modified = expModifier(user, 1);
|
||||
money += modified;
|
||||
exp += modified;
|
||||
statsNotification("Exp,GP +" + (modified.toFixed(2)), 'success');
|
||||
} else {
|
||||
modified = hpModifier(user, 1);
|
||||
hp -= modified;
|
||||
console.log({
|
||||
modified: modified
|
||||
});
|
||||
statsNotification("HP " + (modified.toFixed(2)), 'error');
|
||||
}
|
||||
updateStats(user, {
|
||||
hp: hp,
|
||||
@@ -108,16 +121,24 @@ module.exports.score = score = function(spec) {
|
||||
_ref2 = [user.get('stats.money'), user.get('stats.hp'), user.get('stats.exp'), user.get('stats.lvl')], money = _ref2[0], hp = _ref2[1], exp = _ref2[2], lvl = _ref2[3];
|
||||
if (type === 'reward') {
|
||||
money -= task.get('value');
|
||||
num = task.get('value').toFixed(2);
|
||||
statsNotification("GP -" + num, 'success');
|
||||
if (money < 0) {
|
||||
hp += money;
|
||||
diff = hp + money;
|
||||
hp = diff;
|
||||
statsNotification("HP -" + (diff.toFixed(2)), 'error');
|
||||
money = 0;
|
||||
}
|
||||
}
|
||||
if ((delta > 0 || (type === 'daily' || type === 'todo')) && !cron) {
|
||||
exp += expModifier(user, delta);
|
||||
money += delta;
|
||||
modified = expModifier(user, delta);
|
||||
exp += modified;
|
||||
money += modified;
|
||||
statsNotification("Exp,GP +" + (modified.toFixed(2)), 'success');
|
||||
} else if (type !== 'reward' && type !== 'todo') {
|
||||
hp += hpModifier(user, delta);
|
||||
modified = hpModifier(user, delta);
|
||||
hp += modified;
|
||||
statsNotification("HP " + (modified.toFixed(2)), 'error');
|
||||
}
|
||||
updateStats(user, {
|
||||
hp: hp,
|
||||
|
||||
Reference in New Issue
Block a user