change "roleset" to "game mode" in the code / messages

This commit is contained in:
jacob1 2014-11-29 13:39:55 -05:00
parent 788707ffb1
commit 193ead22aa
2 changed files with 67 additions and 67 deletions

View File

@ -209,8 +209,8 @@ def reset():
var.JOINED_THIS_GAME = [] # keeps track of who already joined this game at least once (cloaks) var.JOINED_THIS_GAME = [] # keeps track of who already joined this game at least once (cloaks)
var.NO_LYNCH = [] var.NO_LYNCH = []
var.FGAMED = False var.FGAMED = False
var.CURRENT_ROLESET = "default" var.CURRENT_GAMEMODE = "default"
var.ROLESET_VOTES = {} #list of players who have used !game var.GAMEMODE_VOTES = {} #list of players who have used !game
reset_settings() reset_settings()
@ -1251,7 +1251,7 @@ def stop_game(cli, winner = ""):
if won or iwon: if won or iwon:
winners.append(splr) winners.append(splr)
var.update_game_stats(var.CURRENT_ROLESET, len(survived) + len(var.DEAD), winner) var.update_game_stats(var.CURRENT_GAMEMODE, len(survived) + len(var.DEAD), winner)
# spit out the list of winners # spit out the list of winners
winners.sort() winners.sort()
@ -1681,8 +1681,8 @@ def del_player(cli, nick, forced_death = False, devoice = True, end_game = True,
var.ASLEEP.remove(nick) var.ASLEEP.remove(nick)
if nick in var.PLAYERS: if nick in var.PLAYERS:
cloak = var.PLAYERS[nick]["cloak"] cloak = var.PLAYERS[nick]["cloak"]
if cloak in var.ROLESET_VOTES: if cloak in var.GAMEMODE_VOTES:
del var.ROLESET_VOTES[cloak] del var.GAMEMODE_VOTES[cloak]
chk_decision(cli) chk_decision(cli)
elif var.PHASE == "night" and ret: elif var.PHASE == "night" and ret:
chk_nightdone(cli) chk_nightdone(cli)
@ -4819,7 +4819,7 @@ def cgamemode(cli, arg):
and not attr.startswith("_")): and not attr.startswith("_")):
var.ORIGINAL_SETTINGS[attr] = getattr(var, attr) var.ORIGINAL_SETTINGS[attr] = getattr(var, attr)
setattr(var, attr, val) setattr(var, attr, val)
var.CURRENT_ROLESET = md var.CURRENT_GAMEMODE = md
return True return True
except var.InvalidModeException as e: except var.InvalidModeException as e:
cli.msg(botconfig.CHANNEL, "Invalid mode: "+str(e)) cli.msg(botconfig.CHANNEL, "Invalid mode: "+str(e))
@ -4864,19 +4864,19 @@ def start(cli, nick, chann_, rest):
return return
if not var.FGAMED: if not var.FGAMED:
votes = {} #key = roleset, not cloak votes = {} #key = gamemode, not cloak
for roleset in var.ROLESET_VOTES.values(): for gamemode in var.GAMEMODE_VOTES.values():
if len(villagers) >= var.GAME_MODES[roleset][1] and len(villagers) <= var.GAME_MODES[roleset][2]: if len(villagers) >= var.GAME_MODES[gamemode][1] and len(villagers) <= var.GAME_MODES[gamemode][2]:
votes[roleset] = votes.get(roleset, 0) + 1 votes[gamemode] = votes.get(gamemode, 0) + 1
voted = [roleset for roleset in votes if votes[roleset] == max(votes.values()) and votes[roleset] > 2*len(villagers)/5] voted = [gamemode for gamemode in votes if votes[gamemode] == max(votes.values()) and votes[gamemode] > 2*len(villagers)/5]
if len(voted): if len(voted):
cgamemode(cli, random.choice(voted)) cgamemode(cli, random.choice(voted))
else: else:
possiblerolesets = [] possiblegamemodes = []
for roleset in var.GAME_MODES.keys(): for gamemode in var.GAME_MODES.keys():
if len(villagers) >= var.GAME_MODES[roleset][1] and len(villagers) <= var.GAME_MODES[roleset][2]: if len(villagers) >= var.GAME_MODES[gamemode][1] and len(villagers) <= var.GAME_MODES[gamemode][2]:
possiblerolesets += [roleset]*(var.GAME_MODES[roleset][3]+votes.get(roleset, 0)*7) possiblegamemodes += [gamemode]*(var.GAME_MODES[gamemode][3]+votes.get(gamemode, 0)*7)
cgamemode(cli, random.choice(possiblerolesets)) cgamemode(cli, random.choice(possiblegamemodes))
for index in range(len(var.ROLE_INDEX) - 1, -1, -1): for index in range(len(var.ROLE_INDEX) - 1, -1, -1):
if var.ROLE_INDEX[index] <= len(villagers): if var.ROLE_INDEX[index] <= len(villagers):
@ -5028,7 +5028,7 @@ def start(cli, nick, chann_, rest):
var.SPECIAL_ROLES["goat herder"] = [ nick ] var.SPECIAL_ROLES["goat herder"] = [ nick ]
cli.msg(chan, ("{0}: Welcome to Werewolf, the popular detective/social party "+ cli.msg(chan, ("{0}: Welcome to Werewolf, the popular detective/social party "+
"game (a theme of Mafia). Using the \002{1}\002 roleset.").format(", ".join(pl), var.CURRENT_ROLESET)) "game (a theme of Mafia). Using the \002{1}\002 game mode.").format(", ".join(pl), var.CURRENT_GAMEMODE))
cli.mode(chan, "+m") cli.mode(chan, "+m")
var.ORIGINAL_ROLES = copy.deepcopy(var.ROLES) # Make a copy var.ORIGINAL_ROLES = copy.deepcopy(var.ROLES) # Make a copy
@ -5613,11 +5613,11 @@ def listroles(cli, nick, chan, rest):
if not len(rest[0]) and pl > 0: if not len(rest[0]) and pl > 0:
txt += " {0}: There {1} \u0002{2}\u0002 playing.".format(nick, "is" if pl == 1 else "are", pl) txt += " {0}: There {1} \u0002{2}\u0002 playing.".format(nick, "is" if pl == 1 else "are", pl)
if var.PHASE in ["night", "day"]: if var.PHASE in ["night", "day"]:
txt += " Using the {0} roleset.".format(var.CURRENT_ROLESET) txt += " Using the {0} game mode.".format(var.CURRENT_GAMEMODE)
#read game mode to get roles for #read game mode to get roles for
if len(rest[0]) and not rest[0].isdigit(): if len(rest[0]) and not rest[0].isdigit():
#check for valid roleset ("roles" roleset is treated as invalid) #check for valid game mode ("roles" gamemode is treated as invalid)
if rest[0] != "roles" and rest[0] in var.GAME_MODES.keys(): if rest[0] != "roles" and rest[0] in var.GAME_MODES.keys():
mode = var.GAME_MODES[rest[0]][0]() mode = var.GAME_MODES[rest[0]][0]()
if hasattr(mode, "ROLE_INDEX"): if hasattr(mode, "ROLE_INDEX"):
@ -5626,11 +5626,11 @@ def listroles(cli, nick, chan, rest):
roleguide = getattr(mode, "ROLE_GUIDE") roleguide = getattr(mode, "ROLE_GUIDE")
rest.pop(0) rest.pop(0)
else: else:
txt += " {0}: {1} is not a valid roleset.".format(nick, rest[0]) txt += " {0}: {1} is not a valid game mode.".format(nick, rest[0])
rest = [] rest = []
roleindex = {} roleindex = {}
#number of players to print the roleset for #number of players to print the game mode for
if len(rest) and rest[0].isdigit(): if len(rest) and rest[0].isdigit():
index = int(rest[0]) index = int(rest[0])
for i in range(len(roleindex)-1, -1, -1): for i in range(len(roleindex)-1, -1, -1):
@ -5833,34 +5833,34 @@ def game_stats(cli, nick, chan, rest):
cli.notice(nick, "Wait until the game is over to view stats.") cli.notice(nick, "Wait until the game is over to view stats.")
return return
roleset = var.CURRENT_ROLESET gamemode = var.CURRENT_GAMEMODE
rest = rest.strip().split() rest = rest.strip().split()
# Check for roleset # Check for gamemode
if len(rest) and not rest[0].isdigit(): if len(rest) and not rest[0].isdigit():
roleset = rest[0] gamemode = rest[0]
if roleset not in var.GAME_MODES.keys(): if gamemode not in var.GAME_MODES.keys():
cli.notice(nick, "{0} is not a valid roleset".format(roleset)) cli.notice(nick, "{0} is not a valid game mode".format(gamemode))
return return
rest.pop(0) rest.pop(0)
# Check for invalid input # Check for invalid input
if len(rest) and rest[0].isdigit() and ( if len(rest) and rest[0].isdigit() and (
int(rest[0]) > var.GAME_MODES[roleset][2] or int(rest[0]) < var.GAME_MODES[roleset][1]): int(rest[0]) > var.GAME_MODES[gamemode][2] or int(rest[0]) < var.GAME_MODES[gamemode][1]):
cli.notice(nick, "Please enter an integer between "+\ cli.notice(nick, "Please enter an integer between "+\
"{0} and {1}.".format(var.GAME_MODES[roleset][1], var.GAME_MODES[roleset][2])) "{0} and {1}.".format(var.GAME_MODES[gamemode][1], var.GAME_MODES[gamemode][2]))
return return
# List all games sizes and totals if no size is given # List all games sizes and totals if no size is given
if not len(rest): if not len(rest):
if chan == nick: if chan == nick:
pm(cli, nick, var.get_game_totals(roleset)) pm(cli, nick, var.get_game_totals(gamemode))
else: else:
cli.msg(chan, var.get_game_totals(roleset)) cli.msg(chan, var.get_game_totals(gamemode))
else: else:
# Attempt to find game stats for the given game size # Attempt to find game stats for the given game size
if chan == nick: if chan == nick:
pm(cli, nick, var.get_game_stats(roleset, int(rest[0]))) pm(cli, nick, var.get_game_stats(gamemode, int(rest[0])))
else: else:
cli.msg(chan, var.get_game_stats(roleset, int(rest[0]))) cli.msg(chan, var.get_game_stats(gamemode, int(rest[0])))
@pmcmd('gamestats', 'gstats') @pmcmd('gamestats', 'gstats')
@ -5942,37 +5942,37 @@ def game(cli, nick, chan, rest):
return return
if rest: if rest:
roleset = rest.lower().split()[0] gamemode = rest.lower().split()[0]
else: else:
rolesets = ", ".join(["\002{}\002".format(roleset) if len(var.list_players()) in range(var.GAME_MODES[roleset][1], gamemodes = ", ".join(["\002{}\002".format(gamemode) if len(var.list_players()) in range(var.GAME_MODES[gamemode][1],
var.GAME_MODES[roleset][2]+1) else roleset for roleset in var.GAME_MODES.keys() if var.GAME_MODES[roleset][3] > 0]) var.GAME_MODES[gamemode][2]+1) else gamemode for gamemode in var.GAME_MODES.keys() if var.GAME_MODES[gamemode][3] > 0])
cli.notice(nick, "No roleset specified. Available rolesets: " + rolesets) cli.notice(nick, "No game mode specified. Available game modes: " + gamemodes)
return return
if roleset not in var.GAME_MODES.keys(): if gamemode not in var.GAME_MODES.keys():
#players can vote by only using partial name #players can vote by only using partial name
matches = 0 matches = 0
possibleroleset = roleset possiblegamemode = gamemode
for gamemode in var.GAME_MODES.keys(): for gamemode in var.GAME_MODES.keys():
if gamemode.startswith(roleset) and var.GAME_MODES[gamemode][3] > 0: if gamemode.startswith(gamemode) and var.GAME_MODES[gamemode][3] > 0:
possibleroleset = gamemode possiblegamemode = gamemode
matches += 1 matches += 1
if matches != 1: if matches != 1:
cli.notice(nick, "\002{0}\002 isn't a valid roleset.".format(roleset)) cli.notice(nick, "\002{0}\002 is not a valid game mode.".format(gamemode))
return return
else: else:
roleset = possibleroleset gamemode = possiblegamemode
if var.GAME_MODES[roleset][3] > 0: if var.GAME_MODES[gamemode][3] > 0:
var.ROLESET_VOTES[cloak] = roleset var.GAMEMODE_VOTES[cloak] = gamemode
cli.msg(chan, "\002{0}\002 votes for the \002{1}\002 roleset.".format(nick, roleset)) cli.msg(chan, "\002{0}\002 votes for the \002{1}\002 game mode.".format(nick, gamemode))
else: else:
cli.notice(nick, "You can't vote for that roleset.") cli.notice(nick, "You can't vote for that game mode.")
def game_help(args=''): def game_help(args=''):
return "Votes to make a specific roleset more likely. Available game mode setters: " +\ return "Votes to make a specific game mode more likely. Available game mode setters: " +\
", ".join(["\002{}\002".format(roleset) if len(var.list_players()) in range(var.GAME_MODES[roleset][1], var.GAME_MODES[roleset][2]+1) ", ".join(["\002{}\002".format(gamemode) if len(var.list_players()) in range(var.GAME_MODES[gamemode][1], var.GAME_MODES[gamemode][2]+1)
else roleset for roleset in var.GAME_MODES.keys() if var.GAME_MODES[roleset][3] > 0]) else gamemode for gamemode in var.GAME_MODES.keys() if var.GAME_MODES[gamemode][3] > 0])
game.__doc__ = game_help game.__doc__ = game_help
@cmd("fpull", admin_only=True) @cmd("fpull", admin_only=True)
@ -6128,19 +6128,19 @@ if botconfig.DEBUG_MODE or botconfig.ALLOWED_NORMAL_MODE_COMMANDS:
return return
if rest: if rest:
rest = roleset = rest.lower().split()[0] rest = mode = rest.lower().split()[0]
if rest not in var.GAME_MODES.keys(): if rest not in var.GAME_MODES.keys():
#players can vote by only using partial name #players can vote by only using partial name
matches = 0 matches = 0
for gamemode in var.GAME_MODES.keys(): for gamemode in var.GAME_MODES.keys():
if gamemode.startswith(rest): if gamemode.startswith(rest):
roleset = gamemode mode = gamemode
matches += 1 matches += 1
if matches != 1: if matches != 1:
cli.notice(nick, "\002{0}\002 isn't a valid roleset.".format(rest)) cli.notice(nick, "\002{0}\002 is not a valid game mode.".format(rest))
return return
if cgamemode(cli, roleset): if cgamemode(cli, mode):
cli.msg(chan, ('\u0002{}\u0002 has changed the game settings ' cli.msg(chan, ('\u0002{}\u0002 has changed the game settings '
'successfully.').format(nick)) 'successfully.').format(nick))
var.FGAMED = True var.FGAMED = True

