Ejemplo n.º 1
0
def pick_monster(game_map, room_id, room_x, room_y, monster_template):
    name, char, colour, hits, weapon = monster_template

    weapon_name, weapon_char, weapon_colour, weapon_power, weapon_uses = weapon

    weapon_stats = Weapon(weapon_power, weapon_uses)
    monster_weapon = Item(game_map,
                          room_id,
                          room_x,
                          room_y,
                          weapon_name,
                          weapon_char,
                          weapon_colour,
                          weapon=weapon_stats)

    fighter_component = Fighter(hits, left_hand=monster_weapon)
    ai_component = BasicMonster()
    monster = Actor(game_map,
                    room_id,
                    room_x,
                    room_y,
                    name,
                    char,
                    colour,
                    fighter=fighter_component,
                    ai=ai_component)

    return monster
Ejemplo n.º 2
0
	def addItemDB(self, data):
		logging.info("addItemDB")
		with DatabaseSession(self.engine) as session:
			instance = Item( name = data['name'],
							 brand = data['brand'],
							 category = data['category'],
							 productCode = data['productcode']
							 )
			

			changelog = Changelog( mode = "ADD",
								   user = data['user'],
								   item_category = True,
								   item_data = json.dumps({"productcode" : data['productcode']})
								   )
			session.add(changelog)
			session.flush()
			session.commit()
			logging.debug("Wrote activity log for addItem")
							
			try:			 
				session.add(instance)
				session.flush()
				session.commit()
				return True
			except exc.IntegrityError as e:
				logging.error('Integrity Error Exception when addITEM : \n %s',e )
				session.rollback()
				return False

		return False
Ejemplo n.º 3
0
    def process_world_map(self, world_map: Dict[Tuple, List[WorldObject]],
                          monsters: Monsters, doors: Doors,
                          inventory: PlayerInventory) -> None:
        for coord, room in world_map.items():
            room_doors = list(
                filter(lambda elem: isinstance(elem, Door), room)
            )
            room_monsters = list(
                filter(lambda elem: isinstance(elem, Monster), room)
            )

            for monster in room_monsters:
                monsters._monsters[monster.monster_name] = monster

            for door in room_doors:
                item_to_open = Item(door._door_name+'_opener')
                monster_w_item: Monster = random.choice(room_monsters)
                while monster_w_item in monsters.monster_action_mapping.keys():
                    monster_w_item = random.choice(room_monsters)
                open_door_action = OpenDoorAction(door._door_name, doors)
                spawn_item_action = SpawnItemInInventoryAction(
                    item_to_open, inventory
                )
                doors._doors_lookup[door._door_name] = door
                inventory.item_action_mapping[item_to_open._item_name] =\
                    open_door_action
                monsters.monster_action_mapping[monster_w_item.monster_name] =\
                    spawn_item_action
Ejemplo n.º 4
0
def task_execute():
    w = World()
    for current in w.populators:
        if not w.denizens.has_key(current.instance):
            denizen = Denizen(current.denizen)
            current.instance = denizen.id
            w.denizens[denizen.id] = denizen
            libsigma.enter_room(denizen, current.target)

    for current in w.placements:
        if not current.instance in [i.id for i in current.target.contents]:
            item = Item(current.item)
            item.quantity = current.quantity
            current.instance = item.id
            w.items[item.id] = item
            current.target.contents.append(item)
Ejemplo n.º 5
0
 def __init__(self, data, sprites):
     # Localização inicial do jogador
     self.spawn = data["player"]
     # Tiles do mapa
     self.map = data["map"]
     self.width, self.height = len(data["map"][0]), len(data["map"])
     self.tex = 64
     # Cores
     self.color = tuple(data["colors"]["floor"]), data["colors"]["ceil"]
     self.dark = data["colors"]["dark"]
     # Música de fundo
     self.music = data["music"]
     # Inimigos e itens
     self.entities = [
         Enemy(pos, sprites[enemy], enemy == "boss")
         for enemy, pos in data["enemies"]
     ] + [
         Item(pos, sprites["items"].sprites[item], item)
         for item, pos in data["items"]
     ]
