示例#1
0
def spawn_player(x, y):
    # Entity Name, Pos & Rend & PLAYER
    x, y = x, y
    pos = PositionComponent(x, y)
    rend = RenderableComponent(glyph='@',
                               char_color='white',
                               render_order=Layers.PLAYER,
                               sprite='chars/player.png')
    name = NameComponent('Player')
    viewshed = ViewshedComponent()
    player = PlayerComponent()
    block = BlockTileComponent()
    attributes = AttributesComponent(
        might=config.DEFAULT_PLAYER_MIGHT_ATTRIBUTE,
        body=config.DEFAULT_PLAYER_BODY_ATTRIBUTE,
        quickness=config.DEFAULT_PLAYER_QUICKNESS_ATTRIBUTE,
        wits=config.DEFAULT_PLAYER_WITS_ATTRIBUTE)
    autopickup = AutopickupComponent()
    skills = SkillsComponent()
    skills.skills[Skills.MELEE] = 1
    skills.skills[Skills.DODGE] = 1
    skills.skills[Skills.FOUND_TRAPS] = 1
    player_pool = Pools(hits=player_hp_at_level(attributes.body, 1),
                        mana=mana_point_at_level(attributes.wits, 1))
    player_initiative = InitiativeComponent(0)

    player_id = World.create_entity(pos, rend, name, player, viewshed, block,
                                    attributes, skills, player_pool,
                                    autopickup, player_initiative)

    known_spells = KnownSpells()
    World.add_component(known_spells, player_id)

    return player_id
示例#2
0
def add_attribute_effect(effect_spawner, target):
    turns = effect_spawner.effect.turns
    World.create_entity(
        StatusEffectComponent(target),
        effect_spawner.effect.attr_bonus,
        DurationComponent(nb_turns=turns),
        NameComponent(Texts.get_text("ATTRIBUTE_MODIFIER"))
    )
    World.add_component(EquipmentChangedComponent(), target)
示例#3
0
def add_damage_over_time_effect(effect_spawner, target):
    turns = effect_spawner.effect.turns
    World.create_entity(
        StatusEffectComponent(target),
        DamageOverTimeEffect(effect_spawner.effect.damage),
        DurationComponent(nb_turns=turns),
        NameComponent(Texts.get_text("DAMAGE_OVER_TIME"))
    )
    World.add_component(EquipmentChangedComponent(), target)
示例#4
0
def add_slow_effect(effect_spawner, target):
    turns = effect_spawner.effect.turns
    slow_effect_name = get_slow_effect_name(effect_spawner.effect.initiative_penality)
    World.create_entity(
        StatusEffectComponent(target),
        SlowSpellEffect(effect_spawner.effect.initiative_penality),
        DurationComponent(nb_turns=turns),
        NameComponent(Texts.get_text(slow_effect_name))
    )
    World.add_component(EquipmentChangedComponent(), target)
示例#5
0
 def spawn_named_spell(name):
     print(f'name is {name}')
     if RawCompendium.spell_index.get(name):
         template = RawCompendium.spells[RawCompendium.spell_index.get(name)
                                         - 1]
         print(f'template is {template}')
         effects = RawsMaster.apply_effects(template.get("effects"))
         spell = World.create_entity(
             SpellTemplate(mana_cost=template.get("mana_cost", 0)),
             NameComponent(name=template.get("name")))
         for effect in effects:
             World.add_component(effect, spell)
示例#6
0
def add_confusion_effect(effect_spawner, target):
    turns = effect_spawner.effect.turns
    World.create_entity(StatusEffectComponent(target),
                        ConfusionComponent(),
                        DurationComponent(nb_turns=turns),
                        NameComponent(Texts.get_text("CONFUSION")))
    logs = World.fetch('logs')
    target_named = World.get_entity_component(target, NameComponent).name
    creator_named = World.get_entity_component(effect_spawner.creator, NameComponent).name
    if target_named and creator_named:
        if target_named != creator_named:
            logs.appendleft(f"{creator_named}{Texts.get_text('_INFLICT_CONFUSION_AT_')}{target_named}")
        else:
            logs.appendleft(f"{creator_named}{Texts.get_text('_INFLICT_CONFUSION_ON_THEMSELF')}")
    elif target_named:
        logs.appendleft(f'{target_named}{Texts.get_text("_BECOMES_CONFUSED")}')
