Ejemplo n.º 1
0
 def get(self, id):
     entity = Entity()
     entity.accessed = entity.now()
     del entity.created
     del entity.modified
     entity.id = id
     self.db.commit()
     return [i for i in self.db.select_one(self.table, id)][1:]
Ejemplo n.º 2
0
    def place_entities(self, room, entities, max_monsters_per_room):
        # Get a random number of monsters
        number_of_monsters = randint(0, max_monsters_per_room)

        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)

            if not any([
                    entity
                    for entity in entities if entity.x == x and entity.y == y
            ]):
                if randint(0, 100) < 80:
                    f = Fighter(hp=10, defense=0, power=3)
                    a = BasicMonster()
                    monster = Entity(x,
                                     y,
                                     'o',
                                     curses.color_pair(11),
                                     'Orc',
                                     blocks=True,
                                     render_order=RenderOrder.ACTOR,
                                     fighter=f,
                                     ai=a)
                else:
                    f = Fighter(hp=16, defense=1, power=4)
                    a = BasicMonster()
                    monster = Entity(x,
                                     y,
                                     'T',
                                     curses.color_pair(3),
                                     'Troll',
                                     blocks=True,
                                     render_order=RenderOrder.ACTOR,
                                     fighter=f,
                                     ai=a)

                entities.append(monster)
Ejemplo n.º 3
0
    def _on_new_connection(self, socket: socket) -> None:
        connection, address = socket.accept()  # Should be ready to read
        print(f'Connected by: {address}')

        connection.setblocking(False)

        mask = selectors.EVENT_READ | selectors.EVENT_WRITE

        entity = Entity.eid()

        self._multiplexer.register(connection, mask, entity)

        Event.trigger(Event(Event.RECEPTION, Servant.instance(),
                            entity=entity))
Ejemplo n.º 4
0
    def _load_json(self, f: PosixPath) -> dict:
        data: dict = {}

        with f.open(encoding='utf-8') as fin:
            print(f'--- processing {f.stem} ---')
            data = json.load(fin)

        if not 'entity' in data:
            data['entity'] = Entity.eid()

            with f.open(mode='w', encoding='utf-8') as fout:
                json.dump(data, fout, ensure_ascii=False, indent=2)

        return data
Ejemplo n.º 5
0
    def construct_entities(self, data, feed):
        entities = []

        for entity in data['entries'][0:1]:
            # add entity to entity manifest
            new_entity = Entity(title=entity.title,
                                date=entity.published,
                                description=entity.summary,
                                url=entity.link)
            entities.append(new_entity)
            # search entity title for symbols
            feed.symbol_type_class.set_relationship(
                new_entity, 'This is an article about BTC')

        return entities
Ejemplo n.º 6
0
def to_spec():
    path = Path(f'.muted/data/spec')

    assert (path.is_dir())

    for f in path.iterdir():
        print(f'------{f}-------')
        if f.is_file():
            with f.open(encoding='utf-8') as fin:
                spec = json.load(fin)

                try:
                    entity = spec['entity']
                except KeyError:
                    spec['entity'] = Entity.eid()

                print(json.dumps(spec, indent=2))
Ejemplo n.º 7
0
def to_spec():
    path = Path(f'.muted/data/spec')

    assert (path.is_dir())

    for f in path.iterdir():
        print(f'------{f}-------')
        if f.is_file():
            spec = ''

            with f.open(encoding='utf-8') as fin:
                spec = json.load(fin)

                for item in spec:
                    try:
                        entity = item['entity']
                    except KeyError:
                        item['entity'] = Entity.eid()

                print(json.dumps(spec, ensure_ascii=False, indent=2))

            with f.open(mode='w', encoding='utf-8') as fout:
                json.dump(spec, fout, ensure_ascii=False, indent=2)
Ejemplo n.º 8
0
 def __init__(self, image):
     Entity.__init__(self, Coordinate(13, 14), image, True)
     self.movement = Movement.UP
Ejemplo n.º 9
0
def Rogue(screen):
    max_y, max_x = screen.getmaxyx()

    # These actually define the height of the canvas (game map) not the host terminal
    screen_width = 80
    screen_height = 30
    cy = int((max_y - screen_height) / 2)
    cx = int((max_x - screen_width) / 2)
    #height, width = canvas.getmaxyx()
    map_height = 23
    map_width = 78

    # Values to define status bars and message log
    bar_width = 30
    panel_height = 6
    panel_y = cy + screen_height - panel_height + 1

    # message_x = bar_width + 2
    message_x = 1
    message_width = screen_width - 2
    message_height = cy


    canvas = curses.newwin(screen_height, screen_width, cy, cx)
    renderer = CursesRenderer(canvas)

    #status_win = curses.newwin(80, 3, 24, 0)
    panel = curses.newwin(panel_height, screen_width, panel_y, cx)
    message_panel = curses.newwin(cy, screen_width, 0, cx)

    colors = {
        'dark_wall': curses.color_pair(236)
    }

    fov = FOV(5)
    fighter = Fighter(hp=30, defense=2, power=5)
    player = Entity(5, 5, '@', curses.color_pair(6),
                    'Player', blocks=True, render_order=RenderOrder.ACTOR, fov=fov, fighter=fighter)
    entities = [player]

    game_map = GameMap(map_width, map_height-1)
    game_map.make_map(15, 8, 10, map_width, map_height, player, entities, 3)

    calculate_fov = True

    message_log = MessageLog(message_x, message_width, message_height)
    game_state = GameStates.PLAYER_TURN
    while True:
        key = canvas.getch()
        curses.flushinp()

        renderer.render_all(canvas, panel, message_panel,
                            bar_width, message_log,
                            game_map, fov, calculate_fov,
                            entities, player, colors)

        panel.refresh()
        message_panel.refresh()

        canvas.border()
        canvas.refresh()

        action = handle_keys(key)
        move = action.get('move')
        exit = action.get('exit')

        player_turn_results = []

        if exit:
            return True

        if move and game_state == GameStates.PLAYER_TURN:
            dx, dy = move
            destination_x = player.x + dx
            destination_y = player.y + dy

            if not game_map.is_blocked(player.x + dx, player.y + dy):
                if not game_map.is_blocked(destination_x, destination_y):
                    target = get_blocking_entities_at_location(entities, destination_x, destination_y)

                    if target:
                        attack_results = player.fighter.attack(target)
                        player_turn_results.extend(attack_results)
                    else:
                        player.move(dx, dy)
                        calculate_fov = True

                    game_state = GameStates.ENEMY_TURN

        for result in player_turn_results:
            message = result.get('message')
            dead_entity = result.get('dead')

            if message:
                message_log.add_message(message)

            if dead_entity:
                if dead_entity == player:
                    message, game_state = kill_player(dead_entity)
                else:
                    message = kill_monster(dead_entity)

                message_log.add_message(message)

        if game_state == GameStates.ENEMY_TURN:
            for entity in entities:
                if entity.ai:
                    enemy_turn_results = entity.ai.take_turn(player, fov, game_map, entities)

                    for result in enemy_turn_results:
                        message = result.get('message')
                        dead_entity = result.get('dead')

                        if message:
                            message_log.add_message(message)

                        if dead_entity:
                            if dead_entity == player:
                                message, game_state = kill_player(dead_entity)
                            else:
                                message = kill_monster(dead_entity)

                            if game_state == GameStates.PLAYER_DEAD:
                                break

                    if game_state == GameStates.PLAYER_DEAD:
                        break
            else:
                game_state = GameStates.PLAYER_TURN
