Esempio n. 1
0
    def save(self, tree_name):
        tree = Movable.save(self, tree_name)

        # Save class (if possible)
        if len(self.classes) > 0:
            class_el = etree.SubElement(tree, 'class')
            class_el.text = self.classes[0]  # Currently, only first class is saved if any

        # Save race
        race = etree.SubElement(tree, 'race')
        race.text = self.race

        # Save gold
        gold = etree.SubElement(tree, 'gold')
        gold.text = str(self.gold)

        # Save inventory
        inventory = etree.SubElement(tree, 'inventory')
        for item in self.items:
            inventory.append(item.save('item'))

        # Save equipment
        equipments = etree.SubElement(tree, 'equipment')
        for equipment in self.equipments:
            equipments.append(equipment.save(equipment.body_part))

        return tree
    def save(self, tree_name):
        tree = Movable.save(self, tree_name)

        # Save loot
        loot = etree.SubElement(tree, "loot")
        for (item, probability) in self.potential_loot:
            if isinstance(item, Gold):
                it_el = etree.SubElement(loot, 'gold')
                it_name = etree.SubElement(it_el, 'amount')
                it_name.text = str(item.amount)
            else:
                it_el = etree.SubElement(loot, 'item')
                it_name = etree.SubElement(it_el, 'name')
                it_name.text = item.name
            it_probability = etree.SubElement(it_el, 'probability')
            it_probability.text = str(probability)

        return tree