def game_start(g): # game started, init state from cards import Deck, CardList g.deck = Deck() ehclasses = list(action_eventhandlers) + _game_ehs.values() for p in g.players: p.cards = CardList(p, 'cards') # Cards in hand p.showncards = CardList(p, 'showncards') # Cards which are shown to the others, treated as 'Cards in hand' p.equips = CardList(p, 'equips') # Equipments p.fatetell = CardList(p, 'fatetell') # Cards in the Fatetell Zone p.special = CardList(p, 'special') # used on special purpose p.showncardlists = [p.showncards, p.fatetell] # cardlists should shown to others p.tags = defaultdict(int) p.dead = False # choose girls init --> from characters import characters as chars chars = list(chars) if Game.CLIENT_SIDE: chars = [None] * len(chars) g.random.shuffle(chars) # choose boss idx = sync_primitive(g.random.randrange(len(g.players)), g.players) boss = g.boss = g.players[idx] boss.identity = Identity() boss.identity.type = Identity.TYPE.BOSS g.process_action(RevealIdentity(boss, g.players)) boss.choices = [CharChoice(c) for c in chars[:4]] del chars[:4] for p in g.players.exclude(boss): p.choices = [CharChoice(c) for c in chars[:3]] del chars[:3] for p in g.players: p.reveal(p.choices) mapping = {boss: boss.choices} with InputTransaction('ChooseGirl', [boss], mapping=mapping) as trans: c = user_input([boss], ChooseGirlInputlet(g, mapping), 30, 'single', trans) c = c or CharChoice(chars.pop()) c.chosen = boss g.players.reveal(c) trans.notify('girl_chosen', c) # mix it in advance # so the others could see it mixin_character(boss, c.char_cls) boss.skills = list(boss.skills) # make it instance variable ehclasses.extend(boss.eventhandlers_required) # boss's hp bonus if len(g.players) > 5: boss.maxlife += 1 boss.life = boss.maxlife # reseat seed = get_seed_for(g.players) random.Random(seed).shuffle(g.players) g.emit_event('reseat', None) # tell the others their own identity il = list(g.identities) g.random.shuffle(il) for p in g.players.exclude(boss): p.identity = Identity() id = il.pop() if Game.SERVER_SIDE: p.identity.type = id g.process_action(RevealIdentity(p, p)) pl = g.players.exclude(boss) mapping = {p: p.choices for p in pl} # CAUTION, DICT HERE with InputTransaction('ChooseGirl', pl, mapping=mapping) as trans: ilet = ChooseGirlInputlet(g, mapping) ilet.with_post_process(lambda p, rst: trans.notify('girl_chosen', rst) or rst) result = user_input(pl, ilet, type='all', trans=trans) # not enough chars for random, reuse unselected for p in pl: if result[p]: result[p].chosen = p chars.extend([i.char_cls for i in p.choices if not i.chosen]) seed = get_seed_for(g.players) random.Random(seed).shuffle(chars) # mix char class with player --> for p in pl: c = result[p] c = c or CharChoice(chars.pop()) g.players.reveal(c) mixin_character(p, c.char_cls) p.skills = list(p.skills) # make it instance variable p.life = p.maxlife ehclasses.extend(p.eventhandlers_required) g.event_handlers = EventHandler.make_list(ehclasses) g.emit_event('game_begin', g) try: for p in g.players: g.process_action(DrawCards(p, amount=4)) pl = g.players.rotate_to(boss) for i, p in enumerate(cycle(pl)): if i >= 6000: break if not p.dead: try: g.process_action(PlayerTurn(p)) except InterruptActionFlow: pass except GameEnded: pass
def game_start(g): # game started, init state from cards import CardList g.action_types[LaunchCard] = RaidLaunchCard g.action_types[ActionStageLaunchCard] = RaidActionStageLaunchCard ehclasses = g.ehclasses = [] for p in g.players: p.cards = CardList(p, 'cards') # Cards in hand p.showncards = CardList(p, 'showncards') # Cards which are shown to the others, treated as 'Cards in hand' p.equips = CardList(p, 'equips') # Equipments p.fatetell = CardList(p, 'fatetell') # Cards in the Fatetell Zone p.faiths = CardList(p, 'faiths') # 'faith' cards p.special = CardList(p, 'special') # used on special purpose p.showncardlists = [p.showncards, p.faiths, p.fatetell] # cardlists should shown to others p.tags = defaultdict(int) p.tags['faithcounter'] = True # for ui p.dead = False # reveal identities mutant = g.mutant = g.players[0] attackers = g.attackers = BatchList(g.players[1:]) mutant.identity = Identity() mutant.identity.type = Identity.TYPE.MUTANT g.process_action(RevealIdentity(mutant, g.players)) for p in attackers: p.identity = Identity() p.identity.type = Identity.TYPE.ATTACKER g.process_action(RevealIdentity(p, g.players)) # mutant's choose from characters import ex_characters as ex_chars choices = [CharChoice(cls) for cls in ex_chars] mapping = {mutant: choices} with InputTransaction('ChooseGirl', [mutant], mapping=mapping) as trans: c = user_input([mutant], ChooseGirlInputlet(g, mapping), timeout=5, trans=trans) c = c or choices[0] c.chosen = mutant trans.notify('girl_chosen', c) # mix it in advance # so the others could see it mixin_character(mutant, c.char_cls) mutant.skills = list(mutant.skills) # make it instance variable ehclasses.extend(mutant.eventhandlers_required) mutant.life = mutant.maxlife mutant.morphed = False # init deck & mutant's initial equip # (SinsackCard, SPADE, 1) # (SinsackCard, HEART, Q) from cards import Deck, SinsackCard, ElementalReactorCard, card_definition raid_carddef = [ carddef for carddef in card_definition if carddef[0] not in (SinsackCard, ElementalReactorCard) ] g.deck = Deck(raid_carddef) # attackers' choose from characters import characters as chars chars = list(chars) seed = get_seed_for(g.players) random.Random(seed).shuffle(chars) for p in g.attackers: p.choices = [CharChoice(cls) for cls in chars[:5]] del chars[:5] # ----------- mapping = {p: p.choices for p in g.attackers} with InputTransaction('ChooseGirl', g.attackers, mapping=mapping) as trans: ilet = ChooseGirlInputlet(g, mapping) ilet.with_post_process(lambda p, rst: trans.notify('girl_chosen', rst) or rst) result = user_input(g.attackers, ilet, 30, 'all', trans) # mix char class with player --> for p in g.attackers: c = result[p] or CharChoice(chars.pop()) c.chosen = p mixin_character(p, c.char_cls) p.skills = list(p.skills) # make it instance variable p.skills.extend([ Cooperation, Protection, Parry, OneUp, ]) p.life = p.maxlife ehclasses.extend(p.eventhandlers_required) g.update_event_handlers() g.emit_event('game_begin', g) # ------- log.info(u'>> Game info: ') log.info(u'>> Mutant: %s', mutant.char_cls.__name__) for p in attackers: log.info(u'>> Attacker: %s', p.char_cls.__name__) # ------- try: g.process_action(DrawCards(mutant, amount=6)) for p in attackers: g.process_action(DrawCards(p, amount=4)) # stage 1 try: for i in xrange(500): g.process_action(CollectFaith(mutant, mutant, 1)) avail = [p for p in attackers if not p.dead and len(p.faiths) < 5] if avail: p, _ = user_input( avail, ChooseOptionInputlet(GetFaith, (None, True)), type='any', ) p = p or avail[0] g.process_action(CollectFaith(p, p, 1)) g.emit_event('round_start', False) for p in attackers: p.tags['action'] = True while True: try: g.process_action(PlayerTurn(mutant)) except InterruptActionFlow: pass avail = BatchList([p for p in attackers if p.tags['action'] and not p.dead]) if not avail: break p, _ = user_input( avail, ChooseOptionInputlet(RequestAction, (None, True)), type='any', ) p = p or avail[0] p.tags['action'] = False try: g.process_action(PlayerTurn(p)) except InterruptActionFlow: pass if not [p for p in attackers if p.tags['action'] and not p.dead]: break except MutantMorph: pass # morphing stage1 = mutant.__class__ stage2 = stage1.stage2 for s in stage1.skills: try: mutant.skills.remove(s) except ValueError: pass mutant.skills.extend(stage2.skills) ehclasses = g.ehclasses for s in stage1.eventhandlers_required: try: ehclasses.remove(s) except ValueError: pass ehclasses.extend(stage2.eventhandlers_required) g.process_action( MaxLifeChange(mutant, mutant, -(stage1.maxlife // 2)) ) mutant.morphed = True mixin_character(mutant, stage2) g.update_event_handlers() for p in attackers: g.process_action(CollectFaith(p, p, 1)) g.process_action(DropCards(mutant, mutant.fatetell)) g.emit_event('mutant_morph', mutant) g.pause(4) # stage 2 for i in xrange(500): g.process_action(CollectFaith(mutant, mutant, 1)) avail = [p for p in attackers if not p.dead and len(p.faiths) < 5] if avail: p, _ = user_input( avail, ChooseOptionInputlet(GetFaith, (None, True)), type='any', ) p = p or avail[0] g.process_action(CollectFaith(p, p, 1)) g.emit_event('round_start', False) for p in attackers: p.tags['action'] = True try: g.process_action(PlayerTurn(mutant)) except InterruptActionFlow: pass while True: avail = BatchList([p for p in attackers if p.tags['action'] and not p.dead]) if not avail: break p, _ = user_input( avail, ChooseOptionInputlet(RequestAction, (None, True)), type='any' ) p = p or avail[0] p.tags['action'] = False try: g.process_action(PlayerTurn(p)) except InterruptActionFlow: pass except GameEnded: pass winner_force = 'Mutant' if g.winners == [mutant] else 'Attackers' log.info(u'>> Winner: %s', winner_force)
def game_start(g): # game started, init state g.action_types[LaunchCard] = RaidLaunchCard g.action_types[ActionStageLaunchCard] = RaidActionStageLaunchCard g.ehclasses = [] # reveal identities mutant = g.mutant = g.players[0] attackers = g.attackers = BatchList(g.players[1:]) mutant.identity = Identity() mutant.identity.type = Identity.TYPE.MUTANT g.process_action(RevealIdentity(mutant, g.players)) for p in attackers: p.identity = Identity() p.identity.type = Identity.TYPE.ATTACKER g.process_action(RevealIdentity(p, g.players)) # mutant's choose from characters import ex_characters as ex_chars choices = [CharChoice(cls) for cls in ex_chars] mapping = {mutant: choices} with InputTransaction('ChooseGirl', [mutant], mapping=mapping) as trans: c = user_input([mutant], ChooseGirlInputlet(g, mapping), timeout=5, trans=trans) c = c or choices[0] c.chosen = mutant trans.notify('girl_chosen', c) # mix it in advance # so the others could see it g.mutant = mutant = g.switch_character(mutant, c.char_cls) mutant.life = mutant.maxlife mutant.morphed = False # init deck & mutant's initial equip # (SinsackCard, SPADE, 1) # (SinsackCard, HEART, Q) from cards import Deck, SinsackCard, ElementalReactorCard, card_definition raid_carddef = [ carddef for carddef in card_definition if carddef[0] not in (SinsackCard, ElementalReactorCard) ] g.deck = Deck(raid_carddef) # attackers' choose from characters import characters as chars chars = list(chars) seed = get_seed_for(g.players) random.Random(seed).shuffle(chars) for p in g.attackers: p.choices = [CharChoice(cls) for cls in chars[:5]] del chars[:5] # ----------- mapping = {p: p.choices for p in g.attackers} with InputTransaction('ChooseGirl', g.attackers, mapping=mapping) as trans: ilet = ChooseGirlInputlet(g, mapping) ilet.with_post_process( lambda p, rst: trans.notify('girl_chosen', rst) or rst) result = user_input(g.attackers, ilet, 30, 'all', trans) # mix char class with player --> for p in g.attackers: c = result[p] or CharChoice(chars.pop()) c.chosen = p p = g.switch_character(p, c.char_cls) p.skills.extend([ Cooperation, Protection, Parry, OneUp, ]) g.update_event_handlers() g.emit_event('game_begin', g) # ------- log.info(u'>> Game info: ') log.info(u'>> Mutant: %s', mutant.__class__.__name__) for p in attackers: log.info(u'>> Attacker: %s', p.__class__.__name__) # ------- try: g.process_action(DrawCards(mutant, amount=6)) for p in attackers: g.process_action(DrawCards(p, amount=4)) # stage 1 try: for i in xrange(500): g.process_action(CollectFaith(mutant, mutant, 1)) avail = [ p for p in attackers if not p.dead and len(p.faiths) < 5 ] if avail: p, _ = user_input( avail, ChooseOptionInputlet(GetFaith, (None, True)), type='any', ) p = p or avail[0] g.process_action(CollectFaith(p, p, 1)) g.emit_event('round_start', False) for p in attackers: p.tags['action'] = True while True: try: g.process_action(PlayerTurn(mutant)) except InterruptActionFlow: pass avail = BatchList([ p for p in attackers if p.tags['action'] and not p.dead ]) if not avail: break p, _ = user_input( avail, ChooseOptionInputlet(RequestAction, (None, True)), type='any', ) p = p or avail[0] p.tags['action'] = False try: g.process_action(PlayerTurn(p)) except InterruptActionFlow: pass if not [ p for p in attackers if p.tags['action'] and not p.dead ]: break except MutantMorph: pass # morphing stage1 = mutant.__class__ stage2 = stage1.stage2 for s in stage1.skills: try: mutant.skills.remove(s) except ValueError: pass mutant.skills.extend(stage2.skills) ehclasses = g.ehclasses for s in stage1.eventhandlers_required: try: ehclasses.remove(s) except ValueError: pass ehclasses.extend(stage2.eventhandlers_required) g.process_action( MaxLifeChange(mutant, mutant, -(stage1.maxlife // 2))) mutant.morphed = True mutant.__class__ = stage2 g.update_event_handlers() for p in attackers: g.process_action(CollectFaith(p, p, 1)) g.process_action(DropCards(mutant, mutant.fatetell)) g.emit_event('mutant_morph', mutant) g.pause(4) # stage 2 for i in xrange(500): g.process_action(CollectFaith(mutant, mutant, 1)) avail = [ p for p in attackers if not p.dead and len(p.faiths) < 5 ] if avail: p, _ = user_input( avail, ChooseOptionInputlet(GetFaith, (None, True)), type='any', ) p = p or avail[0] g.process_action(CollectFaith(p, p, 1)) g.emit_event('round_start', False) for p in attackers: p.tags['action'] = True try: g.process_action(PlayerTurn(mutant)) except InterruptActionFlow: pass while True: avail = BatchList([ p for p in attackers if p.tags['action'] and not p.dead ]) if not avail: break p, _ = user_input(avail, ChooseOptionInputlet( RequestAction, (None, True)), type='any') p = p or avail[0] p.tags['action'] = False try: g.process_action(PlayerTurn(p)) except InterruptActionFlow: pass except GameEnded: pass winner_force = 'Mutant' if g.winners == [mutant] else 'Attackers' log.info(u'>> Winner: %s', winner_force)