def create(self, name, difficulty, gold=100): path = os.path.join("..", "data", "actors", "families", name) if not os.path.exists(path): os.mkdir(path) Configuration(os.path.join(path, "family.ini")).save() familyini = Configuration(os.path.join(path, "family.ini")) familyini.family.__setattr__("difficulty", difficulty) familyini.family.__setattr__("gold", int(gold)) familyini.save()
class Bestiary: def __init__(self, family): self.family = family #save data for the bestiary #gathers all the different enemy types path = os.path.join("..", "data", "actors", "enemies") enemies = os.listdir(path) enemies.sort() path = os.path.join("..", "data", "actors", "families", family.name, "bestiary.ini") if not os.path.exists(path): Configuration(path).save() self.catalog = Configuration(path) self.catalog.bestiary.__setattr__(enemies[0], 0) self.catalog.save() self.catalog = Configuration(path) self.beasts = {} for beast in enemies: try: self.beasts[beast] = self.catalog.bestiary.__getattr__(beast, int) except: self.catalog.bestiary.__setattr__(beast, 0) self.catalog.save() self.catalog = Configuration(path) self.beasts[beast] = self.catalog.bestiary.__getattr__(beast, int) def update(self): for beast in self.beasts: self.catalog.bestiary.__setattr__(beast[0], beast[1]) self.catalog.save() self.catalog = Configuration(path) def __str__(self): str = "" for i, beast in enumerate(self.beasts): str += "%03i: %-16s%02i\n" % (i+1, beast[0], beast[1]) return str
def create( self, family, name, job, stats, points=0, equipment=None, proficiency=None, gender="male", sprite="01", level=1, exp=0, ): Configuration(os.path.join("..", "data", "actors", "families", family, name + ".ini")).save() ini = Configuration(os.path.join("..", "data", "actors", "families", family, name + ".ini")) # nothing like short-handing base = ini.character dist = ini.distribution eqp = ini.equipment prof = ini.proficiency if proficiency == None: proficiency = eval(job + "()").proficiencies if equipment == None: equipment = [None for i in range(10)] base.__setattr__("gender", gender) base.__setattr__("spriteset", sprite) base.__setattr__("job", job) base.__setattr__("level", level) base.__setattr__("exp", exp) base.__setattr__("points", points) dist.__setattr__("hpDist", stats[0]) dist.__setattr__("strDist", stats[1]) dist.__setattr__("defDist", stats[2]) dist.__setattr__("spdDist", stats[3]) dist.__setattr__("evdDist", stats[4]) dist.__setattr__("magDist", stats[5]) dist.__setattr__("resDist", stats[6]) eqp.__setattr__("right hand", equipment[0]) eqp.__setattr__("left hand", equipment[1]) eqp.__setattr__("accessory1", equipment[2]) eqp.__setattr__("accessory2", equipment[3]) eqp.__setattr__("accessory3", equipment[4]) eqp.__setattr__("helmet", equipment[5]) eqp.__setattr__("armor", equipment[6]) eqp.__setattr__("legs", equipment[7]) eqp.__setattr__("feet", equipment[8]) eqp.__setattr__("gloves", equipment[9]) prof.__setattr__("sword", proficiency[0]) prof.__setattr__("dagger", proficiency[1]) prof.__setattr__("spear", proficiency[2]) prof.__setattr__("staff", proficiency[3]) prof.__setattr__("guns", proficiency[4]) prof.__setattr__("fist", proficiency[5]) ini.save()
#command line parser, if running python 2.7 use argparse, else fall-back to optparse try: import argparse except ImportError: import optparse as argparse FPS = 60 caption = 'UlDunAd - Ultimate Dungeon Adventure [FPS: %i]' if not os.path.exists(os.path.join("..", "uldunad.ini")): Configuration(os.path.join("..", "uldunad.ini")).save() runini = Configuration(os.path.join("..", "uldunad.ini")) runini.video.__setattr__("resolution", str(800) + "x" + str(600) + "x" + "W") runini.audio.__setattr__("volume", str(10)) runini.save() Input.create(runini) Input.load(runini) else: runini = Configuration(os.path.join("..", "uldunad.ini")) Input.load(runini) w, h, fullscreen = runini.video.__getattr__("resolution").split("x") w, h = float(w), float(h) resolution = (int(w), int(h)) volume = int(runini.audio.__getattr__("volume")) if fullscreen == "F": fullscreen = True else: fullscreen = False
class Inventory: def __init__(self, family): self.family = family #save data for the inventory #gathers all the different enemy types path = os.path.join("..", "data", "items") items = os.listdir(path) items.sort() path = os.path.join("..", "data", "actors", "families", family.name, "inventory.ini") if not os.path.exists(path): Configuration(path).save() self.catalog = Configuration(path) self.catalog.inventory.__setattr__(items[0], 0) self.catalog.save() self.catalog = Configuration(path) self.items = {} def loadList(): changeMade = False for i in items: if self.catalog.parser.has_option("inventory", i): ini = Configuration(os.path.join("..", "data", "items", i, "item.ini")) #detecting what type of item it is if ini.parser.has_section("weapon"): item = Weapon(i) elif ini.parser.has_section("armor"): item = Armor(i) elif ini.parser.has_section("loot"): item = Loot(i) elif ini.parser.has_section("usable"): item = Usable(i) else: item = Item(i) self.items[i] = [item, self.catalog.inventory.__getattr__(i, int)] else: self.catalog.inventory.__setattr__(i, 0) self.catalog.save() loadList() #adds the amount of said item to the inventory # do not use negative numbers to remove item, use removeItem method instead def addItem(self, name, amount): self.items[name][1] = math.max(_itemMax, self.items[name][1]+amount) #removes the amount of said item from the inventory def removeItem(self, name, amount): self.items[name][1] = math.max(_itemMax, self.items[name][1]-amount) #creates string rep of the inventory def __str__(self): str = "" for i, item in enumerate(self.items.keys()): str += "%03i: %-16s%02i\n" % (i+1, self.items[item][0].name, self.items[item][1]) return str #saves the updated inventory def update(self): for item in self.items.keys(): self.catalog.inventory.__setattr__(item, self.items[item][1]) self.catalog.save() self.catalog = Configuration(path) #all items by type def getByType(self, type = None): available = {} items = self.available() if type == None: return items else: for item in items: if isinstance(items[item][0], type): available[item] = items[item] return available #items that the party possesses def available(self): available = {} for item in self.items.keys(): if self.items[item][1] > 0: available[item] = self.items[item] return available #number of different items the party possesses def __len__(self): return len(self.available())