Esempio n. 1
0
def basic_game(tmpdir):
    g = Game()
    g.gamedir = tmpdir.mkdir("test_game")
    with open('{}/gm_passwords.json'.format(g.gamedir), 'w') as outfile:
        json.dump({'passwords': ['gmpass1', 'gmpass2']}, outfile)
    temp1 = ItemTemplate('backpack', 'Backpack', "It's a backpack", True)
    temp2 = ItemTemplate('key', 'Blue Key', 'This is a key', False)
    g.player_manager.load_gm_passwords(g.gamedir)
    room1 = Room('room1', 'Room #1', 'First room.')
    room2 = Room('room2', 'Room #2', 'Second room.')
    room3 = Room('room3', 'Room #3', 'Third room.')
    room1.adjacent_rooms.add(room2)
    room2.adjacent_rooms.add(room1)
    room2.adjacent_rooms.add(room3)
    room3.adjacent_rooms.add(room2)
    room3.adjacent_rooms.add(room1)
    char1 = Character('char1', 'First Character', '1234', room1)
    char2 = Character('char2', 'Second Character', 'qwerty', room3)
    g.room_manager.rooms['room1'] = room1
    g.room_manager.rooms['room2'] = room2
    g.room_manager.rooms['room3'] = room3
    g.char_manager.characters['char1'] = char1
    g.char_manager.characters['char2'] = char2
    g.item_manager.item_templates[temp1.short_name] = temp1
    g.item_manager.item_templates[temp2.short_name] = temp2
    backpack1 = g.item_manager.new_item(temp1.short_name)
    key1 = g.item_manager.new_item(temp2.short_name)
    backpack2 = g.item_manager.new_item(temp1.short_name)
    key2 = g.item_manager.new_item(temp2.short_name)
    backpack1.add_item(key1)
    char1.items.add_item(backpack1)
    room1.items.add_item(backpack2)
    room1.items.add_item(key2)
    return g
Esempio n. 2
0
def test_new_character(game_factory, game_faker):
    char = Character('face1')
    assert char.face == 'face1'
    assert char.char_id is not None

    char2 = Character('face2')
    assert char2.face == 'face2'
    assert char2.char_id is not None
    assert char2.char_id != char.char_id
Esempio n. 3
0
def add_character():

    new_char = Character()
    status = new_char.character_setup(request.form)

    if status != 0:
        return "FAIL"

    game_state.add_character(new_char)
    save_game()

    if game_state.number_of_characters == len(game_state.characters):
        return redirect(url_for("game"))
    else:
        return redirect(url_for('character_creation'))
Esempio n. 4
0
def test_grid_characters(game_factory, faker):
    grid = Grid(5, 5)
    assert len(grid.characters) == 0

    char = Character(faker.pystr())
    grid.add_character(char)

    assert len(grid.characters) == 1
    assert grid.characters[0] == char

    char2 = Character(faker.pystr())

    grid.add_character(char2)
    assert len(grid.characters) == 2
    assert grid.characters[1] == char2
Esempio n. 5
0
def character_creation():

    if request.method == "GET":

        if game_state.number_of_characters == len( game_state.characters ):
            return redirect(url_for("game"))
        elif game_state.number_of_characters <= 0:
            return redirect(url_for("home"))

        new_char = Character()
        main_skills = [ (key.upper(), val) for key, val in  new_char.main_skills.items() ]
        sub_skills = [[ (mkey.upper(), key.upper(), val) for key, val in  mval.items() ] for mkey, mval in new_char.sub_skills.items()]
        spare_skill_points = [ (key.upper(), val) for key, val in new_char.spare_skill_points.items()]

        return render_template(
            "character_page.html",
            main_skills=main_skills,
            sub_skills=sub_skills,
            spare_skill_points=spare_skill_points,
            button_state=int(game_state.number_of_characters - 1 != len(game_state.characters)),
            character_name=None,
            character_class=None,
            character_gender=None,
            character_avatar=None,
        )
