Грешка във файл

beawinner

Registered
някой може ли да ми каже къде е грешката
ето кода

Код:
<?php
/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ *\
|| + Inferno Technologies Software
|| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|| + Product: vB RPG Inferno V2.4 By Zero Tolerance
|| + Null: DGT
|| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|| + Copyright 2004 - 2005 Inferno Technologies
|| + All Rights Reserved
\* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(0);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'inferno');

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by specific actions
$actiontemplates = array(
'Profile' => array(
	'inferno_profile',
),
'Shop' => array(
	'inferno_inv_end',
	'inferno_inv_row',
	'inferno_inv_top',
	'inferno_shop_end',
	'inferno_shop_row',
	'inferno_shop_top',
	'inferno_cat_end',
	'inferno_cat_row',
	'inferno_cat_top',
),
'Bank' => array(
	'inferno_bank',
),
'scan' => array(
	'inferno_scan',
),
'Healing' => array(
	'inferno_heal_inv_end',
	'inferno_heal_inv_row',
	'inferno_heal_inv_top',
	'inferno_heal_main_end',
	'inferno_heal_main_row',
	'inferno_heal_main_top',
),
'Donate' => array(
	'inferno_donate_item',
	'inferno_donate_money',
),
'Equip' => array(
	'inferno_equip_cat_end',
	'inferno_equip_cat_row',
	'inferno_equip_cat_top',
	'inferno_equip_cur_end',
	'inferno_equip_cur_row',
	'inferno_equip_cur_top',
),
'SelectEquip' => array(
	'inferno_equip_do_end',
	'inferno_equip_do_row',
	'inferno_equip_do_top',
),
'Summon' => array(
	'inferno_summon_end',
	'inferno_summon_row',
	'inferno_summon_top',
	'inferno_summon_your_end',
	'inferno_summon_your_row',
	'inferno_summon_your_top',
),
'ScanSummon' => array(
	'inferno_summon_your_scan',
),
'Battle' => array(
	'inferno_battle_main_end',
	'inferno_battle_main_row',
	'inferno_battle_main_top',
),
'CreateBattle' => array(
	'inferno_battle_create_member',
),
'BattleGround' => array(
	'inferno_preload_image',
	'inferno_battle_log_end',
	'inferno_battle_log_row',
	'inferno_battle_log_top',
	'inferno_battle_your_battle',
	'inferno_battle_p1_cell',
	'inferno_battle_p1_bot_cell',
	'inferno_battle_p1_summon_cell',
	'inferno_battle_p2_cell',
	'inferno_battle_p2_bot_cell',
	'inferno_battle_p2_summon_cell',
	'inferno_battle_image_sprite',
),
'ViewBattle' => array(
	'inferno_battle_log_end',
	'inferno_battle_log_row',
	'inferno_battle_log_top',
	'inferno_battle_view_battle',
	'inferno_battle_p1_view_cell',
	'inferno_battle_p1_view_summon_cell',
	'inferno_battle_p2_view_cell',
	'inferno_battle_p2_bot_view_cell',
	'inferno_battle_p2_view_summon_cell',
	'inferno_battle_image_sprite',
),
'ScanMember' => array(
	'inferno_scanm_end',
	'inferno_scanm_equiptop',
	'inferno_scanm_healtop',
	'inferno_scanm_heal_row',
	'inferno_scanm_invrow',
	'inferno_scanm_mini1',
	'inferno_scanm_miniprof',
	'inferno_scanm_statsend',
	'inferno_scanm_top',
	'inferno_scanm_spellsrow',
	'inferno_scanm_spellstop',
),
'BattleWon' => array(
	'inferno_battle_won',
),
'Synthesis' => array(
	'inferno_synthesis_top',
	'inferno_synthesis_row',
	'inferno_synthesis_end',
	'inferno_synthesis_cur_top',
	'inferno_synthesis_cur_row',
	'inferno_synthesis_cur_end',
),
'BuySynthesis' => array(
	'inferno_synthesis_buy_top',
	'inferno_synthesis_buy_row',
	'inferno_synthesis_buy_end',
),
'Clan' => array(
	'inferno_clan_top',
	'inferno_clan_row',
	'inferno_clan_end',
	'inferno_clan_menu',
),
'ViewClan' => array(
	'inferno_clan_view_top',
	'inferno_clan_view_row',
	'inferno_clan_view_end',
	'inferno_clan_menu',
),
'JoinClan' => array(
	'inferno_clan_invite',
	'inferno_clan_menu',
),
'ManageClan' => array(
	'inferno_clan_manage',
	'inferno_clan_menu',
),
'ManageClanMembers' => array(
	'inferno_clan_manage_members_top',
	'inferno_clan_manage_members_row',
	'inferno_clan_manage_members_end',
	'inferno_clan_menu',
),
'InviteMember' => array(
	'inferno_clan_invite_member',
	'inferno_clan_menu',
),
'BuyClan' => array(
	'inferno_clan_buy',
	'inferno_clan_menu',
),
'Jobs' => array(
	'inferno_job_top',
	'inferno_job_row',
	'inferno_job_end',
	'inferno_job_yours_top',
	'inferno_job_yours_row',
	'inferno_job_yours_end',
),
'Lottery' => array(
	'inferno_lottery_top',
	'inferno_lottery_row',
	'inferno_lottery_end',
	'inferno_lottery_buyticket',
	'inferno_lottery_ticket',
),
'Help' => array(
	'inferno_help_top',
	'inferno_help_row',
	'inferno_help_end',
	'inferno_help_search',
),
'ViewHelp' => array(
	'inferno_help_view',
	'inferno_help_search',
),
'DoHelpSearch' => array(
	'inferno_help_top_search',
	'inferno_help_row_h',
	'inferno_help_end',
	'inferno_help_search',
),
'Store' => array(
	'inferno_store_top',
	'inferno_store_row',
	'inferno_store_end',
),
'Auction' => array(
	'inferno_auction_top',
	'inferno_auction_row',
	'inferno_auction_end',
	'inferno_auction_menu',
),
'StartAuction' => array(
	'inferno_auction_start',
	'inferno_auction_menu',
),
'EditAuction' => array(
	'inferno_auction_edit',
	'inferno_auction_menu',
),
'CancelAuction' => array(
	'inferno_auction_cancel',
	'inferno_auction_menu',
),
'ViewAuction' => array(
	'inferno_auction_view_top',
	'inferno_auction_view_row',
	'inferno_auction_view_end',
	'inferno_auction_menu',
),
'AddBid' => array(
	'inferno_auction_addbid',
	'inferno_auction_menu',
),
'EditBid' => array(
	'inferno_auction_editbid',
	'inferno_auction_menu',
),
'CloseAuction' => array(
	'inferno_auction_close_top',
	'inferno_auction_close_row',
	'inferno_auction_close_end',
	'inferno_auction_menu',
),
'Statistics' => array(
	'inferno_statistics_clan_top',
	'inferno_statistics_clan_row',
	'inferno_statistics_clan_end',
	'inferno_statistics_items_top',
	'inferno_statistics_items_row',
	'inferno_statistics_items_end',
	'inferno_statistics_rpgchar3_top',
	'inferno_statistics_rpgchar3_row',
	'inferno_statistics_rpgchar3_end',
	'inferno_statistics_rpgchar2_top',
	'inferno_statistics_rpgchar2_row',
	'inferno_statistics_rpgchar2_end',
	'inferno_statistics_rpgchar_top',
	'inferno_statistics_rpgchar_row',
	'inferno_statistics_rpgchar_end',
	'inferno_stats_top',
	'inferno_stats_row',
	'inferno_stats_end',
),
'MembersList' => array(
	'inferno_memberlist_topletter',
	'inferno_memberlist_top',
	'inferno_memberlist_row',
	'inferno_memberlist_end',
),
'Spells' => array(
	'inferno_spells_top',
	'inferno_spells_row',
	'inferno_spells_end',
	'inferno_spells_inv_top',
	'inferno_spells_inv_row',
	'inferno_spells_inv_end',
),
'TripleTriadShop' => array(
	'inferno_triad_card_inv_top',
	'inferno_triad_card_inv_row',
	'inferno_triad_card_inv_end',
	'inferno_triad_menu',
),
'BuyCard' => array(
	'inferno_triad_card_buycard_top',
	'inferno_triad_card_buycard_row',
	'inferno_triad_card_buycard_end',
	'inferno_triad_menu',
),
'BuyCardPack' => array(
	'inferno_triad_card_buycard_buy',
	'inferno_triad_menu',
),
'DoBuyCardPack' => array(
	'inferno_triad_card_buycard_bought',
	'inferno_triad_menu',
),
'ScanCard' => array(
	'inferno_triad_card_scan',
	'inferno_triad_menu',
),
'ViewCards' => array(
	'inferno_triad_card_view_top',
	'inferno_triad_card_newrow',
	'inferno_triad_card_cell',
	'inferno_triad_card_view_end',
	'inferno_triad_menu',
),
'ViewPlayerDeck' => array(
	'inferno_triad_viewplayer_top',
	'inferno_triad_menu',
),
'TriadTutorial' => array(
	'inferno_triad_tutorial',
	'inferno_triad_menu',
),
'TriadBattle' => array(
	'inferno_triad_battle_top',
	'inferno_triad_battle_member_row',
	'inferno_triad_battle_bot_row',
	'inferno_triad_battle_end',
	'inferno_triad_menu',
),
'CreateTriadBotBattle' => array(
	'inferno_triad_choosecard_cardcell',
	'inferno_triad_battle_create_bot',
	'inferno_triad_menu',
),
'CreateTriadMemberBattle' => array(
	'inferno_triad_choosecard_cardcell',
	'inferno_triad_battle_create_member',
	'inferno_triad_menu',
),
'VerifyChooseCards' => array(
	'inferno_triad_choosecard_cardcell',
	'inferno_triad_battle_accept_member',
),
'TriadCurrentBotBattle' => array(
	'inferno_triad_battleground_bot',
),
'TriadCurrentBattle' => array(
	'inferno_triad_battleground_member',
),
'TriadWon' => array(
	'inferno_triad_battlewon_top',
	'inferno_triad_battlewon_row',
	'inferno_triad_battlewon_end',
),
'ViewTriadBattle' => array(
	'inferno_triad_battleground_member',
),
'ViewTriadBotBattle' => array(
	'inferno_triad_battleground_bot',
),
'SkillPoints' => array(
	'inferno_skillpoints_conversion',
),
'RPGWorld' => array(
	'inferno_rpgworld_map',
	'inferno_rpgworld_menu',
),
'RPGArena' => array(
	'inferno_rpgarena_end',
	'inferno_rpgarena_row',
	'inferno_rpgarena_top',
	'inferno_rpgworld_menu',
),
'JoinMap' => array(
	'inferno_rpgarena_joinmap',
	'inferno_rpgworld_menu',
),
'ViewMap' => array(
	'inferno_rpgarena_viewmap',
	'inferno_rpgworld_menu',
),
'DonateToClan' => array(
	'inferno_clan_donate_members',
	'inferno_clan_menu',
),
'TriadTrade' => array(
	'inferno_triadtrade_end',
	'inferno_triadtrade_row',
	'inferno_triadtrade_top',
	'inferno_triad_menu',
),
'StartTriadTrade' => array(
	'inferno_triadtrade_create',
	'inferno_triad_menu',
),
'ViewTriadTrade' => array(
	'inferno_triadtrade_view_end',
	'inferno_triadtrade_view_row',
	'inferno_triadtrade_view_top',
	'inferno_triad_menu',
),
'AddOffer' => array(
	'inferno_triadtrade_addoffer',
	'inferno_triad_menu',
),
'MemberSearch' => array(
	'inferno_membersearch',
),
'DoMemberSearch' => array(
	'inferno_memberlist_top',
	'inferno_memberlist_row',
	'inferno_memberlist_end',
),
'Hospital' => array(
	'inferno_hospital',
),
'AcceptTradeOffer' => array(
	'inferno_triadtrade_accept_top',
	'inferno_triadtrade_accept_row',
	'inferno_triadtrade_accept_end',
	'inferno_triad_menu',
),
'RPGWorld-Game' => array(
	'inferno_rpgworld_game',
	'inferno_rpgworld_game_load',
	'inferno_rpgworld_game_load_none',
	'inferno_rpgworld_menu',
),
'RPGWorld-Game' => array(
	'inferno_rpgworld_newgame',
	'inferno_rpgworld_menu',
),
);

// pre-cache templates used by all actions O_O
$globaltemplates = array(
	'inferno',
	'inferno_header',
	'inferno_error',
	'inferno_redirect',
	'inferno_x_main',
	'inferno_users_online',
	'inferno_profile',
	'inferno_inv_end',
	'inferno_inv_row',
	'inferno_inv_top',
	'inferno_shop_end',
	'inferno_shop_row',
	'inferno_shop_top',
	'inferno_cat_end',
	'inferno_cat_row',
	'inferno_cat_top',
	'navbar',
	'inferno_triad_menu',
	'inferno_sec_offline',
	'inferno_battle_cells_view_end',
	'inferno_itemshop_params',
);
// insert shop templates for no action in url (stop useless queries)


// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

// Global Requirements & Functions
	require_once('./global.php');
	require_once(DIR . '/includes/functions_user.php');
	require_once(DIR . '/includes/class_bbcode.php');
	require_once(DIR . '/Inferno/system/engine.system.php');
	require_once(DIR . '/includes/functions_legacy.php');

legacy_enable();

$System = new system_engine;


$DB=$db; // What? Its easier to write ^_^;
$DB_site = $DB; // incase i used it anywhere...
$rpg_body=""; // Template Var

// global query
$gmember=$DB->query("select * from inferno_user where rid='{$bbuserinfo['userid']}'");
$member=$DB->fetch_array($gmember);

$GLOBAL_EXP_Need = EXP_Needed_For_Level((intval($member['level'] + 1)));

$rpg_option=$DB->query_first("select * from inferno_options where id='1'");

	function ConfigureLanguage(){
	global $member;

		if($member['gender']=="Male"){
		$language = "his";
		} else if($member['gender']=="Female"){
		$language = "her";
		} else {
		$language = "their";
		}

	return $language;
	}

	function CheckStatLow(){
	// Globalize a function to check stats are NOT negative
	global $DB,$member;

	$member_r=$DB->query_first("select * from inferno_user where gid='{$member['gid']}'");

	$check_stats=array();
	$check_stats[]="hp";
	$check_stats[]="hpm";
	$check_stats[]="mp";
	$check_stats[]="mpm";
	$check_stats[]="str";
	$check_stats[]="def";
	$check_stats[]="vitality";
	$check_stats[]="evasion";

	$do_query=0;
	$build_query="";
		foreach($check_stats as $check){
			if($member_r[$check]<1){
			$member_r[$check]=1;
			$do_query++;
			} else {
			$member_r[$check] = $member_r[$check];
			}

			if($check=="evasion"){ // last stat check
			$build_query.="{$check}='{$member_r[$check]}'"; // no comma
			} else {
			$build_query.="{$check}='{$member_r[$check]}',"; // comma
			}
		}
		if($do_query>0){ // if the stats are not negative or below 1, then no need to execute a useless query
		$DB->query("update inferno_user set {$build_query} where gid='{$member['gid']}'");
		}

	}



	function RunError($message){
	// Theres probably some globals below not in use, uhm, who cares?
	global $bbuserinfo, $session, $stylevar, $_POST, $vbphrase,$navbits,$show,$header;
	global $templatecache, $DB_site, $vboptions, $style,$headinclude,$footer;
	global $tempusagecache, $templateassoc,$pmbox,$rpg_body;

		if($message=="Sorry, this section has been turned offline. Please contact the administrator for more information" && can_moderate()){
		eval('$rpg_body .= "' . fetch_template('inferno_sec_offline') . '";');
		} else {

		$rpg_body = "";

		eval('$rpg_body .= "' . fetch_template('inferno_error') . '";');
		$navbits = construct_navbits($navbits);
		eval('$navbar = "' . fetch_template('navbar') . '";');

		// Inferno header template (global links)
		eval('$rpgheader = "' . fetch_template('inferno_header') . '";');
		eval('print_output("' . fetch_template('inferno') . '");');
		exit;
		}
	}

	function SendPM($message,$title,$to,$from = 0){
	global $vbulletin, $DB;


	$to             = $DB->query_first("select username, userid from ".TABLE_PREFIX."user where userid='{$to}'");
	$DataManager_PM =& datamanager_init('PM', $vbulletin, ERRTYPE_ARRAY); 
	$DataManager_PM->set('fromuserid', $to['userid']); 
	$DataManager_PM->set('fromusername', $to['username']); 
	$DataManager_PM->set('title', $title); 
	$DataManager_PM->set('message', $message); 
	$DataManager_PM->set_recipients($to['username'],$to['permissions']); 
	$DataManager_PM->set('dateline', TIMENOW); 
	$DataManager_PM->save();
	}

// nasty stuff these sql database's
	function ParseInput($val){
	// Cancel Out Number's
		if(is_int($val))
		{
		$val = intval($val);
		return $val;
		} else {
		$val = htmlspecialchars_uni(trim(addslashes($val)));
		return $val;
		}
	}


	function ReturnTurn($turn){
		if($turn=="P1"){$newturn="P2";}else{$newturn="P1";}
	return $newturn;
	}


	function EXP_Needed_For_Level($Level){
	$EXP_Per_Level = 500;
	$EXP_Needed = ($EXP_Per_Level * $Level);
	return $EXP_Needed;
	}


