⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 building_create_task.php

📁 Download you own three BR
💻 PHP
字号:
<?php
//建造任务队列
if($_POST['action']=="start_build"){

  $_GET['build_page'] = $_POST['build_page'];
  $_POST['grade_type'] = $_POST['build_type'];
  //echo $_POST['build_type'];exit;
  $build_type=$_POST['building_id'];
  
  
  if ($_POST['build_type']<>'destory')
  {
  //判断当前城池使用面积是否己满;
  $query_city_size_if=$db->query("select c_size from city where u_id='".$_COOKIE['UserId']."' and c_id='".$_COOKIE['CityId']."';");
  $list_city_size_num=$db->fetch_array($query_city_size_if);
  if ($list_city_size_num['c_size']<'1') echomsg("当前城池土地面积己满!");
  }
  
  //判断当前建筑队列是否存在
  $query=$db->query("select u_id from building_task where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."' and `b_type`='".$build_type."' ");
  $exis_build = $db->fetch_array($query);
  if($exis_build['u_id']==$_COOKIE['UserId']) echomsg("建筑物正在升级中,请稍候!");

  //根据提交建筑物类型读取相应的所消耗资源的基础值
  $query=$db->query("select * from building_attribute where `b_type`='".$_POST['building_id']."'");
  $task_base_result=$db->fetch_array($query);
     
  //获取当前建筑物的等级
  $query=$db->query("select * from building where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."'");
  $b_current_grade=$db->fetch_array($query);
  
  if($_POST['grade_type']<>"grade" and $_POST['grade_type']<>"destory") echomsg("");

  	 //获取当前城池及总资源的最新数据////|||||||||||||||||
   	 $query=$db->query("select * from city where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."'");
   	 $task_totalresource_result=$db->fetch_array($query);
   	 
   	 $query2=$db->query("select * from resource where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."'");
   	 $total_result=$db->fetch_array($query2);
   	 
   	 $current_grade = $b_current_grade[$b_type_name_en[$task_base_result['b_type']]];//当前等级
   	 //判断是建造还是摧毁,建造100%,摧毁是建造的1/3,但只影响资源,不影响土地及工人
   	 if($_POST['build_type']=="destory"){
   	 	if($current_grade<1) echomsg("当前建筑物为最低等级,无法拆除!");
   	 	$destory_resource = 1/3;
   	 	$destory_flag = 1;
   	 	$t_type = 0;
   	 	$c_land = 0;
   	 	
   	 }else{
   	 	$destory_resource = 1;
   	 	$destory_flag = 0;
   	 	$t_type = 1;
   	 	$c_land = 1;
   	 }
   	 
     $next_grade = $current_grade+1;//下一等级
   	 if($_POST['build_type']=="destory" or $_POST['grade_type']=="destory"){
   	 $next_grade = $b_current_grade[$b_type_name_en[$task_base_result['b_type']]];//摧毁后的等级
   	 }
   	 if($_POST['build_type']<>"destory"){
   	 if($current_grade >= $building_max_grade) echomsg("已达到最高等级上限!");
   	 }
   	 //根据等级算出所需资源
   	 $building_rices = (int)(add_percent($task_base_result['b_rices'],$task_base_result['b_resource_percent'],$next_grade) * $destory_resource );
   	 $building_woods = (int)(add_percent($task_base_result['b_woods'],$task_base_result['b_resource_percent'],$next_grade) * $destory_resource );
   	 $building_irons = (int)(add_percent($task_base_result['b_irons'],$task_base_result['b_resource_percent'],$next_grade) * $destory_resource );
   	 $building_golds = (int)(add_percent($task_base_result['b_golds'],$task_base_result['b_resource_percent'],$next_grade) * $destory_resource );
   	 //升级所需消耗时间
//   	 $build_time = round(add_percent($task_base_result['b_time'],$task_base_result['b_time_percent'],$next_grade) * $destory_resource ,0);
   	 //$build_time *= pow(0.9,$b_current_grade['officer_house']);
   	 $build_time = $task_base_result['b_time'] *pow((1+$task_base_result['b_time_percent']/100),($next_grade-1));
   	 
   	 /*
   	 1级:基础时间×(50%)
	 2级:基础时间×(45%)
	 3级:基础时间×(40%)
	 4级:基础时间×(35%)
	 5级:基础时间×(30%)
	 6级:基础时间×(25%)
	 7级?30级:基础时间×(20%)的当前等级的次方:5 * 20
	 */
   	 if($b_current_grade['officer_house']){
	   	       
   	 	        if($b_current_grade['officer_house']=="1"){
		  	    	$build_time *= 0.6;
		  	    }
		  	    
		  	    if($b_current_grade['officer_house']=="2"){
		  	    	$build_time *= 0.7;
		  	    }
		  	    
		  	    if($b_current_grade['officer_house']>="3"){
		  	    	$build_time = $build_time * 0.6 * 0.7 * pow(0.8,($b_current_grade['officer_house']-2));
		  	    }  
   	 }
   	 
   	 if($build_time < 1) $build_time = 1;
   	 
   	 //$build_time = (int)$build_time;
   	 
//   	 $build_time = round($build_time,0);
   	 $build_time_ls = explode(".",$build_time);
   	 $build_time=$build_time_ls[0];
   	 
   	 //进行木材资源判断
   	 if($build_type<>"12" and $build_type<>"2"){
   	 	if($building_woods > $total_result['woods']) echomsg("木材资源不足!");
   	 }
   	 //进行粮食资源判断
   	 if($build_type<>"1" and $build_type<>"2" and $build_type<>"3" and $build_type<>"4"){
   	 	if($building_rices > $total_result['rices']) echomsg("粮食资源不足!");
   	 }
   	 //进行铁矿资源判断
   	 if($build_type<>"1" and $build_type<>"2" and $build_type<>"4" and $build_type<>"5"){
   	 	if($building_irons > $total_result['ores']) echomsg("铁矿资源不足!");
   	 }
   	 //进行黄金资源判断
   	 if($building_golds > $total_result['golds']) echomsg("黄金资源不足!");
   	 //进行土地判断
   	 if($_POST['build_type']<>"destory"){
   	     if($task_totalresource_result['c_size']<1) echomsg("当前城池已经没有土地可用!");
   	 }
   	    //扣除成功,将建造记录放入建造队列表中
   	    //判断已经存在几个队列
   	    $query=$db->query("select count(t_id) from building_task where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."'");
   	    $rn=$db->result($query,0);
   	    if($rn>=3) echomsg("建筑队列已满!");
   	    
   	   	 
   	    //[用做内测加速调整]/////////////////////////////////////////////
   	    $build_time=$build_time * $speed_percent;
   	    ////////////////////////////////////////////////////////////
   	    $build_time=$build_time*60;
   	    //首先判断是否已经存在建筑队列
   	    $query=$db->query("select t_sort,b_end_time from building_task where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."' order by t_id desc limit 1");
   	    $row=$db->fetch_array($query);
   	    if($row['t_sort']){//如果已存在,则获取它的完成时间
   	    	$b_sort=$row['t_sort']+1;
   	    	//判断是否使用道具
   	    	if ($_POST['build_type']<>'destory'){
   	    		if ($_POST['god_id']>0) {
   	    			if ($_POST['god_id']==115) {
   	    				if ($current_grade>10) echomsg("此宝物只可用于1-10级建筑加速!");
   	    				$build_time=$build_time*0.8;   	    				
   	    			}
   	    			if ($_POST['god_id']==116) {
   	    				if ($current_grade>20 || $current_grade<=10) echomsg("此宝物只可用于11-20级建筑加速!");
   	    				$build_time=$build_time*0.8;
   	    			}
   	    			$query_god_num=$db->query("select num from interior_goods where s_id='".$_POST['god_id']."' and i_uid='".$_COOKIE['UserId']."';");
   	    			$use_god_num=$db->fetch_array($query_god_num);
   	    			if ($use_god_num['num']==1) {
   	    				$db->query("delete from interior_goods where s_id='".$_POST['god_id']."' and i_uid='".$_COOKIE['UserId']."';");   	    				
   	    			}else {
   	    				$db->query("update interior_goods set num=(num-'1') where s_id='".$_POST['god_id']."' and i_uid='".$_COOKIE['UserId']."';");
   	    			}
   	    		}
   	    	}
   	    }else{
   	    	$b_start_time=time();
   	    	$b_sort=1;   	    	
   	    	//判断是否使用道具
   	    	if ($_POST['build_type']<>'destory'){
   	    		if ($_POST['god_id']>0) {
   	    			if ($_POST['god_id']==115) {
   	    				if ($current_grade>10) echomsg("此宝物只可用于1-10级建筑加速!");
   	    				$build_time=$build_time*0.8;   	    				
   	    			}
   	    			if ($_POST['god_id']==116) {
   	    				if ($current_grade>20 || $current_grade<=10) echomsg("此宝物只可用于11-20级建筑加速!");
   	    				$build_time=$build_time*0.8;
   	    			}
   	    			$query_god_num=$db->query("select num from interior_goods where s_id='".$_POST['god_id']."' and i_uid='".$_COOKIE['UserId']."';");
   	    			$use_god_num=$db->fetch_array($query_god_num);
   	    			if ($use_god_num['num']==1) {
   	    				$db->query("delete from interior_goods where s_id='".$_POST['god_id']."' and i_uid='".$_COOKIE['UserId']."';");   	    				
   	    			}else {
   	    				$db->query("update interior_goods set num=(num-'1') where s_id='".$_POST['god_id']."' and i_uid='".$_COOKIE['UserId']."';");
   	    			}
   	    		}
   	    	}
   	    	$b_end_time=$b_start_time+$build_time;//结束时间
   	    } 
   	    
   	    $db->query("update resource as r,city as c set r.`rices`=r.`rices`-'".(int)$building_rices."' ,r.`woods`=r.`woods`-'".(int)$building_woods."',r.`ores`=r.`ores`-'".(int)$building_irons."',r.`golds`=r.`golds`-'".(int)$building_golds."',
	   	 c.`c_size`=c.`c_size`-'".$c_land."' where r.`u_id`=c.`u_id` and r.`c_id`=c.`c_id` and r.`u_id`='".$_COOKIE['UserId']."' and c.`c_id`='".$_COOKIE['CityId']."'");
	  
   	    if(!$t_type) $next_grade = $current_grade - 1;

   	    $query=$db->query("insert into building_task(`t_id`,`u_id`,`c_id`,`b_type`,`b_num_grade`,`b_time`,`b_start_time`,`b_end_time`,`b_hills`,`b_woodlands`,`b_flats`,`b_workers`,`b_woods`,
   	    `b_rices`,`b_irons`,`b_golds`,`t_type`,`g_name`,`g_gid`,`t_sort`,`god_id`) values('','".$_COOKIE['UserId']."','".$_COOKIE['CityId']."','".$build_type."','".$next_grade."','".$build_time."','".$b_start_time."',
   	    '".$b_end_time."','".(int)$building_hills."','".(int)$building_woodlands."','".(int)$building_flats."','".(int)$building_workers."','".(int)$building_woods."',
   	    '".(int)$building_rices."','".(int)$building_irons."','".(int)$building_golds."','".$t_type."','".$g_intellect[2]."','".$g_intellect[0]."','".$b_sort."','".$_POST['god_id']."')");
   	    
   	    //update_resource();
   	    refresh();
   	    
   	    $db->query("update city set ea_if='1' where c_id='".$_COOKIE['CityId']."' and u_id='".$_COOKIE['UserId']."';");
   	    
   	    if($query) echomsg("","?build_page=".$_GET['build_page']);


}

//获取建筑任务队列
$query=$db->query("select * from building_task where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."' order by t_sort");
while($row=$db->fetch_array($query)) $current_task_list[]=$row;

//取消建筑队列
if($_GET['b_action']=="clear_building_task"){

	//全部取消
	if($_GET['chanel_type']=="all"){
		$query=$db->query("select * from building_task where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."'");
		while($row=$db->fetch_array($query)) $task_all[]=$row;
		  if($task_all) foreach ($task_all as $ai=>$am){
			
			//$db->query("update gen set `g_status`='0' where `g_gid`='".$am['g_gid']."' and `g_uid`='".$_COOKIE['UserId']."' and `g_cid`='".$_COOKIE['CityId']."'");
			
			$allready_used_store=$am['b_woods'] + $am['b_rices'] + $am['b_irons'] + $am['b_golds'];
		     if($am['t_type']=="0") $c_land = 0;
		     else $c_land = 1;
			 //还原资源及土地
		   	 $query=$db->query("update resource as r,city as c set r.`rices`=r.`rices`+'".$am['b_rices']."',r.`woods`=r.`woods`+'".$am['b_woods']."',r.`ores`=r.`ores`+'".($am['b_irons'])."',r.`golds`=r.`golds`+'".($am['b_golds'])."',c.`c_size`=c.`c_size`+'".$c_land."'  where r.`u_id`=c.`u_id` and r.`c_id`=c.`c_id` and r.`u_id`='".$_COOKIE['UserId']."' and c.`c_id`='".$am['c_id']."'");
		     //删除任务
		   	 $query=$db->query("delete from building_task where `u_id`='".$_COOKIE['UserId']."' and `t_id`='".$am['t_id']."'");
		}
			
	}else{//取消单个任务
	
		//取得当前要取消的建筑任务的信息
		$query=$db->query("select * from building_task where `u_id`='".$_COOKIE['UserId']."' and `c_id`='".$_COOKIE['CityId']."' and `t_id`='".$_GET['b_id']."'");
		
		$chanel_result=$db->fetch_array($query);
		
		if($_GET['building_sum']>1){
			foreach ($current_task_list as $i=>$m){
				if($i==1){
					$end_other_times=time()+$m['b_time'];
					$db->query("update building_task set `b_end_time`='".$end_other_times."' where `u_id`='".$_COOKIE['UserId']."' and `t_id`='".$m['t_id']."'");
					break;
				}
			}
		}
		$allready_used_store=$chanel_result['b_woods'] + $chanel_result['b_rices'] + $chanel_result['b_irons'] + $chanel_result['b_golds'];
	
		 if($chanel_result['t_type']=="0") $c_land = 0;
		 else $c_land = 1;
		 //还原资源和土地
	   	 $query=$db->query("update resource as r,city as c set r.`rices`=r.`rices`+'".($chanel_result['b_rices'])."',r.`woods`=r.`woods`+'".($chanel_result['b_woods'])."',r.`ores`=r.`ores`+'".($chanel_result['b_irons'])."',r.`golds`=r.`golds`+'".($chanel_result['b_golds'])."',c.`c_size`=c.`c_size`+'".$c_land."'
	   	  where r.`u_id`=c.`u_id` and r.`c_id`=c.`c_id` and r.`u_id`='".$_COOKIE['UserId']."' and c.`c_id`='".$chanel_result['c_id']."'");
		   	 
		 $query=$db->query("delete from building_task where `u_id`='".$_COOKIE['UserId']."' and `t_id`='".$_GET['b_id']."'");
	}
		//update_resource();
		refresh();
		$db->query("update city set ea_if='1' where c_id='".$_COOKIE['CityId']."' and u_id='".$_COOKIE['UserId']."';");
		echomsg("","?build_page=".$_GET['build_page']);
}


//获取当前任务的完成时间差
if($current_task_list<>"") foreach($current_task_list as $i=>$cm){
	if($cm['b_end_time']){
		$complate_time=$cm['b_end_time'];
		$remain_hours=(floor(($complate_time-time())/3600)<1) ? 0 : floor(($complate_time-time())/3600);
		$remain_minutes=(floor(($complate_time-time()-($remain_hours*3600))/60)<1) ? 0 : floor(($complate_time-time()-($remain_hours*3600))/60);
	    $remain_seconds=($complate_time-time()) - (($remain_hours*3600)  + ($remain_minutes*60));
        break;
	}
}

?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -