Exemplo n.º 1
0
async def pay(ctx, target_location, amount):
    if not config['game_ongoing']: return

    amount = int(amount)  # dumb.
    member = ctx.message.author
    p = models.Player()
    try:
        p.custom_load("discord_id = ?", (member.id, ))
    except Exception:
        await ctx.send("I don't have you listed as a player, {}\n\
            If you believe this is an error, please talk to a Lord or the King"
                       .format(member.mention))
        return
    # Make sure player has enough coins!!!
    if amount < 1:
        await ctx.send("You can't pay 0 or negative coins, {}".format(
            member.mention))
        return
    elif amount > p.coins:
        await ctx.send("{}, you don't have enough coins!".format(
            member.mention))
        return
    # Get team, current location id, available locations
    t = models.Team()
    t.load(p.team_id)
    current_loc = t.current_location_id
    avail_locs = graphanalyzer.get_next_location_list(t.team_id)
    # Make sure it's a valid target location.
    if target_location.lower() not in (name.lower()
                                       for name in avail_locs.keys()):
        await ctx.send(
            "I don't think {} is a valid location. Maybe you mistyped it?".
            format(target_location))
        return
    # Get the ID for the target location...
    target_loc = models.Location()
    target_loc.custom_load("name = ? COLLATE NOCASE", (target_location, ))

    edge = models.LocationEdge()
    edge.custom_load("start_location_id = ? AND end_location_id = ?", (
        current_loc,
        target_loc.location_id,
    ))
    # Store the payment in the db
    payment = models.Payment()
    payment.player_id = p.player_id
    payment.team_id = p.team_id
    payment.amount = amount
    payment.location_edge = edge.edge_id
    payment.time = helpers.get_game_day()
    payment.insert()

    # Remove coins from player's account.
    p.coins -= amount
    p.last_active_day = helpers.get_game_day()
    p.update()
    models.save()
    # Send confirmation message.
    await ctx.send("{} has paid **{}** coins toward **{}**".format(
        member.mention, amount, target_loc.name))
Exemplo n.º 2
0
def create_edge(start_loc, end_loc, weight=0):
    print("Trying to create {} -> {}".format(start_loc, end_loc))
    start = models.Location()
    start.custom_load("name = ? COLLATE NOCASE", (start_loc, ))
    end = models.Location()
    end.custom_load("name = ? COLLATE NOCASE", (end_loc, ))

    edge = models.LocationEdge()
    edge.start_location_id = start.location_id
    edge.end_location_id = end.location_id
    edge.weight = weight
    edge.insert()

    print("Added {} to {}, Weight: {}".format(start.name, end.name,
                                              edge.weight))
Exemplo n.º 3
0
def team_attempt_move(team_id):
    process_log = ""
    # Load team.
    t = models.Team()
    t.load(team_id)
    flns = paymentreducer.get_funding_list(team_id,
                                           helpers.get_game_day() - 1, False)
    fl = paymentreducer.get_funding_list(team_id,
                                         helpers.get_game_day() - 1, True)

    # Check for best-funded succesful path
    new_loc = t.current_location_id
    biggest_funding = -1
    was_sabotaged = False
    for k, v in flns.items():
        le = models.LocationEdge()
        le.load(k)
        if v >= le.weight and v > biggest_funding:
            new_loc = le.end_location_id
            biggest_funding = v
            if fl[k] < le.weight:
                was_sabotaged = True
            else:
                was_sabotaged = False

    if biggest_funding == -1:
        process_log = "The {} didn't raise enough to book passage anywhere...".format(
            t.name)
    else:
        l = models.Location()
        l.load(new_loc)
        if was_sabotaged:
            process_log = "The {} tried to travel to {}, but someone sabotaged them and they were stopped by the Black Cats!".format(
                t.name, l.name)
        else:
            t.current_location_id = new_loc
            t.update()
            process_log = "The {} have successfully reached {}!".format(
                t.name, l.name)

    models.save()
    return process_log + "\n"
Exemplo n.º 4
0
def get_funding_table(team_id, day=-1):
    #f = get_funding_list(team_id, day=helpers.get_game_day(), show_sabotage=False)
    f = get_funding_list(team_id, day, show_sabotage=False)
    if len(f.keys()) == 0:
        return "No payments have been made yet today!"

    t = models.Team()
    t.load(team_id)
    tab = []
    row_format = "{:<18}{:<8}{:<8}\n"
    tab.append(row_format.format('Location', 'Toll', 'Paid'))
    tab.append("-" * (34) + "\n")
    # FIXME toooo many queries
    for k, v in f.items():
        le = models.LocationEdge()
        le.load(k)
        l = models.Location()
        l.load(le.end_location_id)
        tab.append(row_format.format(l.name, le.weight, v))

    return "".join(tab)
Exemplo n.º 5
0
async def sabotage(ctx, target_team, target_location, amount):
    if not config['game_ongoing']: return
    # just pay() but with negative coins and another team
    amount = int(amount)  # still dumb
    member = ctx.message.author
    p = models.Player()
    try:
        p.custom_load("discord_id = ?", (member.id, ))
    except Exception:
        await ctx.send(
            "Gonna be hard to sabotage when I don't have you listed as a player, {}\n\
            If you believe this is a mistake, please talk to a Lord or the King"
            .format(member.mention))
        return
    # Mke sure player has enough coins
    if amount < 1:
        await ctx.send("You can't pay 0 or negative coins, {}".format(
            member.mention))
        return
    elif amount > p.coins:
        await ctx.send("{}, you don't have enough coins!".format(
            member.mention))
        return

    t = models.Team()
    try:
        t.custom_load("name = ? COLLATE NOCASE",
                      (target_team, ))  # TODO make this more user-friendly
    except Exception:
        await ctx.send(
            "I don't think {} is a real team, {}. Make sure you type the full name!"
            .format(target_team, member.mention))
        return

    if t.team_id == p.team_id:
        await ctx.send(
            "You can't sabotage your own team, {}!!! They won't like you for that!"
            .format(member.mention))
        return

    current_loc = t.current_location_id
    avail_locs = graphanalyzer.get_next_location_list(t.team_id)
    # Validate target location...
    if target_location.lower() not in (name.lower()
                                       for name in avail_locs.keys()):
        await ctx.send(
            "I don't think {} is a valid location. Maybe a typo?".format(
                target_location))
        return
    # Get id for the target location...
    location = models.Location()
    location.custom_load("name = ? COLLATE NOCASE", (target_location, ))

    edge = models.LocationEdge()
    edge.custom_load("start_location_id = ? AND end_location_id = ?",
                     (current_loc, location.location_id))

    # Store the payment!
    payment = models.Payment()
    payment.player_id = p.player_id
    payment.team_id = t.team_id
    payment.amount = -amount  # VERY IMPORTANT DIFFERENCE
    payment.location_edge = edge.edge_id
    payment.time = helpers.get_game_day()
    payment.insert()

    # Remove coins from the player's account
    p.coins -= amount
    p.last_active_day = helpers.get_game_day()
    p.update()
    models.save()
    # Send confirmation message.
    await ctx.send(
        "{} has paid **{}** coins to sabotage the **{}'** trip to **{}**".
        format(member.mention, amount, t.name, location.name))