Ejemplo n.º 1
0
def test_rpg_channel():
    server = '1'
    channel = '2'
    rpg.set_rpg_channel(server, channel)
    channel = rpg.get_rpg_channel(server)
    print('Setchannel/getchannel', channel, channel == channel)

    channel = '3'
    rpg.set_rpg_channel(server, channel)
    channel = rpg.get_rpg_channel(server)
    print('Setchannel/getchannel', channel, channel == channel)

    rpg.get_table(rpg.RPG_PLAYER_TABLE).drop()
Ejemplo n.º 2
0
def test_rpg_player():
    player = RPGPlayer(userid='1', picture_url='', username='******', health=10)

    try:
        rpg.get_player(player.userid, player.name)
    except ValueError:
        print('No user successful')

    rpg.update_player(player)
    print(player.name)
    for k, v in rpg.get_player(player.userid, player.name).as_dict().items():
        print(k, v)

    rpg.get_table(rpg.RPG_PLAYER_TABLE).drop()
Ejemplo n.º 3
0
def test_boss_parties():
    players = [
        RPGPlayer(userid=str(x), picture_url='', username=str(x))
        for x in range(400)
    ]
    for p in players:
        p.set_busy(BUSY_DESC_BOSSRAID, 10, randint(0, 10))
    rpg.get_table(rpg.RPG_PLAYER_TABLE).insert_many(
        [x.as_dict() for x in players])

    for k, v in rpg.get_boss_parties().items():
        print(k, len(v))

    rpg.get_table(rpg.RPG_PLAYER_TABLE).drop()
Ejemplo n.º 4
0
def test_decrement_busy_counters():
    players = [
        RPGPlayer(userid=str(x), picture_url='', username=str(x))
        for x in range(10)
    ]
    for p in players:
        p.set_busy(BUSY_DESC_ADVENTURE, 20, randint(0, 10))
    rpg.get_table(rpg.RPG_PLAYER_TABLE).insert_many(
        [x.as_dict() for x in players])

    rpg.decrement_busy_counters()
    for x in rpg.get_table(rpg.RPG_PLAYER_TABLE).find():
        print(x.get('busy').get('time'))

    rpg.get_table(rpg.RPG_PLAYER_TABLE).drop()
Ejemplo n.º 5
0
def test_top_list():
    players = [
        RPGPlayer(userid=str(x), picture_url='', username=str(x),
                  exp=x).as_dict() for x in range(400)
    ]
    rpg.get_table(rpg.RPG_PLAYER_TABLE).insert_many(players)

    print('0-10')
    for i in rpg.get_top_players(group='exp', start=0, amount=10):
        print(i)

    print('11-20')
    for i in rpg.get_top_players(group='exp', start=300, amount=10):
        print(i)

        rpg.get_table(rpg.RPG_PLAYER_TABLE).drop()
Ejemplo n.º 6
0
def test_add_stat():
    player = RPGPlayer(userid='1',
                       picture_url='',
                       username='******',
                       pets=[RPGPet(name=str(x)) for x in range(2)])
    rpg.update_player(player)
    exp = player.exp
    rpg.add_stats(player.userid, 'exp', 10)
    print('Player exp from-to', exp,
          rpg.get_player(player.userid, player.name).exp)

    exp = [p.exp for p in rpg.get_player(player.userid, player.name).pets]
    rpg.add_pet_stats(player.userid, 'exp', 10)
    print('Pet exp from-to', exp,
          [p.exp for p in rpg.get_player(player.userid, player.name).pets])

    rpg.get_table(rpg.RPG_PLAYER_TABLE).drop()
Ejemplo n.º 7
0
def test_get_done_players():
    players = [
        RPGPlayer(userid=str(x), picture_url='', username=str(x))
        for x in range(10)
    ]
    for p in players:
        p.set_busy(BUSY_DESC_ADVENTURE, randint(0, 2), '1')
    rpg.get_table(rpg.RPG_PLAYER_TABLE).insert_many(
        [x.as_dict() for x in players])

    print('Done players', len(list(rpg.get_done_players())))
    print('Player busytimes', [
        x.get('busy').get('time')
        for x in rpg.get_table(rpg.RPG_PLAYER_TABLE).find()
    ])

    rpg.get_table(rpg.RPG_PLAYER_TABLE).drop()
Ejemplo n.º 8
0
def get_rpg_players():
    try:
        page, per_page = page_from_query()
    except ValueError:
        return abort(400, {'error': 'invalid parameters'})
    if not per_page:
        per_page = 25
    skip, amount = per_page * (page - 1), per_page
    if amount <= 0 or skip < 0:
        return abort(404)
    r = rpg.get_table(rpg.RPG_PLAYER_TABLE).find({}, {
        '_id': 0
    }).sort('exp', DESC).skip(skip).limit(amount)
    return jsonify(list(r))
Ejemplo n.º 9
0
def get_rpg_player(user_id: int):
    r = rpg.get_table(rpg.RPG_PLAYER_TABLE).find_one({'userid': str(user_id)},
                                                     {'_id': 0})
    return jsonify(r)
Ejemplo n.º 10
0
def get_rpg_players_count():
    c = rpg.get_table(rpg.RPG_PLAYER_TABLE).count({})
    return jsonify({'count': c})