-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtimers.js
More file actions
42 lines (39 loc) · 1.2 KB
/
timers.js
File metadata and controls
42 lines (39 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var schedule = require('node-schedule');
var monsters = require("./monster");
var timeTillSpawn = 0;
var spawnTried = false;
var killed = false;
setInterval(function(){
if(timeTillSpawn>0){
timeTillSpawnT--;
}else if(timeTillSpawn===0){
if(!spawnTried){
var chance = Math.floor(Math.random()*100);
if(chance >= 0){
monsters.spawnRandomMonster();
}
spawnTried=true;
}else{
if(!killed){
if(monsters.MONSTER_EVENT.timeLeft > 0){
console.log("monster has "+monsters.MONSTER_EVENT.timeLeft+" minutes left");
monsters.MONSTER_EVENT.timeLeft--;
if(monsters.MONSTER_EVENT.timeLeft > 1){
monsters.tell("The monster will be done with its evil doing in "+ monsters.MONSTER_EVENT.timeLeft+" minutes");
}else{
monsters.tell("The monster will be done with its evil doing in 1 minute");
}
}else{
console.log("fighting the monster");
monsters.fightMonster();
killed = true;
}
}
}
}
}, 60000);
var j = schedule.scheduleJob('59 * * * *', function(){
timeTillSpawnTry = 1 + (Math.floor(Math.random()*0));
killed = false;
spawnTried = false;
});