mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-10 02:30:17 +01:00
Remove out of zone penality + upgrades
This commit is contained in:
80
traque-back/timeout_handler.js
Normal file
80
traque-back/timeout_handler.js
Normal file
@@ -0,0 +1,80 @@
|
||||
import game from "./game.js";
|
||||
|
||||
class TimeoutManager {
|
||||
constructor() {
|
||||
this.timeouts = new Map();
|
||||
}
|
||||
|
||||
set(key, callback, delay) {
|
||||
const newCallback = () => {
|
||||
this.timeouts.delete(key);
|
||||
callback();
|
||||
}
|
||||
|
||||
if (this.timeouts.has(key)) clearTimeout(this.timeouts.get(key));
|
||||
this.timeouts.set(key, setTimeout(newCallback, delay));
|
||||
}
|
||||
|
||||
clear(key) {
|
||||
if (this.timeouts.has(key)) {
|
||||
clearTimeout(this.timeouts.get(key));
|
||||
this.timeouts.delete(key);
|
||||
}
|
||||
}
|
||||
|
||||
clearAll() {
|
||||
this.timeouts.forEach(timeout => clearTimeout(timeout));
|
||||
this.timeouts = new Map();
|
||||
}
|
||||
}
|
||||
|
||||
export const sendPositionTimeouts = {
|
||||
timeoutManager: new TimeoutManager(),
|
||||
delay: 10, // Minutes
|
||||
|
||||
set(teamID) {
|
||||
const callback = () => {
|
||||
game.sendLocation(teamID);
|
||||
this.set(teamID);
|
||||
}
|
||||
|
||||
this.timeoutManager.set(teamID, callback, this.delay * 60 * 1000);
|
||||
},
|
||||
|
||||
clear(teamID) {
|
||||
this.timeoutManager.clear(teamID);
|
||||
},
|
||||
|
||||
clearAll() {
|
||||
this.timeoutManager.clearAll();
|
||||
},
|
||||
|
||||
setDelay(delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
}
|
||||
|
||||
export const outOfZoneTimeouts = {
|
||||
timeoutManager: new TimeoutManager(),
|
||||
delay: 10, // Minutes
|
||||
|
||||
set(teamID) {
|
||||
const callback = () => {
|
||||
game.handicapTeam(teamID);
|
||||
}
|
||||
|
||||
this.timeoutManager.set(teamID, callback, this.delay * 60 * 1000);
|
||||
},
|
||||
|
||||
clear(teamID) {
|
||||
this.timeoutManager.clear(teamID);
|
||||
},
|
||||
|
||||
clearAll() {
|
||||
this.timeoutManager.clearAll();
|
||||
},
|
||||
|
||||
setDelay(delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user