Example #1
0
    def execute(self, character, target_selection=None):
        holder = target_selection.get("Holder")
        item = target_selection.get("Item")
        pick_pocket_target = character.query.special_ability(PickPocketAbility)
        value = dice.D100(1).roll_total()
        context = contexts.TwoTargetAction(character, holder, item)
        if value > pick_pocket_target:
            if value == 100 or value >= pick_pocket_target * 2:
                message = StringBuilder(TargetOne, Verb("catch", TargetOne),
                                        Actor, "trying to steal")
                self.game.echo.see(character, message, context)
            else:
                self.game.echo.player(character,
                                      "You fail your pick pocket attempt!")

            return False
        else:
            if holder.inventory.remove(item):
                if character.inventory.add(item):
                    message = StringBuilder(Actor, Verb("steal", Actor),
                                            TargetTwo, "from", TargetOne)
                    self.game.echo.player(character, message)
                else:
                    holder.inventory.add(item)
                    message = StringBuilder(Actor, "are too full to steal",
                                            TargetTwo, "from", TargetOne, "!")
                    self.game.echo.player(character, message)

        return True
Example #2
0
    def wear(self, item):
        if self.armor_restrictions and not self.armor_restrictions.can_wear(item.base):
            return False

        if not item.wearable:
            return False

        empty_item_slots = self.get_empty_item_slots()
        for wear_location_set in item.wearable.wear_locations:
            if hasattr(wear_location_set, '__iter__'):
                # Multiple Location Slot
                for slot in wear_location_set:
                    proper_slot = next((item_slot for item_slot in empty_item_slots
                                        if item_slot.keyword == slot), None)
                    if proper_slot is not None:
                        proper_slot.item = item
                    else:
                        return False

                context = contexts.Action(self.host, item)
                message = StringBuilder(Actor, Verb("wear", Actor), Target, ".")
                self.host.game.echo.see(self.host, message, context)

                return True
            else:
                # Single Location Slot
                proper_slot = next((item_slot for item_slot in empty_item_slots
                                    if item_slot.keyword == wear_location_set), None)
                if proper_slot is not None:
                    proper_slot.item = item
                    context = contexts.Action(self.host, item)
                    message = StringBuilder(Actor, Verb("wear", Actor), Target, ".")
                    self.host.game.echo.see(self.host, message, context)
                    return True
        return False
Example #3
0
    def take_damage(self, damage, attacker=None):
        context = Combat(attacker=attacker, defender=self.host)
        echo = self.host.game.echo
        self.current -= damage
        if self.host.stats:
            constitution = int(self.host.stats.constitution)
        else:
            constitution = self._base_max_health

        if -constitution < self.current <= 0:
            if self.conscious:
                self.conscious = False
                echo.see(actor=self.host,
                         message=StringBuilder(Defender,
                                               Verb("fall",
                                                    Defender), "unconscious!"),
                         context=context)

        if self.current <= -constitution:
            if not self.dead:
                self.dead = True
                echo.see(actor=self.host,
                         message=StringBuilder(Defender, Verb("are", Defender),
                                               "dead!"),
                         context=context)

                self.host.blocking = False
                corpsify.turn_into_corpse(self.host)
                if attacker and attacker.experience:
                    attacker.experience.add_experience(
                        self.host.query.experience_value())
Example #4
0
    def _jump_successfully(self, character, obstacles_with_size):
        context = contexts.MultipleTargetAction(character, obstacles_with_size)
        if obstacles_with_size:
            message = StringBuilder(Actor, "successfully", Verb("jump", Actor),
                                    "over", Targets, "!")
        else:
            message = StringBuilder(Actor, Verb("jump", Actor), ".")

        self.game.echo.see(character, message, context)
        character.location.set_local_coords(self.target_coords)
Example #5
0
class NaturalAttack(MeleeAttack):
    name = ""
    on_success = StringBuilder(Attacker, Verb("hit", Attacker), Defender)
    on_failure = StringBuilder(Defender, Verb("dodge", Defender), His(Attacker), "attack!")
    on_stealth = StringBuilder(Attacker, Verb("surprise", Attacker), Defender, "with", His(Attacker), "attack,")

    def can_execute(self, attacker, defender):
        # Natural attacks should come from the body, in turn it should check for it when used.
        return True

    def echo(self, attacker, defender, success, damage, sneak_attack=False):
        context = contexts.Combat(attacker, defender)
        if success:
            if sneak_attack:
                message = self.on_stealth + "for {} damage!".format(damage)
            else:
                message = self.on_success + "for {} damage!".format(damage)
        else:
            message = self.on_failure
        self.game.echo.see(attacker, message, context)

    def execute(self, attacker, defender, attack_set):
        sneak_attack = False
        if attacker.query.special_ability(specialabilities.SneakAttack):
            if not defender.vision.can_see_object(attacker):
                sneak_attack = True

        attacker.events.transmit(events.Attacking(attacker))
        hits = 0
        for _ in range(0, attack_set.amount):
            success = self.make_melee_hit_roll(attacker, defender, sneak_attack=sneak_attack)
            if success:
                hits += 1
                base_attack = attack_set.attack
                damage = self.make_melee_damage_roll(
                    attacker, base_attack.damage_dice,
                    base_attack.damage_bonus,
                    sneak_attack=sneak_attack
                )

                self.echo(attacker, defender, True, damage, sneak_attack=sneak_attack)
                defender_health = defender.health
                if defender_health:
                    defender_health.take_damage(damage, attacker)
            else:
                self.echo(attacker, defender, False, 0)

        return True
