示例#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
                }
                $target_msg = "You have killed {$attacker} in combat and taken {$loot} gold.";
                $attacker_msg = "DEATH: You've been killed by {$target} and lost {$loot} gold!";
                sendMessage($attacker, $target, $target_msg);
                sendMessage($target, $attacker, $attacker_msg);
            }
        }
        // *** END MAIN ATTACK AND DUELING SECTION ***
    }
    if ($loot) {
        add_gold(get_char_id($victor), $loot);
        subtract_gold(get_char_id($loser), $loot);
    }
    if ($rounds > 4) {
        // Even matched battle!  Reward some ki to the attacker, even if they die.
        change_ki($attacker_id, 1);
        // Award Ki.
        $rewarded_ki = 1;
    }
}
// *** Take away at least one turn even on attacks that fail. ***
if ($turns_to_take < 1) {
    $turns_to_take = 1;
}
$ending_turns = subtractTurns($attacker_id, $turns_to_take);
//  ***  START ACTION OVER AGAIN SECTION ***
$attack_again = false;
if (isset($target)) {
    $attacker_health_snapshot = getHealth($attacker_id);
    $defender_health_snapshot = getHealth($target_id);
    if ($AttackLegal && $attacker_health_snapshot > 0 && $defender_health_snapshot > 0) {