예제 #1
0
function relation_setRelation($from, $target, $relation, $duration, $db, $end_time, $from_points_old, $target_points_old, $fame = 0)
{
    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 ") . ", " . "fame ='{$fame}'";
    }
    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;
}
예제 #2
0
파일: tribes.inc.php 프로젝트: norter/Game
function relation_setRelation($from, $target, $relation, $duration, $end_time, $from_points_old, $target_points_old, $fame = 0)
{
    global $db;
    if (($from_points = tribe_getMight($from)) < 0) {
        $from_points = 0;
    }
    if (($target_points = tribe_getMight($target)) < 0) {
        $from_points = 0;
    }
    // have to remember the number of members of the other side?
    if ($GLOBALS['relationList'][$relation]['storeTargetMembers']) {
        $target_members = tribe_getNumberOfMembers($target);
    }
    if ($relation == 0) {
        $sql = $db->prepare("DELETE FROM " . RELATION_TABLE . " \n                         WHERE tribe = :tribe\n                           AND tribe_target = :tribe_target");
        $sql->bindValue('tribe', $from, PDO::PARAM_STR);
        $sql->bindValue('tribe_target', $target, PDO::PARAM_STR);
        if (!$sql->execute() || $sql->rowCount() == 0) {
            return false;
        }
    } else {
        $query = "REPLACE " . RELATION_TABLE . " SET tribe = '{$from}', " . (isset($target_members) && $target_members != 0 ? "target_members = '{$target_members}', " : "") . "tribe_target = '{$target}', " . "timestamp = NOW() +0, " . "relationType = '{$relation}', " . "tribe_rankingPoints = '{$from_points}', " . "target_rankingPoints = '{$target_points}', " . "attackerReceivesFame = '" . $GLOBALS['relationList'][$relation]['attackerReceivesFame'] . "', " . "defenderReceivesFame = '" . $GLOBALS['relationList'][$relation]['defenderReceivesFame'] . "', " . "defenderMultiplicator = '" . $GLOBALS['relationList'][$relation]['defenderMultiplicator'] . "', " . "attackerMultiplicator = '" . $GLOBALS['relationList'][$relation]['attackerMultiplicator'] . "', " . ($end_time ? "duration = '{$end_time}' " : "duration = (NOW() + INTERVAL '{$duration}' HOUR) + 0 ") . ", " . "fame ='{$fame}'";
        if (!$db->query($query)) {
            return false;
        }
    }
    // calculate the fame update if necessary
    if ($GLOBALS['relationList'][$relation]['fameUpdate'] != 0) {
        if ($GLOBALS['relationList'][$relation]['fameUpdate'] > 0) {
            $fame = relation_calcFame($from_points, $from_points_old, $target_points, $target_points_old);
        } else {
            if ($GLOBALS['relationList'][$relation]['fameUpdate'] < 0) {
                // calculate fame: first argument is winner!
                $fame = -1 * relation_calcFame($target_points, $target_points_old, $from_points, $from_points_old);
            }
        }
        $sql = $db->prepare("UPDATE " . TRIBE_TABLE . "\n                         SET fame = fame + :fame\n                         WHERE tag LIKE :from");
        $sql->bindValue('fame', $fame, PDO::PARAM_INT);
        $sql->bindValue('from', $from, PDO::PARAM_STR);
        if (!$sql->execute() || $sql->rowCount() == 0) {
            return false;
        }
    }
    return 1;
}