Пример #1
0
function level_up_if_possible($char_id, $auto_level = false)
{
    // Setup values:
    $max_level = maximum_level();
    $health_to_add = 100;
    $turns_to_give = 50;
    $stat_value_to_add = 5;
    $char_kills = get_kills($char_id);
    if ($char_kills < 0) {
        // If the character doesn't have any kills, shortcut the levelling process.
        return false;
    } else {
        $char_obj = new Player($char_id);
        $username = $char_obj->name();
        $char_level = $char_obj->level();
        if ($auto_level && $char_obj->isAdmin()) {
            // If the character is an admin, do not auto-level them.
            return false;
        } else {
            // For normal characters, do auto-level them.
            // Check required values:
            $nextLevel = $char_level + 1;
            $required_kills = required_kills_to_level($char_level);
            // Have to be under the max level and have enough kills.
            $level_up_possible = $nextLevel <= $max_level && $char_kills >= $required_kills;
            if ($level_up_possible) {
                // ****** Perform the level up actions ****** //
                // Explicitly call for the special case of kill changing to prevent an infinite loop.
                $userKills = change_kills($char_id, -1 * $required_kills, $auto_level_check = false);
                $userLevel = addLevel($char_id, 1);
                change_strength($char_id, $stat_value_to_add);
                change_speed($char_id, $stat_value_to_add);
                change_stamina($char_id, $stat_value_to_add);
                change_karma($char_id, 1);
                // Only add 1 to karma via levelling.
                change_ki($char_id, 50);
                // Add 50 ki points via levelling.
                addHealth($char_id, $health_to_add);
                addTurns($char_id, $turns_to_give);
                // Send a level-up message, for those times when auto-levelling happens.
                send_event($char_id, $char_id, "You levelled up!  Your strength raised by {$stat_value_to_add}, speed by {$stat_value_to_add}, stamina by {$stat_value_to_add}, Karma by 1, and your Ki raised 50!  You gained some health and turns as well!  You are now a level {$userLevel} ninja!  Go kill some stuff.");
                return true;
            } else {
                return false;
            }
        }
    }
}
Пример #2
0
     return $error;
 }
 // Returns an error if the requirements for getting a dim mak aren't met.
 function dim_mak_reqs($char_obj, $turn_req, $str_req)
 {
     $error = null;
     if ($char_obj->turns() < $turn_req) {
         $error = "You don't have enough turns to get a Dim Mak.";
     }
     if ($char_obj->strength() < $str_req) {
         $error = "You don't have enough strength to get a Dim Mak.";
     }
     return $error;
 }
 // Check that they can do one action or another.
 $max_level = maximum_level();
 // For display in the template.
 $nextLevel = $userLevel + 1;
 $class_change_requirement_error = class_change_reqs($char, $class_change_cost);
 $dim_mak_requirement_error = dim_mak_reqs($char, $dim_mak_cost, $dim_mak_strength_requirement);
 // DIM MAK BUY
 if (!$dim_mak_requirement_error && $dimmak_sequence == 2) {
     // *** Start of Dim Mak Code, A dim mak didn't error and was requested. ***
     $char_turns = $char->changeTurns(-1 * $dim_mak_cost);
     add_item($char_id, 'dimmak', 1);
 }
 // *** End of Dim Mak Code. ***
 // Class Change Buy
 $class_change_error = null;
 if ($classChangeSequence == 2 && $current_class_untrusted == $userClass && $destination_class_identity) {
     // Class change requested, not a page refresh, and requested class is existant.