コード例 #1
0
 def drop(self):
     self.coord = self.context.player.coord
     self.context.object_pool.append(self)
     self.context.player.get_inventory().remove(self)
     self.context = None
     self.player = None
     send_message('You droped ' + self.name + '!', Colors.yellow)
コード例 #2
0
 def equip(self):
     equipment = self.player.fighter.get_equipped_items(self.slot)
     if equipment:
         equipment[0].dequip()
     self.is_equipped = True
     send_message('Equipped ' + self.name + ' on ' + self.slot.value + '.',
                  color=Colors.light_green)
コード例 #3
0
    def cast_selfheal(ref, **kwargs):
        # heal the player
        if ref.context.player.fighter.hp == ref.context.player.fighter.max_hp:
            send_message('You are already at full health.', Colors.red)
            return 'cancelled'

        send_message('Your wounds start to feel better!', Colors.light_violet)
        ref.context.player.fighter.heal(kwargs["heal_amount"])
コード例 #4
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.num_turns -= 1

        else:  # restore the previous AI (this one will be deleted because it's not referenced anymore)
            self.owner.ai = self.old_ai
            send_message('The ' + self.owner.name + ' is no longer frozen!',
                         Colors.red)
コード例 #5
0
 def check_level_up(self):
     # see if the player's experience is enough to level-up
     while self.xp >= self.level_up_xp:
         self.level += 1
         self.xp -= self.level_up_xp
         send_message(
             'Your battle skills grow stronger! You reached level ' +
             str(self.level) + '!',
             color=Colors.yellow)
         self.level_up_xp = self._level_up_base + self.level * self._level_up_factor
         broadcast_message("game-controller",
                           {EMessage.LEVEL_UP: self.owner})
コード例 #6
0
    def attack(self, target):
        # a simple formula for attack damage
        damage = self.power - target.fighter.defense

        if damage > 0:
            send_message(
                self.owner.name.capitalize() + ' attacks ' + target.name +
                ' for ' + str(damage) + ' hit points.', Colors.light_blue)
            target.fighter.take_damage(damage)
        else:
            send_message(
                self.owner.name.capitalize() + ' attacks ' + target.name +
                ' but it has no effect!', Colors.light_blue)
コード例 #7
0
 def use(self):
     # just call the "use_function" if it is defined
     if self.use_function is None:
         send_message('The ' + self.name + ' cannot be used. It vanishes!',
                      color=Colors.azure)
     else:
         if self.use_function(
                 self, **self.extra_params
         ) != 'cancelled' and self.context.player.get_inventory():
             self.context.player.get_inventory().remove(
                 self
             )  # destroy after use, unless it was cancelled for some reason
             self.context = None
コード例 #8
0
 def pick_up(self, player):
     if player.get_inventory() is not None:
         if len(player.get_inventory()) >= 26:
             send_message(
                 'Your inventory is full, cannot pick up ' + self.name +
                 '.', Colors.red)
         else:
             self.context = player.context
             player.get_inventory().append(self)
             self.player = player
             send_message('You picked up a ' + self.name + '!',
                          Colors.green)
             if not self.player.fighter.get_equipped_items(self.slot):
                 self.equip()
             return True
     return False
コード例 #9
0
    def cast_lightning(ref, **kwargs):
        # find closest enemy (inside a maximum range) and damage it
        objs = ref.context.targeting(**kwargs)

        if objs:
            for obj in objs:
                # zap it!
                send_message(
                    'A lighting bolt strikes the ' + obj.name +
                    ' with a loud thunder! The damage is ' +
                    str(ref.extra_params["damage"]) + ' hit points.',
                    Colors.light_blue)
                obj.fighter.take_damage(ref.extra_params["damage"])
        else:
            send_message('No targets found!')
            return 'canceled'
コード例 #10
0
 def cast_confuse(ref, **kwargs):
     # find closest enemy in-range and confuse it
     monsters = ref.context.targeting(**kwargs)
     if monsters:  # no enemy found within maximum range
         for monster in monsters:
             # replace the monster's AI with a "confused" one; after some turns it will restore the old AI
             StatusEffects.behavior_change(target=monster,
                                           behaviour="confused",
                                           **kwargs)
             send_message(
                 'The eyes of the ' + monster.name +
                 ' look vacant, as he starts to stumble around!',
                 Colors.light_green)
     else:
         send_message('No enemy is close enough to confuse.', Colors.red)
         return 'cancelled'