Example #6
0
    def execute(self, character, target_selection=None):
        if not target_selection:
            return False

        container_object = target_selection.get("Container").targets[0]
        container = container_object.container
        content = target_selection.get("Content")

        for game_object in content:
            if not character.equipment.remove(game_object) and not character.inventory.remove(game_object):
                self.game.echo.player(character, "You cant drop {}".format(game_object.name))
                continue

            if not container.add_item(game_object):
                self.game.echo.player(
                    actor=character,
                    message="You cant put {} in {}".format(game_object.name, container_object.name))
                continue

            target_level = game_object.location.level
            if target_level:
                target_level.remove_object(game_object)

            context = contexts.Action(actor=character, target=container_object)
            message = StringBuilder(Actor, Verb("put", Actor), "in", Target)
            self.game.echo.see(character, message, context)

        return True
Example #7
0
 def _fail_jump(self, character):
     new_pos = self._select_random_tile_with_offset(character, True)
     context = contexts.Action(character, None)
     message = StringBuilder(Actor, Verb("trip", Actor),
                             "while trying to jump!")
     self.game.echo.see(character, message, context)
     character.location.set_local_coords(new_pos)
Example #8
0
    def wield(self, item):
        if self.weapon_restrictions and not self.weapon_restrictions.can_wield(item.base):
            return False

        hands = 1
        if self.weapon_size_restrictions:
            keyword = self.weapon_size_restrictions.can_wield(item.base)
            if not keyword:
                return False
            else:
                if keyword == self.weapon_size_restrictions.keywords.NeedsTwoHands:
                    hands = 2

        empty_grasp_slots = self.get_empty_grasp_slots()
        if len(empty_grasp_slots) >= hands:
            while hands > 0:
                item_slot = empty_grasp_slots.pop(0)
                item_slot.item = item
                hands -= 1

            context = contexts.Action(self.host, item)
            message = StringBuilder(Actor, Verb("wield", Actor), Target, ".")
            self.host.game.echo.see(self.host, message, context)

            return True
        return False
Example #9
0
    def execute(self, character, target_selection=None):
        for game_object in character.location.level.game_objects:
            if game_object is character:
                continue

            if game_object.vision and game_object.vision.can_see_object(character):
                self.game.echo.player(character, "You may not hide in plain sight.")
                return False

        hide_target = character.query.special_ability(HideAbility)
        value = dice.D100(1).roll_total()
        if value > hide_target:
            if character.effects.has_effect(effects.Hidden):
                character.effects.remove_effect(effects.Hidden)

            context = contexts.Action(character, None)
            self.game.echo.see(
                actor=character,
                message=StringBuilder(Actor, Verb("attempt",Actor),  "to hide."),
                context=context
            )
            return False
        else:
            self.game.echo.player(character, "You attempt to hide.")
            if not character.effects.has_effect(effects.Hidden):
                character.effects.add_effect(effects.Hidden(None))

        return True
Example #10
0
 def on_finish(self, game_object):
     context = Action(game_object, None)
     message = StringBuilder(Actor, Verb("is", Actor), "no longer healing.")
     game_object.game.echo.see(
         actor=game_object,
         message=message,
         context=context,
     )
Example #11
0
 def on_start(self, game_object):
     """
     Show a message,
     :param game_object:
     :return:
     """
     # You are on fire!
     context = contexts.Action(game_object, None)
     message = StringBuilder(Actor, Verb("are", Actor), "on fire!")
     game_object.game.echo.see(game_object, message, context)
