本文整理汇总了Python中src.functions.get_players函数的典型用法代码示例。如果您正苦于以下问题:Python get_players函数的具体用法?Python get_players怎么用?Python get_players使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_players函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_player_win
def on_player_win(evt, var, player, role, winner, survived):
from src.roles.fool import VOTED
if player in LOVERS:
evt.data["special"].append("lover")
if winner == "lovers" and player in LOVERS:
evt.data["iwon"] = True
elif player in LOVERS and survived and LOVERS[player].intersection(get_players()):
for lvr in LOVERS[player]:
if lvr not in get_players():
# cannot win with dead lover (lover idled out)
continue
lover_role = get_main_role(lvr)
if singular(winner) not in Win_Stealer:
evt.data["iwon"] = True
break
elif winner == "fool":
if lvr is VOTED:
evt.data["iwon"] = True
break
elif singular(winner) in Win_Stealer and lover_role == singular(winner):
evt.data["iwon"] = True
break
示例2: on_transition_day_resolve_end
def on_transition_day_resolve_end(evt, var, victims):
for victim in list(evt.data["dead"]):
if GUNNERS.get(victim) and "@wolves" in evt.data["killers"][victim]:
if random.random() < var.GUNNER_KILLS_WOLF_AT_NIGHT_CHANCE:
# pick a random wolf to be shot
wolfset = [wolf for wolf in get_players(Wolf) if wolf not in evt.data["dead"]]
if wolfset:
deadwolf = random.choice(wolfset)
if var.ROLE_REVEAL in ("on", "team"):
evt.data["message"][victim].append(messages["gunner_killed_wolf_overnight"].format(victim, deadwolf, get_reveal_role(deadwolf)))
else:
evt.data["message"][victim].append(messages["gunner_killed_wolf_overnight_no_reveal"].format(victim, deadwolf))
evt.data["dead"].append(deadwolf)
evt.data["killers"][deadwolf].append(victim)
GUNNERS[victim] -= 1 # deduct the used bullet
if var.WOLF_STEALS_GUN and GUNNERS[victim]: # might have used up the last bullet or something
possible = get_players(Wolfchat)
random.shuffle(possible)
for looter in possible:
if looter not in evt.data["dead"]:
break
else:
return # no live wolf, nothing to do here
GUNNERS[looter] = GUNNERS.get(looter, 0) + 1
del GUNNERS[victim]
var.ROLES[rolename].add(looter)
looter.send(messages["wolf_gunner"].format(victim))
示例3: on_transition_night_end
def on_transition_night_end(evt, var):
chances = var.CURRENT_GAMEMODE.TOTEM_CHANCES
max_totems = sum(x["wolf shaman"] for x in chances.values())
ps = get_players()
shamans = get_players(("wolf shaman",))
for s in list(LASTGIVEN):
if s not in shamans:
del LASTGIVEN[s]
for shaman in shamans:
pl = ps[:]
random.shuffle(pl)
if LASTGIVEN.get(shaman):
if LASTGIVEN[shaman] in pl:
pl.remove(LASTGIVEN[shaman])
target = 0
rand = random.random() * max_totems
for t in chances:
target += chances[t]["wolf shaman"]
if rand <= target:
TOTEMS[shaman] = t
break
if shaman.prefers_simple():
# Message about role was sent with wolfchat
shaman.send(messages["totem_simple"].format(TOTEMS[shaman]))
else:
totem = TOTEMS[shaman]
tmsg = messages["shaman_totem"].format(totem)
tmsg += messages[totem + "_totem"]
shaman.send(tmsg)
示例4: on_new_role
def on_new_role(evt, var, player, old_role):
wcroles = get_wolfchat_roles(var)
if old_role is None:
# initial role assignment; don't do all the logic below about notifying other wolves and such
if evt.data["role"] in wcroles:
evt.data["in_wolfchat"] = True
return
sayrole = evt.data["role"]
if sayrole in Hidden:
sayrole = var.HIDDEN_ROLE
an = "n" if sayrole.startswith(("a", "e", "i", "o", "u")) else ""
if player in KILLS:
del KILLS[player]
if old_role not in wcroles and evt.data["role"] in wcroles:
# a new wofl has joined the party, give them tummy rubs and the wolf list
# and let the other wolves know to break out the confetti and villager steaks
wofls = get_players(wcroles)
evt.data["in_wolfchat"] = True
if wofls:
new_wolves = []
for wofl in wofls:
wofl.queue_message(messages["wolfchat_new_member"].format(player, an, sayrole))
wofl.send_messages()
else:
return # no other wolves, nothing else to do
pl = get_players()
if player in pl:
pl.remove(player)
random.shuffle(pl)
pt = []
wevt = Event("wolflist", {"tags": set()})
for p in pl:
prole = get_main_role(p)
wevt.data["tags"].clear()
wevt.dispatch(var, p, player)
tags = " ".join(wevt.data["tags"])
if prole in wcroles:
if tags:
tags += " "
pt.append("\u0002{0}\u0002 ({1}{2})".format(p, tags, prole))
elif tags:
pt.append("{0} ({1})".format(p, tags))
else:
pt.append(p.nick)
evt.data["messages"].append(messages["players_list"].format(", ".join(pt)))
if var.PHASE == "night" and evt.data["role"] in Wolf & Killer:
# inform the new wolf that they can kill and stuff
nevt = Event("wolf_numkills", {"numkills": 1, "message": ""})
nevt.dispatch(var)
if not nevt.data["numkills"] and nevt.data["message"]:
evt.data["messages"].append(messages[nevt.data["message"]])
示例5: on_begin_day
def on_begin_day(evt, var):
# Refund failed bites
for alpha, target in BITTEN.items():
if alpha in get_players() and target not in get_players(Wolf):
alpha.send(messages["alpha_bite_failure"].format(target))
else:
alpha.send(messages["alpha_bite_success"].format(target))
ALPHAS.add(alpha)
BITTEN.clear()
示例6: on_swap_role_state
def on_swap_role_state(evt, var, actor, target, role):
if role == "wild child":
IDOLS[actor], IDOLS[target] = IDOLS[target], IDOLS[actor]
if IDOLS[actor] in get_players():
evt.data["actor_messages"].append(messages["wild_child_idol"].format(IDOLS[actor]))
else: # The King is dead, long live the King!
change_role(var, actor, "wild child", "wolf", message="wild_child_idol_died")
var.ROLES["wild child"].add(actor)
if IDOLS[target] in get_players():
evt.data["target_messages"].append(messages["wild_child_idol"].format(IDOLS[target]))
else:
change_role(var, target, "wild child", "wolf", message="wild_child_idol_died")
var.ROLES["wild child"].add(target)
示例7: add_dying
def add_dying(var, player: User, killer_role: str, reason: str, *, death_triggers: bool = True) -> bool:
"""
Mark a player as dying.
:param var: The game state
:param player: The player to kill off
:param killer_role: The role which is responsible for killing player; must be an actual role
:param reason: The reason the player is being killed off, for stats tracking purposes
:param death_triggers: Whether or not to run role logic that triggers on death; players who die due to quitting or idling out have this set to False
:returns: True if the player was successfully marked as dying, or False if they are already dying or dead
"""
t = time.time()
# ensure that the reaper thread doesn't smash things against the gameplay thread when running this
# (eventually the reaper thread will just pass messages to the main thread via the asyncio event loop and these locks would therefore be unnecessary)
with var.GRAVEYARD_LOCK: # FIXME
if not var.GAME_ID or var.GAME_ID > t:
# either game ended, or a new game has started
return False
if player in DYING or player not in get_players():
return False
DYING[player] = (killer_role, reason, death_triggers)
return True
示例8: get_lovers
def get_lovers():
lovers = []
pl = get_players()
for lover in LOVERS:
done = None
for i, lset in enumerate(lovers):
if lover in pl and lover in lset:
if done is not None: # plot twist! two clusters turn out to be linked!
done.update(lset)
for lvr in LOVERS[lover]:
if lvr in pl:
done.add(lvr)
lset.clear()
continue
for lvr in LOVERS[lover]:
if lvr in pl:
lset.add(lvr)
done = lset
if done is None and lover in pl:
lovers.append(set())
lovers[-1].add(lover)
for lvr in LOVERS[lover]:
if lvr in pl:
lovers[-1].add(lvr)
while set() in lovers:
lovers.remove(set())
return lovers
示例9: on_del_player
def on_del_player(evt, var, player, all_roles, death_triggers):
for h, v in list(KILLS.items()):
if v is player:
h.send(messages["hunter_discard"])
del KILLS[h]
elif h is player:
del KILLS[h]
if death_triggers and "dullahan" in all_roles:
pl = get_players()
with TARGETS[player].intersection(pl) as targets:
if targets:
target = random.choice(list(targets))
protected = try_protection(var, target, player, "dullahan", "dullahan_die")
if protected is not None:
channels.Main.send(*protected)
return
if var.ROLE_REVEAL in ("on", "team"):
role = get_reveal_role(target)
an = "n" if role.startswith(("a", "e", "i", "o", "u")) else ""
channels.Main.send(messages["dullahan_die_success"].format(player, target, an, role))
else:
channels.Main.send(messages["dullahan_die_success_noreveal"].format(player, target))
debuglog("{0} (dullahan) DULLAHAN ASSASSINATE: {1} ({2})".format(player, target, get_main_role(target)))
add_dying(var, target, "dullahan", "dullahan_die")
示例10: send_wolfchat_message
def send_wolfchat_message(var, user, message, roles, *, role=None, command=None):
if role not in Wolf & Killer and var.RESTRICT_WOLFCHAT & var.RW_NO_INTERACTION:
return
if command not in _kill_cmds and var.RESTRICT_WOLFCHAT & var.RW_ONLY_KILL_CMD:
if var.PHASE == "night" and var.RESTRICT_WOLFCHAT & var.RW_DISABLE_NIGHT:
return
if var.PHASE == "day" and var.RESTRICT_WOLFCHAT & var.RW_DISABLE_DAY:
return
if not is_known_wolf_ally(var, user, user):
return
wcroles = get_wolfchat_roles(var)
if var.RESTRICT_WOLFCHAT & var.RW_ONLY_SAME_CMD:
if var.PHASE == "night" and var.RESTRICT_WOLFCHAT & var.RW_DISABLE_NIGHT:
wcroles = roles
if var.PHASE == "day" and var.RESTRICT_WOLFCHAT & var.RW_DISABLE_DAY:
wcroles = roles
wcwolves = get_players(wcroles)
wcwolves.remove(user)
player = None
for player in wcwolves:
player.queue_message(message)
for player in var.SPECTATING_WOLFCHAT:
player.queue_message("[wolfchat] " + message)
if player is not None:
player.send_messages()
示例11: on_gun_chances
def on_gun_chances(evt, var, user, role):
if user in get_players(get_wolfchat_roles(var)):
hit, miss, headshot = var.WOLF_GUN_CHANCES
evt.data["hit"] = hit
evt.data["miss"] = miss
evt.data["headshot"] = headshot
evt.stop_processing = True
示例12: consecrate
def consecrate(var, wrapper, message):
"""Consecrates a corpse, putting its spirit to rest and preventing other unpleasant things from happening."""
alive = get_players()
targ = re.split(" +", message)[0]
if not targ:
wrapper.pm(messages["not_enough_parameters"])
return
dead = set(var.ALL_PLAYERS) - set(alive)
target, _ = users.complete_match(targ, dead)
if target is None:
wrapper.pm(messages["consecrate_fail"].format(targ))
return
# we have a target, so mark them as consecrated, right now all this does is silence a VG for a night
# but other roles that do stuff after death or impact dead players should have functionality here as well
# (for example, if there was a role that could raise corpses as undead somethings, this would prevent that from working)
# regardless if this has any actual effect or not, it still removes the priest from being able to vote
evt = Event("consecrate", {})
evt.dispatch(var, wrapper.source, target)
wrapper.pm(messages["consecrate_success"].format(target))
debuglog("{0} (priest) CONSECRATE: {1}".format(wrapper.source, target))
add_absent(var, wrapper.source, "consecrating")
from src.votes import chk_decision
from src.wolfgame import chk_win
if not chk_win():
# game didn't immediately end due to marking as absent, see if we should force through a lynch
chk_decision(var)
示例13: wait
def wait(var, wrapper, message):
"""Increase the wait time until !start can be used."""
if wrapper.target is not channels.Main:
return
pl = get_players()
with WAIT_LOCK:
global WAIT_TOKENS, WAIT_LAST
wait_check_time = time.time()
WAIT_TOKENS += (wait_check_time - WAIT_LAST) / var.WAIT_TB_DELAY
WAIT_LAST = wait_check_time
WAIT_TOKENS = min(WAIT_TOKENS, var.WAIT_TB_BURST)
now = datetime.now()
if ((LAST_WAIT and wrapper.source in LAST_WAIT and LAST_WAIT[wrapper.source] +
timedelta(seconds=var.WAIT_RATE_LIMIT) > now) or WAIT_TOKENS < 1):
wrapper.pm(messages["command_ratelimited"])
return
LAST_WAIT[wrapper.source] = now
WAIT_TOKENS -= 1
if now > var.CAN_START_TIME:
var.CAN_START_TIME = now + timedelta(seconds=var.EXTRA_WAIT)
else:
var.CAN_START_TIME += timedelta(seconds=var.EXTRA_WAIT)
wrapper.send(messages["wait_time_increase"].format(wrapper.source, var.EXTRA_WAIT))
示例14: add_lycanthropy
def add_lycanthropy(var, target, prefix="lycan"):
"""Effect the target with lycanthropy. Fire the add_lycanthropy event."""
if target in LYCANTHROPES:
return
if target in get_players() and Event("add_lycanthropy", {}).dispatch(var, target):
LYCANTHROPES[target] = prefix
示例15: on_new_role
def on_new_role(evt, var, user, old_role):
if old_role == "sharpshooter":
if evt.data["role"] != "sharpshooter":
del GUNNERS[user]
elif evt.data["role"] == "sharpshooter":
GUNNERS[user] = math.ceil(var.SHARPSHOOTER_MULTIPLIER * len(get_players()))