store event success in redis
This commit is contained in:
parent
648c767849
commit
516131c7a2
|
@ -9,6 +9,8 @@ import logger from './logger';
|
||||||
import {
|
import {
|
||||||
nextEvent,
|
nextEvent,
|
||||||
setNextEvent,
|
setNextEvent,
|
||||||
|
setSuccess,
|
||||||
|
getSuccess,
|
||||||
getEventArea,
|
getEventArea,
|
||||||
clearOldEvent,
|
clearOldEvent,
|
||||||
CANVAS_ID,
|
CANVAS_ID,
|
||||||
|
@ -69,6 +71,9 @@ class Event {
|
||||||
eventCenter: Array;
|
eventCenter: Array;
|
||||||
eventCenterC: Array;
|
eventCenterC: Array;
|
||||||
eventArea: Array;
|
eventArea: Array;
|
||||||
|
// 0 if waiting
|
||||||
|
// 1 if won
|
||||||
|
// 2 if lost
|
||||||
success: boolean;
|
success: boolean;
|
||||||
void: Object;
|
void: Object;
|
||||||
chatTimeout: number;
|
chatTimeout: number;
|
||||||
|
@ -78,10 +83,6 @@ class Event {
|
||||||
this.eventState = -1;
|
this.eventState = -1;
|
||||||
this.eventCenterC = null;
|
this.eventCenterC = null;
|
||||||
this.void = null;
|
this.void = null;
|
||||||
// 0 if waiting
|
|
||||||
// 1 if won
|
|
||||||
// 2 if lost
|
|
||||||
this.success = 0;
|
|
||||||
this.chatTimeout = 0;
|
this.chatTimeout = 0;
|
||||||
this.runEventLoop = this.runEventLoop.bind(this);
|
this.runEventLoop = this.runEventLoop.bind(this);
|
||||||
if (HOURLY_EVENT) {
|
if (HOURLY_EVENT) {
|
||||||
|
@ -90,6 +91,7 @@ class Event {
|
||||||
}
|
}
|
||||||
|
|
||||||
async initEventLoop() {
|
async initEventLoop() {
|
||||||
|
this.success = await getSuccess();
|
||||||
let eventTimestamp = await nextEvent();
|
let eventTimestamp = await nextEvent();
|
||||||
if (!eventTimestamp) {
|
if (!eventTimestamp) {
|
||||||
eventTimestamp = await Event.setNextEvent();
|
eventTimestamp = await Event.setNextEvent();
|
||||||
|
@ -265,6 +267,7 @@ class Event {
|
||||||
'Threat couldn\'t be contained, abandon area',
|
'Threat couldn\'t be contained, abandon area',
|
||||||
);
|
);
|
||||||
this.success = 2;
|
this.success = 2;
|
||||||
|
setSuccess(2);
|
||||||
this.void = null;
|
this.void = null;
|
||||||
const [x, y, w, h] = this.eventArea;
|
const [x, y, w, h] = this.eventArea;
|
||||||
await protectCanvasArea(CANVAS_ID, x, y, w, h, true);
|
await protectCanvasArea(CANVAS_ID, x, y, w, h, true);
|
||||||
|
@ -294,6 +297,7 @@ class Event {
|
||||||
'Threat successfully defeated. Good work!',
|
'Threat successfully defeated. Good work!',
|
||||||
);
|
);
|
||||||
this.success = 1;
|
this.success = 1;
|
||||||
|
setSuccess(1);
|
||||||
}
|
}
|
||||||
this.void.cancel();
|
this.void.cancel();
|
||||||
this.void = null;
|
this.void = null;
|
||||||
|
@ -313,6 +317,7 @@ class Event {
|
||||||
'Void seems to leave again.',
|
'Void seems to leave again.',
|
||||||
);
|
);
|
||||||
this.success = 0;
|
this.success = 0;
|
||||||
|
setSuccess(0);
|
||||||
}
|
}
|
||||||
this.eventState = 13;
|
this.eventState = 13;
|
||||||
}
|
}
|
||||||
|
@ -330,6 +335,7 @@ class Event {
|
||||||
'Celebration time over, get back to work.',
|
'Celebration time over, get back to work.',
|
||||||
);
|
);
|
||||||
this.success = 0;
|
this.success = 0;
|
||||||
|
setSuccess(0);
|
||||||
}
|
}
|
||||||
this.eventState = 14;
|
this.eventState = 14;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,28 @@ import redis from '../redis';
|
||||||
import logger from '../../core/logger';
|
import logger from '../../core/logger';
|
||||||
import RedisCanvas from './RedisCanvas';
|
import RedisCanvas from './RedisCanvas';
|
||||||
|
|
||||||
|
const EVENT_SUCCESS_KEY = 'evt:succ';
|
||||||
const EVENT_TIMESTAMP_KEY = 'evt:time';
|
const EVENT_TIMESTAMP_KEY = 'evt:time';
|
||||||
const EVENT_POSITION_KEY = 'evt:pos';
|
const EVENT_POSITION_KEY = 'evt:pos';
|
||||||
const EVENT_BACKUP_PREFIX = 'evt:bck';
|
const EVENT_BACKUP_PREFIX = 'evt:bck';
|
||||||
// Note: Events always happen on canvas 0
|
// Note: Events always happen on canvas 0
|
||||||
export const CANVAS_ID = '0';
|
export const CANVAS_ID = '0';
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* set success status of event
|
||||||
|
* 0 = waiting
|
||||||
|
* 1 = won
|
||||||
|
* 2 = lost
|
||||||
|
*/
|
||||||
|
export function setSuccess(success) {
|
||||||
|
return redis.setAsync(EVENT_SUCCESS_KEY, success);
|
||||||
|
}
|
||||||
|
export async function getSuccess() {
|
||||||
|
const success = await redis.getAsync(EVENT_SUCCESS_KEY);
|
||||||
|
return (success) ? parseInt(success) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @return time till next event in seconds
|
* @return time till next event in seconds
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user