function WinBattle($winner,$loser,$battle,$rage,$exp){
// Theres probably some globals below not in use, uhm, who cares?
global $bbuserinfo, $session, $stylevar, $_POST, $vbphrase,$navbits,$show,$header;
global $templatecache, $DB_site, $vboptions, $style,$headinclude,$footer;
global $tempusagecache, $templateassoc,$DB,$rpg_option;


	// v2.1 --------------------------------
	// Calculate EXP Reward
	// v2.1 --------------------------------

	// Pull Out Required Variables
	$Winner_HP      = $winner['hpm'];
	$Winner_Level   = $winner['level'];
	$Damage_Taken   = $winner['battle_damage'];
	$Opponent_Level = $loser['level'];
	$Summon_Play    = 0;

		// Summon?
		if($Your_Summon = $DB->query_first("select * from inferno_summons_users where sowner='{$winner['gid']}'")){
		$Summon_Play = 1;
		$Damage_Taken = ($Damage_Taken + $Your_Summon['battle_damage']);
		}

	// Calculate EXP Needed To Level Up
	$EXPNeededToLevel = EXP_Needed_For_Level((intval($Winner_Level + 1)));

	// Set Default % Amount Of EXP You Will Gain
	$EXP_Percent_Gain = 10;

	// Calculate Level Difference - Make EXP Percent Gain Alterations (Up or Down)
	$Level_Diff = $Opponent_Level - $Winner_Level;
	$Reversal   = 0;

		if($Level_Diff < 1){
		$Level_Diff = $Winner_Level - $Opponent_Level;
		$Reversal   = 1;
		}

		if(intval($Winner_Level - $Opponent_Level) == 0){
		$Level_Diff = 1;
		}

		if($Reversal == 1){
		$EXP_Percent_Gain = ($EXP_Percent_Gain - (1 * $Level_Diff));

			if($EXP_Percent_Gain < 1){
			$EXP_Percent_Gain = 1;
			}

		} else {
		$EXP_Percent_Gain = ($EXP_Percent_Gain + (1 * $Level_Diff));
		}

	$EXP_Give = (($EXPNeededToLevel / 100) * $EXP_Percent_Gain);

	// Calculate Damage Taken
	$HP_1_Percent     = ($Winner_HP / 100);
	$DMG_Percent      = intval($Damage_Taken / $HP_1_Percent);
		if($DMG_Percent > 80){ $DMG_Percent = 80; }
	$EXP_Final        = intval($EXP_Give * (($DMG_Percent + 20) / 100));

		// Summon?
		if($Summon_Play == 1){
		$EXP_Final = ($EXP_Final / 2);
		$SEXP = ($EXP_Final + $Your_Summon['exp']);
		$Summon_Level = $Your_Summon['level'];
		$SEXPNeededToLevel = EXP_Needed_For_Level((intval($Summon_Level + 1)));
		$SGain = 0;
			// Calculate How Many Levels Gained If Any
			while(($SEXP >= $SEXPNeededToLevel)){
			$SGain++;
			LevelUpSummon($Your_Summon);
			$SEXP = intval($SEXP - $SEXPNeededToLevel);
			$SEXPNeededToLevel = EXP_Needed_For_Level((intval($Summon_Level + ($SGain + 1))));
			}
		$DB->query("update inferno_summons_users set exp='{$SEXP}',battle_damage='0' where sowner='{$winner['gid']}'");
		}
		
	$Total_EXP_Gained = $EXP_Final;
	$EXP_Final        = intval($winner['exp'] + $EXP_Final);

	$Level_Increation = 0;

		// Calculate How Many Levels Gained If Any
		while(($EXP_Final >= $EXPNeededToLevel)){
		$Level_Increation++;
		$EXP_Final = intval($EXP_Final - $EXPNeededToLevel);
		$EXPNeededToLevel = EXP_Needed_For_Level((intval($Winner_Level + ($Level_Increation + 1))));
		}

	// Set Down New Character Data
	$New_Level        = ($Winner_Level + $Level_Increation);
	$New_Skill_Points = ($winner['skill_points'] + ($rpg_option['skill_point_reward'] * $Level_Increation));

	// v2.1 --------------------------------
	// Calculate EXP Reward
	// v2.1 --------------------------------

	// 5% money from hand + 5% money from bank
	$hand_take=$loser['money']/100*5;
	$hand_take=(int)$hand_take;
	$bank_take=$loser['bankmoney']/100*5;
	$bank_take=(int)$bank_take;
	// Send loser battle lost pm
	$messageb="{$winner['name']} has won the battle between you two, it seems he/her were too strong for you to handle. This has resulted in you loosing {$hand_take} {$vbphrase['money']} from your money on hand and {$bank_take} {$vbphrase['money']} from your bank";
	$messageb=ParseInput($messageb);
	$title="You have lost your battle";
	$to=$loser['rid'];
	$from=$winner['rid'];



	SendPM($messageb,$title,$to,$from);
	// Remove battle
	$DB->query("delete from inferno_battle where bid='{$battle['bid']}'");
	// Remove battle logs
	$DB->query("delete from inferno_battlelog where bid='{$battle['bid']}'");
	// Remove players
	$DB->query("update inferno_user set inbattle='0',money=money+'{$hand_take}',bankmoney=bankmoney+'{$bank_take}',rage='{$rage}',exp='{$EXP_Final}',level='{$New_Level}',skill_points='{$New_Skill_Points}',won=won+'1',battle_damage='0' where gid='{$winner['gid']}'");
	$DB->query("update inferno_user set inbattle='0',money=money-'{$hand_take}',bankmoney=bankmoney-'{$bank_take}',hp='0',lost=lost+'1',battle_damage='0' where gid='{$loser['gid']}'");
	$DB->query("update inferno_summons_users set battle_damage='0' where sowner='{$loser['gid']}'");



	// Redirect winner to battle won screen
	$PackUp = array(
			'exp_gain'    => $Total_EXP_Gained,
			'level_gain'  => $Level_Increation,
			);

	// Wrap Up + Convert Outgoind Data
	$PackUp = serialize($PackUp);
	$PackUp = urlencode($PackUp);

	$loser['name'] = ParseInput($loser['name']);
	RunError("<script>parent.location.href='inferno.php?$session[sessionurl]do=BattleWon&lname={$loser['name']}&data={$PackUp}'</script>");


}


function LevelUpSummon($summon){
// Theres probably some globals below not in use, uhm, who cares?
global $bbuserinfo, $session, $stylevar, $_POST, $vbphrase,$navbits,$show,$header;
global $templatecache, $DB_site, $vboptions, $style,$headinclude,$footer;
global $tempusagecache, $templateassoc,$DB;

$n_hp=rand(3,15);
$n_hp=(int)$n_hp;
$n_mp=rand(3,15);
$n_mp=(int)$n_mp;
$n_str=rand(3,15);
$n_str=(int)$n_str;
$n_def=rand(3,15);
$n_def=(int)$n_def;
$n_evasion=rand(0,3);
$n_evasion=(int)$n_evasion;
$n_vitality=rand(0,3);
$n_vitality=(int)$n_vitality;
$DB->query("update inferno_summons_users set hp=hp+'{$n_hp}',hpm=hpm+'{$n_hp}',mp=mp+'{$n_mp}',mpm=mpm+'{$n_mp}',str=str+'{$n_str}',def=def+'{$n_def}',level=level+'1',evasion=evasion+'{$n_evasion}',vitality=vitality+'{$n_vitality}' where suid='{$summon['suid']}'");
}

function WinBotBattle($winner,$loser,$battle,$rage,$exp){
// Theres probably some globals below not in use, uhm, who cares?
global $bbuserinfo, $session, $stylevar, $_POST, $vbphrase,$navbits,$show,$header;
global $templatecache, $DB_site, $vboptions, $style,$headinclude,$footer;
global $tempusagecache, $templateassoc,$DB,$rpg_option;



	// v2.1 --------------------------------
	// Calculate EXP Reward
	// v2.1 --------------------------------

	// Pull Out Required Variables
	$Winner_HP      = $winner['hpm'];
	$Winner_Level   = $winner['level'];
	$Damage_Taken   = $winner['battle_damage'];
	$Opponent_Level = $loser['bot_level'];
	$Summon_Play    = 0;

		// Summon?
		if($Your_Summon = $DB->query_first("select * from inferno_summons_users where sowner='{$winner['gid']}'")){
		$Summon_Play = 1;
		$Damage_Taken = ($Damage_Taken + $Your_Summon['battle_damage']);
		}

	// Calculate EXP Needed To Level Up
	$EXPNeededToLevel = EXP_Needed_For_Level((intval($Winner_Level + 1)));

	// Set Default % Amount Of EXP You Will Gain
	$EXP_Percent_Gain = 10;

	// Calculate Level Difference - Make EXP Percent Gain Alterations (Up or Down)
	$Level_Diff = $Opponent_Level - $Winner_Level;
	$Reversal   = 0;

		if($Level_Diff < 1){
		$Level_Diff = $Winner_Level - $Opponent_Level;
		$Reversal   = 1;
		}

		if(intval($Winner_Level - $Opponent_Level) == 0){
		$Level_Diff = 1;
		}

		if($Reversal == 1){
		$EXP_Percent_Gain = ($EXP_Percent_Gain - (1 * $Level_Diff));

			if($EXP_Percent_Gain < 1){
			$EXP_Percent_Gain = 1;
			}

		} else {
		$EXP_Percent_Gain = ($EXP_Percent_Gain + (1 * $Level_Diff));
		}

	$EXP_Give = (($EXPNeededToLevel / 100) * $EXP_Percent_Gain);

	// Calculate Damage Taken
	$HP_1_Percent     = ($Winner_HP / 100);
	$DMG_Percent      = intval($Damage_Taken / $HP_1_Percent);
		if($DMG_Percent > 80){ $DMG_Percent = 80; }
	$EXP_Final        = intval($EXP_Give * (($DMG_Percent + 20) / 100));

		// Summon?
		if($Summon_Play == 1){
		$EXP_Final = ($EXP_Final / 2);
		$SEXP = ($EXP_Final + $Your_Summon['exp']);
		$Summon_Level = $Your_Summon['level'];
		$SEXPNeededToLevel = EXP_Needed_For_Level((intval($Summon_Level + 1)));
		$SGain = 0;
			// Calculate How Many Levels Gained If Any
			while(($SEXP >= $SEXPNeededToLevel)){
			$SGain++;
			LevelUpSummon($Your_Summon);
			$SEXP = intval($SEXP - $SEXPNeededToLevel);
			$SEXPNeededToLevel = EXP_Needed_For_Level((intval($Summon_Level + ($SGain + 1))));
			}
		$DB->query("update inferno_summons_users set exp='{$SEXP}',battle_damage='0' where sowner='{$winner['gid']}'");
		}
		
	$Total_EXP_Gained = $EXP_Final;
	$EXP_Final        = intval($winner['exp'] + $EXP_Final);

	$Level_Increation = 0;

		// Calculate How Many Levels Gained If Any
		while(($EXP_Final >= $EXPNeededToLevel)){
		$Level_Increation++;
		$EXP_Final = intval($EXP_Final - $EXPNeededToLevel);
		$EXPNeededToLevel = EXP_Needed_For_Level((intval($Winner_Level + ($Level_Increation + 1))));
		}

	// Set Down New Character Data
	$New_Level        = ($Winner_Level + $Level_Increation);
	$New_Skill_Points = ($winner['skill_points'] + ($rpg_option['skill_point_reward'] * $Level_Increation));

	// v2.1 --------------------------------
	// Calculate EXP Reward
	// v2.1 --------------------------------


// Remove battle
$DB->query("delete from inferno_battle where bid='{$battle['bid']}'");
// Remove battle logs
$DB->query("delete from inferno_battlelog where bid='{$battle['bid']}'");
// Remove players
$DB->query("update inferno_user set inbattle='0',money=money+'{$loser['bot_reward']}',won=won+'1',rage='{$rage}',exp='{$EXP_Final}',level='{$New_Level}',skill_points='{$New_Skill_Points}',battle_damage='0' where gid='{$winner['gid']}'");
$DB->query("update inferno_battlebot set bot_inbattle='0',bot_hp=bot_hpm,bot_mp=bot_mpm,bot_loss=bot_loss+'1' where bot_id='{$loser['bot_id']}'");
// Redirect winner to battle won screen
$loser['bot_name']=ParseInput($loser['bot_name']);


	$PackUp = array(
			'exp_gain'    => $Total_EXP_Gained,
			'level_gain'  => $Level_Increation,
			);

	// Wrap Up + Convert Outgoind Data
	$PackUp = serialize($PackUp);
	$PackUp = urlencode($PackUp);


	// Is it a temp bot?
	if($loser['is_temp'] == "yes"){
	// Remove Temp Bot
	$DB->query("delete from inferno_battlebot where bot_id='{$loser['bot_id']}'");
	RunError("<script>parent.location.href='inferno.php?$session[sessionurl]do=RPGWorld-InGame'</script>");
	} else {
	RunError("<script>parent.location.href='inferno.php?$session[sessionurl]do=BattleWon&lname={$loser['bot_name']}&data={$PackUp}'</script>");
	}



}

function LoseBotBattle($loser,$winner,$battle){
// Theres probably some globals below not in use, uhm, who cares?
global $bbuserinfo, $session, $stylevar, $_POST, $vbphrase,$navbits,$show,$header;
global $templatecache, $DB_site, $vboptions, $style,$headinclude,$footer;
global $tempusagecache, $templateassoc,$DB;
// Remove battle
$DB->query("delete from inferno_battle where bid='{$battle['bid']}'");
// Remove battle logs
$DB->query("delete from inferno_battlelog where bid='{$battle['bid']}'");
// Remove players
$DB->query("update inferno_user set inbattle='0',lost=lost+'1',hp='0',battle_damage='0' where gid='{$loser['gid']}'");
$DB->query("update inferno_battlebot set bot_inbattle='0',bot_hp=bot_hpm,bot_mp=bot_mpm,bot_vics=bot_vics+'1' where bot_id='{$winner['bot_id']}'");

	// Is it a temp bot?
	if($winner['is_temp'] == "yes"){
	// Remove Temp Bot
	$DB->query("delete from inferno_battlebot where bot_id='{$winner['bot_id']}'");
	RunError("<script>alert('You lost your battle with {$winner['bot_name']}');parent.location.href='inferno.php?$session[sessionurl]do=RPGWorld-InGame'</script>");
	} else {
	RunError("<script>alert('You lost your battle with {$winner['bot_name']}');parent.location.href='inferno.php?$session[sessionurl]do=Battle'</script>");
	}
}



	$navbits= array();
	$navbits[""]= "";

if (!$vbulletin->userinfo['userid'])
{
	RunError("RPG Inferno is not available to guests. Please login or <a href='register.php'>Register</a>");
}


