Ejemplo n.º 1
0
    def __parse_item_add(self, line_number, line):
        """ Parse an item and push it to the state """
        if len(self.splitfile) > 1 and self.splitfile[line_number + self.seek -
                                                      1] == line:
            self.log.debug("Skipped duplicate item line from baby presence")
            return False
        is_Jacob_item = line.endswith(
            "(Jacob)"
        ) and self.opt.game_version == "Repentance" and self.state.player == 19
        is_Esau_item = line.endswith(
            " 1 (Esau)"
        ) and self.opt.game_version == "Repentance" and self.state.player == 19
        if self.state.player in (
                14, 33):  # Don't show keeper head on keeper and tainted keeper
            is_Strawman_item = "player 0" not in line and line.endswith(
                "(Keeper)") and self.state.contains_item('667')
            is_EsauSoul_item = "player 0" not in line and line.endswith(
                "(Esau)")
        elif self.state.player == 19:
            is_Strawman_item = line.endswith(
                "(Keeper)") and self.state.contains_item('667')
            is_EsauSoul_item = "player 0" not in line and "player 1 " not in line and line.endswith(
                "(Esau)")
        else:
            is_Strawman_item = line.endswith(
                "(Keeper)") and self.state.contains_item('667')
            is_EsauSoul_item = "player 0" not in line and line.endswith(
                "(Esau)")

        if self.state.player == 19 and not is_Esau_item and not is_Jacob_item and not is_Strawman_item and not is_EsauSoul_item:  # This is when J&E transform into another character
            self.state.player = 8  # Put it on Lazarus by default just in case we got another Anemic
        elif self.state.player not in (19, 37) and is_Jacob_item:
            self.state.player = 19

        space_split = line.split(" ")
        numeric_id = space_split[
            2]  # When you pick up an item, this has the form: "Adding collectible 105 (The D6)" or "Adding collectible 105 (The D6) to Player 0 (Isaac)" in Repentance
        double_word_char = line.endswith("(The Lost)") or line.endswith(
            "(The Forgotten)") or line.endswith("(The Soul)") or line.endswith(
                "(Black Judas)") or line.endswith("(Random Baby)")
        if self.opt.game_version == "Repentance" and double_word_char:
            item_name = " ".join(space_split[3:-4])[1:-4]
        elif self.opt.game_version == "Repentance":
            item_name = " ".join(space_split[3:-4])[1:-1]
        else:
            item_name = " ".join(space_split[3:])[1:-1]

        item_id = ""

        if int(numeric_id) < 0:
            numeric_id = "-1"

        # Check if we recognize the numeric id
        if Item.contains_info(numeric_id):
            item_id = numeric_id
        else:
            # it might be a modded custom item. let's see if we recognize the name
            item_id = Item.modded_item_id_prefix + item_name
            if not Item.contains_info(item_id):
                item_id = "NEW"

        self.log.debug("Picked up item. id: %s, name: %s", item_id, item_name)
        if ((line_number + self.seek) - self.spawned_coop_baby) < (len(self.state.item_list) + 10) \
                and self.state.contains_item(item_id):
            self.log.debug("Skipped duplicate item line from baby entry")
            return False

        # It's a blind pickup if we're on a blind floor and we don't have the Black Candle
        blind_pickup = self.state.last_floor.floor_has_curse(
            Curse.Blind) and not self.state.contains_item('260')
        if not (numeric_id == "214" and (
            (self.state.contains_item('214')
             and self.state.contains_item('332')) or
            (self.state.player == 8 and self.state.contains_item('214')))):
            added = self.state.add_item(
                Item(item_id,
                     numeric_id,
                     self.state.last_floor,
                     self.getting_start_items,
                     blind=blind_pickup,
                     is_Jacob_item=is_Jacob_item,
                     is_Esau_item=is_Esau_item,
                     is_Strawman_item=is_Strawman_item,
                     is_EsauSoul_item=is_EsauSoul_item,
                     shown=Item.get_item_info(item_id).shown))
            if not added:
                self.log.debug(
                    "Skipped adding item %s to avoid space-bar duplicate",
                    item_id)
        else:
            self.log.debug(
                "Skipped adding Anemic from Lazarus Rags because we already have Anemic"
            )

        if item_id in ("144", "238", "239", "278", "388", "550", "552", "626",
                       "627"):
            self.__parse_add_multi_items()
        self.state.export_state()
        return True