View File

@ -341,7 +341,7 @@ class ChangedRolesMode(object):
@game_mode("default", 4, 24, 7) @game_mode("default", 4, 24, 7)
class DefaultMode(object): class DefaultMode(object):
"""Default roleset.""" """Default game mode."""
def __init__(self): def __init__(self):
# No extra settings, just an explicit way to revert to default settings # No extra settings, just an explicit way to revert to default settings
pass pass
@ -376,7 +376,7 @@ class FoolishMode(object):
@game_mode("mad", 7, 22, 3) @game_mode("mad", 7, 22, 3)
class MadMode(object): class MadMode(object):
"""This roleset has mad scientist and many things that may kill you.""" """This game mode has mad scientist and many things that may kill you."""
def __init__(self): def __init__(self):
self.ROLE_INDEX = ( 7 , 8 , 10 , 12 , 14 , 15 , 17 , 18 , 20 ) self.ROLE_INDEX = ( 7 , 8 , 10 , 12 , 14 , 15 , 17 , 18 , 20 )
self.ROLE_GUIDE = reset_roles(self.ROLE_INDEX) self.ROLE_GUIDE = reset_roles(self.ROLE_INDEX)
@ -427,7 +427,7 @@ class EvilVillageMode(object):
@game_mode("classic", 4, 21, 3) @game_mode("classic", 4, 21, 3)
class ClassicMode(object): class ClassicMode(object):
"""Classic roleset from before all the changes.""" """Classic game mode from before all the changes."""
def __init__(self): def __init__(self):
self.ROLE_INDEX = ( 4 , 6 , 8 , 10 , 12 , 15 , 17 , 18 , 20 ) self.ROLE_INDEX = ( 4 , 6 , 8 , 10 , 12 , 15 , 17 , 18 , 20 )
self.ROLE_GUIDE = reset_roles(self.ROLE_INDEX) self.ROLE_GUIDE = reset_roles(self.ROLE_INDEX)
@ -580,7 +580,7 @@ class AmnesiaMode(object):
# Blame arkiwitect for the original name of KrabbyPatty # Blame arkiwitect for the original name of KrabbyPatty
@game_mode("aleatoire", 4, 24, 2) @game_mode("aleatoire", 4, 24, 2)
class AleatoireMode(object): class AleatoireMode(object):
"""Roleset created by Metacity and balanced by woffle.""" """Game mode created by Metacity and balanced by woffle."""
def __init__(self): def __init__(self):
self.SHARPSHOOTER_CHANCE = 1 # SHAMAN , CRAZED SHAMAN self.SHARPSHOOTER_CHANCE = 1 # SHAMAN , CRAZED SHAMAN
self.TOTEM_CHANCES = { "death": ( 4/20 , 1/15 ), self.TOTEM_CHANCES = { "death": ( 4/20 , 1/15 ),
@ -691,8 +691,8 @@ with conn:
'UNIQUE(player, role))')) 'UNIQUE(player, role))'))
c.execute(('CREATE TABLE IF NOT EXISTS gamestats (roleset TEXT, size SMALLINT, villagewins SMALLINT, ' + c.execute(('CREATE TABLE IF NOT EXISTS gamestats (gamemode TEXT, size SMALLINT, villagewins SMALLINT, ' +
'wolfwins SMALLINT, monsterwins SMALLINT, foolwins SMALLINT, totalgames SMALLINT, UNIQUE(roleset, size))')) 'wolfwins SMALLINT, monsterwins SMALLINT, foolwins SMALLINT, totalgames SMALLINT, UNIQUE(gamemode, size))'))
if OPT_IN_PING: if OPT_IN_PING:
@ -778,12 +778,12 @@ def update_role_stats(acc, role, won, iwon):
c.execute("INSERT OR REPLACE INTO rolestats VALUES (?,?,?,?,?)", c.execute("INSERT OR REPLACE INTO rolestats VALUES (?,?,?,?,?)",
(acc, role, wins, iwins, total)) (acc, role, wins, iwins, total))
def update_game_stats(roleset, size, winner): def update_game_stats(gamemode, size, winner):
with conn: with conn:
vwins, wwins, mwins, fwins, total = 0, 0, 0, 0, 0 vwins, wwins, mwins, fwins, total = 0, 0, 0, 0, 0
c.execute("SELECT villagewins, wolfwins, monsterwins, foolwins, totalgames "+ c.execute("SELECT villagewins, wolfwins, monsterwins, foolwins, totalgames "+
"FROM gamestats WHERE roleset=? AND size=?", (roleset, size)) "FROM gamestats WHERE gamemode=? AND size=?", (gamemode, size))
row = c.fetchone() row = c.fetchone()
if row: if row:
vwins, wwins, mwins, fwins, total = row vwins, wwins, mwins, fwins, total = row
@ -799,7 +799,7 @@ def update_game_stats(roleset, size, winner):
total += 1 total += 1
c.execute("INSERT OR REPLACE INTO gamestats VALUES (?,?,?,?,?,?,?)", c.execute("INSERT OR REPLACE INTO gamestats VALUES (?,?,?,?,?,?,?)",
(roleset, size, vwins, wwins, mwins, fwins, total)) (gamemode, size, vwins, wwins, mwins, fwins, total))
def get_player_stats(acc, role): def get_player_stats(acc, role):
if role.lower() not in [k.lower() for k in ROLE_GUIDE.keys()] and role != "lover": if role.lower() not in [k.lower() for k in ROLE_GUIDE.keys()] and role != "lover":
@ -834,9 +834,9 @@ def get_player_totals(acc):
else: else:
return "\u0002{0}\u0002 has not played any games.".format(acc) return "\u0002{0}\u0002 has not played any games.".format(acc)
def get_game_stats(roleset, size): def get_game_stats(gamemode, size):
with conn: with conn:
for row in c.execute("SELECT * FROM gamestats WHERE roleset=? AND size=?", (roleset, size)): for row in c.execute("SELECT * FROM gamestats WHERE gamemode=? AND size=?", (gamemode, size)):
msg = "\u0002%d\u0002 player games | Village wins: %d (%d%%), Wolf wins: %d (%d%%)" % (row[1], row[2], round(row[2]/row[6] * 100), row[3], round(row[3]/row[6] * 100)) msg = "\u0002%d\u0002 player games | Village wins: %d (%d%%), Wolf wins: %d (%d%%)" % (row[1], row[2], round(row[2]/row[6] * 100), row[3], round(row[3]/row[6] * 100))
if row[4] > 0: if row[4] > 0:
msg += ", Monster wins: %d (%d%%)" % (row[4], round(row[4]/row[6] * 100)) msg += ", Monster wins: %d (%d%%)" % (row[4], round(row[4]/row[6] * 100))
@ -846,19 +846,19 @@ def get_game_stats(roleset, size):
else: else:
return "No stats for \u0002{0}\u0002 player games.".format(size) return "No stats for \u0002{0}\u0002 player games.".format(size)
def get_game_totals(roleset): def get_game_totals(gamemode):
size_totals = [] size_totals = []
total = 0 total = 0
with conn: with conn:
for size in range(MIN_PLAYERS, MAX_PLAYERS + 1): for size in range(MIN_PLAYERS, MAX_PLAYERS + 1):
c.execute("SELECT size, totalgames FROM gamestats WHERE roleset=? AND size=?", (roleset, size)) c.execute("SELECT size, totalgames FROM gamestats WHERE gamemode=? AND size=?", (gamemode, size))
row = c.fetchone() row = c.fetchone()
if row: if row:
size_totals.append("\u0002{0}p\u0002: {1}".format(*row)) size_totals.append("\u0002{0}p\u0002: {1}".format(*row))
total += row[1] total += row[1]
if len(size_totals) == 0: if len(size_totals) == 0:
return "No games have been played in the {0} roleset.".format(roleset) return "No games have been played in the {0} game mode.".format(gamemode)
else: else:
return "Total games ({0}) | {1}".format(total, ", ".join(size_totals)) return "Total games ({0}) | {1}".format(total, ", ".join(size_totals))