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 inv = etree.SubElement(tree, 'inventory') for it in self.items: it_el = etree.SubElement(inv, 'item') it_el.text = it.name # Save equipment equip = etree.SubElement(tree, 'equipment') for eq in self.equipments: eq_el = etree.SubElement(equip, eq.body_part) eq_el.text = eq.name return tree
def save(self): tree = Movable.save(self) # Save gold gold = etree.SubElement(tree, 'gold') gold.text = str(self.gold) return tree
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) 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, Item): it_el = etree.SubElement(loot, 'item') it_name = etree.SubElement(it_el, 'name') else: # We assume item is gold it_el = etree.SubElement(loot, 'gold') it_name = etree.SubElement(it_el, 'amount') it_name.text = str(item) it_probability = etree.SubElement(it_el, 'probability') it_probability.text = str(probability) return tree