#!/usr/bin/perl -w

# turns_payout.pl
# (c) CWZ, LLC

# Run the turns payout for CWZ

use strict;
use lib '.';
use CWZ;

Exec: {
    qDb_do("UPDATE Player SET turns = turns +
        CASE
            WHEN (SELECT tier FROM Account WHERE Player.login_id = Account.id) = 1 THEN 3
            WHEN (SELECT tier FROM Account WHERE Player.login_id = Account.id) = 2 THEN 4
            WHEN (SELECT tier FROM Account WHERE Player.login_id = Account.id) = 3 THEN 5
            WHEN (SELECT tier FROM Account WHERE Player.login_id = Account.id) = 4 THEN 5
            WHEN (SELECT tier FROM Account WHERE Player.login_id = Account.id) = 5 THEN 6
            ELSE 0
        END
        WHERE turns < 5000");

        qDb_do("UPDATE Round SET payouts = payouts + 1 WHERE start_date <= NOW() ORDER BY start_date DESC LIMIT 1");

        }
