/** * @method POST * @api create */ public function create() { $character_id = doubleval($_POST['character_id']); //$armor = intval($_POST['armor']); //$buckler = intval($_POST['buckler']); //$helm = intval($_POST['helm']); //$gloves = intval($_POST['gloves']); //$amulet = intval($_POST['amulet']); //$ring = intval($_POST['ring']); $characters = new Character(); $char = $characters->getCharacterByID($character_id); // Calculate the base stats $hp = 0; $mp = 0; $level = $char['character_level']; $char_element = $char['character_element']; $char_mp = $char['character_mp']; // Create base attack & defence stats $att = adr_battle_make_att($char['character_might'], $char['character_constitution']); $ma = adr_battle_make_magic_att($char['character_intelligence']); $def = adr_battle_make_def($char['character_ac'], $char['character_dexterity']); $md = adr_battle_make_magic_def($char['character_wisdom']); $monsters = new Monsters(); $monsters = $monsters->getMonstersByLevel($char['character_level'], 1); $monsters = $monsters[0]; // Be sure monsters of the user level exists if (!$monsters) { return $this->response(array('status' => 0, 'message' => ADR::Lang('Adr_no_monsters'))); } // Get this monster base stats $monster_id = $monsters['monster_id']; $monster_level = $monsters['monster_level']; $monster_base_hp = $monsters['monster_base_hp']; $monster_base_att = $monsters['monster_base_att']; $monster_base_def = $monsters['monster_base_def']; $monster_base_element = $monsters['monster_base_element']; $monster_base_mp = $monsters['monster_base_mp']; $monster_base_mp_power = $monsters['monster_base_mp_power']; $monster_base_ma = $monsters['monster_base_magic_attack']; $monster_base_md = $monsters['monster_base_magic_resistance']; $monster_base_sp = $monsters['monster_base_sp']; ##=== END: new monster selection code by Sederien ===## // If the user is higher level than the monster , update the monster stats if ($monster_level < $level) { if ($adr_general['battle_calc_type']) { // Xanathis's alternative battle modifier calculation for monster battles $modifier = ($adr_general['battle_monster_stats_modifier'] - 100) / 100 * ($level - $monster_level) + 1; } else { $modifier = $adr_general['battle_monster_stats_modifier'] / 100 * ($level - $monster_level); } $monster_base_hp = ceil($monster_base_hp * $modifier); $monster_base_att = ceil($monster_base_att * $modifier); $monster_base_def = ceil($monster_base_def * $modifier); $monster_base_mp = ceil($monster_base_mp * $modifier); $monster_base_ma = ceil($monster_base_ma * $modifier); $monster_base_md = ceil($monster_base_md * $modifier); $monster_base_sp = ceil($monster_base_sp * $modifier); } ##=== START array for equipment id's ## //$equip_array = intval($helm_id).'-'.intval($armor_id).'-'.intval($gloves_id).'-'.intval($buckler_id).'-'.intval($amulet_id).'-'.intval($ring_id).'-'.intval($hp).'-'.intval($mp); // NEED ITEMS $equip_array = '[0,0,0,0,0,0,0,0]'; ##=== END array for equipment id's ## ##=== START: Initiative Checks // 1d20 roll. Highest starts. $monster_dex = 10 + rand(1, $monster_level) * 2; //temp $challenger_init_check = 0; //NEED SKILLS (rand(1,20) + adr_modifier_calc($char['character_dexterity'])); $monster_init_check = 0; //NEED SKILLS (rand(1,20) + adr_modifier_calc($monster_dex)); // Check who will start ELSE do a rand to determine. if ($challenger_init_check >= $monster_init_check) { $turn = 1; } else { $turn = 2; } ##=== END: Initiative Checks $db = DB::instance(); $battle = $db->insert('adr_battle_list', array('battle_type' => 1, 'battle_start' => ".time().", 'battle_turn' => $turn, 'battle_result' => 0, 'battle_text' => '', 'battle_challenger_id' => $character_id, 'battle_challenger_hp' => $hp, 'battle_challenger_mp' => $mp, 'battle_challenger_att' => $att, 'battle_challenger_def' => $def, 'battle_challenger_element' => $char_element, 'battle_challenger_magic_attack' => $ma, 'battle_challenger_magic_resistance' => $md, 'battle_challenger_equipment_info' => $equip_array, 'battle_opponent_id' => $monster_id, 'battle_opponent_hp' => $monster_base_hp, 'battle_opponent_hp_max' => $monster_base_hp, 'battle_opponent_mp' => $monster_base_mp, 'battle_opponent_mp_max' => $monster_base_mp, 'battle_opponent_mp_power' => $monster_base_mp_power, 'battle_opponent_att' => $monster_base_att, 'battle_opponent_def' => $monster_base_def, 'battle_opponent_element' => $monster_base_element, 'battle_opponent_magic_attack' => $monster_base_ma, 'battle_opponent_magic_resistance' => $monster_base_md, 'battle_opponent_sp' => $monster_base_sp)); if ($battle == false) { throw new Exception($db->getErrorMessage()); } return $this->response(array('status' => 1, 'opponent' => $monsters, 'turn' => $turn)); }
##=== END opponent checks ===## $sql = " SELECT battle_id FROM " . ADR_BATTLE_PVP_TABLE . "\r\t\t\t\tORDER BY battle_id DESC LIMIT 1 "; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not obtain user list', '', __LINE__, __FILE__, $sql); } $last_row = $db->sql_fetchrow($result); $last_id = $last_row['battle_id'] + 1; // Fix the items ids $armor = intval($HTTP_POST_VARS['item_armor']); $buckler = intval($HTTP_POST_VARS['item_buckler']); $helm = intval($HTTP_POST_VARS['item_helm']); $greave = intval($HTTP_POST_VARS['item_greave']); $boot = intval($HTTP_POST_VARS['item_boot']); $gloves = intval($HTTP_POST_VARS['item_gloves']); $amulet = intval($HTTP_POST_VARS['item_amulet']); $ring = intval($HTTP_POST_VARS['item_ring']); // Get the user infos $char = adr_get_user_infos($user_id); // Calculate the base stats $hp = $char['character_hp']; $mp = $char['character_mp']; $hp_max = $char['character_hp_max']; $mp_max = $char['character_mp_max']; $hp_regen = 0; $mp_regen = 0; $elemental = $char['character_element']; // Firstly, create the users' phyisial attack and magic attack stats $att = adr_battle_make_att($char['character_might'], $char['character_dexterity']); $ma = adr_battle_make_magic_att($char['character_intelligence']); $def = adr_battle_make_def($char['character_ac'], $char['character_dexterity']); $md = adr_battle_make_magic_def($char['character_wisdom']);
function adr_display_poster_infos($poster_id, $character_info, $race_info, $element_info, $class_info, $alignment_info, $pvp_info, $adr_con_info, $user_cell_time) { global $db, $phpbb_root_path, $lang, $board_config, $phpEx, $table_prefix, $userdata; if (!defined('IN_ADR_CHARACTER')) { define('IN_ADR_CHARACTER', 1); } if (!defined('IN_ADR_BATTLE')) { define('IN_ADR_BATTLE', 1); } include_once $phpbb_root_path . 'adr/includes/adr_constants.' . $phpEx; include_once $phpbb_root_path . 'adr/includes/adr_global.' . $phpEx; include_once $phpbb_root_path . 'adr/includes/adr_functions_battle.' . $phpEx; $adr_general = $adr_con_info; $topic_config = explode('-', $board_config['Adr_topics_display']); $adr_topic_box = ''; $character_rank_info = character_rank_info(); $total_ranks = number_format(count($character_rank_info)); if (!$topic_config[0] && !$topic_config[1] && !$topic_config[2] && !$topic_config[3] && !$topic_config[4] && !$topic_config[5]) { return $adr_topic_box; } for ($adr = 0; $adr < count($character_info); $adr++) { $adr_topic_box = ''; if ($character_info[$adr]['character_id'] == $poster_id && $character_info[$adr]['character_class'] > '0') { for ($x = 0; $x < count($character_rank_info); $x++) { if ($character_rank_info[$x]['character_id'] == $poster_id) { $rank = sprintf($lang['adr_stats_rank'], $x + 1, $total_ranks); } } $adr_topic_box .= '<fieldset class="fieldset" style="margin: 0px 0px 0px 0px;">'; $adr_topic_box .= '<legend>' . $lang['Adr_character'] . '</legend>'; #==== Show INACTIVE or JAILED status, if necessary // if($character_info[$adr]['character_prefs_active'] == '0'){ // $adr_topic_box .= ($poster_id == $userdata['user_id']) ? sprintf($lang['Adr_character_inactive_topic'], '<a href="'. append_sid('adr_character_prefs.'. $phpEx .').'">', '</a>').'<br><br>' : sprintf($lang['Adr_character_inactive_topic'], '<b>', '</b>').'<br><br>'; // } // elseif(($character_info[$adr]['character_prefs_active'] != '0') && ($user_cell_time > '0')){ if ($user_cell_time > '0') { $adr_topic_box .= $poster_id != $userdata['user_id'] ? sprintf($lang['Adr_character_status_jail_topic'], '<a target="_blank" href="' . append_sid('adr_courthouse.' . $phpEx . '?celled_user_id=' . $poster_id) . '">', '</a>') . '<br><br>' : sprintf($lang['Adr_character_status_jail_topic'], '<b>', '</b>') . '<br><br>'; } #==== Show character_name if (!empty($topic_config[5])) { $adr_topic_box .= ' <a href="' . append_sid('adr_character.' . $phpEx . '?u=' . $character_info[$adr]['character_id']) . '">' . $character_info[$adr]['character_name'] . '</a><br>'; } #==== Show current rank if (!empty($topic_config[7])) { $adr_topic_box .= ' ' . $rank . '<br>'; } ##=== Show character level if (!empty($topic_config[0])) { $adr_topic_box .= ' ' . $lang['Adr_topics_level'] . ': ' . $character_info[$adr]['character_level'] . '<br />'; } #==== Show PvP link where applicable // if(($topic_config[6]) && ($character_info[$adr]['prefs_pvp_allow'] == '1') && ($character_info[$adr]['character_prefs_active'] == '1') && ($character_info[$adr]['character_id'] != '0') && ($userdata['user_id'] > '0')) if (!empty($topic_config[6]) && $character_info[$adr]['prefs_pvp_allow'] == '1' && $character_info[$adr]['character_id'] != '0' && $userdata['user_id'] > '0') { #==== Check if the user hasn't already exceeded his maximum number of defies allowed $total_battles = 0; for ($pvp = 0; $pvp < count($pvp_info); $pvp++) { if (($pvp_info[$pvp]['battle_opponent_id'] == $poster_id || $pvp_info[$pvp]['battle_challenger_id'] == $poster_id) && ($pvp_info[$pvp]['battle_result'] == '0' || $pvp_info[$pvp]['battle_result'] == '3')) { $total_battles = $total_battles + 1; if (!$pvp_info[$pvp]['battle_opponent_id']) { break; } } } if ($adr_general['battle_pvp_defies_max'] >= $total_battles && $adr_general['battle_pvp_defies_max'] && $poster_id != $userdata['user_id']) { for ($pvp = 0; $pvp < count($pvp_info); $pvp++) { if (($pvp_info[$pvp]['battle_challenger_id'] == $poster_id || $pvp_info[$pvp]['battle_challenger_id'] == $userdata['user_id']) && ($pvp_info[$pvp]['battle_opponent_id'] == $poster_id || $pvp_info[$pvp]['battle_opponent_id'] == $userdata['user_id']) && ($pvp_info[$pvp]['battle_result'] == '0' || $pvp_info[$pvp]['battle_result'] == '3')) { $this_battle_id = $pvp_info[$pvp]['battle_id']; $this_battle_turn = $pvp_info[$pvp]['battle_turn']; $this_battle_result = $pvp_info[$pvp]['battle_result']; break; } } #==== Close 2nd for array if ($this_battle_id) { #==== Check if is current chars turn if ($this_battle_turn == $userdata['user_id']) { $adr_topic_box .= ' ' . $lang['Adr_pvp_post_text'] . ': <a href="' . append_sid("adr_battle_pvp.{$phpEx}?battle_id=" . $this_battle_id) . '" target="_parent">' . $lang['Adr_pvp_post_your_turn'] . '</a><br />'; } elseif ($this_battle_turn == 0 && $this_battle_result == 0) { $opponent_turn = sprintf($lang['Adr_pvp_post_opponent_turn'], $character_info[$adr]['character_name']); $adr_topic_box .= ' ' . $lang['Adr_pvp_post_text'] . ': <a href="' . append_sid("adr_character_pvp.{$phpEx}?mode=waiting") . '" target="_parent"><i>' . $lang['Adr_pvp_opponent_awaiting'] . '</i></a><br />'; } else { $opponent_turn = sprintf($lang['Adr_pvp_post_opponent_turn'], $character_info[$adr]['character_name']); $adr_topic_box .= ' ' . $lang['Adr_pvp_post_text'] . ': <a href="' . append_sid("adr_battle_pvp.{$phpEx}?mode=see&battle_id=" . $this_battle_id) . '" target="_parent">' . $opponent_turn . '</a><br />'; } } else { $total_battles = 0; for ($pvp = 0; $pvp < count($pvp_info); $pvp++) { if (($pvp_info[$pvp]['battle_opponent_id'] == $userdata['user_id'] || $pvp_info[$pvp]['battle_challenger_id'] == $userdata['user_id']) && ($pvp_info[$pvp]['battle_result'] == '0' || $pvp_info[$pvp]['battle_result'] == '3')) { $total_battles = $total_battles + 1; if (!$pvp_info[$pvp]['battle_opponent_id']) { break; } } } $total = $total_battles; if ($adr_general['battle_pvp_defies_max'] >= $total && $adr_general['battle_pvp_defies_max'] && $poster_id != $userdata['user_id']) { $adr_topic_box .= ' ' . $lang['Adr_pvp_post_text'] . ': <a href="' . append_sid("adr_character_pvp.{$phpEx}?mode=defy_action&defied=" . $poster_id) . '" target="_parent">' . $lang['Adr_pvp_post_attack'] . '</a><br />'; } } } #==== Close 2nd if statement } #==== End of pvp check if (!empty($topic_config[8])) { $adr_topic_box .= '<br>' . $lang['Adr_character_battle_stats_title'] . ':<br>'; $adr_topic_box .= ' ' . $lang['Adr_monster_list_hp'] . ': ' . $character_info[$adr]['character_hp'] . '/' . $character_info[$adr]['character_hp_max'] . '<br>'; $adr_topic_box .= ' ' . $lang['Adr_monster_list_mp'] . ': ' . $character_info[$adr]['character_mp'] . '/' . $character_info[$adr]['character_mp_max'] . '<br>'; $adr_topic_box .= ' ' . $lang['Adr_monster_list_att'] . ': ' . adr_battle_make_att($character_info[$adr]['character_might'], $character_info[$adr]['character_dexterity']) . '<br>'; $adr_topic_box .= ' ' . $lang['Adr_monster_list_def'] . ': ' . adr_battle_make_def($character_info[$adr]['character_ac'], $character_info[$adr]['character_dexterity']) . '<br>'; $adr_topic_box .= ' ' . $lang['Adr_monster_list_ma'] . ': ' . adr_battle_make_magic_att($character_info[$adr]['character_intelligence']) . '<br>'; $adr_topic_box .= ' ' . $lang['Adr_monster_list_md'] . ': ' . adr_battle_make_magic_def($character_info[$adr]['character_wisdom']) . '<br>'; } if ($topic_config[1] || $topic_config[2] || $topic_config[3] || $topic_config[4]) { $adr_topic_box .= '<br>' . $lang['Adr_character_characteristics'] . ':<br>'; } if ($topic_config[1]) { $adr_topic_box .= ' ' . $lang['Adr_topics_class'] . ': '; for ($class = 0; $class < count($class_info); $class++) { if ($character_info[$adr]['character_class'] == $class_info[$class]['class_id']) { $class_lang = adr_get_lang($class_info[$class]['class_name']); $class_img = $class_info[$class]['class_img']; break; } } if ($topic_config[1] == '1') { $adr_topic_box .= $class_lang; } else { $adr_topic_box .= '<img src="adr/images/classes/' . $class_img . '">'; } $adr_topic_box .= '<br />'; } #==== Close topic_config[1] if statement if ($topic_config[2]) { $adr_topic_box .= ' ' . $lang['Adr_topics_race'] . ': '; for ($race = 0; $race < count($race_info); $race++) { if ($character_info[$adr]['character_race'] == $race_info[$race]['race_id']) { $race_lang = adr_get_lang($race_info[$race]['race_name']); $race_img = $race_info[$race]['race_img']; break; } } if ($topic_config[2] == '1') { $adr_topic_box .= $race_lang; } else { $adr_topic_box .= '<img src="adr/images/races/' . $race_img . '">'; } $adr_topic_box .= '<br />'; } #==== Close topic_config[2] if statement if ($topic_config[3]) { $adr_topic_box .= ' ' . $lang['Adr_topics_element'] . ': '; for ($elements = 0; $elements < count($element_info); $elements++) { if ($character_info[$adr]['character_element'] == $element_info[$elements]['element_id']) { $element_lang = adr_get_lang($element_info[$elements]['element_name']); $element_img = $element_info[$elements]['element_img']; break; } } if ($topic_config[3] == '1') { $adr_topic_box .= $element_lang; } else { $adr_topic_box .= '<img src="adr/images/elements/' . $element_img . '">'; } $adr_topic_box .= '<br />'; } #==== Close topic_config[3] if statement if ($topic_config[4]) { $adr_topic_box .= ' ' . $lang['Adr_topics_alignment'] . ': '; for ($alignment = 0; $alignment < count($alignment_info); $alignment++) { if ($character_info[$adr]['character_alignment'] == $alignment_info[$alignment]['alignment_id']) { $alignment_lang = adr_get_lang($alignment_info[$alignment]['alignment_name']); $alignment_img = $alignment_info[$alignment]['alignment_img']; break; } } if ($topic_config[4] == '1') { $adr_topic_box .= $alignment_lang; } else { $adr_topic_box .= '<img src="adr/images/alignments/' . $alignment_img . '">'; } $adr_topic_box .= '<br />'; } #==== Close topic_config[4] if statement $adr_topic_box .= '</fieldset>'; break; } #==== End if statement for matching id } #==== End for array return $adr_topic_box; }
function adr_battle_equip_initialise($user_id, $armor, $buckler, $helm, $gloves, $amulet, $ring) { global $db, $lang, $adr_general, $template, $board_config; $user_id = intval($user_id); $armor = intval($armor); $buckler = intval($buckler); $helm = intval($helm); $gloves = intval($gloves); $amulet = intval($amulet); $ring = intval($ring); // Get the user infos $char = adr_get_user_infos($user_id); ### START restriction checks ### $item_sql = adr_make_restrict_sql($char); ### END restriction checks ### // Be sure he has a character if (!is_numeric($char['character_id'])) { adr_previous(Adr_your_character_lack, adr_character, ''); } // Calculate the base stats $hp = 0; $mp = 0; $level = $char['character_level']; $char_element = $char['character_element']; $char_mp = $char['character_mp']; // Create base attack & defence stats $att = adr_battle_make_att($char['character_might'], $char['character_constitution']); $ma = adr_battle_make_magic_att($char['character_intelligence']); $def = adr_battle_make_def($char['character_ac'], $char['character_dexterity']); $md = adr_battle_make_magic_def($char['character_wisdom']); if ($armor) { $sql = "SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . "\n\t\t\tWHERE item_in_shop = '0'\n\t\t\tAND item_owner_id = '{$user_id}'\n\t\t\tAND item_in_warehouse = '0'\n\t\t\t{$item_sql}\n\t\t\tAND item_id = '{$armor}'"; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); } $item = $db->sql_fetchrow($result); $armor_id = $item['item_id']; $def = $def + ($item['item_power'] + $item['item_add_power']); adr_use_item($armor, $user_id); } if ($buckler) { $sql = "SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . "\n\t\t\tWHERE item_in_shop = '0'\n\t\t\tAND item_owner_id = '{$user_id}'\n\t\t\tAND item_in_warehouse = '0'\n\t\t\t{$item_sql}\n\t\t\tAND item_id = '{$buckler}'"; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); } $item = $db->sql_fetchrow($result); $buckler_id = $item['item_id']; $def = $def + ($item['item_power'] + $item['item_add_power']); adr_use_item($buckler, $user_id); } if ($gloves) { $sql = "SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . "\n\t\t\tWHERE item_in_shop = '0'\n\t\t\tAND item_owner_id = '{$user_id}'\n\t\t\tAND item_in_warehouse = '0'\n\t\t\t{$item_sql}\n\t\t\tAND item_id = '{$gloves}'"; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); } $item = $db->sql_fetchrow($result); $gloves_id = $item['item_id']; $def = $def + ($item['item_power'] + $item['item_add_power']); adr_use_item($gloves, $user_id); } if ($helm) { $sql = "SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . "\n\t\t\tWHERE item_in_shop = '0'\n\t\t\tAND item_owner_id = '{$user_id}'\n\t\t\tAND item_in_warehouse = '0'\n\t\t\t{$item_sql}\n\t\t\tAND item_id = '{$helm}'"; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); } $item = $db->sql_fetchrow($result); $helm_id = $item['item_id']; $def = $def + ($item['item_power'] + $item['item_add_power']); adr_use_item($helm, $user_id); } // Now we modify mp and hp regeneration with amulets and rings if ($amulet) { $sql = " SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . "\n\t\t\tWHERE item_in_shop = '0'\n\t\t\tAND item_owner_id = '{$user_id}'\n\t\t\tAND item_in_warehouse = '0'\n\t\t\t{$item_sql}\n\t\t\tAND item_id = '{$amulet}'"; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); } $item = $db->sql_fetchrow($result); $amulet_id = $item['item_id']; $hp = $hp + $item['item_power']; adr_use_item($amulet, $user_id); } if ($ring) { $sql = "SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . "\n\t\t\tWHERE item_in_shop = '0'\n\t\t\tAND item_owner_id = '{$user_id}'\n\t\t\tAND item_in_warehouse = '0'\n\t\t\t{$item_sql}\n\t\t\tAND item_id = '{$ring}'"; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); } $item = $db->sql_fetchrow($result); $ring_id = $item['item_id']; $mp = $mp + $item['item_power']; adr_use_item($ring, $user_id); } ##=== START: new monster rand selection code as posted by Sederien ===## // Let's care about the opponent now $sql = " SELECT * FROM " . ADR_BATTLE_MONSTERS_TABLE . "\n\t\tWHERE monster_level <= '{$level}'\n\t\tORDER BY RAND() LIMIT 1"; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query monsters list', '', __LINE__, __FILE__, $sql); } $monsters = $db->sql_fetchrow($result); // Be sure monsters of the user level exists if (!$monsters) { adr_previous(Adr_no_monsters, adr_character, ''); } // Get this monster base stats $monster_id = $monsters['monster_id']; $monster_level = $monsters['monster_level']; $monster_base_hp = $monsters['monster_base_hp']; $monster_base_att = $monsters['monster_base_att']; $monster_base_def = $monsters['monster_base_def']; $monster_base_element = $monsters['monster_base_element']; $monster_base_mp = $monsters['monster_base_mp']; $monster_base_mp_power = $monsters['monster_base_mp_power']; $monster_base_ma = $monsters['monster_base_magic_attack']; $monster_base_md = $monsters['monster_base_magic_resistance']; $monster_base_sp = $monsters['monster_base_sp']; ##=== END: new monster selection code by Sederien ===## // If the user is higher level than the monster , update the monster stats if ($monster_level < $level) { if ($adr_general['battle_calc_type']) { // Xanathis's alternative battle modifier calculation for monster battles $modifier = ($adr_general['battle_monster_stats_modifier'] - 100) / 100 * ($level - $monster_level) + 1; } else { $modifier = $adr_general['battle_monster_stats_modifier'] / 100 * ($level - $monster_level); } $monster_base_hp = ceil($monster_base_hp * $modifier); $monster_base_att = ceil($monster_base_att * $modifier); $monster_base_def = ceil($monster_base_def * $modifier); $monster_base_mp = ceil($monster_base_mp * $modifier); $monster_base_ma = ceil($monster_base_ma * $modifier); $monster_base_md = ceil($monster_base_md * $modifier); $monster_base_sp = ceil($monster_base_sp * $modifier); } ##=== START array for equipment id's ## $equip_array = intval($helm_id) . '-' . intval($armor_id) . '-' . intval($gloves_id) . '-' . intval($buckler_id) . '-' . intval($amulet_id) . '-' . intval($ring_id) . '-' . intval($hp) . '-' . intval($mp); ##=== END array for equipment id's ## ##=== START: Initiative Checks // 1d20 roll. Highest starts. $monster_dex = 10 + rand(1, $monster_level) * 2; //temp $challenger_init_check = rand(1, 20) + adr_modifier_calc($char['character_dexterity']); $monster_init_check = rand(1, 20) + adr_modifier_calc($monster_dex); // Check who will start ELSE do a rand to determine. if ($challenger_init_check >= $monster_init_check) { $turn = 1; } else { $turn = 2; } ##=== END: Initiative Checks // Finally insert all theses values into the database $sql = "INSERT INTO " . ADR_BATTLE_LIST_TABLE . "\n\t\t(battle_type, battle_start, battle_turn, battle_result, battle_text, battle_challenger_id, battle_challenger_hp, battle_challenger_mp, battle_challenger_att, battle_challenger_def, battle_challenger_element, battle_challenger_magic_attack, battle_challenger_magic_resistance, battle_challenger_equipment_info, battle_opponent_id, battle_opponent_hp, battle_opponent_hp_max, battle_opponent_mp, battle_opponent_mp_max, battle_opponent_mp_power, battle_opponent_att, battle_opponent_def, battle_opponent_element, battle_opponent_magic_attack, battle_opponent_magic_resistance, battle_opponent_sp)\n\t\tVALUES(1, " . time() . ", {$turn}, 0, '', {$user_id}, {$hp}, {$mp}, {$att}, {$def}, {$char_element}, {$ma}, {$md}, '{$equip_array}', {$monster_id}, {$monster_base_hp}, {$monster_base_hp}, {$monster_base_mp}, {$monster_base_mp}, {$monster_base_mp_power}, {$monster_base_att}, {$monster_base_def}, {$monster_base_element}, {$monster_base_ma}, {$monster_base_md}, {$monster_base_sp})"; $result = $db->sql_query($sql); if (!$result) { message_die(GENERAL_ERROR, "Couldn't insert new battle", "", __LINE__, __FILE__, $sql); } return; }
function adr_battle_equip_initialise($user_id, $armor, $buckler, $helm, $gloves, $amulet, $ring, $greave, $boot) { global $db, $lang, $adr_general, $template, $board_config, $phpEx; $user_id = intval($user_id); $armor = intval($armor); $buckler = intval($buckler); $helm = intval($helm); $gloves = intval($gloves); $amulet = intval($amulet); $ring = intval($ring); // Get the user infos $char = adr_get_user_infos($user_id); ### START restriction checks ### $item_sql = adr_make_restrict_sql($char); ### END restriction checks ### // Be sure he has a character if (!is_numeric($char['character_id'])) { adr_previous(Adr_your_character_lack, adr_character, ''); } // Calculate the base stats $hp = 0; $mp = 0; $level = $char['character_level']; $char_element = $char['character_element']; $char_mp = $char['character_mp']; // Create base attack & defence stats $att = adr_battle_make_att($char['character_might'], $char['character_constitution']); $ma = adr_battle_make_magic_att($char['character_intelligence']); $def = adr_battle_make_def($char['character_ac'], $char['character_dexterity']); $md = adr_battle_make_magic_def($char['character_wisdom']); // Modify stats depending to zone element $zone_user = adr_get_user_infos($user_id); $actual_zone = $zone_user['character_area']; $sql = "SELECT * FROM " . ADR_ZONES_TABLE . "\r\n\t\tWHERE zone_id = {$actual_zone}"; $result = $db->sql_query($sql); if (!$result) { message_die(GENERAL_ERROR, 'Could not obtain zones information', "", __LINE__, __FILE__, $sql); } $zone_check = $db->sql_fetchrow($result); if ($board_config['zone_bonus_enable'] == '1' && $zone_check['zone_element'] == '$char_element') { $bonus_att = $board_config['zone_bonus_att']; $bonus_def = $board_config['zone_bonus_def']; $att = ($char['character_might'] + $char['character_constitution']) * 2 + $bonus_att; $def = $char['character_dexterity'] + $char['character_wisdom'] + $char['character_ac'] + $bonus_def; } // Start party $party = $char['character_party']; if ($party > 0) { $sql = " SELECT character_party FROM " . ADR_CHARACTERS_TABLE . "\r\n\t\t\t WHERE character_party = {$party} "; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query count for info page', '', __LINE__, __FILE__, $sql); } $count_members = $db->sql_numrows($result); } elseif ($party = 0) { $sql = " SELECT character_party FROM " . ADR_CHARACTERS_TABLE . "\r\n\t\t\t WHERE character_party = 0 "; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query count for info page', '', __LINE__, __FILE__, $sql); } $count_members = $db->sql_numrows($result); } // Boost ATT $att = $att + $count_members + $count_members + $count_members; $att = round($att); // Boost DEF $def = $def + $count_members + $count_members + $count_members + $count_members + $count_members; $def = round($def); // Boost MA $ma = $ma + $count_members + $count_members + $count_members; $ma = round($ma); // Boost MD $md = $md + $count_members + $count_members + $count_members + $count_members + $count_members; $md = round($md); // End Party if ($armor) { $sql = "SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . "\r\n\t\t\tWHERE item_in_shop = '0'\r\n\t\t\tAND item_owner_id = '{$user_id}'\r\n\t\t\tAND item_in_warehouse = '0'\r\n\t\t\t{$item_sql}\r\n\t\t\tAND item_id = '{$armor}'"; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); } $item = $db->sql_fetchrow($result); $armor_id = $item['item_id']; $def = $def + ($item['item_power'] + $item['item_add_power']); adr_use_item($armor, $user_id); $armour_name = adr_get_lang($item['item_name']); } $def = $def + $adr_general['shield_bonus'] * $char['character_skill_shield_level']; if ($buckler) { $sql = "SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . "\r\n\t\t\tWHERE item_in_shop = '0'\r\n\t\t\tAND item_owner_id = '{$user_id}'\r\n\t\t\tAND item_in_warehouse = '0'\r\n\t\t\t{$item_sql}\r\n\t\t\tAND item_id = '{$buckler}'"; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); } $item = $db->sql_fetchrow($result); $buckler_id = $item['item_id']; $def = $def + ($item['item_power'] + $item['item_add_power']); adr_use_item($buckler, $user_id); $buckler_name = adr_get_lang($item['item_name']); } if ($gloves) { $sql = "SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . "\r\n\t\t\tWHERE item_in_shop = '0'\r\n\t\t\tAND item_owner_id = '{$user_id}'\r\n\t\t\tAND item_in_warehouse = '0'\r\n\t\t\t{$item_sql}\r\n\t\t\tAND item_id = '{$gloves}'"; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); } $item = $db->sql_fetchrow($result); $gloves_id = $item['item_id']; $def = $def + ($item['item_power'] + $item['item_add_power']); adr_use_item($gloves, $user_id); $gloves_name = adr_get_lang($item['item_name']); } if ($helm) { $sql = "SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . "\r\n\t\t\tWHERE item_in_shop = '0'\r\n\t\t\tAND item_owner_id = '{$user_id}'\r\n\t\t\tAND item_in_warehouse = '0'\r\n\t\t\t{$item_sql}\r\n\t\t\tAND item_id = '{$helm}'"; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); } $item = $db->sql_fetchrow($result); $helm_id = $item['item_id']; $def = $def + ($item['item_power'] + $item['item_add_power']); adr_use_item($helm, $user_id); $helm_name = adr_get_lang($item['item_name']); } // Now we modify mp and hp regeneration with amulets and rings if ($amulet) { $sql = " SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . "\r\n\t\t\tWHERE item_in_shop = '0'\r\n\t\t\tAND item_owner_id = '{$user_id}'\r\n\t\t\tAND item_in_warehouse = '0'\r\n\t\t\t{$item_sql}\r\n\t\t\tAND item_id = '{$amulet}'"; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); } $item = $db->sql_fetchrow($result); $amulet_id = $item['item_id']; $hp = $hp + $item['item_power']; adr_use_item($amulet, $user_id); $amulet_name = adr_get_lang($item['item_name']); } if ($ring) { $sql = "SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . "\r\n\t\t\tWHERE item_in_shop = '0'\r\n\t\t\tAND item_owner_id = '{$user_id}'\r\n\t\t\tAND item_in_warehouse = '0'\r\n\t\t\t{$item_sql}\r\n\t\t\tAND item_id = '{$ring}'"; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); } $item = $db->sql_fetchrow($result); $ring_id = $item['item_id']; $mp = $mp + $item['item_power']; adr_use_item($ring, $user_id); $ring_name = adr_get_lang($item['item_name']); } if ($greave) { $sql = " SELECT item_name , item_power , item_add_power FROM " . ADR_SHOPS_ITEMS_TABLE . "\r\n\t\t\tWHERE item_in_shop = 0 \r\n\t\t\tAND item_owner_id = {$user_id} \r\n\t\t\tAND item_in_warehouse = 0\r\n\t\t\tAND item_id = {$greave} "; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); } $item = $db->sql_fetchrow($result); $def = $def + $item['item_power'] + $item['item_add_power']; $greave_name = $item['item_name']; adr_use_item($greave, $user_id); $greave_name = adr_get_lang($item['item_name']); } if ($boot) { $sql = " SELECT item_name , item_power , item_add_power FROM " . ADR_SHOPS_ITEMS_TABLE . "\r\n\t\t\tWHERE item_in_shop = 0 \r\n\t\t\tAND item_owner_id = {$user_id} \r\n\t\t\tAND item_in_warehouse = 0\r\n\t\t\tAND item_id = {$boot} "; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); } $item = $db->sql_fetchrow($result); $def = $def + $item['item_power'] + $item['item_add_power']; $boot_name = $item['item_name']; adr_use_item($boot, $user_id); $boot_name = adr_get_lang($item['item_name']); } if ($zone_check['zone_monsters_list'] == '') { adr_previous(Adr_zone_no_monsters, adr_zones, ''); } $monster_area = $zone_check['zone_monsters_list'] == '0' ? "" : "AND monster_id IN (" . $zone_check['zone_monsters_list'] . ")"; ##=== START: new monster rand selection code as posted by Sederien ===## # V: JK. That's zone mod's code :). // Let's care about the opponent now $actual_weather = $zone_user['character_weather']; $actual_season = $board_config['adr_seasons']; $actual_time = $board_config['adr_time']; $sql = " SELECT * FROM " . ADR_BATTLE_MONSTERS_TABLE . "\r\n\t\t\tWHERE monster_level <= {$level} \r\n\t\t\t{$monster_area}\r\n\t\t\tAND ( monster_weather = {$actual_weather} || monster_weather = 0 )\r\n\t\t\tAND (monster_time = {$actual_time} OR monster_time = 0)\r\n\t\t\tAND ( monster_season = {$actual_season} || monster_season = 0 )"; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query monsters list', '', __LINE__, __FILE__, $sql); } $monsters = $db->sql_fetchrow($result); // Be sure monsters of the user level exists if (!$monsters) { adr_previous(Adr_no_monsters, adr_character, ''); } // Get this monster base stats $monster_id = $monsters['monster_id']; $monster_level = $monsters['monster_level']; $monster_base_hp = $monsters['monster_base_hp']; $monster_base_att = $monsters['monster_base_att']; $monster_base_def = $monsters['monster_base_def']; $monster_base_element = $monsters['monster_base_element']; $monster_base_mp = $monsters['monster_base_mp']; $monster_base_mp_power = $monsters['monster_base_mp_power']; $monster_base_ma = $monsters['monster_base_magic_attack']; $monster_base_md = $monsters['monster_base_magic_resistance']; $monster_base_sp = $monsters['monster_base_sp']; ##=== END: new monster selection code by Sederien ===## // If the user is higher level than the monster , update the monster stats if ($monster_level < $level) { if ($adr_general['battle_calc_type']) { // Xanathis's alternative battle modifier calculation for monster battles $modifier = ($adr_general['battle_monster_stats_modifier'] - 100) / 100 * ($level - $monster_level) + 1; } else { $modifier = $adr_general['battle_monster_stats_modifier'] / 100 * ($level - $monster_level); } $monster_base_hp = ceil($monster_base_hp * $modifier); $monster_base_att = ceil($monster_base_att * $modifier); $monster_base_def = ceil($monster_base_def * $modifier); $monster_base_mp = ceil($monster_base_mp * $modifier); $monster_base_ma = ceil($monster_base_ma * $modifier); $monster_base_md = ceil($monster_base_md * $modifier); $monster_base_sp = ceil($monster_base_sp * $modifier); } ##=== START array for equipment id's ## $equip_array = intval($helm_id) . '-' . intval($armor_id) . '-' . intval($gloves_id) . '-' . intval($buckler_id) . '-' . intval($amulet_id) . '-' . intval($ring_id) . '-' . intval($hp) . '-' . intval($mp) . '-' . intval($greave) . '-' . intval($boot); ##=== END array for equipment id's ## ##=== START: Initiative Checks // 1d20 roll. Highest starts. $monster_dex = 10 + rand(1, $monster_level) * 2; //temp $challenger_init_check = rand(1, 20) + adr_modifier_calc($char['character_dexterity']); $monster_init_check = rand(1, 20) + adr_modifier_calc($monster_dex); // Check who will start ELSE do a rand to determine. if ($challenger_init_check >= $monster_init_check) { $turn = 1; } else { $turn = 2; } ##=== END: Initiative Checks $spell_effects = explode(':', $char['character_spell_pre_effects']); for ($i = 0; $i < count($spell_effects); $i++) { if ($spell_effects[$i] == 'ATT') { $value = $spell_effects[$i + 1]; $att = $att + $value; } if ($spell_effects[$i] == 'DEF') { $value = $spell_effects[$i + 1]; $def = $def + $value; } } //remove spell pre-effects $sql = "UPDATE " . ADR_CHARACTERS_TABLE . "\r\n\t\tSET character_spell_pre_effects = ''\r\n\t\tWHERE character_id = {$user_id} "; if (!$db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Couldn\'t remove characters spell pre effects for battle', '', __LINE__, __FILE__, $sql); } // Finally insert all theses values into the database $sql = "INSERT INTO " . ADR_BATTLE_LIST_TABLE . "\r\n\t\t(battle_type, battle_start, battle_turn, battle_result, battle_text, battle_challenger_id, battle_challenger_hp, battle_challenger_mp, battle_challenger_att, battle_challenger_def, battle_challenger_element, battle_challenger_magic_attack, battle_challenger_magic_resistance, battle_challenger_equipment_info, battle_opponent_id, battle_opponent_hp, battle_opponent_hp_max, battle_opponent_mp, battle_opponent_mp_max, battle_opponent_mp_power, battle_opponent_att, battle_opponent_def, battle_opponent_element, battle_opponent_magic_attack, battle_opponent_magic_resistance, battle_opponent_sp)\r\n\t\tVALUES(1, " . time() . ", {$turn}, 0, '', {$user_id}, {$hp}, {$mp}, {$att}, {$def}, {$char_element}, {$ma}, {$md}, '{$equip_array}', {$monster_id}, {$monster_base_hp}, {$monster_base_hp}, {$monster_base_mp}, {$monster_base_mp}, {$monster_base_mp_power}, {$monster_base_att}, {$monster_base_def}, {$monster_base_element}, {$monster_base_ma}, {$monster_base_md}, {$monster_base_sp})"; $result = $db->sql_query($sql); if (!$result) { message_die(GENERAL_ERROR, "Couldn't insert new battle", "", __LINE__, __FILE__, $sql); } // Do armour set check // Do armour set check include_once $phpbb_root_path . 'adr/includes/adr_functions_armour_sets.' . $phpEx; adr_armour_set_check($user_id, $armour_name, $buckler_name, $gloves_name, $helm_name, $amulet_name, $ring_name, $greave_name, $boot_name); }