// systemmail($session['user']['referer'],$subj,$body);
 // //Patch to handle second-hand referrers, added by Caveman Joe
 // $sql = "SELECT acctid,name,referer FROM " . db_prefix("accounts") . " WHERE acctid={$session['user']['referer']}";
 // $result = db_query($sql);
 // $row=db_fetch_assoc($result);
 // if ($row['referer']){
 // $award = round(getsetting("refereraward",25) / 2);
 // $subj=array("`%One of your second-hand referrals advanced!`0");
 // $body=array("`&%s`#, referred by `&%s`#, has advanced to level `^%s`# - and so you have earned `^%s`# points!", $session['user']['name'], $row['name'], $session['user']['level'], $award);
 // systemmail($row['referer'],$subj,$body);
 // $sql = "UPDATE " . db_prefix("accounts") . " SET donation=donation+".$award." WHERE acctid={$row['referer']}";
 // db_query($sql);
 // }
 // //end of CMJ patch
 // }
 increment_specialty("`^");
 // Level-Up companions
 // We only get one level per pageload. So we just add the per-level-values.
 // No need to multiply and/or substract anything.
 if (getsetting("companionslevelup", 1) == true) {
     $newcompanions = $companions;
     foreach ($companions as $name => $companion) {
         $companion['attack'] = $companion['attack'] + $companion['attackperlevel'];
         $companion['defense'] = $companion['defense'] + $companion['defenseperlevel'];
         $companion['maxhitpoints'] = $companion['maxhitpoints'] + $companion['maxhitpointsperlevel'];
         $companion['hitpoints'] = $companion['maxhitpoints'];
         $newcompanions[$name] = $companion;
     }
     $companions = $newcompanions;
 }
 invalidatedatacache("list.php-warsonline");