Esempio n. 6
0
def test_item_transfer():
    bp_t = ItemTemplate('backpack', 'A backpack', 'N/A', True)
    bp2_t = ItemTemplate('backpack2', 'Another backpack', 'N/A', True)
    k_t = ItemTemplate('key', 'A key', 'N/A', False)

    # create a backpack (1) with a key (1) in it
    bp_1 = ItemContainer(bp_t)
    k_1 = Item(k_t)
    bp_1.add_item(k_1)

    # create another backpack (2)
    bp_2 = ItemContainer(bp_t)

    # create another backpack (3) with another key (2) in it
    bp_3 = ItemContainer(bp2_t)
    k_2 = Item(k_t)
    bp_3.add_item(k_2)

    # create a room
    r_1 = Room('room', 'room')

    # create a character and give him backpacks (1) and (3)
    c_1 = Character('transferer', '', '', r_1)
    c_1.items.add_item(bp_1)
    c_1.items.add_item(bp_3)

    # create a character and give him backpack (2)
    c_2 = Character('transferee', '', '', r_1)
    c_2.items.add_item(bp_2)

    # move backpack (1) with key (1) to other character
    assert bp_1 in c_1.items
    assert bp_1 not in c_2.items

    c_1.items.transfer_item(bp_1.get_short_name(), c_2.items)

    assert bp_1 not in c_1.items
    assert bp_1 in c_2.items

    # indirectly move key (2) from character's backpack (3) to other character
    assert k_2 in bp_3
    assert k_2 not in c_2.items

    c_1.items.transfer_item(k_2.get_short_name(), c_2.items)

    assert k_2 not in bp_3
    assert k_2 in c_2.items
Esempio n. 7
0
    def create_character(self):
        if len(self.available_faces) < 1:
            raise OutOfCharactersError()

        face = self.available_faces.pop(0)
        char = Character(face)
        self.characters[char.char_id] = char
        return char
Esempio n. 8
0
 def load_characters(self, gamedir, rooms, item_manager):
     data = json.load(open("{}/characters.json".format(gamedir)))
     for char in data:
         room = rooms[char['room']]
         c = Character(char['short_name'], char['full_name'],
                       char['password'], room)
         for item in item_manager.construct_loaded_items(char['items']):
             c.items.add_item(item)
         self.characters[char['short_name']] = c
Esempio n. 9
0
    def place_characters(self):

        indexes = []

        character_types_iter = CharacterTypes.__iter__()

        for i in range(self.nb_characters):

            if not indexes or len(indexes) == 0:
                for i in range(len(self.rooms)):
                    indexes.append(i)

            index = int(random.random() * len(indexes))
            character_type = character_types_iter.__next__()
            character = Character(character_type, self.rooms[index])
            self.rooms[index].add_character(character)
            self.characters.append(character)
            indexes.pop(index)
def login(controller, name):
    """Login the user so long as their name isn't currently active. In
    the future, this will support character accounts and will have to
    validate against a password if the user has a profile within some db
    """
    name = name.strip().lower()
    if not controller.players.has_key(name):
        controller.character = Character(name.lower())
        controller.players[name] = controller
        controller.character.inventory.add(Item(0, 'Random robes'))
        controller.character.inventory.add(Item(1, 'staff'))
        controller.send("You are now known as %s" % name)
        controller.broadcast("\n{} appears from somewhere or " \
                                 "another looking somewhat " \
                                 "dazed and disoriented.".format(YELLOW_TXT(name)),
                             protocol=controller, send2self=False)
        actions.l(controller)
    else:
        controller.send("\nSorry, the name {} is already in use. " \
                            "Please choose another name. ".format(name))
Esempio n. 11
0
    def create_character(self,
                         player=None,
                         address=(3, 3),
                         direction=Direction.LEFT,
                         face=None):
        if player is None:
            self.player or self.create_player()
            player = self.player

        self.game or self.create_game()

        char = Character(face or self.faker.pystr())
        char.attach_to_player(player)
        self.game.characters[char.char_id] = char
        self.game.turn_manager.characters.append(char)
        char.spawn(self.grid, address, direction)

        return char
Esempio n. 12
0
 def copy(self) -> Game:
     new_board = self.board.copy()
     new_char = Character(new_board)
     new_char._having_icon = self.char.having_icon
     return Game(new_board, new_char)
Esempio n. 13
0
    parser.add_argument('--height',
                        type=int,
                        default=10,
                        help="Height to use for map")
    parser.add_argument('--seed',
                        type=int,
                        default=random.random() * 1000,
                        help="Seed random generator with given value")
    parser.add_argument('--ui',
                        type=str,
                        default="text",
                        help="UI to load (curses, gtk, text)")

    return parser.parse_args()


if __name__ == "__main__":
    args = parse_commandline()

    print("Building {0}x{1} map".format(args.width, args.height))

    map = Map(height=args.height, width=args.width, seed=args.seed)
    map.generate()

    player = Character(name="Player")
    wumpus = Character(name="Wumpus")

    map.place_character(player)
    map.place_character(wumpus)

    print(map)
