Ejemplo n.º 1
0
    def test_simple_cost_merge(self):

        self.assertEqual(merge_mana_costs(['B'], ['B', 'B']), ['B', 'B', 'B'])
        self.assertEqual(merge_mana_costs(['2', 'W'], ['R'], ['G']),
                                          ['2', 'W', 'R', 'G'])
        self.assertEqual(merge_mana_costs(['X'], ['2', 'W']), ['X', '2', 'W'])
        self.assertEqual(merge_mana_costs('{X}', '{2}{W}'), ['X', '2', 'W'])
Ejemplo n.º 2
0
    def get(cls, card):
        """
        this card has a triggered ability when cycled that could be
        considered as the "real" mana cost
        """
        cycling_text = (r"\((?P<mana_cost>\{.+\}),\s+"
                        r"Discard this card\: Draw a card\.\)\n\n"
                        r"When you cycle %s(?:.+"
                        r"you may pay (?P<extra_cost>\{.+\}))?.+$" % card.name)
        cycling_match = re.search(cycling_text, card.text, re.I)
        if not cycling_match:
            return

        results = cycling_match.groupdict()
        parsed_cost = parse_mana_cost(results['mana_cost'])
        if results.get('extra_cost'):
            parsed_cost = merge_mana_costs(parsed_cost, results['extra_cost'])

        _cyc = dict(
            mana_cost=stitch_mana_cost(parsed_cost),
            converted_mana_cost=estimate_cmc(parsed_cost)
        )

        return {
            cls.key: _cyc
        }
Ejemplo n.º 3
0
    def get(cls, card):
        """
        Cards that have activated abilities of different colors than their
        normal mana color (if it has a color) often have designers placing them
        in multicolored sections
        """
        merged = merge_mana_costs(*(card.activated_ability_mana_costs or []))
        activated_colors = estimate_colors(merged)

        # don't handle phyrexian, that comes later
        if (not any('/P' in sym for sym in merged) and
                activated_colors and  # there's color reqs in activation costs
                activated_colors != card.colors):  # and they're new
            return {
                cls.key: dict(colors=activated_colors | card.colors)
            }
Ejemplo n.º 4
0
    def _get_kicker_stuff(cls, card):
        kicker_costs = re.search(
            r'Kicker (\{.+\})(?:\s+and/or (\{.+\}))* \(You',
            card.text
        )
        if not kicker_costs:
            return {}

        kicker_colors = set()
        kickers = kicker_costs.groups()

        for cost in kickers:
            kicker_colors |= card.estimate_colors(cost, [])

        updated_cost = merge_mana_costs(card.mana_cost, *kickers)

        return dict(
            updated_colors=kicker_colors | card.colors,
            updated_cost=updated_cost,
            updated_cmc=estimate_cmc(updated_cost)
        )
Ejemplo n.º 5
0
    def get(cls, card):
        """
        but for cards that have phyrexian in their activated abilities, the
        re-occurring cost is a bit much to assume that you can avoid the
        color requirement for
        """
        phyrexian_result = _handle_phyrexian.get(card)
        all_costs = merge_mana_costs(card.activated_ability_mana_costs or [])

        phyrexian_symbols = [sym for sym in all_costs if '/P' in sym]
        # if not, there was no phyrexian anywhere
        if phyrexian_result or phyrexian_symbols:
            # copy whatever they had so far
            ability_result = deepcopy(
                (phyrexian_result or {}).get(_handle_phyrexian.key, {})
            )
            if all_costs and phyrexian_symbols:
                ability_result['colors'] = (
                    ability_result.get('colors', set()) |
                    estimate_colors(all_costs)
                )
                return {
                    cls.key: ability_result
                }