function es_bridge_gp_dohook($hook, $args)
{
    global $session, $baseaccount;
    $item = httpget('item');
    $action = httpget('action');
    if ($session['user']['armor'] != $baseaccount['armor'] && ($action == 'weararmor' || $action == 'buyarmor') && $session['user']['armor'] == $item) {
        $category = 'armor';
        $defense = $session['user']['defense'];
    } elseif ($session['user']['weapon'] != $baseaccount['weapon'] && ($action == 'wearweapon' || $action == 'buyweapon') && $session['user']['weapon'] == $item) {
        $category = 'weapon';
        $attack = $session['user']['attack'];
    } else {
        $category = false;
    }
    if ($category && get_module_pref($category, 'mysticalshop')) {
        $current_id = get_module_pref($category . 'id', 'mysticalshop');
        debug("Current ID is {$current_id}");
        require_once './modules/mysticalshop/lib.php';
        mysticalshop_destroyitem($category);
        mysticalshop_resetbuffs($current_id);
        require_once './modules/mysticalshop_buffs/stripbuff.php';
        mysticalshop_buffs_stripbuff();
        if ($category == 'armor') {
            $session['user']['defense'] = $defense;
        } else {
            $session['user']['attack'] = $attack;
        }
        debuglog('es_bridge_gp: ' . $category . ' (ID: ' . $current_id . ') item removed on action "' . $action . '".');
    }
    return $args;
}
                     $session['user']['armorvalue'] = 0;
                 } else {
                     if ($cat == 4) {
                         mysticalshop_destroyitem("cloak", $rare);
                     } else {
                         if ($cat == 5) {
                             mysticalshop_destroyitem("helm", $rare);
                         } else {
                             if ($cat == 6) {
                                 mysticalshop_destroyitem("glove", $rare);
                             } else {
                                 if ($cat == 7) {
                                     mysticalshop_destroyitem("boot", $rare);
                                 } else {
                                     if ($cat == 8) {
                                         mysticalshop_destroyitem("misc", $rare);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     mysticalshop_resetbuffs($id);
     //now, refund gold and gems
     $session['user']['gold'] += $sellgold;
     $session['user']['gems'] += $sellgems;
     modulehook("mysticalshop-sell-after", array());
 }
<?php

if (is_numeric($id)) {
    require_once './modules/mysticalshop/lib.php';
    $sql = 'SELECT gold,gems,name FROM ' . db_prefix('magicitems') . ' WHERE id=' . $id . ' LIMIT 1';
    $result = db_query($sql);
    if ($row = db_fetch_assoc($result)) {
        $gold = $row['gold'];
        $gems = $row['gems'];
        $discount = mysticalshop_applydiscount($gold, $gems, $disnum);
        $sellgold = round($gold * 0.75, 0);
        $sellgems = round($gems * 0.25, 0);
        $gem = translate_inline('gem');
        $gem_pl = translate_inline('gems');
        output("`2%s `2contemplates for a moment, then offers you a deal of `^%s gold `2and `%%s %s `2for your `3%s`2.`n`n", $shopkeep, $sellgold, $sellgems, abs($sellgems) != 1 ? $gem_pl : $gem, $row['name']);
        if ($discount) {
            output("`3Thinking that price is much too low, %s`3 reminds you the item is currently being sold at a discounted price, thus your refund is set to match.`n`n", $shopkeep);
        }
        output_notl('`0');
        addnav("Yes", $from . "op=shop&what=sellfinal&id={$id}&cat={$cat}");
        addnav("No", $from . "op=shop&what=enter");
    } else {
        $item_cats = array('ring', 'amulet', 'weapon', 'armor', 'cloak', 'helm', 'glove', 'boot', 'misc');
        output('`2%s`2 tries to understand what you are trying to sell, but fails to see it. You realize that you only imagined having "%s`2" and feel a little embarrassed.`0`n`n', $shopkeep, get_module_pref($item_cats[$cat] . 'name'));
        mysticalshop_destroyitem($item_cats[$cat]);
        addnav('Storefront', $from . 'op=shop&what=enter');
    }
} else {
    output('The item can\'t be sold.');
}
                $session['user']['turns'] -= $row['turns'];
                if (get_module_pref("turnadd") > 0) {
                    set_module_pref("turnadd", get_module_pref("turnadd") - $row['turns']);
                }
            }
            if (get_module_pref("favor") != 0) {
                set_module_pref("res", 0);
                set_module_pref("favor", 0);
                set_module_pref("favoradd", 0);
            }
            $rare = FALSE;
            if (get_module_setting('dkreaddrare') && $row['rare']) {
                $rare = $id;
            }
            require_once "modules/mysticalshop/lib.php";
            mysticalshop_destroyitem($item, $rare);
            if (!$autolose) {
                output_notl('`3%s`0`n', $lose_message[$item]);
            }
        }
    }
}
// --------------------------------Restore Stats--------------------------------
if (get_module_setting('restoreAll') && get_module_pref('restoreIndiv') == 0 || get_module_pref('restoreIndiv') == 1) {
    $buffs = array('attack' => 'attack', 'defense' => 'defense', 'turns' => 'turns', 'favor' => 'deathpower');
    if (!is_module_active('globalhp') || !get_module_setting('carrydk', 'globalhp')) {
        $buffs['hitpoints'] = 'maxhitpoints';
    }
    // don't re-add hitpoints if they are not reset at DK
    // Charm doesn't get reset at DK, no need to restore it.
    require_once "modules/mysticalshop/lib.php";