Пример #1
0
    def test_getter_gets_set_values(self):
        e = Entity()
        expected = IntComponent(13)
        e.set(expected)

        actual = e.get(IntComponent)
        self.assertEqual(actual, expected)
Пример #2
0
def generate_monster(map, x, y, id):
    if id is Monsters.PLAYER:
        return Entity(
            "player", {
                Components.READS_INPUT: ReadsInput(),
                Components.POSITION: Position(x, y, True),
                Components.ICON: Icon('@', render_order=Render_Order.ACTOR),
                Components.MOVABLE: Movable(),
                Components.FOV: FOV(map, 8, True, 1),
                Components.ABILITY_SCORES: Ability_Scores(),
                Components.FIGHTER: Fighter(),
                Components.HITPOINTS: Hitpoints(10)
            })

    if id is Monsters.KOBOLD:
        return Entity(
            "kobold", {
                Components.POSITION: Position(x, y, True),
                Components.ICON: Icon('k', tcod.orange, Render_Order.ACTOR),
                Components.MOVABLE: Movable(),
                Components.FOV: FOV(map, 10, algorithm=1),
                Components.ABILITY_SCORES: Ability_Scores(),
                Components.FIGHTER: Fighter(),
                Components.HITPOINTS: Hitpoints(8),
                Components.AI: AI()
            })
Пример #3
0
    def test_no_coincident(self):
        """Target nothing if there are no coincident entities."""
        container = Container()
        system = CursorSystem(container)

        cursor = Entity(PositionComponent(1, 1), CursorComponent())
        first = Entity(PositionComponent(2, 2))

        container.entities = [
            cursor,
            first,
        ]

        system.check_target()

        self.assertIsNone(container.target)
Пример #4
0
def make_throne(x, y):
    return Entity(
        DisplayComponent(char=chr(210),
                         fg=constants.COLOR_YELLOW,
                         layer=DrawLayer.THRONE),
        NameComponent(name='throne'),
        PositionComponent(x, y),
        ThroneComponent(),
    )
Пример #5
0
    def test_swap_second(self):
        """Target the first coincident entity with a RandomNumberComponent."""
        container = Container()
        system = CursorSystem(container)

        cursor = Entity(PositionComponent(1, 1), CursorComponent())
        first = Entity(PositionComponent(1, 1))
        second = Entity(PositionComponent(1, 1), RandomNumberComponent())

        container.entities = [
            cursor,
            first,
            second,
        ]

        system.check_target()

        self.assertIs(container.target, second)
Пример #6
0
    def test_stat_second(self):
        """Target the first coincident entity with a CombatComponent and InventoryComponent."""
        container = Container()
        system = CursorSystem(container)

        cursor = Entity(PositionComponent(1, 1), CursorComponent())
        first = Entity(PositionComponent(1, 1))
        second = Entity(PositionComponent(1, 1),
                        CombatComponent(0, 0, 0, 0, 0), InventoryComponent(0))

        container.entities = [
            cursor,
            first,
            second,
        ]

        system.check_target()

        self.assertIs(container.target, second)
Пример #7
0
def antidote():
    return Entity(
        NameComponent('antidote'),
        DisplayComponent(char=chr(173),
                         fg=constants.COLOR_WHITE,
                         layer=DrawLayer.ITEM),
        ItemComponent(),
        consumables.Antidote(),
        DurabilityComponent(durability=3),
    )
Пример #8
0
def smoke_bomb():
    return Entity(
        NameComponent('smoke bomb'),
        DisplayComponent(char=chr(173),
                         fg=constants.COLOR_WHITE,
                         layer=DrawLayer.ITEM),
        ItemComponent(),
        consumables.SmokeBomb(),
        DurabilityComponent(durability=3),
    )
Пример #9
0
def elixir():
    return Entity(
        NameComponent('elixir'),
        DisplayComponent(char=chr(173),
                         fg=constants.COLOR_WHITE,
                         layer=DrawLayer.ITEM),
        ItemComponent(),
        consumables.Elixir(),
        DurabilityComponent(durability=5),
    )
Пример #10
0
def make_sword_player():
    return Entity(
        NameComponent('ancestral sword'),
        DisplayComponent(char=')',
                         fg=constants.COLOR_YELLOW,
                         layer=DrawLayer.ITEM),
        ItemComponent(droppable=False),
        WeaponComponent(attack_bonus=3, hit_bonus=80, critical_bonus=5),
        ExtraDamageComponent(tier=0),
    )