Ejemplo n.º 6
0
def populate(db):
    items = [
        Item(name="Thunderfury, Blessed Blade of the Windseeker",
             quality=ItemQuality.LEGENDARY,
             icon="inv_sword_39",
             wowhead_id=19019),
        Item(name="Orb of Deception",
             quality=ItemQuality.RARE,
             icon="inv_misc_orb_02",
             wowhead_id=1973),
        Item(name="The Unstoppable Force",
             quality=ItemQuality.EPIC,
             icon="inv_hammer_13",
             wowhead_id=19323),
        Item(name="Noggenfogger Elixir",
             quality=ItemQuality.COMMON,
             icon="inv_potion_83",
             wowhead_id=8529),
        Item(name="Righteous Orb",
             quality=ItemQuality.UNCOMMON,
             icon="inv_misc_gem_pearl_03",
             wowhead_id=12811),
        Item(name="Nat Pagle's Guide to Extreme Anglin'",
             quality=ItemQuality.JUNK,
             icon="inv_misc_book_02",
             wowhead_id=18229),
        Item(name="Savory Deviate Delight",
             quality=ItemQuality.COMMON,
             icon="inv_misc_monsterhead_04",
             wowhead_id=6657),
        Item(name="Carrot on a Stick",
             quality=ItemQuality.UNCOMMON,
             icon="inv_misc_food_54",
             wowhead_id=11122),
        Item(name="Skullflame Shield",
             quality=ItemQuality.EPIC,
             icon="inv_shield_01",
             wowhead_id=1168),
        Item(name="Sulfuras, Hand of Ragnaros",
             quality=ItemQuality.LEGENDARY,
             icon="inv_hammer_unique_sulfuras",
             wowhead_id=17182),
        Item(name="Rusty Warhammer",
             quality=ItemQuality.JUNK,
             icon="inv_hammer_16",
             wowhead_id=1514)
    ]

    for i in items:
        if Item.query.filter_by(name=i.name).first() is None:
            db.session.add(i)
    db.session.commit()
Ejemplo n.º 7
0
    def place_entities_test(self,
                            entities,
                            number_of_enemies,
                            number_of_items,
                            player=None):
        random.seed()

        if player == None:
            player = Humanoid(int(self.width / 2),
                              int(self.height / 2),
                              '@',
                              libtcod.white,
                              'Player',
                              blocks=True,
                              combat_aspect=Combatant(200, 20, 20, 15),
                              ai=Player(),
                              speed=20,
                              inventory=Inventory(20))

        entities.append(player)

        for i in range(number_of_enemies):
            x = random.randint(1, self.width - 1)
            y = random.randint(1, self.height - 1)

            if not any([
                    entity
                    for entity in entities if entity.x == x and entity.y == y
            ]):
                monster = Humanoid(x,
                                   y,
                                   'o',
                                   libtcod.desaturated_green,
                                   'Orc',
                                   blocks=True,
                                   combat_aspect=Combatant(100, 10, 10, 5),
                                   ai=BasicMonster())

            entities.append(monster)

        for i in range(number_of_items):
            x = random.randint(1, self.width - 1)
            y = random.randint(1, self.height - 1)

            if not any([
                    entity
                    for entity in entities if entity.x == x and entity.y == y
            ]):
                if random.randint(1, 100) < 0:
                    item = Item(x,
                                y,
                                '!',
                                libtcod.violet,
                                'Healing Potion',
                                item_aspect=Item_aspect(use_function=heal,
                                                        amount=10))
                elif random.randint(1, 100) < 70:
                    item = Item(
                        x,
                        y,
                        '=',
                        libtcod.red,
                        'Fireball Scroll',
                        item_aspect=Item_aspect(
                            use_function=cast_fireball,
                            targeting=True,
                            targeting_message=
                            'Left-click a target tile for the fireball, or right-click to cancel.',
                            damage=50,
                            radius=3))
                else:
                    pass
                try:
                    entities.append(item)
                except:
                    pass

            else:
                i -= 1