Example #12
0
    def execute(self, character, target_selection=None):
        if not target_selection:
            return False

        for target in target_selection:
            if target.openable and target.openable.closed:
                if target.openable.open():
                    context = contexts.Action(character, target)
                    message = StringBuilder(Actor, Verb("open", Actor), Target)
                    self.game.echo.see(character, message, context)
                    if target.events:
                        target.events.transmit(events.Opened(character))

                    return True
                else:
                    context = contexts.Action(character, target)
                    message = StringBuilder(Actor, Verb("try", Actor), "to open", Target, "but it is locked!")
                    self.game.echo.see(character, message, context)

        return False
Example #13
0
    def _critical_failure_jump(self, character):
        new_pos = self._select_random_tile_with_offset(character, False)
        tile = character.location.level.get_tile(new_pos)
        context = contexts.Action(character, None)
        message = StringBuilder(Actor, Verb("trip", Actor), "and",
                                Verb("faceplant", Actor),
                                "into the %s!" % tile.name)

        self.game.echo.see(character, message, context)
        damage = dice.D4(1).roll_total()
        character.location.set_local_coords(new_pos)
        character.health.take_damage(damage, character)
Example #14
0
    def execute(self, character, target_selection=None):
        level = character.location.level
        for target in target_selection:
            if character.inventory.remove(
                    target) or character.equipment.remove(target):
                target.location.update_from_other(character.location)
                level.add_object(target)
                context = contexts.Action(character, target)
                message = StringBuilder(Actor, Verb("drop", Actor), Target)
                self.game.echo.see(character, message, context)

        return True
Example #15
0
    def execute(self, character, target_selection=None):
        open_lock_target = character.query.special_ability(OpenLockAbility)
        item = target_selection[0]
        value = dice.D100(1).roll_total()
        if value > open_lock_target:
            context = contexts.Action(character, item)
            message = StringBuilder(Actor, Verb("fail", Actor), "at picking",
                                    Target, "'s lock!")
            self.game.echo.see(actor=character,
                               message=message,
                               context=context)
            item.lock.add_failed_attempt(character, character.experience.level)

            return False

        item.lock.unlock()
        context = contexts.Action(character, item)
        message = StringBuilder(Actor, Verb("succeed", Actor), "at picking",
                                Target, "'s lock!")
        self.game.echo.see(actor=character, message=message, context=context)

        return True
Example #16
0
    def execute(self, character, target_selection=None):
        if not target_selection:
            return False

        for target in target_selection:
            if target.openable and not target.openable.closed:
                target.openable.close()
                context = contexts.Action(character, target)
                message = StringBuilder(Actor, Verb("close", Actor), Target)
                self.game.echo.see(character, message, context)
                return True

        return False
Example #17
0
    def execute(self, character, target_selection=None):
        target = target_selection[0]
        effects = target.consumable.effects
        for effect in effects:
            character.effects.add_effect(effect)

        if not character.inventory.remove(target):
            character.equipment.remove(target)

        context = contexts.Action(character, target)
        message = StringBuilder(Actor, Verb("eat", Actor), Target)
        self.game.echo.see(character, message, context)

        return True
Example #18
0
    def on_start(self, game_object):
        """
        Show a message,
        :param game_object:
        :return:
        """
        context = Action(game_object, None)
        message = StringBuilder(Actor, Verb("start", Actor), "healing!")

        game_object.game.echo.see(
            actor=game_object,
            message=message,
            context=context,
        )
Example #19
0
 def update(self, game_object):
     """
     At Each Update it deals damage to the game_object and shows a message
     :param game_object:
     :return:
     """
     super().update(game_object)
     damage = dice.D6(self.power).roll_total()
     # TODO This should be elemental Fire Damage.
     context = contexts.Action(game_object, None)
     message = StringBuilder(Actor, Verb("burn", Actor),
                             "for %s damage!" % damage)
     game_object.game.echo.see(game_object, message, context)
     game_object.health.take_damage(damage)
Example #20
0
    def execute(self, character, target_selection=None):
        remove_trap_target = character.query.special_ability(
            RemoveTrapsAbility)
        item = target_selection[0]
        value = dice.D100(1).roll_total()
        context = contexts.Action(character, item)
        if not target_selection[0].trap or value > remove_trap_target:
            self.game.echo.player(character, "You think there is no trap.")
            return False
        else:
            message = StringBuilder(Actor, Verb("found", Actor), "a", Target)
            self.game.player(character, message, context)

        value = dice.D100(1).roll_total()
        message = StringBuilder(Actor, Verb("attempt", Actor), "to disarm",
                                Target, "'s trap...")
        self.game.see(character, message, context)
        if value > remove_trap_target:
            item.trap.add_failed_attempt(character, character.experience.level)
            return False
        else:
            item.unregister_component_name(components.Trap.NAME)

        return True
