mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-08-03 16:31:59 +02:00
Door utility and door tracking
* Require >= 45s of time in a door before it counts as "run"
This commit is contained in:
parent
4e1997302e
commit
7776391184
5 changed files with 74 additions and 48 deletions
41
core/door_util.js
Normal file
41
core/door_util.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
const UserProps = require('./user_property.js');
|
||||
const Events = require('./events.js');
|
||||
const StatLog = require('./stat_log.js');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
exports.trackDoorRunBegin = trackDoorRunBegin;
|
||||
exports.trackDoorRunEnd = trackDoorRunEnd;
|
||||
|
||||
|
||||
function trackDoorRunBegin(client, doorTag) {
|
||||
const startTime = moment();
|
||||
|
||||
// door must be running for >= 45s for us to officially record it
|
||||
const timeout = setTimeout( () => {
|
||||
StatLog.incrementUserStat(client.user, UserProps.DoorRunTotalCount, 1);
|
||||
|
||||
const eventInfo = { user : client.user };
|
||||
if(doorTag) {
|
||||
eventInfo.doorTag = doorTag;
|
||||
}
|
||||
Events.emit(Events.getSystemEvents().UserRunDoor, eventInfo);
|
||||
}, 45 * 1000);
|
||||
|
||||
return { startTime, timeout, client, doorTag };
|
||||
}
|
||||
|
||||
function trackDoorRunEnd(trackInfo) {
|
||||
const { startTime, timeout, client } = trackInfo;
|
||||
|
||||
clearTimeout(timeout);
|
||||
|
||||
const endTime = moment();
|
||||
const runTimeMinutes = Math.floor(moment.duration(endTime.diff(startTime)).asMinutes());
|
||||
if(runTimeMinutes > 0) {
|
||||
StatLog.incrementUserStat(client.user, UserProps.DoorRunTotalMinutes, runTimeMinutes);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue