Beispiel #1
0
    def load(self):
        with open(self.save_filename, 'r') as f:
            sav = json.load(f)

            weapon = self.weapons[0]
            for w in self.weapons:
                if w.id == sav['weapon_id']:
                    weapon = w
                    break

            self.new_game(sav['name'])
            self.player.hp = sav['hp']
            self.player.max_hp = sav['max_hp']
            self.player.mp = sav['mp']
            self.player.max_mp = sav['max_mp']
            self.player.atk = sav['atk']
            self.player.def_ = sav['def']
            self.player.matk = sav['matk']
            self.player.mdef = sav['mdef']
            self.player.spd = sav['spd']
            self.player.lck = sav['lck']
            self.player.exp = sav['exp']
            self.player.gold = sav['gold']
            self.player.lvl = sav['lvl']
            self.player.change_weapon(weapon, Log())

            for spell in self.spells:
                if spell.id in sav['spell_ids']:
                    self.player.add_spell(spell, Log())

            return ['Loaded game.']
Beispiel #2
0
    def buy(self, index):
        if self.last_used_shop not in [A_WEAPON_SHOP, A_SPELL_SHOP]:
            return ['%s tries to buy something, but is not inside a shop. The people of the town stare in disbelief as %s haggles with an imaginary shopkeeper.' % (self.player.name, self.player.name)]

        is_weapon_shop = self.last_used_shop == A_WEAPON_SHOP

        try:
            index = int(index) - 1
            if index not in range(0, len(self.weapons if is_weapon_shop else self.spells)):
                raise ValueError
        except ValueError:
            return ['%s inspects the shop intensely, but can\'t find such an item.' % self.player.name]

        log = Log()
        item = self.weapons[index] if is_weapon_shop else self.spells[index]

        if is_weapon_shop and item == self.player.weapon or not is_weapon_shop and item in self.player.spells:
            return ['%s already has that.' % self.player.name]

        if self.player.gold < item.cost:
            if self.state == S_DEAD:
                return ['%s doesn\'t have enough dream gold to buy that.' % self.player.name]
            return ['%s doesn\'t have enough gold to buy that.' % self.player.name]

        if is_weapon_shop:
            self.player.change_weapon(item, log)
        else:
            self.player.add_spell(item, log)

        self.player.remove_gold(item.cost, log)
        self.save()

        if self.state == S_DEAD:
            return log.output() + ['Strangely, it materializes next to the sleeping %s. Perhaps dreams do come true after all!' % self.player.name]
        return log.output()
Beispiel #3
0
    def player_spell(self, index, target):
        try:
            index = int(index) - 1
            if index >= len(self.player.spells):
                raise ValueError
        except ValueError:
            return ['%s doesn\'t know such a spell. Maybe the spell shop can help...' % self.player.name]

        log = Log()
        self.encounter.player_spell(self.player.spells[index], target, log)
        return log.output() + self.encounter_result()
Beispiel #4
0
Datei: main.py Projekt: proog/nda
    def player_spell(self, index, target):
        try:
            index = int(index) - 1
            if index >= len(self.player.spells):
                raise ValueError
        except ValueError:
            return ["%s doesn't know such a spell. Maybe the spell shop can help..." % self.player.name]

        log = Log()
        self.encounter.player_spell(self.player.spells[index], target, log)
        return log.output() + self.encounter_result()
Beispiel #5
0
Datei: main.py Projekt: proog/nda
    def buy(self, index):
        if self.last_used_shop not in [A_WEAPON_SHOP, A_SPELL_SHOP]:
            return [
                "%s tries to buy something, but is not inside a shop. The people of the town stare in disbelief as %s haggles with an imaginary shopkeeper."
                % (self.player.name, self.player.name)
            ]

        is_weapon_shop = self.last_used_shop == A_WEAPON_SHOP

        try:
            index = int(index) - 1
            if index not in range(0, len(self.weapons if is_weapon_shop else self.spells)):
                raise ValueError
        except ValueError:
            return ["%s inspects the shop intensely, but can't find such an item." % self.player.name]

        log = Log()
        item = self.weapons[index] if is_weapon_shop else self.spells[index]

        if is_weapon_shop and item == self.player.weapon or not is_weapon_shop and item in self.player.spells:
            return ["%s already has that." % self.player.name]

        if self.player.gold < item.cost:
            if self.state == S_DEAD:
                return ["%s doesn't have enough dream gold to buy that." % self.player.name]
            return ["%s doesn't have enough gold to buy that." % self.player.name]

        if is_weapon_shop:
            self.player.change_weapon(item, log)
        else:
            self.player.add_spell(item, log)

        self.player.remove_gold(item.cost, log)
        self.save()

        if self.state == S_DEAD:
            return log.output() + [
                "Strangely, it materializes next to the sleeping %s. Perhaps dreams do come true after all!"
                % self.player.name
            ]
        return log.output()
Beispiel #6
0
 def __init__(self, name, starting_weapon):
     hp = random.randint(14, 26)
     mp = random.randint(14, 26)
     atk = random.randint(1, 6)
     def_ = random.randint(1, 6)
     matk = random.randint(1, 6)
     mdef = random.randint(1, 6)
     spd = random.randint(1, 6)
     super(Player, self).__init__(None, name, 'The hero of the story.', hp,
                                  mp, atk, def_, matk, mdef, spd)
     self.lck = random.randint(1, 6)
     self.exp = 0
     self.gold = 0
     self.lvl = 1
     self.weapon = None
     self.spells = []
     self.change_weapon(starting_weapon, Log())
Beispiel #7
0
 def player_flee(self):
     log = Log()
     self.encounter.player_flee(log)
     return log.output() + self.encounter_result()
Beispiel #8
0
 def new_encounter(self):
     log = Log()
     self.state = S_ENCOUNTER
     self.encounter = self.dungeon.new_encounter(log)
     return log.output() + self.encounter_result()
Beispiel #9
0
Datei: main.py Projekt: proog/nda
 def player_flee(self):
     log = Log()
     self.encounter.player_flee(log)
     return log.output() + self.encounter_result()
Beispiel #10
0
Datei: main.py Projekt: proog/nda
 def new_encounter(self):
     log = Log()
     self.state = S_ENCOUNTER
     self.encounter = self.dungeon.new_encounter(log)
     return log.output() + self.encounter_result()