<?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=dice">返回上一頁</a>';

$template->set_filenames(array(
	'menu' => 'rpg_header.tpl',
	'body' => 'rpg_dice.tpl')
); // 取得個人資料
$profiledata = get_userdata(intval($userdata['uid'])); $act = trim($act);
/*if (!isset($act) or $act=="") {
  $act="horse";
}*/ $postuname = $profiledata['uname'];
$rpg_dice_result = "";
if ($HTTP_POST_VARS['act']=="bet")
{
	$rpg_dice_result = "";
	$mony=trim(addslashes($pay_money));
	$usermoney =  $profiledata['user_money'];
	$pay =  trim($pay);
	if($pay =="point")
	{
		$point = trim(addslashes($point));
	}
	if ($mony<100 || $mony>10000)
	{
		$rpg_dice_result .="對不起，您的下注金額不在規定的範圍內!!";
		$rpg_dice_result .="<br />".$returnurl;
	}
	else if ($usermoney<$mony)
	{
		$rpg_dice_result .="對不起，您的下注金額超出了您持有的現金!!";
		$rpg_dice_result .="<br />".$returnurl;
	}
	else {
		$sql= "UPDATE xoops_users SET
		user_money=user_money-".$mony." WHERE uid='".$profiledata[uid]."'";
	if( !$db->sql_query($sql) )
	{
		message_die(GENERAL_ERROR, "無法更新會員的現金!!", "", __LINE__, __FILE__, $sql);
	}
		srand((double)microtime()*1000000);
		$randid1 = rand(1, 6);
		$randid2 = rand(1, 6);
		$randid3 = rand(1, 6);
		$randid = $randid1 + $randid2 + $randid3;
		$win = 0;
		if ($pay == "big" && $randid >10)
		{
			$win = 1;
			$mony1 = $mony*2;
		}
		if ($pay == "small" && $randid <=10)
		{
			$win = 1;
			$mony1 = $mony*2;
		}
		if ($pay == "point")
		{
			if ($randid == $point)
			{
				$win = 1;
				$mony1 = $mony*10;
			}
		}
		$rpg_dice_result .="<body bgcolor=\"#FFFFFF\" onLoad=\"MM_preloadImages('images/dice/1.gif','images/dice/2.gif','images/dice/3.gif')\">";
		if ($win)
		{
			$mony2 = $mony1-$mony;
			$rpg_dice_result .="<div id=\"Layer_result\" style=\"position:absolute; left:330px; top:550px; width:330px; height:45px; z-index:1; visibility: hidden\"><center><span class=gen><img src=images/dice/win.gif>恭喜，您贏了 <font color=#FF6600>".$mony2."</font> 元。</font></span><p class=gen>[ <a href=rpg.php?action=dice>再來一盤</a> ] [ <a href=rpg.php?action=menu>回主選單</a> ]</p></center></div>\n";
			$sql= "UPDATE xoops_users SET
			user_money=user_money+".$mony1." WHERE uid='".$profiledata[uid]."'";
			if( !$db->sql_query($sql) )
			{
				message_die(GENERAL_ERROR, "無法更新會員的現金!!", "", __LINE__, __FILE__, $sql);
			}
		}
		else
		{
			$rpg_dice_result .="<div id=\"Layer_result\" style=\"position:absolute; left:330px; top:550px; width:330px; height:45px; z-index:1; visibility: hidden\"><center><span class=gen><img src=images/dice/lose.gif>真遺憾，您輸了 <font color=#FF6600>".$mony."</font> 元。</font></span><p class=gen>[ <a href=rpg.php?action=dice>再來一盤</a> ] [ <a href=index.php>回論壇首頁</a> ]</p></center></div>\n";
		}
		$rpg_dice_result .="<table width=\"410\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">"
							."<tr align=\"center\">"
							."<td width=\"65\"><img src=\"images/dice/run.gif\" width=\"38\" height=\"36\" name=\"run1\"></td>"
							."<td width=\"68\"><img src=\"images/dice/run.gif\" width=\"38\" height=\"36\" name=\"run2\"></td>"
							."<td width=\"71\"><img src=\"images/dice/run.gif\" width=\"38\" height=\"36\" name=\"run3\"></td>"
							."<td width=\"218\"><a href=\"#\"><img src=\"images/dice/button.gif\" width=\"50\" height=\"40\" onClick=\"MM_swapImage('run1','','images/dice/".$randid1.".gif',1);MM_swapImage('run2','','images/dice/".$randid2.".gif',1);MM_swapImage('run3','','images/dice/".$randid3.".gif',1);MM_showHideLayers('Layer_result','','show')\" border=\"0\" align=\"absmiddle\"></a>"
							."<span class=gen> <-- 按下這裡開始!!</span></td>"
							."</tr>"
							."</table></body>";
	}
}
else
{
$rpg_dice_result .="<script language=javascript>"
		."var subNo=0;"
		."function formCheck()"
		."{"
		."	if (document.theform.pay_money.value == \"\")"
		."	{"
		."		alert(\"請填寫下注金額\");"
		."		document.theform.pay_money.focus();"
		."		return false;"
		."	}"
		."	subNo=1;"
		."	return true;"
		."}"
		."</script>";

$rpg_dice_result .="<form name=\"theform\" method=\"post\" action=rpg.php?action=dice onsubmit=\"return formCheck();\">";
$rpg_dice_result .="<input type=\"hidden\" name=\"act\" value=\"bet\">";
$rpg_dice_result .="<table width=535 border=0 cellspacing=1 cellpadding=3  bgcolor=\"#003399\">";
$rpg_dice_result .="<tr bgcolor=\"#FFFFFF\"> "
					."<td colspan=\"4\" height=\"103\">"
					."<p><input type=\"radio\" name=\"pay\" value=\"big\" checked>"
					."<img src=\"images/dice/big.gif\" width=\"46\" height=\"40\">"
					."<input type=\"radio\" name=\"pay\" value=\"small\">"
					."<img src=\"images/dice/small.gif\" width=\"46\" height=\"40\"> <span class=\"gen\">賠率：2</span></p>"
					."<p><input type=\"radio\" name=\"pay\" value=\"point\">"
					."<span class=\"gen\">買點數："
					."<input type=\"text\" name=\"point\" value=\"3\" size=\"2\" maxlength=\"2\"> ( 3 - 18 點) 賠率：10</span>"
					."</p></td>"
					."</tr>"
					."<tr bgcolor=\"#CCCCFF\"> "
					."<td colspan=\"4\" height=\"40\"><span class=\"gen\">下注：</span>"
					."<input type=\"text\" name=\"pay_money\" value=\"100\" size=\"6\"> "
					."<input type=\"submit\" name=\"Submit\" value=\"下注\" onclick=\"if (subNo>0){this.disabled=true; return false;}\">"
					."</td>"
					."</tr></table></form>";
} // 產生資料頁面
$page_title = "水怪大陸 RPG 首頁";
include($phpbb_root_path . 'includes/page_header.'.$phpEx); $template->assign_vars(array(
	'USERNAME' => $profiledata['uname'],
	'AVATAR_IMG' => GetAvatar($profiledata),
	'RPG_MONEY' => number_format($profiledata['user_money']),
	'RPG_DICE_RESULT' => $rpg_dice_result,
	'L_NOWMENU' => '水怪骰子遊戲') ); if ( $act == 'bet' )
{
	$template->assign_block_vars('bet_result', array());
}

$template->pparse('menu');
$template->pparse('body'); include($phpbb_root_path . 'includes/page_tail.'.$phpEx); ?>