Ejemplo n.º 8
0
def post_item():
    if not session.get("logged_in"):
        return login()

    if request.method == "GET":
        fields = []
        fields.append(
            Field(name="name",
                  title="Name",
                  the_type='text',
                  identifier='name',
                  placeholder="Item Name"))
        fields.append(
            Field(name='description',
                  title="Description",
                  the_type="textarea",
                  identifier='description',
                  placeholder='Descriptive Description',
                  tag="textarea"))
        categories = Category.query()

        options = []
        for category in categories:
            option = {}
            option["name"] = category.name
            option["value"] = category.categoryID
            options.append(option)

        fields.append(
            Field(name='category',
                  title="Item Category",
                  the_type="select",
                  identifier="category",
                  placeholder="Select Item Category",
                  tag="select",
                  options=options))

        fields.append(
            Field(name='price',
                  title="Price",
                  the_type="number",
                  identifier="price",
                  placeholder="10.95",
                  step=True))

        fields.append(
            Field(name='file',
                  title="Upload Photo",
                  the_type="file",
                  placeholder="Upload Photo",
                  identifier="file",
                  tag="file"))

        fields.append(
            Field(name='biddable',
                  title="Allow offer amounts other than suggested price.",
                  the_type="number",
                  identifier="biddable",
                  tag="checkbox"))
        title = "Post Item"
        form = Form(fields=fields, title=title, submit="Post")

        notifications = Notification.query(
            Notification.user == session["user_id"]).order(-Notification.time)
        return render_template("post_item.html",
                               item_form=form,
                               notifications=notifications)

    if request.method == "POST":
        name = request.form.get("name")
        description = request.form.get("description")
        category = request.form.get("category")
        price = float(request.form.get("price"))
        seller_id = session["user_id"]
        biddable = False
        if request.form.get("biddable"):
            biddable = True

        # print "nooo"
        # return json.dumps(request.files)

        file = request.files.get("file", None)
        # print "whaattt??"
        file_data = None
        content_type = None
        photo = None
        if file:
            file_data = file.read()
            photo = images.resize(file_data, width=500, height=500)
            content_type = file.content_type

        new_item = Item(name=name,
                        description=description,
                        category=category,
                        price=price,
                        seller_id=seller_id,
                        seller_name=session["first_name"] + " " +
                        session["last_name"],
                        biddable=biddable,
                        sold=False,
                        best_offer=0.0,
                        photo=photo,
                        photo_mimetype=content_type)
        new_item.put()

        return my_items()
