<?php

include($phpbb_root_path . 'rpg/function_rpg.'.$phpEx);

if ( !defined('IN_PHPBB') )
{
	die("Hacking attempt");
	exit;
}

$returnurl = '<br /><br /><a href="rpg.php?action=menu">返回上一頁</a>';

$template->set_filenames(array(
	'menu' => 'rpg_header.tpl',
	'body' => 'rpg_menu.tpl'
	)
);

// 清除歷史記錄
$sql = 'SELECT setting_value1 FROM xoops_pbb_rpg_setting WHERE setting_id = 2';
if ( $result = $db->sql_query($sql) )
{
	if ( $row = $db->sql_fetchrow($result) )
	{
		if ((time() - $row['setting_value1']) > 86400)
		{
			$sql = 'UPDATE xoops_pbb_rpg_setting SET setting_value1 = ' . time() . ' WHERE setting_id = 2';
			if( !$db->sql_query($sql) )
			{
				message_die(GENERAL_ERROR, "更新清除記錄時間發生錯誤!!", "", __LINE__, __FILE__, $sql);
			}
			$sql = 'DELETE FROM xoops_pbb_rpg_event WHERE event_time < ' . (time() - 86400 * 5);
			if( !$db->sql_query($sql) )
			{
				message_die(GENERAL_ERROR, "清除事件簿發生錯誤!!", "", __LINE__, __FILE__, $sql);
			}
			$sql = 'DELETE FROM xoops_pbb_rpg_rob WHERE task_over = 1 AND join_time < ' . (time() - 86400 * 5);
			if( !$db->sql_query($sql) )
			{
				message_die(GENERAL_ERROR, "清除搶劫記錄發生錯誤!!", "", __LINE__, __FILE__, $sql);
			}
		}
	}
}


// 取得個人資料
$profiledata = get_userdata(intval($userdata['uid']));


$righthand = '';
$lefthand = '';

$sql = 'SELECT i.item_name, i.item_position FROM xoops_pbb_rpg_items i, xoops_pbb_rpg_owns o WHERE i.in_which_store = 1 AND i.item_id = o.item_id AND o.uid = ' . intval($userdata['uid']) . ' ORDER BY i.item_position';
if ( $result = $db->sql_query($sql) )
{
	if ( $row = $db->sql_fetchrow($result) )
	{
		do
		{
			switch ($row['item_position'])
			{
				case 1:
					if ($righthand == '')
					{
						$righthand = $row['item_name'];
					}
					else
					{
						$lefthand = $row['item_name'];
					}
					break;
			}
		}
		while ( $row = $db->sql_fetchrow($result) );
	}
}

// 產生資料頁面
$page_title = "水怪大陸 RPG 首頁";
include($phpbb_root_path . 'includes/page_header.'.$phpEx);

$template->assign_vars(array(
	'USERNAME' => $profiledata['uname'],
	'AVATAR_IMG' => GetAvatar($profiledata),
	'RPG_TYPE_NAME' => $profiledata['rpg_medals'],
	'RPG_LEVEL' => $profiledata['rpg_level'],
	'RPG_EXP_VALUE' => $profiledata['rpg_cur_exp'] . ' / ' . $profiledata['rpg_max_exp'],
	'RPG_HP_VALUE' => $profiledata['rpg_cur_hp'] . ' / ' . $profiledata['rpg_max_hp'],
	'RPG_MP_VALUE' => $profiledata['rpg_cur_mp'] . ' / ' . $profiledata['rpg_max_mp'],
	'RPG_ATTACK' => $profiledata['rpg_attack'],
	'RPG_DEFENSE' => $profiledata['rpg_defense'],
	'RPG_MAGIC' => $profiledata['rpg_magic'],
	'RPG_SPEED' => $profiledata['rpg_speed'],
	'RPG_MONEY' => number_format($profiledata['user_money']),
	'RPG_BANK' => number_format($profiledata['user_bank']),
	'RPG_LEFT_HAND' => $lefthand,
	'RPG_RIGHT_HAND' => $righthand,
	'L_NOWMENU' => '檢視個人資料') );

$template->pparse('menu');
$template->pparse('body');

include($phpbb_root_path . 'includes/page_tail.'.$phpEx);

?>