parent
b86e52de25
commit
6d0d6f7169
71
src/roles/timelord.py
Normal file
71
src/roles/timelord.py
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
import re
|
||||||
|
import random
|
||||||
|
import itertools
|
||||||
|
import math
|
||||||
|
import time
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
import botconfig
|
||||||
|
from src.utilities import *
|
||||||
|
from src import channels, users, debuglog, errlog, plog
|
||||||
|
from src.functions import get_players, get_all_players, get_main_role, get_reveal_role, get_target
|
||||||
|
from src.decorators import command, event_listener
|
||||||
|
from src.containers import UserList, UserSet, UserDict, DefaultUserDict
|
||||||
|
from src.messages import messages
|
||||||
|
from src.events import Event
|
||||||
|
|
||||||
|
TIME_ATTRIBUTES = (
|
||||||
|
("DAY_TIME_LIMIT", "TIME_LORD_DAY_LIMIT"),
|
||||||
|
("DAY_TIME_WARN", "TIME_LORD_DAY_WARN"),
|
||||||
|
("SHORT_DAY_LIMIT", "TIME_LORD_DAY_LIMIT"),
|
||||||
|
("SHORT_DAY_WARN", "TIME_LORD_DAY_WARN"),
|
||||||
|
("NIGHT_TIME_LIMIT", "TIME_LORD_NIGHT_LIMIT"),
|
||||||
|
("NIGHT_TIME_WARN", "TIME_LORD_NIGHT_WARN"),
|
||||||
|
)
|
||||||
|
|
||||||
|
@event_listener("del_player")
|
||||||
|
def on_del_player(evt, var, user, mainrole, allroles, death_triggers):
|
||||||
|
if not death_triggers or "time lord" not in allroles:
|
||||||
|
return
|
||||||
|
|
||||||
|
for attr, new_attr in TIME_ATTRIBUTES:
|
||||||
|
if attr not in var.ORIGINAL_SETTINGS:
|
||||||
|
var.ORIGINAL_SETTINGS[attr] = getattr(var, attr)
|
||||||
|
|
||||||
|
setattr(var, attr, getattr(var, new_attr))
|
||||||
|
|
||||||
|
channels.Main.send(messages["time_lord_dead"].format(var.TIME_LORD_DAY_LIMIT, var.TIME_LORD_NIGHT_LIMIT))
|
||||||
|
|
||||||
|
if var.GAMEPHASE == "day":
|
||||||
|
time_limit = var.DAY_TIME_LIMIT
|
||||||
|
time_warn = var.DAY_TIME_WARN
|
||||||
|
phase_id = "DAY_ID"
|
||||||
|
timer_name = "day_warn"
|
||||||
|
elif var.GAMEPHASE == "night":
|
||||||
|
time_limit = var.NIGHT_TIME_LIMIT
|
||||||
|
time_warn = var.NIGHT_TIME_WARN
|
||||||
|
phase_id = "NIGHT_ID"
|
||||||
|
timer_name = "night_warn"
|
||||||
|
|
||||||
|
if var.GAMEPHASE in var.TIMERS:
|
||||||
|
time_left = int((var.TIMERS[var.GAMEPHASE][1] + var.TIMERS[var.GAMEPHASE][2]) - time.time())
|
||||||
|
|
||||||
|
if time_left > time_limit > 0:
|
||||||
|
t = threading.Timer(time_limit, hurry_up, [phase_id, True])
|
||||||
|
var.TIMERS[var.GAMEPHASE] = (t, time.time(), time_limit)
|
||||||
|
t.daemon = True
|
||||||
|
t.start()
|
||||||
|
|
||||||
|
# Don't duplicate warnings, i.e. only set the warning timer if a warning was not already given
|
||||||
|
if timer_name in var.TIMERS:
|
||||||
|
timer = var.TIMERS[timer_name][0]
|
||||||
|
if timer.isAlive():
|
||||||
|
timer.cancel()
|
||||||
|
t = threading.Timer(time_warn, hurry_up, [phase_id, False])
|
||||||
|
var.TIMERS[timer_name] = (t, time.time(), time_warn)
|
||||||
|
t.daemon = True
|
||||||
|
t.start()
|
||||||
|
|
||||||
|
debuglog("{0} (time lord) TRIGGER".format(user))
|
||||||
|
|
||||||
|
# vim: set sw=4 expandtab:
|
@ -2472,56 +2472,6 @@ def del_player(player, *, devoice=True, end_game=True, death_triggers=True, kill
|
|||||||
debuglog("{0} ({1}) LOVE SUICIDE: {2} ({3})".format(lover, get_main_role(lover), player, mainrole))
|
debuglog("{0} ({1}) LOVE SUICIDE: {2} ({3})".format(lover, get_main_role(lover), player, mainrole))
|
||||||
del_player(lover, end_game=False, killer_role=killer_role, deadlist=deadlist, original=original, ismain=False)
|
del_player(lover, end_game=False, killer_role=killer_role, deadlist=deadlist, original=original, ismain=False)
|
||||||
pl = refresh_pl(pl)
|
pl = refresh_pl(pl)
|
||||||
if mainrole == "time lord":
|
|
||||||
if "DAY_TIME_LIMIT" not in var.ORIGINAL_SETTINGS:
|
|
||||||
var.ORIGINAL_SETTINGS["DAY_TIME_LIMIT"] = var.DAY_TIME_LIMIT
|
|
||||||
if "DAY_TIME_WARN" not in var.ORIGINAL_SETTINGS:
|
|
||||||
var.ORIGINAL_SETTINGS["DAY_TIME_WARN"] = var.DAY_TIME_WARN
|
|
||||||
if "SHORT_DAY_LIMIT" not in var.ORIGINAL_SETTINGS:
|
|
||||||
var.ORIGINAL_SETTINGS["SHORT_DAY_LIMIT"] = var.SHORT_DAY_LIMIT
|
|
||||||
if "SHORT_DAY_WARN" not in var.ORIGINAL_SETTINGS:
|
|
||||||
var.ORIGINAL_SETTINGS["SHORT_DAY_WARN"] = var.SHORT_DAY_WARN
|
|
||||||
if "NIGHT_TIME_LIMIT" not in var.ORIGINAL_SETTINGS:
|
|
||||||
var.ORIGINAL_SETTINGS["NIGHT_TIME_LIMIT"] = var.NIGHT_TIME_LIMIT
|
|
||||||
if "NIGHT_TIME_WARN" not in var.ORIGINAL_SETTINGS:
|
|
||||||
var.ORIGINAL_SETTINGS["NIGHT_TIME_WARN"] = var.NIGHT_TIME_WARN
|
|
||||||
var.DAY_TIME_LIMIT = var.TIME_LORD_DAY_LIMIT
|
|
||||||
var.DAY_TIME_WARN = var.TIME_LORD_DAY_WARN
|
|
||||||
var.SHORT_DAY_LIMIT = var.TIME_LORD_DAY_LIMIT
|
|
||||||
var.SHORT_DAY_WARN = var.TIME_LORD_DAY_WARN
|
|
||||||
var.NIGHT_TIME_LIMIT = var.TIME_LORD_NIGHT_LIMIT
|
|
||||||
var.NIGHT_TIME_WARN = var.TIME_LORD_NIGHT_WARN
|
|
||||||
channels.Main.send(messages["time_lord_dead"].format(var.TIME_LORD_DAY_LIMIT, var.TIME_LORD_NIGHT_LIMIT))
|
|
||||||
if var.GAMEPHASE == "day" and timeleft_internal("day") > var.DAY_TIME_LIMIT and var.DAY_TIME_LIMIT > 0:
|
|
||||||
if "day" in var.TIMERS:
|
|
||||||
var.TIMERS["day"][0].cancel()
|
|
||||||
t = threading.Timer(var.DAY_TIME_LIMIT, hurry_up, [var.DAY_ID, True])
|
|
||||||
var.TIMERS["day"] = (t, time.time(), var.DAY_TIME_LIMIT)
|
|
||||||
t.daemon = True
|
|
||||||
t.start()
|
|
||||||
# Don't duplicate warnings, i.e. only set the warn timer if a warning was not already given
|
|
||||||
if "day_warn" in var.TIMERS and var.TIMERS["day_warn"][0].isAlive():
|
|
||||||
var.TIMERS["day_warn"][0].cancel()
|
|
||||||
t = threading.Timer(var.DAY_TIME_WARN, hurry_up, [var.DAY_ID, False])
|
|
||||||
var.TIMERS["day_warn"] = (t, time.time(), var.DAY_TIME_WARN)
|
|
||||||
t.daemon = True
|
|
||||||
t.start()
|
|
||||||
elif var.GAMEPHASE == "night" and timeleft_internal("night") > var.NIGHT_TIME_LIMIT and var.NIGHT_TIME_LIMIT > 0:
|
|
||||||
if "night" in var.TIMERS:
|
|
||||||
var.TIMERS["night"][0].cancel()
|
|
||||||
t = threading.Timer(var.NIGHT_TIME_LIMIT, hurry_up, [var.NIGHT_ID, True])
|
|
||||||
var.TIMERS["night"] = (t, time.time(), var.NIGHT_TIME_LIMIT)
|
|
||||||
t.daemon = True
|
|
||||||
t.start()
|
|
||||||
# Don't duplicate warnings, e.g. only set the warn timer if a warning was not already given
|
|
||||||
if "night_warn" in var.TIMERS and var.TIMERS["night_warn"][0].isAlive():
|
|
||||||
var.TIMERS["night_warn"][0].cancel()
|
|
||||||
t = threading.Timer(var.NIGHT_TIME_WARN, hurry_up, [var.NIGHT_ID, False])
|
|
||||||
var.TIMERS["night_warn"] = (t, time.time(), var.NIGHT_TIME_WARN)
|
|
||||||
t.daemon = True
|
|
||||||
t.start()
|
|
||||||
|
|
||||||
debuglog(player.nick, "(time lord) TRIGGER")
|
|
||||||
|
|
||||||
pl = refresh_pl(pl)
|
pl = refresh_pl(pl)
|
||||||
# i herd u liek parameters
|
# i herd u liek parameters
|
||||||
@ -5960,22 +5910,20 @@ def timeleft(cli, nick, chan, rest):
|
|||||||
reply(cli, nick, chan, msg)
|
reply(cli, nick, chan, msg)
|
||||||
|
|
||||||
if var.PHASE in var.TIMERS:
|
if var.PHASE in var.TIMERS:
|
||||||
remaining = timeleft_internal(var.PHASE)
|
|
||||||
if var.PHASE == "day":
|
if var.PHASE == "day":
|
||||||
what = "sunset"
|
what = "sunset"
|
||||||
elif var.PHASE == "night":
|
elif var.PHASE == "night":
|
||||||
what = "sunrise"
|
what = "sunrise"
|
||||||
elif var.PHASE == "join":
|
elif var.PHASE == "join":
|
||||||
what = "the game is canceled if it's not started"
|
what = "the game is canceled if it's not started"
|
||||||
|
|
||||||
|
remaining = int((var.TIMERS[var.PHASE][1] + var.TIMERS[var.PHASE][2]) - time.time())
|
||||||
msg = "There is \u0002{0[0]:0>2}:{0[1]:0>2}\u0002 remaining until {1}.".format(divmod(remaining, 60), what)
|
msg = "There is \u0002{0[0]:0>2}:{0[1]:0>2}\u0002 remaining until {1}.".format(divmod(remaining, 60), what)
|
||||||
else:
|
else:
|
||||||
msg = messages["timers_disabled"].format(var.PHASE.capitalize())
|
msg = messages["timers_disabled"].format(var.PHASE.capitalize())
|
||||||
|
|
||||||
reply(cli, nick, chan, msg)
|
reply(cli, nick, chan, msg)
|
||||||
|
|
||||||
def timeleft_internal(phase):
|
|
||||||
return int((var.TIMERS[phase][1] + var.TIMERS[phase][2]) - time.time()) if phase in var.TIMERS else -1
|
|
||||||
|
|
||||||
@cmd("roles", pm=True)
|
@cmd("roles", pm=True)
|
||||||
def listroles(cli, nick, chan, rest):
|
def listroles(cli, nick, chan, rest):
|
||||||
"""Displays which roles are enabled at a certain number of players."""
|
"""Displays which roles are enabled at a certain number of players."""
|
||||||
|
Loading…
Reference in New Issue
Block a user