Ejemplo n.º 10
0
 def __init__(self, screen, rect, boundry, speed, health=100, name=None, save_entity=False):
     # Speed Metric: Time it takes to move across entire screen.
     Entity.__init__(self, screen, rect, health=health, name=name, save_entity=save_entity)
     PlayerInput.__init__(self, boundry, speed)
Ejemplo n.º 11
0
 def draw(self):
     print(self.weapon)
     Entity.draw(self)
Ejemplo n.º 12
0
 def update(self, dt):
     Entity.update(self)
     x, y = PlayerInput.update_position(self, self.rect, self.settings, dt)
     self.rect[0] = x
     self.rect[1] = y
Ejemplo n.º 13
0
#stuff i didnt make
import tcod as libtcod
import tcod.event as libtcod_event

#cfgs
import console.console_cfg

#classes
from entity.entity import Entity

player = Entity(int(console.console_cfg.screen_width / 2), int(console.console_cfg.screen_width / 2), '@', libtcod.white)

entities = [player]
Ejemplo n.º 14
0
 def __init__(self):
     Entity.__init__(self, Coordinate(13, 23),
                     pg.image.load("assets/images/pacman.png"), False)
Ejemplo n.º 15
0
    def parse_data(self, packet):
        instances = packet[3:].split('|')
        for instance in instances:
            if len(instance) < 1:
                continue
            if instance[0] == '+':
                infos = instance[1:].split(';')
                if len(infos) < 6:
                    continue

                cell = int(infos[0])
                template = infos[4]
                try:
                    type_ = int(infos[5]) if ',' not in infos[5] else int(
                        infos[5].split(',')[0])
                except:
                    continue

                entity_id = int(infos[3])

                # SWITCH
                if type_ == -1:  # creature
                    pass
                elif type_ == -2:  # mob
                    # if not self.character_state.isFighting:
                    #    return
                    #monster_team = infos[15] if len(infos) <= 18 else infos[22]
                    levels = list(map(int, infos[7].split(',')))
                    if len(infos) == 12:
                        self.entity_gestion.add_entity(
                            Entity('Mob',
                                   cell=cell,
                                   id=entity_id,
                                   template=template,
                                   pa=infos[12],
                                   vie=infos[13],
                                   pm=infos[14]))
                    else:
                        self.entity_gestion.add_entity(
                            Entity('Mob',
                                   cell=cell,
                                   id=entity_id,
                                   template=template,
                                   pa=None,
                                   vie=None,
                                   pm=None))
                    #self.entities.append(Entity('Mob', cell=cell, id=entity_id, template=template, pa=infos[12], vie=infos[13], pm=infos[14]))
                elif type_ == -3:  # group of mob
                    templates = list(map(int, template.split(',')))
                    levels = list(map(int, infos[7].split(',')))
                    entity_id = int(infos[3])

                    self.entity_gestion.add_entity(
                        Entity('GroupMob',
                               cell=cell,
                               id=entity_id,
                               templates=templates,
                               levels=levels))
                elif type_ == -4:  # NPC
                    pass  # map.entities.add(id, Npc(id, int(nombre_template), cell))
                elif type_ == -5:  # Merchants
                    pass  # map.entities.add(id, Mercantes(id, cell))
                elif type_ == -6:  # resources
                    pass
                else:  # players
                    if entity_id != int(self.character.id_):
                        self.entity_gestion.add_entity(
                            Entity('Player',
                                   cell=cell,
                                   id=entity_id,
                                   name=infos[4],
                                   pa=None,
                                   vie=None,
                                   pm=None))
                    else:
                        self.entity_gestion.add_entity(
                            Entity('Player',
                                   cell=cell,
                                   id=entity_id,
                                   name=infos[4],
                                   isMainCharacter=True,
                                   pa=None,
                                   vie=None,
                                   pm=None))

            elif instance[0] == '-':  # player leave
                entity_id = int(instance[1:])

                self.entity_gestion.update_entity(entity_id, None)