| [ PHPXref.com ] | [ Generated: Sun Jul 20 18:37:24 2008 ] | [ MetaBB 5.0 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /*************************************************************************** 3 * adr_character_pvp.php 4 * ------------------------ 5 * begin : 30/03/2004 6 * copyright : Malicious Rabbit / Dr DLP 7 * 8 * 9 ***************************************************************************/ 10 11 /*************************************************************************** 12 * 13 * This program is free software; you can redistribute it and/or modify 14 * it under the terms of the GNU General Public License as published by 15 * the Free Software Foundation; either version 2 of the License, or 16 * (at your option) any later version. 17 * 18 * 19 ***************************************************************************/ 20 21 define('IN_PHPBB', true); 22 define('IN_ADR_SHOPS', true); 23 define('IN_ADR_CHARACTER', true); 24 define('IN_ADR_BATTLE', true); 25 define('IN_ADR_PVP', true); 26 $phpbb_root_path = './'; 27 include ($phpbb_root_path . 'extension.inc'); 28 include($phpbb_root_path . 'common.'.$phpEx); 29 30 $loc = 'battle_community'; 31 $sub_loc = 'adr_character_pvp'; 32 33 // 34 // Start session management 35 $userdata = session_pagestart($user_ip, PAGE_INDEX); 36 init_userprefs($userdata); 37 // End session management 38 // 39 40 include($phpbb_root_path . 'adr/includes/adr_global.'.$phpEx); 41 $user_id = $userdata['user_id']; 42 43 // Sorry , only logged users ... 44 if ( !$userdata['session_logged_in'] ) 45 { 46 $redirect = "adr_character_pvp.$phpEx"; 47 $redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : ''; 48 header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true)); 49 } 50 51 // have the mail sender infos 52 $script_name = preg_replace('/^\/?(.*?)\/?$/', "\\1", trim($board_config['script_path'])); 53 $script_name = ( $script_name != '' ) ? $script_name . '/adr_character_pvp.'.$phpEx.'?mode=waiting' : 'adr_character_pvp.'.$phpEx; 54 $server_name = trim($board_config['server_name']); 55 $server_protocol = ( $board_config['cookie_secure'] ) ? 'https://' : 'http://'; 56 $server_port = ( $board_config['server_port'] <> 80 ) ? ':' . trim($board_config['server_port']) . '/' : '/'; 57 58 adr_template_file('adr_battle_pvp_list_body.tpl'); 59 include($phpbb_root_path . 'includes/page_header.'.$phpEx); 60 61 // Get the general config 62 $adr_general = adr_get_general_config(); 63 64 adr_enable_check(); 65 adr_ban_check($user_id); 66 adr_character_created_check($user_id); 67 68 if ( !$adr_general['battle_pvp_enable'] ) 69 { 70 adr_previous ( Adr_pvp_disabled , adr_character , '' ); 71 } 72 73 if ( (!( isset($HTTP_POST_VARS[POST_USERS_URL]) || isset($HTTP_GET_VARS[POST_USERS_URL]))) || ( empty($HTTP_POST_VARS[POST_USERS_URL]) && empty($HTTP_GET_VARS[POST_USERS_URL]))) 74 { 75 $view_userdata = $userdata; 76 } 77 else 78 { 79 $view_userdata = get_userdata(intval($HTTP_GET_VARS[POST_USERS_URL])); 80 } 81 $searchid = $view_userdata['user_id']; 82 83 if( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) ) 84 { 85 $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode']; 86 $mode = htmlspecialchars($mode); 87 } 88 else 89 { 90 $mode = ""; 91 } 92 93 $defy_action = isset($HTTP_POST_VARS['defy']); 94 $accept_action = isset($HTTP_POST_VARS['accept_action']); 95 96 // Now we define some strange cases 97 $mode = ( $defy_action ) ? 'defy_action' : $mode; 98 $mode = ( $accept_action ) ? 'accept_action' : $mode; 99 $mode = ( $mode == 'current' ) ? '' : $mode; 100 101 if ( $mode != "" ) 102 { 103 switch($mode) 104 { 105 case 'accept' : 106 107 $battle_id = intval($HTTP_GET_VARS['battle_id']); 108 109 $template->assign_block_vars('equip',array()); 110 $template->assign_block_vars('equip.accept',array()); 111 112 // Be sure the user is live before beginning the battle 113 $sql = " SELECT * FROM " . ADR_CHARACTERS_TABLE . " 114 WHERE character_id = $user_id "; 115 if( !($result = $db->sql_query($sql)) ) 116 { 117 message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); 118 } 119 $char = $db->sql_fetchrow($result); 120 if ( $char['character_hp'] < 1 ) 121 { 122 $message = $lang['Adr_battle_character_dead']; 123 $message .= '<br /><br />'.sprintf($lang['Adr_battle_temple'] ,"<a href=\"" . 'adr_temple.'.$phpEx . "\">", "</a>") ; 124 $message .= '<br /><br />'.sprintf($lang['Adr_character_return'] ,"<a href=\"" . 'adr_character.'.$phpEx . "\">", "</a>") ; 125 message_die ( GENERAL_MESSAGE , $message ); 126 } 127 128 // See if we have to limit the items 129 $item_sql = ( $adr_general['item_power_level'] ) ? ' AND item_power <='.$char['character_level'] : ''; 130 131 // First select the available items 132 $sql = " SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . " 133 WHERE item_in_shop = 0 134 AND item_duration > 0 135 $item_sql 136 AND item_owner_id = $user_id "; 137 if( !($result = $db->sql_query($sql)) ) 138 { 139 message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); 140 } 141 $items = $db->sql_fetchrowset($result); 142 143 // Prepare the items list 144 $armor_list = '<select name="item_armor">'; 145 $armor_list .= '<option value = "0" >' . $lang['Adr_battle_no_armor'] . '</option>'; 146 $buckler_list = '<select name="item_buckler">'; 147 $buckler_list .= '<option value = "0" >' . $lang['Adr_battle_no_buckler'] . '</option>'; 148 $helm_list = '<select name="item_helm">'; 149 $helm_list .= '<option value = "0" >' . $lang['Adr_battle_no_helm'] . '</option>'; 150 $gloves_list = '<select name="item_gloves">'; 151 $gloves_list .= '<option value = "0" >' . $lang['Adr_battle_no_gloves'] . '</option>'; 152 $amulet_list = '<select name="item_amulet">'; 153 $amulet_list .= '<option value = "0" >' . $lang['Adr_battle_no_amulet'] . '</option>'; 154 $ring_list = '<select name="item_ring">'; 155 $ring_list .= '<option value = "0" >' . $lang['Adr_battle_no_ring'] . '</option>'; 156 $equip_armor = $char['equip_armor']; 157 $equip_buckler = $char['equip_buckler']; 158 $equip_helm = $char['equip_helm']; 159 $equip_gloves = $char['equip_gloves']; 160 $equip_amulet = $char['equip_amulet']; 161 $equip_ring = $char['equip_ring']; 162 163 for ( $i = 0 ; $i < count($items) ; $i ++ ) 164 { 165 $item_power = $items[$i]['item_power'] + $items[$i]['item_add_power']; 166 167 if ( $items[$i]['item_type_use'] == 7 ) 168 { 169 $armor_selected = ( $equip_armor == $items[$i]['item_id'] ) ? 'selected' : ''; 170 $armor_list .= '<option value = "'.$items[$i]['item_id'].'" '.$armor_selected.' >' . adr_get_lang($items[$i]['item_name']) . ' ( ' . $lang['Adr_items_power'] . ' : ' . $items[$i]['item_power'] . ' - ' . $lang['Adr_items_duration'] . ' : ' . $items[$i]['item_duration'] . ' )'.'</option>'; 171 } 172 if ( $items[$i]['item_type_use'] == 8 ) 173 { 174 $buckler_selected = ( $equip_buckler == $items[$i]['item_id'] ) ? 'selected' : ''; 175 $buckler_list .= '<option value = "'.$items[$i]['item_id'].'" '.$buckler_selected.'>' . adr_get_lang($items[$i]['item_name']) . ' ( ' . $lang['Adr_items_power'] . ' : ' . $items[$i]['item_power'] . ' - ' . $lang['Adr_items_duration'] . ' : ' . $items[$i]['item_duration'] . ' )'.'</option>'; 176 } 177 if ( $items[$i]['item_type_use'] == 9 ) 178 { 179 $helm_selected = ( $equip_helm == $items[$i]['item_id'] ) ? 'selected' : ''; 180 $helm_list .= '<option value = "'.$items[$i]['item_id'].'" '.$helm_selected.'>' . adr_get_lang($items[$i]['item_name']) . ' ( ' . $lang['Adr_items_power'] . ' : ' . $items[$i]['item_power'] . ' - ' . $lang['Adr_items_duration'] . ' : ' . $items[$i]['item_duration'] . ' )'.'</option>'; 181 } 182 if ( $items[$i]['item_type_use'] == 10 ) 183 { 184 $gloves_selected = ( $equip_gloves == $items[$i]['item_id'] ) ? 'selected' : ''; 185 $gloves_list .= '<option value = "'.$items[$i]['item_id'].'" '.$gloves_selected.'>' . adr_get_lang($items[$i]['item_name']) . ' ( ' . $lang['Adr_items_power'] . ' : ' . $items[$i]['item_power'] . ' - ' . $lang['Adr_items_duration'] . ' : ' . $items[$i]['item_duration'] . ' )'.'</option>'; 186 } 187 if ( $items[$i]['item_type_use'] == 13 ) 188 { 189 $amulet_selected = ( $equip_amulet == $items[$i]['item_id'] ) ? 'selected' : ''; 190 $amulet_list .= '<option value = "'.$items[$i]['item_id'].'" '.$amulet_selected.'>' . adr_get_lang($items[$i]['item_name']) . ' ( ' . $lang['Adr_items_power'] . ' : ' . $items[$i]['item_power'] . ' - ' . $lang['Adr_items_duration'] . ' : ' . $items[$i]['item_duration'] . ' )'.'</option>'; 191 } 192 if ( $items[$i]['item_type_use'] == 14 ) 193 { 194 $ring_selected = ( $equip_ring == $items[$i]['item_id'] ) ? 'selected' : ''; 195 $ring_list .= '<option value = "'.$items[$i]['item_id'].'" '.$ring_selected.'>' . adr_get_lang($items[$i]['item_name']) . ' ( ' . $lang['Adr_items_power'] . ' : ' . $items[$i]['item_power'] . ' - ' . $lang['Adr_items_duration'] . ' : ' . $items[$i]['item_duration'] . ' )'.'</option>'; 196 } 197 } 198 199 $armor_list .= '</select>'; 200 $buckler_list .= '</select>'; 201 $helm_list .= '</select>'; 202 $gloves_list .= '</select>'; 203 $amulet_list .= '</select>'; 204 $ring_list .= '</select>'; 205 206 $template->assign_vars(array( 207 'BATTLE_ID' => $battle_id, 208 'SELECT_ARMOR' => $armor_list, 209 'SELECT_BUCKLER' => $buckler_list, 210 'SELECT_HELM' => $helm_list, 211 'SELECT_GLOVES' => $gloves_list, 212 'SELECT_AMULET' => $amulet_list, 213 'SELECT_RING' => $ring_list, 214 "L_ACCEPT_DEFY" => $lang['Adr_pvp_defy_accept'], 215 'L_EQUIPMENT' => $lang['Adr_battle_equipment'], 216 'L_SELECT_ARMOR' => $lang['Adr_battle_select_armor'], 217 'L_SELECT_BUCKLER' => $lang['Adr_battle_select_buckler'], 218 'L_SELECT_HELM' => $lang['Adr_battle_select_helm'], 219 'L_SELECT_GLOVES' => $lang['Adr_battle_select_gloves'], 220 'L_SELECT_AMULET' => $lang['Adr_battle_select_amulet'], 221 'L_SELECT_RING' => $lang['Adr_battle_select_ring'], 222 )); 223 224 break; 225 226 case 'accept_action' : 227 228 $battle_id = intval($HTTP_POST_VARS['battle_id']); 229 230 // Fix the items ids 231 $armor = intval($HTTP_POST_VARS['item_armor']); 232 $buckler = intval($HTTP_POST_VARS['item_buckler']); 233 $helm = intval($HTTP_POST_VARS['item_helm']); 234 $gloves = intval($HTTP_POST_VARS['item_gloves']); 235 $amulet = intval($HTTP_POST_VARS['item_amulet']); 236 $ring = intval($HTTP_POST_VARS['item_ring']); 237 238 // Get the user infos 239 $sql = " SELECT * FROM " . ADR_CHARACTERS_TABLE . " 240 WHERE character_id = $user_id "; 241 if( !($result = $db->sql_query($sql)) ) 242 { 243 message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); 244 } 245 $char = $db->sql_fetchrow($result); 246 247 // Be sure he has a character 248 if ( !(is_numeric($char['character_id']))) 249 { 250 adr_previous( Adr_your_character_lack , adr_character , '' ); 251 } 252 253 // Calculate the base stats 254 $hp = $char['character_hp']; 255 $mp = $char['character_mp']; 256 $ma = $char['character_magic_attack']; 257 $md = $char['character_magic_resistance']; 258 $hp_max = $char['character_hp_max']; 259 $mp_max = $char['character_mp_max']; 260 $hp_regen = 0; 261 $mp_regen = 0; 262 $elemental = $char['character_element']; 263 264 // At first make the attack power . This is the sum of might and constitution * 2 265 $att = ( $char['character_might'] + $char['character_constitution'] ) * 2 ; 266 267 // Then make the defense power . This is the sum of dexterity , armor class and willpower , plus the items power 268 $def = $char['character_dexterity'] + $char['character_wisdom'] + $char['character_ac']; 269 270 if ( $armor ) 271 { 272 $sql = " SELECT item_power, item_add_power FROM " . ADR_SHOPS_ITEMS_TABLE . " 273 WHERE item_in_shop = 0 274 AND item_owner_id = $user_id 275 AND item_id = $armor "; 276 if( !($result = $db->sql_query($sql)) ) 277 { 278 message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); 279 } 280 $item = $db->sql_fetchrow($result); 281 282 $def = ( $def + $item['item_power'] ) + $item['item_add_power']; 283 $armour_name = $item['item_name']; 284 adr_use_item($armor , $user_id); 285 } 286 287 if ( $buckler ) 288 { 289 $sql = " SELECT item_name , item_power , item_add_power FROM " . ADR_SHOPS_ITEMS_TABLE . " 290 WHERE item_in_shop = 0 291 AND item_owner_id = $user_id 292 AND item_id = $buckler "; 293 if( !($result = $db->sql_query($sql)) ) 294 { 295 message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); 296 } 297 $item = $db->sql_fetchrow($result); 298 299 $def = ( $def + $item['item_power'] ) + $item['item_add_power']; 300 $buckler_name = $item['item_name']; 301 adr_use_item($buckler , $user_id); 302 } 303 304 if ( $gloves ) 305 { 306 $sql = " SELECT item_name , item_power , item_add_power FROM " . ADR_SHOPS_ITEMS_TABLE . " 307 WHERE item_in_shop = 0 308 AND item_owner_id = $user_id 309 AND item_id = $gloves "; 310 if( !($result = $db->sql_query($sql)) ) 311 { 312 message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); 313 } 314 $item = $db->sql_fetchrow($result); 315 316 $def = ( $def + $item['item_power'] ) + $item['item_add_power']; 317 $gloves_name = $item['item_name']; 318 adr_use_item($gloves , $user_id); 319 } 320 321 if ( $helm ) 322 { 323 $sql = " SELECT item_name , item_power , item_add_power FROM " . ADR_SHOPS_ITEMS_TABLE . " 324 WHERE item_in_shop = 0 325 AND item_owner_id = $user_id 326 AND item_id = $helm "; 327 if( !($result = $db->sql_query($sql)) ) 328 { 329 message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); 330 } 331 $item = $db->sql_fetchrow($result); 332 333 $def = ( $def + $item['item_power'] ) + $item['item_add_power']; 334 $helm_name = $item['item_name']; 335 adr_use_item($helm , $user_id); 336 } 337 338 // Now we modify mp and hp regeneration with amulets and rings 339 if ( $amulet ) 340 { 341 $sql = " SELECT item_power FROM " . ADR_SHOPS_ITEMS_TABLE . " 342 WHERE item_in_shop = 0 343 AND item_owner_id = $user_id 344 AND item_id = $amulet "; 345 if( !($result = $db->sql_query($sql)) ) 346 { 347 message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); 348 } 349 $item = $db->sql_fetchrow($result); 350 351 $hp_regen = $hp_regen + $item['item_power']; 352 353 adr_use_item($amulet , $user_id); 354 } 355 356 if ( $ring ) 357 { 358 $sql = " SELECT item_power FROM " . ADR_SHOPS_ITEMS_TABLE . " 359 WHERE item_in_shop = 0 360 AND item_owner_id = $user_id 361 AND item_id = $ring "; 362 if( !($result = $db->sql_query($sql)) ) 363 { 364 message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); 365 } 366 $item = $db->sql_fetchrow($result); 367 368 $mp_regen = $mp_regen + $item['item_power']; 369 370 adr_use_item($ring , $user_id); 371 } 372 373 // Now update the database 374 $sql = " UPDATE " . ADR_BATTLE_PVP_TABLE . " 375 SET battle_opponent_att = $att, 376 battle_opponent_def = $def, 377 battle_opponent_magic_attack = $ma, 378 battle_opponent_magic_resistance = $md, 379 battle_opponent_hp = $hp, 380 battle_opponent_mp = $mp, 381 battle_opponent_hp_max = $hp_max, 382 battle_opponent_mp_max = $mp_max, 383 battle_opponent_hp_regen = $hp_regen, 384 battle_opponent_mp_regen = $mp_regen, 385 battle_opponent_element = $elemental, 386 battle_turn = $user_id, 387 battle_result = 3 388 WHERE battle_id = $battle_id 389 AND battle_opponent_id = $user_id "; 390 $result = $db->sql_query($sql); 391 if( !$result ) 392 { 393 message_die(GENERAL_ERROR, "Couldn't insert new battle", "", __LINE__, __FILE__, $sql); 394 } 395 // Do armour set check for opponent 396 adr_pvp_armour_set_check($battle_id, 0, $user_id, $armour_name, $buckler_name, $gloves_name, $helm_name); 397 398 $sql = " SELECT * FROM " . ADR_BATTLE_PVP_TABLE . " 399 WHERE battle_result = 3 400 AND battle_id = $battle_id 401 AND ( battle_opponent_id = $user_id OR battle_challenger_id = $user_id ) "; 402 if( !($result = $db->sql_query($sql)) ) 403 { 404 message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); 405 } 406 $row = $db->sql_fetchrow($result); 407 408 // Get the "other" id 409 $other_id = ( $row['battle_opponent_id'] != $user_id ) ? intval($row['battle_opponent_id']) : intval($row['battle_challenger_id']); 410 411 // Get opponent's character name name 412 $ssql = "SELECT character_name FROM " . ADR_CHARACTERS_TABLE . " 413 WHERE character_id = '$other_id'"; 414 if(!($sresult = $db->