示例#1
0
def join_battle():
    cmd = commands.JoinBattle(
        request.json['battle_ref'],
        request.json['team_name'],
    )
    uow = unit_of_work.UnitOfWork()
    battle_ref = messagebus.handle(cmd, uow)
    return jsonify({'status': 'OK'}), 200
示例#2
0
def register_a_pokemon_change():
    cmd = commands.RegisterChangePokemon(
        request.json['battle_ref'],
        request.json['player'],
        request.json['pokemon_nickname'],
    )
    uow = unit_of_work.UnitOfWork()
    battle_ref = messagebus.handle(cmd, uow)
    return jsonify({'status': 'OK'}), 200
示例#3
0
def register_a_move():
    cmd = commands.RegisterUseMove(
        request.json['battle_ref'],
        request.json['player'],
        request.json['move_name'],
    )
    uow = unit_of_work.UnitOfWork()
    battle_ref = messagebus.handle(cmd, uow)
    return jsonify({'status': 'OK'}), 200
示例#4
0
def get_actions(ref):
    uow = unit_of_work.UnitOfWork()
    player = request.args.get('player')
    with uow:
        battle = uow.battles.get(ref)

    moves = battle.get_possible_moves(player)
    pokemons = battle.get_inactive_pokemons(player)
    return jsonify({'moves': moves, 'pokemons': pokemons}), 200
示例#5
0
def add_pokemon():
    cmd = commands.AddPokemonToTeam(
        request.json['team_name'],
        request.json['nickname'],
        request.json['species'],
        request.json['level'],
        request.json['moves'],
    )
    uow = unit_of_work.UnitOfWork()
    messagebus.handle(cmd, uow)
    return jsonify({'status': 'OK'}), 200
示例#6
0
def get_battle(ref):
    uow = unit_of_work.UnitOfWork()
    with uow:
        battle = uow.battles.get(ref)
    return jsonify(battle.to_dict()), 200
示例#7
0
def host_battle():
    cmd = commands.HostBattle(request.json['team_name'], )
    uow = unit_of_work.UnitOfWork()
    battle_ref = messagebus.handle(cmd, uow)
    return jsonify({'battle_ref': battle_ref}), 201
示例#8
0
def add_team():
    cmd = commands.AddTeam(request.json['name'])
    uow = unit_of_work.UnitOfWork()
    messagebus.handle(cmd, uow)
    return jsonify({'status': 'OK'}), 201