function event_trigger_get_item($zone) { global $area_id, $db, $lang, $user_id; //Select zone specific items $sql = " SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . " \n\t\tWHERE item_owner_id = '1'\n\t\tAND ( item_zone = '{$area_id}' || item_zone = '0' )\n\t\tORDER BY rand() LIMIT 1 "; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query battle list', '', __LINE__, __FILE__, $sql); } $new_item = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$new_item) { return; } adr_shop_insert_item($new_item['item_id'], adr_make_new_item_id($user_id), $user_id, 1); $item_name = $new_item['item_name']; $message = '<img src="adr/images/zones/get_item.gif"><br /><br />' . $lang['Adr_zone_event_item'] . '<br /><br /><b>' . $item_name . '</b><br /><br /><img src="adr/images/items/' . $item_icon . '"><br /><br />' . $item_desc . '<br /><br />' . $lang['Adr_zone_event_return'] . '<br /><br />'; message_die(GENERAL_ERROR, $message, 'Zones', ''); }
function drop_gather_loot($zone_id, $user_id, $type, $skill_number) { define('IN_ADR_ZONES', true); /****************************************************************************** * $zone_id = zone the chracter is in * $user_id = chracters id * $type = type of gathering being done, mine, fish, etc, corresponds to * the loottable field in phpbb_adr_zone table * $skill_number = number of skill given in phpbb_adr_skills ******************************************************************************/ global $db, $lang, $adr_general; $user_id = intval($user_id); $zone_id = intval($zone_id); $sql = "SELECT * FROM " . ADR_ZONES_TABLE . "\r\n\tWHERE zone_id = {$zone_id}\r\n\t"; $result = $db->sql_query($sql); if (!$result) { message_die(GENERAL_ERROR, 'Could not obtain zone information', "", __LINE__, __FILE__, $sql); } $zone = $db->sql_fetchrow($result); //build zone check from table $loot_to_find = 'zone_' . $type . '_table'; // V: return early if ($zone[$loot_to_find] == '' || $zone[$loot_to_find] == '0') { // return empty return null; } $zone_loottables = explode(':', $zone[$loot_to_find]); $sql = "SELECT * FROM " . ADR_SKILLS_TABLE . "\r\n\tWHERE skill_id = {$skill_number}"; $result = $db->sql_query($sql); if (!$result) { message_die(GENERAL_ERROR, 'Could not obtain skill information', "", __LINE__, __FILE__, $sql); } $skill_data = mysql_fetch_array($result); //build character check from table $skill_to_use = "character_skill_" . $type; //$difficulty = loottable drop chance? $user_chance = $adr_user[$skill_to_use] * $skill_data['skill_chance']; do { $timer++; //roll the loottable $rnd_loottable = rand(0, count($zone_loottables)); //sort out deactivated loottables $sql = "SELECT * FROM " . ADR_LOOTTABLES_TABLE . "\r\n\t\t\tWHERE loottable_status = 1\r\n\t\t\tAND loottable_id = '" . $zone_loottables[$rnd_loottable] . "'"; $result = $db->sql_query($sql); if (!$result) { message_die(GENERAL_ERROR, 'Could not obtain loottable information', "", __LINE__, __FILE__, $sql); } //incase all monsters loottables are deactivated for some reason if ($timer > 10) { break; } } while (!($rolled_loottable = $db->sql_fetchrow($result))); //incase all monsters loottables are deactivated for some reason //if ($timer > 10000){break;} //now roll to see if we actually get an item $max = $user_chance * 100; $dicer = rand(1, $max); $dicer = $dicer + $adr_user[$skill_to_use] * $skill_data['skill_chance']; if ($dicer >= $rolled_loottable['loottable_dropchance']) { $sql = "SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . "\r\n\t\tWHERE item_owner_id = 1\r\n\t\tAND (item_loottables like '" . $rolled_loottable['loottable_id'] . ":" . "%'\r\n\t\tOR item_loottables like '" . $rolled_loottable['loottable_id'] . "'\r\n\t\tOR item_loottables like '%" . ":" . $rolled_loottable['loottable_id'] . ":" . "%'\r\n\t\tOR item_loottables like '%" . ":" . $rolled_loottable['loottable_id'] . "')"; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query items list', '', __LINE__, __FILE__, $sql); } $possible_items_db = $db->sql_fetchrowset($result); //now roll for the item $rnd_item = rand(0, count($possible_items_db) - 1); //echo "<br> possible_items_db[rnd_item]['item_id']" . $possible_items_db[$rnd_item]['item_id']; $item_id = $possible_items_db[$rnd_item]['item_id']; // V: REFACTOOOR $item_data = adr_shop_insert_item($item_id, adr_make_new_item_id($user_id), $user_id, 1); $message .= "<br><br><table align=\"center\" border=\"0\" cellpadding=\"0\" class=\"gen\"><tr>"; $message .= "<tr><td align=\"center\" valign=\"top\"><span class=\"gen\">Vous avez obtenu : " . adr_get_lang($item_data['item_name']) . "<br><img src=\"./adr/images/items/" . $item_data['item_icon'] . "\"</span></td></tr>"; $message .= "</table>"; } return $message; }
function zone_npc_actions() { global $db, $userdata, $area_id, $user_id, $lang, $adr_user, $user_npc_visit_array, $user_npc_quest_array; if (isset($_GET['npc']) || isset($_POST['npc'])) { $npc_action = isset($_POST['npc']) ? intval($_POST['npc']) : intval($_GET['npc']); } $npc_give_action = isset($_POST['npc_give']) ? $_POST['npc_give'] : null; if (isset($npc_action)) { // Deny access if user is imprisioned if ($userdata['user_cell_time']) { adr_previous('Adr_zone_no_thief_npc', 'adr_cell', ''); } if (isset($_GET['npc_id']) || isset($_POST['npc_id'])) { $npc_id = isset($_POST['npc_id']) ? intval($_POST['npc_id']) : intval($_GET['npc_id']); } $adr_user = adr_npc_visit_update($npc_id, $adr_user); $sql = "SELECT * FROM " . ADR_NPC_TABLE . "\n\t\t\t\tWHERE npc_id = '{$npc_id}'\n\t\t\t\t\tAND npc_enable = '1'"; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query npc information', '', __LINE__, __FILE__, $sql); } //prevent user exploit if (!($npc_row = $db->sql_fetchrow($result))) { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } $npc_zone_array = explode(',', $npc_row['npc_zone']); $npc_race_array = explode(',', $npc_row['npc_race']); $npc_class_array = explode(',', $npc_row['npc_class']); $npc_alignment_array = explode(',', $npc_row['npc_alignment']); $npc_element_array = explode(',', $npc_row['npc_element']); $npc_character_level_array = explode(',', $npc_row['npc_character_level']); $npc_visit_array = explode(',', $npc_row['npc_visit_prerequisite']); $npc_quest_array = explode(',', $npc_row['npc_quest_prerequisite']); $npc_visit = array(); $npc_quest = array(); $no_talk_message = array(); $npc_quest_hide_array = array(); // you can't click a disabled npc if (!$npc_row['npc_enable']) { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } // you can't click a npc in another area if (!in_array($area_id, $npc_zone_array) && $npc_zone_array[0] != '0') { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } if (!in_array($adr_user['character_race'], $npc_race_array) && $npc_race_array[0] != '0' && !$npc_row['npc_view']) { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } else { if (!in_array($adr_user['character_race'], $npc_race_array) && $npc_race_array[0] != '0' && $npc_row['npc_view']) { $no_talk_message[] = $lang['Adr_Npc_race_no_talk_message']; } } if (!in_array($adr_user['character_class'], $npc_class_array) && $npc_class_array[0] != '0' && !$npc_row['npc_view']) { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } else { if (!in_array($adr_user['character_class'], $npc_class_array) && $npc_class_array[0] != '0' && $npc_row['npc_view']) { $no_talk_message[] = $lang['Adr_Npc_class_no_talk_message']; } } if (!in_array($adr_user['character_alignment'], $npc_alignment_array) && $npc_alignment_array[0] != '0' && !$npc_row['npc_view']) { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } else { if (!in_array($adr_user['character_alignment'], $npc_alignment_array) && $npc_alignment_array[0] != '0' && $npc_row['npc_view']) { $no_talk_message[] = $lang['Adr_Npc_alignment_no_talk_message']; } } if (!in_array($adr_user['character_element'], $npc_element_array) && $npc_element_array[0] != '0' && !$npc_row['npc_view']) { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } else { if (!in_array($adr_user['character_element'], $npc_element_array) && $npc_element_array[0] != '0' && $npc_row['npc_view']) { $no_talk_message[] = $lang['Adr_Npc_element_no_talk_message']; } } if (!in_array($adr_user['character_level'], $npc_character_level_array) && $npc_character_level_array[0] != '0' && !$npc_row['npc_view']) { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } else { if (!in_array($adr_user['character_level'], $npc_character_level_array) && $npc_character_level_array[0] != '0' && $npc_row['npc_view']) { $no_talk_message[] = $lang['Adr_Npc_character_level_no_talk_message']; } } for ($y = 0; $y < count($user_npc_visit_array); $y++) { $npc_visit[$y] = in_array($user_npc_visit_array[$y], $npc_visit_array) ? '1' : '0'; } if (!in_array('1', $npc_visit) && $npc_visit_array[0] != '0' && !$npc_row['npc_view']) { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } else { if (!in_array('1', $npc_visit) && $npc_visit_array[0] != '0' && $npc_row['npc_view']) { $no_talk_message[] = $lang['Adr_Npc_character_visit_no_talk_message']; } } for ($y = 0; $y < count($user_npc_quest_array); $y++) { $npc_quest_id = explode(':', $user_npc_quest_array[$y]); $npc_quest[$y] = in_array($npc_quest_id[0], $npc_quest_array) ? '1' : '0'; $npc_quest_hide_array[$y] = $npc_quest_id[0] == $npc_row['npc_id'] ? '1' : '0'; } if (!in_array('1', $npc_quest) && $npc_quest_array[0] != '0' && !$npc_row['npc_view']) { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } else { if (!in_array('1', $npc_quest) && $npc_quest_array[0] != '0' && $npc_row['npc_view']) { $no_talk_message[$x] = $lang['Adr_Npc_character_quest_no_talk_message']; } } if (in_array('1', $npc_quest_hide_array) && $npc_row['npc_quest_hide']) { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } $adr_moderators_array = explode(',', $board_config['zone_adr_moderators']); if ($npc_row['npc_user_level'] != '0' && !($npc_row['npc_user_level'] == '1' && $userdata['user_level'] == ADMIN || $npc_row['npc_user_level'] == '2' && (in_array($user_id, $adr_moderators_array) || $userdata['user_level'] == ADMIN))) { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } //---- adr_substract_points($user_id, $npc_row['npc_price'], 'adr_zones', ''); if (count($no_talk_message)) { $message_id = rand(0, count($no_talk_message) - 1); $message = "<img src=\"adr/images/zones/npc/" . $npc_row['npc_img'] . "\"><br /><br /><b>" . $npc_row['npc_name'] . ":</b> <i>\"" . $no_talk_message[$message_id] . "\"</i><br /><br />" . $lang['Adr_zone_event_return']; $adr_zone_npc_title = sprintf($lang['Adr_Npc_speaking_with'], $npc_row['npc_name']); message_die(GENERAL_MESSAGE, $message, $adr_zone_npc_title, ''); break; } else { if (adr_item_quest_check($npc_row['npc_id'], $adr_user['character_npc_check'], $npc_row['npc_times'])) { zone_npc_item_quest_check($npc_row); } else { $message = "<img src=\"adr/images/zones/npc/" . $npc_row['npc_img'] . "\"><br /><br /><b>" . $npc_row['npc_name'] . ":</b> <i>\"" . $npc_row['npc_message3'] . "\"</i><br /><br />" . $lang['Adr_zone_event_return']; $adr_zone_npc_title = sprintf($lang['Adr_Npc_speaking_with'], $npc_row['npc_name']); message_die(GENERAL_ERROR, $message, $adr_zone_npc_title, ''); break; } } } else { if (isset($npc_give_action)) { $npc_id = intval($_POST['npc_id']); $item_id_array = explode(',', $_POST['item_id']); $sql = "SELECT * FROM " . ADR_NPC_TABLE . "\n\t\t\t\tWHERE npc_id = '{$npc_id}'"; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query npc information', '', __LINE__, __FILE__, $sql); } //prevent user exploit if (!($npc_give_row = $db->sql_fetchrow($result))) { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } if (!$npc_give_row['npc_enable']) { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } // V: let's add some security to this bullshit. $sql = "SELECT * FROM " . ADR_QUEST_LOG_TABLE . "\n\t\t\t\t\t \t\tWHERE user_id = '{$user_id}'\n\t\t\t\t\t\t\tAND npc_id = '{$npc_id}'\n\t\t\t\t\t\t\t"; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query quest log information', __LINE__, __FILE__, $sql); } $quest = $db->sql_fetchrow($result); if (!$quest) { $message = "<img src=\"adr/images/zones/npc/" . $npc_give_row['npc_img'] . "\"><br /><br /><b>" . $lang['npc_cant_give_quest_u_dont_have'] . "</b><br /><br />" . $lang['Adr_zone_event_return']; $adr_zone_npc_title = sprintf($lang['Adr_Npc_speaking_with'], $npc_row['npc_name']); message_die(GENERAL_ERROR, $message, $adr_zone_npc_title, ''); break; } $npc_zone_array = explode(',', $npc_give_row['npc_zone']); $npc_race_array = explode(',', $npc_give_row['npc_race']); $npc_class_array = explode(',', $npc_give_row['npc_class']); $npc_alignment_array = explode(',', $npc_give_row['npc_alignment']); $npc_element_array = explode(',', $npc_give_row['npc_element']); $npc_character_level_array = explode(',', $npc_give_row['npc_character_level']); $npc_visit_array = explode(',', $npc_give_row['npc_visit_prerequisite']); $npc_quest_array = explode(',', $npc_give_row['npc_quest_prerequisite']); $npc_visit = array(); $npc_quest = array(); $npc_quest_hide_array = array(); if (!in_array($area_id, $npc_zone_array) && $npc_zone_array[0] != '0') { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } if (!in_array($adr_user['character_race'], $npc_race_array) && $npc_race_array[0] != '0') { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } if (!in_array($adr_user['character_class'], $npc_class_array) && $npc_class_array[0] != '0') { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } if (!in_array($adr_user['character_alignment'], $npc_alignment_array) && $npc_alignment_array[0] != '0') { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } if (!in_array($adr_user['character_element'], $npc_element_array) && $npc_element_array[0] != '0') { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } if (!in_array($adr_user['character_level'], $npc_character_level_array) && $npc_character_level_array[0] != '0') { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } for ($y = 0; $y < count($user_npc_visit_array); $y++) { $npc_visit[$y] = in_array($user_npc_visit_array[$y], $npc_visit_array) ? '1' : '0'; } if (!in_array('1', $npc_visit) && $npc_visit_array[0] != '0' && !$npc_give_row['npc_view']) { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } for ($y = 0; $y < count($user_npc_quest_array); $y++) { $npc_quest_id = explode(':', $user_npc_quest_array[$y]); $npc_quest[$y] = in_array($npc_quest_id[0], $npc_quest_array) ? '1' : '0'; $npc_quest_hide_array[$y] = $npc_quest_id[0] == $npc_give_row['npc_id'] ? '1' : '0'; } if (!in_array('1', $npc_quest) && $npc_quest_array[0] != '0' && !$npc_give_row['npc_view']) { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } if (in_array('1', $npc_quest_hide_array) && $npc_give_row['npc_quest_hide']) { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } $adr_moderators_array = explode(',', $board_config['zone_adr_moderators']); if ($npc_give_row['npc_user_level'] != '0' && !($npc_give_row['npc_user_level'] == '1' && $userdata['user_level'] == ADMIN || $npc_give_row['npc_user_level'] == '2' && (in_array($user_id, $adr_moderators_array) || $userdata['user_level'] == ADMIN))) { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } if (!$npc_give_row['npc_quest_clue']) { // Check if user has the item(s) $npc_item_array = explode(',', $npc_give_row['npc_item']); for ($i = 0; $i < count($npc_item_array); $i++) { $sql = "SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . "\n\t \t\t\t\t\tWHERE item_id = '" . $item_id_array[$i] . "'\n\t \t\t\t\t\t AND item_name = '" . $npc_item_array[$i] . "'\n\t \t\t\t\t\t\tAND item_owner_id = '{$user_id}'\n\t\t \t\t\t\t\tAND item_in_shop = '0'\n\t\t\t \t\t\t\tAND item_in_warehouse = '0'\n\t\t\t\t\t\tLIMIT 1 "; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not query shop item information', '', __LINE__, __FILE__, $sql); } $item_npc = $db->sql_fetchrowset($result); if (count($item_npc) == 0 && ($npc_give_row['npc_kill_monster'] == "" or $npc_give_row['npc_kill_monster'] == '0')) { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_1']); } } } else { if (!$npc_give_row['npc_quest_clue']) { adr_item_quest_cheat_notification($user_id, $lang['Adr_zone_npc_cheating_type_2']); } } if (adr_item_quest_check($npc_give_row['npc_id'], $adr_user['character_npc_check'], $npc_give_row['npc_times'])) { if (!$npc_give_row['npc_quest_clue']) { //Delete item(s) from character inventory for ($i = 0; $i < count($npc_item_array); $i++) { $delsql = "DELETE FROM " . ADR_SHOPS_ITEMS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE item_owner_id = '{$user_id}'\n\t\t\t\t\t\t\t\t\tAND item_id = '" . $item_id_array[$i] . "' "; if (!($aresult = $db->sql_query($delsql))) { message_die(GENERAL_ERROR, "Couldn't update inventory info", "", __LINE__, __FILE__, $asql); } $sql5 = "SELECT * FROM " . ADR_QUEST_LOG_TABLE . "\n\t\t\t\t\t\tWHERE quest_item_need like '" . $npc_item_array[$i] . "," . "%' \n\t\t\t\t\t\tOR quest_item_need like '" . $npc_item_array[$i] . "'\n\t\t\t\t\t\tOR quest_item_need like '" . $npc_item_array[$i] . "," . "'\n\t\t\t\t\t\tOR quest_item_need like '%" . "," . $npc_item_array[$i] . "," . "%'\n\t\t\t\t\t\tOR quest_item_need like '%" . "," . $npc_item_array[$i] . "'\n\t\t\t\t\t\tAND user_id = '{$user_id}'\n\t\t\t\t\t\t"; $cresult = $db->sql_query($sql5); if (!$cresult) { message_die(GENERAL_ERROR, 'Could not obtain required quest information', "", __LINE__, __FILE__, $sql5); } if ($got_item_log = $db->sql_fetchrow($cresult)) { $got_item += 1; } if ($got_item == count($npc_item_array) && ($npc_give_row['npc_kill_monster'] == '0' || $npc_give_row['npc_kill_monster'] == "")) { //Copy Quest to the History $insertsql = "INSERT INTO " . ADR_QUEST_LOG_HISTORY_TABLE . "\n\t\t\t\t\t\t\t( user_id, quest_killed_monster , quest_killed_monsters_amount , npc_id, quest_item_gave)\n\t\t\t\t\t\t\tVALUES ( '{$user_id}' , '" . $npc_give_row['npc_kill_monster'] . "' , '" . $npc_give_row['npc_monster_amount'] . "' , '" . $npc_give_row['npc_id'] . "', '" . $npc_give_row['npc_item'] . "' )"; $result = $db->sql_query($insertsql); if (!$result) { message_die(GENERAL_ERROR, "Couldn't insert finished quest", "", __LINE__, __FILE__, $insertsql); } //Delete the Quest of the log $delsql2 = " DELETE FROM " . ADR_QUEST_LOG_TABLE . "\n\t\t\t\t\t \t\tWHERE user_id = '{$user_id}'\n\t\t\t\t\t\t\tAND npc_id = '{$npc_id}'\n\t\t\t\t\t \t\t"; if (!($bresult = $db->sql_query($delsql2))) { message_die(GENERAL_ERROR, "Couldn't update questlog info", "", __LINE__, __FILE__, $delsql2); } } } if ($npc_give_row['npc_kill_monster'] != '0' && $npc_give_row['npc_kill_monster'] != "" && $npc_give_row['quest_kill_monster_current_amount'] == $npc_give_row['npc_kill_monster_amount']) { //Copy Quest to the History $insertsql = "INSERT INTO " . ADR_QUEST_LOG_HISTORY_TABLE . "\n\t\t\t\t\t\t( user_id, quest_killed_monster , quest_killed_monsters_amount , npc_id, quest_item_gave)\n\t\t\t\t\t\tVALUES ( '{$user_id}' , '" . $npc_give_row['npc_kill_monster'] . "' , '" . $npc_give_row['npc_monster_amount'] . "' , '" . $npc_give_row['npc_id'] . "', '" . $npc_give_row['npc_item'] . "' )"; $result = $db->sql_query($insertsql); if (!$result) { message_die(GENERAL_ERROR, "Couldn't insert finished quest", "", __LINE__, __FILE__, $insertsql); } //Delete the Quest of the log $delsql3 = " DELETE FROM " . ADR_QUEST_LOG_TABLE . "\n\t\t\t \t\t\tWHERE quest_kill_monster = '" . $npc_give_row['npc_kill_monster'] . "'\n\t\t\t \t\t\tAND quest_kill_monster_current_amount = '" . $npc_give_row['npc_monster_amount'] . "'\n\t\t\t\t\t\tAND user_id = '{$user_id}'\n\t\t\t\t\t\tAND npc_id = '{$npc_id}'\n\t\t\t\t \t\t"; if (!($dresult = $db->sql_query($delsql3))) { message_die(GENERAL_ERROR, "Couldn't update questlog info", "", __LINE__, __FILE__, $delsql3); } } } else { adr_substract_points($user_id, $npc_give_row['npc_quest_clue_price'], adr_zones, ''); //Delete the Quest of the log $delsql2 = " DELETE FROM " . ADR_QUEST_LOG_TABLE . "\n\t\t\t \t\tWHERE user_id = '{$user_id}'\n\t\t\t\t\tAND npc_id = '{$npc_id}'\n\t\t\t \t\t"; if (!($bresult = $db->sql_query($delsql2))) { message_die(GENERAL_ERROR, "Couldn't update questlog info", "", __LINE__, __FILE__, $delsql2); } } //give points prize adr_add_points($user_id, $npc_give_row['npc_points']); //give exp and sp prize $sql = "UPDATE " . ADR_CHARACTERS_TABLE . "\n\t\t\t\t\tSET character_xp = character_xp + '" . $npc_give_row['npc_exp'] . "',\n\t\t\t\t\t\tcharacter_sp = character_sp + '" . $npc_give_row['npc_sp'] . "'\n\t\t\t\t\tWHERE character_id = '{$user_id}' "; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, 'Could not update character information', '', __LINE__, __FILE__, $sql); } $prize_item = ''; if ($npc_give_row['npc_item2'] != "0" && $npc_give_row['npc_item2'] != "") { $npc_item2_array = explode(',', $npc_give_row['npc_item2']); for ($i = 0; $i < count($npc_item2_array); $i++) { adr_shop_insert_item($npc_item2_array[$i], adr_make_new_item_id($user_id), $user_id, 1, 0, 0, 'item_name'); if (count($npc_item2_array) == 1) { $prize_item .= adr_get_lang($npc_item2_array[$i]); } else { if ($i >= 1 && $i == count($npc_item2_array) + 1) { $prize_item .= ' and ' . adr_get_lang($npc_item2_array[$i]); } else { $prize_item .= ', ' . adr_get_lang($npc_item2_array[$i]); } } } $prize_message = sprintf($lang['Adr_zone_npc_item_prize'], $npc_give_row['npc_name'], $prize_item); } //Insert Character in check field if ($npc_give_row['npc_times'] > 0) { adr_item_quest_check_insert($adr_user['character_npc_check'], $npc_give_row['npc_id'], $user_id); } //---- $points_prize_lang = $npc_give_row['npc_points'] == 0 ? "" : sprintf($lang['Adr_zone_npc_points_prize'], number_format(intval($npc_give_row['npc_points'])), $board_config['points_name']); $exp_prize_lang = $npc_give_row['npc_exp'] == 0 ? "" : sprintf($lang['Adr_zone_npc_exp_prize'], number_format(intval($npc_give_row['npc_exp']))); $sp_prize_lang = $npc_give_row['npc_sp'] == 0 ? "" : sprintf($lang['Adr_zone_npc_sp_prize'], number_format(intval($npc_give_row['npc_sp']))); $item_prize_lang = count($npc_item2_array) == 0 || $npc_give_row['npc_item2'] == "" ? "" : $prize_message; $message = "<img src=\"adr/images/zones/npc/" . $npc_give_row['npc_img'] . "\"><br /><br /><b>" . $npc_give_row['npc_name'] . ":</b> <i>\"" . $npc_give_row['npc_message2'] . "\"</i><br /><br />" . $item_prize_lang . "" . $points_prize_lang . "" . $exp_prize_lang . "" . $sp_prize_lang . "<br />" . $lang['Adr_zone_event_return']; $adr_zone_npc_title = sprintf($lang['Adr_Npc_speaking_with'], $npc_row['npc_name']); message_die(GENERAL_ERROR, $message, $adr_zone_npc_title, ''); break; } else { $message = "<img src=\"adr/images/zones/npc/" . $npc_give_row['npc_img'] . "\"><br /><br /><b>" . $npc_give_row['npc_name'] . ":</b> <i>\"" . $npc_give_row['npc_message2'] . "\"</i><br /><br />" . $lang['Adr_zone_event_return']; $adr_zone_npc_title = sprintf($lang['Adr_Npc_speaking_with'], $npc_row['npc_name']); message_die(GENERAL_ERROR, $message, $adr_zone_npc_title, ''); break; } } } }
function adr_buy_item($user_id, $item_id, $shop_owner_id, $shop_id, $direct, $nav) { global $db, $lang, $board_config, $phpEx, $userdata, $adr_general, $adr_user; // Fix the values $user_id = intval($user_id); $item_id = intval($item_id); $shop_owner_id = intval($shop_owner_id); $shop_id = intval($shop_id); $sql = "SELECT character_trading_limit FROM " . ADR_CHARACTERS_TABLE . "\r\n\t\t\tWHERE character_id = {$user_id} "; $result = $db->sql_query($sql); if (!$result) { message_die(GENERAL_ERROR, 'Could not obtain shops items information', "", __LINE__, __FILE__, $sql); } $trading_limit = $db->sql_fetchrow($result); if ($adr_general['Adr_character_limit_enable'] != 0 && $trading_limit['character_trading_limit'] < 1) { adr_previous(Adr_trading_limit, adr_shops, ''); } // Select the item infos $shop_more_sql = $shop_owner_id != 1 ? 'AND item_in_shop = 1' : ''; // Prevents users to buy items not in shops $sql = "SELECT * FROM " . ADR_SHOPS_ITEMS_TABLE . "\r\n\t\tWHERE item_owner_id = {$shop_owner_id}\r\n\t\tAND item_id = {$item_id} \r\n\t\t{$shop_more_sql} "; $result = $db->sql_query($sql); if (!$result) { message_die(GENERAL_ERROR, 'Could not obtain shops items information', "", __LINE__, __FILE__, $sql); } $item_data = $db->sql_fetchrow($result); // Check if the item exists if (!is_numeric($item_data['item_price'])) { adr_previous(Adr_lack_items, $direct, $nav); } // Calculate the sum using the trading skill $sum = $item_data['item_price']; $sum = adr_use_skill_trading($user_id, $sum, buy); // Substract the points adr_substract_points($user_id, $sum, $direct, $nav); $new_item_id = adr_make_new_item_id($user_id); // If the shop isn't the forums one , transfer , else duplicate if ($shop_owner_id != 1) { $sql = "UPDATE " . ADR_SHOPS_ITEMS_TABLE . "\r\n\t\t\tSET item_owner_id = {$user_id} ,\r\n\t\t\t\titem_id = {$new_item_id} ,\r\n\t\t\t\titem_bought_timestamp = " . time() . ",\r\n\t\t\t\titem_in_shop = 0 , \r\n\t\t\t\titem_auth = 0,\r\n\t\t\t\titem_donated_by = '',\r\n\t\t\t\titem_donated_timestamp = 0\r\n\t\t\tWHERE item_owner_id = {$shop_owner_id}\r\n\t\t\tAND item_id = {$item_id} "; $result = $db->sql_query($sql); if (!$result) { message_die(GENERAL_ERROR, 'Could not obtain shops items information', "", __LINE__, __FILE__, $sql); } // Give money to the seller adr_add_points($shop_owner_id, $sum); } else { adr_shop_insert_item($item_id, $new_item_id, $user_id, $shop_owner_id); } return $sum; }