Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * building
- *
- * @param int $bid, building id
- * @param int $aid, account id
- * @param int $start_time, Time()
- * @param int $duration, time to new building's level
- */
- function building($bid,$aid,$start_time,$duration) {
- if( isset($bid) && isset($aid) && isset($start_time) && isset($duration)) {
- $work_query = "SELECT COUNT(*) FROM building_work WHERE aid = $aid";
- $work_number = mysql_result(mysql_query($work_query), 0);
- $same_query = "SELECT COUNT(*) FROM building_work WHERE aid = $aid AND bid = $bid";
- $same_work = mysql_result(mysql_query($same_query), 0);
- if ( $work_number < 2 ) {
- if( $same_work == 0 ) {
- $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";
- $building = mysql_fetch_assoc(mysql_query($building_query));
- if ( $building['level'] != 1 ) {
- $reconstruction_costs = ($building['price']*$building['level'])*1.5;
- $reconstruction_time = ($building['time']*$building['level'])*1.2;
- }
- else {
- $reconstruction_costs = (int) $building['price'];
- $reconstruction_time = (int) $building['time'];
- }
- $player_query = "SELECT * FROM player WHERE aid = $aid";
- $player = mysql_fetch_assoc(mysql_query($player_query));
- if ( $player['money'] >= $reconstruction_costs ) {
- mysql_query("INSERT INTO building_work (aid,bid,start_time,duration) VALUES ('$aid','$bid','$start_time','$duration')");
- }
- else {
- // player doesn't has money
- }
- } else {
- // we aren't ready for the same work
- }
- }
- else {
- // this building has been renovated
- }
- }
- }
Add Comment
Please, Sign In to add comment