def apply_action(self): g = Game.getgame() params = self.params from thb.cards import Deck g.stats = [] g.deck = Deck() g.ehclasses = [] if params['random_force']: seed = get_seed_for(g.players) random.Random(seed).shuffle(g.players) g.draw_extra_card = params['draw_extra_card'] f1 = BatchList() f2 = BatchList() g.forces = BatchList([f1, f2]) H, M = Identity.TYPE.HAKUREI, Identity.TYPE.MORIYA for p, id, f in zip(g.players, [H, H, M, M], [f1, f1, f2, f2]): p.identity = Identity() p.identity.type = id p.force = f f.append(p) pl = g.players for p in pl: g.process_action(RevealIdentity(p, pl)) roll_rst = roll(g, self.items) f1, f2 = partition(lambda p: p.force is roll_rst[0].force, roll_rst) final_order = [f1[0], f2[0], f2[1], f1[1]] g.players[:] = final_order g.emit_event('reseat', None) # ban / choose girls --> from . import characters chars = characters.get_characters('common', '2v2') seed = get_seed_for(g.players) random.Random(seed).shuffle(chars) testing = list(settings.TESTING_CHARACTERS) testing, chars = partition(lambda c: c.__name__ in testing, chars) chars.extend(testing) chars = chars[-20:] choices = [CharChoice(cls) for cls in chars] banned = set() mapping = {p: choices for p in g.players} with InputTransaction('BanGirl', g.players, mapping=mapping) as trans: for p in g.players: c = user_input([p], ChooseGirlInputlet(g, mapping), timeout=30, trans=trans) c = c or [_c for _c in choices if not _c.chosen][0] c.chosen = p banned.add(c.char_cls) trans.notify('girl_chosen', (p, c)) assert len(banned) == 4 g.stats.extend([ {'event': 'ban', 'attributes': { 'gamemode': g.__class__.__name__, 'character': i.__name__ }} for i in banned ]) chars = [_c for _c in chars if _c not in banned] g.random.shuffle(chars) if Game.CLIENT_SIDE: chars = [None] * len(chars) for p in g.players: p.choices = [CharChoice(cls) for cls in chars[-4:]] p.choices[-1].akari = True del chars[-4:] p.reveal(p.choices) g.pause(1) mapping = {p: p.choices for p in g.players} with InputTransaction('ChooseGirl', g.players, mapping=mapping) as trans: ilet = ChooseGirlInputlet(g, mapping) @ilet.with_post_process def process(p, c): c = c or p.choices[0] trans.notify('girl_chosen', (p, c)) return c rst = user_input(g.players, ilet, timeout=30, type='all', trans=trans) # reveal for p, c in rst.items(): c.akari = False g.players.reveal(c) g.set_character(p, c.char_cls) # ------- for p in g.players: log.info( u'>> Player: %s:%s %s', p.__class__.__name__, Identity.TYPE.rlookup(p.identity.type), p.account.username, ) # ------- g.emit_event('game_begin', g) for p in g.players: g.process_action(DistributeCards(p, amount=4)) for i, p in enumerate(cycle(pl)): if i >= 6000: break if not p.dead: g.emit_event('player_turn', p) try: g.process_action(PlayerTurn(p)) except InterruptActionFlow: pass return True
def apply_action(self): g = Game.getgame() params = self.params from thb.cards import Deck g.stats = [] g.deck = Deck() g.ehclasses = [] if params['random_force']: seed = get_seed_for(g.players) random.Random(seed).shuffle(g.players) g.draw_extra_card = params['draw_extra_card'] f1 = BatchList() f2 = BatchList() g.forces = BatchList([f1, f2]) H, M = Identity.TYPE.HAKUREI, Identity.TYPE.MORIYA for p, id, f in zip(g.players, [H, H, M, M], [f1, f1, f2, f2]): p.identity = Identity() p.identity.type = id p.force = f f.append(p) pl = g.players for p in pl: g.process_action(RevealIdentity(p, pl)) roll_rst = roll(g, self.items) f1, f2 = partition(lambda p: p.force is roll_rst[0].force, roll_rst) final_order = [f1[0], f2[0], f2[1], f1[1]] g.players[:] = final_order g.emit_event('reseat', None) # ban / choose girls --> from . import characters chars = characters.get_characters('common', '2v2') seed = get_seed_for(g.players) random.Random(seed).shuffle(chars) # ANCHOR(test) testing = list(settings.TESTING_CHARACTERS) testing, chars = partition(lambda c: c.__name__ in testing, chars) chars.extend(testing) chars = chars[-20:] choices = [CharChoice(cls) for cls in chars] banned = set() mapping = {p: choices for p in g.players} with InputTransaction('BanGirl', g.players, mapping=mapping) as trans: for p in g.players: c = user_input([p], ChooseGirlInputlet(g, mapping), timeout=30, trans=trans) c = c or [_c for _c in choices if not _c.chosen][0] c.chosen = p banned.add(c.char_cls) trans.notify('girl_chosen', (p, c)) assert len(banned) == 4 g.stats.extend([{ 'event': 'ban', 'attributes': { 'gamemode': g.__class__.__name__, 'character': i.__name__ } } for i in banned]) chars = [_c for _c in chars if _c not in banned] g.random.shuffle(chars) if Game.CLIENT_SIDE: chars = [None] * len(chars) for p in g.players: p.choices = [CharChoice(cls) for cls in chars[-4:]] p.choices[-1].as_akari = True del chars[-4:] p.reveal(p.choices) g.pause(1) mapping = {p: p.choices for p in g.players} with InputTransaction('ChooseGirl', g.players, mapping=mapping) as trans: ilet = ChooseGirlInputlet(g, mapping) @ilet.with_post_process def process(p, c): c = c or p.choices[0] trans.notify('girl_chosen', (p, c)) return c rst = user_input(g.players, ilet, timeout=30, type='all', trans=trans) # reveal for p, c in rst.items(): c.as_akari = False g.players.reveal(c) g.set_character(p, c.char_cls) # ------- for p in g.players: log.info( u'>> Player: %s:%s %s', p.__class__.__name__, Identity.TYPE.rlookup(p.identity.type), p.account.username, ) # ------- g.emit_event('game_begin', g) for p in g.players: g.process_action(DistributeCards(p, amount=4)) for i, p in enumerate(cycle(pl)): if i >= 6000: break if not p.dead: g.emit_event('player_turn', p) try: g.process_action(PlayerTurn(p)) except InterruptActionFlow: pass return True
def apply_action(self): g = Game.getgame() params = self.params from thb.cards import Deck g.picks = [] g.deck = Deck() g.ehclasses = list(action_eventhandlers) + g.game_ehs.values() H, M = Identity.TYPE.HAKUREI, Identity.TYPE.MORIYA if params['random_seat']: # reseat seed = get_seed_for(g.players) random.Random(seed).shuffle(g.players) g.emit_event('reseat', None) L = [[H, H, M, M, H, M], [H, M, H, M, H, M]] rnd = random.Random(get_seed_for(g.players)) L = rnd.choice(L) * 2 s = rnd.randrange(0, 6) idlist = L[s:s+6] del L, s, rnd else: idlist = [H, M, H, M, H, M] del H, M for p, identity in zip(g.players, idlist): p.identity = Identity() p.identity.type = identity g.process_action(RevealIdentity(p, g.players)) force_hakurei = BatchList() force_moriya = BatchList() force_hakurei.pool = [] force_moriya.pool = [] for p in g.players: if p.identity.type == Identity.TYPE.HAKUREI: force_hakurei.append(p) p.force = force_hakurei elif p.identity.type == Identity.TYPE.MORIYA: force_moriya.append(p) p.force = force_moriya g.forces = BatchList([force_hakurei, force_moriya]) roll_rst = roll(g, self.items) first = roll_rst[0] # choose girls --> from . import characters chars = characters.get_characters('common', 'faith') choices, _ = build_choices( g, self.items, candidates=chars, players=g.players, num=[4] * 6, akaris=[1] * 6, shared=False, ) rst = user_input(g.players, SortCharacterInputlet(g, choices, 2), timeout=30, type='all') for p in g.players: a, b = [choices[p][i] for i in rst[p][:2]] b.chosen = None p.force.reveal(b) g.switch_character(p, a) p.force.pool.append(b) for p in g.players: if p.player is first: first = p break pl = g.players first_index = pl.index(first) order = BatchList(range(len(pl))).rotate_to(first_index) for p in pl: g.process_action(RevealIdentity(p, pl)) g.emit_event('game_begin', g) for p in pl: g.process_action(DistributeCards(p, amount=4)) pl = g.players.rotate_to(first) rst = user_input(pl[1:], ChooseOptionInputlet(DeathHandler(), (False, True)), type='all') for p in pl[1:]: rst.get(p) and g.process_action(RedrawCards(p, p)) pl = g.players for i, idx in enumerate(cycle(order)): if i >= 6000: break p = pl[idx] if p.dead: continue g.emit_event('player_turn', p) try: g.process_action(PlayerTurn(p)) except InterruptActionFlow: pass return True
def apply_action(self): g = Game.getgame() params = self.params from thb.cards import Deck g.deck = Deck() g.ehclasses = [] if params['random_seat']: seed = get_seed_for(g.players) random.Random(seed).shuffle(g.players) g.emit_event('reseat', None) for i, p in enumerate(g.players): p.identity = Identity() p.identity.type = (Identity.TYPE.HAKUREI, Identity.TYPE.MORIYA)[i % 2] g.forces = forces = BatchList([BatchList(), BatchList()]) for i, p in enumerate(g.players): f = i % 2 p.force = f forces[f].append(p) pl = g.players for p in pl: g.process_action(RevealIdentity(p, pl)) from . import characters chars = characters.get_characters('common', '3v3') choices, imperial_choices = build_choices( g, self.items, candidates=chars, players=g.players, num=16, akaris=4, shared=True, ) roll_rst = roll(g, self.items) first = roll_rst[0] first_index = g.players.index(first) order_list = (0, 5, 3, 4, 2, 1) n = len(order_list) order = [g.players[(first_index + i) % n] for i in order_list] akaris = [] with InputTransaction('ChooseGirl', g.players, mapping=choices) as trans: chosen = set() for p, c in imperial_choices: chosen.add(p) c.chosen = p g.set_character(p, c.char_cls) trans.notify('girl_chosen', (p, c)) for p in order: if p in chosen: continue c = user_input([p], ChooseGirlInputlet(g, choices), timeout=30, trans=trans) c = c or [_c for _c in reversed(choices[p]) if not _c.chosen][0] c.chosen = p if c.akari: c.akari = False akaris.append((p, c)) else: g.set_character(p, c.char_cls) trans.notify('girl_chosen', (p, c)) # reveal akaris if akaris: g.players.reveal([i[1] for i in akaris]) for p, c in akaris: g.set_character(p, c.char_cls) # ------- for p in g.players: log.info( u'>> Player: %s:%s %s', p.__class__.__name__, Identity.TYPE.rlookup(p.identity.type), p.account.username, ) # ------- first = g.players[first_index] g.emit_event('game_begin', g) for p in g.players: g.process_action(DrawCards(p, amount=3 if p is first else 4)) pl = g.players.rotate_to(first) for i, p in enumerate(cycle(pl)): if i >= 6000: break if not p.dead: g.emit_event('player_turn', p) try: g.process_action(PlayerTurn(p)) except InterruptActionFlow: pass return True
def apply_action(self): g = Game.getgame() from . import cards g.pick_history = [] g.deck = cards.Deck(cards.kof_card_definition) g.ehclasses = [] g.current_player = None for i, p in enumerate(g.players): p.identity = Identity() p.identity.type = (Identity.TYPE.HAKUREI, Identity.TYPE.MORIYA)[i % 2] # choose girls --> from thb.characters import get_characters chars = get_characters('common', 'kof') A, B = roll(g, self.items) order = [A, B, B, A, A, B, B, A, A, B] choices, imperial_choices = build_choices( g, self.items, candidates=chars, players=[A, B], num=10, akaris=4, shared=True, ) chosen = {A: [], B: []} with InputTransaction('ChooseGirl', g.players, mapping=choices) as trans: for p, c in imperial_choices: c.chosen = p chosen[p].append(c) trans.notify('girl_chosen', (p, c)) order.remove(p) for p in order: c = user_input([p], ChooseGirlInputlet(g, choices), 10, 'single', trans) c = c or first(choices[p], lambda c: not c.chosen) c.chosen = p chosen[p].append(c) trans.notify('girl_chosen', (p, c)) # reveal akaris for themselves for p in [A, B]: for c in chosen[p]: c.akari = False p.reveal(c) del c.chosen list_shuffle(chosen[A], A) list_shuffle(chosen[B], B) with InputTransaction('ChooseGirl', g.players, mapping=chosen) as trans: ilet = ChooseGirlInputlet(g, chosen) ilet.with_post_process(lambda p, rst: trans.notify('girl_chosen', (p, rst)) or rst) rst = user_input([A, B], ilet, type='all', trans=trans) def s(p): c = rst[p] or chosen[p][0] chosen[p].remove(c) p.choices = chosen[p] p.remaining = [2] p = g.next_character(p, c) return p A, B = s(A), s(B) order = [1, 0] if A is g.players[0] else [0, 1] for p in [A, B]: g.process_action(RevealIdentity(p, g.players)) g.emit_event('game_begin', g) g.process_action(DistributeCards(A, amount=4)) g.process_action(DistributeCards(B, amount=3)) for i in order: g.emit_event('character_debut', (None, g.players[i])) for i, idx in enumerate(cycle(order)): p = g.players[idx] if i >= 6000: break if p.dead: KOFCharacterSwitchHandler.do_switch_dead() p = g.players[idx] # player changed assert not p.dead try: g.emit_event('player_turn', p) g.process_action(PlayerTurn(p)) except InterruptActionFlow: pass
def apply_action(self): g = Game.getgame() params = self.params from thb.cards import Deck g.picks = [] g.deck = Deck() g.ehclasses = list(action_eventhandlers) + g.game_ehs.values() H, M = Identity.TYPE.HAKUREI, Identity.TYPE.MORIYA if params['random_seat']: # reseat seed = get_seed_for(g.players) random.Random(seed).shuffle(g.players) g.emit_event('reseat', None) L = [[H, H, M, M, H, M], [H, M, H, M, H, M]] rnd = random.Random(get_seed_for(g.players)) L = rnd.choice(L) * 2 s = rnd.randrange(0, 6) idlist = L[s:s + 6] del L, s, rnd else: idlist = [H, M, H, M, H, M] del H, M for p, identity in zip(g.players, idlist): p.identity = Identity() p.identity.type = identity g.process_action(RevealIdentity(p, g.players)) force_hakurei = BatchList() force_moriya = BatchList() force_hakurei.pool = [] force_moriya.pool = [] for p in g.players: if p.identity.type == Identity.TYPE.HAKUREI: force_hakurei.append(p) p.force = force_hakurei elif p.identity.type == Identity.TYPE.MORIYA: force_moriya.append(p) p.force = force_moriya g.forces = BatchList([force_hakurei, force_moriya]) roll_rst = roll(g, self.items) first = roll_rst[0] # choose girls --> from . import characters chars = characters.get_characters('common', 'faith') choices, _ = build_choices( g, self.items, candidates=chars, players=g.players, num=[4] * 6, akaris=[1] * 6, shared=False, ) rst = user_input(g.players, SortCharacterInputlet(g, choices, 2), timeout=30, type='all') for p in g.players: a, b = [choices[p][i] for i in rst[p][:2]] b.chosen = None p.force.reveal(b) g.switch_character(p, a) p.force.pool.append(b) for p in g.players: if p.player is first: first = p break pl = g.players first_index = pl.index(first) order = BatchList(range(len(pl))).rotate_to(first_index) for p in pl: g.process_action(RevealIdentity(p, pl)) g.emit_event('game_begin', g) for p in pl: g.process_action(DistributeCards(p, amount=4)) pl = g.players.rotate_to(first) rst = user_input(pl[1:], ChooseOptionInputlet(DeathHandler(), (False, True)), type='all') for p in pl[1:]: rst.get(p) and g.process_action(RedrawCards(p, p)) pl = g.players for i, idx in enumerate(cycle(order)): if i >= 6000: break p = pl[idx] if p.dead: continue g.emit_event('player_turn', p) try: g.process_action(PlayerTurn(p)) except InterruptActionFlow: pass return True