Ejemplo n.º 9
0
def main():
    tdl.set_font('terminal16x16.png', greyscale=True,
                 altLayout=False)  # Load the font from a png.
    tdl.set_fps(100)

    map_width = 20
    map_height = 20

    room_width = 30
    room_height = 30

    screen_width = room_width + 22
    screen_height = room_height + 22

    root_console = tdl.init(screen_width, screen_height, title='7DRL 2019')
    top_panel_console = tdl.Console(screen_width, 10)
    view_port_console = tdl.Console(room_width, room_height)
    bottom_panel_console = tdl.Console(screen_width, 10)
    message_log = MessageLog(0, 0, screen_width, 9)

    entities = []

    game_map = GameMap(map_width, map_height)

    sword_stats = Weapon(2, 10)
    player_weapon = Item(game_map,
                         "0x0",
                         0,
                         0,
                         "Sword",
                         "|", (255, 255, 255),
                         weapon=sword_stats)
    player_stats = Fighter(hits=10, left_hand=player_weapon)
    player = Actor(game_map,
                   "2x2",
                   15,
                   10,
                   "Player",
                   "@", (255, 255, 255),
                   fighter=player_stats)
    entities.append(player)

    generate_map(game_map, entities, player)

    all_consoles = [
        root_console, view_port_console, bottom_panel_console,
        top_panel_console
    ]

    fov_algorithm = "BASIC"
    fov_light_walls = True
    fov_radius = 50
    fov_recompute = True

    game_state = GameStates.PLAYER_TURN

    while not tdl.event.is_window_closed():
        if fov_recompute:  # Compute the field of view to show changes.
            game_map.rooms[player.map_x][player.map_y]\
                .compute_fov(player.room_x, player.room_y,
                             fov=fov_algorithm, radius=fov_radius, light_walls=fov_light_walls, sphere=True)

            render_all(all_consoles, game_map, entities, player, fov_recompute,
                       message_log)
            tdl.flush()
            clear_all(view_port_console, entities)
            fov_recompute = False

        for event in tdl.event.get():
            if event.type == 'KEYUP':
                user_input = event
                break

        else:
            user_input = None

        if not user_input:
            continue

        action = handle_keys(user_input)

        move = action.get('move')
        exit_game = action.get('exit_game')
        select_hand = action.get('select_hand')
        drop_item = action.get('drop_item')
        pickup_item = action.get('pickup_item')
        shuffle_rooms = action.get('shuffle_rooms')

        player_turn_results = []

        if shuffle_rooms:
            message = game_map.shuffle_rooms(player, entities)
            message_log.add_message(message)
            fov_recompute = True

        # TODO at the moment these functions are doing all the leg work and player_turn_results isn't used. Rectify.

        if select_hand and game_state == GameStates.PLAYER_TURN:
            player.fighter.selected_hand = select_hand
            fov_recompute = True

        if drop_item and game_state == GameStates.PLAYER_TURN:
            message = player.fighter.drop_item(game_map, entities)
            message_log.add_message(message)
            game_state = GameStates.ENEMY_TURN
            fov_recompute = True

        if pickup_item and game_state == GameStates.PLAYER_TURN:
            message = player.fighter.pickup_item(entities)
            message_log.add_message(message)
            game_state = GameStates.ENEMY_TURN
            fov_recompute = True

        if move and game_state == GameStates.PLAYER_TURN:
            dx, dy = move
            destination_room_x = player.room_x + dx
            destination_room_y = player.room_y + dy

            if destination_room_x < 0:
                dx = 0

                if player.map_x - 1 < 0:
                    player.map_x = map_width - 1
                else:
                    player.map_x -= 1

                player.room_x = room_width - 1

            if destination_room_x == room_width:
                destination_room_x -= 1
                dx = 0

                if player.map_x + 1 > map_width - 1:
                    player.map_x = 0
                else:
                    player.map_x += 1

                player.room_x = 0

            if destination_room_y < 0:
                dy = 0

                if player.map_y - 1 < 0:
                    player.map_y = map_height - 1
                else:
                    player.map_y -= 1

                player.room_y = room_height - 1

            if destination_room_y == room_height:
                destination_room_y -= 1
                dy = 0

                if player.map_y + 1 > map_height - 1:
                    player.map_y = 0
                else:
                    player.map_y += 1

                player.room_y = 0

            if game_map.rooms[player.map_x][player.map_y].walkable[
                    destination_room_x, destination_room_y]:
                target = get_blocking_entities_at_location(
                    entities, player.map_x, player.map_y, destination_room_x,
                    destination_room_y)

                if target:  # Combat here
                    attack_results = player.fighter.attack(target)
                    player_turn_results.extend(
                        attack_results
                    )  # Add the result of the last turn to the list
                    fov_recompute = True

                else:
                    player.move(dx, dy)  # Or just move
                    player.set_current_room(game_map)

                    # TODO: Bug with the new room layouts - some cause change of room to break.
                    print("MapPos: ",
                          player.map_x,
                          ",",
                          player.map_y,
                          end=" / ")
                    print("RoomPos: ", player.room_x, ",", player.room_y)
                    fov_recompute = True

                game_state = GameStates.ENEMY_TURN  # Switch over the enemy's turn.

        if exit_game:
            return True

        for player_turn_result in player_turn_results:
            message = player_turn_result.get("message")  # Pull any messages
            dead_entity = player_turn_result.get(
                "dead")  # Or anything that died

            if message:
                message_log.add_message(
                    message
                )  # Add the message (if any) to the message log to print on screen.

            if dead_entity:  # If anything died...
                if dead_entity == player:
                    message, game_state = kill_player(dead_entity)  # Game over
                else:
                    message = kill_monster(
                        dead_entity
                    )  # Print a death message for monster, add exp

                message_log.add_message(message)  # Print messages to screen.

        player_turn_results.clear()  # Clear ready for next turn.

        if game_state == GameStates.ENEMY_TURN:
            for entity in entities:
                if entity.map_x == player.map_x and entity.map_y == player.map_y:
                    if entity.ai:  # If the entity has some intelligence (monsters, npc)
                        enemy_turn_results = entity.ai.take_turn(
                            player, game_map, entities)

                        for enemy_turn_result in enemy_turn_results:  # Same deal as the player turns
                            message = enemy_turn_result.get("message")
                            dead_entity = enemy_turn_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.PLAYER_DEAD:
                                break

                        enemy_turn_results.clear()

                    if game_state == GameStates.PLAYER_DEAD:
                        break

            else:
                game_state = GameStates.PLAYER_TURN
Ejemplo n.º 10
0
                 if getSimNao('Os dados estão corretos?'):
                     session.commit()
                     break
                 else:
                     session.rollback()
         if c == 2:
             while True:
                 cls()
                 print(AZUL + 'NOVO ITEM\n' + RESET)
                 nome = input('Nome: ')
                 descricao = input('Descrição: ')
                 equipavel = getSimNao('Equipável')
                 ataque = getValor('Ataque')
                 defesa = getValor('Defesa')
                 valor = getValor('Valor')
                 item = Item(nome, descricao, equipavel, ataque, defesa,
                             valor)
                 session.add(item)
                 cls()
                 print(item)
                 if getSimNao('Os dados estão corretos?'):
                     session.commit()
                     break
                 else:
                     session.rollback()
         if c == 0:
             break
 elif c == 2:
     while True:
         cls()
         print(AZUL + 'VISUALIZAR ENTIDADES' + RESET)
         print('1. Personagens')