Beispiel #1
0
def create_world():
    ###############################################################################
    """
    Create a World object based on the current state of the game's
    configuration.

    Encapsulates knowledge of which factories are available and what the
    config string to select them looks like.
    """
    # Get user's choice of world
    config = Configuration.instance().world_config()
    if (config == ""):
        config = _DEFAULT_WORLD_CONFIG

    if (config.isdigit()):
        # Numeric implies hardcoded world
        factory = _WorldFactoryHardcoded(config)
    elif (config == _WorldFactoryRandom.CONFIG):
        factory = _WorldFactoryRandom(config)
    elif (_WorldFactoryFromFile.is_baal_map_file(config)):
        factory = _WorldFactoryFromFile(config)
    else:
        urequire(False, "Invalid world configuration '%s'" % config)

    return factory.create()
Beispiel #2
0
    def __init__(self, args):
    ###########################################################################
        urequire(len(args) == 1, self.name(), " takes one argument")

        self.__spell_cls = SpellFactory.get(args[0])

        grant_access(self, Player.ALLOW_LEARN)
Beispiel #3
0
 def get(cls, name):
 ###########################################################################
     """
     Get Command class object associate with name.
     """
     urequire(name in cls.__cmd_map,
            "'%s'" % name, " is not a valid command. Type 'help' for help.")
     return cls.__cmd_map[name]
Beispiel #4
0
    def __init__(self, args):
    ###########################################################################
        urequire(len(args) <= 1, self.name(), " takes at most one argument")

        # Parse draw mode
        self.__new_mode = None
        if (args):
            self.__new_mode = DrawMode(args[0])
Beispiel #5
0
    def __init__(self, args):
    ###########################################################################
        urequire(len(args) <= 1, self.name(), " takes at most one argument")

        if (args):
            self.__savegame = args[0]
        else:
            self.__savegame = time.strftime("baal_%Y-%m-%d__%H:%M:%S.save")
Beispiel #6
0
    def __init__(self, args):
    ###########################################################################
        urequire(len(args) <= 1, self.name(), " takes at most one argument")

        # Parse exp
        self.__exp = None
        if (args):
            try:
                self.__exp = int(args[0])
            except ValueError:
                urequire(False, "'%s' is not a valid integer" % args[0])
Beispiel #7
0
    def apply(self):
    ###########################################################################
        world  = engine().world()
        player = engine().player()

        # Ensure location is in-bounds
        urequire(world.in_bounds(self.__spell_location),
                 "Location ", self.__spell_location, " out of bounds. ",
                 "Max row is: ", world.height() - 1,
                 ", max col is: ", world.width() - 1)

        # Create the spell.
        spell = SpellFactory.create_spell(self.__spell_name,
                                          self.__spell_level,
                                          self.__spell_location)

        # Verify that player can cast this spell (can throw)
        player.verify_cast(spell)

        # Verify that it makes sense to cast this exact spell (can throw)
        spell.verify_apply()

        # These last two operations need to be atomic, neither should
        # ever throw a user error.
        try:
            # Let the player object know that the spell has been cast
            # and to adjust it's state accordingly.
            player.cast(spell)

            # Apply the spell to the world
            exp = spell.apply()

            # Give player experience
            player.gain_exp(exp)
        except UserError, e:
            prequire(False, "User error interrupted atomic operations: ", e)
Beispiel #8
0
    def __check_prereqs_impl(self, spell_name, spell_level):
    ###########################################################################
        urequire(self.__player.level() > self.__num_learned,
                 "You cannot learn any more spells until you level-up")
        urequire(spell_level <= self._MAX_SPELL_LEVEL,
                 "You've already hit the maximum level for that spell")

        # Compute prereqs
        spell = SpellFactory.create_spell(spell_name, spell_level)
        prereqs = spell.prereqs()
        min_level = prereqs.min_player_level()
        must_know_spells = prereqs.must_know_spells()

        # Check prereqs
        urequire(self.__player.level() >= min_level,
                 "You must be level ", min_level, " to learn this spell")
        for prereq_spell_spec in must_know_spells:
            urequire(prereq_spell_spec in self,
                     "Missing required prereq: ", "%s[%d]" % prereq_spell_spec)
Beispiel #9
0
    def __init__(self, args):
    ###########################################################################
        urequire(len(args) <= 1, self.name(), " takes at most one argument")

        self.__num_turns = 1
        if (args):
            # Parse num turns
            try:
                self.__num_turns = int(args[0])
            except ValueError:
                urequire(False, "'%s' is not a valid integer" % args[0])
            urequire(self.__num_turns > 0 and
                     self.__num_turns <= self.__MAX_SKIP_TURNS,
                     "num-turns must be between 0 and ", self.__MAX_SKIP_TURNS)
Beispiel #10
0
    def __init__(self, args):
    ###########################################################################
        urequire(len(args) == 3, self.name(), " takes three arguments")

        # Get spell name
        self.__spell_name = args[0]

        # Parse spell level
        try:
            self.__spell_level = int(args[1])
        except ValueError:
            urequire(False, "arg ", "'%s' is not a valid integer" % args[1])

        # Parse location
        try:
            self.__spell_location = Location.parse(args[2])
        except UserError:
            urequire(False, "arg ", "'%s' not a valid location" % args[2])
Beispiel #11
0
 def apply(self):
 ###########################################################################
     # TODO: Aaron, please re-implement in python
     urequire(False, "Not implemented yet")
Beispiel #12
0
 def __init__(self, args):
 ###########################################################################
     urequire(len(args) == 0, self.name(), " takes no arguments")
Beispiel #13
0
 def __verify_cast_impl(self, spell):
     ###########################################################################
     urequire(spell.cost() <= self.__mana, "Spell requires ", spell.cost(),
              " mana, player only has ", self.__mana, " mana")
     urequire(spell in self.__talents, "Player cannot cast spell ", spell)