Guest User

Untitled

a guest
Jul 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.28 KB | None | 0 0
  1.     /**
  2.     * building
  3.     *
  4.     * @param int $bid, building id
  5.     * @param int $aid, account id
  6.     * @param int $start_time, Time()
  7.     * @param int $duration, time to new building's level
  8.     */
  9.     function building($bid,$aid,$start_time,$duration) {
  10.         if( isset($bid) && isset($aid) && isset($start_time) && isset($duration)) {
  11.            
  12.             $work_query = "SELECT COUNT(*) FROM building_work WHERE aid = $aid";
  13.             $work_number = mysql_result(mysql_query($work_query), 0);
  14.            
  15.             $same_query = "SELECT COUNT(*) FROM building_work WHERE aid = $aid AND bid = $bid";
  16.             $same_work = mysql_result(mysql_query($same_query), 0);
  17.            
  18.             if ( $work_number < 2 ) {
  19.                 if( $same_work == 0 ) {
  20.                     $building_query = "SELECT * FROM building LEFT JOIN building_player ON building.bid = building_player.bid WHERE building_player.aid = $aid AND building_player.bid = $bid";            
  21.                     $building = mysql_fetch_assoc(mysql_query($building_query));
  22.                    
  23.                     if ( $building['level'] != 1 ) {
  24.                         $reconstruction_costs = ($building['price']*$building['level'])*1.5;
  25.                         $reconstruction_time = ($building['time']*$building['level'])*1.2;  
  26.                     }
  27.                     else {
  28.                         $reconstruction_costs = (int) $building['price'];
  29.                         $reconstruction_time = (int) $building['time'];
  30.                     }
  31.                    
  32.                     $player_query = "SELECT * FROM player WHERE aid = $aid";
  33.                     $player = mysql_fetch_assoc(mysql_query($player_query));
  34.                      
  35.                     if ( $player['money'] >= $reconstruction_costs ) {
  36.                         mysql_query("INSERT INTO building_work (aid,bid,start_time,duration) VALUES ('$aid','$bid','$start_time','$duration')");
  37.                     }
  38.                     else {
  39.                         // player doesn't has money
  40.                     }
  41.                 } else {
  42.                     // we aren't ready for the same work
  43.                 }
  44.             }
  45.             else {
  46.                 // this building has been renovated
  47.             }
  48.         }
  49.     }
Add Comment
Please, Sign In to add comment