Bugfixes
Fix crash if a template cannot be assigned due to role restrictions. Fix gunner being able to become sharpshooter even if sharpshooter isn't in the list of allowed thingies.
This commit is contained in:
parent
a670925779
commit
32312ed2d6
@ -3925,25 +3925,44 @@ def start(cli, nick, chann_, rest):
|
|||||||
# Now for the templates
|
# Now for the templates
|
||||||
for template, restrictions in var.TEMPLATE_RESTRICTIONS.items():
|
for template, restrictions in var.TEMPLATE_RESTRICTIONS.items():
|
||||||
if template == "sharpshooter":
|
if template == "sharpshooter":
|
||||||
var.ROLES["sharpshooter"] = []
|
|
||||||
continue # sharpshooter gets applied specially
|
continue # sharpshooter gets applied specially
|
||||||
possible = pl[:]
|
possible = pl[:]
|
||||||
for cannotbe in var.list_players(restrictions):
|
for cannotbe in var.list_players(restrictions):
|
||||||
possible.remove(cannotbe)
|
possible.remove(cannotbe)
|
||||||
|
if len(possible) < len(var.ROLES[template]):
|
||||||
|
cli.msg(chan, "Not enough valid targets for the {0} template.".format(template))
|
||||||
|
if var.ORIGINAL_SETTINGS:
|
||||||
|
reset_settings()
|
||||||
|
cli.msg(chan, "The default settings have been restored. Please !start again.")
|
||||||
|
var.PHASE = "join"
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
cli.msg(chan, "This role has been skipped for this game.")
|
||||||
|
continue
|
||||||
|
|
||||||
var.ROLES[template] = random.sample(possible, len(var.ROLES[template]))
|
var.ROLES[template] = random.sample(possible, len(var.ROLES[template]))
|
||||||
|
|
||||||
# Handle gunner
|
# Handle gunner
|
||||||
cannot_be_sharpshooter = var.list_players(var.TEMPLATE_RESTRICTIONS["sharpshooter"])
|
cannot_be_sharpshooter = var.list_players(var.TEMPLATE_RESTRICTIONS["sharpshooter"])
|
||||||
gunner_list = copy.copy(var.ROLES["gunner"])
|
gunner_list = copy.copy(var.ROLES["gunner"])
|
||||||
|
num_sharpshooters = 0
|
||||||
for gunner in gunner_list:
|
for gunner in gunner_list:
|
||||||
if gunner in var.ROLES["village drunk"]:
|
if num_sharpshooters < addroles["sharpshooter"]:
|
||||||
var.GUNNERS[gunner] = (var.DRUNK_SHOTS_MULTIPLIER * math.ceil(var.SHOTS_MULTIPLIER * len(pl)))
|
if gunner in var.ROLES["village drunk"]:
|
||||||
elif gunner not in cannot_be_sharpshooter and random.random() <= var.SHARPSHOOTER_CHANCE:
|
var.GUNNERS[gunner] = (var.DRUNK_SHOTS_MULTIPLIER * math.ceil(var.SHOTS_MULTIPLIER * len(pl)))
|
||||||
var.GUNNERS[gunner] = math.ceil(var.SHARPSHOOTER_MULTIPLIER * len(pl))
|
elif gunner not in cannot_be_sharpshooter and random.random() <= var.SHARPSHOOTER_CHANCE:
|
||||||
var.ROLES["gunner"].remove(gunner)
|
var.GUNNERS[gunner] = math.ceil(var.SHARPSHOOTER_MULTIPLIER * len(pl))
|
||||||
var.ROLES["sharpshooter"].append(gunner)
|
var.ROLES["gunner"].remove(gunner)
|
||||||
else:
|
var.ROLES["sharpshooter"].append(gunner)
|
||||||
var.GUNNERS[gunner] = math.ceil(var.SHOTS_MULTIPLIER * len(pl))
|
num_sharpshooters += 1
|
||||||
|
else:
|
||||||
|
var.GUNNERS[gunner] = math.ceil(var.SHOTS_MULTIPLIER * len(pl))
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
var.ROLES["sharpshooter"].remove(None)
|
||||||
|
except ValueError:
|
||||||
|
break
|
||||||
|
|
||||||
var.SPECIAL_ROLES["goat herder"] = []
|
var.SPECIAL_ROLES["goat herder"] = []
|
||||||
if var.GOAT_HERDER:
|
if var.GOAT_HERDER:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user