Exemplo n.º 1
0
def cast_heal():
    # heal the player
    if var.player.fighter.hp == var.player.fighter.max_hp:
        message('You are already at full health.', 'red')
        return 'cancelled'
    message('Your wounds start to feel better!', 'light violet')
    var.player.fighter.heal(var.HEAL_AMOUNT)
Exemplo n.º 2
0
def check_level_up():
    # see if the player's experience is enough to level-up
    level_up_exp = var.LEVEL_UP_BASE + var.player.level * var.LEVEL_UP_FACTOR
    if var.player.fighter.xp >= level_up_exp:
        # it is! level up
        var.player.level += 1
        var.player.fighter.xp -= level_up_exp
        message(
            'Your battle skills grow stronger! You reached level ' +
            str(var.player.level) + '!', 'yellow')
        choice = None
        while choice is None:
            # keep asking until a choice is made
            choice = menu('Level up! Choose a stat to raise:\n', [
                'Constitution (+20 HP, from ' +
                str(var.player.fighter.base_max_hp) + ')',
                'Strength (+1 attack, from ' +
                str(var.player.fighter.base_power) + ')',
                'Agility (+1 defense, from ' +
                str(var.player.fighter.base_defense) + ')'
            ], var.LEVEL_SCREEN_WIDTH)
        if choice == 0:
            var.player.fighter.base_max_hp += 20
            var.player.fighter.hp += 20
        elif choice == 1:
            var.player.fighter.base_power += 1
        elif choice == 2:
            var.player.fighter.base_defense += 1
Exemplo n.º 3
0
 def take_turn(self):
     if self.num_turns > 0:  # still confused
         # move in a random direction and decrease the number of turns confused
         self.owner.move(randint(-1, 1), randint(-1, 1))
         self.num_turns -= 1
     else:  # restore the previous AI (this one will be deleted because it isn't referenced anymore)
         self.owner.ai = self.old_ai
         message('The ' + self.owner.name + ' is no longer confused!',
                 'red')
Exemplo n.º 4
0
 def equip(self):
     # if the slot is already being used, dequip whatever is there first
     old_equipment = get_equipped_in_slot(self.slot)
     if old_equipment is not None:
         old_equipment.dequip()
     # equip an object and show a message about it
     self.is_equipped = True
     message('Equipped ' + self.owner.name + ' on ' + self.slot + '.',
             'light green')
Exemplo n.º 5
0
def drop_item(item):
    # special case: if the object has the Equipment component, dequip it before dropping
    if item.owner.equipment:
        item.owner.equipment.dequip()
    # put an item on the floor
    var.entities.append(item.owner)
    var.inventory.remove(item.owner)
    item.owner.x = var.player.x
    item.owner.y = var.player.y
    message('You dropped a ' + item.owner.name + '.', 'yellow')
Exemplo n.º 6
0
def next_level():
    # advance to the next level
    message('You take a moment to rest and recover your strength.',
            'light violet')
    var.player.fighter.heal(var.player.fighter.max_hp / 2)
    message(
        'After a rare moment of peace, you descend deeper into the heart of the dungeon...',
        'red')
    var.dungeon_level += 1
    make_map()
    initialize_fov()
Exemplo n.º 7
0
 def attack(self, target):
     # a simple formula for attack damage
     damage = self.power - target.fighter.defense
     if damage > 0:
         # make the target take some damage
         message(self.owner.name.capitalize() + ' attacks ' + target.name +
                 ' for ' + str(damage) + ' hit points.')
         target.fighter.take_damage(damage)
     else:
         message(self.owner.name.capitalize() + ' attacks ' + target.name +
                 ' but it has no effect!')
Exemplo n.º 8
0
def cast_lightning():
    # find closest enemy (inside max range) and damage it
    monster = closest_monster(var.LIGHTNING_RANGE)
    if monster is None:
        message('No enemy is close enough to strike.', 'red')
        return 'cancelled'
    # zap it!
    message(
        'A lightning bolt strikes the ' + monster.name +
        ' with booming thunder! The damage is ' + str(var.LIGHTNING_DAMAGE) +
        ' hit points.', 'light blue')
    monster.fighter.take_damage(var.LIGHTNING_DAMAGE)
