当前位置: 首页>>代码示例>>PHP>>正文


PHP DBAccess::getAffectedRows方法代码示例

本文整理汇总了PHP中DBAccess::getAffectedRows方法的典型用法代码示例。如果您正苦于以下问题:PHP DBAccess::getAffectedRows方法的具体用法?PHP DBAccess::getAffectedRows怎么用?PHP DBAccess::getAffectedRows使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DBAccess的用法示例。


在下文中一共展示了DBAccess::getAffectedRows方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: revive_players

/**
 * Revive up to a small max in minor hours, and a stable percent on major hours.
 * Defaults
 * sample_use: revive_players(array('just_testing'=>true));
 * @params array('full_max'=>80, 'minor_revive_to'=>100, 'major_revive_percent'=>5,
 *      'just_testing'=>false)
**/
function revive_players($params = array())
{
    // Previous min/max was 2-4% always, ~3000 players, so 60-120 each time.
    // In: full_max, default 80%
    $full_max = isset($params['full_max']) ? $params['full_max'] : 80;
    // minor_revive_to, default 100
    $minor_revive_to = isset($params['minor_revive_to']) ? $params['minor_revive_to'] : 100;
    // major_revive_percent, default 5%
    $major_revive_percent = isset($params['major_revive_percent']) ? $params['major_revive_percent'] : 5;
    $just_testing = isset($params['just_testing']) ? 'true' : 'false';
    $major_hour = 3;
    // Hour for the major revive.
    $revive_amount = 0;
    // Initial.
    /* New schedule should be:
       1: revive to 100
       2: revive to 100 (probably 0)
       3: revive 150, (250 total) to a max of 80% of total, ~2500.
       4: revive to 100 (almost certainly no more)
       5: revive to 100 (almost certainly no more)
       6: revive 150, (400 total) to a max of 80% of total, ~2500
       7: ...etc.
       */
    // SQL pulls.
    $db = new DBAccess();
    // Determine the total dead (& confirmed).
    $sel_dead = 'select count(*) from players where health<1 and confirmed=1';
    $dead_count = $db->QueryItem($sel_dead);
    // If none dead, return false.
    if (!$dead_count) {
        return array(0, 0);
    }
    // Determine the total confirmed.
    $sel_total_active = 'select count(*) from players where confirmed=1';
    $total_active = $db->QueryItem($sel_total_active);
    // Calc the total alive.
    $total_alive = $total_active - $dead_count;
    // Determine major or minor based on the hour.
    $sel_current_time = "SELECT amount from time where time_label='hours'";
    $current_time = $db->QueryItem($sel_current_time);
    assert(is_numeric($current_time));
    $major = false;
    if ($current_time % $major_hour == 0) {
        $major = true;
    }
    // If minor, and total_alive is more than minor_revive_to-1, return 0/total.
    if (!$major) {
        // minor
        if ($total_alive > $minor_revive_to - 1) {
            // minor_revive_to already met.
            return array(0, $dead_count);
        } else {
            // else revive minor_revive_to - total_alive.
            $revive_amount = floor($minor_revive_to - $total_alive);
        }
    } else {
        // major.
        $percent_int = floor($major_revive_percent / 100 * $total_active);
        if ($dead_count < $percent_int) {
            // If major, and total_dead is less than target_num (major_revive_percent*total, floored)
            // just revive those that are dead.
            $revive_amount = $dead_count;
        } else {
            // Else revive target_num (major_revive_percent*total, floored)
            $revive_amount = $percent_int;
        }
    }
    //die();
    assert(isset($revive_amount));
    assert(isset($current_time));
    assert(isset($just_testing));
    assert(isset($dead_count));
    assert(isset($major));
    // Actually perform the revive on those integers.
    // Use the order by clause to determine who revives, by time, days and then by level, using the limit set previously.
    //select uname, player_id, level,floor(($major_revive_percent/100)*$total_active) days, resurrection_time from players where confirmed = 1 AND health < 1 ORDER BY abs(8 - resurrection_time) asc, level desc, days asc
    $select = "select player_id from players where confirmed = 1 AND health < 1 ORDER BY abs(" . intval($current_time) . "\n        \t- resurrection_time) asc, level desc, days asc limit " . $revive_amount;
    $up_revive_players = "UPDATE players\n                    SET status = 0,\n                    health =\n                    \tCASE WHEN " . $just_testing . "\n                    \tTHEN health\n                    \tELSE\n                    \t\t(\n                    \t\tCASE WHEN class='White'\n                    \t\tTHEN (150+(level*3))\n                    \t\tELSE (100+(level*3)) END\n                    \t\t)\n                    \tEND\n                    WHERE\n                    player_id IN (" . $select . ")\n                  ";
    $db->Update($up_revive_players);
    $truly_revived = $db->getAffectedRows();
    // Return the 'revived/total' actually revived.
    return array($truly_revived, $dead_count);
}
开发者ID:ninjajerry,项目名称:ninjawars,代码行数:90,代码来源:lib_deity.php


注:本文中的DBAccess::getAffectedRows方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。