Door utility and door tracking

* Require >= 45s of time in a door before it counts as "run"
This commit is contained in:
Bryan Ashby 2019-01-18 22:09:10 -07:00
parent 4e1997302e
commit 7776391184
5 changed files with 74 additions and 48 deletions

41
core/door_util.js Normal file
View 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);
}
}