Exemplo n.º 9
0
def new_game():
    # initialize variables
    initialize_variables()
    var.dungeon_level = 1
    if not var.bsp_map_gen:
        make_map()
    else:
        make_bsp()
    initialize_fov()
    message(
        'Welcome stranger! Prepare to perish in the Tombs of the Ancient Kings.',
        'red')
Exemplo n.º 10
0
 def use(self):
     # special case: if the object has the Equipment component, the "use"
     # action is to equip/dequip
     if self.owner.equipment:
         self.owner.equipment.toggle_equip()
         return
     # just call the "use_function" if defined
     if self.use_function is None:
         message('The ' + self.owner.name + ' cannot be used.')
     else:
         if self.use_function() != 'cancelled':
             remove_item_from_inventory(
                 self)  # destroy after use, unless cancelled
Exemplo n.º 11
0
def monster_death(monster):
    # transform it into a nasty corpse! it doesn't block
    # can't be attacked and doesn't move
    message(
        monster.name.capitalize() + ' is dead! You gain ' +
        str(monster.fighter.xp) + ' experience points.', 'orange')
    monster.char = '%'
    monster.color = 'dark red'
    monster.blocks = False
    monster.fighter = None
    monster.ai = None
    monster.name = 'remains of ' + monster.name
    send_to_back(monster)
Exemplo n.º 12
0
def pick_up_item(item):
    # add to the player's inventory and remove from the map
    if len(var.inventory) >= 26:
        message(
            'Your inventory is full, cannot pick up ' + item.owner.name + '.',
            'red')
    else:
        var.inventory.append(item.owner)
        var.entities.remove(item.owner)
        message('You picked up a ' + item.owner.name + '!', 'green')
        # special case: automatically equip equipment if slot is available
        equipment = item.owner.equipment
        if equipment and get_equipped_in_slot(equipment.slot) is None:
            equipment.equip()
Exemplo n.º 13
0
def cast_confuse():
    # ask a player for a target to confuse
    message('Left-click an enemy to confuse it, or right-click to cancel.',
            'light cyan')
    monster = target_monster(var.CONFUSE_RANGE)
    if monster is None:
        return 'cancelled'
    # replace the monsters AI withe a 'confused' one
    old_ai = monster.ai
    monster.ai = ConfusedMonster(old_ai)
    monster.ai.owner = monster  # tell the new component who owns it
    message(
        'The eyes of the ' + monster.name +
        ' look vacant, as it starts to stumble around!', 'light green')
Exemplo n.º 14
0
def cast_fireball():
    # as the player for a target tile to throw a fireball at
    message(
        'left-click a target tile for the fireball, or right-click to cancel',
        'light cyan')
    (x, y) = target_tile()
    if x is None:
        return 'cancelled'
    message(
        'The fireball explodes, burning everything within ' +
        str(var.FIREBALL_RADIUS) + ' tiles!', 'orange')
    for ent in var.entities:  # damage every fighter in range, including the player
        if ent.distance_to(ent) <= var.FIREBALL_RADIUS and ent.fighter:
            message(
                'The ' + ent.name + ' gets burned for ' +
                str(var.FIREBALL_DAMAGE) + 'hit points.', 'orange')
            ent.fighter.take_damage(var.FIREBALL_DAMAGE)
Exemplo n.º 15
0
def player_death(player):
    message('You died!', 'red')
    var.game_state = 'dead'
    # for added affect, transform the player into a corpse!
    player.char = '%'
    player.color = 'dark red'
Exemplo n.º 16
0
 def dequip(self):
     # dequip object and show a message about it
     if not self.is_equipped: return
     self.is_equipped = False
     message('Dequipped ' + self.owner.name + ' from ' + self.slot + '.',
             'light yellow')