Example #1
0
 public function drop_loot($user_id)
 {
     if ($this->error == 1) {
         return;
     }
     if ($this->npc['dropable'] == 1) {
         $seldrop = myquery("SELECT * FROM game_npc_drop WHERE npc_id=" . $this->templ['npc_id'] . ";");
         if ($seldrop != false and mysql_num_rows($seldrop)) {
             $sum_chance = 0;
             $massiv = array(0);
             $m_last = 1;
             $mes = "";
             $lcm = array();
             $str = "";
             $r = 0;
             $no_loot = 0;
             //Обработаем профессию "Охотник"
             if ($this->templ['npc_id'] == npc_id_olen) {
                 if (checkCraftTrain($user_id, 8)) {
                     $r = $r + 2 * getCraftLevel($user_id, 8);
                 } else {
                     $no_loot = 1;
                 }
             }
             while ($chance = mysql_fetch_array($seldrop)) {
                 $lcm[] = $chance['random_max'];
             }
             mysql_data_seek($seldrop, 0);
             $lcm = lcm_arr($lcm);
             while ($chance = mysql_fetch_array($seldrop)) {
                 $this_chance = ($chance['random'] + $r) * $lcm / gcd($lcm, $chance['random_max']);
                 $massiv = array_merge($massiv, array_fill($m_last, $this_chance, $chance));
                 $m_last += $this_chance;
             }
             if ($m_last < $lcm + 1) {
                 $massiv = array_merge($massiv, array_fill($m_last, $lcm + 1 - $m_last, array('items_id' => 0)));
             }
             $drop = $massiv[mt_rand(1, $lcm)];
             if ($drop['items_id'] != 0 and $no_loot == 0) {
                 $it_user_id = 0;
                 $priznak = 2;
                 $kol_predmetov = mt_rand($drop['mincount'], $drop['maxcount']);
                 $map_name = 0;
                 $map_xpos = 0;
                 $map_ypos = 0;
                 for ($cikl = 1; $cikl <= $kol_predmetov; $cikl++) {
                     $add_result = array(0);
                     if ($drop['kuda'] == 1) {
                         $it_user_id = $user_id;
                         $priznak = 0;
                         //проверим вес
                         if ($drop['drop_type'] == 1) {
                             $item = mysql_fetch_array(myquery("SELECT * FROM game_items_factsheet WHERE id=" . $drop['items_id'] . ""));
                         } elseif ($drop['drop_type'] == 2) {
                             $item = mysql_fetch_array(myquery("SELECT * FROM craft_resource WHERE id=" . $drop['items_id'] . ""));
                         }
                         list($CW, $CC) = mysql_fetch_array(myquery("SELECT CW,CC FROM view_active_users WHERE user_id={$it_user_id}"));
                         $prov = mysqlresult(myquery("SELECT COUNT(*) FROM game_wm WHERE user_id={$it_user_id} AND type=1"), 0, 0);
                         if ($CC - $CW < $item['weight'] and $prov == 0) {
                             //инвентарь заполнен. На землю его!
                             $it_user_id = 0;
                             $priznak = 2;
                             list($map_name, $map_xpos, $map_ypos) = mysql_fetch_array(myquery("SELECT map_name,map_xpos,map_ypos FROM game_users_map WHERE user_id={$it_user_id}"));
                             $drop['kuda'] = 0;
                         }
                     }
                     //если предмет
                     if ($drop['drop_type'] == 1) {
                         if ($priznak == 0) {
                             $Item = new Item();
                             $add_result = $Item->add_user($drop['items_id'], $it_user_id, 0, 0, 1);
                             // не получилось добавить один - не выйдет и остальные.
                             if ($add_result[0] == 0) {
                                 break;
                             }
                         } else {
                             if (!isset($item)) {
                                 $item = mysql_fetch_array(myquery("SELECT * FROM game_items_factsheet WHERE id=" . $drop['items_id'] . ""));
                             }
                             myquery("INSERT INTO game_items (user_id,item_id,priznak,ref_id,item_uselife,item_uselife_max,item_cost,map_name,map_xpos,map_ypos) VALUES ('{$it_user_id}','" . $drop['items_id'] . "','{$priznak}',0,'" . $item['item_uselife'] . "','" . $item['item_uselife_max'] . "','" . $item['item_cost'] . "','{$map_name}','{$map_xpos}','{$map_ypos}')");
                         }
                     } elseif ($drop['drop_type'] == 2) {
                         if ($drop['kuda'] == 1) {
                             $Res = new Res($item, 0);
                             $Res->add_user(0, $it_user_id, 1);
                             if ($this->templ['npc_id'] == npc_id_olen) {
                                 myquery("INSERT INTO craft_stat (build_id, gp, res_id, dob, vip, dat, user, type) values (0, 0, " . $drop['items_id'] . ", 0, 1, " . time() . ", {$it_user_id}, 'z')");
                                 setCraftTimes($it_user_id, 8, 1, 1);
                                 add_exp_for_craft($it_user_id, 8);
                             }
                         } elseif ($drop['kuda'] == 0) {
                             $Res = new Res(0, $drop['items_id']);
                             $Res->add_map(0, 0, 1, 0, $map_name, $map_xpos, $map_ypos);
                             myquery("INSERT INTO craft_resource_market (user_id,town,col,price,res_id,opis,map_name,map_xpos,map_ypos) VALUES (0,0,1,0," . $drop['items_id'] . ",'','" . $map_name . "','" . $map_xpos . "','" . $map_ypos . "')");
                         }
                     }
                     if ($it_user_id > 0) {
                         if ($drop['drop_type'] == 1) {
                             $mes = '<font color=\\"#eeeeee\\">После убийства монстра ты ' . echo_sex('увидел', 'увидела') . ' оставшийся от него предмет: <b>' . $item['name'] . '</b>.Ты быстро ' . echo_sex('подобрал', 'подобрала') . ' выпавший предмет и ' . echo_sex('положил', 'положила') . ' его в свой инвентарь!</font>';
                         } elseif ($drop['drop_type'] == 2) {
                             $mes = '<font color=\\"#eeeeee\\">После убийства монстра ты ' . echo_sex('заметил', 'заметила') . ', как он выронил из рук: <b>' . $item['name'] . '<b/>. Не мешкая ты быстро ' . echo_sex('подобрал', 'подобрала') . ' выпавший ресурс и ' . echo_sex('положил', 'положила') . ' его в свой инвентарь!</font>';
                         }
                         $result = myquery("INSERT game_battles SET attacker_id=" . $user_id . ", target_id=0, map_name=" . $map_name . ", map_xpos=" . $map_xpos . ", map_ypos=" . $map_ypos . ", contents='" . $mes . "', post_time=" . time() . "");
                     }
                 }
             }
         }
     }
 }