Add !mp start
This commit is contained in:
parent
3309f2f8fd
commit
5975e84f52
|
@ -1,6 +1,7 @@
|
||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
|
import threading
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import time
|
import time
|
||||||
|
@ -844,6 +845,47 @@ def multiplayer(fro, chan, message):
|
||||||
matchID = getMatchIDFromChannel(chan)
|
matchID = getMatchIDFromChannel(chan)
|
||||||
glob.matches.matches[matchID].removeHost()
|
glob.matches.matches[matchID].removeHost()
|
||||||
|
|
||||||
|
def mpStart():
|
||||||
|
def _start():
|
||||||
|
matchID = getMatchIDFromChannel(chan)
|
||||||
|
success = glob.matches.matches[matchID].start()
|
||||||
|
if not success:
|
||||||
|
chat.sendMessage("FokaBot", chan, "Couldn't start match. Make sure there are enough players and "
|
||||||
|
"teams are valid. The match has been unlocked.")
|
||||||
|
else:
|
||||||
|
chat.sendMessage("FokaBot", chan, "Have fun!")
|
||||||
|
|
||||||
|
|
||||||
|
def _decreaseTimer(t):
|
||||||
|
if t <= 0:
|
||||||
|
_start()
|
||||||
|
else:
|
||||||
|
if t % 10 == 0 or t <= 5:
|
||||||
|
chat.sendMessage("FokaBot", chan, "Match starts in {} seconds. The match has been locked. "
|
||||||
|
"Please don't leave the match during the countdown "
|
||||||
|
"or you might receive a penalty".format(t))
|
||||||
|
threading.Timer(1.00, _decreaseTimer, [t - 1]).start()
|
||||||
|
|
||||||
|
if len(message) < 2 or not message[1].isdigit():
|
||||||
|
startTime = 0
|
||||||
|
else:
|
||||||
|
startTime = int(message[1])
|
||||||
|
|
||||||
|
_match = glob.matches.matches[getMatchIDFromChannel(chan)]
|
||||||
|
|
||||||
|
# Force everyone to ready
|
||||||
|
for i, slot in enumerate(_match.slots):
|
||||||
|
if slot.status != slotStatuses.READY and slot.user is not None:
|
||||||
|
_match.toggleSlotReady(i)
|
||||||
|
|
||||||
|
if startTime == 0:
|
||||||
|
_start()
|
||||||
|
return "Starting match"
|
||||||
|
else:
|
||||||
|
_match.isStarting = True
|
||||||
|
threading.Timer(1.00, _decreaseTimer, [startTime - 1]).start()
|
||||||
|
return "Match starts in {} seconds".format(startTime)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subcommands = {
|
subcommands = {
|
||||||
"make": mpMake,
|
"make": mpMake,
|
||||||
|
@ -855,6 +897,7 @@ def multiplayer(fro, chan, message):
|
||||||
"move": mpMove,
|
"move": mpMove,
|
||||||
"host": mpHost,
|
"host": mpHost,
|
||||||
"clearhost": mpClearHost,
|
"clearhost": mpClearHost,
|
||||||
|
"start": mpStart,
|
||||||
}
|
}
|
||||||
requestedSubcommand = message[0].lower().strip()
|
requestedSubcommand = message[0].lower().strip()
|
||||||
if requestedSubcommand not in subcommands:
|
if requestedSubcommand not in subcommands:
|
||||||
|
|
|
@ -57,6 +57,7 @@ class match:
|
||||||
self.matchDataCache = bytes()
|
self.matchDataCache = bytes()
|
||||||
self.isTourney = isTourney
|
self.isTourney = isTourney
|
||||||
self.isLocked = False # if True, users can't change slots/teams. Used in tourney matches
|
self.isLocked = False # if True, users can't change slots/teams. Used in tourney matches
|
||||||
|
self.isStarting = False
|
||||||
|
|
||||||
# Create all slots and reset them
|
# Create all slots and reset them
|
||||||
self.slots = []
|
self.slots = []
|
||||||
|
@ -216,6 +217,8 @@ class match:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
# Update ready status and setnd update
|
# Update ready status and setnd update
|
||||||
|
if self.slots[slotID].user is None or self.isStarting:
|
||||||
|
return
|
||||||
oldStatus = self.slots[slotID].status
|
oldStatus = self.slots[slotID].status
|
||||||
if oldStatus == slotStatuses.READY:
|
if oldStatus == slotStatuses.READY:
|
||||||
newStatus = slotStatuses.NOT_READY
|
newStatus = slotStatuses.NOT_READY
|
||||||
|
@ -499,7 +502,7 @@ class match:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
# Make sure the match is not locked
|
# Make sure the match is not locked
|
||||||
if self.isLocked:
|
if self.isLocked or self.isStarting:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Make sure the user is in room
|
# Make sure the user is in room
|
||||||
|
@ -654,7 +657,7 @@ class match:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
# Make sure the match is not locked
|
# Make sure the match is not locked
|
||||||
if self.isLocked:
|
if self.isLocked or self.isStarting:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Make sure the user is in room
|
# Make sure the user is in room
|
||||||
|
@ -712,9 +715,12 @@ class match:
|
||||||
|
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
# Remove isStarting timer flag thingie
|
||||||
|
self.isStarting = False
|
||||||
|
|
||||||
# Make sure we have enough players
|
# Make sure we have enough players
|
||||||
if self.countUsers() < 2 or not self.checkTeams():
|
if self.countUsers() < 2 or not self.checkTeams():
|
||||||
return
|
return False
|
||||||
|
|
||||||
# Create playing channel
|
# Create playing channel
|
||||||
glob.streams.add(self.playingStreamName)
|
glob.streams.add(self.playingStreamName)
|
||||||
|
@ -737,3 +743,4 @@ class match:
|
||||||
|
|
||||||
# Send updates
|
# Send updates
|
||||||
self.sendUpdates()
|
self.sendUpdates()
|
||||||
|
return True
|
||||||
|
|
Loading…
Reference in New Issue
Block a user