function oldman_runevent($type)
{
    global $session;
    // We assume this event only shows up in the forest currently.
    $from = "forest.php?";
    $session['user']['specialinc'] = "module:oldman";
    require_once "lib/partner.php";
    $partner = get_partner();
    $op = httpget('op');
    if ($op == "" || $op == "search") {
        output("`@You encounter a strange old man!`n`n");
        output("He beckons you over to talk with you.");
        output("He looks harmless enough, but you have heard tales of the evil creatures which lurk in this forest disguised as normal people.`n`n");
        addnav("Old Man");
        addnav("Talk with him", $from . "op=talk");
        addnav("Back away", $from . "op=chicken");
    } elseif ($op == "chicken") {
        $session['user']['specialinc'] = "";
        output("`@You back away slowly, and then when you are out of sight, turn and move quickly to another part of the forest.`n`n");
        if (e_rand(1, 2) == 2) {
            output("`@You are quite sure that your paranoia saved your life today.");
        } else {
            output("`@You are quite sure that %s`@ would think you are a wuss for being scared of an old man.", $partner);
            if ($session['user']['sex'] == SEX_MALE) {
                output("Fortunately, she isn't here to see your cowardice.");
            } else {
                output("Fortunately, he isn't here to see your cowardice.");
            }
        }
    } elseif ($op == "talk") {
        // Okay.. now we get to have fun.  Which old man do they get?
        switch (e_rand(1, 5)) {
            case 1:
                // This is the pretty stick.
                $session['user']['specialinc'] = "";
                output("`@As you approach, he pulls out his Pretty Stick, whacks you on the temple, giggles, and runs away!`n`n");
                output("`^You `%gain one`^ charm point!");
                $session['user']['charm']++;
                break;
            case 2:
                // The ugly stick
                $session['user']['specialinc'] = "";
                if ($session['user']['charm'] > 0) {
                    output("`@As you approach, he pulls out his Ugly Stick, whacks you on the nose, giggles, and runs away!`n`n");
                    output("`^You `%lose one`^ charm point!");
                    $session['user']['charm']--;
                } else {
                    output("`@As you approach, he pulls out his Ugly Stick, whacks you on the nose, then gasps as his stick `%loses one`@ charm point.`n`n");
                    output("`@He quickly recovers his composure and runs away!`n`n");
                    output("Dang! You're even uglier than his Ugly Stick!");
                }
                break;
            case 3:
                // The lost man.
                output("`@\"`#I am lost,`@\" he says, \"`#can you lead me back to town?`@\"`n`n");
                output("You know that if you do, you will lose time for a forest fight for today.`n`n");
                output("Will you help out this poor old man?");
                addnav("Old Man");
                addnav("Walk him to town", $from . "op=walk");
                addnav("Leave him here", $from . "op=leavehim");
                break;
            case 4:
                // The betting game
                output("`@\"`#Would you like to play a little guessing game?`@\", he asks.");
                output("Knowing his sort, you know he will probably insist on a small wager if you do.`n`n");
                output("`@Do you wish to play his game?`n`n");
                addnav("Old Man");
                addnav("Play game", $from . "op=game");
                addnav("Leave", $from . "op=nogame");
                break;
            case 5:
                // The necromancer
                output("`@As you approach the old man, his face twists into a maniacal, evil grin.");
                switch (e_rand(1, 15)) {
                    case 1:
                        $session['user']['specialinc'] = "";
                        output("`@When you reach him, he mutters, \"`#Didn't y' own mother teach you never t' talk t' strangers?`@\"");
                        output("The old necromancer cackles and pulls out a black wand, waving it quickly over your head.`n`n");
                        output("`@You feel a searing pain as your soul is forcibly ripped from your body and cast into the underworld to fuel his evil spells!`n`n");
                        output("`^Your spirit has been ripped from your body!`n");
                        output("`^That treacherous old man searches your body and takes all of your gold.`n");
                        output("You lose 5% of your experience!`n");
                        output("You may continue playing again tomorrow.");
                        $session['user']['alive'] = false;
                        $session['user']['hitpoints'] = 0;
                        $session['user']['experience'] *= 0.95;
                        $session['user']['gold'] = 0;
                        addnav("Daily News", "news.php");
                        addnews("The body of %s was found in the woods, stripped of all gold and with dark symbols drawn upon it.", $session['user']['name']);
                        break;
                    case 2:
                    case 3:
                        $session['user']['specialinc'] = "";
                        output("`@When you reach him, he mutters, \"`#Aye, me %s, come a wee bit closer.  That's it, just a bit CLOSER!`@\"`n`n", translate_inline($session['user']['sex'] ? "lass" : "lad"));
                        output("As the old necromancer screams that last word, he pulls out a black wand and your body twists in agony as if molten fire has replaced your blood.`n`n");
                        output("Your vision goes dark and you feel the hand of %s`@ closing around your heart.", getsetting("deathoverlord", '`$Ramius'));
                        output("Just as you are sure you will die, the pain stops as quickly as it began.`n`n");
                        output("You climb to your feet, shaking and weak.");
                        output("The old necromancer is nowhere to be seen.`n`n");
                        output("`@You feel you will never be quite the %s you were before.`n`n", translate_inline($session['user']['sex'] ? "woman" : "man"));
                        if ($session['user']['maxhitpoints'] > $session['user']['level'] * 10) {
                            $session['user']['maxhitpoints']--;
                            set_module_pref("extrahps", get_module_pref("extrahps") - 1);
                            $hptype = "permanently";
                            if (!get_module_setting("carrydk") || is_module_active("globalhp") && !get_module_setting("carrydk", "globalhp")) {
                                $hptype = "temporarily";
                            }
                            $hptype = translate_inline($hptype);
                            output("`^You `b%s`b `\$lose`^ one hitpoint!`n", $hptype);
                        }
                        $loss = round($session['user']['maxhitpoints'] * 0.25, 0);
                        if ($loss > $session['user']['hitpoints']) {
                            $loss = $session['user']['hitpoints'] - 1;
                        }
                        output("`^You have taken `\$%s`^ damage from wounds.", $loss);
                        $session['user']['hitpoints'] -= $loss;
                        if ($session['user']['sex']) {
                            $msg = "%s came home from the forest, a bit less the woman than she was before.";
                        } else {
                            $msg = "%s came home from the forest, a bit less the man than he was before.";
                        }
                        addnews($msg, $session['user']['name']);
                        break;
                    case 4:
                    case 5:
                    case 6:
                    case 7:
                    case 8:
                    case 9:
                    case 10:
                        output("`@When you reach him, he mutters, \"`#A gem for me own self, yes?`@\"`n`n");
                        output("Do you give him a gem?");
                        addnav("Old Man");
                        addnav("Give him a gem", $from . "op=givegem");
                        addnav("Keep your gems", $from . "op=keepgem");
                        break;
                    case 11:
                    case 12:
                    case 13:
                    case 14:
                    case 15:
                        $session['user']['specialinc'] = "";
                        output("`@You are almost in front of him, when you hear a crashing sound coming from your right.`n`n");
                        output("You turn to look and see one of the bodyguards from the Inn walking through the woods heading your direction.");
                        output("You turn back to the old man, but he seems to have vanished.`n`n");
                        output("Oh well, you'll never know what he wanted now.");
                        break;
                }
                break;
        }
    } elseif ($op == "walk") {
        // Walking the oldman (#3) to town
        $session['user']['turns']--;
        output("`@You take the time to lead the old man back to town.`n`n");
        if (e_rand(0, 1) == 0) {
            output("`@In exchange, he whacks you with his Pretty Stick and you `%gain one`@ charm point.");
            $session['user']['charm']++;
        } else {
            output("`@In exchange, he gives you `%a gem`@!");
            $session['user']['gems']++;
            debuglog("gained 1 gem for walking old man to village");
        }
    } elseif ($op == "leavehim") {
        $session['user']['specialinc'] = "";
        // Being a cruel insensitive clod who hates old men.
        output("`@You tell the old man that you are far too busy to aid him.`n`n");
        output("`@Not a big deal, he should be able to find his way back to town on his own, he made his way out here, didn't he?");
        output("A wolf howls in the distance to your left, and a few seconds later one howls somewhere closer to your right.");
        output("Yep, he should be fine.");
    } elseif ($op == "nogame") {
        // Penny-pincher :)
        $session['user']['specialinc'] = "";
        output("`@Afraid to part with your precious precious money, you decline the old man his game.`n`n");
        output("There wasn't much point to it anyhow, as you certainly would have won.`n`n");
        output("Yep, definitely not afraid of the old man, nope.");
    } elseif ($op == "game") {
        if ($session['user']['gold'] <= 0) {
            $session['user']['specialinc'] = "";
            output("`@The old man reaches out with his stick and pokes your coin purse.  \"`#Empty?!?!  How can you bet with no money??`@\" he shouts.");
            output("With that, he turns with a HARUMPH, and disappears into the underbrush.");
        } else {
            oldman_bettinggame($from);
        }
    } elseif ($op == "givegem") {
        if ($session['user']['gems'] <= 0) {
            $session['user']['specialinc'] = "";
            output("`@You reach into your pack to find that you have no gems.");
            output("The old man looks at you expectantly.`n`n");
            output("When he sees you have no gems, he starts to frown.");
            output("Sensing trouble, you turn to flee toward the forest.`n`n");
            output("From behind you, you hear an evil laugh and feel a sharp pain in your back!`n`n");
            $loss = round($session['user']['maxhitpoints'] * 0.2, 0);
            if ($loss > $session['user']['hitpoints']) {
                $loss = $session['user']['hitpoints'] - 1;
            }
            output("`^You have taken `\$%s`^ damage from wounds.", $loss);
            $session['user']['hitpoints'] -= $loss;
        } else {
            $session['user']['specialinc'] = "";
            output("`@Feeling sorry for the old man, you reach into your pack and extract a gem which he snatches eagerly from your hand.`n");
            $session['user']['gems']--;
            switch (e_rand(1, 6)) {
                case 1:
                case 2:
                case 3:
                    output("`@He cackles with glee.");
                    output("He turns to you and says, \"`#Since y' made such a fine bargain w' me, me %s, I'll be puttin' in a good word for y' with m' ol' friend %s`#.`@\"`n`n", translate_inline($session['user']['sex'] ? "deary" : "lad"), getsetting("deathoverlord", '`$Ramius'));
                    output("`@The necromancer pulls out a black wand, raps you thrice on the head, and runs off into the forest.`n`n");
                    $favor = e_rand(5, 20);
                    output("`^You gain `&%s`^ favor with `\$Ramius`^.", $favor);
                    $session['user']['deathpower'] += $favor;
                    break;
                case 4:
                case 5:
                    if (is_module_active("specialtydarkarts")) {
                        output("`@He cackles with glee.");
                        output("He turns to you and says, \"`#Since y' made such a fine bargain w' me, me %s, I'll be teachin' y' a bit of m' art!`@\"`n`n", translate_inline($session['user']['sex'] ? "deary" : "lad"));
                        output("`@The necromancer pulls out a black wand, raps you thrice on the head, and runs off into the forest.`n`n");
                        output("`^You feel knowledge of the `\$Dark Arts`^ settle into your brain like a stain of blood into straw.`n");
                        require_once "lib/increment_specialty.php";
                        increment_specialty('`$', 'DA');
                        break;
                    }
                    // Fall through if we don't have dark arts enabled.
                // Fall through if we don't have dark arts enabled.
                case 6:
                    output("`@He runs off into the forest.`n`n");
                    output("That greedy old man stole your gem!");
            }
        }
    } elseif ($op == "keepgem") {
        $session['user']['specialinc'] = "";
        output("`@Not wanting to part with one of your precious gems, you turn around and march back toward the forest.`n`n");
        output("From behind you, you hear an evil laugh and feel a sharp pain in your back!`n`n");
        $loss = round($session['user']['maxhitpoints'] * 0.1, 0);
        if ($loss > $session['user']['hitpoints']) {
            $loss = $session['user']['hitpoints'] - 1;
        }
        output("`^You have taken `\$%s`^ damage from wounds.", $loss);
        $session['user']['hitpoints'] -= $loss;
    }
    output("`0");
}
function get_effect($item = false, $noeffecttext = "", $giveoutput = true)
{
    global $session;
    tlschema("inventory");
    $out = array();
    if ($item === false) {
        if ($noeffecttext == "") {
            $args = modulehook("item-noeffect", array("msg" => "`&Nothing happens.`n", "item" => $item));
            $out[] = sprintf_translate($args['msg']);
        } else {
            $out[] = sprintf_translate($noeffecttext);
        }
    } else {
        eval($item['execvalue']);
        if (isset($hitpoints) && $hitpoints != 0) {
            if (!isset($override_maxhitpoints)) {
                $override_maxhitpoints = false;
            }
            if ($hitpoints > 0) {
                if ($session['user']['hitpoints'] >= $session['user']['maxhitpoints'] && $override_maxhitpoints == false) {
                } else {
                    if ($session['user']['hitpoints'] + $hitpoints > $session['user']['maxhitpoints'] && $override_maxhitpoints == false) {
                        $session['user']['hitpoints'] = $session['user']['maxhitpoints'];
                        $out[] = sprintf_translate("`^Your hitpoints have been `@fully`^ restored.`n");
                    } else {
                        if ($override_maxhitpoints == false) {
                            $hitpoints = min($session['user']['maxhitpoints'] - $session['user']['hitpoints'], $hitpoints);
                        }
                        if ($hitpoints > 0) {
                            $session['user']['hitpoints'] += $hitpoints;
                            $out[] = sprintf_translate("`^You have been `@healed`^ for %s points.`n", $hitpoints);
                        }
                    }
                }
            } else {
                if ($hitpoints < 0) {
                    if ($session['user']['hitpoints'] + $hitpoints > 0) {
                        output("`^You `4loose`^ %s hitpoints.", abs($hitpoints));
                        $session['user']['hitpoints'] += $hitpoints;
                    } else {
                        if (!$killable) {
                            $session['user']['hitpoints'] = 1;
                            $out[] = sprintf_translate("`^You were `\$almost`^ killed.`n");
                        } else {
                            $experience = -$killable / 100;
                            $session['user']['hitpoints'] = 0;
                            $session['user']['alive'] = 0;
                            $out[] = sprintf_translate("`\$You die.`n");
                        }
                    }
                }
            }
        }
        if (isset($turns) && $turns != 0) {
            $session['user']['turns'] += $turns;
            debuglog("'s turns were altered by {$turns} by item {$item['itemid']}.");
            if ($turns > 0) {
                if ($turns == 1) {
                    $out[] = sprintf_translate("`^You `@gain`^ one turn.`n");
                } else {
                    $out[] = sprintf_translate("`^You `@gain`^ %s turns.`n", $turns);
                }
            } else {
                if ($session['user']['turns'] <= 0) {
                    $out[] = sprintf_translate("`^You `\$lose`^ all your turns.`n");
                    $session['user']['turns'] = 0;
                } else {
                    if ($turns == -1) {
                        $out[] = sprintf_translate("`^You `\$lose`^ one turn.`n");
                    } else {
                        $out[] = sprintf_translate("`^You `\$lose`^ %s turns.`n", abs($turns));
                    }
                }
            }
        }
        if (isset($attack) && $attack != 0) {
            $session['user']['attack'] += $attack;
            debuglog("'s attack was altered by {$attack} by item {$item['itemid']}.");
            if ($attack > 0) {
                $out[] = sprintf_translate("`^Your attack is `@increased`^ by %s.`n", $attack);
            } else {
                if ($session['user']['attack'] <= 1) {
                    $out[] = sprintf_translate("`^You `\$lose`^ all your attack except the strength of your bare fists.`n");
                    $session['user']['attack'] = 1;
                } else {
                    $out[] = sprintf_translate("`^Your attack is `\$decreased`^ by %s.`n", abs($attack));
                }
            }
        }
        if (isset($defense) && $defense != 0) {
            $session['user']['defense'] += $defense;
            debuglog("'s defense was altered by {$defense} by item {$item['itemid']}.");
            if ($defense > 0) {
                $out[] = sprintf_translate("`^Your defense is `@increased`^ by %s.`n", $defense);
            } else {
                if ($session['user']['defense'] <= 1) {
                    $out[] = sprintf_translate("`^You `\$lose`^ all your defense except the durability of your everpresent T-Shirt.`n");
                    $session['user']['defense'] = 1;
                } else {
                    $out[] = sprintf_translate("`^Your defense is `\$decreased`^ by %s.`n", abs($defense));
                }
            }
        }
        if (isset($charm) && $charm != 0) {
            $session['user']['charm'] += $turns;
            if ($charm > 0) {
                $out[] = sprintf_translate("`^Your charm is `@increased`^ by %s.`n", $charm);
            } else {
                if ($session['user']['charm'] <= 0) {
                    $out[] = sprintf_translate("`^You `\$lose`^ all your charm.`n");
                    $session['user']['charm'] = 0;
                } else {
                    $out[] = sprintf_translate("`^Your charm is `\$decreased`^ by %s.`n", abs($charm));
                }
            }
        }
        if (isset($maxhitpoints) && $maxhitpoints != 0) {
            if ($maxhitpoints > 0) {
                $session['user']['maxhitpoints'] += $maxhitpoints;
                $out[] = sprintf_translate("`^Your maximum hitpoints are permanently `@increased`^ by %s.`n", $maxhitpoints);
            } else {
                reset($session['user']['dragonpoints']);
                $hp = 0;
                while (list($key, $val) = each($session['user']['dragonpoints'])) {
                    if ($val == "hp") {
                        $dkhp++;
                    }
                }
                $minhp = $session['user']['level'] * 10 + $hp * 5;
                if ($session['user']['maxhitpoints'] + $maxhitpoints < $minhp) {
                    $maxhitpoints = $session['user']['maxhitpoints'] - $minhp;
                }
                if ($maxhitpoints < 0) {
                    $out[] = sprintf_translate("`^Your maximum hitpoints are permanently `\$decreased`^ by %s.`n", abs($maxhitpoints));
                    $session['user']['maxhitpoints'] += $maxhitpoints;
                }
            }
        }
        if (isset($uses)) {
            $modules = modulehook("specialtymodules");
            $names = modulehook("specialtynames");
            if (is_array($uses)) {
                while (list($key, $val) = each($uses)) {
                    if ($val > 0) {
                        if ($val == 1) {
                            $out[] = sprintf_translate("`^You `@gain`^ one point in %s.`n", $val, $names[$key]);
                        } else {
                            $out[] = sprintf_translate("`^You `@gain`^ %s points in %s.`n", $val, $names[$key]);
                        }
                    } else {
                        $val = min(abs($val), get_module_pref("uses", $modules[$key]));
                        if ($val == 1) {
                            $out[] = sprintf_translate("`^You `\$lose`^ one point in %s.`n", $val, $names[$key]);
                        } else {
                            $out[] = sprintf_translate("`^You `\$lose`^ %s points in %s.`n", $val, $names[$key]);
                        }
                        $val *= -1;
                    }
                    increment_module_pref("uses", $val, $modules[$key]);
                }
            } else {
                if ($uses == 'looseall') {
                    while (list($key, $val) = each($modules)) {
                        set_module_pref("uses", 0, $val);
                    }
                    $out[] = "`^You `\$lose all`^ uses in `\$all`^ specialties.`n";
                } else {
                    if (is_numeric($uses) && $uses > 0 && $session['user']['specialty'] != "") {
                        increment_module_pref("uses", $uses, $modules[$session['user']['specialty']]);
                        $out[] = sprintf_translate("`^You `@gain`^ %s points in %s.`n", $uses, $names[$session['user']['specialty']]);
                    } else {
                        if (is_numeric($uses) && $session['user']['specialty'] != "") {
                            $out[] = sprintf_translate("`^You `\$lose`^ %s points in %s.`n", $uses, $names[$key]);
                        }
                    }
                }
            }
        }
        if (isset($increment_specialty) && $increment_specialty > 0) {
            require_once "lib/increment_specialty.php";
            while ($increment_specialty) {
                increment_specialty("`^");
                $increment_specialty--;
            }
            $giveoutput = false;
        }
        if (isset($gems) && $gems != 0) {
            $session['user']['gems'] += $gems;
            debuglog("'s gems were altered by {$gems} by item {$item['itemid']}.");
            if ($gems > 0) {
                if ($gems == 1) {
                    $out[] = sprintf_translate("`^You `@gain`^ one gem.`n");
                } else {
                    $out[] = sprintf_translate("`^You `@gain`^ %s gems.`n", $gems);
                }
            } else {
                $gems = min(abs($gems), $session['user']['gems']);
                if ($gems == 1) {
                    $out[] = sprintf_translate("`^You `\$lose`^ one gem.`n", $gems);
                } else {
                    $out[] = sprintf_translate("`^You `\$lose`^ %s gems.`n", $gems);
                }
            }
        }
        if (isset($gold) && $gold != 0) {
            $session['user']['gold'] += $gold;
            debuglog("'s gold were altered by {$gold} by item {$item['itemid']}.");
            if ($gold > 0) {
                $out[] = sprintf_translate("`^You `@gain`^ %s gold.`n", $gold);
            } else {
                $gold = min(abs($gold), $session['user']['gold']);
                $out[] = sprintf_translate("`^You `\$lose`^ %s gold.`n", $gold);
            }
        }
        if (isset($experience) && $experience != 0) {
            if (is_float($experience)) {
                $bonus = round($session['user']['experience'] * $experience, 0);
            } else {
                $bonus = $experience;
            }
            $session['user']['experience'] += $experience;
            debuglog("'s experience was altered by {$bonus} by item {$item['itemid']}.");
            if ($bonus > 0) {
                $out[] = sprintf_translate("`^You `@gain`^ %s experience.`n", $bonus);
            } else {
                $bonus = min(abs($bonus), $session['user']['experience']);
                $out[] = sprintf_translate("`^You `\$lose`^ %s experience.`n", $bonus);
            }
        }
        if (isset($deathpower) && $deathpower != 0) {
            $session['user']['deathpower'] += $deathpower;
            if ($deathpower > 0) {
                $out[] = sprintf_translate("`^You `@gain`^ %s favor with `\$Ramius`0.`n", $deathpower);
            } else {
                $deathpower = min(abs($deathpower), $session['user']['deathpower']);
                $out[] = sprintf_translate("`^You `\$lose`^ %s favor with `\$Ramius`0.`n", $deathpower);
            }
        }
        if (isset($gravefights) && $gravefights != 0) {
            $session['user']['gravefights'] += $gravefights;
            if ($gravefights > 0) {
                $out[] = sprintf_translate("`^You `@gain`^ %s gravefights.`n", $gravefights);
            } else {
                $deathpower = min(abs($gravefights), $session['user']['gravefights']);
                $out[] = sprintf_translate("`^You `\$lose`^ %s gravefights.`n", $gravefights);
            }
        }
        if (isset($extraflirt) && is_module_active("lovers") && $extraflirt == true && get_module_pref("seenlover", "lovers")) {
            set_module_pref("seenlover", false, "lovers");
            $him = sprintf_translate("him");
            $her = sprintf_translate("her");
            require_once "lib/partner.php";
            $out[] = sprintf_translate("`^You miss %s`^ and want to see %s again.`n", get_partner(), $session['user']['sex'] ? $him : $her);
        }
        if (isset($extratravel) && is_module_active("cities") && $extratravel != 0) {
            increment_module_pref("traveltoday", -$extratravel, "cities");
            if ($extratravel > 0) {
                $out[] = sprintf_translate("`^You feel `@refreshed`^.");
                $out[] = sprintf_translate("`^You may travel %s times `@more`^ today.`n", $extratravel);
            } else {
                $out[] = sprintf_translate("`^You feel `\$tired`^.");
                $out[] = sprintf_translate("`^You may travel %s times `\$less`^ today.`n", $extratravel);
            }
        }
        if (isset($buff) && is_array($buff)) {
            require_once "lib/buffs.php";
            apply_buff("item-{$item['itemid']}", $buff);
            $out[] = sprintf_translate("`^Something feels strange within your body.`n");
        }
        if (isset($extrabuff) && is_array($extrabuff)) {
            require_once "lib/buffs.php";
            while (list($key, $val) = each($extrabuff)) {
                if (has_buff($key)) {
                    while (list($vkey, $vval) = each($val)) {
                        $session['bufflist'][$key][$vkey] += $vval;
                        $things = true;
                    }
                }
            }
            if ($things) {
                $out[] = sprintf_translate("`^You feel something strange happening.`n");
            }
        }
        if (isset($strip)) {
            require_once "lib/buffs.php";
            if (has_buff($strip)) {
                strip_buff($strip);
                $out[] = sprintf_translate("`^You have a weird feeling.`n");
            }
        }
    }
    foreach ($out as $index => $text) {
        if (is_array($text)) {
            foreach ($text as $sec => $text2) {
                $newout[] = $text2;
            }
        } else {
            $newout[] = $text;
        }
    }
    $args = modulehook("itemeffect", array("out" => $newout, "item" => $item));
    $out = $args['out'];
    if (count($out) == 0) {
        if ($noeffecttext == "") {
            $args = modulehook("item-noeffect", array("msg" => "`&Nothing happens.`n", "item" => $item));
            $out[] = sprintf_translate($args['msg']);
        } else {
            if ($giveoutput) {
                $out[] = sprintf_translate($noeffecttext);
            }
        }
    }
    $effect_text = join($out, "");
    tlschema();
    return $effect_text;
}
Exemplo n.º 4
0
			output("`#You advance to level `^".$session[user][level]."`#!`n");
			output("Your maximum hitpoints are now `^".$session[user][maxhitpoints]."`#!`n");
			output("You gain an attack point!`n");
			output("You gain a defense point!`n");
			if ($session['user']['level']<15){
				output("You have a new master.`n");
			}else{
				output("None in the land are mightier than you!`n");
			}
			if ($session['user']['referer']>0 && $session['user']['level']>=4 && $session['user']['refererawarded']<1){
				$sql = "UPDATE accounts SET donation=donation+25 WHERE acctid={$session['user']['referer']}";
				db_query($sql);
				$session['user']['refererawarded']=1;
				systemmail($session['user']['referer'],"`%One of your referrals advanced!`0","`%{$session['user']['name']}`# has advanced to level `^{$session['user']['level']}`#, and so you have earned `^25`# points!");
			}
			increment_specialty();
			addnav("Question Master","train.php?op=question");
			addnav("Challenge Master","train.php?op=challenge");
			if ($session['user']['superuser'] > 2) {
				addnav("Superuser Gain level","train.php?op=challenge&victory=1");
			}
			addnav("Return to the Village","village.php");
			addnews("`%".$session[user][name]."`3 has defeated ".($session[user][sex]?"her":"his")." master, `%$badguy[creaturename]`3 to advance to level `^".$session[user][level]."`3 on ".($session[user][sex]?"her":"his")." `^".ordinal($session[user][age])."`3 day!!");
			$badguy=array();
			$session[user][hitpoints] = $session[user][maxhitpoints];
			//$session[user][seenmaster]=1;
		}else{
			if($defeat){
				//addnav("Daily news","news.php");
				$sql = "SELECT taunt FROM taunts ORDER BY rand(".e_rand().") LIMIT 1";
				$result = db_query($sql) or die(db_error(LINK));
function fairydust_run()
{
    global $session;
    $op = httpget("op");
    $cost = get_module_setting("cost");
    $buff = get_module_setting("buff");
    require_once "lib/increment_specialty.php";
    if ($op == "usebottle") {
        page_header("Fairy Dust");
        output("`%You cautiously unstopper the tiny vial of dust and, holding your breath, tip the contents over your head with your eyes shut.");
        output("A shimmering rain of dust cascades over you!`n`n`^");
        $dust = get_module_pref("fairydustbottles");
        $dust--;
        set_module_pref("fairydustbottles", $dust);
        if ($buff == 1) {
            apply_buff('Fairy Dust', array("name" => "`\$Fairy Dust", "rounds" => 10, "wearoff" => "You have shaken all the dust off.", "defmod" => 1.1, "roundmsg" => "The dust shimmers around you, making you harder to hit!", "schema" => "module-fairydust"));
            output("The dust conceals you from the eyes of enemies!`n`n");
        }
        debuglog("used Fairy Dust");
        switch (e_rand(1, 7)) {
            case 1:
                $extra = get_module_setting("fftoaward");
                if ($extra == 1) {
                    output("You receive an extra forest fight!");
                } else {
                    output("You receive %s extra forest fights!", $extra);
                }
                $session['user']['turns'] += $extra;
                break;
            case 2:
            case 3:
                output("You feel perceptive and notice `%TWO gems`^ nearby!");
                $session['user']['gems'] += 2;
                debuglog("found 2 gem from fairy dust");
                break;
            case 4:
            case 5:
                $hptype = "permanently";
                if (!get_module_setting("carrydk") || is_module_active("globalhp") && !get_module_setting("carrydk", "globalhp")) {
                    $hptype = "temporarily";
                }
                $hptype = translate_inline($hptype);
                $extra = get_module_setting("hptoaward");
                output("Your maximum hitpoints are `b%s`b increased by %d!", $hptype, $extra);
                $session['user']['maxhitpoints'] += $extra;
                $session['user']['hitpoints'] += $extra;
                set_module_pref("extrahps", get_module_pref("extrahps") + $extra);
                break;
            case 6:
            case 7:
                increment_specialty("`^");
                break;
        }
        output("You now have %s bottles of Fairy dust left!", $dust);
        output("`n`nMoments later, you open your eyes, blinking away remnants of glittering dust.");
        addnav("O?Open your Eyes", "forest.php");
    } elseif ($op == "bottlebuy") {
        page_header("Hunter's Lodge");
        output("`7J. C. Petersen turns to you. \"`&A bottle of Fairy Dust costs %s points, and a gem for our suppliers,`7\" he says.  \"`&Will this suit you?`7\"`n`n", $cost);
        addnav("Confirm Fairy Dust Purchase");
        addnav("Yes", "runmodule.php?module=fairydust&op=bottlebuyconfirm");
        addnav("No", "lodge.php");
    } elseif ($op == "bottlebuyconfirm") {
        page_header("Hunter's Lodge");
        addnav("L?Return to the Lodge", "lodge.php");
        $pointsavailable = $session['user']['donation'] - $session['user']['donationspent'];
        if ($pointsavailable >= $cost && $session['user']['gems'] > 0) {
            output("`7J. C. Petersen reaches behind a painting and hands you a tiny vial of shimmering fairy dust. In return you grudgingly give him one of your precious gems.");
            $dust = get_module_pref("fairydustbottles");
            $dust++;
            set_module_pref("fairydustbottles", $dust);
            $session['user']['gems']--;
            $session['user']['donationspent'] += $cost;
        } else {
            if ($pointsavailable < $cost && $session['user']['gems'] < 1) {
                // Missing points and gem
                output("`7J. C. Petersen looks down his nose at you. \"`&I'm sorry, but you do not have the %s points, nor the gem,  required to procure a bottle of fairy dust.  Please return when you do and I'll be happy to sell them to you.`7\"", $cost);
            } elseif ($pointsavailable < $cost) {
                // missing only points
                output("`7J. C. Petersen looks down his nose at you. \"`&I'm sorry, but you do not have the %s points required to procure a bottle of fairy dust.  Please return when you do and I'll be happy to sell them to you.`7\"", $cost);
            } else {
                // missing only gem
                output("`7J. C. Petersen looks down his nose at you. \"`&I'm sorry, but you do not have the gem required to procure a bottle of fairy dust.  Please return when you do and I'll be happy to sell them to you.`7\"");
            }
        }
    }
    page_footer();
}