示例#7
0
    def create_prop(name, x, y):
        to_create = RawCompendium.props[RawCompendium.props_index[name] - 1]
        components_for_entity = list()

        if to_create.get("name"):
            components_for_entity.append(NameComponent(to_create.get("name")))

        if to_create.get("renderable"):
            components_for_entity.append(
                RenderableComponent(
                    glyph=to_create["renderable"].get('glyph'),
                    char_color=to_create["renderable"].get('fg'),
                    render_order=to_create["renderable"].get('order'),
                    sprite=to_create["renderable"].get('sprite')))

        if to_create.get("hidden"):
            components_for_entity.append(HiddenComponent())

        if to_create.get("entry_trigger"):
            components_for_entity.append(EntryTriggerComponent())
            if to_create['entry_trigger'].get('effects'):
                if to_create['entry_trigger']['effects'].get('damage'):
                    damage = InflictsDamageComponent(
                        int(to_create['entry_trigger']['effects'].get(
                            'damage')))
                    components_for_entity.append(damage)
                if to_create['entry_trigger']['effects'].get('activations'):
                    activations = ActivationComponent(
                        int(to_create['entry_trigger']['effects'].get(
                            'activations')))
                    components_for_entity.append(activations)

        if to_create.get("blocks_tile"):
            components_for_entity.append(BlockTileComponent())

        if to_create.get('blocks_visibility'):
            components_for_entity.append(BlockVisibilityComponent())

        if to_create.get('door_close'):
            components_for_entity.append(
                DoorComponent(to_create.get('door_close')))

        prop_id = World.create_entity(PositionComponent(x, y))

        for component in components_for_entity:
            World.add_component(component, prop_id)
示例#8
0
    def create_item(name, x, y):
        to_create = RawCompendium.items[RawCompendium.item_index[name] - 1]

        components_for_entity = [ItemComponent()]

        if to_create.get('name'):
            components_for_entity.append(NameComponent(to_create.get('name')))

        if to_create.get('renderable'):
            renderable = to_create.get('renderable')
            components_for_entity.append(
                RenderableComponent(glyph=renderable.get('glyph'),
                                    char_color=renderable.get('fg'),
                                    render_order=renderable.get('order'),
                                    sprite=renderable.get('sprite')))

        if to_create.get('consumable'):
            consumable_comp = ConsumableComponent()
            consumable_dic = to_create.get('consumable')

            if consumable_dic.get('effects'):
                effect_components = RawsMaster.apply_effects(
                    consumable_dic.get('effects'))

                for effect_component in effect_components:
                    components_for_entity.append(effect_component)

            if consumable_dic.get('charges'):
                consumable_comp.charges = consumable_dic.get('charges', 1)

            components_for_entity.append(consumable_comp)

        if to_create.get('weapon'):
            weapon = to_create.get('weapon')
            components_for_entity.append(
                EquippableComponent(EquipmentSlots.MELEE))

            weap_attribute = weapon.get('attribute', WeaponAttributes.MIGHT)
            weap_min_dmg = weapon.get('min_dmg')
            weap_max_dmg = weapon.get('max_dmg')
            weap_dmg_bonus = weapon.get('dmg_bonus')
            weap_hit_bonus = weapon.get('hit_bonus')
            weap_proc_chance = weapon.get('proc_chance', 0)
            weap_proc_target = weapon.get('proc_target', 0)
            weap_proc_effects = weapon.get('proc_effects')

            components_for_entity.append(
                MeleeWeaponComponent(weap_attribute, weap_min_dmg,
                                     weap_max_dmg, weap_dmg_bonus,
                                     weap_hit_bonus, weap_proc_chance,
                                     weap_proc_target))

            if weap_proc_effects:
                effects_list = RawsMaster.apply_effects(weap_proc_effects)
                for effect in effects_list:
                    components_for_entity.append(effect)

        if to_create.get('wearable'):
            wearable = to_create.get('wearable')
            components_for_entity.append(
                EquippableComponent(wearable.get('slot')))

            if wearable.get('armor'):
                components_for_entity.append(
                    WearableComponent(wearable.get('armor')))

        if to_create.get('magic'):
            magic = to_create.get('magic')
            identified_items = World.fetch('master_dungeon').identified_items
            magic_class = magic.get('class', MagicItemClass.COMMON)
            magic_naming_convention = magic.get('naming')
            magic_cursed = magic.get('cursed', False)

            # si nom inconnu, on utilise l'obfuscation
            print(f'create magic item: name is {name}')
            if name not in identified_items:
                if magic_naming_convention == 'scroll':
                    scroll_names = World.fetch(
                        'master_dungeon').scroll_mappings
                    components_for_entity.append(
                        ObfuscatedNameComponent(scroll_names.get(name)))
                elif magic_naming_convention == 'potion':
                    print(f'create magic item potion: name is {name}')
                    potion_names = World.fetch(
                        'master_dungeon').potion_mappings
                    print(
                        f'create magic potion potion names get :  {potion_names.get(name)} '
                    )
                    components_for_entity.append(
                        ObfuscatedNameComponent(potion_names.get(name)))
                else:
                    components_for_entity.append(
                        ObfuscatedNameComponent(magic_naming_convention))

            components_for_entity.append(
                MagicItemComponent(magic_class=magic_class,
                                   naming=magic_naming_convention,
                                   cursed=magic_cursed))

            if magic_cursed:
                components_for_entity.append(CursedItemComponent())

        if to_create.get('attributes'):
            attributes = to_create.get('attributes')
            components_for_entity.append(
                AttributeBonusComponent(might=attributes.get('might'),
                                        body=attributes.get('body'),
                                        quickness=attributes.get('quickness'),
                                        wits=attributes.get('wits')))

        item_id = World.create_entity(PositionComponent(x, y))
        for component in components_for_entity:
            World.add_component(component, item_id)

        return True