Пример #11
0
def make_endboss_weapon():
    return Entity(
        NameComponent('executioner\'s sword'),
        DisplayComponent(char=')',
                         fg=constants.COLOR_YELLOW,
                         layer=DrawLayer.ITEM),
        ItemComponent(droppable=False),
        WeaponComponent(attack_bonus=15, hit_bonus=30),
        ExecuteComponent(),
    )
Пример #12
0
    def test_set_overwrites_previous_value(self):
        e = Entity()
        expected = IntComponent(13)

        e.set(IntComponent(1888))
        e.set(expected)

        actual = e.get(IntComponent)
        self.assertEqual(actual, expected)
Пример #13
0
def make_axe3():
    return Entity(
        NameComponent('steel axe'),
        DisplayComponent(char=')',
                         fg=constants.COLOR_GRAY3,
                         layer=DrawLayer.ITEM),
        ItemComponent(),
        WeaponComponent(attack_bonus=17, hit_bonus=40),
        DurabilityComponent(durability=20),
        CleaveComponent(tier=2),
    )
Пример #14
0
def make_spear2():
    return Entity(
        NameComponent('iron spear'),
        DisplayComponent(char=')',
                         fg=constants.COLOR_GRAY3,
                         layer=DrawLayer.ITEM),
        ItemComponent(),
        WeaponComponent(attack_bonus=10, hit_bonus=55),
        DurabilityComponent(durability=25),
        KnockbackComponent(tier=1),
    )
Пример #15
0
def make_sword1():
    return Entity(
        NameComponent('bronze sword'),
        DisplayComponent(char=')',
                         fg=constants.COLOR_GRAY3,
                         layer=DrawLayer.ITEM),
        ItemComponent(),
        WeaponComponent(attack_bonus=5, hit_bonus=70),
        DurabilityComponent(durability=30),
        ExtraDamageComponent(tier=0),
    )
Пример #16
0
def make_axe2():
    return Entity(
        NameComponent('iron axe'),
        DisplayComponent(char=')',
                         fg=constants.COLOR_GRAY3,
                         layer=DrawLayer.ITEM),
        ItemComponent(),
        WeaponComponent(attack_bonus=12, hit_bonus=45),
        DurabilityComponent(durability=25),
        CleaveComponent(tier=1),
    )
Пример #17
0
def make_sword3():
    return Entity(
        NameComponent('steel sword'),
        DisplayComponent(char=')',
                         fg=constants.COLOR_GRAY3,
                         layer=DrawLayer.ITEM),
        ItemComponent(),
        WeaponComponent(attack_bonus=13, hit_bonus=60),
        DurabilityComponent(durability=20),
        ExtraDamageComponent(tier=2),
    )
Пример #18
0
def make_spear3():
    return Entity(
        NameComponent('steel spear'),
        DisplayComponent(char=')',
                         fg=constants.COLOR_GRAY3,
                         layer=DrawLayer.ITEM),
        ItemComponent(),
        WeaponComponent(attack_bonus=15, hit_bonus=60),
        DurabilityComponent(durability=20),
        KnockbackComponent(tier=2),
    )
Пример #19
0
def make_axe1():
    return Entity(
        NameComponent('bronze axe'),
        DisplayComponent(char=')',
                         fg=constants.COLOR_GRAY3,
                         layer=DrawLayer.ITEM),
        ItemComponent(),
        WeaponComponent(attack_bonus=9, hit_bonus=50),
        DurabilityComponent(durability=30),
        CleaveComponent(tier=0),
    )
Пример #20
0
def make_crossbow1():
    return Entity(
        NameComponent('light crossbow'),
        DisplayComponent(char=')',
                         fg=constants.COLOR_GRAY3,
                         layer=DrawLayer.ITEM),
        ItemComponent(),
        WeaponComponent(max_range=constants.FOV_RADIUS,
                        attack_bonus=5,
                        hit_bonus=50),
        DurabilityComponent(durability=30),
        ExtraDamageComponent(tier=0),
    )
Пример #21
0
def make_crossbow3():
    return Entity(
        NameComponent('arbalest'),
        DisplayComponent(char=')',
                         fg=constants.COLOR_GRAY3,
                         layer=DrawLayer.ITEM),
        ItemComponent(),
        WeaponComponent(max_range=constants.FOV_RADIUS,
                        attack_bonus=13,
                        hit_bonus=40),
        DurabilityComponent(durability=20),
        ExtraDamageComponent(tier=2),
    )
Пример #22
0
def make_midboss_weapon():
    return Entity(
        NameComponent('book of lightning'),
        DisplayComponent(char=')',
                         fg=constants.COLOR_YELLOW,
                         layer=DrawLayer.ITEM),
        ItemComponent(droppable=False),
        WeaponComponent(max_range=constants.FOV_RADIUS,
                        attack_bonus=15,
                        hit_bonus=0,
                        smite=True),
        ThunderComponent(),
    )
Пример #23
0
def make_boss(x, y, level, case):
    max_hp = 30 + 5 * level + random.randint(0, 5)
    attack_stat = 5 + 2 * level + random.randint(0, 5)
    defend_stat = 5 + 2 * level + random.randint(0, 5)
    hit_stat = 15 + 2 * level + random.randint(0, 5)
    critical_stat = 15 + level + random.randint(0, 5)

    combat = CombatComponent(
        max_hp=max_hp,
        attack_stat=attack_stat,
        defend_stat=defend_stat,
        hit_stat=hit_stat,
        critical_stat=critical_stat,
    )

    if case == 1:
        display = DisplayComponent('W')
        name = NameComponent('sword master')
        weapon = make_exotic_sword(level)
    elif case == 2:
        display = DisplayComponent('A')
        name = NameComponent('axe master')
        weapon = make_exotic_axe(level)
    elif case == 3:
        display = DisplayComponent('P')
        name = NameComponent('spear master')
        weapon = make_exotic_spear(level)
    elif case == 4:
        display = DisplayComponent('C')
        name = NameComponent('crossbow master')
        weapon = make_exotic_bow(level)
    else:
        assert False  # Unreachable branch

    inventory = InventoryComponent(capacity=2)
    inventory.items[0] = weapon

    if random.random() < 0.4:
        inventory.items[1] = random_consumable()

    return Entity(
        display,
        name,
        PositionComponent(x, y),
        AIComponent(),
        RandomNumberComponent(),
        BlockingComponent(),
        BossComponent(),
        combat,
        inventory,
    )
Пример #24
0
def make_player(x, y):
    inventory = InventoryComponent(capacity=10)
    inventory.items = {
        0: make_sword_player(),
        1: elixir(),
        2: smoke_bomb(),
    }
    return Entity(
        DisplayComponent(char='@'),
        NameComponent(name='you'),
        CombatComponent(20, 8, 8, 10, 5),
        PositionComponent(x, y),
        RandomNumberComponent(),
        BlockingComponent(),
        inventory,
    )
Пример #25
0
def make_endboss(x, y):
    inventory = InventoryComponent(capacity=1)
    inventory.items = {
        0: make_endboss_weapon(),
    }
    return Entity(
        DisplayComponent(char='G'),
        NameComponent(name='general'),
        CombatComponent(75, 30, 30, 45, 30),
        PositionComponent(x, y),
        BossComponent(),
        AIComponent(),
        RandomNumberComponent(),
        BlockingComponent(),
        inventory,
    )
Пример #26
0
def make_midboss(x, y):
    inventory = InventoryComponent(capacity=3)
    inventory.items = {
        0: make_midboss_weapon(),
        1: tonic(),
        2: tonic(),
    }
    return Entity(
        DisplayComponent(char='M'),
        NameComponent(name='magician'),
        CombatComponent(50, 15, 10, 35, 30),
        PositionComponent(x, y),
        BossComponent(),
        AIComponent(),
        RandomNumberComponent(),
        BlockingComponent(),
        inventory,
    )
Пример #27
0
def tonic():
    pool = [
        ('health tonic', consumables.HealthTonic, 1),
        ('attack tonic', consumables.AttackTonic, 1),
        ('defend tonic', consumables.DefendTonic, 1),
        ('hit tonic', consumables.HitTonic, 1),
        ('critical tonic', consumables.CriticalTonic, 1),
    ]

    name, constructor, durability = random.choice(pool)

    return Entity(
        NameComponent(name),
        DisplayComponent(char=chr(173),
                         fg=constants.COLOR_YELLOW,
                         layer=DrawLayer.ITEM),
        ItemComponent(),
        constructor(),
        DurabilityComponent(durability=durability),
    )
Пример #28
0
 def test_to_json(self):
     e = Entity()
     json = e.to_json()
     self.assertIsInstance(json, str)
Пример #29
0
 def test_id(self):
     e = Entity()
     self.assertIsInstance(e.id, str)
     self.assertGreater(len(e.id), 0)
Пример #30
0
 def test_from_json(self):
     json = '{"id": "e4cee65e81b111e8a9bf4ccc6a6cfbd8"}'
     e = Entity.from_json(json)
     self.assertEqual(e.id, 'e4cee65e81b111e8a9bf4ccc6a6cfbd8')