Esempio n. 14
0
def char(faker):
    return Character(faker.pystr())
Esempio n. 15
0
def load_char_chunk(line, loader, program_type, callbacks):
    line, description = line.split('\n')
    values = line.split(',')
    for index in range(len(values)):
        values[index] = values[index].strip()
    res_path = 'res/characters/' + values[ID] + '/' + values[ID]
    skel_path = 'res/characters/' + values[ID] + '/' + values[SKEL_ID] + '.skel'

    skills = get_skills(loader, values)

    char_id, name, display_name, skel_id = values[ID:SKEL_ID + 1]
    race = int(values[RACE])
    gender = int(values[GENDER])
    age = values[AGE]  # TODO: Adjust age based on played game time
    if age != 'Unknown':
        age = int(age)

    character_development = None
    if char_id in loader.get('save')['character_development']:
        character_development = loader.get(
            'save')['character_development'][char_id]
        ranks = character_development['ranks']
    else:
        ranks = None

    path = resource_find('data/' + program_type + '/grids/' + values[ID] +
                         '.txt')
    if path:
        ranks = Rank.load_ranks(path, ranks)
    else:
        ranks = Rank.load_ranks(
            resource_find('data/' + program_type + '/grids/base.txt'), ranks)
    # TODO - Add rank loading from save/load

    hp, mp, s, m, e, a, d = values[HEALTH:DEXTERITY + 1]

    element = 0
    attack_type = None
    favorite_weapon = None
    favorite_sub_weapon = None
    if values[TYPE] == 'A':
        attack_type = int(values[ATTACK_TYPE])
        element = int(values[ELEMENT])

        favorite_weapon = int(values[WEAPON_TYPE])
        if values[SUB_WEAPON_TYPE] != '-' and values[SUB_WEAPON_TYPE] != '-1':
            favorite_sub_weapon = int(values[SUB_WEAPON_TYPE])

    recruitment_items = {}
    for index in range(int(values[RECRUITMENT_ITEM_COUNT])):
        item_id, count = values[RECRUITMENT_ITEM - index].split('#')
        recruitment_items[item_id] = int(count)

    is_support = values[TYPE] == 'S'

    rank = 1
    familiarities = {}
    abilities = []
    perks = []
    if character_development is not None:
        for rank_status in character_development['ranks']['unlocked'][1:]:
            if rank_status:
                rank += 1
        familiarities = character_development['familiarities']
        abilities = character_development['abilities']
        perks = character_development['perks']

    # TODO Add equipped items to save/load and character_development

    if character_development is not None:
        family, high_damage, floor_depth, monsters_slain, people_slain = character_development[
            'family'], character_development[
                'high_damage'], character_development[
                    'floor_depth'], character_development[
                        'monsters_slain'], character_development[
                            'people_slain']
    else:
        family, high_damage, floor_depth, monsters_slain, people_slain = '', 0, 0, 0, 0

    char = Character(char_id,
                     name,
                     skel_path,
                     res_path,
                     int(hp),
                     int(mp),
                     int(s),
                     int(m),
                     int(e),
                     int(a),
                     int(d),
                     element,
                     skills,
                     _race=race,
                     _gender=gender,
                     _age=age,
                     _description=description,
                     _familiarities=familiarities,
                     _abilities=abilities,
                     _perks=perks,
                     _display_name=display_name,
                     _index=len(loader.get('chars')),
                     _is_support=is_support,
                     _ranks=ranks,
                     _rank=rank,
                     _attack_type=attack_type,
                     _family=family,
                     _high_damage=high_damage,
                     _lowest_floor=floor_depth,
                     _monsters_slain=monsters_slain,
                     _people_slain=people_slain,
                     _recruitment_items=recruitment_items,
                     _favorite_weapon=favorite_weapon,
                     _favorite_sub_weapon=favorite_sub_weapon)

    outfit = char.get_outfit()
    inventory = Refs.gc.get_inventory()
    if character_development is not None:
        for index, equipment_id in enumerate(
                character_development['equipment']):
            if equipment_id is None:
                continue
            item_id, item_hash = equipment_id.split('#')
            outfit.set_equipment(index + WEAPON,
                                 inventory.get_item(item_id, int(item_hash)))

    char.refresh_stats()

    loader.append('chars', char_id, char)
    for callback in callbacks:
        if callback is not None:
            callback()
Esempio n. 16
0
 def construct_character(short_name, full_name, password, room):
     c = Character(short_name, full_name, password, room)
     basic_game.char_manager.characters[short_name] = c
     return c