Esempio n. 1
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
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
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)
Esempio n. 5
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
Esempio n. 6
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)
Esempio n. 7
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
Esempio n. 8
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)
Esempio n. 9
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
Esempio n. 10
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
Esempio n. 11
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
Esempio n. 12
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
Esempio n. 13
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)
Esempio n. 14
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
Esempio n. 15
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)