Esempio n. 1
0
def do_special_melee(attack_type, source, target):
    """
    Have a Dude perform a special melee attack.

    attack_type - a string representing the type of special attack.
    source - the Dude attacking.
    target - the Dude being attacked.
    """

    if attack_type == "CRITICAL":
        damage_dealt = CRIT_MULTIPLIER * \
                       damage(source.attack, target.defense,
                              source.char_level, target.char_level)
        source.currentLevel.messages.append(
        "%(SOURCE_NAME)s runs %(TARGET_NAME)s all the way through! (%(DAMAGE)d)"
            % {"SOURCE_NAME": source.getName(),
               "DAMAGE": damage_dealt,
               "TARGET_NAME": target.getName()})
        target.cur_HP -= damage_dealt
        target.checkDeath()
    elif attack_type == "KNOCK":
        damage_dealt = KNOCK_DAMAGE
        direction = coordinates.subtract(target.coords, source.coords)
        source.currentLevel.messages.append(
        "%(SOURCE_NAME)s delivers a wicked punch to %(TARGET_NAME)s! (%(DAMAGE)d)"
            % {"SOURCE_NAME": source.getName(),
               "DAMAGE": damage_dealt,
               "TARGET_NAME": target.getName()})
        for i in range(KNOCK_DISTANCE):
            display.refresh_screen()
            destination = coordinates.add(target.coords, direction)
            if target.canMove(destination):
                target.currentLevel.moveDude(target, destination)
            else:
                break
        display.refresh_screen()
        target.cur_HP -= damage_dealt
        target.checkDeath()
    elif attack_type == "EXPLODE":
        explode_action = Explode(source.currentLevel, source.coords, 10)
        source.currentLevel.messages.append(
        "%(SOURCE_NAME)s explodes!"
            % {"SOURCE_NAME": source.getName()})
        explode_action.do()
    elif attack_type == "STICK":
        damage_dealt = damage(source.attack, target.defense,
                       source.char_level, target.char_level) / 5
        source.currentLevel.messages.append(
        "%(SOURCE_NAME)s spins a web around %(TARGET_NAME)s! (%(DAMAGE)d)"
            % {"SOURCE_NAME": source.getName(),
               "DAMAGE": damage_dealt,
               "TARGET_NAME": target.getName()})
        target.giveCondition(cond.Stuck(8))
        target.cur_HP -= damage_dealt
        target.checkDeath()
    else:
        raise exc.InvalidDataWarning("%s special ability used by %s on %s."
                                     % (attack_type, str(source), str(target)))
Esempio n. 2
0
File: msg.py Progetto: nrook/Spirit
    def say(self, thing_to_say):
        """
        Display a new string and refresh the display.

        thing_to_say - the string to be displayed.
        """

        self.append(thing_to_say)
        display.refresh_screen()
Esempio n. 3
0
    def do(self):
        cur_lev = self.source.currentLevel
        next_loc = self.source.coords

# Essentially a for loop, for i in range(self.distance).
        i = 0
        while True:
            if i >= self.distance:
                cur_lev.messages.append("%s pounced, but caught only air."
                    % self.source.getName())
                break

            i += 1

            next_loc = coordinates.add(self.source.coords, self.direction)
            display.refresh_screen()
            
            if not cur_lev.isEmpty(next_loc):
                cur_lev.messages.append("%s pounced at the wall."
                    % self.source.getName())
                break
            elif next_loc in cur_lev.dudeLayer:
                # The pouncer hit a dude.
                target = cur_lev.dudeLayer[next_loc]
                # Bounce off: behind the dude if possible, in front otherwise.
                behind = coordinates.add(next_loc, self.direction)
                in_front = coordinates.subtract(next_loc, self.direction)

                if (cur_lev.isEmpty(behind) and behind not in cur_lev.dudeLayer):
                    cur_lev.moveDude(self.source, behind)
# The pouncer should already be in front of the target, so if it is not going
# through them, no motion is necessary.

                damage_dealt = damage(self.source.attack, target.defense,
                               self.source.char_level, target.char_level)
                cur_lev.messages.append("%s pounced on %s! (%d)"
                    % (self.source.getName(), target.getName(), damage_dealt))
                target.cur_HP -= damage_dealt
                target.checkDeath()
                break

            else:
                cur_lev.moveDude(self.source, next_loc)

        display.refresh_screen()
        return self.source.speed
Esempio n. 4
0
File: pc.py Progetto: nrook/Spirit
    def act(self):
        """
        Take a turn or do interface things, depending on what the player wants.

        Returns: True if the player has taken a turn; False otherwise.
        """
        self.resetFOV()

        display.refresh_screen(self.currentLevel)

# Clear the message buffer.
        self.currentLevel.messages.archive()

        cond_action = self.getConditionAction()
        if cond_action is None:
# First, get an action.  The entire purpose of these lines is to get an action
# which can then be performed.  If they return instead, they should return
# False, as no action has been performed.  Note that if the player is trying to
# do something that basically exists outside of the game world (like quitting
# or saving the game), there is no reason not to just let him do it within the
# getAction() function itself.
            cur_action = self.getAction()
        else:
            cur_action = cond_action

        if cur_action.getCode() == "DO NOTHING":
            return 0

        if cur_action.getCode() == "UP":
# Going up a level is an action which the Level being left cannot feasibly deal
# with.  As such, an exception is raised instead, to be caught in the main
# loop.
            raise exc.LevelChange()
        
        action_ticks = cur_action.do()
        if action_ticks != 0:
            self.updateConditions()

        return action_ticks
Esempio n. 5
0
    def do(self):
        current_location = self.source.coords
        self.source.currentLevel.addSolidEffect(current_location, ARROW_GLYPH)
        self.source.currentLevel.makeNoise(
            self.message % {"SOURCE_NAME": self.source.getName()},
            self.source.coords)

        i = 0
        while True:
            i += 1
            display.refresh_screen()
            self.source.currentLevel.removeSolidEffect(current_location, ARROW_GLYPH)
            current_location = coordinates.add(current_location, self.direction)
            self.source.currentLevel.addSolidEffect(current_location, ARROW_GLYPH)

            if not self.source.currentLevel.isEmpty(current_location):
                break # If the arrow runs into a wall, just stop.
            elif current_location in self.source.currentLevel.dudeLayer:
                # The arrow hit a dude!
                target = self.source.currentLevel.dudeLayer[current_location]
                damage_dealt = damage(self.source.attack, target.defense,
                               self.source.char_level, target.char_level)
                self.source.currentLevel.makeNoise(
                    "The arrow hit %s. (%d)"
                    % (target.getName(), damage_dealt),
                    self.source.coords)
                display.refresh_screen()
                target.cur_HP -= damage_dealt
                target.checkDeath()
                self.source.currentLevel.removeSolidEffect(current_location, ARROW_GLYPH)
                break
            else:
                if i >= 12:
                    self.source.currentLevel.removeSolidEffect(current_location, ARROW_GLYPH)
                    display.refresh_screen()
                    break

        return self.source.speed