Beispiel #1
0
def test_can_not_drop_item_that_actor_does_not_have_exception(world, room, item):
    world.add_system(PerceiveRoom(), 0)
    world.add_system(TakeOrDrop(throw_exc=True), 1)
    actor = world.create_entity(
        RoomPresence(room=room._uid),
        Inventory(),
        DropAction(item=item._uid),
    )
    with pytest.raises(ItemNotInInventory):
        world.update()
Beispiel #2
0
def can_not_drop_untakeable_item_exception(world, room):
    world.add_system(PerceiveRoom(), 0)
    world.add_system(TakeOrDrop(throw_exc=True), 1)

    item =  world.create_entity()
    actor = world.create_entity(
        RoomPresence(room=room._uid),
        Inventory(contents=[item._uid]),
        DropAction(item=item._uid),
    )
    with pytest.raises(NotTakeable):
        world.update()
Beispiel #3
0
def test_can_not_take_from_the_void_exception(world):
    world.add_system(PerceiveRoom(), 0)
    world.add_system(TakeOrDrop(throw_exc=True), 1)

    item = world.create_entity(
        Takeable(),
    )
    actor = world.create_entity(
        Inventory(contents=[item._uid]),
        DropAction(item=item._uid),
    )
    with pytest.raises(ActorNotInRoom):
        world.update()
Beispiel #4
0
    def drop_command(self, entity, object_id):
        # If I have an inventory...
        if not entity.has_component(Inventory):
            print("{} has no inventory.".format(name))
            return False

        inventory = entity.get_component(Inventory).contents
        item = self.world.get_entity(inventory[object_id])

        if can_drop(item, entity):
            entity.add_component(DropAction(item=item._uid))
            return True

        return False
Beispiel #5
0
def test_can_not_drop_item_that_actor_does_not_have(world, room, item):
    world.add_system(PerceiveRoom(), 0)
    world.add_system(TakeOrDrop(), 1)
    world.add_system(PerceiveRoom(), 2, add_duplicates=True)
    actor = world.create_entity(
        RoomPresence(room=room._uid),
        Inventory(),
        DropAction(item=item._uid),
    )
    world.update()

    assert actor.get_component(Inventory).contents == []
    assert not actor.has_component(DropAction)
    assert item.has_component(RoomPresence)
Beispiel #6
0
def can_not_drop_untakeable_item(world, room):
    world.add_system(PerceiveRoom(), 0)
    world.add_system(TakeOrDrop(), 1)
    world.add_system(PerceiveRoom(), 2, add_duplicates=True)

    item =  world.create_entity()
    actor = world.create_entity(
        RoomPresence(room=room._uid),
        Inventory(contents=[item._uid]),
        DropAction(item=item._uid),
    )
    world.update()

    assert actor.get_component(Inventory).contents == [item._uid]
    assert not actor.has_component(DropAction)
    assert not item.has_component(RoomPresence)