コード例 #11
0
 def use(self):
     if not self.is_equipped:
         self.equip()
     else:
         # just call the "use_function" if it is defined
         if self.use_function is None or self.charges <= 0:
             send_message('There are no special properties on ' + self.name,
                          color=Colors.azure)
         else:
             if self.use_function(
                     self, **self.extra_params
             ) != 'cancelled' and self.context.player.get_inventory():
                 if self.charges != "infinite":
                     if self.charges > 0:
                         self.charges -= 1
                         send_message(
                             "There are {} charges left on {}!".format(
                                 self.charges, self.name),
                             color=Colors.azure)
コード例 #12
0
 def pick_up(self, player):
     # add to the player's inventory and remove from the map
     if player.get_inventory() is not None:
         if len(player.get_inventory()) >= 26:
             try:
                 send_message(
                     'Your inventory is full, cannot pick up ' + self.name +
                     '.', Colors.red)
             except Exception as e:
                 logger.error("send_message() is not initialized yet", e)
         else:
             self.context = player.context
             player.get_inventory().append(self)
             try:
                 send_message('You picked up a ' + self.name + '!',
                              Colors.green)
             except Exception as e:
                 logger.error("send_message() is not initialized yet", e)
             return True
     return False
コード例 #13
0
    def custom_magic(ref, **kwargs):
        targets = ref.context.targeting(**kwargs)

        if targets:  # no enemy found within maximum range
            if "status_effect" in kwargs.keys():
                status_effect = kwargs["status_effect"]
            else:
                status_effect = None

            if "heal_amount" in kwargs.keys():
                heal_amount = kwargs["heal_amount"]
            else:
                heal_amount = None
            if "damage" in kwargs.keys():
                damage = kwargs["damage"]
            else:
                damage = None

            if "flavor_text" in kwargs.keys():
                flavor_text = kwargs["flavor_text"]
            else:
                flavor_text = "The {target} was hit by {name}!"

            for target in targets:
                if status_effect:
                    status_effect(target=target, **kwargs)

                if target.fighter:
                    if damage:
                        target.fighter.take_damage(damage)
                    if heal_amount:
                        target.fighter.heal(heal_amount)

                send_message(
                    flavor_text.format(target=target.name,
                                       name=ref.name,
                                       **kwargs), Colors.light_green)
        else:
            send_message('No target found!', Colors.red)
            return 'cancelled'
コード例 #14
0
    def cast_heal(ref, **kwargs):
        # heal the targets
        objs = ref.context.targeting(**kwargs)

        if objs:
            for obj in objs:
                if obj.fighter.hp < obj.fighter.max_hp:
                    send_message("The {}'s wounds start to feel better!",
                                 Colors.light_violet)
                    obj.fighter.heal(kwargs["heal_amount"])
                else:
                    send_message("The {} is already at full health!",
                                 Colors.light_violet)
        else:
            send_message('No targets found!', Colors.red)
            return 'cancelled'
コード例 #15
0
    def cast_fireball(ref, **kwargs):
        # ask the player for a target tile to throw a fireball at

        send_message(
            'Left-click a target tile for the {}, or right-click to cancel.'.
            format(ref.name), Colors.light_cyan)

        objs = ref.context.targeting(**kwargs)

        if objs:
            send_message(
                'The fireball explodes, burning everything within ' +
                str(kwargs["radius"]) + ' tiles!', Colors.orange)
            for obj in objs:
                # damage every fighter in range, including the player
                send_message(
                    'The ' + obj.name + ' gets burned for ' +
                    str(kwargs["damage"]) + ' hit points.', Colors.orange)
                if obj.fighter:
                    obj.fighter.take_damage(kwargs["damage"])
        else:
            send_message('Canceled!', Colors.blue)
            return 'cancelled'
コード例 #16
0
 def dequip(self):
     if self.is_equipped:
         self.is_equipped = False
         send_message('Dequipped ' + self.name + ' from ' + self.slot.name +
                      '.',
                      color=Colors.light_yellow)
コード例 #17
0
 def invalid_function(ref, **kwargs):
     send_message('The {} vanishes!'.format(ref.name))
コード例 #18
0
 def gain_xp(self, amount):
     send_message("{name} gained {amount} xp".format(name=self.owner.name,
                                                     amount=amount),
                  color=Colors.cyan)
     self.xp += amount
     self.check_level_up()