Example #21
0
    def add(self, item):
        if self.host.equipment:
            containers = (item.container
                          for item in self.host.equipment.get_all_items()
                          if item.container)
            for container in containers:
                if container.add_item(item):
                    message = StringBuilder(Actor, Verb("add",
                                                        Actor), TargetOne,
                                            "to", His(Actor), TargetTwo)
                    context = contexts.TwoTargetAction(self.host, item,
                                                       container.host)
                    self.host.game.echo.see(self.host, message, context)

                    return True

        return False
Example #22
0
    def update(self, game_object):
        """
        At Each Update it deals damage to the game_object and shows a message
        :param game_object:
        :return:
        """
        super().update(game_object)
        health = self.dice.roll_total()
        context = Action(game_object, None)
        message = StringBuilder(Actor, Verb("recover", Actor),
                                "%s health!" % health)

        game_object.game.echo.see(
            actor=game_object,
            message=message,
            context=context,
        )

        game_object.health.restore_health(health)
Example #23
0
    def execute(self, attacker, defender, fired_weapons, distance, compatible_ammo):
        attacker.events.transmit(events.Attacking(attacker))
        for fired_weapon in fired_weapons:
            ammunition_spent = self.consume_ammunition(attacker, fired_weapon, compatible_ammo)
            context = contexts.RangedCombat(attacker, defender, fired_weapon, ammunition_spent)
            message = StringBuilder(
                Attacker, Verb("fire", Attacker), His(Attacker), AttackerWeapon, "at", Defender
            )
            if self.make_hit_roll(attacker, defender, fired_weapon, distance):
                damage = self.make_damage_roll(ammunition_spent)
                message += "hitting for %s damage!" % damage
                self.game.echo.see(attacker, message, context)
                defender.health.take_damage(damage, attacker)
            else:
                # TODO This message here could be better.
                message += "missing the shot!"
                self.game.echo.see(attacker, message, context)

        return True
Example #24
0
 def on_finish(self, game_object):
     context = contexts.Action(game_object, None)
     message = StringBuilder(Actor, Verb("are", Actor),
                             "no longer burning.")
     game_object.game.echo.see(game_object, message, context)
Example #25
0
class Sting(NaturalAttack):
    name = "sting"
    base_attack = attacks.Sting
    on_success = StringBuilder(Attacker, Verb("sting", Attacker), Defender)
    on_failure = StringBuilder(Defender, Verb("dodge", Defender), His(Attacker), "attack!")
    on_stealth = StringBuilder(Attacker, Verb("surprise", Attacker), Defender, "with", His(Attacker), "sting,")
Example #26
0
class Punch(NaturalAttack):
    name = "punch"
    base_attack = attacks.Punch
    on_success = StringBuilder(Attacker, Verb("punch", Attacker), Defender)
    on_failure = StringBuilder(Defender, Verb("dodge", Defender), His(Attacker), "attack!")
    on_stealth = StringBuilder(Attacker, Verb("surprise", Attacker), Defender, "with", His(Attacker), "punch,")
Example #27
0
class Kick(NaturalAttack):
    name = "kick"
    base_attack = attacks.Kick
    on_success = StringBuilder(Attacker, Verb("kick", Attacker), Defender)
    on_failure = StringBuilder(Defender, Verb("dodge", Defender), His(Attacker), "attack!")
    on_stealth = StringBuilder(Attacker, Verb("surprise", Attacker), Defender, "with", His(Attacker), "kick,")
Example #28
0
class Crush(NaturalAttack):
    name = "crush"
    base_attack = attacks.Crush
    on_success = StringBuilder(Attacker, Verb("crush", Attacker), Defender)
    on_failure = StringBuilder(Defender, Verb("dodge", Defender), His(Attacker), "attack!")
    on_stealth = StringBuilder(Attacker, Verb("surprise", Attacker), Defender, "with", His(Attacker), "crushing attack,")
Example #29
0
class ConfusionBySwarm(NaturalAttack):
    name = "Confusion By Swarm"
    base_attack = attacks.ConfusionBySwarm
    on_success = StringBuilder(Attacker, Verb("confuse", Attacker), Defender)
    on_failure = StringBuilder(Defender, Verb("dodge", Defender), His(Attacker), "attack!")
    on_stealth = StringBuilder(Attacker, Verb("surprise", Attacker), Defender, "with", His(Attacker), "confusing attack,")
Example #30
0
class Gaze(NaturalAttack):
    name = "gaze"
    base_attack = attacks.Gaze
    on_success = StringBuilder(Attacker, Verb("gaze", Attacker), Defender)
    on_failure = StringBuilder(Defender, Verb("dodge", Defender), His(Attacker), "attack!")
    on_stealth = StringBuilder(Attacker, Verb("surprise", Attacker), Defender, "with", His(Attacker), "gaze,")