def full_desc(self, player: MPlayer): desc = self.desc if self.items: desc += " There is %s here." % dib.smart_list( [i.desc for i in self.items]) else: desc += " There are no items here." if ni := self.nonitems((player.person, )): desc += " %s %s here." % (dib.smart_list([i.desc for i in ni]), ("is" if len(ni) < 2 else "are")) for p in ni: if p.player.special_desc: desc += " %s." % p.player.special_desc
async def betting_phase(self,game:WitsAndWagers): unique_answers=list(self.answers.inverse.keys()) unique_answers.sort() if len(unique_answers)%2: bet_rows=[(abs(len(unique_answers)//2-n)+2,a,len(self.answers.inverse[a])) for n,a in enumerate(unique_answers)] else: bet_rows=[(max(len(unique_answers)//2-n,n-len(unique_answers)//2+1)+2,a,len(self.answers.inverse[a])) for n,a in enumerate(unique_answers)] bet_rows.insert(0,(6,"smaller",1)) bet_dict={ans:mult for mult,ans,t in bet_rows} await game.send("The Board:\n"+"\n".join("%s to 1: %s x %s" % b for b in bet_rows)) await dib.gather([self.manage_bets(p,game) for p in self.answers.keys()]) winning="smaller" if all(u>self.answer for u in unique_answers) else [u for u in unique_answers if u<=self.answer][-1] await game.send("The actual answer was %s, so the winning answer was %s!" % (self.answer,winning)) if winning!="smaller": winners=self.answers.inverse[winning] await game.send("%s got it right and get %s points!" % (dib.smart_list([p.name for p in winners]),CORRECT)) for w in winners: w.points+=CORRECT for p,bets in self.bets.items(): for b,amount in bets.items(): if b==winning: await game.send("%s made a correct bet and wins %s!" % (p.name,amount*bet_dict[b])) p.points+=amount+amount*bet_dict[b] else: p.points+=min(amount,3-len(bets))
async def execute(self, game: MUD, player: MPlayer): for i in self.items: player.items.remove(i) player.area.entities.append(i) await self.notify( player, "dropped %s" % dib.smart_list([i.desc for i in self.items]))
async def run(self,*modifiers): random.shuffle(self.players) w=self.players+self.players quips=[Quip(p,w[n+1:n+1+len(self.players)//2]) for n,p in enumerate(self.players)] await dib.gather([r.submit_phase(self) for r in quips]) await dib.gather([p_finish_phase(p,self,quips) for p in self.players]) await self.channel.send("It's voting time!") random.shuffle(quips) for r in quips: finishes=defaultdict(list) for p,fin in r.finishes.items(): finishes[fin].append(p) if len(finishes)>1: await self.channel.send("%s gave this prompt: %s" % (r.prompter.name,r.prompt)) fl=list(finishes.keys()) random.shuffle(fl) await self.channel.send("\n".join("%s: %s" % (n+1,prompt) for n,prompt in enumerate(fl))) voters=r.get_others(self.players) guesses=await dib.smart_gather([self.choose_number(g,True,1,len(fl),"Vote for your favourite ending!") for g in voters],voters) for n,f in enumerate(fl): if voted:= [v for v in voters if guesses[v]==n+1]: await self.send("%s voted for %s's \"%s\" - %s points!" % (dib.smart_list([v.name for v in voted]),dib.smart_list([p.name for p in finishes[f]]),f,len(voted))) for p in finishes[f]: p.points+=len(voted) else: await self.channel.send("Everybody put the same ending! Are you all psychic??? NO POINTS!")
async def night_phase(self): await self.send("The night phase has begun! No talking!") phases = set(sum((p.role.night_phases for p in self.alive), [])) for ph in sorted(phases): await dib.gather([ p.role.night_phase(self, ph) for p in self.alive if ph in p.role.night_phases ]) dead = [ p for p in self.alive if p.attacked and await p.role.on_attack(self) ] if dead: for p in dead: await p.dm("You died! Don't reveal anything!") p.dead = True await self.send( "As the sun rises, you find %s brutally murdered in their sleep." % dib.smart_list([p.name for p in dead])) else: await self.send( "As the sun rises, you find that on this one night, nobody died!" ) for p in self.alive: p.attacked = False p.healed = False
def full_desc(self, player): base = super().full_desc(player) if self.links: if len(self.links) > 1: return base + " There are doors to the %s." % dib.smart_list( list(self.links.keys())) else: return base + " There is a door to the %s." % list( self.links.keys())[0] return base + " There are no doors here. How did you get in?!"
async def run(self, *modifiers): self.deck = self.deck.copy() random.shuffle(self.deck) for n in range(self.ROUNDS): targets = [self.deck.pop() for _ in range(self.WORDS)] await self.send("ROUND %s/%s\nWORDS: " % (n + 1, self.ROUNDS) + " ".join(t.emoji for t in targets)) self.deal(12) assigned = {p: random.choice(targets) for p in self.players} clues = await dib.smart_gather([ self.wait_for_text( p, "Your word: %s. Submit your clue!" % assigned[p], True, lambda t, p=p: self.valid_clue(t, p), "%s has submitted their clue!") for p in self.players ], self.players) for p in self.players: await self.send("%s's clue:\n%s\nGuess the word!" % (p.name, clues[p])) guessers = [o for o in self.players if o != p] guesses = await dib.smart_gather([ self.smart_options( g, True, targets, lambda t: t.text, "%s's clue:\n%s\nGuess the word!\nOptions: " % (p.name, clues[p])) for g in guessers ], guessers) correct = [ g for (g, guess) in guesses.items() if guess == assigned[p] ] if correct: await self.send( "%s got it right and recieve 1 point! %s recieves %s points! (The word was %s)" % (dib.smart_list([c.name for c in correct]), p.name, len(correct), assigned[p])) for c in correct: c.points += 1 p.points += len(correct) else: await self.send( "Nobody got it right! No points! The actual word was %s!" % assigned[p]) await self.show_scoreboard() await self.end_points()
async def run(self,*modifiers): defuse=cards.Defuse self.deck=[c() for c in cards.basedeck] bombs=[cards.ExplodingPenguin() for _ in self.players] + [c() for c in cards.spbombs] for p in self.players: p.hand.extend(random.sample(self.deck,self.START_HAND_SIZE)) for c in p.hand: self.deck.remove(c) p.hand.append(defuse()) self.deck.extend(bombs) random.shuffle(self.deck) random.shuffle(self.players) self.discards=[] await asyncio.gather(*(p.send_hand() for p in self.players)) while not self.done: await self.run_turn(self.cp) if self.survivors: await self.channel.send("GAME OVER! %s survived and gets 10c!" % dib.smart_list([s.name for s in self.survivors])) for s in self.survivors: s.user.update_balance(10) await self.end_game(self.survivors) else: await self.channel.send("GAME OVER! Unfortunately, nobody survived...")
def view(self): return dib.smart_list([c.name for c in self.contents])
async def run(self, *modifiers): self.grid = CodeGrid(V2(7, 7) if "extreme" in modifiers else V2(5, 5)) await self.send("Speak now if you wish to become master of the codes.") left_master = await self.wait_for_shout("") await self.send("%s has volunteered for red codemaster" % left_master.name) right_master = await self.wait_for_shout( "", [p for p in self.players if p != left_master]) remaining = [ p for p in self.players if p not in (left_master, right_master) ] random.shuffle(remaining) left_team = remaining[:len(remaining) // 2] right_team = remaining[len(remaining) // 2:] await self.send( "Red team: %s; lead by %s.\nBlue team: %s; led by %s." % (dib.smart_list([p.name for p in left_team]), left_master.name, dib.smart_list([p.name for p in right_team]), right_master.name)) masters = [left_master, right_master] teams = [left_team, right_team] self.grid.render_img(True) await right_master.dm("THE BOARD:", file=discord.File("codenames/board.png")) turn = 0 while not self.done: self.grid.render_img() await self.send("Current Board:", file=discord.File("codenames/board.png")) await self.send("%s's codemaster is thinking of a clue..." % self.team_names[turn].capitalize()) self.grid.render_img(True) await masters[turn].dm("Current Board:", file=discord.File("codenames/board.png")) clue = await self.wait_for_text(masters[turn], "Submit your clue!", True, self.grid.is_valid_clue) await self.send("THE CLUE: %s" % clue.upper()) word, num = clue.lower().split() guesses = 0 while num == "0" or num == "inf" or guesses <= int(num): guesses += 1 word = await self.choose_option( teams[turn], False, self.grid.leftover_words + ["pass"], "Guessing time!" if guesses == 1 else "The guessing continues...", True) if word == "pass": break colour = self.grid.wcols[word] self.grid.flipped.add(word) if colour in self.team_names: await self.send("%s was a %s team word!" % (word.upper(), colour)) if colour == self.team_names[ turn] and not self.grid.team_won( self.team_names[turn]): continue elif colour == "ASSASSIN": await self.send("%s was the assassin! Bad luck!" % word.upper()) await self.end_game(teams[not turn] + [masters[not turn]]) return else: await self.send("%s was neutral." % word.upper()) break if self.grid.team_won("RED"): await self.send("RED TEAM WINS!") await self.end_game(left_team + [left_master]) elif self.grid.team_won("BLUE"): await self.send("BLUE TEAM WINS!") await self.end_game(right_team + [right_master]) await self.send("Guessing phase over!") turn = 1 - turn
async def on_become(self,game:MUD,player:MPlayer): await super().on_become(game,player) fellows=[p for p in game.players if p is not player and isinstance(p.role,Impostor)] if fellows: await player.dm("Your fellow impostors are: %s" % dib.smart_list([f.mname for f in fellows]))
async def on_become(self,game:MUD,player:MPlayer): await super().on_become(game,player) player.items.append(items.Blaster()) fellows = [p for p in game.players if p is not player and isinstance(p.role, Security)] if fellows: await player.dm("Your fellow security guards are: %s" % dib.smart_list([f.mname for f in fellows]))
async def run(self, *modifiers): agnijo = "agnijo" in modifiers if agnijo: await self.send( ":warning::sleeping::warning: TIMER DISABLED :warning::sleeping::warning:" ) gs = GameState(":red_circle:", ":blue_circle:") random.shuffle(self.players) left_team = self.players[::2] right_team = self.players[1::2] codewords = random.sample(common, 8) teams = left_team, right_team codemaster = [0, 0] intercepts = [0, 0] miscoms = [0, 0] await self.send( "Team %s: %s\nTeam %s: %s" % (gs.emojis[0], dib.smart_list([p.name for p in left_team]), gs.emojis[1], dib.smart_list([p.name for p in right_team]))) for n in range(2): for p in teams[n]: await p.dm("Your codewords:\n" + "\n".join( dib.to_emoji(i + 1) + ": " + codewords[i * 2 + n].upper() for i in range(4))) for r in range(8): codemasters = [left_team[codemaster[0]], right_team[codemaster[1]]] await self.send("ROUND %s/8: Codemasters: %s and %s" % (r + 1, codemasters[0].name, codemasters[1].name)) codes = [random.choice(possible_codes) for _ in range(2)] clues = [None, None] tasks = [ self.wait_for_text( p, "Sequence to send: " + "".join(dib.to_emoji(c) for c in codes[n]) + "\nSubmit your clue, comma separated.", validation=get_valid_clue, confirmation="%s has submitted their clues!", faked="dog,cat,horse") for n, p in enumerate(codemasters) ] tasks = [asyncio.create_task(t) for t in tasks] await asyncio.wait(tasks, return_when=(asyncio.ALL_COMPLETED if agnijo else asyncio.FIRST_COMPLETED)) try: not_done = next(t for t in tasks if not t.done()) nidx = tasks.index(not_done) await self.send( "%s, you have %s seconds to submit your clue!" % (codemasters[nidx].tag, LEEWAY)) await asyncio.wait_for(not_done, LEEWAY) except StopIteration: pass except asyncio.TimeoutError: await self.send("Oh no! %s did not submit clues in time..." % codemasters[nidx].name) for n, t in enumerate(tasks): if not t.cancelled(): clues[n] = t.result() for e in gs.get_embeds(): await self.send(embed=e) guesses = None if r: await self.send( "Interception time!\n%s's clues: %s.\n%s's clues: %s" % (gs.emojis[0], clues[0] or "Not submitted", gs.emojis[1], clues[1] or "Not submitted")) guesses = await dib.gather([ self.wait_for_text(teams[n], "", False, get_guess, "%s's team submitted their guess!", random_guess()) for n in range(2) ]) guesses = [get_guess(g) for g in guesses] await self.send("Guessing time!\n%s's clues: %s.\n%s's clues: %s" % (gs.emojis[0], clues[0] or "Not submitted", gs.emojis[1], clues[1] or "Not submitted")) results = await dib.gather([ self.wait_for_text( [p for p in teams[n] if p != codemasters[n]], "", False, get_guess, "%s's team submitted their guess!", random_guess()) for n in range(2) ]) results = [get_guess(r) for r in results] failure = False for n in range(2): codemaster[n] += 1 codemaster[n] %= len(teams[n]) for idx, w in enumerate(codes[n]): if clues[n]: gs.add_clue(n, w, get_valid_clue(clues[n])[idx]) for n, e in enumerate(gs.emojis): if guesses and guesses[n] == codes[1 - n]: intercepts[n] += 1 await self.send("%s intercepted!" % e) failure = True if results[n] != codes[n]: miscoms[n] += 1 await self.send( "%s miscommunicated! The clue was actually %s" % (e, "".join(dib.to_emoji(c) for c in codes[n]))) failure = True if not failure: await self.send("Both teams were successful!") if any(t == 2 for t in intercepts + miscoms): break await self.send( "The game continues...\nCurrent miscommunications: %s\nCurrent interceptions: %s" % ("-".join(str(m) for m in miscoms), "-".join( str(i) for i in intercepts))) for e in gs.get_embeds(): await self.send(embed=e) totals = [intercepts[n]**2 - miscoms[n]**2 for n in range(2)] for e in gs.get_embeds(): await self.send(embed=e) if totals[0] > totals[1]: await self.send("%s wins!" % gs.emojis[0]) await self.end_game(left_team) elif totals[1] > totals[0]: await self.send("%s wins!" % gs.emojis[1]) await self.end_game(right_team) else: await self.send("It's a draw!") await self.end_game(right_team, draw=True)
async def run(self, *modifiers): random.shuffle(self.players) rounds = [ DrawfulRound(p, self.players[n - 1]) for n, p in enumerate(self.players) ] random.shuffle(rounds) await dib.gather([r.submit_phase(self) for r in rounds]) await dib.gather([r.draw_phase(self) for r in rounds]) await dib.gather( [p_guess_phase(p, self, rounds) for p in self.players]) await self.channel.send("It's voting time!") for r in rounds: smart_people = [] other_prompts = defaultdict(list) other_prompts[r.prompt].append(r.prompter) for p, guess in r.guesses.items(): if guess.lower() == r.prompt.lower(): smart_people.append(p) else: other_prompts[guess].append(p) if len(other_prompts) > 1: await self.channel.send( "%s drew this: %s\nWhat was the original prompt?" % (r.drawer.name, r.pic)) if smart_people: await self.channel.send( "%s guessed the prompt correctly and get %spts!" % (dib.smart_list([p.name for p in smart_people ]), self.SMART_POINTS)) for p in smart_people: p.points += self.SMART_POINTS opl = list(other_prompts.keys()) random.shuffle(opl) await self.channel.send("\n".join( "%s: %s" % (n + 1, prompt) for n, prompt in enumerate(opl))) guessers = [ p for p in r.get_others(self.players) if p not in smart_people ] guesses = await dib.smart_gather([ self.choose_number(g, True, 1, len(opl), "Guess which prompt is correct!") for g in guessers ], guessers) correct = opl.index(r.prompt) + 1 for p, g in guesses.items(): if g == correct: await self.channel.send( "%s guessed the correct prompt! They get %spts and the drawer gets %spt." % (p.name, self.GUESS_POINTS, self.GOOD_DRAWING_POINTS)) p.points += self.GUESS_POINTS r.drawer.points += self.GOOD_DRAWING_POINTS else: interceptors = other_prompts[opl[g - 1]] if p in interceptors: await self.channel.send( "%s guessed their own prompt! NO POINTS!" % p.name) else: await self.channel.send( "%s guessed %s's prompt! They get %spts!" % (p.name, dib.smart_list([ pp.name for pp in interceptors ]), self.INTERCEPT_POINTS)) for pp in interceptors: pp.points += self.INTERCEPT_POINTS else: await self.channel.send( "Everybody guessed the prompt correctly! Are you all psychic???" ) for p in r.get_others(self.players): p.points += self.SMART_POINTS await self.show_scoreboard(True) await self.end_points()
async def run(self,*modifiers): subset = random.sample(locations.keys(),self.SUBSET) for n in range(self.ROUNDS): await self.send(f"Round {n+1}/{self.ROUNDS}") spies = random.sample(self.players,1+len(self.players)//self.MULT) for p in self.players: p.done = False p.vote = True p.guess = None normies = [p for p in self.players if p not in spies] location = random.choice(subset) for n in normies: await n.dm(f"You are in the {emojified(location)}! Find the spy!") for s in spies: await s.dm("You are a spy! Find out the location before you're found out!") first = random.choice(self.players) await self.send("Anyone can accuse someone by tagging them in this chat.\n%s, you're asking the first question!" % first.tag) timer = dib.TextTimer(8*60,self.channel) while not all(s.done for s in spies) and any(n.vote for n in normies): undone = [p for p in self.players if not p.done] can_call_votes = [p for p in undone if p.vote] done,pending = await asyncio.wait([s.spy_phase(self,subset) for s in spies if not s.done]+[timer.run(),self.wait_for_tag(can_call_votes,undone)], return_when=asyncio.FIRST_COMPLETED) for p in pending: p.cancel() if timer.done: await self.send("TIME'S UP! All surviving spies (%s) get points!" % dib.smart_list([s.name for s in spies])) for s in spies: if not s.done: s.points+=1 break else: for d in done: res = d.result() if isinstance(res,Agent): self.dunnit.vote = False await self.send(f"{self.dunnit.name} has accused {res.name} of being a spy!") votes = await dib.gather([self.choose_option(p,True,["yes","no"],f"Is {res.name} a spy?",True) for p in undone if p not in spies and p!=res]) successful = all(v=="yes" for v in votes) if successful: await self.send("The vote was successful!") if res in spies: await self.send(f"{res.name} was a spy!") res.done=True for n in normies: n.points+=1 else: await self.send(f"Oh no! {res.name} wasn't a spy! You idiots!") for s in spies: s.points+=1 s.done=True else: await self.send("The vote wasn't successful. The game continues...") else: for s in spies: if s.guess and not s.done: s.done = True if s.guess==location: await self.send(f"{s.name} was a spy, and guessed the location correctly!") s.points+=1 else: await self.send(f"{s.name} was a spy, and got the location wrong!") s.points-=1 await self.send(f"(The location was {location})") await self.show_scoreboard(n==self.ROUNDS-1) await self.end_points()