function mountaccessoriesstamina_dohook($hookname, $args)
{
    global $session, $acc;
    switch ($hookname) {
        case "mountaccessories_apply_accessory":
            require_once "modules/staminasystem/lib/lib.php";
            $numberofbuffs = $acc['numberofstaminabuffs'];
            for ($i = 0; $i <= $numberofbuffs; $i++) {
                apply_stamina_buff($acc['staminabuffref' . $i], array("name" => $acc['staminabuffname' . $i], "action" => $acc['staminabuffaction' . $i], "class" => $acc['staminabuffclass' . $i], "costmod" => $acc['staminabuffcostmod' . $i], "expmod" => $acc['staminabuffexpmod' . $i], "rounds" => $acc['staminabuffrounds' . $i], "roundmsg" => $acc['staminabuffroundmsg' . $i], "wearoffmsg" => $acc['staminabuffwearoffmsg' . $i]));
            }
            break;
        case "mountaccessories_strip_accessory":
            require_once "modules/staminasystem/lib/lib.php";
            $numberofbuffs = $acc['numberofstaminabuffs'];
            for ($i = 0; $i <= $numberofbuffs; $i++) {
                strip_stamina_buff($acc['staminabuffref' . $i]);
            }
            break;
    }
    return $args;
}
function items_weightpenalty_dohook($hookname, $args)
{
    global $session;
    switch ($hookname) {
        case "items_weights":
            require_once "modules/staminasystem/lib/lib.php";
            foreach ($args as $carrier => $prefs) {
                if ($prefs['weight_current'] && $prefs['weight_max'] && $prefs['wlimit_use_sbuff']) {
                    $mult = $prefs['weight_current'] / $prefs['weight_max'];
                    $sbuffid = "wlimit_" . $carrier;
                    if ($mult > 1) {
                        apply_stamina_buff($sbuffid, array("name" => $prefs['wlimit_sbuff_name'], "action" => "Global", "costmod" => $mult, "expmod" => 1, "rounds" => -1, "roundmsg" => $prefs['wlimit_sbuff_roundmsg'], "wearoffmsg" => ""));
                    } else {
                        //debug("stripping buff ".$sbuffid);
                        strip_stamina_buff($sbuffid);
                    }
                }
            }
            break;
    }
    return $args;
}
function iitems_weightandmass_process_weights($applybuffs = false, $showbars = false, $returnlocation = false)
{
    global $session, $weightinfo;
    require_once "modules/iitems/lib/lib.php";
    $inventory = iitems_get_player_inventory();
    $weightinfo = array();
    foreach ($inventory as $key => $values) {
        if ($values['wlimit_capacity']) {
            $weightinfo[$values['inventorylocation']]['max'] += $values['wlimit_capacity'];
            if ($values['wlimit_display_name']) {
                $weightinfo[$values['inventorylocation']]['wlimit_display_name'] = $values['wlimit_display_name'];
            }
            if ($values['wlimit_sbuff_name']) {
                $weightinfo[$values['inventorylocation']]['wlimit_sbuff_name'] = $values['wlimit_sbuff_name'];
            }
            if ($values['wlimit_sbuff_roundmsg']) {
                $weightinfo[$values['inventorylocation']]['wlimit_sbuff_roundmsg'] = $values['wlimit_sbuff_roundmsg'];
            }
            if ($values['wlimit_sbuff_action']) {
                $weightinfo[$values['inventorylocation']]['wlimit_sbuff_action'] = $values['wlimit_sbuff_action'];
            }
            if ($values['wlimit_use_sbuff']) {
                $weightinfo[$values['inventorylocation']]['wlimit_use_sbuff'] = $values['wlimit_use_sbuff'];
            }
            if ($values['wlimit_hardlimit']) {
                $weightinfo[$values['inventorylocation']]['wlimit_hardlimit'] = $values['wlimit_hardlimit'];
            }
        }
        if ($values['quantity']) {
            $weightinfo[$values['inventorylocation']]['current'] += $values['weight'] * $values['quantity'];
        } else {
            $weightinfo[$values['inventorylocation']]['current'] += $values['weight'];
        }
    }
    require_once "modules/staminasystem/lib/lib.php";
    if ($applybuffs) {
        foreach ($weightinfo as $invloc => $details) {
            $sbuffid = "wlimit_" . $invloc;
            if ($details['current'] > $details['max']) {
                if ($details['wlimit_use_sbuff']) {
                    $penalty = $details['current'] / $details['max'];
                    apply_stamina_buff($sbuffid, array("name" => $details['wlimit_sbuff_name'], "action" => $details['wlimit_sbuff_action'], "costmod" => $penalty, "expmod" => 1, "rounds" => -1, "roundmsg" => $details['wlimit_sbuff_roundmsg'], "wearoffmsg" => ""));
                }
            } else {
                strip_stamina_buff($sbuffid);
            }
        }
    }
    if ($showbars) {
        foreach ($weightinfo as $invloc => $details) {
            $cur = $details['current'] * 5;
            $max = $details['max'] * 5;
            $left = $max - $cur;
            if ($left >= 0) {
                rawoutput("<table><tr><td>" . $details['wlimit_display_name'] . "</td><td><table style='border: solid 1px #000000' width='{$max}' height='7' bgcolor='#333333' cellpadding=0 cellspacing=0><tr><td width='{$cur}' bgcolor='#00ff00'></td><td width='{$left}'></td></tr></table></td><td>" . $details['current'] . "kg / " . $details['max'] . "kg</td></tr></table>");
            } else {
                $over = $cur - $max;
                $totalwidth = $max + $over;
                rawoutput("<table><tr><td>" . $details['wlimit_display_name'] . "</td><td><table style='border: solid 1px #000000' height='7' width='{$totalwidth}' cellpadding=0 cellspacing=0><tr><td width='{$max}' bgcolor='#990000'></td><td width='{$over}' bgcolor='#ff0000'></td></tr></table></td><td>" . $details['current'] . "kg / " . $details['max'] . "kg</td></tr></table>");
            }
        }
    }
    if ($returnlocation) {
        return $weightinfo[$returnlocation];
    } else {
        return true;
    }
}