Guest User

Untitled

a guest
Jan 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.56 KB | None | 0 0
  1. function create_village($userid, $username = '', $direction) {
  2.                 global $config;
  3.                 global $cl_units;
  4.                 global $db;
  5.  
  6.                 $result = $db->query( 'SELECT * from create_village' );
  7.                 $row = $db->Fetch( $result );
  8.  
  9.                 if ($direction == 'random') {
  10.                         $min = min( $row['no'], ['nw'], ['sw'], ['so'] );
  11.                         switch ($min) {
  12.                                 case $row['no']: {
  13.                                         $direction = 'no';
  14.                                         break;
  15.                                 }
  16.  
  17.                                 case $row['nw']: {
  18.                                         $direction = 'nw';
  19.                                         break;
  20.                                 }
  21.  
  22.                                 case $row['so']: {
  23.                                         $direction = 'so';
  24.                                         break;
  25.                                 }
  26.  
  27.                                 case $row['sw']: {
  28.                                         $direction = 'sw';
  29.                                 }
  30.                         }
  31.                 } else {
  32.                         if ($direction = 'random_left') {
  33.                                 $dir = array( '1' => 'no', '2' => 'sw', '3' => 'so', '4' => 'nw' );
  34.                                 $direction = $dir[$rand = rand( 1, 4 )];
  35.                         } else {
  36.                                 $direction = parse( $direction );
  37.                         }
  38.                 }
  39.  
  40.                 $alpha = $row[$direction . '_alpha'];
  41.                 do {
  42.                         $db->query( 'UNLOCK TABLES' );
  43.                         $size_c = mt_rand( $row[$direction . '_c'], $longest_c - $long2 = round( ( $longest_c = max( $row['no_c'], ['nw_c'], ['sw_c'], ['so_c'] ) - $row[$direction . '_c'] ) / 2 ) );
  44.  
  45.                         if (90 <= ( $alpha += 90 / $row[$direction . '_c'] * $zufall = rand( 130, 250 ) / 100 )) {
  46.                                 $row[$direction . '_alpha'] = rand( 1, 25 );
  47.                                 $do_alpha_to_null = true;
  48.                                 $row[$direction . '_c'] += mt_rand( 1, 3 );
  49.                                 $alpha = $row[$direction . '_alpha'];
  50.                         } else {
  51.                                 $do_alpha_to_null = false;
  52.                         }
  53.  
  54.                         $x = round( sin( $bogen = $alpha * 2 * pi(  ) / 360 ) * $size_c );
  55.                         $y = round( cos( $bogen ) * $size_c );
  56.  
  57.                         if ($direction == 'nw') {
  58.                                 $x = 525 - $x;
  59.                                 $y = 525 + $y;
  60.                         }
  61.  
  62.                         if ($direction == 'no') {
  63.                                 $x = 525 + $x;
  64.                                 $y = 525 + $y;
  65.                         }
  66.  
  67.                         if ($direction == 'so') {
  68.                                 $x = 525 + $x;
  69.                                 $y = 525 - $y;
  70.                         }
  71.  
  72.                         if ($direction == 'sw') {
  73.                                 $x = 525 - $x;
  74.                                 $y = 525 - $y;
  75.                         }
  76.  
  77.                         $db->query( 'LOCK TABLES villages read' );
  78.                         $result = $db->query( 'SELECT COUNT(id) AS count_village FROM villages WHERE x = ' . $x . ' AND y = ' . $y );
  79.  
  80.                         if (!( $row2 = $db->Fetch( $result )['count_village'])) {
  81.                                 $db->query( 'UNLOCK TABLES' );
  82.                         }
  83.                 }while (!( $row2['count_village'] == '1'));
  84.  
  85.  
  86.                 if ($userid != '-1') {
  87.                         $lang = new aLang( 'functions', $config['lang'] );
  88.                         $villagename = parse( entparse( $username ) . 's ' . $lang->get( 'village' ) );
  89.                 } else {
  90.                         $villagename = urldecode( $config['left_name'] );
  91.                 }
  92.  
  93.                 $arr = convert_to_continents( $x, $y );
  94.                 $unit = $cl_units->get_array( 'name' );
  95.                 $db->query( 'INSERT into villages (x,y,name,userid,continent,last_prod_aktu,create_time,conmap_con) VALUES (\'' . $x . '\',\'' . $y . '\',\'' . $villagename . '\',\'' . $userid . ( '\',\'' . $arr['con'] . '\',\'' ) . time(  ) . '\',\'' . time(  ) . '\',\'' . get_conmap( $arr[con], $x, $y ) . '\')' );
  96.                 $db->query( 'INSERT into unit_place (villages_from_id,villages_to_id) VALUES (\'' . $villageid = $db->GetLastId(  ) . '\',\'' . $villageid . '\')' );
  97.                 reload_village_points( $villageid );
  98.                 load_bh( $villageid );
  99.  
  100.                 if ($userid != '-1') {
  101.                         $db->query( 'UPDATE users SET villages=villages+\'1\' where id=\'' . $userid . '\'' );
  102.                         reload_player_points( $userid );
  103.                         reload_player_rangs(  );
  104.                 }
  105.  
  106.                 $row[$direction . '_alpha'] = $alpha;
  107.  
  108.                 if ($do_alpha_to_null) {
  109.                         $row[$direction . '_alpha'] = 0;
  110.                 }
  111.  
  112.                 $add_sql = '';
  113.                 $create_lager = false;
  114.  
  115.                 if (0 < $config['count_create_left']) {
  116.                         if ($userid != '-1') {
  117.                                 if ($row['next_left'] <= 1) {
  118.                                         $create_lager = true;
  119.                                         $add_sql = ',next_left=\'' . $config['count_create_left'] . '\'';
  120.                                 } else {
  121.                                         $add_sql = ',next_left=next_left-1';
  122.                                 }
  123.                         }
  124.                 }
  125.  
  126.                 $db->query( 'UPDATE create_village SET nw_c=\'' . $row['nw_c'] . '\',no_c=\'' . ['no_c'] . '\',
  127.                                        so_c=\'' . ['so_c'] . '\',sw_c=\'' . ['sw_c'] . ( '\',
  128.                                        ' . $direction . '=' . $direction . '+1,
  129.                                        nw_alpha=\'' ) . ['nw_alpha'] . '\',no_alpha=\'' . ['no_alpha'] . '\',
  130.                                        so_alpha=\'' . ['so_alpha'] . '\',sw_alpha=\'' . ['sw_alpha'] . ( '\'
  131.                                        ' . $add_sql ) );
  132.  
  133.                 if ($create_lager) {
  134.                         create_village( '-1', '', 'random_left' );
  135.                 }
  136.  
  137.                 if ($userid != '-1') {
  138.                         return $villageid;
  139.                 }
  140.  
  141.         }
Add Comment
Please, Sign In to add comment