Example #1
0
function relation_setRelation($from, $target, $relation, $duration, $db, $end_time, $from_points_old, $target_points_old)
{
    global $relationList;
    if (($from_points = tribe_getMight($from, $db)) < 0) {
        $from_points = 0;
    }
    if (($target_points = tribe_getMight($target, $db)) < 0) {
        $from_points = 0;
    }
    // have to remember the number of members of the other side?
    if ($relationList[$relation]['storeTargetMembers']) {
        $target_members = tribe_getNumberOfMembers($target, $db);
    }
    if ($relation == 0) {
        $query = "DELETE FROM Relation " . "WHERE tribe = '{$from}' " . "AND tribe_target = '{$target}'";
    } else {
        $query = "REPLACE Relation " . "SET tribe = '{$from}', " . ($target_members != 0 ? "target_members = '{$target_members}', " : "") . "tribe_target = '{$target}', " . "timestamp = NOW() +0, " . "relationType = '{$relation}', " . "tribe_rankingPoints = '{$from_points}', " . "target_rankingPoints = '{$target_points}', " . "attackerReceivesFame = '" . $relationList[$relation][attackerReceivesFame] . "', " . "defenderReceivesFame = '" . $relationList[$relation][defenderReceivesFame] . "', " . "defenderMultiplicator = '" . $relationList[$relation][defenderMultiplicator] . "', " . "attackerMultiplicator = '" . $relationList[$relation][attackerMultiplicator] . "', " . ($end_time ? "duration = '{$end_time}' " : "duration = (NOW() + INTERVAL '{$duration}' HOUR) + 0 ");
    }
    if (!$db->query($query)) {
        echo $query;
        return 0;
    }
    // calculate the fame update if necessary
    if ($relationList[$relation][fameUpdate] != 0) {
        if ($relationList[$relation][fameUpdate] > 0) {
            $fame = relation_calcFame($from_points, $from_points_old, $target_points, $target_points_old);
        } else {
            if ($relationList[$relation][fameUpdate] < 0) {
                // calculate fame: first argument is winner!
                $fame = -1 * relation_calcFame($target_points, $target_points_old, $from_points, $from_points_old);
            }
        }
        $query = "UPDATE Tribe " . "SET fame = fame + {$fame} " . "WHERE tag LIKE '{$from}'";
        if (!$db->query($query)) {
            echo $query;
            return 0;
        }
    }
    return 1;
}
Example #2
0
function ranking_calculateElo($db, $winnertag, $winnerpoints, $losertag, $loserpoints)
{
    // get actual points
    $winnerpoints_actual = tribe_getMight($winnertag, $db);
    $loserpoints_actual = tribe_getMight($losertag, $db);
    $faktor = 10;
    //k faktor bestimmen
    echo $winnertag . " " . $winnerpoints . " " . $loser . " " . $loserpoints;
    $k = 10;
    if ($winnerpoints < 2400) {
        $query = "SELECT calculateTime from RankingTribe where tribe like '{$winnertag}'";
        $res = $db->query($query);
        if (!$res) {
            return 0;
        }
        $res = $res->nextRow(MYSQL_ASSOC);
        if ($res['calculateTime'] > 30) {
            $k = 15;
        } else {
            $k = 25;
        }
    }
    $eloneu = $winnerpoints_actual + $k * $faktor * (1 - 1 / (1 + pow(10, ($loserpoints - $winnerpoints) / 400)));
    $query = "UPDATE RankingTribe SET points_rank=" . (int) $eloneu . ", calculateTime = calculateTime+1 WHERE tribe like '{$winnertag}'";
    if (!$db->query($query)) {
        return 0;
    }
    $k = 10;
    if ($loserpoints < 2400) {
        $query = "SELECT calculateTime from RankingTribe where tribe like '{$losertag}'";
        $res = $db->query($query);
        if (!$res) {
            return 0;
        }
        $res = $res->nextRow(MYSQL_ASSOC);
        if ($res['calculateTime'] > 30) {
            $k = 15;
        } else {
            $k = 25;
        }
    }
    $eloneu = $loserpoints_actual + $k * $faktor * (0 - 1 / (1 + pow(10, ($winnerpoints - $loserpoints) / 400)));
    $query = "UPDATE RankingTribe SET points_rank=" . (int) $eloneu . ", calculateTime = calculateTime+1 WHERE tribe like '{$losertag}'";
    if (!$db->query($query)) {
        return 0;
    }
    return ranking_sort($db);
}
Example #3
0
function ranking_calculateElo($winnertag, $winnerpoints, $losertag, $loserpoints)
{
    global $db;
    // get actual points
    $winnerpoints_actual = tribe_getMight($winnertag);
    $loserpoints_actual = tribe_getMight($losertag);
    $faktor = 2;
    //k faktor bestimmen
    //echo($winnertag. " ". $winnerpoints." ". $loser." ". $loserpoints);
    $k = 10;
    if ($winnerpoints < 2400) {
        $query = "SELECT calculateTime FROM " . RANKING_TRIBE_TABLE . " WHERE tribe LIKE '{$winnertag}'";
        $res = $db->query($query);
        if (!$res) {
            return 0;
        }
        $res = $res->fetch(PDO::FETCH_ASSOC);
        if ($res['calculateTime'] > 30) {
            $k = 15;
        } else {
            $k = 25;
        }
    }
    $eloneu = $winnerpoints_actual + max(2, $k * $faktor * (1 - 1 / (1 + pow(10, ($loserpoints - $winnerpoints) / 400))));
    $sql = $db->prepare("UPDATE " . RANKING_TRIBE_TABLE . " SET \n                        points_rank = :points_rank, \n                        calculateTime = calculateTime+1 \n                      WHERE tribe like :winnertag");
    $sql->bindValue('points_rank', $eloneu, PDO::PARAM_INT);
    $sql->bindValue('winnertag', $winnertag, PDO::PARAM_STR);
    if (!$sql->execute()) {
        return 0;
    }
    $k = 10;
    if ($loserpoints < 2400) {
        $query = "SELECT calculateTime FROM " . RANKING_TRIBE_TABLE . " WHERE tribe LIKE '{$losertag}'";
        $res = $db->query($query);
        if (!$res) {
            return 0;
        }
        $res = $res->fetch(PDO::FETCH_ASSOC);
        if ($res['calculateTime'] > 30) {
            $k = 15;
        } else {
            $k = 25;
        }
    }
    $eloneu = $loserpoints_actual + min(-2, $k * $faktor * (0 - 1 / (1 + pow(10, ($winnerpoints - $loserpoints) / 400))));
    $sql = $db->prepare("UPDATE " . RANKING_TRIBE_TABLE . "\n                       SET points_rank = :points_rank,\n                         calculateTime = calculateTime + 1\n                       WHERE tribe LIKE :tag");
    $sql->bindValue('points_rank', $eloneu, PDO::PARAM_INT);
    $sql->bindValue('tag', $losertag, PDO::PARAM_STR);
    if (!$sql->execute() || $sql->rowCount() == 0) {
        return 0;
    }
}