}
         }
     }
 }
 if ($op == "fight") {
     $battle = true;
 }
 if ($op == "run") {
     output("`\$Your pride prevents you from running from this conflict!`0");
     $op = "fight";
     $battle = true;
 }
 if ($battle) {
     require_once "lib/battle-skills.php";
     require_once "lib/extended-battle.php";
     suspend_buffs('allowintrain', "`&Your pride prevents you from using extra abilities during the fight!`0`n");
     suspend_companions("allowintrain");
     if (!$victory) {
         require_once "battle.php";
     }
     if ($victory) {
         $badguy['creaturelose'] = substitute_array($badguy['creaturelose']);
         output_notl("`b`&");
         output($badguy['creaturelose']);
         output_notl("`0`b`n");
         output("`b`\$You have defeated %s!`0`b`n", $badguy['creaturename']);
         $session['user']['level']++;
         $session['user']['maxhitpoints'] += 10;
         $session['user']['soulpoints'] += 5;
         $session['user']['attack']++;
         $session['user']['defense']++;
function dwellings_pvp_run()
{
    global $session, $badguy, $pvptime, $pvptimeout, $options;
    $pvptime = getsetting("pvptimeout", 600);
    $pvptimeout = date("Y-m-d H:i:s", strtotime("-{$pvptime} seconds"));
    $last = date("Y-m-d H:i:s", strtotime("-" . getsetting("LOGINTIMEOUT", 900) . " sec"));
    $ac = db_prefix("accounts");
    $mu = db_prefix("module_userprefs");
    $dw = db_prefix("dwellings");
    $cl = db_prefix("clans");
    $op = httpget('op');
    $dwid = httpget('dwid');
    page_header("Dwellings PvP");
    if ($op != "fight1" && $op != "fight") {
        require_once "modules/dwellings_pvp/run/case_{$op}.php";
    }
    if ($op == "fight1") {
        $name = rawurldecode(httpget('name'));
        require_once "modules/dwellings/lib.php";
        if (is_numeric($name)) {
            $name = getlogin($name);
        }
        require_once "lib/pvpsupport.php";
        $badguy = setup_target($name);
        require_once "lib/battle-skills.php";
        suspend_buffs("allowinpvp", "`&The gods prevent you from using any special abilities!`0");
        $session['user']['badguy'] = createstring($badguy);
        $session['user']['playerfights']--;
        $op = "fight";
    }
    if ($op == "fight") {
        $options['type'] = 'pvp';
        $battle = true;
    }
    if ($battle) {
        include "battle.php";
        if ($victory) {
            $killedin = sprintf("%s Dwellings", $session['user']['location']);
            require_once "lib/pvpsupport.php";
            pvpvictory($badguy, $killedin, $options);
            addnews("`4%s`3 defeated `4%s`3 while they were sleeping in their Dwelling.", $session['user']['name'], $badguy['creaturename']);
            $badguy = array();
            unsuspend_buffs("allowinpvp", "`&The gods have restored your special abilities!`0");
            addnav("Leave");
            addnav("Hamlet Registry", "runmodule.php?module=dwellings&op=list&ref=hamlet");
        } elseif ($defeat) {
            $killedin = sprintf("%s Dwellings", $session['user']['location']);
            require_once "lib/taunt.php";
            $taunt = select_taunt_array();
            require_once "lib/pvpsupport.php";
            pvpdefeat($badguy, $killedin, $taunt, $options);
            unsuspend_buffs("allowinpvp", "`&The gods have restored your special abilities!`0");
            addnews("`4%s`3 was defeated while attacking `4%s`3 as they were sleeping in their Dwelling.`n%s", $session['user']['name'], $badguy['creaturename'], $taunt);
            output("`n`n`&You are sure that someone, sooner or later, will stumble over your corpse and return it to %s for you.", $session['user']['location']);
            addnav("Return to the Shades", "shades.php");
        } else {
            $script = "runmodule.php?module=dwellings_pvp&op=fight";
            require_once "lib/fightnav.php";
            fightnav(false, false, $script);
        }
    }
    page_footer();
}
    }
}
$victory = false;
$defeat = false;
if ($enemycounter > 0) {
    output("`\$`c`b~ ~ ~ Fight ~ ~ ~`b`c`0");
    modulehook("battle", $enemies);
    foreach ($enemies as $index => $badguy) {
        if ($badguy['creaturehealth'] > 0 && $session['user']['hitpoints'] > 0) {
            output("`@You have encountered `^%s`@ which lunges at you with `%%s`@!`0`n", $badguy['creaturename'], $badguy['creatureweapon']);
        }
    }
    output_notl("`n");
    show_enemies($enemies);
}
suspend_buffs($options['type'] == 'pvp' ? "allowinpvp" : false);
suspend_companions($options['type'] == 'pvp' ? "allowinpvp" : false);
// Now that the bufflist is sane, see if we should add in the bodyguard.
$inn = (int) httpget('inn');
if ($options['type'] == 'pvp' && $inn == 1) {
    apply_bodyguard($badguy['bodyguardlevel']);
}
$surprised = false;
if ($op != "run" && $op != "fight" && $op != "newtarget") {
    if (count($enemies) > 1) {
        $surprised = true;
        output("`b`^YOUR ENEMIES`\$ surprise you and get the first round of attack!`0`b`n`n");
    } else {
        // Let's try this instead.Biggest change is that it adds possibility of
        // being surprised to all fights.
        if (!array_key_exists('didsurprise', $options) || !$options['didsurprise']) {
     } else {
         villagenav();
     }
 } elseif ($session['user']['dragonkills'] >= get_module_setting('dkenter')) {
     output("`2You enter the Abandoned Castle, as you do the door slams behind you.");
     output("Try as you may the door won't budge!  Looks like you are going to have to find ");
     output("another way out of this place!`n");
     output("You look around, and in the dim light you see that the castle's narrow passage is ");
     output("littered with junk and remains of past visitors.`n");
     if ($session['user']['hashorse'] > 0) {
         global $playermount;
         output("Too bad your %s couldn't come in with you, now you are all alone.`n", $playermount['mountname']);
     }
     $skill = "";
     require_once "lib/battle-skills.php";
     suspend_buffs('allowintrain', "This place feels strange... it's draining any buffs you have ... they are unusable.`n`n");
     $locale = 6;
     $umazeturn = 0;
     set_module_pref("mazeturn", 0);
     //they have to do an unfinished maze.
     if ($maze == "") {
         //maze generation array.  Mazes are premade.
         //as you add mazes make sure you change the e_rand value to match your quantity of mazes
         switch (e_rand(1, 45)) {
             case 1:
                 //author: Lonnyl
                 //title: uno
                 $maze = array(j, d, d, d, b, c, k, o, d, d, k, f, d, b, d, a, n, i, d, b, d, e, i, d, c, k, m, j, d, p, g, o, e, o, b, k, i, k, g, j, n, f, k, g, o, e, g, j, e, i, a, b, a, h, g, j, h, i, h, i, n, g, i, e, j, e, i, d, k, j, d, d, h, l, i, h, g, j, d, h, g, o, b, d, c, d, d, h, i, b, d, c, k, g, j, d, b, d, k, j, c, d, d, e, i, a, d, a, d, e, i, d, d, n, i, k, i, k, i, d, e, o, d, d, b, b, a, k, i, d, d, h, o, d, d, h, m, z, i, d, d, d, n);
                 break;
             case 2:
                 //author: Kain