[ PHPXref.com ] [ Generated: Sun Jul 20 18:37:24 2008 ] [ MetaBB 5.0 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> adr_ambush.php (source)

   1  <?php 
   2  /***************************************************************************

   3   *                    adr_battle.php

   4   *                ------------------------

   5   *    begin             : 08/02/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_CHARACTER', true); 
  23  define('IN_ADR_BATTLE', true); 
  24  define('IN_ADR_SHOPS', true);
  25  $phpbb_root_path = './'; 
  26  include ($phpbb_root_path . 'extension.inc'); 
  27  include($phpbb_root_path . 'common.'.$phpEx);
  28  
  29  $loc = 'battle_community';
  30  $sub_loc = 'adr_battle';
  31  
  32  //

  33  // Start session management

  34  $userdata = session_pagestart($user_ip, PAGE_INDEX); 
  35  init_userprefs($userdata); 
  36  // End session management

  37  //

  38  $user_id = $userdata['user_id'];
  39  $user_points = $userdata['user_points'];
  40  include($phpbb_root_path . 'adr/includes/adr_global.'.$phpEx);
  41  
  42  // Sorry , only logged users ...

  43  if ( !$userdata['session_logged_in'] )
  44  {
  45      $redirect = "adr_battle.$phpEx";
  46      $redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : '';
  47      header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true));
  48  }
  49  
  50  // Get the general config

  51  $adr_general = adr_get_general_config();
  52  
  53  adr_enable_check();
  54  adr_ban_check($user_id);
  55  adr_character_created_check($user_id);
  56  adr_levelup_check($user_id);
  57  adr_weight_check($user_id);
  58  
  59  if ( !$adr_general['battle_enable'] ) 
  60  {    
  61      adr_previous ( Adr_battle_disabled , adr_character , '' );
  62  }
  63  // Deny access if user is imprisioned 

  64  if($userdata['user_cell_time']){ 
  65  adr_previous(Adr_shops_no_thief, adr_cell, '');
  66  }
  67  
  68  
  69  // Includes the tpl and the header

  70  adr_template_file('adr_battle_body.tpl');
  71  include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  72  
  73  $equip = isset($HTTP_POST_VARS['equip']);
  74  $attack = isset($HTTP_POST_VARS['attack']);
  75  $spell = isset($HTTP_POST_VARS['spell']);
  76  $potion = isset($HTTP_POST_VARS['potion']);
  77  $defend = isset($HTTP_POST_VARS['defend']);
  78  $flee = isset($HTTP_POST_VARS['flee']);
  79  $scan = isset($HTTP_POST_VARS['scan']);
  80  
  81  // Select if the user has a battle in progress or no

  82  $sql = " SELECT * FROM  " . ADR_BATTLE_LIST_TABLE . " 
  83      WHERE battle_challenger_id = $user_id
  84      AND battle_result = 0
  85      AND battle_type = 1 ";
  86  if( !($result = $db->sql_query($sql)) )
  87  {
  88      message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql);
  89  }
  90  $bat = $db->sql_fetchrow($result);
  91  
  92  if ( !(is_numeric($bat['battle_id'])) && !$equip )
  93  {
  94      // Be sure the user is     live before beginning the battle

  95      $sql = " SELECT * FROM  " . ADR_CHARACTERS_TABLE . " 
  96          WHERE character_id = $user_id ";
  97      if( !($result = $db->sql_query($sql)) )
  98      {
  99          message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql);
 100      }
 101      $char = $db->sql_fetchrow($result);
 102  
 103      if ( $char['character_hp'] < 1 )
 104      {
 105          $message = $lang['Adr_battle_character_dead'];
 106          $message .= '<br /><br />'.sprintf($lang['Adr_battle_temple'] ,"<a href=\"" . 'adr_temple.'.$phpEx . "\">", "</a>") ;
 107          $message .= '<br /><br />'.sprintf($lang['Adr_character_return'] ,"<a href=\"" . 'adr_character.'.$phpEx . "\">", "</a>") ;
 108          message_die ( GENERAL_MESSAGE , $message );
 109      }
 110  
 111      // No battle in progress , display the equipment page

 112      adr_template_file('adr_battle_equip_body.tpl');
 113  
 114      // See if we have to limit the items 

 115      $item_sql = ( $adr_general['item_power_level'] ) ? ' AND item_power <='.$char['character_level'] : '';
 116  
 117      // First select the available items

 118      $sql = " SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . "
 119          WHERE item_in_shop = 0 
 120          AND item_duration > 0
 121          AND item_in_warehouse = 0
 122          $item_sql
 123          AND item_owner_id = $user_id ";
 124      if( !($result = $db->sql_query($sql)) )
 125      {
 126          message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql);
 127      }
 128      $items = $db->sql_fetchrowset($result);
 129  
 130      // Prepare the items list

 131      $armor_list = '<select name="item_armor">';
 132      $armor_list .= '<option value = "0" >' . $lang['Adr_battle_no_armor'] . '</option>';
 133      $buckler_list = '<select name="item_buckler">';
 134      $buckler_list .= '<option value = "0" >' . $lang['Adr_battle_no_buckler'] . '</option>';
 135      $helm_list = '<select name="item_helm">';
 136      $helm_list .= '<option value = "0" >' . $lang['Adr_battle_no_helm'] . '</option>';
 137      $gloves_list = '<select name="item_gloves">';
 138      $gloves_list .= '<option value = "0" >' . $lang['Adr_battle_no_gloves'] . '</option>';
 139      $amulet_list = '<select name="item_amulet">';
 140      $amulet_list .= '<option value = "0" >' . $lang['Adr_battle_no_amulet'] . '</option>';
 141      $ring_list = '<select name="item_ring">';
 142      $ring_list .= '<option value = "0" >' . $lang['Adr_battle_no_ring'] . '</option>';
 143      $equip_armor = $char['equip_armor'];
 144      $equip_buckler = $char['equip_buckler'];
 145      $equip_helm = $char['equip_helm'];
 146      $equip_gloves = $char['equip_gloves'];
 147      $equip_amulet = $char['equip_amulet'];
 148      $equip_ring = $char['equip_ring'];
 149  
 150      for ( $i = 0 ; $i < count($items) ; $i ++ )
 151      {
 152          $item_power = $items[$i]['item_power'] + $items[$i]['item_add_power'];
 153  
 154          if ( $items[$i]['item_type_use'] == 7 )
 155          {
 156              $armor_selected = ( $equip_armor == $items[$i]['item_id'] ) ? 'selected' : '';
 157              $armor_list .= '<option value = "'.$items[$i]['item_id'].'" '.$armor_selected.' >' . adr_get_lang($items[$i]['item_name']) . ' ( ' . $lang['Adr_items_power'] . ' : ' . $item_power . ' - ' . $lang['Adr_items_duration'] . ' : ' . $items[$i]['item_duration'] . ' )'.'</option>';
 158          }
 159          if ( $items[$i]['item_type_use'] == 8 )
 160          {
 161              $buckler_selected = ( $equip_buckler == $items[$i]['item_id'] ) ? 'selected' : '';
 162              $buckler_list .= '<option value = "'.$items[$i]['item_id'].'" '.$buckler_selected.'>' . adr_get_lang($items[$i]['item_name']) . ' ( ' . $lang['Adr_items_power'] . ' : ' . $item_power . ' - ' . $lang['Adr_items_duration'] . ' : ' . $items[$i]['item_duration'] . ' )'.'</option>';
 163          }
 164          if ( $items[$i]['item_type_use'] == 9 )
 165          {
 166              $helm_selected = ( $equip_helm == $items[$i]['item_id'] ) ? 'selected' : '';
 167              $helm_list .= '<option value = "'.$items[$i]['item_id'].'" '.$helm_selected.'>' . adr_get_lang($items[$i]['item_name']) . ' ( ' . $lang['Adr_items_power'] . ' : ' . $item_power . ' - ' . $lang['Adr_items_duration'] . ' : ' . $items[$i]['item_duration'] . ' )'.'</option>';
 168          }
 169          if ( $items[$i]['item_type_use'] == 10 )
 170          {
 171              $gloves_selected = ( $equip_gloves == $items[$i]['item_id'] ) ? 'selected' : '';
 172              $gloves_list .= '<option value = "'.$items[$i]['item_id'].'" '.$gloves_selected.'>' . adr_get_lang($items[$i]['item_name']) . ' ( ' . $lang['Adr_items_power'] . ' : ' . $item_power . ' - ' . $lang['Adr_items_duration'] . ' : ' . $items[$i]['item_duration'] . ' )'.'</option>';
 173          }
 174          if ( $items[$i]['item_type_use'] == 13 )
 175          {
 176              $amulet_selected = ( $equip_amulet == $items[$i]['item_id'] ) ? 'selected' : '';
 177              $amulet_list .= '<option value = "'.$items[$i]['item_id'].'" '.$amulet_selected.'>' . adr_get_lang($items[$i]['item_name']) . ' ( ' . $lang['Adr_items_power'] . ' : ' . $item_power . ' - ' . $lang['Adr_items_duration'] . ' : ' . $items[$i]['item_duration'] . ' )'.'</option>';
 178          }
 179          if ( $items[$i]['item_type_use'] == 14 )
 180          {
 181              $ring_selected = ( $equip_ring == $items[$i]['item_id'] ) ? 'selected' : '';
 182              $ring_list .= '<option value = "'.$items[$i]['item_id'].'" '.$ring_selected.'>' . adr_get_lang($items[$i]['item_name']) . ' ( ' . $lang['Adr_items_power'] . ' : ' . $item_power . ' - ' . $lang['Adr_items_duration'] . ' : ' . $items[$i]['item_duration'] . ' )'.'</option>';
 183          }
 184      }
 185  
 186      $armor_list .= '</select>';
 187      $buckler_list .= '</select>';
 188      $helm_list .= '</select>';
 189      $gloves_list .= '</select>';
 190      $amulet_list .= '</select>';
 191      $ring_list .= '</select>';
 192  
 193      $template->assign_vars(array(
 194          'SELECT_ARMOR'  => $armor_list,
 195          'SELECT_BUCKLER' => $buckler_list,
 196          'SELECT_HELM' => $helm_list,
 197          'SELECT_GLOVES' => $gloves_list,
 198          'SELECT_AMULET' => $amulet_list,
 199          'SELECT_RING' => $ring_list, 
 200          'L_EQUIPMENT' => $lang['Adr_battle_equipment'],
 201          'L_SELECT_ARMOR'  => $lang['Adr_battle_select_armor'],
 202          'L_SELECT_BUCKLER' => $lang['Adr_battle_select_buckler'],
 203          'L_SELECT_HELM' => $lang['Adr_battle_select_helm'],
 204          'L_SELECT_GLOVES' => $lang['Adr_battle_select_gloves'],
 205          'L_SELECT_AMULET' => $lang['Adr_battle_select_amulet'],
 206          'L_SELECT_RING' => $lang['Adr_battle_select_ring'],
 207          'L_FIGHT' => $lang['Adr_battle_fight'],
 208      ));
 209  
 210  }
 211  
 212  else if ( !(is_numeric($bat['battle_id'])) && $equip )
 213  {
 214      // Check quota

 215      if($adr_general['Adr_character_limit_enable'] == '1') adr_battle_quota_check($user_id);
 216  
 217      // Let's calculate all the statistics now

 218  
 219      // Fix the items ids

 220      $armor = intval($HTTP_POST_VARS['item_armor']);
 221      $buckler = intval($HTTP_POST_VARS['item_buckler']);
 222      $helm = intval($HTTP_POST_VARS['item_helm']);
 223      $gloves = intval($HTTP_POST_VARS['item_gloves']);
 224      $amulet = intval($HTTP_POST_VARS['item_amulet']);
 225      $ring = intval($HTTP_POST_VARS['item_ring']);
 226  
 227      // Get the user infos

 228      $sql = " SELECT * FROM  " . ADR_CHARACTERS_TABLE . " 
 229          WHERE character_id = $user_id ";
 230      if( !($result = $db->sql_query($sql)) )
 231      {
 232          message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql);
 233      }
 234      $char = $db->sql_fetchrow($result);
 235  
 236      // Be sure he has a character 

 237      if ( !(is_numeric($char['character_id'])))
 238      {
 239          adr_previous( Adr_your_character_lack , adr_character , '' );
 240      }
 241  
 242      // Calculate the base stats

 243      $hp = 0;
 244      $mp = 0;
 245      $level = $char['character_level'];
 246      $char_element = $char['character_element'];
 247      $char_mp = $char['character_mp'];
 248      $ma = $char['character_magic_attack'];
 249      $md = $char['character_magic_resistance'];
 250      $int = $char['character_intelligence'];
 251  
 252      // At first make the attack power . This is the sum of might and constitution * 2

 253      $att = ( $char['character_might'] + $char['character_constitution'] ) * 2 ;
 254  
 255      // Then make the defense power . This is the sum of dexterity , armor class and willpower , plus the items power

 256      $def = $char['character_dexterity'] + $char['character_wisdom'] + $char['character_ac'];
 257      // Modify stats depending to zone element

 258      $zone_user = adr_get_user_infos($user_id);
 259      $actual_zone = $zone_user['character_area'];
 260      $sql = "SELECT * FROM " . ADR_ZONES_TABLE ."
 261          WHERE zone_id = $actual_zone";
 262      $result = $db->sql_query($sql);
 263      if( !$result ) 
 264          message_die(GENERAL_ERROR, 'Could not obtain zones information', "", __LINE__, __FILE__, $sql);
 265  
 266      $zone_check = $db->sql_fetchrow($result);
 267  
 268      if ( ( $board_config['zone_bonus_enable'] == '1' ) && ( $zone_check['zone_element'] == '$char_element') )
 269      {
 270          $bonus_att = $board_config['zone_bonus_att'];
 271          $bonus_def = $board_config['zone_bonus_def'];
 272          $att = ( ( ( $char['character_might'] + $char['character_constitution'] ) * 2 ) + $bonus_att );
 273          $def = ( ( $char['character_dexterity'] + $char['character_wisdom'] + $char['character_ac'] ) + $bonus_def );
 274      }
 275  
 276      if ( $armor )
 277      {
 278          $sql = " SELECT item_name , item_power , item_add_power FROM " . ADR_SHOPS_ITEMS_TABLE . "
 279              WHERE item_in_shop = 0 
 280              AND item_owner_id = $user_id 
 281              AND item_in_warehouse = 0
 282              AND item_id = $armor ";
 283          if( !($result = $db->sql_query($sql)) )
 284          {
 285              message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql);
 286          }
 287          $item = $db->sql_fetchrow($result);
 288  
 289          $def = ( $def + ($item['item_power'] ) + $item['item_add_power']);
 290          $armour_name = $item['item_name'];
 291          adr_use_item($armor , $user_id);
 292      }
 293  
 294      if ( $buckler )
 295      {
 296          $sql = " SELECT item_name , item_power , item_add_power FROM " . ADR_SHOPS_ITEMS_TABLE . "
 297              WHERE item_in_shop = 0 
 298              AND item_owner_id = $user_id
 299              AND item_in_warehouse = 0 
 300              AND item_id = $buckler ";
 301          if( !($result = $db->sql_query($sql)) )
 302          {
 303              message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql);
 304          }
 305          $item = $db->sql_fetchrow($result);
 306  
 307          $def = ( $def + ($item['item_power'] ) + $item['item_add_power']);
 308          $buckler_name = $item['item_name'];
 309          adr_use_item($buckler , $user_id);
 310      }
 311  
 312      if ( $gloves )
 313      {
 314          $sql = " SELECT item_name , item_power , item_add_power FROM " . ADR_SHOPS_ITEMS_TABLE . "
 315              WHERE item_in_shop = 0 
 316              AND item_owner_id = $user_id 
 317              AND item_in_warehouse = 0
 318              AND item_id = $gloves ";
 319          if( !($result = $db->sql_query($sql)) )
 320          {
 321              message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql);
 322          }
 323          $item = $db->sql_fetchrow($result);
 324  
 325          $def = ( $def + ($item['item_power'] ) + $item['item_add_power']);
 326          $gloves_name = $item['item_name'];
 327          adr_use_item($gloves , $user_id);
 328      }
 329  
 330      if ( $helm )
 331      {
 332          $sql = " SELECT item_name , item_power , item_add_power FROM " . ADR_SHOPS_ITEMS_TABLE . "
 333              WHERE item_in_shop = 0 
 334              AND item_owner_id = $user_id 
 335              AND item_in_warehouse = 0
 336              AND item_id = $helm ";
 337          if( !($result = $db->sql_query($sql)) )
 338          {
 339              message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql);
 340          }
 341          $item = $db->sql_fetchrow($result);
 342  
 343          $def = ( $def + $item['item_power'] ) + $item['item_add_power'];
 344          $helm_name = $item['item_name'];
 345          adr_use_item($helm , $user_id);
 346      }
 347  
 348      // Now we modify mp and hp regeneration with amulets and rings

 349      if ( $amulet )
 350      {
 351          $sql = " SELECT item_power FROM " . ADR_SHOPS_ITEMS_TABLE . "
 352              WHERE item_in_shop = 0 
 353              AND item_owner_id = $user_id 
 354              AND item_in_warehouse = 0
 355              AND item_id = $amulet ";
 356          if( !($result = $db->sql_query($sql)) )
 357          {
 358              message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql);
 359          }
 360          $item = $db->sql_fetchrow($result);
 361  
 362          $hp = $hp + $item['item_power'];
 363  
 364          adr_use_item($amulet , $user_id);
 365      }
 366  
 367      if ( $ring )
 368      {
 369          $sql = " SELECT item_power FROM " . ADR_SHOPS_ITEMS_TABLE . "
 370              WHERE item_in_shop = 0 
 371              AND item_owner_id = $user_id 
 372              AND item_in_warehouse = 0
 373              AND item_id = $ring ";
 374          if( !($result = $db->sql_query($sql)) )
 375          {
 376              message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql);
 377          }
 378          $item = $db->sql_fetchrow($result);
 379  
 380          $mp = $mp + $item['item_power'];
 381  
 382          adr_use_item($ring , $user_id);
 383      }
 384  
 385      // Let's care about the opponent now

 386      $actual_weather = $zone_user['character_weather'];
 387      $actual_season = $board_config['adr_seasons'];
 388      if ( $zone_check['zone_monsters_list'] == '' )
 389          adr_previous( Adr_zone_no_monsters , adr_zones , '' );
 390  
 391      $monster_area = ( $zone_check['zone_monsters_list'] == '0' ) ? "" : "AND monster_id IN (".$zone_check['zone_monsters_list'].")";
 392      $sql = " SELECT * FROM " . ADR_BATTLE_MONSTERS_TABLE . "
 393              WHERE monster_level <= $level 
 394              $monster_area
 395              AND ( monster_weather = $actual_weather || monster_weather = 0 )
 396              AND ( monster_season = $actual_season || monster_season = 0 )";
 397      if( !($result = $db->sql_query($sql)) )
 398      {
 399          message_die(GENERAL_ERROR, 'Could not query monsters list', '', __LINE__, __FILE__, $sql);
 400      }
 401      $monsters = $db->sql_fetchrowset($result);
 402      $monsters_count = count($monsters);
 403  
 404      // Be sure monsters of the user level exists

 405      if ( !($monsters_count))
 406      {
 407          adr_previous( Adr_no_monsters , adr_character , '' );
 408      }
 409  
 410      // Let the hazard select the monster

 411      $haz = rand ( 0 , ( $monsters_count - 1 ));
 412      
 413      // Get this monster base stats

 414      $monster_id = $monsters[$haz]['monster_id'];
 415      $monster_level = $monsters[$haz]['monster_level'];
 416      $monster_base_hp = $monsters[$haz]['monster_base_hp'];
 417      $monster_base_att = $monsters[$haz]['monster_base_att'];
 418      $monster_base_def = $monsters[$haz]['monster_base_def'];
 419      $monster_base_element = $monsters[$haz]['monster_base_element'];
 420      $monster_base_mp = $monsters[$haz]['monster_base_mp'];
 421      $monster_base_mp_power = $monsters[$haz]['monster_base_mp_power'];
 422      $monster_base_ma = $monsters[$haz]['monster_base_magic_attack'];
 423      $monster_base_md = $monsters[$haz]['mon