-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.js
64 lines (45 loc) · 1.35 KB
/
game.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const moment = require('moment')
const config = require('./config.js')
function GameInstance (ending, prize) {
this.players = {}
this.ending = ending
this.ended = false
this.prize = prize
// adds a player to the game
this.addPlayer = function (user) {
if (this.ended)
return false
this.players[user.id] = user
return true
}
// picks a random winner weighted on something later on
function pickWinner () {
let pRnd = []
for (key in this.players) {
pRnd.push(this.players[key])
}
let ticket = Math.floor((Math.random() * pRnd.length) + 1)
return pRnd[ticket]
}
}
function Game (dbHandle) {
/*
object responsible for holding the games going on
*/
this.games = {}
// sets game ending time
// invoked by a user, so we get the Message object with all its perks
this.start = function (msg) {
let channelId = msg.channel.id
if (!games.hasOwnProperty(channelId)) {
let game = newGame(channelId, moment().add(3, 's'), config.defaultRaidPrize)
game.addPlayer(msg.author)
}
}
function newGame (channelId, ending, prize) {
let game = new GameInstance(ending, prize)
this.games[channelId] = game
return game
}
}
module.exports = Game