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

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

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

//開始設定HP的值 
if ( isset($HTTP_POST_VARS['hps']) ) //取得使用者在頁面中輸入的hp值 
{ 
    $profiledata = get_userdata(intval($userdata['uid'])); //設定變數$profiledata為使用者資料 
    $hp = $HTTP_POST_VARS['hp']; //設定變數$hp為使用者在網頁中輸入的hp值 
    $fl_hp_money = "" . floor($hp * 20) . ""; 
    if (($hp > 0) && ($hp <= $profiledata['rpg_max_hp'])) //如果hp值大於0 而且 hp值等於使用者最大的HP值 
    { 
        if ($hp < 5) //如果hp值小於5 
        { 
            $rpg_hospital_result = "阿∼您真小氣耶..一次補這樣夠您冒險嗎？本醫院不接受 5 點以下的服務!"; //輸出警告文字 
        } 
      else if ($hp > $profiledata['rpg_max_hp'] - $profiledata['rpg_cur_hp']) //如果hp值大於使用者最大HP值減使用者現在的HP值 
      { 
         $rpg_hospital_result = "您....這樣輸入是不行的喔....明明沒有那麼多的ＨＰ"; //輸出警告文字 
      } 
      else if ($fl_hp_money > $profiledata['user_money']) //如果hp值大於使用者現金 
      { 
         $rpg_hospital_result = "咧....您的錢明明沒有那麼多"; //輸出警告文字 
      } 
        else //其他狀況下 
        { 
            $sql = "UPDATE " . USERS_TABLE . " SET rpg_cur_hp = rpg_cur_hp + " . ($hp) .", user_money = user_money - " . $fl_hp_money . " WHERE uid = " . intval($userdata['uid']); //設定SQL::恢復HP並減少HP值*20的金錢 
            if( !$db->sql_query($sql) ) 
            { 
                message_die(GENERAL_ERROR, "無法修改個人HP!", "", __LINE__, __FILE__, $sql); 
            } 
       $sql = "UPDATE " . CONFIG_TABLE . " SET config_value = config_value + " . $fl_hp_money . " WHERE config_name = 'rpg_jackpot'"; 
            if( !$db->sql_query($sql) ) 
            { 
                message_die(GENERAL_ERROR, "無法更新頭彩獎金!", "", __LINE__, __FILE__, $sql); 
            } 
            $rpg_hospital_result = "回復ＨＰ值 " . ($hp) . " 成功! (小護士收您 " . $fl_hp_money . " 元納入頭彩彩金)"; 
       $profiledata = get_userdata(intval($userdata['uid'])); 
        } 
    } 
    else 
    { 
            $rpg_hospital_result = "您HP輸入太多了啦！別自不量力好嗎？"; 
    } 
} 
/*開始設定MP的值*/ 
if ( isset($HTTP_POST_VARS['mps']) ) 
{ 
    $profiledata = get_userdata(intval($userdata['uid'])); 
    $mp = $HTTP_POST_VARS['mp']; 
    $fl_mp_money = "" . floor($mp * 10) . ""; 
    if (($mp > 0) && ($mp <= $profiledata['rpg_max_mp'])) 
    { 
        if ($mp < 5) 
        { 
            $rpg_hospital_result = "啊∼您真小氣耶..一次補這樣夠您冒險嗎？本醫院不接受 5 點以下的服務!"; 
        } 
      else if ($mp > $profiledata['rpg_max_mp'] - $profiledata['rpg_cur_mp']) 
      { 
         $rpg_hospital_result = "您....這樣輸入是不行的喔....明明沒有那麼多的ＭＰ"; 
      } 
      else if ($fl_mp_money > $profiledata['user_money']) 
      { 
         $rpg_hospital_result = "咧....您的錢明明沒有那麼多"; 
      } 
        else 
        { 
            $sql = "UPDATE " . USERS_TABLE . " SET rpg_cur_mp = rpg_cur_mp + " . ($mp) .", user_money = user_money - " . $fl_mp_money . " WHERE uid = " . intval($userdata['uid']); 
            if( !$db->sql_query($sql) ) 
            { 
                message_die(GENERAL_ERROR, "無法修改個人MP!", "", __LINE__, __FILE__, $sql); 
            } 
       $sql = "UPDATE " . CONFIG_TABLE . " SET config_value = config_value + " . $fl_mp_money . " WHERE config_name = 'rpg_jackpot'"; 
            if( !$db->sql_query($sql) ) 
            { 
                message_die(GENERAL_ERROR, "無法更新頭彩獎金!", "", __LINE__, __FILE__, $sql); 
            } 
            $rpg_hospital_result = "回復ＭＰ " . ($mp) . " 成功! (小護士收您 " . $fl_mp_money . " 納入頭彩彩金)"; 
       $profiledata = get_userdata(intval($userdata['uid'])); 
        } 
    } 
    else 
    { 
            $rpg_hospital_result = "您ＭＰ輸入太多了啦！別自不量力好嗎？"; 
    } 
} 

/* Hospital WaterMonster RPG Mod by bu<buhip@yahoo.co.jp> 
   global $db; 

   $sql = "update xoops_users set rpg_cur_hp = rpg_max_hp, rpg_cur_mp = rpg_max_mp where uid = $uid"; 
   $rpg_hospital_result = "ＨＰ和ＭＰ已經補滿"; 

   if ( !($result = $db->sql_query($sql)) ) 
   { 
      message_die(GENERAL_ERROR, '無法治療您的傷害，真是對不起', '', __LINE__, __FILE__, $sql); 
   }*/ 

// 產生資料頁面 

$page_title = "俏護士小醫院"; 
include($phpbb_root_path . 'includes/page_header.'.$phpEx); 

$template->assign_vars(array( 
   'RPG_LEVEL' => $profiledata['rpg_level'], 
   'RPG_HP_VALUE' => $profiledata['rpg_cur_hp'] . ' / ' . $profiledata['rpg_max_hp'], 
   'RPG_MP_VALUE' => $profiledata['rpg_cur_mp'] . ' / ' . $profiledata['rpg_max_mp'], 
   'USERNAME' => $profiledata['uname'], 
   'AVATAR_IMG' => GetAvatar($profiledata), 
   'RPG_MONEY' => number_format($profiledata['user_money']), 
   'RPG_HOSPITAL_RESULT' => $rpg_hospital_result, 
   'HP_MAX' => $profiledata['rpg_max_hp'] - $profiledata['rpg_cur_hp'], 
   'MP_MAX' => $profiledata['rpg_max_mp'] - $profiledata['rpg_cur_mp']) 
); 

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

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

?> 