function staminatest_run()
{
    global $session;
    page_header("Stamina Testing");
    switch (httpget("op")) {
        case "start":
            output("Testing Testing!");
            break;
        case "add":
            output("Attempting to install an action called Sexins, with these parameters:`n`nStarting and Maximum costs: 500`nMinimum cost: 200`nReps for a Reduction: 20`nReduction: 10`n");
            install_action("Sexins", array("maxcost" => 25000, "mincost" => 10000, "expperrep" => 100, "expforlvl" => 1000, "costreduction" => 10, "dkpct" => 2.5));
            break;
        case "process":
            output("Processing the Sexins action");
            process_action("Sexins");
            break;
        case "newday":
            output("Processing a New Day");
            stamina_process_newday();
            break;
        case "buff":
            output("Applying a stamina buff to Sexins for the current user, for 20 rounds, reducing action cost to half.");
            apply_stamina_buff('ultra-sexy-buff-for-sexins', array("name" => "Ultra Sexy Buff for Sexins", "action" => "Sexins", "costmod" => 0.5, "expmod" => 0.8, "rounds" => 5, "roundmsg" => "Round Message!", "wearoffmsg" => "Wearoff Message!"));
            output("Also applying a Stamina Class buff to all Hunting actions, reducing their cost to half for twenty rounds.");
            apply_stamina_buff('huntclasstest', array("name" => "Hunting Class test buff", "class" => "Hunting", "costmod" => 0.5, "expmod" => 0.8, "rounds" => 20, "roundmsg" => "Round Message!", "wearoffmsg" => "Wearoff Message!"));
            break;
        case "get":
            $thingtodebug = get_player_action("Sexins");
            debug($thingtodebug);
            break;
        case "uninstall":
            output("Uninstalling the Sexins action, deleting all actions entries and associated buffs");
            uninstall_action("Sexins");
            break;
        case "dragonkill":
            output("Processing a Dragon Kill");
            stamina_process_dragonkill();
            break;
        case "calcbuffs":
            output("Calculating Buffs");
            stamina_calculate_buffed_cost("Sexins");
            break;
        case "calcexp":
            output("Calculating Buffed EXP");
            stamina_calculate_buffed_exp("Sexins");
            break;
    }
    addnav("Install an action called Sexins", "runmodule.php?module=staminatest&op=add");
    addnav("Uninstall", "runmodule.php?module=staminatest&op=uninstall");
    addnav("Process the Sexins Action for the current user", "runmodule.php?module=staminatest&op=process");
    addnav("Process newday", "runmodule.php?module=staminatest&op=newday");
    addnav("Add a buff", "runmodule.php?module=staminatest&op=buff");
    addnav("Get Stamina", "runmodule.php?module=staminatest&op=get");
    addnav("Process a Dragon Kill", "runmodule.php?module=staminatest&op=dragonkill");
    addnav("Calculate Buffed Cost", "runmodule.php?module=staminatest&op=calcbuffs");
    addnav("Calculate Buffed exp", "runmodule.php?module=staminatest&op=calcexp");
    addnav("Back to the Grotto", "superuser.php");
    page_footer();
    return true;
}
function scrapbots_scavenge($reps = 1)
{
    global $session;
    //todo: hook in Stamina system, factor in remaining Stamina and experience
    //Get the player's Scrap
    $playerscrap = scrapbots_get_player_scrap();
    for ($i = 0; $i < $reps; $i++) {
        //Actually, let's just put in a random chance that the player will trip and impale themselves on a rusty bit of pointy scrap
        require_once "modules/staminasystem/lib/lib.php";
        $return = process_action("Scavenging for Scrap");
        if ($return['lvlinfo']['levelledup'] == true) {
            output("`n`c`b`0You gained a level in Scavenging for Scrap!  You are now level %s!  This action will cost fewer Stamina points now, so you can Scavenge more each day!`b`c`n", $return['lvlinfo']['newlvl']);
        }
        $stamina = get_stamina();
        $failchance = e_rand(1, 100);
        if ($stamina < 100) {
            output("`4You're getting tired.`0  Clambering around on a big pile of pointy, rusted scrap metal while you're half-asleep carries certain risks.`n");
        }
        if ($failchance > $stamina) {
            output("`\$This fact is driven home to you as you slip on an oily bit of sheet metal and fall head-first into the pile!`nYou `blose`b some hitpoints!`n`0");
            $hploss = e_rand(0, floor($session['user']['maxhitpoints'] / 2));
            $session['user']['hitpoints'] -= $hploss;
            if ($session['user']['hitpoints'] <= 0) {
                output("`\$You begin to feel a bit dizzy from the lack of blood.  Before you know it, you've collapsed, and the friendly local Robots have helped themselves to your cash and summoned the Retraining Personnel!`n");
                $session['user']['alive'] = false;
                $session['user']['gold'] = 0;
                addnav("Whoops.");
                addnav("Daily News", "news.php");
                blocknav("runmodule.php?module=scrapbots&scavenge=1");
                blocknav("runmodule.php?module=scrapbots&scavenge=10");
                blocknav("village.php");
                break;
            }
        }
        //dummy vals for now
        $normalchance = 100;
        $rarechance = 66;
        $veryrarechance = 99;
        $scrapnames = scrapbots_scrapnames();
        $scavengerarity = e_rand(1, 99);
        if ($scavengerarity <= $normalchance) {
            //award normal object
            $award = e_rand(0, 15);
            $playerscrap['data']['normalitems'][$award] += 1;
            output("`0You rummage through the scrap pile and come up with a `5%s`0.`n", $scrapnames['normalitems'][$award]);
        } elseif ($scavengerarity > $normalchance && $scavengerarity <= $rarechance) {
            $award = e_rand(0, 12);
            $playerscrap['data']['rareitems'][$award] += 1;
            output("`0You find a rare item!  A pretty nice `5%s`0.`n", $scrapnames['rareitems'][$award]);
        } elseif ($scavengerarity > $rarechance) {
            //award very rare item
            $award = e_rand(0, 3);
            $playerscrap['data']['veryrareitems'][$award] += 1;
            output("`0You find a very rare item!  This `5%s`0 looks like it's in good nick!`n", $scrapnames['veryrareitems'][$award]);
        }
    }
    set_module_pref("scrap", serialize($playerscrap), "scrapbots");
    return;
}
                 }
                 if (!$qleft) {
                     $qleft = "no";
                 }
                 output("You have %s %s left.`n`n", $qleft, $iname);
             }
         }
     }
 }
 if ($interrupt) {
     break;
 }
 foreach ($actions as $action => $reps) {
     output_notl("%s`n`n", $house['data']['buildjobs'][$job]['jobs'][$subjob]['desc']);
     for ($i = 0; $i < $reps; $i++) {
         $actinfo = process_action($action);
         if ($actinfo['lvlinfo']['levelledup']) {
             output("`n`c`b`0You gained a level in %s!  You are now level %s!  This action will cost fewer Stamina points now.`b`c`n", $action, $actinfo['lvlinfo']['newlvl']);
         }
     }
 }
 //now update the job counter, add our name to the Helpers list and show how many more times we must do this
 $jobtoperform['done'] += 1;
 //check to see if the job has been done
 if ($jobtoperform['done'] >= $jobtoperform['req']) {
     $jobtoperform['completed'] = 1;
     $house['data']['buildjobs'][$job]['jobs'][$subjob] = $jobtoperform;
     //now check to see if all jobs have been done
     $finished_subjobs = 1;
     foreach ($house['data']['buildjobs'][$job]['jobs'] as $key => $vals) {
         if (!$vals['completed']) {
function staminacorecombat_run()
{
    global $session;
    $op = httpget('op');
    if ($op == "search") {
        $return = process_action("Hunting - Normal");
        if ($return['lvlinfo']['levelledup'] == true) {
            redirect("forest.php?op=search&levelup=normal");
        } else {
            redirect("forest.php?op=search");
        }
    }
    if ($op == "slum") {
        $return = process_action("Hunting - Easy Fights");
        if ($return['lvlinfo']['levelledup'] == true) {
            redirect("forest.php?op=search&levelup=easy");
        } else {
            redirect("forest.php?op=search&type=slum");
        }
    }
    if ($op == "thrill") {
        $return = process_action("Hunting - Big Trouble");
        if ($return['lvlinfo']['levelledup'] == true) {
            redirect("forest.php?op=search&levelup=hard");
        } else {
            redirect("forest.php?op=search&type=thrill");
        }
    }
    if ($op == "suicide") {
        $return = process_action("Hunting - Suicidal");
        if ($return['lvlinfo']['levelledup'] == true) {
            redirect("forest.php?op=search&levelup=suicide");
        } else {
            redirect("forest.php?op=search&type=suicide");
        }
    }
    if ($op == "fight") {
        process_action("Fighting - Standard");
        redirect("forest.php?op=fight");
    }
    if ($op == "run") {
        process_action("Running Away");
        redirect("forest.php?op=fight");
    }
    page_footer();
    return $args;
}
Ejemplo n.º 5
0
} else {
    function strtoupper_utf($str)
    {
        return strtoupper($str);
    }
    function strtolower_utf($str)
    {
        return strtolower($str);
    }
    function strlen_utf($str)
    {
        return strlen($str);
    }
    function substr_utf($str, $from, $to)
    {
        return substr($str, $from, $to);
    }
}
///
///
/// main
///
///
error_reporting(E_ALL);
ini_set('display_errors', 'on');
remove_magic_quotes();
init_session();
init_default_languages();
process_action(get('action'));
# phpFolding plugin _most_ recommended, http://www.vim.org/scripts/script.php?script_id=1623
# vim: set tw=120 ts=4 sts=4 sw=4 et : #
function meatsystem_run()
{
    global $session;
    require_once "modules/staminasystem/lib/lib.php";
    page_header("Meat!");
    addnav("Meat Skills");
    $from = httpget('from');
    switch (httpget('op')) {
        case "devour":
            //special ability for Zombies only - Zombies can eat raw meat, so we're giving them the ability to simply devour the carcass where it lies.
            $carcasses = unserialize(get_module_pref("carcasses"));
            if (!is_array($carcasses)) {
                $carcasses = array();
            }
            debug($carcasses);
            foreach ($carcasses as $carcassnum => $creatureid) {
                $sql = "SELECT creaturename FROM " . db_prefix("creatures") . " WHERE creatureid = " . $creatureid . " ";
                $result = db_query_cached($sql, "creaturename-" . $creatureid, 86400);
                $creature = db_fetch_assoc($result);
                output("Giving in to your primal urges, you lean down and begin ripping meat from the still-twitching %s with your teeth.`n`n", $creature['creaturename']);
                $meat1 = get_module_objpref("creatures", $creatureid, "meat1");
                $meat2 = get_module_objpref("creatures", $creatureid, "meat2");
                $meat3 = get_module_objpref("creatures", $creatureid, "meat3");
                for ($i = 0; $i < $meat1; $i++) {
                    increment_module_pref("nutrition", 1, "staminafood");
                    increment_module_pref("fat", 3, "staminafood");
                    increment_module_pref("fullness", 1, "staminafood");
                    addstamina(1000);
                }
                for ($i = 0; $i < $meat2; $i++) {
                    increment_module_pref("nutrition", 2, "staminafood");
                    increment_module_pref("fat", 2, "staminafood");
                    increment_module_pref("fullness", 1, "staminafood");
                    addstamina(2000);
                }
                for ($i = 0; $i < $meat3; $i++) {
                    increment_module_pref("nutrition", 3, "staminafood");
                    increment_module_pref("fat", 1, "staminafood");
                    increment_module_pref("fullness", 1, "staminafood");
                    addstamina(5000);
                }
                output("For the record, and since it's nice to know these things even if you're too busy tearing cartilage and muscle from the bone to really pay attention to them, in this meal you have eaten %s bite's-worth of Crap Meat, %s bite's-worth of Half-Decent Meat, and %s bite's-worth of Tasty Meat.`n", $meat1, $meat2, $meat3);
                $full = get_module_pref("fullness", "staminafood");
                if ($full < 0) {
                    output("You still feel as though you haven't eaten in days.`n`n");
                }
                if ($full >= 0 && $full < 50) {
                    output("You feel a little less hungry.`n`n");
                }
                if ($full >= 50 && $full < 100) {
                    output("You still feel as though you've got room for more!`n`n");
                }
                if ($full >= 100) {
                    output("You're stuffed!  You feel as though you can't possibly eat anything more today.`n`n");
                }
                unset($carcasses[$carcassnum]);
                set_module_pref("carcasses", serialize($carcasses));
            }
            break;
        case "clean":
            $creatureid = httpget('creatureid');
            $carcass = httpget('carcass');
            $meat1 = get_module_objpref("creatures", $creatureid, "meat1");
            $meat2 = get_module_objpref("creatures", $creatureid, "meat2");
            $meat3 = get_module_objpref("creatures", $creatureid, "meat3");
            $amber = get_stamina();
            $return = process_action("Cleaning the Carcass");
            if ($return['lvlinfo']['levelledup'] == true) {
                output("`n`c`b`0You gained a level in Cleaning Carcasses!  You are now level %s!  This action will cost fewer Stamina points now, so you can butcher more creatures each day!`b`c`n", $return['lvlinfo']['newlvl']);
            }
            $failchance = e_rand(0, 100);
            if ($failchance > $amber) {
                //failure - the nice meat gets turned into Crap Meat
                $meat1 += $meat2;
                $meat1 += $meat3;
                output("`4You sit down to clean the carcass.  Your exhausted, clumsy incisions make a mockery of the choicest cuts - what is left over can only be described as Crap Meat.  %s bite's-worth, to be precise.  It looks like it was hacked into chunks by a blind woodsman.", $meat1);
                //todo
                for ($i = 0; $i < $meat1; $i++) {
                    give_item("meat_low", false, false, true);
                }
                load_inventory();
                $carcasses = unserialize(get_module_pref("carcasses"));
                unset($carcasses[$carcass]);
                $carcasses = array_values($carcasses);
                set_module_pref("carcasses", serialize($carcasses));
            } else {
                //success - all meat is sorted
                output("You spend a few minutes up to your elbows in gore, and getting rather hungry.`n");
                if ($meat1 > 0) {
                    output("You tear off enough to make %s rough bite's-worth of what the locals affectionately call Crap Meat.  It's mostly wobbling chunks of stinking yellow fat, intermingled with the occasional squirmy tendon.`n", $meat1);
                }
                if ($meat2 > 0) {
                    output("You make swift work of the fattier muscle, and before too long you have %s rough bite's-worth of Half-Decent Meat.`n", $meat2);
                }
                if ($meat3 > 0) {
                    output("The red, tender slivers of muscle slide easily from the bone, and you wind up with %s rough bite's-worth of Tasty Meat.`n", $meat3);
                }
                //todo
                for ($i = 0; $i < $meat1; $i++) {
                    give_item("meat_low", false, false, true);
                }
                for ($i = 0; $i < $meat2; $i++) {
                    give_item("meat_medium", false, false, true);
                }
                for ($i = 0; $i < $meat3; $i++) {
                    give_item("meat_high", false, false, true);
                }
                load_inventory();
                $carcasses = unserialize(get_module_pref("carcasses"));
                unset($carcasses[$carcass]);
                $carcasses = array_values($carcasses);
                set_module_pref("carcasses", serialize($carcasses));
                $pmeat1 = has_item("meat_low");
                $pmeat2 = has_item("meat_medium");
                $pmeat3 = has_item("meat_high");
                if (($pmeat1 || $pmeat2 || $pmeat3) && $session['user']['race'] != "Robot") {
                    if (get_module_pref("fullness", "staminafood") < 100) {
                        $cookcost = stamina_getdisplaycost("Cooking");
                        addnav(array("Cook up some meat (`Q%s%%`0)", $cookcost), "runmodule.php?module=meatsystem&op=cook&from=" . $from);
                    } else {
                        addnav("You're too full to cook, let alone eat", "");
                    }
                }
            }
            break;
        case "cook":
            $pmeat1qty = has_item_quantity("meat_low");
            $pmeat2qty = has_item_quantity("meat_medium");
            $pmeat3qty = has_item_quantity("meat_high");
            output("You whip out your camping stove.  It's time to cook!`n`nWhat will you put in the pan?  You can fit up to 20 bite's-worth of meat in there.  Right now you have %s bite's-worth of Crap Meat, %s bite's-worth of Half-Decent Meat, and %s bite's-worth of Tasty Meat.`n`n", $pmeat1qty, $pmeat2qty, $pmeat3qty);
            rawoutput("<form action='runmodule.php?module=meatsystem&op=cookfinal&from=" . $from . "' method='POST'>");
            rawoutput("Put in <input name='meat1' width='2' value='0'> bite's-worth of Crap Meat.<br />");
            rawoutput("Put in <input name='meat2' width='2' value='0'> bite's-worth of Half-Decent Meat.<br />");
            rawoutput("Put in <input name='meat3' width='2' value='0'> bite's-worth of Tasty Meat.<br />");
            rawoutput("<input type='submit' class='button' value='" . translate_inline("Cook!") . "'>");
            rawoutput("</form>");
            addnav("", "runmodule.php?module=meatsystem&op=cookfinal&from=" . $from);
            break;
        case "cookfinal":
            $pmeat1qty = has_item_quantity("meat_low");
            $pmeat2qty = has_item_quantity("meat_medium");
            $pmeat3qty = has_item_quantity("meat_high");
            $meat1 = httppost("meat1");
            $meat2 = httppost("meat2");
            $meat3 = httppost("meat3");
            //check for the dumbass player cooking meat that they don't have
            if ($meat1 > $pmeat1qty || $meat2 > $pmeat2qty || $meat3 > $pmeat3qty) {
                output("You don't `ihave`i that much meat!`n`n");
                addnav("Whoops");
                addnav("Sorry, I forgot how to count for a second there.  Let's try this again.", "runmodule.php?module=meatsystem&op=cook&from=" . $from);
                break;
            }
            //check for the dumbass player inputting a negative number
            if ($meat1 < 0 || $meat2 < 0 || $meat3 < 0) {
                page_header("Either taking vegetarianism to whole new levels, or trying to grow meat from an empty pan");
                output("You want to cook `inegative`i meat?  How very Zen of you.`n`n");
                addnav("You sneaky bugger");
                addnav("Abandon your efforts to produce the opposite of meat and try again, pretending that you weren't just trying to cheat.", "runmodule.php?module=meatsystem&op=cook&from=" . $from);
                break;
            }
            //check for the dumbass player trying to put too much meat in the pan
            $totalmeat = $meat1 + $meat2 + $meat3;
            if ($totalmeat > 20) {
                output("Your pan can't hold that much meat, pal.`n`n");
                addnav("Whoops");
                addnav("Try again, without filling the pan up so much", "runmodule.php?module=meatsystem&op=cook&from=" . $from);
                break;
            }
            //check for the dumbass player trying to cook no meat at all
            $totalmeat = $meat1 + $meat2 + $meat3;
            if ($totalmeat == 0) {
                output("You start the process of cooking up your tasty meat.  After a few minutes of poking around in your pan, growing hungrier by the second, you realise that you've forgotten something.`n`n");
                addnav("Whoops");
                addnav("Try again, with meat this time", "runmodule.php?module=meatsystem&op=cook&from=" . $from);
                break;
            }
            //Stamina interaction, including consequences and level-up details.
            $amber = get_stamina();
            $return = process_action("Cooking");
            if ($return['lvlinfo']['levelledup'] == true) {
                output("`n`c`b`0You gained a level in Cooking!  You are now level %s!  This action will cost fewer Stamina points now, so you can cook more tasty meals each day!`b`c`n", $return['lvlinfo']['newlvl']);
            }
            $failchance = e_rand(0, 100);
            if ($failchance > $amber) {
                output("`4You put your meat into the pan, and sit down to stir-fry it.  The hypnotic motion and white-noise sizzling, combined with your tiredness, sends you staring into space.  While your concentration is impaired, the meat bursts into flames.  You jerk back into awareness, and look down sadly at the flaming chunks.  Bummer.");
                for ($i = 0; $i < $meat1; $i++) {
                    delete_item(has_item("meat_low"));
                }
                for ($i = 0; $i < $meat2; $i++) {
                    delete_item(has_item("meat_medium"));
                }
                for ($i = 0; $i < $meat3; $i++) {
                    delete_item(has_item("meat_high"));
                }
                break;
            }
            //we can now assume that the player is not some sort of cheating reprobate, or trying to cook while dog-tired, and do some cooking!
            for ($i = 0; $i < $meat1; $i++) {
                increment_module_pref("nutrition", 1, "staminafood");
                increment_module_pref("fat", 3, "staminafood");
                increment_module_pref("fullness", 1, "staminafood");
                delete_item(has_item("meat_low"));
                addstamina(1000);
            }
            for ($i = 0; $i < $meat2; $i++) {
                increment_module_pref("nutrition", 2, "staminafood");
                increment_module_pref("fat", 2, "staminafood");
                increment_module_pref("fullness", 1, "staminafood");
                delete_item(has_item("meat_medium"));
                addstamina(2000);
            }
            for ($i = 0; $i < $meat3; $i++) {
                increment_module_pref("nutrition", 3, "staminafood");
                increment_module_pref("fat", 1, "staminafood");
                increment_module_pref("fullness", 1, "staminafood");
                delete_item(has_item("meat_high"));
                addstamina(5000);
            }
            output("You fry up your lovely meaty loveliness, and sit down to eat.  You gain some Stamina!`n`n");
            $full = get_module_pref("fullness", "staminafood");
            if ($full < 0) {
                output("You still feel as though you haven't eaten in days.`n`n");
            }
            if ($full >= 0 && $full < 50) {
                output("You feel a little less hungry.`n`n");
            }
            if ($full >= 50 && $full < 100) {
                output("You still feel as though you've got room for more!`n`n");
            }
            if ($full >= 100) {
                output("You're stuffed!  You feel as though you can't possibly eat anything more today.`n`n");
            }
            break;
    }
    $carcasses = unserialize(get_module_pref("carcasses"));
    if (!is_array($carcasses)) {
        $carcasses = array();
    }
    if (count($carcasses) > 0) {
        output("You look at the spoils of your most recent battle.  They lie bloodied and broken on the ground.  What will you do with them?");
        foreach ($carcasses as $carcassnum => $creatureid) {
            $sql = "SELECT creaturename FROM " . db_prefix("creatures") . " WHERE creatureid = " . $creatureid . " ";
            $result = db_query_cached($sql, "creaturename-" . $creatureid, 86400);
            $creature = db_fetch_assoc($result);
            $cleancost = stamina_getdisplaycost("Cleaning the Carcass");
            addnav(array("Clean the carcass of %s (`Q%s%%`0)", $creature['creaturename'], $cleancost), "runmodule.php?module=meatsystem&op=clean&creatureid=" . $creatureid . "&carcass=" . $carcassnum . "&from=" . $from);
        }
    } else {
        if (httpget('op') != "cook" && httpget('op') != "cookfinal") {
            output("Now only bloody bones lie strewn around the area.`n`n");
        }
    }
    addnav("Ah, screw it.");
    if ($from == "forest") {
        addnav("Return to the Jungle", "forest.php");
    } else {
        if ($from == "world") {
            addnav("Return to the World Map", "runmodule.php?module=worldmapen&op=continue");
        }
    }
    page_footer();
    return true;
}
function meatschool_run()
{
    global $session;
    page_header("Maiko's Cookery Academy");
    switch (httpget('op')) {
        case "start":
            if (get_module_pref("meatsmith", "meatsystem") == 0) {
                //this is the player's first trip to the Meat School
                output("\"`%Don't worry, it won't feel a thing!`0\"`n`nThe voice comes through confidently - one that's clearly used to carrying across a room full of students.  A teacher's voice.  You step into the hall.`n`nTwenty or so students sit on slightly rickety-looking chairs inside, facing a raised platform.  You barely have time to register the petite, smiling KittyMorph woman before a loud `iBOOM-ch-KA`i draws your attention to the captive bolt pistol in her hand, and the cow-sized, green-furred beast that is at this very moment falling to the floor with a bass-heavy `ithump`i.  Several students squirm in their seats.`n`nThe teacher looks in your direction, and gives you a smile as she puts down the bolt pistol and picks up a pair of razor-sharp knives.  \"`%A new recruit!  I'll bring you up to speed real quick - I'm Maiko, and today we're learning how to cook Bewilderbeest steaks.  From scratch!  Come in, sit down, the first lesson's free!`0\"`n`nYou nervously make your way to a chair and take a seat.  \"`%James, tell me why it's important to begin the bleeding process right away.`0\"`n`nA sick-looking youth stutters a reply.  \"S-s-so it doesn't wake up?\"`n`n\"`%No.  No, if you've kept your gun looked after and done the stunning properly, it won't wake up from that.  The stunning pretty well destroys the forebrain - the animal's alive only in a very clinical sense of the term.  In every sense that matters, to you or to it, it's dead.  No, we start the bleeding process straight away because the blood pressure increases the longer we leave it, and that can rupture blood vessels, and cause muscular haemorrhages - which just makes the meat spoil faster.  Also, when you're out killing monsters in the jungle, if you don't get the meat from them straight away, something's apt to take the carcass the moment you turn your back, be it Midgets or other monsters.  So we butcher the monsters the moment they're unconscious, right?  Now, watch as I make the cuts.  First one, down here - and now we pull that out, and if you want to, you can tie a knot in it.  Second one, this way, and then again, and now we reach in and...  One more...  Aah!  There we go.  Hold these for me, James.  And now - see?  Just like that.  Can you see, there, at the back?  Good.  Look here - the meat can sometimes jump around a little bit.  Don't be freaked out, it's not still alive.  That's just the muscle reacting to the air - it's not used to this much oxygen.  See?  This bit in my hand is still twitching around, even though it's not attached to anything.  I'd like to point out as I'm doing this that it won't always be possible to do it so neatly while you're cleaning the animals that tried to kill you - but just do the best you can.  We're only interested in the best cuts, these ones here - the Zombies and Humans will take the other meat, and the Midgets will only take the... well, James, you could probably sell `ithose`i to them.  Now, we'll do a couple more over here, and...  Um... you there, the new recruit, are you okay?  You look a bit, um...`0\"`n`nVarious students turn around to look at you.  \"Fine,\" you squeak.`n`n\"`%Jolly good then - come on, up you come, let's see if you can do this bit.  You'll soon learn to swim if we chuck you in the deep end, eh?`0\"  You gulp, and head up to the platform.  Right into the deep end.`n`nAn hour later, Maiko shakes your hand.  \"`%That was a very successful first lesson!  If you want to gain some experience in field-dressing, cleaning and cooking, I can offer private tuition at ten Requisition per lesson.  But to be honest - you're a natural!`0\"`n`nYou're not entirely sure how to take that.`n`n`c`bYou have gained two new skills!`b`nYou are now at level one in Carcass Cleaning and Cooking!`c");
                require_once "modules/staminasystem/lib/lib.php";
                get_player_action("Cleaning the Carcass");
                get_player_action("Cooking");
                set_module_pref("meatsmith", 1, "meatsystem");
            } else {
                //lessons
                require_once "modules/staminasystem/lib/lib.php";
                $amber = get_stamina();
                if ($amber == 100) {
                    output("Maiko greets you at the door with a wide grin.  \"`%Back for some more training, eh?  Ten Req per lesson, and I keep the meat.  How's that sound?`0\"`n`n`JMaiko, like other teachers in Improbable Island, can help you level up some of your skills.  When you pay to train with Maiko, you'll use as much Stamina in performing your chosen actions as normal, but you'll receive two and a half times the experience.  Higher levels in Cooking and Carcass Cleaning will make these actions cost fewer Stamina points.`n`n`0Will you train with Maiko?`n`n");
                    addnav("Train with Maiko");
                    if ($session['user']['gold'] >= 10) {
                        $cleancost = stamina_getdisplaycost("Cleaning the Carcass");
                        addnav(array("Pay 10 Req for a Carcass Cleaning lesson (`Q%s%%`0)", $cleancost), "runmodule.php?module=meatschool&op=train&train=clean");
                        $cookcost = stamina_getdisplaycost("Cooking");
                        addnav(array("Pay 10 Req for a Cookery lesson (`Q%s%%`0)", $cookcost), "runmodule.php?module=meatschool&op=train&train=cook");
                    } else {
                        addnav("You don't have enough money.  No lessons for you.", "");
                    }
                } else {
                    output("Maiko greets you at the door with a wide grin.  \"`%Back for some more training, eh?  Well, you look half-asleep to me.  Training won't do you any good at all if you're too tired to take it in.  Go and get some rest, or a coffee or something, then we'll talk.`0\"  She shoos you out of the door.");
                }
            }
            addnav("Leave this place");
            addnav("Return to Kittania", "village.php");
            break;
        case "train":
            if (is_module_active("medals")) {
                require_once "modules/medals.php";
                medals_award_medal("maiko_train", "Maiko's Meat School", "This player took lessons at Maiko's Meat School!", "medal_maiko.png");
            }
            $session['user']['gold'] -= 10;
            require_once "modules/staminasystem/lib/lib.php";
            switch (httpget('train')) {
                case "clean":
                    apply_stamina_buff('maikoclean', array("name" => "Maiko\\'s Training", "action" => "Cleaning the Carcass", "costmod" => 1, "expmod" => 2.5, "rounds" => 1, "roundmsg" => "", "wearoffmsg" => ""));
                    output("Maiko shows you a big smile.  \"`%Another butchery lesson!  Great stuff.  Let's get started!`0\"`n`nMaiko grabs her knives and captive bolt pistol, you don your gloves, and the two of you spend the next little while up to your elbows in warm, still-twitching muscle.  Under Maiko's careful watch, her gentle hands occasionally guiding yours to make a difficult cut, you learn one or two things that you didn't know before.");
                    $return = process_action("Cleaning the Carcass");
                    output("You receive %s experience in Cleaning the Carcass.`n`n", $return['exp_earned']);
                    if ($return['lvlinfo']['levelledup'] == true) {
                        output("`c`b`0You gained a level in Cleaning Carcasses!  You are now level %s!  This action will cost fewer Stamina points now, so you can butcher more creatures each day!`b`c`n", $return['lvlinfo']['newlvl']);
                    }
                    break;
                case "cook":
                    apply_stamina_buff('maikocook', array("name" => "Maiko\\'s Training", "action" => "Cooking", "costmod" => 1, "expmod" => 2.5, "rounds" => 1, "roundmsg" => "", "wearoffmsg" => ""));
                    output("Maiko shows you a big smile.  \"`%Another cookery lesson!  Great stuff.  Let's get started!`0\"`n`nMaiko grabs her pans and some ingredients, and you don the 'hilarious' apron Maiko has so thoughtfully provided.  Under Maiko's helpful guidance, you learn one or two things that you didn't know before.");
                    $return = process_action("Cooking");
                    output("You receive %s experience in Cooking.`n`n", $return['exp_earned']);
                    if ($return['lvlinfo']['levelledup'] == true) {
                        output("`n`c`b`0You gained a level in Cooking!  You are now level %s!  This action will cost fewer Stamina points now, so you can cook more tasty meals each day!`b`c`n", $return['lvlinfo']['newlvl']);
                    }
                    break;
            }
            $amber = get_stamina();
            if ($amber == 100) {
                addnav("More Training");
                if ($session['user']['gold'] >= 10) {
                    $cleancost = stamina_getdisplaycost("Cleaning the Carcass");
                    addnav(array("Pay 10 Req for a Carcass Cleaning lesson (`Q%s%%`0)", $cleancost), "runmodule.php?module=meatschool&op=train&train=clean");
                    $cookcost = stamina_getdisplaycost("Cooking");
                    addnav(array("Pay 10 Req for a Cookery lesson (`Q%s%%`0)", $cookcost), "runmodule.php?module=meatschool&op=train&train=cook");
                } else {
                    addnav("You don't have enough money.  No more lessons for you.", "");
                }
            } else {
                output("Maiko shows you a grin.  \"`%Well, that was a lot of fun.  But I can see you're getting tired - no point in training any more today, I'm afraid.`0\"  She shoos you out of the door.");
            }
            addnav("Leave this place");
            addnav("Return to Kittania", "village.php");
            break;
    }
    page_footer();
    return true;
}
     } else {
         output("The name of your room is too long.  You've got 55 characters to play with, including colour codes.  Let's give that another go.`n`n");
         rawoutput("<form action='runmodule.php?module=improbablehousing&op=decorate&subop=change&hid={$hid}&rid={$rid}' method='POST'><input name='name' id='name' value=\"{$newname}\"><br /><textarea name='newdesc' id='newdesc'>{$newdesc}</textarea><input type=submit>");
         addnav("", "runmodule.php?module=improbablehousing&op=decorate&subop=change&hid={$hid}&rid={$rid}");
     }
     break;
 case "confirm":
     output("Okay!  Your new decoration description is set.  Now you'd better get decorating!`n`n");
     $house['data']['rooms'][$rid]['dec'] = $house['data']['rooms'][$rid]['proposed_dec'];
     unset($house['data']['rooms'][$rid]['proposed_dec']);
     $house['data']['rooms'][$rid]['dec']['done'] = 0;
     improbablehousing_sethousedata($house);
     break;
 case "decorate":
     require_once "modules/staminasystem/lib/lib.php";
     $actinfo = process_action("Decorating");
     if ($actinfo['lvlinfo']['levelledup']) {
         output("`n`c`b`0You gained a level in Decorating!  You are now level %s!  This action will cost fewer Stamina points now.`b`c`n", $actinfo['lvlinfo']['newlvl']);
     }
     $house['data']['rooms'][$rid]['dec']['done'] += 1;
     //check if the job's done
     if ($house['data']['rooms'][$rid]['dec']['done'] == $house['data']['rooms'][$rid]['dec']['req']) {
         output("The decorating job is completed!  You step back and admire your work.  Pretty nice!`n`n");
         $house['data']['rooms'][$rid]['desc'] = $house['data']['rooms'][$rid]['dec']['desc'];
         unset($house['data']['rooms'][$rid]['dec']);
         $eraseroomdec = "DELETE FROM " . db_prefix("room_prefs") . " WHERE pref = 'dec' AND hid = '{$hid}' AND rid = '{$rid}'";
         db_query($eraseroomdec);
     } else {
         output("You set about painting and decorating.  Before too long, the room is one step closer to being fully decorated.`n`n");
         require_once "lib/bars.php";
         $bar = fadebar($house['data']['rooms'][$rid]['dec']['done'], $house['data']['rooms'][$rid]['dec']['req'], 150, 5);
function items_world_map_gathering_run()
{
    global $session;
    page_header("Gathering Materials");
    $type = httpget('mat');
    $item = httpget('item');
    require_once "modules/staminasystem/lib/lib.php";
    if ($type == "wood") {
        $lv = process_action("Logging");
        $stam = get_stamina();
        $rstam = get_stamina(0);
        $failchance = e_rand(0, 99);
        if ($failchance < $stam) {
            give_item("wood");
            use_item($item, "logging");
            output("`0You hack away until you have what can only be described as a bloody enormous log, suitable as a part of a quaint little cabin.  It couldn't possibly fit into your backpack, but you stuff it in anyway.`n");
            if ($lv['lvlinfo']['levelledup'] == true) {
                output("`n`c`b`0You gained a level in Logging!  You are now level %s!  This action will cost fewer Stamina points now, so you can lumberjack more lumber each day!`b`c`n", $lv['lvlinfo']['newlvl']);
            }
        } else {
            if ($failchance < $rstam) {
                output("You hack away until you have what can only be described as a whole shitload of matchsticks.  The wood just splintered into barely more than pulp under your clumsy, half-asleep paws.`n`nMaybe it'd be a good idea to rest a bit before you try this again.`n`n");
            } else {
                $fail = 1;
                output("You hack away at the tree, your half-asleep mind blissfully ignorant of its wild swaying.  Ignorant, that is, until it falls on you.`n`nYou wake up, naturally, on the FailBoat.`n`n");
            }
        }
    } else {
        if ($type == "stone") {
            $lv = process_action("Stonecutting");
            $stam = get_stamina();
            $rstam = get_stamina(0);
            $failchance = e_rand(0, 99);
            if ($failchance < $stam) {
                $success = 1;
                give_item("stone");
                use_item($item, "stonecutting");
                output("`0You hack away until you have what can only be described as a huge-ass lump of stone, very heavy and cumbersome.  For some reason your backpack seems like a really good place to put it.`n");
                if ($lv['lvlinfo']['levelledup'] == true) {
                    output("`n`c`b`0You gained a level in Stonecutting!  You are now level %s!  This action will cost fewer Stamina points now, so you can break more rocks each day!`b`c`n", $lv['lvlinfo']['newlvl']);
                }
            } else {
                if ($failchance < $rstam) {
                    output("You hack away until you have what can only be described as a whole shitload of gravel.  The rock just smashed into splinters under your clumsy, half-asleep paws.`n`nMaybe it'd be a good idea to rest a bit before you try this again.`n`n");
                } else {
                    $fail = 1;
                    output("You hack away at the rock, blissfully unaware that another, larger rock is being gently dislodged by your half-asleep ministrations.  Another, larger rock that happens to be balanced precariously on an outcrop just above your head.`n`nYou wake up, naturally, on the FailBoat.`n`n");
                }
            }
        }
    }
    if (!$fail) {
        items_world_map_gathering_showgather();
        addnav("Other");
        addnav("Show Inventory", "inventory.php?items_context=worldmap");
        addnav("Return to the World Map", "runmodule.php?module=worldmapen&op=continue");
    } else {
        $session['user']['hitpoints'] = 0;
        $session['user']['gold'] = 0;
        $session['user']['alive'] = 0;
        //set the user's location to the last place on the map they touched
        $session['user']['location'] = get_module_pref("lastCity", "worldmapen");
        addnav("Guess what happens now?");
        addnav("That's right.", "shades.php");
    }
    page_footer();
}
Ejemplo n.º 10
0
<?php

/**
 * Astronomical Algorithms UI
 *
 * @author    Michel Corne <*****@*****.**>
 * @copyright 2012 Michel Corne
 * @license   http://opensource.org/licenses/mit-license.php MIT
 */
$_time = microtime(true);
$dir = dirname(__FILE__);
set_include_path($dir . '/api');
define('ROOT', $dir);
require_once ROOT . '/ui/controller.php';
prepare_action();
process_action();
finish_action();
require_once ROOT . '/ui/display.php';
require ROOT . '/ui/views/layout.phtml';
function creaturetargets_dohook($hookname, $args)
{
    global $session, $enemies;
    switch ($hookname) {
        case "buffbadguy":
            if (get_module_objpref("creatures", $args['creatureid'], "usetargets") == 1) {
                for ($i = 1; $i <= 6; $i++) {
                    $args['target' . $i . '']['name'] = get_module_objpref("creatures", $args['creatureid'], "target" . $i . "");
                    $args['target' . $i . '']['hitpoints'] = round($args['creaturehealth'] / 100 * get_module_objpref("creatures", $args['creatureid'], "hitpoints" . $i . ""));
                    $args['target' . $i . '']['killatk'] = get_module_objpref("creatures", $args['creatureid'], "killatk" . $i . "");
                    $args['target' . $i . '']['killdef'] = get_module_objpref("creatures", $args['creatureid'], "killdef" . $i . "");
                    $args['target' . $i . '']['killhp'] = get_module_objpref("creatures", $args['creatureid'], "killhp" . $i . "");
                    $args['target' . $i . '']['killmsg'] = get_module_objpref("creatures", $args['creatureid'], "killmsg" . $i . "");
                    $args['target' . $i . '']['hitatk'] = get_module_objpref("creatures", $args['creatureid'], "hitatk" . $i . "");
                    $args['target' . $i . '']['hitdef'] = get_module_objpref("creatures", $args['creatureid'], "hitdef" . $i . "");
                    $args['target' . $i . '']['hitmsg'] = get_module_objpref("creatures", $args['creatureid'], "hitmsg" . $i . "");
                    $args['target' . $i . '']['currenttarget'] = 0;
                }
            }
            //Check to see if there's an AI Script involved with this creature, and if not, tell battle.php (via our modifications) to execute our AI Script at the start of the round, not the end - as long as we're actually using multiple hit targets with this creature, of course
            if ($args['target1']['hitpoints'] != 0) {
                if ($args['creatureaiscript'] == '') {
                    $args['creatureaiscript'] = "require(\"ai/creaturetargetai.php\");";
                }
            }
            //Give the creature a set of starting hitpoints, because it's SO DAMNED USEFUL
            $args['creaturestartinghealth'] = $args['creaturehealth'];
            debug($args['creaturestartinghealth']);
            //Set the phase for the AI Script and move on
            $args['phase'] = 1;
            // debug("Debugging args after creatureencounter");
            // debug ($args);
            return $args;
            break;
        case "battle":
            foreach ($enemies as $index => $badguy) {
                $badguy['oldhitpoints'] = $badguy['creaturehealth'];
                $enemies[$index] = $badguy;
            }
            //		debug("Debugging enemies at battle");
            //		debug($enemies);
            break;
        case "apply-specialties":
            foreach ($enemies as $index => $badguy) {
                $skill = httpget('skill');
                $target = httpget('target');
                if ($badguy['istarget'] == 1) {
                    if ($skill == "target") {
                        require_once "modules/staminasystem/lib/lib.php";
                        $return = process_action("Fighting - Targeted");
                        if ($return['lvlinfo']['levelledup'] == true) {
                            output("`n`c`b`0You gained a level in Targeted Fighting!  You are now level %s!  This action will cost fewer Stamina points now.`b`c`n", $return['lvlinfo']['newlvl']);
                        }
                        //					debug("Altering creature stats");
                        //First grab and save the current attack and defence stats, so we can revert back in the next round
                        $badguy['oldcreatureattack'] = $badguy['creatureattack'];
                        $badguy['oldcreaturedefense'] = $badguy['creaturedefense'];
                        //Now change the values for hitting the relevant target
                        $badguy['creatureattack'] = $badguy['creatureattack'] * $badguy['target' . $target . '']['hitatk'];
                        $badguy['creaturedefense'] = $badguy['creaturedefense'] * $badguy['target' . $target . '']['hitdef'];
                        // Set this target as the target being... targeted, I guess.
                        $badguy['target' . $target . '']['currenttarget'] = 1;
                        //Tell the AI Script to put the stats back the way they were
                        $badguy['revert'] = 1;
                        //Output the hit message.  We're using a buff so that it goes in the right place in the text.  The atkmod is only there to force the buff to output the start message.
                        apply_buff("creaturetargets", array("rounds" => 1, "startmsg" => array("%s", stripslashes($badguy['target' . $target . '']['hitmsg'])), "atkmod" => 1, "schema" => "module-creaturetargets"));
                    }
                }
                $enemies[$index] = $badguy;
            }
            //		debug("Debugging enemies after apply-specialties");
            //		debug($enemies);
            break;
        case "fightnav-specialties":
            $script = $args['script'];
            require_once "modules/staminasystem/lib/lib.php";
            $cost = stamina_getdisplaycost("Fighting - Targeted");
            foreach ($enemies as $index => $badguy) {
                for ($i = 1; $i <= 6; $i++) {
                    if ($badguy['istarget'] == 1 && $badguy['target' . $i . '']['hitpoints'] > 0) {
                        addnav(array("Targeting (`Q+%s%%`0)", $cost));
                        addnav(array("Aim for the %s", $badguy['target' . $i . '']['name']), $script . "op=fight&skill=target&target=" . $i . "", true);
                    }
                }
            }
            break;
    }
    return $args;
}
function insults_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "fightnav-specialties":
            if (get_module_pref("able")) {
                $script = $args['script'];
                require_once "modules/staminasystem/lib/lib.php";
                addnav("Ronsen-Kiai");
                if (get_module_pref("ableclassy")) {
                    addnav(array("Classy (`Q+%s%%`0)", stamina_getdisplaycost("Insults - Classy", 3)), $script . "op=fight&skill=insult&l=3");
                }
                addnav(array("Confusing (`Q+%s%%`0)", stamina_getdisplaycost("Insults - Confusing", 3)), $script . "op=fight&skill=insult&l=2");
                addnav(array("Coarse (`Q+%s%%`0)", stamina_getdisplaycost("Insults - Coarse", 3)), $script . "op=fight&skill=insult&l=1");
            }
            break;
        case "apply-specialties":
            if (httpget('skill') == "insult") {
                require_once "modules/staminasystem/lib/lib.php";
                switch (httpget("l")) {
                    case 1:
                        //Coarse insults
                        $act = process_action("Insults - Coarse");
                        //todo - level up text
                        $l = insults_roll("Coarse");
                        $insult = insults_coarse();
                        switch ($l) {
                            case 1:
                                apply_buff('insults-coarse', array("startmsg" => "`0You take a deep breath to unleash a witty and disgusting remark about your foe's mother.  Unfortunately, you picked the exact wrong time to do so - the creature smashes you right in the face.", "rounds" => 1, "atkmod" => 0, "defmod" => 0, "schema" => "module-insults"));
                                break;
                            case 2:
                                apply_buff('insults-coarse', array("startmsg" => "`0You face your attacker, and let loose with a flurry of profanities.  Actually - no, no you don't.  You get a bit tongue-tied, and end up saying \"`#Yeah, you... your mother likes... oh, just leave me alone, you big bully!`0\"  The creature laughs at you, and smacks you upside the head while you pout.", "rounds" => 1, "atkmod" => 0.6, "defmod" => 0.6, "schema" => "module-insults"));
                                break;
                            case 3:
                                apply_buff('insults-coarse', array("startmsg" => "`0You take a breath to unleash a devastating insult, but notice your enemy lunging for a vicious attack.  You were `ialmost`i caught off-guard, but managed to go into the defensive at the last moment - your counterattack won't be as powerful in this round, though.", "rounds" => 1, "atkmod" => 0.6, "defmod" => 1.2, "schema" => "module-insults"));
                                break;
                            case 4:
                                apply_buff('insults-coarse', array("startmsg" => "`0You reach into yourself and pull out the darkest, smelliest insult you can find - but you don't quite get a chance to use it, as you are distracted by a flurry of blows from your enemy.  Well, at least you didn't fumble it this time.", "rounds" => 1, "atkmod" => 1, "schema" => "module-insults"));
                                break;
                            case 5:
                                $msg = "`0You grin cheerfully at your enemy, and let loose a casual slur.`n\"`#" . $insult . ",`0\" you snicker.  Your foe is enraged!  It hurls itself at you with a furious growl, attacking hard - but letting its guard down in its anger!";
                                apply_buff('insults-coarse', array("startmsg" => $msg, "rounds" => 1, "badguyatkmod" => 1.2, "badguydefmod" => 0.6, "schema" => "module-insults"));
                                break;
                            case 6:
                                $msg = "`0You show your enemy a disconcerting leer, and bring the emotional pain.`n\"`#" . $insult . "!`0\" you cry.  You can tell you've struck a deep blow!  Your enemy is demoralized, and can neither attack nor defend as effectively for this round!";
                                apply_buff('insults-coarse', array("startmsg" => $msg, "rounds" => 1, "badguyatkmod" => 0.6, "badguydefmod" => 0.6, "schema" => "module-insults"));
                                break;
                            case 7:
                                $msg = "`0You draw a deep breath, look your foe straight in the eye, and bellow \"`#" . $insult . "!`0\"`nBirds scatter from the trees and your enemy stands stunned, open-mouthed.  You take this opportunity to really put the boot in!";
                                apply_buff('insults-coarse', array("startmsg" => $msg, "rounds" => 1, "badguyatkmod" => 0, "badguydefmod" => 0, "schema" => "module-insults"));
                                break;
                        }
                        if ($act['lvlinfo']['levelledup'] == true) {
                            output("`n`c`b`0You gained a level in Coarse Insults!  You are now level %s!  This action will cost fewer Stamina points now, so you can execute more sailor-mouthed insults per day!  Also, your odds of success for this Insults class have been slightly improved!`b`c`n", $act['lvlinfo']['newlvl']);
                        }
                        break;
                    case 2:
                        //Confusing insults
                        $act = process_action("Insults - Confusing");
                        //todo - level up text
                        $l = insults_roll("Confusing");
                        $insult = insults_confusing();
                        switch ($l) {
                            case 1:
                                apply_buff('insults-confusing', array("startmsg" => "`0You take a deep breath to unleash a bewildering proposition upon your enemy.  Unfortunately, you picked the exact wrong time to do so - the creature smashes you right in the face.", "rounds" => 1, "atkmod" => 0, "defmod" => 0, "schema" => "module-insults"));
                                break;
                            case 2:
                                apply_buff('insults-confusing', array("startmsg" => "`0You face your attacker, and let loose with a surreal and bemusing insult that twists their brain into knots.  Actually - no, no you don't.  You get a bit tongue-tied, and end up saying \"`#Lick my... thing... with your... your thing!  You `iTHING!`i`0\"  The creature laughs at you, and smacks you upside the head while you pout.", "rounds" => 1, "atkmod" => 0.5, "defmod" => 0.5, "schema" => "module-insults"));
                                break;
                            case 3:
                                apply_buff('insults-confusing', array("startmsg" => "`0You take a breath to unleash a devastating and confusing slur, but notice your enemy lunging for a vicious attack.  You were `ialmost`i caught off-guard, but managed to go into the defensive at the last moment - your counterattack won't be as powerful in this round, though.", "rounds" => 1, "atkmod" => 0.5, "defmod" => 1.2, "schema" => "module-insults"));
                                break;
                            case 4:
                                apply_buff('insults-confusing', array("startmsg" => "`0You reach deep inside and pull out the most bewildering phrase you can find - but you don't quite get a chance to use it, as you are distracted by a flurry of blows from your enemy.  Well, at least you didn't fumble it this time.", "rounds" => 1, "atkmod" => 1, "schema" => "module-insults"));
                                break;
                            case 5:
                                $msg = "`0You lean forward and whisper your insult with a knowing smile.`n\"`#" . $insult . ".`0\"  Your foe is confused and enraged!  It hurls itself at you with a furious growl, attacking hard - but letting its guard down in its anger!";
                                apply_buff('insults-confusing', array("startmsg" => $msg, "rounds" => 1, "badguyatkmod" => 1.2, "badguydefmod" => 0.5, "schema" => "module-insults"));
                                break;
                            case 6:
                                $msg = "`0You grin cheerfully at your enemy, and offer a subtle and complex proposition.`n\"`#" . $insult . "!`0\" you cry.  You can tell you've struck a deep blow!  Your enemy is distracted, and can neither attack nor defend as effectively for this round!";
                                apply_buff('insults-confusing', array("startmsg" => $msg, "rounds" => 1, "badguyatkmod" => 0.5, "badguydefmod" => 0.5, "schema" => "module-insults"));
                                break;
                            case 7:
                                $msg = "`0You draw a deep breath, look your foe straight in the eye, and bellow \"`#" . $insult . "!`0\"`nBirds scatter from the trees and your enemy stands stunned, open-mouthed and bewildered.  You take this opportunity to really put the boot in!";
                                apply_buff('insults-confusing', array("startmsg" => $msg, "rounds" => 1, "badguyatkmod" => 0, "badguydefmod" => 0, "schema" => "module-insults"));
                                break;
                        }
                        if ($act['lvlinfo']['levelledup'] == true) {
                            output("`n`c`b`0You gained a level in Confusing Insults!  You are now level %s!  This action will cost fewer Stamina points now, so you can forward more bizarre propositions per day!  Also, your odds of success for this Insults class have been slightly improved!`b`c`n", $act['lvlinfo']['newlvl']);
                        }
                        break;
                    case 3:
                        //Classy insults
                        $act = process_action("Insults - Classy");
                        //todo - level up text
                        $l = insults_roll("Classy");
                        $insult = insults_classy();
                        switch ($l) {
                            case 1:
                                apply_buff('insults-classy', array("startmsg" => "`0You draw breath to unleash a devastating, Churchill-esque derision.  Unfortunately, you picked the exact wrong time to do so - the creature catches you off-guard and smashes you right in the face.", "rounds" => 1, "atkmod" => 0, "defmod" => 0, "schema" => "module-insults"));
                                break;
                            case 2:
                                apply_buff('insults-classy', array("startmsg" => "`0You face your attacker, and let loose with a discourtesy that shakes your foe to its very core.  Actually - no, no you don't.  You suffer a momentary lapse in wit and end up saying \"`#You are a... bloody... flibbling... oh, just piss off!`0\"  The creature laughs at you, and smacks you upside the head while you fume impotently.", "rounds" => 1, "atkmod" => 0.5, "defmod" => 0.5, "schema" => "module-insults"));
                                break;
                            case 3:
                                apply_buff('insults-classy', array("startmsg" => "`0You take a breath to unleash a devastating and distressing slur, but notice your enemy lunging for a vicious attack.  You were `ialmost`i caught off-guard, but managed to go into the defensive at the last moment - your counterattack won't be as powerful in this round, though.", "rounds" => 1, "atkmod" => 0.5, "defmod" => 1.2, "schema" => "module-insults"));
                                break;
                            case 4:
                                apply_buff('insults-classy', array("startmsg" => "`0You summon all your wit and ingenuity to concoct a truly powerful accusation - but you don't quite get a chance to use it, as you are distracted by a flurry of blows from your enemy.  Well, at least you didn't fumble it this time.", "rounds" => 1, "atkmod" => 1, "schema" => "module-insults"));
                                break;
                            case 5:
                                $msg = "`0You strike a pose and cast out your insult.`n\"`#You " . $insult . "!`0\"  Your foe is enraged!  It hurls itself at you with a furious growl, attacking hard - but letting its guard down in its anger!";
                                apply_buff('insults-classy', array("startmsg" => $msg, "rounds" => 1, "badguyatkmod" => 1.2, "badguydefmod" => 0.5, "schema" => "module-insults"));
                                break;
                            case 6:
                                $msg = "`0You step back for a moment, and cast out a truly vile accusation.`n\"`#You are the biggest " . $insult . " that it has ever been my misfortune to encounter!`0\" you cry.  You can tell you've struck a deep blow!  Your enemy is most vexed and distressed, and can neither attack nor defend as effectively for this round!";
                                apply_buff('insults-classy', array("startmsg" => $msg, "rounds" => 1, "badguyatkmod" => 0.5, "badguydefmod" => 0.5, "schema" => "module-insults"));
                                break;
                            case 7:
                                $msg = "`0You draw a deep breath, look your foe straight in the eye, and call in a firm, assertive voice \"`#I have it on good authority that you, my friend, are a " . $insult . "!`0\"`nBirds scatter from the trees and your enemy stands stunned, open-mouthed and bewildered.  You take this opportunity to really put the boot in!";
                                apply_buff('insults-classy', array("startmsg" => $msg, "rounds" => 1, "badguyatkmod" => 0, "badguydefmod" => 0, "schema" => "module-insults"));
                                break;
                        }
                        if ($act['lvlinfo']['levelledup'] == true) {
                            output("`n`c`b`0You gained a level in Classy Insults!  You are now level %s!  This action will cost fewer Stamina points now, so you can cast more disdainful accusations per day!  Also, your odds of success for this Insults class have been slightly improved!`b`c`n", $act['lvlinfo']['newlvl']);
                        }
                        break;
                }
            }
            break;
    }
    return $args;
}
function worldmapen_terrain_takestamina($x, $y, $z = 1)
{
    global $session;
    $terrain = worldmapen_getTerrain($x, $y, $z);
    require_once 'modules/staminasystem/lib/lib.php';
    switch ($terrain['type']) {
        case "Plains":
            $plains = process_action("Travelling - Plains");
            break;
        case "Forest":
            $forest = process_action("Travelling - Jungle");
            break;
        case "River":
            $river = process_action("Travelling - River");
            break;
        case "Ocean":
            $ocean = process_action("Travelling - Ocean");
            break;
        case "Desert":
            $desert = process_action("Travelling - Beach");
            break;
        case "Swamp":
            $swamp = process_action("Travelling - Swamp");
            break;
        case "Mount":
            $mount = process_action("Travelling - Mountains");
            break;
        case "Snow":
            $snow = process_action("Travelling - Snow");
            break;
    }
    if ($plains['lvlinfo']['levelledup'] == true) {
        output("`n`c`b`0You gained a level in Travel across plains!  You are now level %s!  This action will cost fewer Stamina points now, so you can saunter across more fields per day.`b`c`n", $plains['lvlinfo']['newlvl']);
    }
    if ($forest['lvlinfo']['levelledup'] == true) {
        output("`n`c`b`0You gained a level in Travel across dense jungle!  You are now level %s!  This action will cost fewer Stamina points now, so you can navigate more thick jungle terrain per day.`b`c`n", $forest['lvlinfo']['newlvl']);
    }
    if ($river['lvlinfo']['levelledup'] == true) {
        output("`n`c`b`0You gained a level in Travel across rivers!  You are now level %s!  This action will cost fewer Stamina points now, so you can wade through more rivers in a single day.`b`c`n", $river['lvlinfo']['newlvl']);
    }
    if ($ocean['lvlinfo']['levelledup'] == true) {
        output("`n`c`b`0You gained a level in Travel across deep water!  You are now level %s!  This action will cost fewer Stamina points now, so you can swim more in a single day.`b`c`n", $ocean['lvlinfo']['newlvl']);
    }
    if ($desert['lvlinfo']['levelledup'] == true) {
        output("`n`c`b`0You gained a level in Travel across beaches!  You are now level %s!  This action will cost fewer Stamina points now, so you can saunter across more beachy terrain in a single day.`b`c`n", $desert['lvlinfo']['newlvl']);
    }
    if ($swamp['lvlinfo']['levelledup'] == true) {
        output("`n`c`b`0You gained a level in Travel across swamps!  You are now level %s!  This action will cost fewer Stamina points now, so you can wade through more swampy goo every day.`b`c`n", $swamp['lvlinfo']['newlvl']);
    }
    if ($mount['lvlinfo']['levelledup'] == true) {
        output("`n`c`b`0You gained a level in Travel across mountains!  You are now level %s!  This action will cost fewer Stamina points now, so you can scale more mountains in a single day.`b`c`n", $mount['lvlinfo']['newlvl']);
    }
    if ($snow['lvlinfo']['levelledup'] == true) {
        output("`n`c`b`0You gained a level in Travel across snow!  You are now level %s!  This action will cost fewer Stamina points now, so you can stomp through more snow in a single day.`b`c`n", $snow['lvlinfo']['newlvl']);
    }
}
$playerscrap = scrapbots_get_player_scrap();
require_once "modules/staminasystem/lib/lib.php";
$name1 = array("Grunt", "Fisto", "Brains", "Speedy", "Hammer", "Nails", "Servo", "Bob", "Brock", "Prince", "Awesome", "Ratchet", "Random", "Locke", "Grawp", "Sparky", "Bastard");
$name2 = array("The Felcher", "The Fister", "The Hatchet", "The Axle", "The Hammer", "Nails", "Servo", "The Rammer", "The Whittler", "The Duke", "The Spanker", "The Chainsaw", "The Prat", "The Stock", "The Juggernaut", "The Plonker", "The Bastard");
$name3 = array("McGrunt", "McFisty", "McBrainy", "McSpeedy", "McHammer", "McNails", "McServo", "McThunderCrotch", "McAwesome", "McKing", "McBadass", "McSpanner", "McRandom", "McBarrel", "McJuggernaut", "McLaser", "McBastard");
$r1 = e_rand(0, 16);
$r2 = e_rand(0, 16);
$r3 = e_rand(0, 16);
$name = "" . $name1[$r1] . " \"" . $name2[$r2] . "\" " . $name3[$r3] . "";
$owner = $session['user']['acctid'];
$sql = "INSERT INTO " . db_prefix("scrapbots") . " (owner,name,activated,hitpoints,brains,brawn,briskness,junglefighter,retreathp) VALUES ({$owner},'" . mysql_real_escape_string($name) . "',0,10,1,1,1,0,0)";
db_query($sql);
output("You get to work.  It takes a long, long time, welding and soldering and programming and grinding and smoking and cursing and sweating, but eventually your ScrapBot is complete, and magnificent.  You hook it into the diagnostics station and power it up.`n`nThe diagnostic station queries the CPUID, and returns the ScrapBot's name - %s.  The ScrapBot is ready to activate!`n`n", $name);
$solder = process_action("Soldering");
$program = process_action("Programming");
$metalwork = process_action("Metalworking");
if ($solder['lvlinfo']['levelledup'] == true) {
    output("`n`c`b`0You gained a level in Soldering!  You are now level %s!  This action will cost fewer Stamina points now, so you can solder up more circuitry and wiring harnesses each day!`b`c`n", $return['lvlinfo']['newlvl']);
}
if ($program['lvlinfo']['levelledup'] == true) {
    output("`n`c`b`0You gained a level in Programming!  You are now level %s!  This action will cost fewer Stamina points now, so you can geek out even more every day!`b`c`n", $return['lvlinfo']['newlvl']);
}
if ($metalwork['lvlinfo']['levelledup'] == true) {
    output("`n`c`b`0You gained a level in Metalworking!  You are now level %s!  This action will cost fewer Stamina points now, so you can grind and cut and weld more each day!`b`c`n", $return['lvlinfo']['newlvl']);
}
$playerscrap['data']['veryrareitems'][0] -= 1;
$playerscrap['data']['veryrareitems'][1] -= 1;
$playerscrap['data']['veryrareitems'][2] -= 1;
$playerscrap['data']['veryrareitems'][3] -= 1;
$playerscrap['data']['rareitems'][0] -= 2;
$playerscrap['data']['rareitems'][3] -= 1;
function staminacorecombat_dohook($hookname, $args)
{
    global $session;
    static $damagestart = 0;
    switch ($hookname) {
        case "forest":
            blocknav("forest.php?op=search");
            blocknav("forest.php?op=search&type=slum");
            blocknav("forest.php?op=search&type=thrill");
            blocknav("forest.php?op=search&type=suicide");
            addnav("Fight");
            $normalcost = stamina_getdisplaycost("Hunting - Normal");
            $slumcost = stamina_getdisplaycost("Hunting - Easy Fights");
            $thrillcost = stamina_getdisplaycost("Hunting - Big Trouble");
            $suicidecost = stamina_getdisplaycost("Hunting - Suicidal");
            addnav(array("T?Look for Trouble (`Q%s%%`0)", $normalcost), "forest.php?op=search&stam=search");
            if ($session['user']['level'] > 1) {
                addnav(array("E?Look for an Easy Fight (`Q%s%%`0)", $slumcost), "forest.php?op=search&type=slum&stam=slum");
            }
            addnav(array("B?Look for Big Trouble (`Q%s%%`0)", $thrillcost), "forest.php?op=search&type=thrill&stam=thrill");
            if (getsetting("suicide", 0)) {
                if (getsetting("suicidedk", 10) <= $session['user']['dragonkills']) {
                    addnav(array("*?Search `\$Suicidally`0 (`Q%s%%`0)", $suicidecost), "forest.php?op=search&type=suicide&stam=suicide");
                }
            }
            break;
        case "fightnav-graveyard":
        case "fightnav":
            $script = $args['script'];
            $fightcost = stamina_getdisplaycost("Fighting - Standard");
            $runcost = stamina_getdisplaycost("Running Away");
            blocknav($script . "op=fight");
            blocknav($script . "op=run");
            addnav("Standard Fighting");
            addnav(array("F?Fight (`Q%s%%`0)", $fightcost), $script . "op=fight&stam=fight");
            addnav(array("R?Run (`Q%s%%`0)", $runcost), $script . "op=run&stam=run");
            break;
        case "startofround-prebuffs":
            $process = httpget("stam");
            switch ($process) {
                case "search":
                    $return = process_action("Hunting - Normal");
                    if ($return['lvlinfo']['levelledup'] == true) {
                        output("`c`b`0You gained a level in Looking for Trouble!  This action costs fewer Stamina points now, so you can find more beasties to aggress!`b`c`n`n");
                    }
                    break;
                case "slum":
                    $return = process_action("Hunting - Easy Fights");
                    if ($return['lvlinfo']['levelledup'] == true) {
                        output("`c`b`0You gained a level in Looking for Easy Fights!  This action costs fewer Stamina points now, so you can pick on more small creatures!`b`c`n`n");
                    }
                    break;
                case "thrill":
                    $return = process_action("Hunting - Big Trouble");
                    if ($return['lvlinfo']['levelledup'] == true) {
                        output("`c`b`0You gained a level in Looking for Big Trouble!  This action costs fewer Stamina points now, so you can throw yourself on the mercy of large creatures more often!`b`c`n`n");
                    }
                    break;
                case "suicide":
                    $return = process_action("Hunting - Suicidal");
                    if ($return['lvlinfo']['levelledup'] == true) {
                        output("`c`b`0You gained a level in Looking for Really Big Trouble!  This action costs fewer Stamina points now, so you can put yourself in mortal danger more often!`b`c`n`n");
                    }
                    break;
            }
            if ($session['user']['alive'] == 1) {
                staminacorecombat_applystaminabuff();
            }
            $damagestart = $session['user']['hitpoints'];
            break;
        case "endofround":
            $damagetaken = $damagestart - $session['user']['hitpoints'];
            if (httpget("stam") == "fight" || httpget("op") == "fight") {
                $return = process_action("Fighting - Standard");
                if ($return['lvlinfo']['levelledup'] == true) {
                    output("`n`c`b`0You gained a level in Standard Fighting!  You are now level %s!  This action will cost fewer Stamina points now.`b`c`n", $return['lvlinfo']['newlvl']);
                }
            } else {
                if (httpget("op") == "fight" && httpget("auto") || httpget("op") == "fight" && httpget("skill")) {
                    $return = process_action("Fighting - Standard");
                    if ($return['lvlinfo']['levelledup'] == true) {
                        output("`n`c`b`0You gained a level in Standard Fighting!  You are now level %s!  This action will cost fewer Stamina points now.`b`c`n", $return['lvlinfo']['newlvl']);
                    }
                }
            }
            if (httpget("stam") == "run" || httpget("op") == "run") {
                $return = process_action("Running Away");
                if ($return['lvlinfo']['levelledup'] == true) {
                    output("`n`c`b`0You gained a level in Running Away!  You are now level %s!  This action will cost fewer Stamina points now, so you can run away like a cowardly dog more often!`b`c`n", $return['lvlinfo']['newlvl']);
                }
            }
            $reps = $damagetaken / $session['user']['maxhitpoints'] * 9;
            if ($reps >= 1) {
                $staminalost = 0;
                for ($i = 0; $i < floor($reps); $i++) {
                    $return = process_action("Taking It on the Chin");
                    $staminalost += $return['points_used'];
                    if ($return['lvlinfo']['levelledup'] == true) {
                        output("`n`c`b`0You gained a level in Taking It On The Chin!  You are now level %s!  This action will cost fewer Stamina points now, so getting beaten up will tire you out a little less.  Good thing, really!`b`c`n", $return['lvlinfo']['newlvl']);
                    }
                }
                output("The force of the blow sends you reeling, and knocks %s Stamina points out of you!`n", $staminalost);
            }
            break;
    }
    return $args;
}
function insultschool_run()
{
    global $session;
    page_header("Cuthbert's Academy of Lingual Defence");
    switch (httpget('op')) {
        case "start":
            if (!get_module_pref("able", "insults")) {
                //this is the player's first trip to the Insults Academy
                //ronsengi
                output("\"`qAh.  Not seen you here before.`0\"`n`nA three-eyed, broad-mouthed Mutant sits behind a desk, wearing a loose-fitting black garment reminiscent of a kimono.  \"`qMy name's Cuthbert, and this is my Academy of Lingual Defence.`0\"`n`n\"`#Lingual Defence?`0\" you ask.`n`n\"`qLingual Defence,`0\" replies Cuthbert proudly.  \"`qA perfect supplement to your preferred martial art, perfected over twenty years by my good self.`0\"`n`n\"`#I see.`0\"  You look around the room.  \"`#I don't see any weaponry?`0\"`n`n\"`qNot `iphysical`i weaponry, no.  The art of Lingual Defence, or Ronsen-Kiai, doesn't require any equipment except for every now and then in training.`0\"  He grins.  \"`qThat's not a `iprecise`i translation, by the way, but I find throwing a bit of Japanese in there helps with the marketing.`0\"`n`nYou nod, looking around at the empty room and the rather sparse student list hanging on one wall.  You decide to indulge the guy - it seems he could use the business.  \"`#Can you show me a bit of this Ronsen-Kiai?`0\"`n`nCuthbert shows you an excited grin.  \"`qAbsolutely!  Here, take this.`0\"  He reaches below his desk and hands you a heavy wooden axe handle, before moving to the center of the room.  \"`qNow come and attack me with that.`0\"  He grins.  \"`qDon't be shy, now.  I'll tell you when to stop.`0\"`n`nYou shrug, heft the axe handle, and rush towards him, bringing your weapon down in a crushing arc onto his head, which isn't there.  The Mutant has stepped to the inside, and now stands close enough for you to feel his breath.`n`n\"`qFUCKWIT!`0\" roars the Mutant as you swing the axe handle towards his sides.  \"`qI've seen `iMOLD`i-`0\" the tip of the axe handle sails harmlessly past his stomach - \"`q...swing an axe handle better than that!  Holy shit you're slow!`0\"  The Mutant takes a step back and another breath, and you flick the axe handle around so that you can charge him with the tip.  \"`qAnd FAT!  Jesus Christ, your arse looks like two Volkswagens parked side-by-side!`0\" the Mutant steps back and away from your axe handle, then takes a very rapid step first towards and then past you, your axe handle chasing but not quite catching his thighs.  You switch into opposite stance, to see the Mutant giving you the finger.  \"`qAnd stupid!  Damn, you're denser than that axe handle!`0\"  Man, that's distracting.  You piston your leading leg upwards, hoping to catch the Mutant in the chest.  The Mutant catches your foot and sniffs.  \"`qAnd the stench of your feet could kill a concrete elephant at twenty paces!`0\"  Enraged, you slam your leading leg downwards while pouncing from your back leg, using the Mutant's arms like a set of stairs so that you can kick his stupid mean face like a football.`n`nYou land poorly.`n`nThe Mutant stands over you.  \"`qYou imbecilic, mewling, malodorous pervert.  You feeble-minded, cloth-eared, illigitimate buffoon.  You twisted, disgusting, Thatcher-licking dullard.  Your father f***s sheep and your mother says \"Baaa.\"  You're a disgrace.  An obscenity.  An embarrassment.\"`n`n\"`#Stop!`0\" you cry.  \"`#Why're you saying these things?`0\"`n`nThe Mutant leans down and helps you to your feet.  \"`qBecause they distract you,`0\" he says kindly.  \"`qThey get you so riled up that you try silly maneouvers like the one that just ended with you winded on the floor.  And even though I can tell that you're a better fighter than me, and would have stoved my head in under different circumstances, I was still able to get away with not being hit because a part of you was paying attention to what I was saying.`0\"`n`nYou blink.  \"`#`iThat's`i Ronsen-Kai?  Spouting a load of insults while fighting?`0\"`n`nThe Mutant nods, smiling.  \"`qTwenty cigarettes for your first lesson.  You'll learn the two starter techniques, Coarse and Confusing.  Then when you can prove to me that you're ready, I'll teach you the third technique - Classy, or as some call it, \"Shakespearean.\"  So.  Are you interested in learning how to fight with your tongue as well as your fists and feet?`0\"`n`nWell?  `iAre`i you?");
                addnav("Learn a new combat technique for 20 cigarettes?");
                if ($session['user']['gems'] >= 20) {
                    addnav("Hell yes!", "runmodule.php?module=insultschool&op=learnbasic");
                } else {
                    addnav("No, because you don't have 20 cigarettes.", "village.php");
                }
            } else {
                //lessons
                require_once "modules/staminasystem/lib/lib.php";
                $amber = get_stamina();
                if ($amber == 100) {
                    output("Cuthbert greets you with a firm handshake.  \"`qHello again!  Back for some more training, eh?  Well, you've completed the basic course, so I can give you refresher lessons at 25 Requisition each.`0\"`n`n");
                    $coarse = get_player_action("Insults - Coarse");
                    $confusing = get_player_action("Insults - Confusing");
                    $level = $coarse['lvl'] + $confusing['lvl'];
                    if ($level > 20) {
                        if (!get_module_pref("ableclassy", "insults")) {
                            output("Cuthbert pauses for a moment and looks you up and down.  \"`qYou know,`0\" he says, \"`qI think you might be ready to learn some Classy insults.  It'll be another 20 cigarettes for the basic Classy course, if you're interested.`0\"`n`n");
                            addnav("Train with Cuthbert");
                            if ($session['user']['gems'] >= 20) {
                                addnav("Pay 20 Cigarettes to learn the Classy Insults action", "runmodule.php?module=insultschool&op=learnclassy");
                            }
                        }
                    }
                    output("`JCuthbert, like other teachers in Improbable Island, can help you level up some of your skills.  When you pay to train with Cuthbert, you'll use as much Stamina in performing your chosen actions as normal, but you'll receive two and a half times the experience.  Higher levels in any given Stamina action will make that action cost fewer Stamina points.  Higher levels in Insults skills will also improve your chances of casting successful Insults, and reduce the chances of fumbling.`n`n`0Will you train with Cuthbert?`n`n");
                    addnav("Train with Cuthbert");
                    if ($session['user']['gold'] >= 25) {
                        $coarsecost = stamina_getdisplaycost("Insults - Coarse");
                        addnav(array("Pay 25 Req for a lesson in Coarse Insults (`Q%s%%`0)", $coarsecost), "runmodule.php?module=insultschool&op=train&train=coarse");
                        $confusingcost = stamina_getdisplaycost("Insults - Confusing");
                        addnav(array("Pay 25 Req for a lesson in Confusing Insults (`Q%s%%`0)", $confusingcost), "runmodule.php?module=insultschool&op=train&train=confusing");
                        if (get_module_pref("ableclassy", "insults")) {
                            $classycost = stamina_getdisplaycost("Insults - Classy");
                            addnav(array("Pay 25 Req for a lesson in Classy Insults (`Q%s%%`0)", $classycost), "runmodule.php?module=insultschool&op=train&train=classy");
                        }
                    } else {
                        addnav("You don't have enough Requisition to improve your existing Insults skills.", "");
                    }
                } else {
                    output("Cuthbert greets you with a firm handshake.  He grins.  \"`qI know what you're thinking - you want more lessons, huh?  Well, you look half-asleep to me.  This isn't something you should try without a good night's rest.  Come see me tomorrow.`0\"");
                }
            }
            addnav("Leave this place");
            addnav("Return to Pleasantville", "village.php");
            break;
        case "train":
            $session['user']['gold'] -= 25;
            if (is_module_active("medals")) {
                require_once "modules/medals.php";
                medals_award_medal("cuthbert_train", "Cuthbert's Academy of Lingual Defence", "This player took lessons at Cuthbert's Academy of Lingual Defence!", "medal_cuthbert.png");
            }
            require_once "modules/staminasystem/lib/lib.php";
            switch (httpget('train')) {
                case "coarse":
                    apply_stamina_buff('traincoarse', array("name" => "Cuthbert's Training", "action" => "Insults - Coarse", "costmod" => 1, "expmod" => 2.5, "rounds" => 1, "roundmsg" => "", "wearoffmsg" => ""));
                    require_once "modules/insults.php";
                    $i1 = insults_coarse();
                    $i2 = insults_coarse();
                    $i3 = insults_coarse();
                    $i4 = insults_coarse();
                    $i5 = insults_coarse();
                    output("Cuthbert shows you a big smile.  \"`qIt's good to train with you again.  Coarse insults it is.  Let's get started!`0\"`n`nOutside the hut, for the next half an hour or so, people stop to listen to the bizzarre and filthy profanities spouted from within.`n`n");
                    output("`i\"`#%s!`0\"`n`n\"`q%s!`0\"`n`n\"`#%s!`0\"`n`n\"`q%s!`0\"`n`n\"`#%s!`0\"`n`n\"`qVery good!`0\"", $i1, $i2, $i3, $i4, $i5);
                    $return = process_action("Insults - Coarse");
                    output("You receive %s experience in Coarse Insults.`n`n", $return['exp_earned']);
                    if ($return['lvlinfo']['levelledup'] == true) {
                        output("`c`b`0You gained a level in Coarse Insults!  You are now level %s!  This action will cost fewer Stamina points now, and you have a higher chance of casting a successful Insult!`b`c`n", $return['lvlinfo']['newlvl']);
                    }
                    break;
                case "confusing":
                    apply_stamina_buff('trainconfusing', array("name" => "Cuthbert's Training", "action" => "Insults - Confusing", "costmod" => 1, "expmod" => 2.5, "rounds" => 1, "roundmsg" => "", "wearoffmsg" => ""));
                    require_once "modules/insults.php";
                    $i1 = insults_confusing();
                    $i2 = insults_confusing();
                    $i3 = insults_confusing();
                    $i4 = insults_confusing();
                    $i5 = insults_confusing();
                    output("Cuthbert shows you a big smile.  \"`qIt's good to train with you again.  Confusing insults it is.  Let's get started!`0\"`n`nOutside the hut, for the next half an hour or so, people stop to listen to the bizzarre and surreal propositions spouted from within.`n`n");
                    output("`i\"`#%s!`0\"`n`n\"`q%s!`0\"`n`n\"`#%s!`0\"`n`n\"`q%s!`0\"`n`n\"`#%s!`0\"`n`n\"`qVery good!`0\"", $i1, $i2, $i3, $i4, $i5);
                    $return = process_action("Insults - Confusing");
                    output("You receive %s experience in Confusing Insults.`n`n", $return['exp_earned']);
                    if ($return['lvlinfo']['levelledup'] == true) {
                        output("`c`b`0You gained a level in Confusing Insults!  You are now level %s!  This action will cost fewer Stamina points now, and you have a higher chance of casting a successful Insult!`b`c`n", $return['lvlinfo']['newlvl']);
                    }
                    break;
                case "classy":
                    apply_stamina_buff('trainclassy', array("name" => "Cuthbert's Training", "action" => "Insults - Classy", "costmod" => 1, "expmod" => 2.5, "rounds" => 1, "roundmsg" => "", "wearoffmsg" => ""));
                    require_once "modules/insults.php";
                    $i1 = insults_classy();
                    $i2 = insults_classy();
                    $i3 = insults_classy();
                    $i4 = insults_classy();
                    $i5 = insults_classy();
                    output("Cuthbert shows you a big smile.  \"`qIt's good to train with you again.  Classy insults it is.  Let's get started!`0\"`n`nOutside the hut, for the next half an hour or so, people stop to listen to the witty and scathing insults spouted from within.`n`n");
                    output("`i\"`#You %s!`0\"`n`n\"`qI retort that you are a %s!`0\"`n`n\"`#I've never seen such a %s!`0\"`n`n\"`qIt is a matter of public record that you are a %s!`0\"`n`n\"`#And proud of it!  You sir, on the other hand, are a %s!`0\"`n`n\"`qVery good!`0\"`n`n`i", $i1, $i2, $i3, $i4, $i5);
                    $return = process_action("Insults - Classy");
                    output("You receive %s experience in Classy Insults.`n`n", $return['exp_earned']);
                    if ($return['lvlinfo']['levelledup'] == true) {
                        output("`c`b`0You gained a level in Classy Insults!  You are now level %s!  This action will cost fewer Stamina points now, and you have a higher chance of casting a successful Insult!`b`c`n", $return['lvlinfo']['newlvl']);
                    }
                    break;
            }
            $amber = get_stamina();
            if ($amber == 100) {
                addnav("More Training");
                if ($session['user']['gold'] >= 25) {
                    $coarsecost = stamina_getdisplaycost("Insults - Coarse");
                    addnav(array("Pay 25 Req for a lesson in Coarse Insults (`Q%s%%`0)", $coarsecost), "runmodule.php?module=insultschool&op=train&train=coarse");
                    $confusingcost = stamina_getdisplaycost("Insults - Confusing");
                    addnav(array("Pay 25 Req for a lesson in Confusing Insults (`Q%s%%`0)", $confusingcost), "runmodule.php?module=insultschool&op=train&train=confusing");
                    if (get_module_pref("ableclassy", "insults")) {
                        $classycost = stamina_getdisplaycost("Insults - Classy");
                        addnav(array("Pay 25 Req for a lesson in Classy Insults (`Q%s%%`0)", $classycost), "runmodule.php?module=insultschool&op=train&train=classy");
                    }
                } else {
                    addnav("You don't have enough Requisition to improve your existing Insults skills.", "");
                }
            } else {
                output("Cuthbert shows you a grin.  \"`qWell, that was a lot of fun.  But I can see you're getting tired - no point in training any more today, I'm afraid.`0\"");
            }
            addnav("Leave this place");
            addnav("Return to Pleasantville", "village.php");
            break;
        case "learnbasic":
            $session['user']['gems'] -= 20;
            output("\"`qExcellent!  Let's get started.  There are three classes of Insults - Coarse, Confusing, and Classy.  Coarse insults are the most vulgar sort, Confusing tend to be surreal and off-putting, and Classy insults are more formal and refined.  Each type has different effects upon the foe, and different difficulties.  Obviously, you'll get better at each one with time - I'm only going to teach you the Coarse and Confusing types today, and you can come back to learn the Classy insults when I think you're ready.`0\"`n`n\"`qCoarse insults are quite predictable.  They usually have only minor effects upon the enemy, but if they backfire the damage won't be too great either.  Obviously, once in a while you'll either land a critical insult or suffer a catastrophic fumble, but for the most part you'll find this happens more rarely with Coarse insults.`0\"`n`n\"`qConfusing insults are a little more erratic - your chances of fumbling or scoring a critical emotional hit are increased when compared with Coarse insults.  Similarly, the effects are slightly more potent.`0\"`n`n\"`qClassy insults go even further than Confusing insults, with potentially devastating effects - but, of course, those effects can backfire and just as easily throw `iyou`i off-kilter.`0\"`n`n\"`qRemember, a poorly-cast insult can backfire against you, so use these techniques carefully.`0\"`n`n\"`qWhen you first start using Ronsen-Kiai, you'll probably end up doing yourself about as much harm as good.  But don't be discouraged - as you gain more experience in each Insult type, you'll get the hang of it.  Now let's get started.`0\"`n`nFor the next few hours, passers-by are shocked by the profanities, obscene suggestions, bizarre propositions and scathing retorts emanating from the Academy.  By the time Cuthbert shakes your hand and sends you out into the world, you're sweating, red-faced and sore-throated - but you feel a sense of true accomplishment.`n`n`c`bYou have gained two new skills!`b`nYou are now qualified to cast Coarse and Confusing Insults against your foes!`c");
            set_module_pref("able", 1, "insults");
            addnav("Leave this place");
            addnav("Return to Pleasantville", "village.php");
            break;
        case "learnclassy":
            $session['user']['gems'] -= 20;
            output("\"`qExcellent!  Let's get started.  Remember, Classy insults are more unpredictable than others, but their effects are greater, so use them carefully.`0\"For the next few hours, passers-by are shocked by the bizarre, Shakespearean language emanating from the Academy.  By the time Cuthbert shakes your hand and sends you out into the world, you're sweating, red-faced and sore-throated - but you feel a sense of true accomplishment.`n`n`c`bYou have gained a new skill!`b`nYou are now qualified to cast Classy Insults against your foes!`c");
            set_module_pref("ableclassy", 1, "insults");
            addnav("Leave this place");
            addnav("Return to Pleasantville", "village.php");
            break;
    }
    page_footer();
    return true;
}
function onslaught_run()
{
    global $session, $battle, $enemies;
    global $companions, $companion, $newcompanions;
    debug($session['user']['location']);
    switch (httpget('op')) {
        case "lookaround":
            page_header("What's the situation?");
            $rawnum = onslaught_nummonsters();
            require_once "lib/dialogue.php";
            $vague = vagueify($rawnum);
            output("Taking a moment during a lull in the fighting to look around, you'd say as a rough estimate that there are between %s and %s monsters rampaging through the Outpost.`n`n", $vague['low'], $vague['high']);
            $playercount = 0;
            output("Looking around you, you can see the following players engaged in battle alongside you:`n");
            $sql = "SELECT name,acctid,level FROM " . db_prefix("accounts") . " WHERE locked=0 AND loggedin=1 AND alive=1 AND location='" . $session['user']['location'] . "' AND laston>'" . date("Y-m-d H:i:s", strtotime("-" . getsetting("LOGINTIMEOUT", 900) . " seconds")) . "' ORDER BY level DESC";
            $result = db_query($sql);
            while ($row = db_fetch_assoc($result)) {
                $playercount++;
                output("`0%s`0`n", $row['name']);
            }
            if (!$playercount) {
                output("`bNobody!`b  You're fighting all on your lonesome!`n`n");
            } else {
                output_notl("`n");
            }
            $def = onslaught_checkwalls();
            output("You take a quick glance at the walls, and see they've got %s hitpoints, whatever the hell a \"hitpoint\" is.`n`n", $def);
            $breakchance = e_rand(0, 100);
            if ($breakchance > 50) {
                addnav("What will you do?");
                addnav("Reinforce the defences", "runmodule.php?module=onslaught&op=reinforce");
                addnav("Get back into the fight", "runmodule.php?module=onslaught&op=start&nodesc=1");
                addnav("Run outside and let the Outpost fend for itself", "runmodule.php?module=onslaught&op=runmap");
            } else {
                addnav("And here comes another monster!");
                addnav("Fight!", "runmodule.php?module=onslaught&op=continue&nodesc=1");
            }
            break;
        case "reinforce":
            page_header("Outpost Walls");
            $lv = onslaught_checkmonsters();
            $num = onslaught_nummonsters();
            $def = onslaught_checkwalls();
            output("`0You take a look at the Outpost walls.  Fortunately there are some lengths of timber, a hammer, and some nails sat conveniently next to a portion that's looking a little worse for wear.`n`nThis Outpost's hitpoints: `b%s`b`n`n", number_format($def));
            $stopchance = e_rand(0, 100);
            if ($lv > 100 && $def < $num && $stopchance > 80) {
                output("Before you have a chance to pick up the hammer, you hear the sound of approaching thunderous footsteps from behind you!  You whirl around, dropping the hammer and drawing your weapon, to see a slavering beast bearing down upon you!`n`n");
                addnav("Oh dear...");
                addnav("Fight!", "runmodule.php?module=onslaught&op=start&nodesc=1");
            } else {
                addnav("What will you do?");
                require_once "modules/staminasystem/lib/lib.php";
                $cost = stamina_getdisplaycost("Reinforcement");
                addnav(array("Reinforce the defences (`Q%s%%`0)", $cost), "runmodule.php?module=onslaught&op=reinforceconfirm");
                addnav("Return to the Outpost", "village.php");
            }
            break;
        case "reinforceconfirm":
            $iterations = httpget('iterations');
            if (!$iterations) {
                $iterations = 1;
            }
            page_header("Outpost Walls");
            $lv = onslaught_checkmonsters();
            $num = onslaught_nummonsters();
            output("`0You pick up the hammer and nails, and set about reinforcing the walls with new wood.`n`n");
            require_once "modules/staminasystem/lib/lib.php";
            for ($i = 0; $i < $iterations; $i++) {
                $def = onslaught_checkwalls();
                $stopchance = e_rand(0, 100);
                if ($lv > 100 && $def < $num && $stopchance > 80) {
                    output("Before you have a chance to pound a single nail, you hear the sound of approaching thunderous footsteps from behind you!  You whirl around, dropping the hammer and drawing your weapon, to see a slavering beast bearing down upon you!`n`n");
                    addnav("Oh dear...");
                    addnav("Fight!", "runmodule.php?module=onslaught&op=start&nodesc=1");
                    $nomore = 1;
                    break;
                } else {
                    $act = process_action("Reinforcement");
                    $actinfo = get_player_action("Reinforcement");
                    $actlvl = $actinfo['lvl'];
                    if ($act['lvlinfo']['levelledup'] == true) {
                        output("`n`c`b`0You gained a level in Reinforcement!  You are now level %s!  This action will cost fewer Stamina points now, so reinforcing Outposts will tire you out a little less.`b`c`n", $act['lvlinfo']['newlvl']);
                    }
                    $stamina = get_stamina();
                    $failchance = e_rand(1, 100);
                    if ($failchance > $stamina) {
                        output("`4`c`bDisaster!`b`c`0`n");
                        $red = get_stamina(0);
                        $death = e_rand(0, 100);
                        if ($death > $red) {
                            output("`\$Your exhaustion makes itself known - the hammer rebounds rather spectacularly and hits you square in the forehead, knocking you out cold.  The head injury causes you to lose 10% of your experience, and all your Requisition is stolen by opportunistic Midgets.`n`n`0");
                            $session['user']['hitpoints'] = 0;
                            $session['user']['experience'] = round($session['user']['experience'] * 0.9);
                            $session['user']['gold'] = 0;
                            addnav("It's FailBoat time!");
                            addnav("Well, damn.", "shades.php");
                            $nomore = 1;
                            break;
                        } else {
                            output("You're so exhausted that you make a right pig's ear of the job!`n`nThe fresh plank hangs for a second on one lonely nail before falling off.  What a waste of time!`n`n");
                        }
                    } else {
                        $definc = e_rand($actlvl * 0.8, $actlvl * 1.2);
                        if ($definc < 2) {
                            $definc = 2;
                        }
                        $newdef = $def + $definc;
                        output("You hammer the board to the walls, reinforcing them quite nicely and adding %s hitpoints to this Outpost's defences.`n`nThis Outpost's hitpoints: `b%s`b`n`n", $definc, number_format($newdef));
                        require_once "modules/cityprefs/lib.php";
                        $cid = get_cityprefs_cityid("location", $session['user']['location']);
                        if ($cid) {
                            set_module_objpref("city", $cid, "defences", $newdef);
                        }
                    }
                }
            }
            if (!$nomore) {
                $cost = stamina_getdisplaycost("Reinforcement");
                addnav(array("Wall reinforcement: (`Q%s%%`0)", $cost));
                addnav("Reinforce once", "runmodule.php?module=onslaught&op=reinforceconfirm");
                addnav("5?Reinforce x 5", "runmodule.php?module=onslaught&op=reinforceconfirm&iterations=5");
                addnav("1?Reinforce x 10", "runmodule.php?module=onslaught&op=reinforceconfirm&iterations=10");
                addnav("O?Return to the Outpost", "village.php");
            }
            break;
        case "runsuccess":
            page_header("Run Like Hell!");
            output("You manage to flee your opponent.  You stand close to the Outpost gates, watching the carnage inside.  For the moment, everybody and everything is leaving you alone.  That will not last for long.`n`nNearby, someone has abandoned their timber, hammer and nails.  Abandoned or been dragged from, anyway.`n`n");
            addnav("What will you do?");
            addnav("Reinforce the defences", "runmodule.php?module=onslaught&op=reinforce");
            addnav("Get back into the fight", "runmodule.php?module=onslaught&op=start&nodesc=1");
            addnav("Run outside and let the Outpost fend for itself", "runmodule.php?module=onslaught&op=runmap");
            addnav("Take stock of the situation", "runmodule.php?module=onslaught&op=lookaround");
            break;
        case "runmap":
            redirect("runmodule.php?module=worldmapen&op=beginjourney", "Onslaught - Running Away");
            break;
        case "start":
            page_header("Breach!");
            output("`b`i`4THE WALLS OF %s ARE BREACHED!`0`i`b`nMonsters are pouring into the Outpost through jagged, splintered holes in the Outpost defences!  You picked one `ihell`i of a time to go about your business here!`n`n", strtoupper($session['user']['location']));
            onslaught_getenemy();
            break;
        case "run":
            page_header("Breach!");
            if (e_rand(1, 5) < 3) {
                // They managed to get away.
                $battle = false;
                redirect("runmodule.php?module=onslaught&op=runsuccess", "Onslaught: successful running");
            } else {
                output("You try to run, but your enemy gives chase!`n");
                $op = "fight";
                httpset('op', $op);
                $battle = true;
            }
            break;
        case "fight":
            page_header("Breach!");
            $battle = true;
            break;
        case "continue":
            page_header("Breach!");
            $out1 = onslaught_getcompanion();
            $out2 = onslaught_companion_escape();
            if ($out1) {
                output("`0%s`n", $out1);
            } else {
                if ($out2) {
                    output("`0%s`n", $out2);
                }
            }
            onslaught_getenemy();
            if (!$battle) {
                $left = onslaught_checkmonsters();
                if ($left > 100) {
                    $breakchance = e_rand(0, 100);
                    if ($breakchance > 70) {
                        addnav("Phew!");
                        addnav("Looks like everything else is busy...", "");
                        addnav("Reinforce the defences", "runmodule.php?module=onslaught&op=reinforce");
                        addnav("Get back into the fight", "runmodule.php?module=onslaught&op=start&nodesc=1");
                        addnav("Run outside and let the Outpost fend for itself", "runmodule.php?module=onslaught&op=runmap");
                        addnav("Take stock of the situation", "runmodule.php?module=onslaught&op=lookaround");
                    } else {
                        addnav("They just keep coming!");
                        addnav("Here comes another one!", "runmodule.php?module=onslaught&op=continue&nodesc=1");
                    }
                } else {
                    output("There are no more monsters to fight...`n`n");
                    //Display cleanup text, tart this up a bit
                    addnav("Village", "village.php");
                }
            }
            break;
    }
    if ($battle) {
        include_once "battle.php";
        // if( isset( $enemies ) && !$pvp )
        // $badguy = &$enemies;
        if ($victory) {
            $experience = e_rand($badguy['creatureexp'] * 1.25, $badguy['creatureexp'] * 2);
            $experience = round($experience);
            output("`#You receive `6%s `#experience!`n", $experience);
            $session['user']['experience'] += $experience;
            $left = onslaught_checkmonsters();
            if ($left > 100) {
                $breakchance = e_rand(0, 100);
                if ($breakchance > 70) {
                    addnav("Phew!");
                    addnav("Looks like everything else is busy...", "");
                    addnav("Reinforce the defences", "runmodule.php?module=onslaught&op=reinforce");
                    addnav("Get back into the fight", "runmodule.php?module=onslaught&op=start&nodesc=1");
                    addnav("Run outside and let the Outpost fend for itself", "runmodule.php?module=onslaught&op=runmap");
                    addnav("Take stock of the situation", "runmodule.php?module=onslaught&op=lookaround");
                } else {
                    addnav("They just keep coming!");
                    addnav("Here comes another one!", "runmodule.php?module=onslaught&op=continue&nodesc=1");
                }
            } else {
                output("You lower your weapon, blood splattered over your clothing.  It looks like you're winning - there are no more monsters to fight just now.`n`n");
                //Display cleanup text, tart this up a bit
                addnav("Village", "village.php");
            }
        } elseif ($defeat) {
            require_once "lib/forestoutcomes.php";
            forestdefeat(array($badguy), "in an Outpost");
        } else {
            require_once "lib/fightnav.php";
            fightnav(true, true, "runmodule.php?module=onslaught&nodesc=1");
        }
    }
    page_footer();
}