Ejemplo n.º 1
0
def orc(point=None, dungeon_level=1):
    #create an orc
    health_component = Health(20)
    ai_component = BasicNPC()

    npc = Character(point,
                    'O',
                    'orc',
                    COLORS.get('orc'),
                    ai=ai_component,
                    species=Species.ORC,
                    health=health_component,
                    act_energy=5)

    npc.add_component(Offence(base_power=10), 'offence')
    npc.add_component(Defence(defence=4), 'defence')
    npc.add_component(Level(xp_value=10), 'level')

    npc.movement.routing_avoid.extend(npc_avoid)

    item = equipment.create_weapon('shortsword')
    item.lootable = False

    npc.inventory.add_item(item)
    npc.equipment.toggle_equip(item)

    return npc
Ejemplo n.º 2
0
def goblin(point=None, dungeon_level=1):
    #create a goblin
    health_component = Health(20)
    ai_component = BasicNPC()

    npc = Character(point,
                    'G',
                    'goblin',
                    COLORS.get('goblin'),
                    ai=ai_component,
                    species=Species.GOBLIN,
                    health=health_component,
                    act_energy=5)

    npc.add_component(Offence(base_power=5), 'offence')
    npc.add_component(Defence(defence=5), 'defence')
    npc.add_component(Level(xp_value=10), 'level')

    npc.movement.routing_avoid.extend(npc_avoid)

    dagger = equipment.create_weapon('dagger')
    dagger.lootable = False

    npc.inventory.add_item(dagger)
    npc.equipment.toggle_equip(dagger)

    pubsub.pubsub.subscribe(
        pubsub.Subscription(npc, pubsub.PubSubTypes.DEATH,
                            goblin_observed_death))

    return npc
Ejemplo n.º 3
0
def mimic_activate(sub, message, level_map):
    if (sub.entity.uuid == message.target.uuid):
        sub.entity.add_component(BasicNPC(), 'ai')
        sub.entity.char = 'M'
        sub.entity.base_name = 'Mimic'
        sub.entity.del_component('shimmer')
        sub.entity.ai.set_target(message.entity)
        pubsub.pubsub.mark_subscription_for_removal(sub)
Ejemplo n.º 4
0
def convert_to_skeleton(npc):
    npc.char = 'S'
    npc.add_component(Naming(npc.base_name, prefix='Skeletal'), 'naming')
    npc.add_component(BasicNPC(), 'ai')
    npc.add_component(Health(max(1, npc.health.max_hp // 3)), 'health')
    npc.add_component(DamageModifier(blunt=1.2, slashing=0.8, poison=0),
                      'damagemodifier')

    npc.species = Species.UNDEAD
    npc.movement.routing_avoid.append(Tiles.SHALLOW_WATER)

    return npc
Ejemplo n.º 5
0
def hornets(point=None, dungeon_level=1):
    health_component = Health(2)

    creature = Character(point,
                         chr(178),
                         'hornet',
                         COLORS.get('hornet'),
                         ai=BasicNPC(),
                         species=Species.INSECT,
                         health=health_component,
                         act_energy=3)

    creature.add_component(Offence(base_power=1), 'offence')
    creature.add_component(Defence(defence=1), 'defence')
    creature.add_component(Level(xp_value=10), 'level')
    creature.add_component(
        Display([
            chr(176),
            chr(176),
            chr(176),
            chr(177),
            chr(177),
            chr(177),
            chr(178),
            chr(178),
            chr(178)
        ]), 'display')
    creature.add_component(
        DamageModifier(blunt=0.8,
                       slashing=0.8,
                       fire=1.2,
                       ice=1.2,
                       electric=1.2), 'damagemodifier')

    teeth = equipment.teeth()
    teeth.lootable = False

    creature.inventory.add_item(teeth)
    creature.equipment.toggle_equip(teeth)

    return creature
Ejemplo n.º 6
0
def troll(point=None, dungeon_level=1):
    #create a troll
    health_component = Health(30)
    ai_component = BasicNPC()

    npc = Character(point,
                    'T',
                    'troll',
                    COLORS.get('troll'),
                    ai=ai_component,
                    species=Species.TROLL,
                    health=health_component,
                    act_energy=6)

    npc.add_component(Offence(base_power=12), 'offence')
    npc.add_component(Defence(defence=8), 'defence')
    npc.add_component(Level(xp_value=10), 'level')
    regen = Regeneration()
    npc.add_component(regen, 'regeneration')
    npc.add_component(DamageModifier(fire=1.5), 'damagemodifier')
    regen.start()

    npc.movement.routing_avoid.extend(npc_avoid)

    item = None
    dice = randint(1, 100)
    if dice > 75:
        item = equipment.create_weapon('heavy mace')
        equipment.add_smashing(item)
    else:
        item = equipment.create_weapon('longsword')

    item.lootable = False

    npc.inventory.add_item(item)
    npc.equipment.toggle_equip(item)

    return npc
Ejemplo n.º 7
0
    def place_entities(self, room, entities):
        max_npcs_per_room = from_dungeon_level([[1, 1], [2, 4]],
                                               self.dungeon_level)
        max_monsters_per_room = from_dungeon_level([[2, 1], [3, 4], [5, 6]],
                                                   self.dungeon_level)
        max_items_per_room = from_dungeon_level([[1, 1], [2, 4]],
                                                self.dungeon_level)

        # Get a random number of npcs
        number_of_npcs = randint(1, max_npcs_per_room)

        # Get a random number of monsters
        number_of_monsters = randint(0, max_monsters_per_room)

        # Get a random number of items
        number_of_items = randint(0, max_items_per_room)

        npc_chances = {
            'bob':
            80,
            'robert':
            from_dungeon_level([[15, 1], [30, 5], [60, 7]], self.dungeon_level)
        }

        monster_chances = {
            'orc':
            80,
            'troll':
            from_dungeon_level([[15, 3], [30, 5], [60, 7]], self.dungeon_level)
        }

        item_chances = {
            'healing_potion': 35,
            'sword': from_dungeon_level([[5, 4]], self.dungeon_level),
            'shield': from_dungeon_level([[15, 8]], self.dungeon_level),
            'lightning_scroll': from_dungeon_level([[25, 4]],
                                                   self.dungeon_level),
            'fireball_scroll': from_dungeon_level([[25, 6]],
                                                  self.dungeon_level),
            'confusion_scroll': from_dungeon_level([[10, 2]],
                                                   self.dungeon_level)
        }

        for i in range(number_of_npcs):
            # Choose a random location in the room
            x = randint(room.x1 + 1, room.x2 - 1)
            y = randint(room.y1 + 1, room.y2 - 1)

            # Check if an entity is already in that location
            if not any([
                    entity
                    for entity in entities if entity.x == x and entity.y == y
            ]):
                npc_choice = random_choice_from_dict(npc_chances)

                if npc_choice == 'bob':
                    fighter_component = Fighter(hp=20,
                                                defense=0,
                                                power=4,
                                                xp=0)
                    social_component = Social(bond=0)
                    ai_component = BasicNPC()

                    npc = Entity(x,
                                 y,
                                 'b',
                                 libtcod.desaturated_green,
                                 'Bob',
                                 blocks=True,
                                 render_order=RenderOrder.ACTOR,
                                 fighter=fighter_component,
                                 social=social_component,
                                 ai=ai_component)
                else:
                    fighter_component = Fighter(hp=30,
                                                defense=2,
                                                power=8,
                                                xp=0)
                    social_component = Social(bond=0)
                    ai_component = BasicNPC()

                    npc = Entity(x,
                                 y,
                                 'R',
                                 libtcod.darker_green,
                                 'robert',
                                 blocks=True,
                                 fighter=fighter_component,
                                 render_order=RenderOrder.ACTOR,
                                 social=social_component,
                                 ai=ai_component)

                entities.append(npc)

        for i in range(number_of_monsters):
            # Choose a random location in the room
            x = randint(room.x1 + 1, room.x2 - 1)
            y = randint(room.y1 + 1, room.y2 - 1)

            # Check if an entity is already in that location
            if not any([
                    entity
                    for entity in entities if entity.x == x and entity.y == y
            ]):
                monster_choice = random_choice_from_dict(monster_chances)

                if monster_choice == 'orc':
                    fighter_component = Fighter(hp=20,
                                                defense=0,
                                                power=4,
                                                xp=35)
                    ai_component = BasicMonster()

                    monster = Entity(x,
                                     y,
                                     'o',
                                     libtcod.desaturated_green,
                                     'Orc',
                                     blocks=True,
                                     render_order=RenderOrder.ACTOR,
                                     fighter=fighter_component,
                                     ai=ai_component)
                else:
                    fighter_component = Fighter(hp=30,
                                                defense=2,
                                                power=8,
                                                xp=100)
                    ai_component = BasicMonster()

                    monster = Entity(x,
                                     y,
                                     'T',
                                     libtcod.darker_green,
                                     'Troll',
                                     blocks=True,
                                     fighter=fighter_component,
                                     render_order=RenderOrder.ACTOR,
                                     ai=ai_component)

                entities.append(monster)

        for i in range(number_of_items):
            x = randint(room.x1 + 1, room.x2 - 1)
            y = randint(room.y1 + 1, room.y2 - 1)

            if not any([
                    entity
                    for entity in entities if entity.x == x and entity.y == y
            ]):
                item_choice = random_choice_from_dict(item_chances)

                if item_choice == 'healing_potion':
                    item_component = Item(use_function=heal, amount=40)
                    item = Entity(x,
                                  y,
                                  '!',
                                  libtcod.violet,
                                  'Healing Potion',
                                  render_order=RenderOrder.ITEM,
                                  item=item_component)
                elif item_choice == 'sword':
                    equippable_component = Equippable(EquipmentSlots.MAIN_HAND,
                                                      power_bonus=3)
                    item = Entity(x,
                                  y,
                                  '/',
                                  libtcod.sky,
                                  'Sword',
                                  equippable=equippable_component)
                elif item_choice == 'shield':
                    equippable_component = Equippable(EquipmentSlots.OFF_HAND,
                                                      defense_bonus=1)
                    item = Entity(x,
                                  y,
                                  '[',
                                  libtcod.darker_orange,
                                  'Shield',
                                  equippable=equippable_component)
                elif item_choice == 'fireball_scroll':
                    item_component = Item(
                        use_function=cast_fireball,
                        targeting=True,
                        targeting_message=Message(
                            'Left-click a target tile for the fireball, or right-click to cancel.',
                            libtcod.light_cyan),
                        damage=25,
                        radius=3)
                    item = Entity(x,
                                  y,
                                  '#',
                                  libtcod.red,
                                  'Fireball Scroll',
                                  render_order=RenderOrder.ITEM,
                                  item=item_component)
                elif item_choice == 'confusion_scroll':
                    item_component = Item(
                        use_function=cast_confuse,
                        targeting=True,
                        targeting_message=Message(
                            'Left-click an enemy to confuse it, or right-click to cancel.',
                            libtcod.light_cyan))
                    item = Entity(x,
                                  y,
                                  '#',
                                  libtcod.light_pink,
                                  'Confusion Scroll',
                                  render_order=RenderOrder.ITEM,
                                  item=item_component)
                else:
                    item_component = Item(use_function=cast_lightning,
                                          damage=40,
                                          maximum_range=5)
                    item = Entity(x,
                                  y,
                                  '#',
                                  libtcod.yellow,
                                  'Lightning Scroll',
                                  render_order=RenderOrder.ITEM,
                                  item=item_component)

                entities.append(item)
Ejemplo n.º 8
0
def teleport(**kwargs):
    '''Cast teleport.

    Transport the casting entity to a random open tile on the map.
    There is a chance the teleport will have a secondary negative effect:
    10% of entity being damaged for 1d6 + distance between start and end points.
    1% chance a clone of the entity is created which hunts them down.

    Parameters
    ----------
    kwargs:
       caster (Entity): Entity that initiated the spell.
       game_map (GameMap): Current game map.

    Returns
    -------
    results (list)
        Results of casting the spell.
    '''
    caster = kwargs.get('caster')
    game_map = kwargs.get('game_map')

    results = []

    point = game_map.current_level.find_random_open_position()
    orginal_point = caster.point
    caster.movement.place(point.x, point.y, game_map.current_level)

    results.append({
        ResultTypes.MESSAGE:
        Message(
            'You feel like you are torn apart and put back together again.',
            COLORS.get('success_text'))
    })
    results.append({ResultTypes.FOV_RECOMPUTE: True})

    chance_of_teleport_going_wrong = randint(1, 100)

    if (chance_of_teleport_going_wrong >= 99):
        clone = bestiary.create_player()
        clone_point = game_map.current_level.find_random_open_position()
        clone.set_point(clone_point)
        clone.char = 'C'
        clone.base_name = 'Clone of ' + clone.base_name
        clone.add_component(BasicNPC(), 'ai')
        clone.ai.set_target(caster)
        clone.ai.tree.namespace["target_point"] = caster.point
        game_map.current_level.add_entity(clone)
        results.append({
            ResultTypes.MESSAGE:
            Message(f"You feel as if you are split in two.",
                    COLORS.get('damage_text'))
        })

    elif (chance_of_teleport_going_wrong >= 89):
        damage_results, total_damage = caster.health.take_damage(
            die_roll(1, 6, int(orginal_point.distance_to(point))))
        results.append({
            ResultTypes.MESSAGE:
            Message(f"You take {str(total_damage)} damage.",
                    COLORS.get('damage_text'))
        })
        results.extend(damage_results)

    return results