示例#9
0
    def create_mob(name, x, y):
        to_create = RawCompendium.mobs[RawCompendium.mob_index[name] - 1]

        components_for_entity = list()
        components_for_entity.append(MonsterComponent())
        components_for_entity.append(
            InitiativeComponent(config.BASE_MONSTER_INITIATIVE))

        if to_create.get("name"):
            components_for_entity.append(NameComponent(to_create.get("name")))

        if to_create.get('renderable'):
            renderable = to_create.get('renderable')
            components_for_entity.append(
                RenderableComponent(glyph=renderable.get('glyph'),
                                    char_color=renderable.get('fg'),
                                    render_order=renderable.get('order'),
                                    sprite=renderable.get('sprite')))

        if to_create.get('blocks_tile'):
            components_for_entity.append(to_create.get('blocks_tile'))

        if to_create.get('vision_range'):
            components_for_entity.append(
                ViewshedComponent(to_create.get('vision_range')))

        if to_create.get('attributes'):
            attributes = to_create.get('attributes')
            mob_attr = AttributesComponent(might=attributes.get('might', 1),
                                           body=attributes.get('body', 1),
                                           quickness=attributes.get(
                                               'quickness', 1),
                                           wits=attributes.get('wits', 1))
            components_for_entity.append(mob_attr)

            # attributes needed for pv & mana
            if to_create.get('lvl'):
                mob_lvl = to_create.get('lvl')
            else:
                mob_lvl = 1
            mob_hp = npc_hp_at_lvl(mob_attr.body, mob_lvl)
            mob_mana = mana_point_at_level(mob_attr.wits, mob_lvl)

            components_for_entity.append(Pools(mob_hp, mob_mana, mob_lvl))

        if to_create.get('skills'):
            skills = to_create.get('skills')
            skill_component = SkillsComponent()
            for skill in skills:
                skill_component.skills[skill] = skills[skill]
            components_for_entity.append(skill_component)

        if to_create.get('natural'):
            natural = to_create.get('natural')
            natural_def_attack_component = NaturalAttackDefenseComponent(
                natural.get('armor', 0))

            attacks = natural.get('attacks')
            if attacks:
                for attack in attacks:
                    attack_to_create = RawCompendium.natural_attacks[
                        RawCompendium.natural_attacks_index[attack] - 1]
                    natural_attack = NaturalAttack(
                        attack_to_create.get('name', 'Unknown attack'),
                        attack_to_create.get('attribute',
                                             WeaponAttributes.MIGHT),
                        attack_to_create.get('min_dmg',
                                             config.DEFAULT_MIN_DMG),
                        attack_to_create.get('max_dmg',
                                             config.DEFAULT_MAX_DMG),
                        attack_to_create.get('dmg_bonus', 0),
                        attack_to_create.get('hit_bonus', 0))
                    natural_def_attack_component.attacks.append(natural_attack)
            components_for_entity.append(natural_def_attack_component)

        mob_id = World.create_entity(PositionComponent(x, y))

        for component in components_for_entity:
            print(f'CREATE MOB: Component : {component}')
            World.add_component(component, mob_id)

        return True