def parse_single_entity_xml(self, xml, id, locale=None): """ Parse a single Entity tag If the locale argument is set, read it as single-locale. Otherwise, read it as merged-locales. """ entity = cardxml.CardXML(id) entity.version = int(xml.attrib["version"]) self.entity_strings[id] = {k: {} for k in entity.strings} for e in xml: if e.tag == "Tag": tag = GameTag(int(e.attrib["enumID"])) if e.attrib["type"] == "String": if locale: self.entity_strings[id][tag][locale] = e.text else: for loc in e: self.entity_strings[id][tag][loc.tag] = loc.text else: value = int(e.attrib["value"]) entity.tags[tag] = value elif e.tag == "ReferencedTag": tag = GameTag(int(e.attrib["enumID"])) value = int(e.attrib["value"]) entity.referenced_tags[tag] = value elif e.tag == "MasterPower": entity.master_power = e.text.strip() elif e.tag == "Power": power = cardxml._read_power_tag(e) entity.powers.append(power) elif e.tag == "EntourageCard": card_id = e.attrib.pop("cardID") if not card_id: raise ValueError( "Missing cardID on EntourageCard for entity %r" % (entity)) entity.entourage.append(card_id) if e.attrib: raise NotImplementedError("EntourageCard attributes: %r" % (e.attrib)) elif e.tag == "TriggeredPowerHistoryInfo": effect_index = e.attrib.pop("effectIndex") show_in_history = string_to_bool(e.attrib.pop("showInHistory")) entity.triggered_power_history_info.append({ "effectIndex": effect_index, "showInHistory": show_in_history, }) if e.attrib: raise NotImplementedError( "TriggeredPowerHistoryInfo attributes: %r" % (e.attrib)) else: raise NotImplementedError("Unhandled tag: %r" % (e.tag)) self.entities[id] = entity
def merge(id, card, cardscript=None): """ Find the xmlcard and the card definition of \a id Then return a merged class of the two """ if card is None: card = cardxml.CardXML(id) if cardscript is None: cardscript = get_script_definition(id) if cardscript: card.scripts = type(id, (cardscript, ), {}) else: card.scripts = type(id, (), {}) scriptnames = ("activate", "combo", "deathrattle", "draw", "inspire", "play", "enrage", "update", "powered_up", "outcast", "awaken") for script in scriptnames: actions = getattr(card.scripts, script, None) if actions is None: # Set the action by default to avoid runtime hasattr() calls setattr(card.scripts, script, []) elif not callable(actions): if not hasattr(actions, "__iter__"): # Ensure the actions are always iterable setattr(card.scripts, script, (actions, )) for script in ("events", "secret"): events = getattr(card.scripts, script, None) if events is None: setattr(card.scripts, script, []) elif not hasattr(events, "__iter__"): setattr(card.scripts, script, [events]) if not hasattr(card.scripts, "cost_mod"): card.scripts.cost_mod = None if not hasattr(card.scripts, "Hand"): card.scripts.Hand = type("Hand", (), {}) if not hasattr(card.scripts.Hand, "events"): card.scripts.Hand.events = [] if not hasattr(card.scripts.Hand.events, "__iter__"): card.scripts.Hand.events = [card.scripts.Hand.events] if not hasattr(card.scripts.Hand, "update"): card.scripts.Hand.update = () if not hasattr(card.scripts.Hand.update, "__iter__"): card.scripts.Hand.update = (card.scripts.Hand.update, ) # Set choose one cards if hasattr(cardscript, "choose"): card.choose_cards = cardscript.choose[:] else: card.choose_cards = [] if hasattr(cardscript, "tags"): for tag, value in cardscript.tags.items(): card.tags[tag] = value if hasattr(cardscript, "requirements"): card.powers.append({"requirements": cardscript.requirements}) else: card.powers.append({"requirements": {}}) if hasattr(cardscript, "entourage"): card.entourage = cardscript.entourage if hasattr(cardscript, "dormant"): card.dormant = cardscript.dormant else: card.dormant = 0 return card
def merge(id, card, cardscript=None): """ Find the xmlcard and the card definition of \a id Then return a merged class of the two """ if card is None: card = cardxml.CardXML(id) if cardscript is None: cardscript = get_script_definition(id) if cardscript: card.scripts = type(id, (cardscript, ), {}) else: card.scripts = type(id, (), {}) scriptnames = ( "activate", "combo", "deathrattle", "draw", "inspire", "play", "enrage", "update", "powered_up" ) for script in scriptnames: actions = getattr(card.scripts, script, None) if actions is None: # Set the action by default to avoid runtime hasattr() calls setattr(card.scripts, script, []) elif not callable(actions): if not hasattr(actions, "__iter__"): # Ensure the actions are always iterable setattr(card.scripts, script, (actions, )) for script in ("events", "secret"): events = getattr(card.scripts, script, None) if events is None: setattr(card.scripts, script, []) elif not hasattr(events, "__iter__"): setattr(card.scripts, script, [events]) if not hasattr(card.scripts, "cost_mod"): card.scripts.cost_mod = None #Setup Hand defaults CardDB.setup_zone_script_defaults(card, "Hand") #Setup Deck defaults CardDB.setup_zone_script_defaults(card, "Deck") #Setup Discard defaults CardDB.setup_zone_script_defaults(card, "Discard") # Set choose one cards if hasattr(cardscript, "choose"): card.choose_cards = cardscript.choose[:] else: card.choose_cards = [] if hasattr(cardscript, "tags"): for tag, value in cardscript.tags.items(): card.tags[tag] = value # Set some additional events based on the base tags... if card.poisonous: card.scripts.events.append(POISONOUS) return card