mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-05 04:07:23 +02:00
Achievement & Event improvements
* User stat set vs user stat increment system events * Proper addMultipleEventListener() and removeMultipleEventListener() Events APIs * userStatSet vs userStatInc user stat achievement types. userStatInc for example can be used for door minutes used
This commit is contained in:
parent
925ca134c6
commit
34c9178099
6 changed files with 107 additions and 35 deletions
|
@ -122,12 +122,18 @@ class StatLog {
|
|||
// User specific stats
|
||||
// These are simply convenience methods to the user's properties
|
||||
//
|
||||
setUserStat(user, statName, statValue, cb) {
|
||||
setUserStatWithOptions(user, statName, statValue, options, cb) {
|
||||
// note: cb is optional in PersistUserProperty
|
||||
user.persistProperty(statName, statValue, cb);
|
||||
|
||||
const Events = require('./events.js'); // we need to late load currently
|
||||
return Events.emit(Events.getSystemEvents().UserStatUpdate, { user, statName, statValue } );
|
||||
if(!options.noEvent) {
|
||||
const Events = require('./events.js'); // we need to late load currently
|
||||
Events.emit(Events.getSystemEvents().UserStatSet, { user, statName, statValue } );
|
||||
}
|
||||
}
|
||||
|
||||
setUserStat(user, statName, statValue, cb) {
|
||||
return this.setUserStatWithOptions(user, statName, statValue, {}, cb);
|
||||
}
|
||||
|
||||
getUserStat(user, statName) {
|
||||
|
@ -143,16 +149,27 @@ class StatLog {
|
|||
|
||||
let newValue = parseInt(user.properties[statName]);
|
||||
if(newValue) {
|
||||
if(!_.isNumber(newValue)) {
|
||||
if(!_.isNumber(newValue) && cb) {
|
||||
return cb(new Error(`Value for ${statName} is not a number!`));
|
||||
}
|
||||
|
||||
newValue += incrementBy;
|
||||
} else {
|
||||
newValue = incrementBy;
|
||||
}
|
||||
|
||||
return this.setUserStat(user, statName, newValue, cb);
|
||||
this.setUserStatWithOptions(user, statName, newValue, { noEvent : true }, err => {
|
||||
if(!err) {
|
||||
const Events = require('./events.js'); // we need to late load currently
|
||||
Events.emit(
|
||||
Events.getSystemEvents().UserStatIncrement,
|
||||
{ user, statName, statIncrementBy: incrementBy, statValue : newValue }
|
||||
);
|
||||
}
|
||||
|
||||
if(cb) {
|
||||
return cb(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// the time "now" in the ISO format we use and love :)
|
||||
|
@ -362,7 +379,7 @@ class StatLog {
|
|||
systemEvents.UserAchievementEarned,
|
||||
];
|
||||
|
||||
Events.addListenerMultipleEvents(interestedEvents, (eventName, event) => {
|
||||
Events.addMultipleEventListener(interestedEvents, (event, eventName) => {
|
||||
this.appendUserLogEntry(
|
||||
event.user,
|
||||
'system_event',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue