def richii_command(event: TenhouEvent, ctx): player_id = int(event.attrib["who"]) cmd = Builder(GameCommand) with cmd.when(sub_scope=player_id): if event.attrib["step"] == "1": yield cmd(update=Update.REPLACE, prop=PlayerView.in_richii, value=True) elif event.attrib["step"] == "2": yield cmd(update=Update.REMOVE, prop=PlayerView.score, value=1000)
def no_win_command(event: TenhouEvent, ctx): cmd = Builder(GameCommand) with cmd.when(update=Update.REPLACE): yield cmd(prop=GameView.nobody_win, value=True) yield cmd(prop=GameView.extra_reason, value=DRAWN_TYPES[event.attrib["type"]] if "type" in event.attrib else "EXHAUSTED") sc_list = number_list(event.attrib["sc"]) if "sc" in event.attrib else None yield from game_finish(cmd, ctx, math.nan, math.nan, sc_list, [], event)
def open_hand(event: TenhouEvent, ctx): meld = meld_from(event) cmd = Builder(GameCommand) with cmd.when(sub_scope=int(event.attrib["who"])): with cmd.when(update=Update.ADD): yield cmd(prop=PlayerView.meld_public_tiles, value=tile_str_list(meld.self_tiles)) meld_value = tile_str_list(meld.self_tiles | meld.borrowed_tiles) if not isinstance(meld, Kita): yield cmd(prop=PlayerView.fixed_meld, value=[meld_value]) else: yield cmd(prop=PlayerView.bonus_tiles, value=meld_value) with cmd.when(update=Update.REMOVE): yield from hand_update(cmd, meld.self_tiles, ctx)
def discard_command(event: TenhouEvent, ctx): discard = discard_tile_tenhou(event) cmd = Builder(GameCommand) if discard: tile_raw = discard['tile'] player_id = discard['player'] with cmd.when( sub_scope=player_id, value=tile_str_list([tile_raw]), ): yield cmd(prop=PlayerView.round, update=Update.ADD, value=1) discard = int(tile_raw) draw_tile = ctx[(player_id, "_right_most_tile_int")] yield cmd(prop=PlayerView.discard_from_hand, update=Update.ADD, value=[discard != draw_tile]) with cmd.when(update=Update.REMOVE): yield from hand_update(cmd, str(tile_raw), ctx) yield cmd(prop=PlayerView.discard_tiles, update=Update.ADD)
def agari_command(event: TenhouEvent, ctx): _not_fully_support(event) player_id = int(event.attrib["who"]) from_player_id = int(event.attrib["fromWho"]) sc_list = number_list(event.attrib["sc"]) cmd = Builder(GameCommand) with cmd.when(update=Update.ASSERT_EQUAL_OR_SET, sub_scope=player_id): expected_hand = tile_str_list(event.attrib["hai"]) if player_id != from_player_id: expected_hand.remove(tile_str_list(event.attrib["machi"])[0]) yield cmd(prop=PlayerView.hand, value=expected_hand) with cmd.when(update=Update.REPLACE): yield cmd(prop=GameView.nobody_win, value=False) attr = event.attrib yaku = list( map(lambda t: SCORE_PATTERN[t], number_list(attr.get("yaku", attr.get("yakuman"))))) yield from game_finish(cmd, ctx, from_player_id, player_id, sc_list, yaku, event)
def game_init_command(event: TenhouEvent, ctx): _not_fully_support(event) seed = number_list(event.attrib["seed"]) game_indexer = ctx["_game_indexer"] sub_game = seed[1] richii_counts = seed[2] initial_dora = seed[-1] cmd = Builder(GameCommand) with cmd.when(update=Update.REPLACE): prevailing, game_index = game_indexer.category(seed[0]) yield cmd(prop=GameView.wind, value=prevailing) yield cmd(prop=GameView.round, value=game_index) yield cmd(prop=GameView.sub_round, value=sub_game) yield cmd(prop=GameView.richii_remain_scores, value=richii_counts * 1000) oya_index = int(event.attrib["oya"]) yield from set_oya_command_yield(cmd, ctx, oya_index) yield cmd(prop=GameView.dora_indicators, value=tile_str_list([initial_dora]), event=EventType.new_dora) for player_id in range(ctx[("all", RecordView.player_count)]): score_all = number_list(event.attrib['ten']) with cmd.when(sub_scope=player_id): with cmd.when(update=Update.RESET_DEFAULT): yield cmd(prop=PlayerView.discard_tiles) yield cmd(prop=PlayerView.fixed_meld) yield cmd(prop=PlayerView.meld_public_tiles) yield cmd(prop=PlayerView.bonus_tiles) yield cmd(prop=PlayerView.round) yield cmd(prop=PlayerView.in_richii, value=False) hand_raw = event.attrib['hai{}'.format(player_id)] yield from hand_update(cmd, hand_raw, ctx) with cmd.when(update=Update.ASSERT_EQUAL_OR_SET): yield cmd(prop=PlayerView.score, value=score_all[player_id] * 100)
def game_type_command(event: TenhouEvent, ctx): cmd = Builder(GameCommand) game_type = GameType(event.attrib["type"]) ctx["_game_indexer"] = SubCategory(game_type.play_wind_count() + 1, 4, caption="prevailing_and_game", names=["prevailing", "game_index"]) with cmd.when(update=Update.REPLACE): yield cmd(prop=RecordView.play_level, value=if_value(game_type.with_tips(), "若銀琥孔", "般上特鳳")[game_type.play_level()]) yield cmd(prop=RecordView.show_discard_shadow, value=game_type.show_discard_shadow()) yield cmd(prop=RecordView.play_wind_count, value=game_type.play_wind_count()) yield cmd(prop=RecordView.allow_tanyao_open, value=game_type.allow_tanyao_open()) yield cmd(prop=RecordView.speed_up, value=game_type.speed_up()) yield cmd(prop=RecordView.player_count, value=game_type.player_count()) yield cmd(prop=RecordView.using_tiles, value=initial_tiles(game_type.player_count(), game_type.has_aka_dora()))
def set_player_command(event: TenhouEvent, ctx): dan = number_list(get_list_attr("dan", event)) rate = number_list(get_list_attr("rate", event)) sex = get_list_attr("sx", event).split(",") cmd = Builder(GameCommand) for i in PlayerId: player_id = i.value name_attr = "n%s" % player_id if name_attr in event.attrib and event.attrib[name_attr].strip() != "": player = TenhouPlayer(player_id, event.attrib[name_attr], dan[player_id], rate[player_id], sex[player_id]) with cmd.when(sub_scope=player_id, update=Update.REPLACE): yield cmd(prop=PlayerView.disconnected, value=False, event=EventType.connect_change) yield cmd(prop=PlayerView.name, value=player.name, update=Update.ASSERT_EQUAL_OR_SET) if "dan" in event.attrib: yield cmd(prop=PlayerView.level, value=player.level_str()) if "rate" in event.attrib: yield cmd(prop=PlayerView.extra_level, value=player.rate)
def draw_command(event: TenhouEvent, ctx): draw = draw_tile_tenhou(event) if draw: cmd = Builder(GameCommand) with cmd.when(update=Update.ADD, sub_scope=draw['player']): yield from hand_update(cmd, [draw['tile']], ctx)
def set_oya_command(event: TenhouEvent, ctx): yield from set_oya_command_yield(Builder(GameCommand), ctx, int(event.attrib['oya']))