Ejemplo n.º 1
0
def move(txt_args, db, chat_id, username):
    args = txt_args.split(' ')
    campaign_id, campaign = db.get_campaign(chat_id)
    dm_username = campaign.get('dm_username', None)
    
    turns = campaign.get('turns', None)
    turn_index = int(campaign.get('turn_index', '0'))
    current_turn = turns[turn_index % len(turns)]

    if len(args) > 1:
        user_param = utils.normalized_username(args[0])
        position = args[1]
        if dm_username != username:
            return f"Only the Dungeon Master can move other characters"
    else:
        user_param = username
        position = args[0]
        if utils.normalized_username(current_turn) != username:
            return f"Is the turn of {current_turn}. You can move only on your turn"

    result = db.set_char_position(campaign_id, user_param, position)
    
    if result is None:
        return f"{user_param} does not exist on this battle field"

    return f"{user_param} moved to {position} successfully!"
Ejemplo n.º 2
0
def set_hp(command, txt_args, db, chat_id, username):
    args = txt_args.split(' ')
    if args[0].isdigit():
        points = int(args[0])
    else:
        return f'Invalid commands parameters, the correct structure is: \r\n {command}  <integer>  <username|character>'

    campaign_id, campaign = db.get_campaign(chat_id)
    dm_username = campaign.get('dm_username', None)
    if dm_username != username:
        return f'Only the Dungeon Master can execute this command'

    if len(args) > 1:
        user_param = args[1]
    else:
        user_param = username

    user_param = utils.normalized_username(user_param)
    character = get_linked_character(db, chat_id, user_param)

    if command == '/damage':
        result = character.removed_hit_points + int(points)
        if result > character.max_hit_points:
            result = character.max_hit_points
    else:
        result = character.removed_hit_points - int(points)
        if result < 0:
            result = 0

    character.current_hit_points = character.max_hit_points - result

    db.set_char_hp(character.id, hit_points=result)
    return f'{character.name} received {points} pts of {command}. HP: {character.current_hit_points}/{character.max_hit_points}'
Ejemplo n.º 3
0
def get_status(other_username, db, chat_id, username):
    search_param = other_username if other_username != '' else username
    search_param = utils.normalized_username(search_param)
    character = get_linked_character(db, chat_id, search_param)

    return (
        f'{character.name} | {character.race} {character._class} Level {character.level}\r\n'
        f'HP: {character.current_hit_points}/{character.max_hit_points} | XP: {character.current_experience}'
    )
Ejemplo n.º 4
0
def get_spells(other_username, db, chat_id, username):
    search_param = other_username if other_username != '' else username
    search_param = utils.normalized_username(search_param)
    character = get_linked_character(db, chat_id, search_param)

    if len(character.spells) > 0:
        spells = ', '.join([s.name for s in character.spells])
        return f'Attack spells for {character.name}: {spells}'
    else:
        return f'{character.name} does not have any attack spells'
Ejemplo n.º 5
0
def get_weapons(other_username, db, chat_id, username):
    search_param = other_username if other_username != '' else username
    search_param = utils.normalized_username(search_param)
    character = get_linked_character(db, chat_id, search_param)

    if len(character.weapons) > 0:
        weapons = [w.name for w in character.weapons]
        return f'Weapons in {character.name}\'s inventory: {weapons}'
    else:
        return f'{character.name} does not have any weapon'
Ejemplo n.º 6
0
def link_character(command, txt_args, db, chat_id, username, **kargs):
    campaign = kargs.get('campaign')
    campaign_id = kargs.get('campaign_id')
    params = [x.strip() for x in txt_args.split(' ')]

    character_id = params[0]
    if (len(params) > 1):
        player = utils.normalized_username(params[1])
    else:
        player = username

    db.set_character_link(campaign_id, player, character_id)

    return f'Character with id {character_id} linked to {player} successfully!'
Ejemplo n.º 7
0
def link_character(args, db, chat_id, username):
    params = [x.strip() for x in args.split(' ')]

    character_id = params[0]
    if (len(params) > 1):
        player = utils.normalized_username(params[1])
    else:
        player = username

    campaign_id, campaign = db.get_campaign(chat_id)
    if campaign_id is None:
        return f'You must be in an active campaign to link characters!'

    db.set_character_link(campaign_id, player, character_id)

    return f'Character with id {character_id} linked to {player} successfully!'
Ejemplo n.º 8
0
        def wrapper(command, txt_args, db, chat_id, username, **kargs):
            if 'campaign' not in kargs:
                raise CampaignNotFound

            args = txt_args.split(' ')

            search_param = args[0] if from_params is True and len(
                args) > 0 and args[0] != '' else username
            search_param = utils.normalized_username(search_param)

            kargs['character_id'] = db.get_character_id(
                kargs.get('campaign_id'), search_param)
            kargs['character'] = db.get_character(kargs.get('character_id'),
                                                  find_by_id=True)

            if kargs.get('character') is None:
                raise CharacterNotFound

            return func(command, txt_args, db, chat_id, username, **kargs)
Ejemplo n.º 9
0
def set_battle_positions(chat_id, txt_args, db, username):
    campaign_id, campaign = db.get_campaign(chat_id)
    if campaign_id == None or campaign == None:
        raise CampaignNotFound

    dm_username = campaign.get('dm_username', None)
    if dm_username != username:
        raise NotADM

    args = txt_args.split(',')
    positions = {}
    for position in args:
        position = position.split(' ')
        position = list(filter(None, position))
        positions[utils.normalized_username(position[0])] = position[1]
        positions[position[0]] = position[1]

    db.set_battle_positions(campaign_id, positions)

    return "Positions setted successfully!"