示例#1
0
    def getBGESpreadsheets(self, bge="athletic"):
        cards = self.api.getCards()
        combos = self.api.getCombos()

        # Gets all combo bge cards
        combo_list = self.searchXML(xml_files=[cards],
                                    musthave=[('trait', bge), ('set', '1001')])
        exp_two_list = self.searchXML(xml_files=[cards],
                                      musthave=[('trait', bge),
                                                ('set', '1002')])
        combo_list.extend(exp_two_list)

        combo_deck = Deck()

        input_list = []
        for card_id in combo_list:
            for card in combos.findall('combo'):
                if int(card.find('card_id').text) == card_id:
                    cards = card.find('cards')

                    if cards.get('card1') == '' or cards.get('card2') == '':
                        continue

                    card_one_id = int(cards.get('card1'))
                    card_two_id = int(cards.get('card2'))

                    # Skip mythics
                    if card_one_id > 1000000:
                        continue

                    one_index = combo_deck.getCardIndex(card_one_id)
                    two_index = combo_deck.getCardIndex(card_two_id)

                    if one_index is None:
                        one_index = len(combo_deck.cards)
                        combo_deck.addCard(card_id=card_one_id)

                    if two_index is None:
                        two_index = len(combo_deck.cards)
                        combo_deck.addCard(card_id=card_two_id)

                    new_combo = Combo(combo_deck.cards[one_index],
                                      combo_deck.cards[two_index], card_id)
                    combo_deck.combos.append(new_combo)

        if len(combo_deck.combos) <= 0:
            # print("No combos found for {0}".format(bge))
            return

        combo_deck.updateDeckFromXML()
        combo_deck.updateCombosFromXML()

        # Create 2d array of items on left and chars on top
        combo_deck.cards.sort(key=lambda x: (x.type, -x.rarity, x.name))

        # Count columns and rows
        col_count = 0
        row_count = 0

        while col_count < len(combo_deck.cards) and \
                (combo_deck.cards[col_count].type == constants.CHAR or
                 combo_deck.cards[col_count].type == constants.MYTHIC):
            col_count += 1

        while col_count + row_count < len(combo_deck.cards) and \
                combo_deck.cards[row_count + col_count].type == constants.ITEM:
            row_count += 1

        col_count += 1
        row_count += 1
        arr = [["-"] * col_count for x in range(row_count)]

        m = 1
        while m - 1 < len(combo_deck.cards) and \
                (combo_deck.cards[m - 1].type == constants.CHAR or
                 combo_deck.cards[m - 1].type == constants.MYTHIC):
            arr[0][m] = combo_deck.cards[m - 1].name
            m += 1

        i = 1
        while (i + m - 2) < len(combo_deck.cards) and combo_deck.cards[
                i + m - 2].type == constants.ITEM:
            arr[i][0] = combo_deck.cards[i + m - 2].name
            i += 1

        for x in range(len(combo_deck.combos)):
            # find column
            a = 1
            while arr[0][a].lower() != combo_deck.combos[x].char.name.lower():
                a += 1

            # find row
            b = 1
            while arr[b][0].lower() != combo_deck.combos[x].item.name.lower():
                b += 1

            arr[b][a] = combo_deck.combos[x].name

        # Write combos to file

        target = open(
            getFullPath(self.savePath, "{0}_combos_table.csv".format(bge)),
            'w')
        target.truncate()

        for i in range(len(arr)):
            for j in range(len(arr[i])):
                target.write("\"" + arr[i][j] + "\", ")
            target.write("\n")
        target.close()

        target = open(
            getFullPath(self.savePath, "{0}_combos_list.csv".format(bge)), 'w')
        target.truncate()

        for i in range(len(combo_deck.combos)):
            target.write("\"" + combo_deck.combos[i].char.name + "\", " +
                         "\"" + combo_deck.combos[i].item.name + "\", " +
                         "\"" + combo_deck.combos[i].name + "\", \n")
        target.close()
示例#2
0
    def getBGEImages(self, bge="athletic"):
        cards = self.api.getCards()
        combos = self.api.getCombos()
        pc = self.api.getPC()

        # Gets all non-combo bge cards
        bge_pc = self.searchXML(xml_files=[pc], musthave=[('trait', bge)])
        input_cards = self.searchXML(xml_files=[cards],
                                     musthave=[('trait', bge)],
                                     mustnothave=[('set', '1001'),
                                                  ('set', '1002')])

        # Gets all combo bge cards
        combo_list = self.searchXML(xml_files=[cards],
                                    musthave=[('trait', bge), ('set', '1001')])
        exp_two_list = self.searchXML(xml_files=[cards],
                                      musthave=[('trait', bge),
                                                ('set', '1002')])
        combo_list.extend(exp_two_list)

        combo_deck = Deck()

        input_list = []
        for card_id in combo_list:
            for card in combos.findall('combo'):
                if int(card.find('card_id').text) == card_id:
                    cards = card.find('cards')
                    if cards.get('card1') == '' or cards.get('card2') == '':
                        continue

                    card_one_id = int(cards.get('card1'))
                    card_two_id = int(cards.get('card2'))

                    one_index = combo_deck.getCardIndex(card_one_id)
                    two_index = combo_deck.getCardIndex(card_two_id)

                    if one_index is None:
                        one_index = len(combo_deck.cards)
                        combo_deck.addCard(card_id=card_one_id)

                    if two_index is None:
                        two_index = len(combo_deck.cards)
                        combo_deck.addCard(card_id=card_two_id)

                    new_combo = Combo(combo_deck.cards[one_index],
                                      combo_deck.cards[two_index], card_id)
                    combo_deck.combos.append(new_combo)

        combo_deck.updateDeckFromXML()
        combo_deck.updateCombosFromXML()
        combo_deck.trimCombos()

        # combo_deck.combos.sort(key=lambda x : (-x.rarity, x.name, -x.combo_power))
        combo_path = combo_deck.createLargeComboImage(bge + "_combos", 10)
        input_cards, input_path = self.createImageFromList(
            bge + "_input_cards", [input_cards])
        pc, pc_path = self.createImageFromList(bge + "_pc", [bge_pc])

        # print("Deck image saved as {0}".format(combo_path))
        # print("Deck image saved as {0}".format(input_path))
        # print("Deck image saved as {0}".format(pc_path))

        combo_deck.printCombosToTerminal()
        input_cards.printDeckToTerminal()
        pc.printDeckToTerminal()