if($member['rid']=="" && $_GET['do']!='DoProfile' && $_GET['do']!='Help'){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
	$navbits= array("inferno.php?$session[sessionurl]do=Profile" => "Creating Profile");
	$navbits[""]= "RPG Profile";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['rpgcp_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

// need to create rpg profile
// grab elements
$elements="";
$gete=$DB->query("select * from inferno_element order by eid");
while($element=$DB->fetch_array($gete)){
if($element['eid']==$member['element']){
$elements.="<option value='{$element['eid']}' strength='{$element['strength']}' weakness='{$element['weakness']}' str='{$element['estr']}' hp='{$element['ehp']}' mp='{$element['emp']}' def='{$element['edef']}' img='{$element['img']}' effect='{$element['effect']}' selected>{$element['element']}</option>";
} else {
$elements.="<option value='{$element['eid']}' strength='{$element['strength']}' weakness='{$element['weakness']}' str='{$element['estr']}' hp='{$element['ehp']}' mp='{$element['emp']}' def='{$element['edef']}' img='{$element['img']}' effect='{$element['effect']}'>{$element['element']}</option>";
}}
// Create Drops For Av Height/Width
$avh="";
$avw="";
for($d=0;$d<=$rpg_option['max_avh'];$d++){
$avh.="<option value='{$d}'>{$d}</option>";
}
for($d=0;$d<=$rpg_option['max_avw'];$d++){
$avw.="<option value='{$d}'>{$d}</option>";
}

$rpg_avatars="<option value='CustomAvatar'>Use Own Settings</option>";
$get_av_cats=$DB->query("select * from inferno_rpgavatar_gallery_cats order by catname");
while($cat=$DB->fetch_array($get_av_cats)){
$Cats[]=$cat;
}

$get_av=$DB->query("select * from inferno_rpgavatar_gallery order by avname");
while($avatars_i = $DB->fetch_array($get_av)){
$all_avatars[] = $avatars_i;
}

if($Cats[0]){
	foreach($Cats as $av_cat){
	$rpg_avatars.="<optgroup label='{$av_cat['catname']}'>";

		foreach($all_avatars as $av){
			if($av['avcat']==$av_cat['acid']){
				if($member['avatar']==$vboptions[bburl].'/Inferno/Avatar_Gallery/'.$av['avurl']){
				$rpg_avatars.="<option value='{$vboptions[bburl]}/Inferno/Avatar_Gallery/{$av['avurl']}' selected>{$av['avname']}</option>";
				} else {
				$rpg_avatars.="<option value='{$vboptions[bburl]}/Inferno/Avatar_Gallery/{$av['avurl']}'>{$av['avname']}</option>";
				}
			}
		}
	}
}


	eval('$rpg_body .= "' . fetch_template('inferno_profile') . '";');
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
// Inferno header template (global links)
eval('$rpgheader = "' . fetch_template('inferno_header') . '";');
eval('$rpg_body .= "' . fetch_template('inferno_x_main') . '";');
eval('print_output("' . fetch_template('inferno') . '");');
}

function UpdateLocation($act){
global $DB,$rpg_option,$member;
$_SERVER['QUERY_STRING']=ParseInput($_SERVER['QUERY_STRING']);
$DB->query("update inferno_user set rpg_location='{$_SERVER['QUERY_STRING']}',time_location='".time()."' where gid='{$member['gid']}'");
}


// ############################ NO ACTION ################################

if (!$_GET['do'] || $_GET['do']=="") {
	$_GET['do'] = "Shop";
}

$InfernoPerms = convert_bits_to_array($vbulletin->userinfo['permissions']['infernopermissions'], $vbulletin->bf_ugp['infernopermissions']);

if (!$InfernoPerms['canuseinferno'])
{
	RunError('You\'re usergroup does not have access to use RPG Inferno.');
}


// No RPG Name?
if($member['name']=="" && $_GET['do']!='DoProfile' && $_GET['do']!='Help' && $_GET['do']!='Profile'){
	$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Profile Error");
	$navbits[""]= "Profile Error";
RunError("Your RPG Name is currently blank. Please go to the <a href='inferno.php?$session[sessionurl]do=Profile'>RPG CP</a> to fix this");
}



// ######################### Functions Array #############################
// Action
$Action=$_GET['do'];
if($Action=="Profile"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// RPG Profile
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
	$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Updating RPG Profile");
	$navbits[""]= "RPG Profile";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['rpgcp_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

// grab elements
$elements="";
$gete=$DB->query("select * from inferno_element order by eid");
while($element=$DB->fetch_array($gete)){
if($element['eid']==$member['element']){
$elements.="<option value='{$element['eid']}' strength='{$element['strength']}' weakness='{$element['weakness']}' str='{$element['estr']}' hp='{$element['ehp']}' mp='{$element['emp']}' def='{$element['edef']}' img='{$element['img']}' effect='{$element['effect']}' selected>{$element['element']}</option>";
} else {
$elements.="<option value='{$element['eid']}' strength='{$element['strength']}' weakness='{$element['weakness']}' str='{$element['estr']}' hp='{$element['ehp']}' mp='{$element['emp']}' def='{$element['edef']}' img='{$element['img']}' effect='{$element['effect']}'>{$element['element']}</option>";
}}
// Create Drops For Av Height/Width
$avh="";
$avw="";
for($d=0;$d<=$rpg_option['max_avh'];$d++){
	if($d==$member['ah']){
	$avh.="<option value='{$d}' selected>{$d}</option>";
	} else {
	$avh.="<option value='{$d}'>{$d}</option>";
	}
}
for($d=0;$d<=$rpg_option['max_avw'];$d++){
	if($d==$member['aw']){
	$avw.="<option value='{$d}' selected>{$d}</option>";
	} else {
	$avw.="<option value='{$d}'>{$d}</option>";
	}
}

$rpg_avatars="<option value='CustomAvatar'>Use Own Settings</option>";
$get_av_cats=$DB->query("select * from inferno_rpgavatar_gallery_cats order by catname");
while($cat=$DB->fetch_array($get_av_cats)){
$Cats[]=$cat;
}

$get_av=$DB->query("select * from inferno_rpgavatar_gallery order by avname");
while($avatars_i = $DB->fetch_array($get_av)){
$all_avatars[] = $avatars_i;
}

if($Cats[0]){
	foreach($Cats as $av_cat){
	$rpg_avatars.="<optgroup label='{$av_cat['catname']}'>";

		foreach($all_avatars as $av){
			if($av['avcat']==$av_cat['acid']){
				if($member['avatar']==$vboptions[bburl].'/Inferno/Avatar_Gallery/'.$av['avurl']){
				$rpg_avatars.="<option value='{$vboptions[bburl]}/Inferno/Avatar_Gallery/{$av['avurl']}' selected>{$av['avname']}</option>";
				} else {
				$rpg_avatars.="<option value='{$vboptions[bburl]}/Inferno/Avatar_Gallery/{$av['avurl']}'>{$av['avname']}</option>";
				}
			}
		}
	}
}

eval('$rpg_body .= "' . fetch_template('inferno_profile') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// RPG Profile
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="DoProfile"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// RPG Profile [Add/Update]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
	$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "RPG Profile Updated");
	$navbits[""]= "RPG Profile";

if($_POST['name']==""){
RunError("You did not enter a character name. Please go back and enter one");
}

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['rpgcp_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

// ++++++++++++
// Parse Inputs
// ++++++++++++
$_POST['element']=ParseInput($_POST['element']);
$_POST['aw']=ParseInput($_POST['aw']);
$_POST['ah']=ParseInput($_POST['ah']);
$_POST['name']=ParseInput($_POST['name']);
$_POST['smove']=ParseInput($_POST['smove']);
$_POST['gender']=ParseInput($_POST['gender']);
$_POST['align']=ParseInput($_POST['align']);
$_POST['avatar']=ParseInput($_POST['avatar']);
$_POST['rpg_avatar_gallery']=ParseInput($_POST['rpg_avatar_gallery']);
// ++++++++++++
// Parse Inputs
// ++++++++++++

// Checking RPG Name...
if($check_name=$DB->query_first("select * from inferno_user where name='{$_POST['name']}'")){
// check it isn't you :P
if($check_name['gid']!=$member['gid']){
RunError("This RPG Name has already been chosen, please choose another");
}
}

// Possible Errors --
if($_POST['aw']>$rpg_option['max_avw'] || $_POST['ah']>$rpg_option['max_avh']){
RunError("Sorry but your inputted values for either avatar width/height are beyond the set limits");
}
if($member['inbattle']>0){
RunError("You are in battle, you cannot change your profile");
}

// using from rpg avatar gallery?
if($_POST['rpg_avatar_gallery']!="CustomAvatar"){
// determine image dimensions
$_POST['rpg_avatar_gallery']=str_replace(' ','%20',$_POST['rpg_avatar_gallery']);

$size=@getimagesize($_POST['rpg_avatar_gallery']);


$_POST['aw']=$size[0];
$_POST['ah']=$size[1];
$_POST['avatar']=$_POST['rpg_avatar_gallery'];
}

// connect to element selected
$gelm=$DB->query("select * from inferno_element where eid='{$_POST['element']}'");
$theelement=$DB->fetch_array($gelm);
if($member['rid']==""){
// Add New Row [oh god =( ]
// elemental selection - stats increase
// new peeps first
$nhp=100;
$nhpm=100;
$nmp=100;
$nmpm=100;
$nstr=30;
$ndef=30;
$nhp+=$theelement['ehp'];
$nhpm+=$theelement['ehp'];
$nmp+=$theelement['emp'];
$nmpm+=$theelement['emp'];
$nstr+=$theelement['estr'];
$ndef+=$theelement['edef'];
$DB->query("insert into inferno_user values('',
'".$bbuserinfo[userid]."',
'{$rpg_option['new_characer_money']}',
'0',
'',
'0',
'0',
'0',
'0',
'0',
$nhp,
$nhpm,
$nmp,
$nmpm,
$nstr,
$ndef,
'0',
'0',
'0',
'".$_POST['element']."',
'0',
'0',
'0',
'".$_POST['aw']."',
'".$_POST['ah']."',
'0',
'',
'0',
'',
'".$_POST['name']."',
'".$_POST['smove']."',
'',
'".$_POST['gender']."',
'".$_POST['align']."',
'".$_POST['avatar']."',
'',
'0',
'0',
'{$Action}',
'".time()."',
'15',
'15',
'',
'0',
'no',
'0',
'0')");
} else {
// connect to old element - remove those stats
$gelmo=$DB->query("select * from inferno_element where eid='{$member['element']}'");
$oldelement=$DB->fetch_array($gelmo);
$member['hp']-=$oldelement['ehp'];
$member['hpm']-=$oldelement['ehp'];
$member['mp']-=$oldelement['emp'];
$member['mpm']-=$oldelement['emp'];
$member['str']-=$oldelement['estr'];
$member['def']-=$oldelement['edef'];
// Increase stats from new selected element (even if it aint new, just cancels it out :P)
// connect to element selected
$gelm=$DB->query("select * from inferno_element where eid='{$_POST['element']}'");
$theelement=$DB->fetch_array($gelm);
$member['hp']+=$theelement['ehp'];
$member['hpm']+=$theelement['ehp'];
$member['mp']+=$theelement['emp'];
$member['mpm']+=$theelement['emp'];
$member['str']+=$theelement['estr'];
$member['def']+=$theelement['edef'];

// Yay!, just update XD
$DB->query("update inferno_user set avatar='{$_POST['avatar']}',aw='{$_POST['aw']}',ah='{$_POST['ah']}',align='{$_POST['align']}',smove='{$_POST['smove']}',gender='".$_POST['gender']."',name='".$_POST['name']."',element='".$_POST['element']."',hp='{$member['hp']}',hpm='{$member['hpm']}',mp='{$member['mp']}',mpm='{$member['mpm']}',str='{$member['str']}',def='{$member['def']}' where rid='".$bbuserinfo['userid']."'");
}
// Redirect Bitch!
$message="RPG Profile Updated!";
$url="inferno.php?$session[sessionurl]do=Profile";
	eval('$rpg_body .= "' . fetch_template('inferno_redirect') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// RPG Profile [Add/Update]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($Action=='Shop') {
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Itemshop
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
	$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Buy Items");
	$navbits[""]= "Itemshop";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['itemshop_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

$View_Options = false;
$Display      = $_GET['display'];

	if($Display == 'buyonly'){
	$YCID = $DB->query_first("select jid from inferno_jobs where jname='{$member['class']}'");
	$YCID = $YCID['jid'];
	}

$cache_upgrade=array(); // Why reload what we already have? O_o
$myitem=array();

// Call Inventory Top
	eval('$rpg_body .= "' . fetch_template('inferno_inv_top') . '";');

// Call Inventory Row
	$inv_row=$DB->query("select u.*,s.*,i.*
	from inferno_stock s
	left join inferno_items i on(i.id=s.item_id)
	left join inferno_synthesis u on(u.sid=s.upgrade_id)
	where s.member_id='".$member['gid']."'");
	while ($items = $DB->fetch_array($inv_row)) {
	$myitem[]=$items;
	}
	// display items with upgrade
if($myitem[0]){ // member has any items? [if not cancel out foreach()]
	foreach($myitem as $the_item){
		// upgrade?
		if($the_item['upgrade_id']>0){
		$the_item['the_upgrade']=$the_item['sname'];
		} else {
		$the_item['the_upgrade']="<i>None</i>";
		}
	$the_item['Sell']=(int)$the_item['cost']/3;
	$the_item['Sell']=floor($the_item['Sell']);
	$the_item['Sell']=number_format($the_item['Sell']);
	$items=$the_item; // clarify var
	eval('$rpg_body .= "' . fetch_template('inferno_inv_row') . '";');
	
	}
}
// Call Inventory End
	eval('$rpg_body .= "' . fetch_template('inferno_inv_end') . '";');

$CatAll=array();

$all=$DB->query("select * from inferno_cat order by cid");
// step 1 - array cats
$all_items = 0;
$all_sold = 0;
$all_profit = 0;
while($cat=$DB->fetch_array($all)){
$CatAll[$cat['cid']]=$cat;
$all_items+=$cat['citems'];
$all_sold+=$cat['csold'];
$all_profit+=$cat['cprofit'];
}

$all_items = number_format($all_items);
$all_sold = number_format($all_sold);
$all_profit = number_format($all_profit);

$all_profit.=" {$vbphrase['money']}";

	if($_GET['showshop']){

// select all items (saves mass queries for tons of categories)
$get_all_items = $DB->query("select * from inferno_items order by cost");
while($all_i = $DB->fetch_array($get_all_items)){
$AllItems[]=$all_i;
}

if($_GET['showshop']=="all_shops"){
// --- Show All Shops ---

$View_Options = true;



// step 2 - paste shops
if(is_array($CatAll)){
	foreach($CatAll as $TheCat){
	// - relay shop top
	$cats=$TheCat;
		eval('$rpg_body .= "' . fetch_template('inferno_shop_top') . '";');
	// - relay shop items
		if(is_array($AllItems)){
			foreach($AllItems as $items){
				if($items['type']==$TheCat['cid']){

					if($Display == 'buyonly'){
					$Check = $System->CanBuyItem($items,$YCID);
					} else {
					$Check = 1 == 1;
					}

					if($member['money'] >= $items['cost']){
					$items['BuyLink']="<a href='?$session[sessionurl]do=BuyItem&id={$items['id']}'>Buy</a>";
					} else {
					$items['BuyLink']="<a disabled=true href='javascript:;' title='Not Enough {$vbphrase[money]} To Buy This Item'>Buy</a>";
					}
				$items['cost']=number_format($items['cost']);

					if($Check){
					eval('$rpg_body .= "' . fetch_template('inferno_shop_row') . '";');
					}
				}
			}
		}

	// - relay shop bottom
		eval('$rpg_body .= "' . fetch_template('inferno_shop_end') . '";');
	}
}


// --- Show All Shops ---
} else {

// Grab Shop From DB
	$cats=$CatAll[$_GET['showshop']];
	if($cats['cname']!=""){ // Cat Exists

	$View_Options = true;

// Call Shop Top
	eval('$rpg_body .= "' . fetch_template('inferno_shop_top') . '";');
// Call Shop Cat/All Cats + Items (If Selected)
	if(is_array($AllItems)){
		foreach($AllItems as $items){
			if($items['type']==$_GET['showshop']){

				if($Display == 'buyonly'){
				$Check = $System->CanBuyItem($items,$YCID);
				} else {
				$Check = 1 == 1;
				}

				if($member['money'] >= $items['cost']){
				$items['BuyLink']="<a href='?$session[sessionurl]do=BuyItem&id={$items['id']}'>Buy</a>";
				} else {
				$items['BuyLink']="<a disabled=true href='javascript:;' title='Not Enough {$vbphrase[money]} To Buy This Item'>Buy</a>";
				}
			$items['cost']=number_format($items['cost']);
			
				if($Check){
				eval('$rpg_body .= "' . fetch_template('inferno_shop_row') . '";');
				}
			}
		}
	}
// Call Shop Bottom
	eval('$rpg_body .= "' . fetch_template('inferno_shop_end') . '";');
	}}}

// Call Shop Cats Top
	eval('$rpg_body .= "' . fetch_template('inferno_cat_top') . '";');

	if($View_Options){
	eval('$rpg_body = str_replace("<{ITEMSHOP_PARAMS}>","' . fetch_template('inferno_itemshop_params') . '",$rpg_body);');
	} else {
	$rpg_body = str_replace("<{ITEMSHOP_PARAMS}>","",$rpg_body);
	}

// Call Shop Cats Row
if(is_array($CatAll)){
	foreach($CatAll as $thecats){
	$thecats['csold']=number_format($thecats['csold']);
	$thecats['cprofit']=number_format($thecats['cprofit']);
	$thecats['citems']=number_format($thecats['citems']);
	eval('$rpg_body .= "' . fetch_template('inferno_cat_row') . '";');
	}
}
// Call Shop Cats Bottom
	eval('$rpg_body .= "' . fetch_template('inferno_cat_end') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Itemshop
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="BuyItem"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Buy Item [actually]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
	$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Buying Item");
	$navbits[""]= "Itemshop";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['itemshop_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

// Check item exists
$gitem=$DB->query("select * from inferno_items where id='{$_GET['id']}'");
$item=$DB->fetch_array($gitem);
if($item['id']==""){
RunError("The item you have requested was not found, please check the link you have clicked");
}

// Can you actually afford this item?
if(($member['money']-$item['cost']) < 0){
RunError("The item you have requested is too expensive for you to buy at this moment");
}

// have the required stats
if($item['level']>$member['level'] || $item['hp_require']>$member['hpm'] || $item['mp_require']>$member['mpm'] || $item['str_require']>$member['str'] || $item['def_require']>$member['def'] || $item['vit_require']>$member['vitality'] || $item['eva_require']>$member['evasion']){
RunError("You do not meet the requirements to handle this item. Please <a href='inferno.php?$session[sessionurl]do=scan&id={$item['id']}'>Scan</a> the item to see the requirements needed.");
}

// not out of stock?
if($item['stock']<1){
RunError("This item is currently out of stock. Please call again when we have some more in stock");
}


// Your Class = Allowed?
$Your_Class = $DB->query_first("select * from inferno_jobs where jname = '{$member['class']}'");

$Allowed = explode("|",$item['class_allow']);
$Allow = 0;

	if(is_array($Allowed)){
		foreach($Allowed as $jid){
			if($jid == $Your_Class['jid']){
			$Allow++;
			}
		}
	}

	if($Allow == 0){
	RunError("Sorry but this item cannot be used by your class.");
	}

	

// already own?
$runx=$DB->query("select * from inferno_stock where item_id='{$item['id']}' and member_id='{$member['gid']}'");
$your_items=$DB->fetch_array($runx);
if($your_items['uid']!=""){
RunError("You already own this item");
}

// take money
$DB->query("update inferno_user set money=money-'{$item['cost']}' where gid='{$member['gid']}'");
// insert into inventory
$DB->query("insert into inferno_stock values('','{$item['id']}','{$member['gid']}','0')");

// update cat statistics
$DB->query("update inferno_cat set csold=csold+'1',cprofit=cprofit+'{$item['cost']}' where cid='{$item['type']}'");
$DB->query("update inferno_items set sold=sold+'1',stock=stock-'1' where id='{$item['id']}'");

// ok, no problems, get the hell out of here O.o
$message="Item {$item['name']} Successfully Purchased";
$url="inferno.php?showshop={$item['type']}";
	eval('$rpg_body .= "' . fetch_template('inferno_redirect') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Buy Item [actually]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="sellitem"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Sell Item
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
	$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Selling Item");
	$navbits[""]= "Itemshop";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['itemshop_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

// Check item exists
$gitem=$DB->query("select * from inferno_items where id='{$_GET['id']}'");
$item=$DB->fetch_array($gitem);
if($item['id']==""){
RunError("The item you have requested was not found, please check the link you have clicked");
}
// Check you own the item
$runx=$DB->query("select * from inferno_stock where item_id='{$item['id']}' and member_id='{$member['gid']}'");
$your_items=$DB->fetch_array($runx);
if($your_items['uid']==""){
RunError("You do not own this item to sell");
}
// you put item in an auction?
if($auction=$DB->query_first("select * from inferno_auction where item='{$item['id']}' and owner='{$member['gid']}'")){
RunError("The item you are trying to sell is currently in an auction you are running, please close or cancel the auction first");
}
// upgraded?
if($your_items['upgrade_id']>0){
RunError("Please remove any upgrades to an item before selling it.");
}
// Give Money (3rd)
$sell=(int)$item['cost']/3;
$sell=floor($sell);
$DB->query("update inferno_user set money=money+'".$sell."' where gid='{$member['gid']}'"&#41
 
Ето и другите части

Код:
// Remove item from stock
$DB->query("delete from inferno_stock where item_id='{$item['id']}' and member_id='{$member['gid']}'");
// equipped? - take stats down - remove record
$eq=$DB->query("select * from inferno_equip where the_item='{$item['id']}' and the_owner='{$member['gid']}'");
$the_x_equip=$DB->fetch_array($eq);
if($the_x_equip['xid']!=""){
// so you have it equipped, muahaha take it away!!
$DB->query("update inferno_user set hp=hp-'{$item['hp']}',hpm=hpm-'{$item['hp']}',mp=mp-'{$item['mp']}',mpm=mpm-'{$item['mp']}',str=str-'{$item['str']}',def=def-'{$item['def']}' where gid='{$member['gid']}'");
// remove record
$DB->query("delete from inferno_equip where the_item='{$item['id']}' and the_owner='{$member['gid']}'");
// Thats it neo, spin around, kick his ass, then go eat lunch <--------- WTF? 0.o
CheckStatLow();
}
// cat stats
$DB->query("update inferno_cat set csold=csold-'1',cprofit=cprofit-'{$item['cost']}' where cid='{$item['type']}'");



// Redirect ^_^
$message="Item {$item['name']} Sold";
$url="inferno.php";
	eval('$rpg_body .= "' . fetch_template('inferno_redirect') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Sell Item
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="scan"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Scan Item
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
	$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Scanning Item");
	$navbits[""]= "Itemshop";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['itemshop_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

// Check item exists
$gitem=$DB->query("select i.*,c.*
from inferno_items i
left join inferno_cat c on(i.type=c.cid)
where i.id='{$_GET['id']}'");
$item=$DB->fetch_array($gitem);
if($item['id']==""){
RunError("The item you have requested was not found, please check the link you have clicked");
}


$get_jobs = $DB->query("select * from inferno_jobs");
while($tjob = $DB->fetch_array($get_jobs)){
$AllJobs[$tjob['jid']] = $tjob;
}


	$classes = explode("|",$item['class_allow']);
	$class_allow = "";
		if(is_array($classes)){
			foreach($classes as $a_c){
				$class_allow .= "{$AllJobs[$a_c]['jname']}, ";
			}
		}
		if($class_allow == ""){
		$class_allow = "<i>None</i>";
		} else {
		$class_allow = substr($class_allow,0,-2);
		}


		if($member['money'] >= $item['cost']){
		$item['BuyLink']="<a href='?$session[sessionurl]do=BuyItem&id={$item['id']}'>Buy</a>";
		} else {
		$item['BuyLink']="<a disabled=true href='javascript:;' title='Not Enough {$vbphrase[money]} To Buy This Item'>Buy</a>";
		}
	eval('$rpg_body .= "' . fetch_template('inferno_scan') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Scan Item
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}

	if($rpg_option['check_interest']=="global"){
	// Do we have interest? - Give em it before they see anything o_o (sneaky)
	$intrest   = $rpg_option['bankinterest'];
	$rate      = $rpg_option['banktime'];
	$lastvisit = $member['lastvisit'];
	$bankmoney = $member['bankmoney'];
	$nowtime   = time();

	// Have we been good and left bank to gain interest?
	$checktime = $nowtime-$lastvisit;

		if($checktime > $rate){

			// Bank Loan - Yes/No? - Disable Interest - Yes/No?
			if($BankLoan = $DB->query_first("select * from inferno_bankloans where l_user='{$member['gid']}'")){
			$hasloan = 1;
			} else {
			$hasloan = 0;
			}

			if($hasloan == 0 || $rpg_option[bank_loan_disable] == 0){
			$addintrest = $bankmoney/100*$intrest;
			$addintrest = (int)$addintrest;
			$addintrest = $addintrest+$bankmoney;
			$DB->query("UPDATE inferno_user SET bankmoney='{$addintrest}', lastvisit='{$nowtime}' WHERE rid='{$member['rid']}'");

				if($_GET['do']=="Bank"){ // only needed for bank
				// Reconnect to member (to get updated data)
				$gmember = $DB->query("select * from inferno_user where rid='{$bbuserinfo['userid']}'");
				$member  = $DB->fetch_array($gmember);
				}
			}
		}
	}

if($_GET['do']=="Bank"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Bank Main
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
	$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Bank");
	$navbits[""]= "Bank";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['bank_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

	// Bank Loan - Yes/No?
	if($BankLoan = $DB->query_first("select * from inferno_bankloans where l_user='{$member['gid']}'")){
	$hasloan = 1;
	$BankLoan['l_payback'] = vbdate($vboptions['dateformat'], $BankLoan['l_payback']) . ", " . vbdate($vboptions['timeformat'], $BankLoan['l_payback']);

		if($rpg_option[bank_loan_disable]){
		$member['timeXX'] = "<i>Disabled - Bank Loan Active</i>";
		}

	} else {
	$hasloan = 0;
	}

if($rpg_option['check_interest']=="bank"){
// Do we have interest? - Give em it before they see anything o_o (sneaky)
$intrest=$rpg_option['bankinterest'];
$rate=$rpg_option['banktime'];
$lastvisit=$member['lastvisit'];
$bankmoney=$member['bankmoney'];
$nowtime=time();

// Have we been good and left bank to gain interest?
$checktime=$nowtime-$lastvisit;
if($checktime > $rate){
$addintrest=$bankmoney/100*$intrest;
$addintrest=(int)$addintrest;
$addintrest=$addintrest+$bankmoney;

	// Bank Loan Active? Don't Give The Interest
	if($hasloan == 0 || $rpg_option[bank_loan_disable] == 0){
	$DB->query("UPDATE inferno_user SET bankmoney='{$addintrest}', lastvisit='{$nowtime}' WHERE rid='{$member['rid']}'");
	// Reconnect to member (to get updated data)
	$gmember=$DB->query("select * from inferno_user where rid='{$bbuserinfo['userid']}'");
	$member=$DB->fetch_array($gmember);
	}
}}


$bankmoney=$member['bankmoney'];
// [Calculate Time Untill Next Payment]
$diff = time()-$member['lastvisit'];
$diff = $rate-$diff;
$daysDiff = floor($diff/60/60/24);
$diff -= $daysDiff*60*60*24;
$hrsDiff = floor($diff/60/60);
$diff -= $hrsDiff*60*60;
$minsDiff = floor($diff/60);
$diff -= $minsDiff*60;
$secsDiff = $diff;
$tdays=$daysDiff;
$thrs=$hrsDiff;
$tmins=$minsDiff;
$tsecs=$secsDiff;
$addeth=$bankmoney/100*$intrest;
$addeth=(int)$addeth;
$addeth=number_format($addeth);
$timer ="{$tdays} days, ".$thrs." hours, ".$tmins." minutes and ".$tsecs." seconds until next payment of {$addeth} {$vbphrase['money']}";

	if($hasloan == 0 || $rpg_option[bank_loan_disable] == 0){
	$member['timeXX']=$timer;
	}

// -- Bank Stats --
$bank['clients']=0;
$bank['total_own']=0;
$allx=$DB->query("select * from inferno_user where rid>0 and bankmoney>0");
while($renderM=$DB->fetch_array($allx)){
$bank['clients']++;
$bank['total_own']+=$renderM['bankmoney'];
}
if($member['bankmoney'] < 1){ $member['acc_set']="Offline"; }else{ $member['acc_set']="Online";}
// -- Bank Stats --

// Parse Members Money
$member['money']=number_format($member['money']);
$member['bankmoney']=number_format($member['bankmoney']);
$bank['clients']=number_format($bank['clients']);
$bank['total_own']=number_format($bank['total_own']);



// Spit out bank html :P
eval('$rpg_body .= "' . fetch_template('inferno_bank') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Bank Main
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}


if($_GET['do']=="Loan"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Bank [Loan]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
	$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Bank");
	$navbits[""]= "Bank";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['bank_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

	// Bank Loan - Yes/No?
	if($BankLoan = $DB->query_first("select * from inferno_bankloans where l_user='{$member['gid']}'")){
	RunError("You already have a bank loan currently active. You must pay off that loan before applying for a new one.");
	}

$Loan = intval($_POST['loan']);
$Max  = $rpg_option['bank_loan_maximum'];

	if($Loan > $Max){
	RunError("The maximum loan amount is {$Max} {$vbphrase[money]}. You may not take a loan out larger than this amount.");
	}

	if($Loan < 1){
	RunError("You cannot loan under 1 {$vbphrase[money]}.");
	}

	if($member['bankmoney'] < 0){
	RunError("Your bank funds are currently negative, you may not take out a loan while in this state.");
	}

$Rate     = $rpg_option['bank_loan_interest'];
$Payback  = intval(($Loan / 100) * $Rate) + $Loan;
$Deadline = $rpg_option['bank_loan_payback'];
$Deadline = (60 * 60 * 24) * $Deadline;
$Deadline = time() + $Deadline;

$DB->query("insert into inferno_bankloans (l_amount,l_user,l_payback) values ($Payback,$member[gid],$Deadline)");
$DB->query("update inferno_user set bankmoney=bankmoney+{$Loan} where gid='{$member['gid']}'");

$message = "You have successfully loaned {$Loan} {$vbphrase[money]}";
$url     = "inferno.php?$session[sessionurl]do=Bank";
eval('$rpg_body .= "' . fetch_template('inferno_redirect') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Bank [Loan]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}


if($_GET['do']=="LoanPayback"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Bank [Loan Payback]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
	$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Bank");
	$navbits[""]= "Bank";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['bank_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

	// Bank Loan - Yes/No?
	if(!$BankLoan = $DB->query_first("select * from inferno_bankloans where l_user='{$member['gid']}'")){
	RunError("You do not have any active bank loans to payback.");
	}

$Payback = intval($_POST['payback']);

	if($Payback < 1){
	RunError("You must pay atleast 1 {$vbphrase[money]} back.");
	}

	if($Payback > $BankLoan['l_amount']){
	RunError("You are trying to payback more than you have to.");
	}

	if($Payback > $member['bankmoney']){
	RunError("You have insufficient funds within your bank to payback this amount.");
	}

$NewAmount = ($BankLoan['l_amount'] - $Payback);
$NewBMoney = ($member['bankmoney']  - $Payback);

	if($NewAmount == 0){ // Loan Paid Off
	$Msg = "You have successfully paid off your loan.";
	$DB->query("delete from inferno_bankloans where l_user='{$member['gid']}'");
	} else {
	$Msg = "You have successfully paid back {$Payback} {$vbphrase[money]} off your loan.";
	$DB->query("update inferno_bankloans set l_amount='{$NewAmount}' where l_user='{$member['gid']}'");
	}

$DB->query("update inferno_user set bankmoney='{$NewBMoney}' where gid='{$member['gid']}'");

$message = $Msg;
$url     = "inferno.php?$session[sessionurl]do=Bank";
eval('$rpg_body .= "' . fetch_template('inferno_redirect') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Bank [Loan Payback]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}


// ######()()()()()()()()()()() == Thank you for reading this comment, it has wasted approx 3 seconds of your life =D
if($_GET['do']=="deposit"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Deposit Money
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
	$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Bank");
	$navbits[""]= "Deposit Money"; // MONEH!!! 0.o

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['bank_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

$deposit=$_POST['deposit'];
$deposit=str_replace (",", "", $deposit);
$deposit=(int)$deposit;

// your not trying to screw about are you?
if($member['money']-$deposit < 0){
// I don't think so, heh
RunError("Sorry, your trying to deposit more than you own, please go back and check the values you inputted");
}
if($deposit<1){
RunError("Your not depositing anything, enter a value higher than 0");
}
if($deposit==""){
RunError("No value entered, please go back and check the values you inputted");
}
// Ok lets deposit :)
$money=$member['money']-$deposit;
// one last check ^_^
if($money < 0){
RunError("Sorry, your trying to deposit more than you own, please go back and check the values you inputted");
}
// ok were gonna do it now XD
$DB->query("update inferno_user set money=money-'{$deposit}',bankmoney=bankmoney+'{$deposit}',lastvisit='".time()."' where rid='{$member['rid']}'");
// redirect needed :)
$message="{$vbphrase['money']} Deposited Successfully";
$url="inferno.php?$session[sessionurl]do=Bank";
	eval('$rpg_body .= "' . fetch_template('inferno_redirect') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Deposit Money
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="withdraw"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Withdraw Money
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
	$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Bank");
	$navbits[""]= "Withdraw Money"; // MONEH!!! 0.o

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['bank_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

$withdraw=$_POST['withdraw'];
$withdraw=str_replace (",", "", $withdraw);
$withdraw=(int)$withdraw;

// your not trying to screw about are you?
if($member['bankmoney']-$withdraw < 0){
// I don't think so, heh
RunError("Sorry, your trying to withdraw more than you have inside the bank, please go back and check the values you inputted");
}
if($withdraw<1){
RunError("Your not withdrawing anything, enter a value higher than 0");
}
if($withdraw==""){
RunError("No value entered, please go back and check the values you inputted");
}
// Ok lets withdraw :)
$money=$member['bankmoney']-$withdraw;
// one last check ^_^
if($money < 0){
RunError("Sorry, your trying to withdraw more than you have inside the bank, please go back and check the values you inputted");
}
// ok were gonna do it now XD
$DB->query("update inferno_user set money=money+'{$withdraw}',bankmoney=bankmoney-'{$withdraw}',lastvisit='".time()."' where rid='{$member['rid']}'");
// redirect needed :)
$message="{$vbphrase['money']} Withdrew Successfully";
$url="inferno.php?$session[sessionurl]do=Bank";
	eval('$rpg_body .= "' . fetch_template('inferno_redirect') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Withdraw Money
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="ScanMember"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Scan Member
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
	$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Scan Member");
	$navbits[""]= "Scanning Members RPG Profile";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['scan_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

// check member has rpg profile
// - wait, are you scanning yourself? O_o
if($_GET['id']==$member['rid']){
$themember=$member; // why the fuck should we run a query we did already..huh? 0_o'
} else {
if(!$themember=$DB->query_first("select * from inferno_user where rid='{$_GET['id']}'")){
RunError("Sorry but no RPG Profile was found for this member. They havn't made one or the id you have inputted is incorrect.");
}
}


$themember['EXP_Need'] = EXP_Needed_For_Level((intval($themember['level'] + 1)));

// member exists - draw up form
if($themember['name']==""){$themember['name']="<i>No Name</i>";}
// Player Stats
// HP Bar
$hp = $themember['hp'];
$hpm= $themember['hpm'];
$hpa= $hp/$hpm;
$hpa= $hpa*100;
$themember['hpd']=$hpa;
// MP Bar
$mp = $themember['mp'];
$mpm= $themember['mpm'];
$mpa= $mp/$mpm;
$mpa= $mpa*100;
$themember['mpd']=$mpa;
// DEF Bar
$def= $themember['def'];
$defm=$hpm;
$defa=$def/$defm;
$defa=$defa*100;
$themember['defd']=$defa;
// STR Bar
$str= $themember['str'];
$strm=$hpm;
$stra=$str/$strm;
$stra=$stra*100;
$themember['strd']=$stra;
if($themember['strd'] > 100){
$themember['strd']=100;
}
if($themember['defd'] > 100){
$themember['defd']=100;
}
$gelm=$DB->query("select * from inferno_element where eid='{$themember['element']}'");
$theelm=$DB->fetch_array($gelm);
if($theelm['element']!=""){
$themember['element']="<img src='Inferno/elements/{$theelm['img']}' alt='{$theelm['element']}'>";
} else {
$themember['element']="<i>No Element</i>";
}
if($themember['status']==""){$themember['status']="<i>None</i>";}
// Top
eval('$rpg_body .= "' . fetch_template('inferno_scanm_top') . '";');
// Mini Profile

// clan?
if($themember['inclan']==0 || !$themember['inclan']>0){
$themember['intheclan']="<i>None</i>";
} else {
// connect to clan
$theclan=$DB->query_first("select * from inferno_clan where cid='{$themember['inclan']}'");
$themember['intheclan']="<a href='inferno.php?$session[sessionurl]do=ViewClan&cid={$theclan['cid']}'>{$theclan['cname']}</a>";
}

// -- RPG Avatar --
if($themember['avatar']!=""){
$RPav="<img src='{$themember['avatar']}' alt='{$themember['name']}' width='{$themember['aw']}' height='{$themember['ah']}'>";
} else {
$RPav="<i><b>No Avatar Selected</b></i>";
}
eval('$rpg_body .= "' . fetch_template('inferno_scanm_miniprof') . '";');
// Mini1 (From Mini-Prof To Inv)
eval('$rpg_body .= "' . fetch_template('inferno_scanm_mini1') . '";');
// Get Inventory

$cache_upgrade=array(); // because there are lots or Mr. Smiths =D

// +++++++++++++++++
// Upgrades Inament?
// +++++++++++++++++
// Call Inventory Row
	$inv_row=$DB->query("select u.*,s.*,i.*
	from inferno_stock s
	left join inferno_items i on(i.id=s.item_id)
	left join inferno_synthesis u on(u.sid=s.upgrade_id)
	where s.member_id='".$themember['gid']."'");
	while ($items = $DB->fetch_array($inv_row)) {
	$myitem[]=$items;
	}
	// display items with upgrade
if($myitem[0]){ // member has any items? [if not cancel out foreach()]
	foreach($myitem as $the_item){
		// upgrade?
		if($the_item['upgrade_id']>0){
		$the_item['the_upgrade']=$the_item['sname'];
		} else {
		$the_item['the_upgrade']="<i>None</i>";
		}
	$item=$the_item; // clarify var
	eval('$rpg_body .= "' . fetch_template('inferno_scanm_invrow') . '";');
	}
}

$cache_heal=array(); // yeeees mr smith again =D

$gpot=$DB->query("select * from inferno_heal order by cost");
while($heal=$DB->fetch_array($gpot)){
$all_heal[$heal['hid']]=$heal;
}

// Move to healing - top first
eval('$rpg_body .= "' . fetch_template('inferno_scanm_healtop') . '";');

if(intval($themember['heal1'])>0 && $themember['heal1']!="" && !preg_match("/(\d+)_(\d+)/",$themember['heal1'])){

$heal1=$all_heal[$themember['heal1']];
} else if(preg_match("/(\d+)_(\d+)/",$themember['heal1'])){
// Fused Healing Potion

$prime_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$1",$themember['heal1'])];
$secon_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$2",$themember['heal1'])];

$heal1 = array(
	'img'     => $prime_heal['img'],
	'name'    => "{$prime_heal['name']} Fused With {$secon_heal['name']}",
	'desc'    => $prime_heal['desc'],
	'hid'     => "{$prime_heal['hid']}_{$secon_heal['hid']}",
	'ability' => $prime_heal['ability'],
	'hp'      => ($prime_heal['hp'] + $secon_heal['hp']),
	'mp'      => ($prime_heal['mp'] + $secon_heal['mp']),
	'cost'    => ($prime_heal['cost'] + $secon_heal['cost']),
	);

}

if(intval($themember['heal2'])>0 && $themember['heal2']!="" && !preg_match("/(\d+)_(\d+)/",$themember['heal2'])){
$heal2=$all_heal[$themember['heal2']];
} else if(preg_match("/(\d+)_(\d+)/",$themember['heal2'])){
// Fused Healing Potion

$prime_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$1",$themember['heal2'])];
$secon_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$2",$themember['heal2'])];

$heal2 = array(
	'img'     => $prime_heal['img'],
	'name'    => "{$prime_heal['name']} Fused With {$secon_heal['name']}",
	'desc'    => $prime_heal['desc'],
	'hid'     => "{$prime_heal['hid']}_{$secon_heal['hid']}",
	'ability' => $prime_heal['ability'],
	'hp'      => ($prime_heal['hp'] + $secon_heal['hp']),
	'mp'      => ($prime_heal['mp'] + $secon_heal['mp']),
	'cost'    => ($prime_heal['cost'] + $secon_heal['cost']),
	);

}

if(intval($themember['heal3'])>0 && $themember['heal3']!="" && !preg_match("/(\d+)_(\d+)/",$themember['heal3'])){
$heal3=$all_heal[$themember['heal3']];
} else if(preg_match("/(\d+)_(\d+)/",$themember['heal3'])){
// Fused Healing Potion

$prime_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$1",$themember['heal3'])];
$secon_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$2",$themember['heal3'])];

$heal3 = array(
	'img'     => $prime_heal['img'],
	'name'    => "{$prime_heal['name']} Fused With {$secon_heal['name']}",
	'desc'    => $prime_heal['desc'],
	'hid'     => "{$prime_heal['hid']}_{$secon_heal['hid']}",
	'ability' => $prime_heal['ability'],
	'hp'      => ($prime_heal['hp'] + $secon_heal['hp']),
	'mp'      => ($prime_heal['mp'] + $secon_heal['mp']),
	'cost'    => ($prime_heal['cost'] + $secon_heal['cost']),
	);

}

	if($heal1){
	$heal=$heal1;
	eval('$rpg_body .= "' . fetch_template('inferno_scanm_heal_row') . '";');
	}

	if($heal2){
	$heal=$heal2;
	eval('$rpg_body .= "' . fetch_template('inferno_scanm_heal_row') . '";');
	}

	if($heal3){
	$heal=$heal3;
	eval('$rpg_body .= "' . fetch_template('inferno_scanm_heal_row') . '";');
	}


// Move to equipped items - top first
eval('$rpg_body .= "' . fetch_template('inferno_scanm_equiptop') . '";');
// Select Currently Equipped Items From Database


// +++++++++++++++++
// Upgrades Inament?
// +++++++++++++++++
// Call Inventory Row
	$inv_row=$DB->query("select e.*,i.*,u.*,s.*
	from inferno_equip e
	left join inferno_stock s on(s.item_id=e.the_item and s.member_id=e.the_owner)
	left join inferno_items i on(i.id=e.the_item)
	left join inferno_synthesis u on(u.sid=s.upgrade_id)
	where e.the_owner='{$themember['gid']}'");
	while ($items = $DB->fetch_array($inv_row)) {
	$myequip[]=$items;
	}
	// display items with upgrade
if($myequip[0]){ // member has any items? [if not cancel out foreach()]
	foreach($myequip as $theitem){
	// grab item

	$the_item = $theitem;

		// upgrade?
		if($the_item['upgrade_id']>0){
		$the_item['the_upgrade']=$the_item['sname'];
		} else {
		$the_item['the_upgrade']="<i>None</i>";
		}
	$item=$the_item; // clarify var
	eval('$rpg_body .= "' . fetch_template('inferno_scanm_invrow') . '";');
	}
}

// Spells =D
// Move to spells - top first
eval('$rpg_body .= "' . fetch_template('inferno_scanm_spellstop') . '";');
// ok now row :P
$get_spells=$DB->query("select spell.*,spell_inventory.* from inferno_spells_inventory spell_inventory left join inferno_spells spell on (spell.sid=spell_inventory.spell) where spell_inventory.spell_owner='{$themember['gid']}' order by spell.mp_cost");
while($spell=$DB->fetch_array($get_spells)){
eval('$rpg_body .= "' . fetch_template('inferno_scanm_spellsrow') . '";');
}


// Player statistics hp/mp....
eval('$rpg_body .= "' . fetch_template('inferno_scanm_statsend') . '";');
// End scan page
eval('$rpg_body .= "' . fetch_template('inferno_scanm_end') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Scan Member
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="Equip"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Equip Items [Main Screen]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
	$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Equip");
	$navbits[""]= "Equip Your Character";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['equip_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

$cache_upgrade=array();
// Top Table [Equip Cat Selection]
eval('$rpg_body .= "' . fetch_template('inferno_equip_cat_top') . '";');
// Select Cats To Equip From
	$cats=$DB->query("select * from inferno_cat");
	while ($thecats = $DB->fetch_array($cats)) {
	eval('$rpg_body .= "' . fetch_template('inferno_equip_cat_row') . '";');
	}
// End category selection for equipping
eval('$rpg_body .= "' . fetch_template('inferno_equip_cat_end') . '";');


// Top Table [Currently Equipped Items]
eval('$rpg_body .= "' . fetch_template('inferno_equip_cur_top') . '";');
// Select Currently Equipped Items From Database
// +++++++++++++++++
// Upgrades Inament?
// +++++++++++++++++
// Call Inventory Row
	$inv_row=$DB->query("select e.*,i.*,u.*,s.*
	from inferno_equip e
	left join inferno_stock s on(s.item_id=e.the_item and s.member_id=e.the_owner)
	left join inferno_items i on(i.id=e.the_item)
	left join inferno_synthesis u on(u.sid=s.upgrade_id)
	where e.the_owner='{$member['gid']}'");
	while ($items = $DB->fetch_array($inv_row)) {
	$myequip[]=$items;
	}
	// display items with upgrade
if($myequip[0]){ // member has any items? [if not cancel out foreach()]
	foreach($myequip as $theitem){
	// grab item

	$the_item = $theitem;

		// upgrade?
		if($the_item['upgrade_id']>0){
		$the_item['the_upgrade']=$the_item['sname'];
		} else {
		$the_item['the_upgrade']="<i>None</i>";
		}
	$item=$the_item; // clarify var
	eval('$rpg_body .= "' . fetch_template('inferno_equip_cur_row') . '";');
	}
}
// End Table [Currently Equipped Items]
eval('$rpg_body .= "' . fetch_template('inferno_equip_cur_end') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Equip Items [Main Screen]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="SelectEquip"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Equip Items [Choose Equip]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
	$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Equip From Category");
	$navbits[""]= "Equip Your Character";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['equip_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

// Check Category Exists
if(!$TheCat=$DB->query_first("select * from inferno_cat where cid='{$_GET['Cat']}'")){
RunError("The category you have specified doesn't seem to be inside the database. Please check the url");
}
// Already Equipped From This Category?
if($DB->query_first("select * from inferno_equip where the_cat='{$_GET['Cat']}' and the_owner='{$themember['gid']}'")){
RunError("Sorry but it seems you have already equipped an item from this category, please unequip it first"); // Loser!!! XD
}
// Seems ok, lets get your items ^_^
// Table Top
eval('$rpg_body .= "' . fetch_template('inferno_equip_do_top') . '";');
// Grab Your Inventory - From This Cat


// +++++++++++++++++
// Upgrades Inament?
// +++++++++++++++++
// Call Inventory Row
	$inv_row=$DB->query("select i.*,u.*,s.*
	from inferno_stock s
	left join inferno_items i on(i.id=s.item_id)
	left join inferno_synthesis u on(u.sid=s.upgrade_id)
	where s.member_id='{$member['gid']}' and i.type='{$TheCat['cid']}'");
	while ($items = $DB->fetch_array($inv_row)) {
	$myequip[]=$items;
	}
	// display items with upgrade
if($myequip[0]){ // member has any items? [if not cancel out foreach()]
	foreach($myequip as $theitem){
	// grab item
	$the_item = $theitem;

		// upgrade?
		if($the_item['upgrade_id']>0){
		// get upgrade
		$the_item['the_upgrade']=$the_item['sname'];
		} else {
		$the_item['the_upgrade']="<i>None</i>";
		}
	$item=$the_item; // clarify var
	eval('$rpg_body .= "' . fetch_template('inferno_equip_do_row') . '";');
	}
}

// Aaaaaaaaaaand end the table =P
eval('$rpg_body .= "' . fetch_template('inferno_equip_do_end') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Equip Items [Choose Equip]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="DoEquip"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Equip Items [Do Equip]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
	$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Equipping Character");
	$navbits[""]= "Equip Your Character";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['equip_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

if($member['inbattle']>0){
RunError("You cannot equip items during battle");
}

// Check Item Exixts (Also need var for below ;D)
if(!$item=$DB->query_first("select * from inferno_items where id='{$_GET['id']}'")){
RunError("You are trying to equip a none existant item. Check the url you have followed");
}
// Check Your Own This Item
if(!$own=$DB->query_first("select * from inferno_stock where item_id='{$item['id']}' and member_id='{$member['gid']}'")){
RunError("The item you are trying to equip you do not own"); // *cough* Yeah nice try
}
// you put item in an auction?
if($auction=$DB->query_first("select * from inferno_auction where item='{$item['id']}' and owner='{$member['gid']}'")){
RunError("The item you are trying to equip is currently in an auction you are running, please close or cancel the auction first");
}
// Check you havn't equipped from this category
if($DB->query_first("select * from inferno_equip where the_cat='{$item['type']}' and the_owner='{$member['gid']}'")){
RunError("Sorry but it seems you have already equipped an item from this category, please unequip it first"); // Loser!!! XD
}
// Ok - your a good boy - lets build you up

// record equip
$DB->query("insert into inferno_equip values('','{$item['id']}','{$member['gid']}','{$item['type']}')");
// Increase Your Stats
$DB->query("update inferno_user set hp=hp+'{$item['hp']}',hpm=hpm+'{$item['hp']}',mp=mp+'{$item['mp']}',mpm=mpm+'{$item['mp']}',str=str+'{$item['str']}',def=def+'{$item['def']}',vitality=vitality+'{$item['vitality']}',evasion=evasion+'{$item['evasion']}' where gid='{$member['gid']}'");
// upgraded item?
if($own['upgrade_id']>0){
$synthesis=$DB->query_first("select * from inferno_synthesis where sid='{$own['upgrade_id']}'");
if($synthesis['sid']!=""){
// Increase Your Stats [upgrade]
$DB->query("update inferno_user set hp=hp+'{$synthesis['shp']}',hpm=hpm+'{$synthesis['shp']}',mp=mp+'{$synthesis['smp']}',mpm=mpm+'{$synthesis['smp']}',str=str+'{$synthesis['sstr']}',def=def+'{$synthesis['sdef']}',vitality=vitality+'{$synthesis['svitality']}',evasion=evasion+'{$synthesis['sevasion']}' where gid='{$member['gid']}'");
}
}

CheckStatLow();

// Redirect
$message="{$item['name']} Successfully Equipped";
$url="inferno.php?$session[sessionurl]do=Equip";
	eval('$rpg_body .= "' . fetch_template('inferno_redirect') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Equip Items [Do Equip]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="Unequip"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Equip Items [Unequip]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
	$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Equipping Character");
	$navbits[""]= "Equip Your Character";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['equip_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

if($member['inbattle']>0){
RunError("You cannot unequip items during battle");
}

// Check Item Exixts (Also need var for below ;D)
if(!$item=$DB->query_first("select * from inferno_items where id='{$_GET['id']}'")){
RunError("You are trying to unequip a none existant item. Check the url you have followed");
}
// Check Your Own This Item
if(!$own=$DB->query_first("select * from inferno_stock where item_id='{$item['id']}' and member_id='{$member['gid']}'")){
RunError("The item you are trying to unequip you do not own"); // *cough* Yeah nice try
}
// Check item is equipped
if(!$DB->query_first("select * from inferno_equip where the_cat='{$item['type']}' and the_owner='{$member['gid']}' and the_item='{$item['id']}'")){
RunError("You do not own this item to unequip. Check the url you have followed"); // Loser!!! XD
}
// Ok - your a good boy - lets build you up

// remove record
$DB->query("delete from inferno_equip where the_item='{$item['id']}' and the_owner='{$member['gid']}'");
// Decrease Your Stats
$DB->query("update inferno_user set hp=hp-'{$item['hp']}',hpm=hpm-'{$item['hp']}',mp=mp-'{$item['mp']}',mpm=mpm-'{$item['mp']}',str=str-'{$item['str']}',def=def-'{$item['def']}',vitality=vitality-'{$item['vitality']}',evasion=evasion-'{$item['evasion']}' where gid='{$member['gid']}'");
// upgraded item?
if($own['upgrade_id']>0){
$synthesis=$DB->query_first("select * from inferno_synthesis where sid='{$own['upgrade_id']}'");
if($synthesis['sid']!=""){
// Decrease Your Stats [upgrade]
$DB->query("update inferno_user set hp=hp-'{$synthesis['shp']}',hpm=hpm-'{$synthesis['shp']}',mp=mp-'{$synthesis['smp']}',mpm=mpm-'{$synthesis['smp']}',str=str-'{$synthesis['sstr']}',def=def-'{$synthesis['sdef']}',vitality=vitality-'{$synthesis['svitality']}',evasion=evasion-'{$synthesis['sevasion']}' where gid='{$member['gid']}'");
}
}
CheckStatLow();
// Redirect
$message="{$item['name']} Successfully Unequipped";
$url="inferno.php?$session[sessionurl]do=Equip";
	eval('$rpg_body .= "' . fetch_template('inferno_redirect') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Equip Items [Unequip]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="Healing"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Healing Center [Main]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
	$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Healing Center");
	$navbits[""]= "Heal Your Character";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['healing_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

// Query Reduction Program
// Potions
$gpot=$DB->query("select * from inferno_heal order by cost");
while($heal=$DB->fetch_array($gpot)){
$all_heal[$heal['hid']]=$heal;
}

if($member['status']==""){$member['status']="<i>None</i>";}

// Table Top [Heal Inv]
eval('$rpg_body .= "' . fetch_template('inferno_heal_inv_top') . '";');
// Your Healing

if(intval($member['heal1'])>0 && $member['heal1']!="" && !preg_match("/(\d+)_(\d+)/",$member['heal1'])){

$heal1=$all_heal[$member['heal1']];
} else if(preg_match("/(\d+)_(\d+)/",$member['heal1'])){
// Fused Healing Potion

$prime_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$1",$member['heal1'])];
$secon_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$2",$member['heal1'])];

$heal1 = array(
	'img'     => $prime_heal['img'],
	'name'    => "{$prime_heal['name']} Fused With {$secon_heal['name']}",
	'desc'    => $prime_heal['desc'],
	'hid'     => "{$prime_heal['hid']}_{$secon_heal['hid']}",
	'ability' => $prime_heal['ability'],
	'hp'      => ($prime_heal['hp'] + $secon_heal['hp']),
	'mp'      => ($prime_heal['mp'] + $secon_heal['mp']),
	'cost'    => ($prime_heal['cost'] + $secon_heal['cost']),
	);

}

if(intval($member['heal2'])>0 && $member['heal2']!="" && !preg_match("/(\d+)_(\d+)/",$member['heal2'])){
$heal2=$all_heal[$member['heal2']];
} else if(preg_match("/(\d+)_(\d+)/",$member['heal2'])){
// Fused Healing Potion

$prime_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$1",$member['heal2'])];
$secon_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$2",$member['heal2'])];

$heal2 = array(
	'img'     => $prime_heal['img'],
	'name'    => "{$prime_heal['name']} Fused With {$secon_heal['name']}",
	'desc'    => $prime_heal['desc'],
	'hid'     => "{$prime_heal['hid']}_{$secon_heal['hid']}",
	'ability' => $prime_heal['ability'],
	'hp'      => ($prime_heal['hp'] + $secon_heal['hp']),
	'mp'      => ($prime_heal['mp'] + $secon_heal['mp']),
	'cost'    => ($prime_heal['cost'] + $secon_heal['cost']),
	);

}

if(intval($member['heal3'])>0 && $member['heal3']!="" && !preg_match("/(\d+)_(\d+)/",$member['heal3'])){
$heal3=$all_heal[$member['heal3']];
} else if(preg_match("/(\d+)_(\d+)/",$member['heal3'])){
// Fused Healing Potion

$prime_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$1",$member['heal3'])];
$secon_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$2",$member['heal3'])];

$heal3 = array(
	'img'     => $prime_heal['img'],
	'name'    => "{$prime_heal['name']} Fused With {$secon_heal['name']}",
	'desc'    => $prime_heal['desc'],
	'hid'     => "{$prime_heal['hid']}_{$secon_heal['hid']}",
	'ability' => $prime_heal['ability'],
	'hp'      => ($prime_heal['hp'] + $secon_heal['hp']),
	'mp'      => ($prime_heal['mp'] + $secon_heal['mp']),
	'cost'    => ($prime_heal['cost'] + $secon_heal['cost']),
	);

}

$InInv = 0;

	if($heal1)
	{
	$heal=$heal1;
	$heal['sell']=(int)$heal['cost']/3;
	$heal['sell']=floor($heal['sell']);
	eval('$rpg_body .= "' . fetch_template('inferno_heal_inv_row') . '";');
	$InInv++;
	}
	if($heal2)
	{
	$heal=$heal2;
	$heal['sell']=(int)$heal['cost']/3;
	$heal['sell']=floor($heal['sell']);
	eval('$rpg_body .= "' . fetch_template('inferno_heal_inv_row') . '";');
	$InInv++;
	}
	if($heal3)
	{
	$heal=$heal3;
	$heal['sell']=(int)$heal['cost']/3;
	$heal['sell']=floor($heal['sell']);
	eval('$rpg_body .= "' . fetch_template('inferno_heal_inv_row') . '";');
	$InInv++;
	}
// End Heal Inv Table
eval('$rpg_body .= "' . fetch_template('inferno_heal_inv_end') . '";');

	$prime_fuse = "";
	$secon_fuse = "";

	if(is_array($all_heal)){
		foreach($all_heal as $heal){
		$prime_fuse .= "<option value='{$heal['hid']}'>{$heal['name']}</option>";
		$secon_fuse .= "<option value='{$heal['hid']}'>{$heal['name']}</option>";
		}
	}

	$MultiBuy = array(
			'2' => 0,
			'3' => 0,
	);

	if($InInv == 0){
	$MultiBuy['2'] = 1;
	$MultiBuy['3'] = 1;
	} else if($InInv == 1){
	$MultiBuy['2'] = 1;
	}

// Buy Healing
eval('$rpg_body .= "' . fetch_template('inferno_heal_main_top') . '";');
	// Potions
	if(is_array($all_heal)){
		foreach($all_heal as $heal){
		eval('$rpg_body .= "' . fetch_template('inferno_heal_main_row') . '";');
		}
	}
// end table [and then yawn 0.o]
eval('$rpg_body .= "' . fetch_template('inferno_heal_main_end') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Healing Center [Main]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="BuyHeal"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Healing Center [Buy]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
	$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Healing Center");
	$navbits[""]= "Buying Potion";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['healing_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

$multi = intval($_GET['multi']);

	if($multi < 1){
	$multi = 1;
	}

	if($multi > 3){
	$multi = 3;
	}

// Now lets take ya through a crash course of possible errors or stunts you may try to pull XD
// in battle?
if($member['inbattle']>0){
RunError("You are in battle, you may not buy any more Healing Potions");
}
// 1st up, does the healing item exist?
// Check Item Exixts (Also need var for below ;D)
if(!$heal=$DB->query_first("select * from inferno_heal where hid='{$_GET['id']}'")){
RunError("You are trying to buy a none existant potion. Check the url you have followed");
}
// ok - now check you have enough money =D
if($member['money']-$heal['cost']<0){
RunError("Sorry, but this potion costs more {$vbphrase['money']} than you have on hand. Try withdrawing from your bank or waiting untill you get more {$vbphrase['money']}");
}
// already own 3 healing items?
if($member['heal1']!="0" && $member['heal2']!="0" && $member['heal3']!="0"){
if($member['heal1']!="" && $member['heal2']!="" && $member['heal3']!=""){
RunError("You already own 3 healing potions, this is the max you can hold at any given time");
}}
// hmm, ok you pass =D

// into which heal?
if($member['heal1']=="" || $member['heal1']=="0"){
// this one!!
$DB->query("update inferno_user set heal1='{$heal['hid']}' where gid='{$member['gid']}'");
} elseif($member['heal2']=="" || $member['heal2']=="0"){
// no this one!!!
$DB->query("update inferno_user set heal2='{$heal['hid']}' where gid='{$member['gid']}'");
} elseif($member['heal3']=="" || $member['heal3']=="0"){
// no this one!!!
$DB->query("update inferno_user set heal3='{$heal['hid']}' where gid='{$member['gid']}'");
} else {
// uhh sorry bud
RunError("You already own 3 healing potions, this is the max you can hold at any given time");
}

// inserted - take money
$DB->query("update inferno_user set money=money-'{$heal['cost']}' where gid='{$member['gid']}'");

	if($multi > 1){
	$message = "Proceeding To Buy Potion Again - Please Stand By";
	$url     = "inferno.php?$session[sessionurl]do=BuyHeal&id={$heal['hid']}&multi=".($multi-1);
	} else {
	$message="{$heal['name']} Successfully Purchased";
	$url="inferno.php?$session[sessionurl]do=Healing";
	}

	eval('$rpg_body .= "' . fetch_template('inferno_redirect') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Healing Center [Buy]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}

if($_GET['do']=="BuyFusedHeal"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Healing Center [Buy Fused]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
	$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Healing Center");
	$navbits[""]= "Buying Potion";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['healing_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

// Now lets take ya through a crash course of possible errors or stunts you may try to pull XD
	// in battle?
	if($member['inbattle']>0){
	RunError("You are in battle, you may not buy any more Healing Potions");
	}

	// Incomming Vars
	$prime = intval($_POST['prime_fuse']);
	$secon = intval($_POST['secon_fuse']);

	// Check Both Healing Items Exist
	if(!$prime_heal=$DB->query_first("select * from inferno_heal where hid='{$prime}'")){
	RunError("The primary potion you have tried to buy does not exist.");
	}

	if(!$secon_heal=$DB->query_first("select * from inferno_heal where hid='{$secon}'")){
	RunError("The secondary potion you have tried to buy does not exist.");
	}

	// Combined Cost
	$Fuse_Cost = ($prime_heal['cost'] + $secon_heal['cost']);

	if($member['money']-$Fuse_Cost<0){
	RunError("The combined price of the potions amounts up to more than you currently have.");
	}



	// already own 3 healing items?
	if($member['heal1']!="0" && $member['heal2']!="0" && $member['heal3']!="0"){
		if($member['heal1']!="" && $member['heal2']!="" && $member['heal3']!=""){
		RunError("You already own 3 healing potions, this is the max you can hold at any given time");
		}
	}

$Fuse_Save = "{$prime_heal['hid']}_{$secon_heal['hid']}";

// into which heal?
if($member['heal1']=="" || $member['heal1']=="0"){
// this one!!
$DB->query("update inferno_user set heal1='{$Fuse_Save}' where gid='{$member['gid']}'");
} elseif($member['heal2']=="" || $member['heal2']=="0"){
// no this one!!!
$DB->query("update inferno_user set heal2='{$Fuse_Save}' where gid='{$member['gid']}'");
} elseif($member['heal3']=="" || $member['heal3']=="0"){
// no this one!!!
$DB->query("update inferno_user set heal3='{$Fuse_Save}' where gid='{$member['gid']}'");
} else {
// uhh sorry bud
RunError("You already own 3 healing potions, this is the max you can hold at any given time");
}

// inserted - take money
$DB->query("update inferno_user set money=money-'{$Fuse_Cost}' where gid='{$member['
 
// Remove item from stock
$DB->query("delete from inferno_stock where item_id='{$item['id']}' and member_id='{$member['gid']}'");
// equipped? - take stats down - remove record
$eq=$DB->query("select * from inferno_equip where the_item='{$item['id']}' and the_owner='{$member['gid']}'");
$the_x_equip=$DB->fetch_array($eq);
if($the_x_equip['xid']!=""){
// so you have it equipped, muahaha take it away!!
$DB->query("update inferno_user set hp=hp-'{$item['hp']}',hpm=hpm-'{$item['hp']}',mp=mp-'{$item['mp']}',mpm=mpm-'{$item['mp']}',str=str-'{$item['str']}',def=def-'{$item['def']}' where gid='{$member['gid']}'");
// remove record
$DB->query("delete from inferno_equip where the_item='{$item['id']}' and the_owner='{$member['gid']}'");
// Thats it neo, spin around, kick his ass, then go eat lunch <--------- WTF? 0.o
CheckStatLow();
}
// cat stats
$DB->query("update inferno_cat set csold=csold-'1',cprofit=cprofit-'{$item['cost']}' where cid='{$item['type']}'");



// Redirect ^_^
$message="Item {$item['name']} Sold";
$url="inferno.php";
eval('$rpg_body .= "' . fetch_template('inferno_redirect') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Sell Item
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="scan"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Scan Item
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Scanning Item");
$navbits[""]= "Itemshop";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['itemshop_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

// Check item exists
$gitem=$DB->query("select i.*,c.*
from inferno_items i
left join inferno_cat c on(i.type=c.cid)
where i.id='{$_GET['id']}'");
$item=$DB->fetch_array($gitem);
if($item['id']==""){
RunError("The item you have requested was not found, please check the link you have clicked");
}


$get_jobs = $DB->query("select * from inferno_jobs");
while($tjob = $DB->fetch_array($get_jobs)){
$AllJobs[$tjob['jid']] = $tjob;
}


$classes = explode("|",$item['class_allow']);
$class_allow = "";
if(is_array($classes)){
foreach($classes as $a_c){
$class_allow .= "{$AllJobs[$a_c]['jname']}, ";
}
}
if($class_allow == ""){
$class_allow = "<i>None</i>";
} else {
$class_allow = substr($class_allow,0,-2);
}


if($member['money'] >= $item['cost']){
$item['BuyLink']="<a href='?$session[sessionurl]do=BuyItem&id={$item['id']}'>Buy</a>";
} else {
$item['BuyLink']="<a disabled=true href='javascript:;' title='Not Enough {$vbphrase[money]} To Buy This Item'>Buy</a>";
}
eval('$rpg_body .= "' . fetch_template('inferno_scan') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Scan Item
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}

if($rpg_option['check_interest']=="global"){
// Do we have interest? - Give em it before they see anything o_o (sneaky)
$intrest = $rpg_option['bankinterest'];
$rate = $rpg_option['banktime'];
$lastvisit = $member['lastvisit'];
$bankmoney = $member['bankmoney'];
$nowtime = time();

// Have we been good and left bank to gain interest?
$checktime = $nowtime-$lastvisit;

if($checktime > $rate){

// Bank Loan - Yes/No? - Disable Interest - Yes/No?
if($BankLoan = $DB->query_first("select * from inferno_bankloans where l_user='{$member['gid']}'")){
$hasloan = 1;
} else {
$hasloan = 0;
}

if($hasloan == 0 || $rpg_option[bank_loan_disable] == 0){
$addintrest = $bankmoney/100*$intrest;
$addintrest = (int)$addintrest;
$addintrest = $addintrest+$bankmoney;
$DB->query("UPDATE inferno_user SET bankmoney='{$addintrest}', lastvisit='{$nowtime}' WHERE rid='{$member['rid']}'");

if($_GET['do']=="Bank"){ // only needed for bank
// Reconnect to member (to get updated data)
$gmember = $DB->query("select * from inferno_user where rid='{$bbuserinfo['userid']}'");
$member = $DB->fetch_array($gmember);
}
}
}
}

if($_GET['do']=="Bank"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Bank Main
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Bank");
$navbits[""]= "Bank";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['bank_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

// Bank Loan - Yes/No?
if($BankLoan = $DB->query_first("select * from inferno_bankloans where l_user='{$member['gid']}'")){
$hasloan = 1;
$BankLoan['l_payback'] = vbdate($vboptions['dateformat'], $BankLoan['l_payback']) . ", " . vbdate($vboptions['timeformat'], $BankLoan['l_payback']);

if($rpg_option[bank_loan_disable]){
$member['timeXX'] = "<i>Disabled - Bank Loan Active</i>";
}

} else {
$hasloan = 0;
}

if($rpg_option['check_interest']=="bank"){
// Do we have interest? - Give em it before they see anything o_o (sneaky)
$intrest=$rpg_option['bankinterest'];
$rate=$rpg_option['banktime'];
$lastvisit=$member['lastvisit'];
$bankmoney=$member['bankmoney'];
$nowtime=time();

// Have we been good and left bank to gain interest?
$checktime=$nowtime-$lastvisit;
if($checktime > $rate){
$addintrest=$bankmoney/100*$intrest;
$addintrest=(int)$addintrest;
$addintrest=$addintrest+$bankmoney;

// Bank Loan Active? Don't Give The Interest
if($hasloan == 0 || $rpg_option[bank_loan_disable] == 0){
$DB->query("UPDATE inferno_user SET bankmoney='{$addintrest}', lastvisit='{$nowtime}' WHERE rid='{$member['rid']}'");
// Reconnect to member (to get updated data)
$gmember=$DB->query("select * from inferno_user where rid='{$bbuserinfo['userid']}'");
$member=$DB->fetch_array($gmember);
}
}}


$bankmoney=$member['bankmoney'];
// [Calculate Time Untill Next Payment]
$diff = time()-$member['lastvisit'];
$diff = $rate-$diff;
$daysDiff = floor($diff/60/60/24);
$diff -= $daysDiff*60*60*24;
$hrsDiff = floor($diff/60/60);
$diff -= $hrsDiff*60*60;
$minsDiff = floor($diff/60);
$diff -= $minsDiff*60;
$secsDiff = $diff;
$tdays=$daysDiff;
$thrs=$hrsDiff;
$tmins=$minsDiff;
$tsecs=$secsDiff;
$addeth=$bankmoney/100*$intrest;
$addeth=(int)$addeth;
$addeth=number_format($addeth);
$timer ="{$tdays} days, ".$thrs." hours, ".$tmins." minutes and ".$tsecs." seconds until next payment of {$addeth} {$vbphrase['money']}";

if($hasloan == 0 || $rpg_option[bank_loan_disable] == 0){
$member['timeXX']=$timer;
}

// -- Bank Stats --
$bank['clients']=0;
$bank['total_own']=0;
$allx=$DB->query("select * from inferno_user where rid>0 and bankmoney>0");
while($renderM=$DB->fetch_array($allx)){
$bank['clients']++;
$bank['total_own']+=$renderM['bankmoney'];
}
if($member['bankmoney'] < 1){ $member['acc_set']="Offline"; }else{ $member['acc_set']="Online";}
// -- Bank Stats --

// Parse Members Money
$member['money']=number_format($member['money']);
$member['bankmoney']=number_format($member['bankmoney']);
$bank['clients']=number_format($bank['clients']);
$bank['total_own']=number_format($bank['total_own']);



// Spit out bank html :P
eval('$rpg_body .= "' . fetch_template('inferno_bank') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Bank Main
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}


if($_GET['do']=="Loan"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Bank [Loan]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Bank");
$navbits[""]= "Bank";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['bank_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

// Bank Loan - Yes/No?
if($BankLoan = $DB->query_first("select * from inferno_bankloans where l_user='{$member['gid']}'")){
RunError("You already have a bank loan currently active. You must pay off that loan before applying for a new one.");
}

$Loan = intval($_POST['loan']);
$Max = $rpg_option['bank_loan_maximum'];

if($Loan > $Max){
RunError("The maximum loan amount is {$Max} {$vbphrase[money]}. You may not take a loan out larger than this amount.");
}

if($Loan < 1){
RunError("You cannot loan under 1 {$vbphrase[money]}.");
}

if($member['bankmoney'] < 0){
RunError("Your bank funds are currently negative, you may not take out a loan while in this state.");
}

$Rate = $rpg_option['bank_loan_interest'];
$Payback = intval(($Loan / 100) * $Rate) + $Loan;
$Deadline = $rpg_option['bank_loan_payback'];
$Deadline = (60 * 60 * 24) * $Deadline;
$Deadline = time() + $Deadline;

$DB->query("insert into inferno_bankloans (l_amount,l_user,l_payback) values ($Payback,$member[gid],$Deadline)");
$DB->query("update inferno_user set bankmoney=bankmoney+{$Loan} where gid='{$member['gid']}'");

$message = "You have successfully loaned {$Loan} {$vbphrase[money]}";
$url = "inferno.php?$session[sessionurl]do=Bank";
eval('$rpg_body .= "' . fetch_template('inferno_redirect') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Bank [Loan]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}


if($_GET['do']=="LoanPayback"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Bank [Loan Payback]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Bank");
$navbits[""]= "Bank";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['bank_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

// Bank Loan - Yes/No?
if(!$BankLoan = $DB->query_first("select * from inferno_bankloans where l_user='{$member['gid']}'")){
RunError("You do not have any active bank loans to payback.");
}

$Payback = intval($_POST['payback']);

if($Payback < 1){
RunError("You must pay atleast 1 {$vbphrase[money]} back.");
}

if($Payback > $BankLoan['l_amount']){
RunError("You are trying to payback more than you have to.");
}

if($Payback > $member['bankmoney']){
RunError("You have insufficient funds within your bank to payback this amount.");
}

$NewAmount = ($BankLoan['l_amount'] - $Payback);
$NewBMoney = ($member['bankmoney'] - $Payback);

if($NewAmount == 0){ // Loan Paid Off
$Msg = "You have successfully paid off your loan.";
$DB->query("delete from inferno_bankloans where l_user='{$member['gid']}'");
} else {
$Msg = "You have successfully paid back {$Payback} {$vbphrase[money]} off your loan.";
$DB->query("update inferno_bankloans set l_amount='{$NewAmount}' where l_user='{$member['gid']}'");
}

$DB->query("update inferno_user set bankmoney='{$NewBMoney}' where gid='{$member['gid']}'");

$message = $Msg;
$url = "inferno.php?$session[sessionurl]do=Bank";
eval('$rpg_body .= "' . fetch_template('inferno_redirect') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Bank [Loan Payback]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}


// ######()()()()()()()()()()() == Thank you for reading this comment, it has wasted approx 3 seconds of your life =D
if($_GET['do']=="deposit"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Deposit Money
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Bank");
$navbits[""]= "Deposit Money"; // MONEH!!! 0.o

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['bank_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

$deposit=$_POST['deposit'];
$deposit=str_replace (",", "", $deposit);
$deposit=(int)$deposit;

// your not trying to screw about are you?
if($member['money']-$deposit < 0){
// I don't think so, heh
RunError("Sorry, your trying to deposit more than you own, please go back and check the values you inputted");
}
if($deposit<1){
RunError("Your not depositing anything, enter a value higher than 0");
}
if($deposit==""){
RunError("No value entered, please go back and check the values you inputted");
}
// Ok lets deposit :)
$money=$member['money']-$deposit;
// one last check ^_^
if($money < 0){
RunError("Sorry, your trying to deposit more than you own, please go back and check the values you inputted");
}
// ok were gonna do it now XD
$DB->query("update inferno_user set money=money-'{$deposit}',bankmoney=bankmoney+'{$deposit}',lastvisit='".time()."' where rid='{$member['rid']}'");
// redirect needed :)
$message="{$vbphrase['money']} Deposited Successfully";
$url="inferno.php?$session[sessionurl]do=Bank";
eval('$rpg_body .= "' . fetch_template('inferno_redirect') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Deposit Money
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="withdraw"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Withdraw Money
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Bank");
$navbits[""]= "Withdraw Money"; // MONEH!!! 0.o

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['bank_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

$withdraw=$_POST['withdraw'];
$withdraw=str_replace (",", "", $withdraw);
$withdraw=(int)$withdraw;

// your not trying to screw about are you?
if($member['bankmoney']-$withdraw < 0){
// I don't think so, heh
RunError("Sorry, your trying to withdraw more than you have inside the bank, please go back and check the values you inputted");
}
if($withdraw<1){
RunError("Your not withdrawing anything, enter a value higher than 0");
}
if($withdraw==""){
RunError("No value entered, please go back and check the values you inputted");
}
// Ok lets withdraw :)
$money=$member['bankmoney']-$withdraw;
// one last check ^_^
if($money < 0){
RunError("Sorry, your trying to withdraw more than you have inside the bank, please go back and check the values you inputted");
}
// ok were gonna do it now XD
$DB->query("update inferno_user set money=money+'{$withdraw}',bankmoney=bankmoney-'{$withdraw}',lastvisit='".time()."' where rid='{$member['rid']}'");
// redirect needed :)
$message="{$vbphrase['money']} Withdrew Successfully";
$url="inferno.php?$session[sessionurl]do=Bank";
eval('$rpg_body .= "' . fetch_template('inferno_redirect') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Withdraw Money
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="ScanMember"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Scan Member
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Scan Member");
$navbits[""]= "Scanning Members RPG Profile";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['scan_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

// check member has rpg profile
// - wait, are you scanning yourself? O_o
if($_GET['id']==$member['rid']){
$themember=$member; // why the fuck should we run a query we did already..huh? 0_o'
} else {
if(!$themember=$DB->query_first("select * from inferno_user where rid='{$_GET['id']}'")){
RunError("Sorry but no RPG Profile was found for this member. They havn't made one or the id you have inputted is incorrect.");
}
}


$themember['EXP_Need'] = EXP_Needed_For_Level((intval($themember['level'] + 1)));

// member exists - draw up form
if($themember['name']==""){$themember['name']="<i>No Name</i>";}
// Player Stats
// HP Bar
$hp = $themember['hp'];
$hpm= $themember['hpm'];
$hpa= $hp/$hpm;
$hpa= $hpa*100;
$themember['hpd']=$hpa;
// MP Bar
$mp = $themember['mp'];
$mpm= $themember['mpm'];
$mpa= $mp/$mpm;
$mpa= $mpa*100;
$themember['mpd']=$mpa;
// DEF Bar
$def= $themember['def'];
$defm=$hpm;
$defa=$def/$defm;
$defa=$defa*100;
$themember['defd']=$defa;
// STR Bar
$str= $themember['str'];
$strm=$hpm;
$stra=$str/$strm;
$stra=$stra*100;
$themember['strd']=$stra;
if($themember['strd'] > 100){
$themember['strd']=100;
}
if($themember['defd'] > 100){
$themember['defd']=100;
}
$gelm=$DB->query("select * from inferno_element where eid='{$themember['element']}'");
$theelm=$DB->fetch_array($gelm);
if($theelm['element']!=""){
$themember['element']="<img src='Inferno/elements/{$theelm['img']}' alt='{$theelm['element']}'>";
} else {
$themember['element']="<i>No Element</i>";
}
if($themember['status']==""){$themember['status']="<i>None</i>";}
// Top
eval('$rpg_body .= "' . fetch_template('inferno_scanm_top') . '";');
// Mini Profile

// clan?
if($themember['inclan']==0 || !$themember['inclan']>0){
$themember['intheclan']="<i>None</i>";
} else {
// connect to clan
$theclan=$DB->query_first("select * from inferno_clan where cid='{$themember['inclan']}'");
$themember['intheclan']="<a href='inferno.php?$session[sessionurl]do=ViewClan&cid={$theclan['cid']}'>{$theclan['cname']}</a>";
}

// -- RPG Avatar --
if($themember['avatar']!=""){
$RPav="<img src='{$themember['avatar']}' alt='{$themember['name']}' width='{$themember['aw']}' height='{$themember['ah']}'>";
} else {
$RPav="<i><b>No Avatar Selected</b></i>";
}
eval('$rpg_body .= "' . fetch_template('inferno_scanm_miniprof') . '";');
// Mini1 (From Mini-Prof To Inv)
eval('$rpg_body .= "' . fetch_template('inferno_scanm_mini1') . '";');
// Get Inventory

$cache_upgrade=array(); // because there are lots or Mr. Smiths =D

// +++++++++++++++++
// Upgrades Inament?
// +++++++++++++++++
// Call Inventory Row
$inv_row=$DB->query("select u.*,s.*,i.*
from inferno_stock s
left join inferno_items i on(i.id=s.item_id)
left join inferno_synthesis u on(u.sid=s.upgrade_id)
where s.member_id='".$themember['gid']."'");
while ($items = $DB->fetch_array($inv_row)) {
$myitem[]=$items;
}
// display items with upgrade
if($myitem[0]){ // member has any items? [if not cancel out foreach()]
foreach($myitem as $the_item){
// upgrade?
if($the_item['upgrade_id']>0){
$the_item['the_upgrade']=$the_item['sname'];
} else {
$the_item['the_upgrade']="<i>None</i>";
}
$item=$the_item; // clarify var
eval('$rpg_body .= "' . fetch_template('inferno_scanm_invrow') . '";');
}
}

$cache_heal=array(); // yeeees mr smith again =D

$gpot=$DB->query("select * from inferno_heal order by cost");
while($heal=$DB->fetch_array($gpot)){
$all_heal[$heal['hid']]=$heal;
}

// Move to healing - top first
eval('$rpg_body .= "' . fetch_template('inferno_scanm_healtop') . '";');

if(intval($themember['heal1'])>0 && $themember['heal1']!="" && !preg_match("/(\d+)_(\d+)/",$themember['heal1'])){

$heal1=$all_heal[$themember['heal1']];
} else if(preg_match("/(\d+)_(\d+)/",$themember['heal1'])){
// Fused Healing Potion

$prime_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$1",$themember['heal1'])];
$secon_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$2",$themember['heal1'])];

$heal1 = array(
'img' => $prime_heal['img'],
'name' => "{$prime_heal['name']} Fused With {$secon_heal['name']}",
'desc' => $prime_heal['desc'],
'hid' => "{$prime_heal['hid']}_{$secon_heal['hid']}",
'ability' => $prime_heal['ability'],
'hp' => ($prime_heal['hp'] + $secon_heal['hp']),
'mp' => ($prime_heal['mp'] + $secon_heal['mp']),
'cost' => ($prime_heal['cost'] + $secon_heal['cost']),
);

}

if(intval($themember['heal2'])>0 && $themember['heal2']!="" && !preg_match("/(\d+)_(\d+)/",$themember['heal2'])){
$heal2=$all_heal[$themember['heal2']];
} else if(preg_match("/(\d+)_(\d+)/",$themember['heal2'])){
// Fused Healing Potion

$prime_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$1",$themember['heal2'])];
$secon_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$2",$themember['heal2'])];

$heal2 = array(
'img' => $prime_heal['img'],
'name' => "{$prime_heal['name']} Fused With {$secon_heal['name']}",
'desc' => $prime_heal['desc'],
'hid' => "{$prime_heal['hid']}_{$secon_heal['hid']}",
'ability' => $prime_heal['ability'],
'hp' => ($prime_heal['hp'] + $secon_heal['hp']),
'mp' => ($prime_heal['mp'] + $secon_heal['mp']),
'cost' => ($prime_heal['cost'] + $secon_heal['cost']),
);

}

if(intval($themember['heal3'])>0 && $themember['heal3']!="" && !preg_match("/(\d+)_(\d+)/",$themember['heal3'])){
$heal3=$all_heal[$themember['heal3']];
} else if(preg_match("/(\d+)_(\d+)/",$themember['heal3'])){
// Fused Healing Potion

$prime_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$1",$themember['heal3'])];
$secon_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$2",$themember['heal3'])];

$heal3 = array(
'img' => $prime_heal['img'],
'name' => "{$prime_heal['name']} Fused With {$secon_heal['name']}",
'desc' => $prime_heal['desc'],
'hid' => "{$prime_heal['hid']}_{$secon_heal['hid']}",
'ability' => $prime_heal['ability'],
'hp' => ($prime_heal['hp'] + $secon_heal['hp']),
'mp' => ($prime_heal['mp'] + $secon_heal['mp']),
'cost' => ($prime_heal['cost'] + $secon_heal['cost']),
);

}

if($heal1){
$heal=$heal1;
eval('$rpg_body .= "' . fetch_template('inferno_scanm_heal_row') . '";');
}

if($heal2){
$heal=$heal2;
eval('$rpg_body .= "' . fetch_template('inferno_scanm_heal_row') . '";');
}

if($heal3){
$heal=$heal3;
eval('$rpg_body .= "' . fetch_template('inferno_scanm_heal_row') . '";');
}


// Move to equipped items - top first
eval('$rpg_body .= "' . fetch_template('inferno_scanm_equiptop') . '";');
// Select Currently Equipped Items From Database


// +++++++++++++++++
// Upgrades Inament?
// +++++++++++++++++
// Call Inventory Row
$inv_row=$DB->query("select e.*,i.*,u.*,s.*
from inferno_equip e
left join inferno_stock s on(s.item_id=e.the_item and s.member_id=e.the_owner)
left join inferno_items i on(i.id=e.the_item)
left join inferno_synthesis u on(u.sid=s.upgrade_id)
where e.the_owner='{$themember['gid']}'");
while ($items = $DB->fetch_array($inv_row)) {
$myequip[]=$items;
}
// display items with upgrade
if($myequip[0]){ // member has any items? [if not cancel out foreach()]
foreach($myequip as $theitem){
// grab item

$the_item = $theitem;

// upgrade?
if($the_item['upgrade_id']>0){
$the_item['the_upgrade']=$the_item['sname'];
} else {
$the_item['the_upgrade']="<i>None</i>";
}
$item=$the_item; // clarify var
eval('$rpg_body .= "' . fetch_template('inferno_scanm_invrow') . '";');
}
}

// Spells =D
// Move to spells - top first
eval('$rpg_body .= "' . fetch_template('inferno_scanm_spellstop') . '";');
// ok now row :P
$get_spells=$DB->query("select spell.*,spell_inventory.* from inferno_spells_inventory spell_inventory left join inferno_spells spell on (spell.sid=spell_inventory.spell) where spell_inventory.spell_owner='{$themember['gid']}' order by spell.mp_cost");
while($spell=$DB->fetch_array($get_spells)){
eval('$rpg_body .= "' . fetch_template('inferno_scanm_spellsrow') . '";');
}


// Player statistics hp/mp....
eval('$rpg_body .= "' . fetch_template('inferno_scanm_statsend') . '";');
// End scan page
eval('$rpg_body .= "' . fetch_template('inferno_scanm_end') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Scan Member
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="Equip"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Equip Items [Main Screen]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Equip");
$navbits[""]= "Equip Your Character";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['equip_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

$cache_upgrade=array();
// Top Table [Equip Cat Selection]
eval('$rpg_body .= "' . fetch_template('inferno_equip_cat_top') . '";');
// Select Cats To Equip From
$cats=$DB->query("select * from inferno_cat");
while ($thecats = $DB->fetch_array($cats)) {
eval('$rpg_body .= "' . fetch_template('inferno_equip_cat_row') . '";');
}
// End category selection for equipping
eval('$rpg_body .= "' . fetch_template('inferno_equip_cat_end') . '";');


// Top Table [Currently Equipped Items]
eval('$rpg_body .= "' . fetch_template('inferno_equip_cur_top') . '";');
// Select Currently Equipped Items From Database
// +++++++++++++++++
// Upgrades Inament?
// +++++++++++++++++
// Call Inventory Row
$inv_row=$DB->query("select e.*,i.*,u.*,s.*
from inferno_equip e
left join inferno_stock s on(s.item_id=e.the_item and s.member_id=e.the_owner)
left join inferno_items i on(i.id=e.the_item)
left join inferno_synthesis u on(u.sid=s.upgrade_id)
where e.the_owner='{$member['gid']}'");
while ($items = $DB->fetch_array($inv_row)) {
$myequip[]=$items;
}
// display items with upgrade
if($myequip[0]){ // member has any items? [if not cancel out foreach()]
foreach($myequip as $theitem){
// grab item

$the_item = $theitem;

// upgrade?
if($the_item['upgrade_id']>0){
$the_item['the_upgrade']=$the_item['sname'];
} else {
$the_item['the_upgrade']="<i>None</i>";
}
$item=$the_item; // clarify var
eval('$rpg_body .= "' . fetch_template('inferno_equip_cur_row') . '";');
}
}
// End Table [Currently Equipped Items]
eval('$rpg_body .= "' . fetch_template('inferno_equip_cur_end') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Equip Items [Main Screen]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="SelectEquip"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Equip Items [Choose Equip]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Equip From Category");
$navbits[""]= "Equip Your Character";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['equip_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

// Check Category Exists
if(!$TheCat=$DB->query_first("select * from inferno_cat where cid='{$_GET['Cat']}'")){
RunError("The category you have specified doesn't seem to be inside the database. Please check the url");
}
// Already Equipped From This Category?
if($DB->query_first("select * from inferno_equip where the_cat='{$_GET['Cat']}' and the_owner='{$themember['gid']}'")){
RunError("Sorry but it seems you have already equipped an item from this category, please unequip it first"); // Loser!!! XD
}
// Seems ok, lets get your items ^_^
// Table Top
eval('$rpg_body .= "' . fetch_template('inferno_equip_do_top') . '";');
// Grab Your Inventory - From This Cat


// +++++++++++++++++
// Upgrades Inament?
// +++++++++++++++++
// Call Inventory Row
$inv_row=$DB->query("select i.*,u.*,s.*
from inferno_stock s
left join inferno_items i on(i.id=s.item_id)
left join inferno_synthesis u on(u.sid=s.upgrade_id)
where s.member_id='{$member['gid']}' and i.type='{$TheCat['cid']}'");
while ($items = $DB->fetch_array($inv_row)) {
$myequip[]=$items;
}
// display items with upgrade
if($myequip[0]){ // member has any items? [if not cancel out foreach()]
foreach($myequip as $theitem){
// grab item
$the_item = $theitem;

// upgrade?
if($the_item['upgrade_id']>0){
// get upgrade
$the_item['the_upgrade']=$the_item['sname'];
} else {
$the_item['the_upgrade']="<i>None</i>";
}
$item=$the_item; // clarify var
eval('$rpg_body .= "' . fetch_template('inferno_equip_do_row') . '";');
}
}

// Aaaaaaaaaaand end the table =P
eval('$rpg_body .= "' . fetch_template('inferno_equip_do_end') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Equip Items [Choose Equip]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="DoEquip"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Equip Items [Do Equip]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Equipping Character");
$navbits[""]= "Equip Your Character";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['equip_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

if($member['inbattle']>0){
RunError("You cannot equip items during battle");
}

// Check Item Exixts (Also need var for below ;D)
if(!$item=$DB->query_first("select * from inferno_items where id='{$_GET['id']}'")){
RunError("You are trying to equip a none existant item. Check the url you have followed");
}
// Check Your Own This Item
if(!$own=$DB->query_first("select * from inferno_stock where item_id='{$item['id']}' and member_id='{$member['gid']}'")){
RunError("The item you are trying to equip you do not own"); // *cough* Yeah nice try
}
// you put item in an auction?
if($auction=$DB->query_first("select * from inferno_auction where item='{$item['id']}' and owner='{$member['gid']}'")){
RunError("The item you are trying to equip is currently in an auction you are running, please close or cancel the auction first");
}
// Check you havn't equipped from this category
if($DB->query_first("select * from inferno_equip where the_cat='{$item['type']}' and the_owner='{$member['gid']}'")){
RunError("Sorry but it seems you have already equipped an item from this category, please unequip it first"); // Loser!!! XD
}
// Ok - your a good boy - lets build you up

// record equip
$DB->query("insert into inferno_equip values('','{$item['id']}','{$member['gid']}','{$item['type']}')");
// Increase Your Stats
$DB->query("update inferno_user set hp=hp+'{$item['hp']}',hpm=hpm+'{$item['hp']}',mp=mp+'{$item['mp']}',mpm=mpm+'{$item['mp']}',str=str+'{$item['str']}',def=def+'{$item['def']}',vitality=vitality+'{$item['vitality']}',evasion=evasion+'{$item['evasion']}' where gid='{$member['gid']}'");
// upgraded item?
if($own['upgrade_id']>0){
$synthesis=$DB->query_first("select * from inferno_synthesis where sid='{$own['upgrade_id']}'");
if($synthesis['sid']!=""){
// Increase Your Stats [upgrade]
$DB->query("update inferno_user set hp=hp+'{$synthesis['shp']}',hpm=hpm+'{$synthesis['shp']}',mp=mp+'{$synthesis['smp']}',mpm=mpm+'{$synthesis['smp']}',str=str+'{$synthesis['sstr']}',def=def+'{$synthesis['sdef']}',vitality=vitality+'{$synthesis['svitality']}',evasion=evasion+'{$synthesis['sevasion']}' where gid='{$member['gid']}'");
}
}

CheckStatLow();

// Redirect
$message="{$item['name']} Successfully Equipped";
$url="inferno.php?$session[sessionurl]do=Equip";
eval('$rpg_body .= "' . fetch_template('inferno_redirect') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Equip Items [Do Equip]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="Unequip"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Equip Items [Unequip]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Equipping Character");
$navbits[""]= "Equip Your Character";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['equip_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

if($member['inbattle']>0){
RunError("You cannot unequip items during battle");
}

// Check Item Exixts (Also need var for below ;D)
if(!$item=$DB->query_first("select * from inferno_items where id='{$_GET['id']}'")){
RunError("You are trying to unequip a none existant item. Check the url you have followed");
}
// Check Your Own This Item
if(!$own=$DB->query_first("select * from inferno_stock where item_id='{$item['id']}' and member_id='{$member['gid']}'")){
RunError("The item you are trying to unequip you do not own"); // *cough* Yeah nice try
}
// Check item is equipped
if(!$DB->query_first("select * from inferno_equip where the_cat='{$item['type']}' and the_owner='{$member['gid']}' and the_item='{$item['id']}'")){
RunError("You do not own this item to unequip. Check the url you have followed"); // Loser!!! XD
}
// Ok - your a good boy - lets build you up

// remove record
$DB->query("delete from inferno_equip where the_item='{$item['id']}' and the_owner='{$member['gid']}'");
// Decrease Your Stats
$DB->query("update inferno_user set hp=hp-'{$item['hp']}',hpm=hpm-'{$item['hp']}',mp=mp-'{$item['mp']}',mpm=mpm-'{$item['mp']}',str=str-'{$item['str']}',def=def-'{$item['def']}',vitality=vitality-'{$item['vitality']}',evasion=evasion-'{$item['evasion']}' where gid='{$member['gid']}'");
// upgraded item?
if($own['upgrade_id']>0){
$synthesis=$DB->query_first("select * from inferno_synthesis where sid='{$own['upgrade_id']}'");
if($synthesis['sid']!=""){
// Decrease Your Stats [upgrade]
$DB->query("update inferno_user set hp=hp-'{$synthesis['shp']}',hpm=hpm-'{$synthesis['shp']}',mp=mp-'{$synthesis['smp']}',mpm=mpm-'{$synthesis['smp']}',str=str-'{$synthesis['sstr']}',def=def-'{$synthesis['sdef']}',vitality=vitality-'{$synthesis['svitality']}',evasion=evasion-'{$synthesis['sevasion']}' where gid='{$member['gid']}'");
}
}
CheckStatLow();
// Redirect
$message="{$item['name']} Successfully Unequipped";
$url="inferno.php?$session[sessionurl]do=Equip";
eval('$rpg_body .= "' . fetch_template('inferno_redirect') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Equip Items [Unequip]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="Healing"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Healing Center [Main]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Healing Center");
$navbits[""]= "Heal Your Character";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['healing_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

// Query Reduction Program
// Potions
$gpot=$DB->query("select * from inferno_heal order by cost");
while($heal=$DB->fetch_array($gpot)){
$all_heal[$heal['hid']]=$heal;
}

if($member['status']==""){$member['status']="<i>None</i>";}

// Table Top [Heal Inv]
eval('$rpg_body .= "' . fetch_template('inferno_heal_inv_top') . '";');
// Your Healing

if(intval($member['heal1'])>0 && $member['heal1']!="" && !preg_match("/(\d+)_(\d+)/",$member['heal1'])){

$heal1=$all_heal[$member['heal1']];
} else if(preg_match("/(\d+)_(\d+)/",$member['heal1'])){
// Fused Healing Potion

$prime_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$1",$member['heal1'])];
$secon_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$2",$member['heal1'])];

$heal1 = array(
'img' => $prime_heal['img'],
'name' => "{$prime_heal['name']} Fused With {$secon_heal['name']}",
'desc' => $prime_heal['desc'],
'hid' => "{$prime_heal['hid']}_{$secon_heal['hid']}",
'ability' => $prime_heal['ability'],
'hp' => ($prime_heal['hp'] + $secon_heal['hp']),
'mp' => ($prime_heal['mp'] + $secon_heal['mp']),
'cost' => ($prime_heal['cost'] + $secon_heal['cost']),
);

}

if(intval($member['heal2'])>0 && $member['heal2']!="" && !preg_match("/(\d+)_(\d+)/",$member['heal2'])){
$heal2=$all_heal[$member['heal2']];
} else if(preg_match("/(\d+)_(\d+)/",$member['heal2'])){
// Fused Healing Potion

$prime_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$1",$member['heal2'])];
$secon_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$2",$member['heal2'])];

$heal2 = array(
'img' => $prime_heal['img'],
'name' => "{$prime_heal['name']} Fused With {$secon_heal['name']}",
'desc' => $prime_heal['desc'],
'hid' => "{$prime_heal['hid']}_{$secon_heal['hid']}",
'ability' => $prime_heal['ability'],
'hp' => ($prime_heal['hp'] + $secon_heal['hp']),
'mp' => ($prime_heal['mp'] + $secon_heal['mp']),
'cost' => ($prime_heal['cost'] + $secon_heal['cost']),
);

}

if(intval($member['heal3'])>0 && $member['heal3']!="" && !preg_match("/(\d+)_(\d+)/",$member['heal3'])){
$heal3=$all_heal[$member['heal3']];
} else if(preg_match("/(\d+)_(\d+)/",$member['heal3'])){
// Fused Healing Potion

$prime_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$1",$member['heal3'])];
$secon_heal = $all_heal[preg_replace("/(\d+)_(\d+)/","$2",$member['heal3'])];

$heal3 = array(
'img' => $prime_heal['img'],
'name' => "{$prime_heal['name']} Fused With {$secon_heal['name']}",
'desc' => $prime_heal['desc'],
'hid' => "{$prime_heal['hid']}_{$secon_heal['hid']}",
'ability' => $prime_heal['ability'],
'hp' => ($prime_heal['hp'] + $secon_heal['hp']),
'mp' => ($prime_heal['mp'] + $secon_heal['mp']),
'cost' => ($prime_heal['cost'] + $secon_heal['cost']),
);

}

$InInv = 0;

if($heal1)
{
$heal=$heal1;
$heal['sell']=(int)$heal['cost']/3;
$heal['sell']=floor($heal['sell']);
eval('$rpg_body .= "' . fetch_template('inferno_heal_inv_row') . '";');
$InInv++;
}
if($heal2)
{
$heal=$heal2;
$heal['sell']=(int)$heal['cost']/3;
$heal['sell']=floor($heal['sell']);
eval('$rpg_body .= "' . fetch_template('inferno_heal_inv_row') . '";');
$InInv++;
}
if($heal3)
{
$heal=$heal3;
$heal['sell']=(int)$heal['cost']/3;
$heal['sell']=floor($heal['sell']);
eval('$rpg_body .= "' . fetch_template('inferno_heal_inv_row') . '";');
$InInv++;
}
// End Heal Inv Table
eval('$rpg_body .= "' . fetch_template('inferno_heal_inv_end') . '";');

$prime_fuse = "";
$secon_fuse = "";

if(is_array($all_heal)){
foreach($all_heal as $heal){
$prime_fuse .= "<option value='{$heal['hid']}'>{$heal['name']}</option>";
$secon_fuse .= "<option value='{$heal['hid']}'>{$heal['name']}</option>";
}
}

$MultiBuy = array(
'2' => 0,
'3' => 0,
);

if($InInv == 0){
$MultiBuy['2'] = 1;
$MultiBuy['3'] = 1;
} else if($InInv == 1){
$MultiBuy['2'] = 1;
}

// Buy Healing
eval('$rpg_body .= "' . fetch_template('inferno_heal_main_top') . '";');
// Potions
if(is_array($all_heal)){
foreach($all_heal as $heal){
eval('$rpg_body .= "' . fetch_template('inferno_heal_main_row') . '";');
}
}
// end table [and then yawn 0.o]
eval('$rpg_body .= "' . fetch_template('inferno_heal_main_end') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Healing Center [Main]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="BuyHeal"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Healing Center [Buy]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Healing Center");
$navbits[""]= "Buying Potion";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['healing_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

$multi = intval($_GET['multi']);

if($multi < 1){
$multi = 1;
}

if($multi > 3){
$multi = 3;
}

// Now lets take ya through a crash course of possible errors or stunts you may try to pull XD
// in battle?
if($member['inbattle']>0){
RunError("You are in battle, you may not buy any more Healing Potions");
}
// 1st up, does the healing item exist?
// Check Item Exixts (Also need var for below ;D)
if(!$heal=$DB->query_first("select * from inferno_heal where hid='{$_GET['id']}'")){
RunError("You are trying to buy a none existant potion. Check the url you have followed");
}
// ok - now check you have enough money =D
if($member['money']-$heal['cost']<0){
RunError("Sorry, but this potion costs more {$vbphrase['money']} than you have on hand. Try withdrawing from your bank or waiting untill you get more {$vbphrase['money']}");
}
// already own 3 healing items?
if($member['heal1']!="0" && $member['heal2']!="0" && $member['heal3']!="0"){
if($member['heal1']!="" && $member['heal2']!="" && $member['heal3']!=""){
RunError("You already own 3 healing potions, this is the max you can hold at any given time");
}}
// hmm, ok you pass =D

// into which heal?
if($member['heal1']=="" || $member['heal1']=="0"){
// this one!!
$DB->query("update inferno_user set heal1='{$heal['hid']}' where gid='{$member['gid']}'");
} elseif($member['heal2']=="" || $member['heal2']=="0"){
// no this one!!!
$DB->query("update inferno_user set heal2='{$heal['hid']}' where gid='{$member['gid']}'");
} elseif($member['heal3']=="" || $member['heal3']=="0"){
// no this one!!!
$DB->query("update inferno_user set heal3='{$heal['hid']}' where gid='{$member['gid']}'");
} else {
// uhh sorry bud
RunError("You already own 3 healing potions, this is the max you can hold at any given time");
}

// inserted - take money
$DB->query("update inferno_user set money=money-'{$heal['cost']}' where gid='{$member['gid']}'");

if($multi > 1){
$message = "Proceeding To Buy Potion Again - Please Stand By";
$url = "inferno.php?$session[sessionurl]do=BuyHeal&id={$heal['hid']}&multi=".($multi-1);
} else {
$message="{$heal['name']} Successfully Purchased";
$url="inferno.php?$session[sessionurl]do=Healing";
}

eval('$rpg_body .= "' . fetch_template('inferno_redirect') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Healing Center [Buy]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}

if($_GET['do']=="BuyFusedHeal"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Healing Center [Buy Fused]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Healing Center");
$navbits[""]= "Buying Potion";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['healing_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

// Now lets take ya through a crash course of possible errors or stunts you may try to pull XD
// in battle?
if($member['inbattle']>0){
RunError("You are in battle, you may not buy any more Healing Potions");
}

// Incomming Vars
$prime = intval($_POST['prime_fuse']);
$secon = intval($_POST['secon_fuse']);

// Check Both Healing Items Exist
if(!$prime_heal=$DB->query_first("select * from inferno_heal where hid='{$prime}'")){
RunError("The primary potion you have tried to buy does not exist.");
}

if(!$secon_heal=$DB->query_first("select * from inferno_heal where hid='{$secon}'")){
RunError("The secondary potion you have tried to buy does not exist.");
}

// Combined Cost
$Fuse_Cost = ($prime_heal['cost'] + $secon_heal['cost']);

if($member['money']-$Fuse_Cost<0){
RunError("The combined price of the potions amounts up to more than you currently have.");
}



// already own 3 healing items?
if($member['heal1']!="0" && $member['heal2']!="0" && $member['heal3']!="0"){
if($member['heal1']!="" && $member['heal2']!="" && $member['heal3']!=""){
RunError("You already own 3 healing potions, this is the max you can hold at any given time");
}
}

$Fuse_Save = "{$prime_heal['hid']}_{$secon_heal['hid']}";

// into which heal?
if($member['heal1']=="" || $member['heal1']=="0"){
// this one!!
$DB->query("update inferno_user set heal1='{$Fuse_Save}' where gid='{$member['gid']}'");
} elseif($member['heal2']=="" || $member['heal2']=="0"){
// no this one!!!
$DB->query("update inferno_user set heal2='{$Fuse_Save}' where gid='{$member['gid']}'");
} elseif($member['heal3']=="" || $member['heal3']=="0"){
// no this one!!!
$DB->query("update inferno_user set heal3='{$Fuse_Save}' where gid='{$member['gid']}'");
} else {
// uhh sorry bud
RunError("You already own 3 healing potions, this is the max you can hold at any given time");
}

// inserted - take money
$DB->query("update inferno_user set money=money-'{$Fuse_Cost}' where gid='{$member['gid']}'");

// redirect =D
$message="{$prime_heal['name']} Fused With {$secon_heal['name']} Successfully Purchased";
$url="inferno.php?$session[sessionurl]do=Healing";
eval('$rpg_body .= "' . fetch_template('inferno_redirect') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Healing Center [Buy Fused]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}

if($_GET['do']=="SellHeal"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Healing Center [Sell]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Healing Center");
$navbits[""]= "Selling Potion";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['healing_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

// Now lets take ya through a crash course of possible errors or stunts you may try to pull XD


// Incomming
$the_id = $_GET['id'];

// 1st up, does the healing item exist?

if(!preg_match("/(\d+)_(\d+)/",$the_id)){

// Check Item Exixts (Also need var for below ;D)
if(!$heal=$DB->query_first("select * from inferno_heal where hid='".intval($the_id)."'")){
RunError("You are trying to sell a none existant potion. Check the url you have followed");
}

$heal['sell']=(int)$heal['cost']/3;
$heal['sell']=floor($heal['sell']);

} else if(preg_match("/(\d+)_(\d+)/",$the_id)){

$prime_heal = preg_replace("/(\d+)_(\d+)/","$1",$the_id);
$secon_heal = preg_replace("/(\d+)_(\d+)/","$2",$the_id);

// Check Item Exixts (Also need var for below ;D)
if(!$p_heal=$DB->query_first("select * from inferno_heal where hid='{$prime_heal}'")){
RunError("You are trying to sell a none existant potion. Check the url you have followed");
}

if(!$s_heal=$DB->query_first("select * from inferno_heal where hid='{$secon_heal}'")){
RunError("You are trying to sell a none existant potion. Check the url you have followed");
}

$heal['cost'] = ($p_heal['cost'] + $s_heal['cost']);
$heal['name'] = "{$p_heal['name']} Fused With {$s_heal['name']}";

$heal['sell']=(int)$heal['cost']/3;
$heal['sell']=floor($heal['sell']);

} else {
RunError("You are trying to sell a none existant potion. Check the url you have followed");
}


if($member['heal1']==$the_id){
$DB->query("update inferno_user set money=money+'{$heal['sell']}',heal1='0' where gid='{$member['gid']}'");
} elseif($member['heal2']==$the_id){
$DB->query("update inferno_user set money=money+'{$heal['sell']}',heal2='0' where gid='{$member['gid']}'");
} elseif($member['heal3']==$the_id){
$DB->query("update inferno_user set money=money+'{$heal['sell']}',heal3='0' where gid='{$member['gid']}'");
} else {
// you got fucked with XD
RunError("You are trying to sell a potion you do not own. Check the url you have followed");
}

// redirect =D
$message="{$heal['name']} Successfully Sold";
$url="inferno.php?$session[sessionurl]do=Healing";
eval('$rpg_body .= "' . fetch_template('inferno_redirect') . '";');
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Healing Center [Sell]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
if($_GET['do']=="UseHeal"){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Healing Center [Use Heal]
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Navigation
$navbits= array("inferno.php?$session[sessionurl]do=".$Action => "Healing Center");
$navbits[""]= "Using Potion";

// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------
if($rpg_option['healing_status']=="offline"){
RunError("Sorry, this section has been turned offline. Please contact the administrator for more information");
}
// ---------------------------------
// Section Control: Online/Offline -
// ---------------------------------

// 1st up, does the healing item exist?

// Incomming
$the_id = $_GET['id'];

if(!preg_match("/(\d+)_(\d+)/",$the_id)){

// Check Item Exixts (Also need var for below ;D)
if(!$heal=$DB->query_first("select * from inferno_heal where hid='".intval($the_id)."'")){
RunError("You are trying to use a none existant potion. Check the url you have followed");
}

// Possible new hp/mp if query executes =D
$hp=$member['hp']+$heal['hp'];
if($hp>$member['hpm']){
$hp=$member['hpm']; // cant go over your max hp =D
}
$mp=$member['mp']+$heal['mp'];
if($mp>$member['mpm']){
$mp=$member['mpm']; // cant go over your max mp =D
}
// status?
if($member['status']=="Blind" && $heal['ability']=="Cures Blind"){
$newstatus="";
} else if($member['status']=="Poison" && $heal['ability']=="Cures Poison"){
$newstatus="";
} else if($member['status']=="Silence" && $heal['ability']=="Cures Silence"){
$newstatus="";
} else {
$newstatus=$member['status'];
}

} else if(preg_match("/(\d+)_(\d+)/",$the_id)){

$prime_heal = preg_replace("/(\d+)_(\d+)/","$1",$the_id);
$secon_heal = preg_replace("/(\d+)_(\d+)/","$2",$the_id);

// Check Item Exixts (Also need var for below ;D)
if(!$p_heal=$DB->query_first("select * from inferno_heal where hid='{$prime_heal}'")){
RunError("You are trying to use a none existant potion. Check the url you have followed");
}

if(!$s_heal=$DB->query_first("select * from inferno_heal where hid='{$secon_heal}'")){
RunError("You are trying to use a none existant potion. Check the url you have followed");
}

$heal = array(
'img' => $p_heal['img'],
'name' => "{$p_heal['name']} Fused With {$s_heal['name']}",
'desc' => $p_heal['desc'],
'hid' => "{$p_heal['hid']}_{$s_heal['hid']}",
'ability' => $p_heal['ability'],
'hp' => ($p_heal['hp'] + $s_heal['hp']),
'mp' => ($p_heal['mp'] + $s_heal['mp']),
'cost' => ($p_heal['cost'] + $s_heal['cost']),
);

// Possible new hp/mp if query executes =D
$hp=$member['hp']+$heal['hp'];
if($hp>$member['hpm']){
$hp=$member['hpm']; // cant go over your max hp =D
}
$mp=$member['mp']+$heal['mp'];
if($mp>$member['mpm']){
$mp=$member['mpm']; // cant go over your max mp =D
}
// status?
if($member['status']=="Blind" && $heal['ability']=="Cures Blind"){
$newstatus="";
} else if($member['status']=="Poison" && $heal['ability']=="Cures Poison"){
$newstatus="";
} else if($member['status']=="Silence" && $heal['ability']=="Cures Silence"){
$newstatus="";
} else {
$newstatus=$member['status'];
}

} else {
RunError("You are trying to use a none existant potion. Check the url you have followed");
}



if($member['heal1']==$heal['hid']){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Heal During Battle Check ---
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@
// in battle? only use if your turn + use's up your turn PLUUUS adds it into battle log :P
if($member['inbattle']>0){
// connect to battle
$battle=$DB->query_first("select * from inferno_battle where bid='{$member['inbattle']}'");
if($battle['bid']!=""){
// who are you?
if($member['gid']==$battle['P1']){
// player uno =D
// your turn?
if($battle['turn']!="P1"){
RunError("You may only heal your self on your turn when in a battle");
} else {
// add log + change turn
$md="{$member['name']} used a healing potion taking ".ConfigureLanguage()." HP upto {$hp} and MP upto {$mp}";
$md=ParseInput($md);
$DB->query("insert into inferno_battlelog values ('','{$battle['bid']}','{$md}','')");
if($battle['type']!="Bot"){
$DB->query("update inferno_battle set turn='P2' where bid='{$battle['bid']}'");
}
}
} else if($member['gid']==$battle['P2']){
// player dos =D
// your turn?
if($battle['turn']!="P2"){
RunError("You may only heal your self on your turn when in a battle");
} else {
// add log + change turn
$md="{$member['name']} used a healing potion taking ".ConfigureLanguage()." HP upto {$hp} and MP upto {$mp}";
$md=ParseInput($md);
$DB->query("insert into inferno_battlelog values ('','{$battle['bid']}','{$md}','')");
if($battle['type']!="Bot"){
$DB->query("update inferno_battle set turn='P1' where bid='{$battle['bid']}'");
}
}
} else {
// wtf? no nothing o_o
}
}
}
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Heal During Battle Check ---
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@
$DB->query("update inferno_user set hp='{$hp}',mp='{$mp}',heal1='0',status='{$newstatus}' where gid='{$member['gid']}'");
} elseif($member['heal2']==$heal['hid']){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Heal During Battle Check ---
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@
// in battle? only use if your turn + use's up your turn PLUUUS adds it into battle log :P
if($member['inbattle']>0){
// connect to battle
$battle=$DB->query_first("select * from inferno_battle where bid='{$member['inbattle']}'");
if($battle['bid']!=""){
// who are you?
if($member['gid']==$battle['P1']){
// player uno =D
// your turn?
if($battle['turn']!="P1"){
RunError("You may only heal your self on your turn when in a battle");
} else {
// add log + change turn
$md="{$member['name']} used a healing potion taking ".ConfigureLanguage()." HP upto {$hp} and MP upto {$mp}";
$md=ParseInput($md);
$DB->query("insert into inferno_battlelog values ('','{$battle['bid']}','{$md}','')");
if($battle['type']!="Bot"){
$DB->query("update inferno_battle set turn='P2' where bid='{$battle['bid']}'");
}
}
} else if($member['gid']==$battle['P2']){
// player dos =D
// your turn?
if($battle['turn']!="P2"){
RunError("You may only heal your self on your turn when in a battle");
} else {
// add log + change turn
$md="{$member['name']} used a healing potion taking ".ConfigureLanguage()." HP upto {$hp} and MP upto {$mp}";
$md=ParseInput($md);
$DB->query("insert into inferno_battlelog values ('','{$battle['bid']}','{$md}','')");
if($battle['type']!="Bot"){
$DB->query("update inferno_battle set turn='P1' where bid='{$battle['bid']}'");
}
}
} else {
// wtf? no nothing o_o
}
}
}
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Heal During Battle Check ---
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@
$DB->query("update inferno_user set hp='{$hp}',mp='{$mp}',heal2='0',status='{$newstatus}' where gid='{$member['gid']}'");
} elseif($member['heal3']==$heal['hid']){
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Heal During Battle Check ---
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@
// in battle? only use if your turn + use's up your turn PLUUUS adds it into battle log :P
if($member['inbattle']>0){
// connect to battle
$battle=$DB->query_first("select * from inferno_battle where bid='{$member['inbattle']}'");
if($battle['bid']!=""){
// who are you?
if($member['gid']==$battle['P1']){
// player uno =D
// your turn?
if($battle['turn']!="P1"){
RunError("You may only heal your self on your turn when in a battle");
} else {
// add log + change turn
$md="{$member['name']} used a healing potion taking ".ConfigureLanguage()." HP upto {$hp} and MP upto {$mp}";
$md=ParseInput($md);
 
Ми там дават линк за сваляне и изтриване,и копираш само линка за сваляне.
 

Back
Горе